@platformatic/control 2.0.0-alpha.1 → 2.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/control.js CHANGED
@@ -17,7 +17,7 @@ const streamRuntimeLogsCommand = require('./lib/logs')
17
17
 
18
18
  const help = helpMe({
19
19
  dir: join(__dirname, 'help'),
20
- ext: '.txt'
20
+ ext: '.txt',
21
21
  })
22
22
 
23
23
  const program = commist({ maxDistance: 2 })
@@ -42,9 +42,9 @@ async function runControl (argv) {
42
42
  const args = parseArgs({
43
43
  args: argv,
44
44
  options: {
45
- version: { type: 'boolean', short: 'v' }
45
+ version: { type: 'boolean', short: 'v' },
46
46
  },
47
- strict: false
47
+ strict: false,
48
48
  }).values
49
49
 
50
50
  if (args.version && argv[0] !== 'inject') {
@@ -79,5 +79,5 @@ module.exports = {
79
79
  stopRuntimeCommand,
80
80
  restartRuntimeCommand,
81
81
  injectRuntimeCommand,
82
- streamRuntimeLogsCommand
82
+ streamRuntimeLogsCommand,
83
83
  }
@@ -0,0 +1,3 @@
1
+ 'use strict'
2
+
3
+ module.exports = require('neostandard')({})
package/index.js CHANGED
@@ -3,5 +3,5 @@
3
3
  const RuntimeApiClient = require('./lib/runtime-api-client')
4
4
 
5
5
  module.exports = {
6
- RuntimeApiClient
6
+ RuntimeApiClient,
7
7
  }
package/lib/config.js CHANGED
@@ -9,9 +9,9 @@ async function getRuntimeConfigCommand (argv) {
9
9
  options: {
10
10
  pid: { type: 'string', short: 'p' },
11
11
  name: { type: 'string', short: 'n' },
12
- service: { type: 'string', short: 's' }
12
+ service: { type: 'string', short: 's' },
13
13
  },
14
- strict: false
14
+ strict: false,
15
15
  }).values
16
16
 
17
17
  const client = new RuntimeApiClient()
package/lib/env.js CHANGED
@@ -8,9 +8,9 @@ async function getRuntimeEnvCommand (argv) {
8
8
  args: argv,
9
9
  options: {
10
10
  pid: { type: 'string', short: 'p' },
11
- name: { type: 'string', short: 'n' }
11
+ name: { type: 'string', short: 'n' },
12
12
  },
13
- strict: false
13
+ strict: false,
14
14
  }).values
15
15
 
16
16
  const client = new RuntimeApiClient()
package/lib/errors.js CHANGED
@@ -20,5 +20,5 @@ module.exports = {
20
20
  FailedToGetRuntimeServiceConfig: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_CONFIG`, 'Failed to get runtime service config %s.'),
21
21
  FailedToGetRuntimeHistoryLogs: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS`, 'Failed to get history logs %s.'),
22
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.')
23
+ FailedToGetRuntimeLogIndexes: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS_COUNT`, 'Failed to get history logs count %s.'),
24
24
  }
package/lib/inject.js CHANGED
@@ -17,9 +17,9 @@ async function injectRuntimeCommand (argv) {
17
17
  data: { type: 'string', short: 'd' },
18
18
  include: { type: 'boolean', short: 'i', default: false },
19
19
  verbose: { type: 'boolean', short: 'v', default: false },
20
- output: { type: 'string', short: 'o' }
20
+ output: { type: 'string', short: 'o' },
21
21
  },
22
- strict: false
22
+ strict: false,
23
23
  })
24
24
 
25
25
  const client = new RuntimeApiClient()
package/lib/logs.js CHANGED
@@ -10,7 +10,7 @@ const pinoLogLevels = {
10
10
  warn: 40,
11
11
  info: 30,
12
12
  debug: 20,
13
- trace: 10
13
+ trace: 10,
14
14
  }
15
15
 
16
16
  async function streamRuntimeLogsCommand (argv) {
@@ -21,9 +21,9 @@ async function streamRuntimeLogsCommand (argv) {
21
21
  name: { type: 'string', short: 'n' },
22
22
  level: { type: 'string', short: 'l', default: 'info' },
23
23
  pretty: { type: 'string', default: 'true' },
24
- service: { type: 'string', short: 's' }
24
+ service: { type: 'string', short: 's' },
25
25
  },
26
- strict: false
26
+ strict: false,
27
27
  }).values
28
28
 
29
29
  const client = new RuntimeApiClient()
package/lib/ps.js CHANGED
@@ -6,29 +6,29 @@ const RuntimeApiClient = require('./runtime-api-client')
6
6
  const tableColumns = [
7
7
  {
8
8
  value: 'pid',
9
- alias: 'PID'
9
+ alias: 'PID',
10
10
  },
11
11
  {
12
12
  value: 'packageName',
13
- alias: 'NAME'
13
+ alias: 'NAME',
14
14
  },
15
15
  {
16
16
  value: 'platformaticVersion',
17
- alias: 'PLT'
17
+ alias: 'PLT',
18
18
  },
19
19
  {
20
20
  value: 'uptimeSeconds',
21
21
  alias: 'TIME',
22
- formatter: formatRuntimeTime
22
+ formatter: formatRuntimeTime,
23
23
  },
24
24
  {
25
25
  value: 'url',
26
- alias: 'URL'
26
+ alias: 'URL',
27
27
  },
28
28
  {
29
29
  value: 'projectDir',
30
- alias: 'PWD'
31
- }
30
+ alias: 'PWD',
31
+ },
32
32
  ]
33
33
 
34
34
  function formatRuntimeTime (timeSeconds) {
@@ -56,9 +56,9 @@ const tableConfig = {
56
56
  border: getBorderCharacters('void'),
57
57
  columnDefault: {
58
58
  paddingLeft: 0,
59
- paddingRight: 1
59
+ paddingRight: 1,
60
60
  },
61
- drawHorizontalLine: () => false
61
+ drawHorizontalLine: () => false,
62
62
  }
63
63
 
64
64
  async function printRuntimes (runtimes) {
package/lib/reload.js CHANGED
@@ -8,9 +8,9 @@ async function reloadRuntimeCommand (argv) {
8
8
  args: argv,
9
9
  options: {
10
10
  pid: { type: 'string', short: 'p' },
11
- name: { type: 'string', short: 'n' }
11
+ name: { type: 'string', short: 'n' },
12
12
  },
13
- strict: false
13
+ strict: false,
14
14
  }).values
15
15
 
16
16
  const client = new RuntimeApiClient()
package/lib/restart.js CHANGED
@@ -8,9 +8,9 @@ async function restartRuntimeCommand (argv) {
8
8
  args: argv,
9
9
  options: {
10
10
  pid: { type: 'string', short: 'p' },
11
- name: { type: 'string', short: 'n' }
11
+ name: { type: 'string', short: 'n' },
12
12
  },
13
- strict: false
13
+ strict: false,
14
14
  }).values
15
15
 
16
16
  const client = new RuntimeApiClient()
@@ -3,11 +3,12 @@
3
3
  const { tmpdir, platform, EOL } = require('node:os')
4
4
  const { join } = require('node:path')
5
5
  const { exec, spawn } = require('node:child_process')
6
- const { readdir, rm, access } = require('node:fs/promises')
6
+ const { readdir, access } = require('node:fs/promises')
7
7
  const { Readable } = require('node:stream')
8
8
  const { Client } = require('undici')
9
9
  const WebSocket = require('ws')
10
10
  const errors = require('./errors.js')
11
+ const { safeRemove } = require('@platformatic/utils')
11
12
 
12
13
  const PLATFORMATIC_TMP_DIR = join(tmpdir(), 'platformatic', 'runtimes')
13
14
  const PLATFORMATIC_PIPE_PREFIX = '\\\\.\\pipe\\platformatic-'
@@ -34,12 +35,10 @@ class RuntimeApiClient {
34
35
  }
35
36
 
36
37
  async getRuntimes () {
37
- const runtimePIDs = platform() === 'win32'
38
- ? await this.#getWindowsRuntimePIDs()
39
- : await this.#getUnixRuntimePIDs()
38
+ const runtimePIDs = platform() === 'win32' ? await this.#getWindowsRuntimePIDs() : await this.#getUnixRuntimePIDs()
40
39
 
41
40
  const getMetadataRequests = await Promise.allSettled(
42
- runtimePIDs.map(async (runtimePID) => {
41
+ runtimePIDs.map(async runtimePID => {
43
42
  return this.getRuntimeMetadata(runtimePID)
44
43
  })
45
44
  )
@@ -63,7 +62,7 @@ class RuntimeApiClient {
63
62
 
64
63
  const { statusCode, body } = await client.request({
65
64
  path: '/api/v1/metadata',
66
- method: 'GET'
65
+ method: 'GET',
67
66
  })
68
67
 
69
68
  if (statusCode !== 200) {
@@ -80,7 +79,7 @@ class RuntimeApiClient {
80
79
 
81
80
  const { statusCode, body } = await client.request({
82
81
  path: '/api/v1/services',
83
- method: 'GET'
82
+ method: 'GET',
84
83
  })
85
84
 
86
85
  if (statusCode !== 200) {
@@ -97,7 +96,7 @@ class RuntimeApiClient {
97
96
 
98
97
  const { statusCode, body } = await client.request({
99
98
  path: `/api/v1/services/${serviceId}/config`,
100
- method: 'GET'
99
+ method: 'GET',
101
100
  })
102
101
 
103
102
  if (statusCode !== 200) {
@@ -114,7 +113,7 @@ class RuntimeApiClient {
114
113
 
115
114
  const { statusCode, body } = await client.request({
116
115
  path: '/api/v1/config',
117
- method: 'GET'
116
+ method: 'GET',
118
117
  })
119
118
 
120
119
  if (statusCode !== 200) {
@@ -131,7 +130,7 @@ class RuntimeApiClient {
131
130
 
132
131
  const { statusCode, body } = await client.request({
133
132
  path: '/api/v1/env',
134
- method: 'GET'
133
+ method: 'GET',
135
134
  })
136
135
 
137
136
  if (statusCode !== 200) {
@@ -158,7 +157,7 @@ class RuntimeApiClient {
158
157
 
159
158
  const { statusCode, body } = await client.request({
160
159
  path: '/api/v1/reload',
161
- method: 'POST'
160
+ method: 'POST',
162
161
  })
163
162
 
164
163
  if (statusCode !== 200) {
@@ -172,7 +171,7 @@ class RuntimeApiClient {
172
171
 
173
172
  const { statusCode, body } = await client.request({
174
173
  path: '/api/v1/stop',
175
- method: 'POST'
174
+ method: 'POST',
176
175
  })
177
176
 
178
177
  if (statusCode !== 200) {
@@ -211,7 +210,7 @@ class RuntimeApiClient {
211
210
  const { statusCode, body } = await client.request({
212
211
  path: '/api/v1/logs/' + logsId,
213
212
  method: 'GET',
214
- query: { pid: runtimePID }
213
+ query: { pid: runtimePID },
215
214
  })
216
215
 
217
216
  if (statusCode !== 200) {
@@ -229,7 +228,7 @@ class RuntimeApiClient {
229
228
  const { statusCode, body } = await client.request({
230
229
  path: '/api/v1/logs/all',
231
230
  method: 'GET',
232
- query: { pid: runtimePID }
231
+ query: { pid: runtimePID },
233
232
  })
234
233
 
235
234
  if (statusCode !== 200) {
@@ -247,7 +246,7 @@ class RuntimeApiClient {
247
246
  const { statusCode, body } = await client.request({
248
247
  path: '/api/v1/logs/indexes',
249
248
  method: 'GET',
250
- query: { all }
249
+ query: { all },
251
250
  })
252
251
 
253
252
  if (statusCode !== 200) {
@@ -269,7 +268,7 @@ class RuntimeApiClient {
269
268
  method: options.method,
270
269
  headers: options.headers,
271
270
  query: options.query,
272
- body: options.body
271
+ body: options.body,
273
272
  })
274
273
  return response
275
274
  }
@@ -287,10 +286,13 @@ class RuntimeApiClient {
287
286
  let undiciClient = this.#undiciClients.get(pid)
288
287
  if (!undiciClient) {
289
288
  const socketPath = this.#getSocketPathFromPid(pid)
290
- undiciClient = new Client({
291
- hostname: 'localhost',
292
- protocol: 'http:'
293
- }, { socketPath })
289
+ undiciClient = new Client(
290
+ {
291
+ hostname: 'localhost',
292
+ protocol: 'http:',
293
+ },
294
+ { socketPath }
295
+ )
294
296
 
295
297
  this.#undiciClients.set(pid, undiciClient)
296
298
  }
@@ -332,24 +334,20 @@ class RuntimeApiClient {
332
334
 
333
335
  async #getWindowsNamedPipes () {
334
336
  return new Promise((resolve, reject) => {
335
- exec(
336
- '[System.IO.Directory]::GetFiles("\\\\.\\pipe\\")',
337
- { shell: 'powershell.exe' },
338
- (err, stdout) => {
339
- if (err) {
340
- reject(err)
341
- return
342
- }
343
- const namedPipes = stdout.split(EOL)
344
- resolve(namedPipes)
337
+ exec('[System.IO.Directory]::GetFiles("\\\\.\\pipe\\")', { shell: 'powershell.exe' }, (err, stdout) => {
338
+ if (err) {
339
+ reject(err)
340
+ return
345
341
  }
346
- )
342
+ const namedPipes = stdout.split(EOL)
343
+ resolve(namedPipes)
344
+ })
347
345
  })
348
346
  }
349
347
 
350
348
  async #removeRuntimeTmpDir (pid) {
351
349
  const runtimeDir = join(PLATFORMATIC_TMP_DIR, pid.toString())
352
- await rm(runtimeDir, { recursive: true, force: true })
350
+ await safeRemove(runtimeDir)
353
351
  }
354
352
  }
355
353
 
@@ -358,13 +356,13 @@ class WebSocketStream extends Readable {
358
356
  super()
359
357
  this.ws = new WebSocket(url)
360
358
 
361
- this.ws.on('message', (data) => {
359
+ this.ws.on('message', data => {
362
360
  this.push(data)
363
361
  })
364
362
  this.ws.on('close', () => {
365
363
  this.push(null)
366
364
  })
367
- this.ws.on('error', (err) => {
365
+ this.ws.on('error', err => {
368
366
  this.emit('error', new errors.FailedToStreamRuntimeLogs(err.message))
369
367
  })
370
368
  this.on('close', () => {
package/lib/services.js CHANGED
@@ -7,28 +7,28 @@ const RuntimeApiClient = require('./runtime-api-client')
7
7
  const tableColumns = [
8
8
  {
9
9
  value: 'id',
10
- alias: 'NAME'
10
+ alias: 'NAME',
11
11
  },
12
12
  {
13
13
  value: 'type',
14
- alias: 'TYPE'
14
+ alias: 'TYPE',
15
15
  },
16
16
  {
17
17
  value: 'entrypoint',
18
18
  alias: 'ENTRYPOINT',
19
19
  formatter: (entrypoint) => {
20
20
  return entrypoint ? 'yes' : 'no'
21
- }
22
- }
21
+ },
22
+ },
23
23
  ]
24
24
 
25
25
  const tableConfig = {
26
26
  border: getBorderCharacters('void'),
27
27
  columnDefault: {
28
28
  paddingLeft: 0,
29
- paddingRight: 1
29
+ paddingRight: 1,
30
30
  },
31
- drawHorizontalLine: () => false
31
+ drawHorizontalLine: () => false,
32
32
  }
33
33
 
34
34
  async function printRuntimeServices (services) {
@@ -56,9 +56,9 @@ async function getRuntimeServicesCommand (argv) {
56
56
  args: argv,
57
57
  options: {
58
58
  pid: { type: 'string', short: 'p' },
59
- name: { type: 'string', short: 'n' }
59
+ name: { type: 'string', short: 'n' },
60
60
  },
61
- strict: false
61
+ strict: false,
62
62
  }).values
63
63
 
64
64
  const client = new RuntimeApiClient()
package/lib/stop.js CHANGED
@@ -8,9 +8,9 @@ async function stopRuntimeCommand (argv) {
8
8
  args: argv,
9
9
  options: {
10
10
  pid: { type: 'string', short: 'p' },
11
- name: { type: 'string', short: 'n' }
11
+ name: { type: 'string', short: 'n' },
12
12
  },
13
- strict: false
13
+ strict: false,
14
14
  }).values
15
15
 
16
16
  const client = new RuntimeApiClient()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Platformatic Control",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -17,14 +17,16 @@
17
17
  },
18
18
  "homepage": "https://github.com/platformatic/platformatic#readme",
19
19
  "devDependencies": {
20
- "borp": "^0.16.0",
20
+ "borp": "^0.17.0",
21
21
  "desm": "^1.3.1",
22
+ "eslint": "9",
22
23
  "execa": "^8.0.1",
23
- "snazzy": "^9.0.0",
24
+ "neostandard": "^0.11.1",
24
25
  "split2": "^4.2.0",
25
- "standard": "^17.1.0",
26
26
  "tsd": "^0.31.0",
27
- "@platformatic/runtime": "2.0.0-alpha.1"
27
+ "typescript": "^5.5.4",
28
+ "@platformatic/runtime": "2.0.0-alpha.3",
29
+ "@platformatic/service": "2.0.0-alpha.3"
28
30
  },
29
31
  "dependencies": {
30
32
  "@fastify/error": "^3.4.1",
@@ -34,12 +36,13 @@
34
36
  "pino-pretty": "^11.0.0",
35
37
  "table": "^6.8.1",
36
38
  "undici": "^6.9.0",
37
- "ws": "^8.16.0"
39
+ "ws": "^8.16.0",
40
+ "@platformatic/utils": "2.0.0-alpha.3"
38
41
  },
39
42
  "scripts": {
40
43
  "test": "pnpm run lint && pnpm run unit",
41
- "unit": "borp --concurrency=1 --timeout 60000",
44
+ "unit": "borp --concurrency=1 --timeout=180000",
42
45
  "build": "node lib/schema.js | json2ts > config.d.ts",
43
- "lint": "standard | snazzy"
46
+ "lint": "eslint"
44
47
  }
45
48
  }