@platformatic/control 1.33.0 → 1.35.1

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
@@ -47,7 +47,7 @@ async function runControl (argv) {
47
47
  strict: false
48
48
  }).values
49
49
 
50
- if (args.version) {
50
+ if (args.version && argv[0] !== 'inject') {
51
51
  const packageJson = require(join(__dirname, 'package.json'))
52
52
  console.log(packageJson.version)
53
53
  process.exit(0)
package/help/inject.txt CHANGED
@@ -16,6 +16,7 @@ Options:
16
16
  * `-H, --header <string>` - The request header. Can be used multiple times.
17
17
  * `-d, --data <string>` - The request data.
18
18
  * `-i, --include <boolean>` - Include the response headers in the output. Default is `false`.
19
+ * `-v, --verbose <boolean>` - Make the operation more talkative. Default is `false`.
19
20
  * `-o, --output <file>` - Write the response to the specified file.
20
21
 
21
22
  The `inject` command sends a request to the runtime service and prints the
package/lib/inject.js CHANGED
@@ -16,6 +16,7 @@ async function injectRuntimeCommand (argv) {
16
16
  header: { type: 'string', short: 'H', multiple: true },
17
17
  data: { type: 'string', short: 'd' },
18
18
  include: { type: 'boolean', short: 'i', default: false },
19
+ verbose: { type: 'boolean', short: 'v', default: false },
19
20
  output: { type: 'string', short: 'o' }
20
21
  },
21
22
  strict: false
@@ -34,30 +35,59 @@ async function injectRuntimeCommand (argv) {
34
35
  throw errors.MissingRequestURL()
35
36
  }
36
37
 
38
+ let result = ''
39
+
37
40
  const fullUrl = new URL(positionals[0], runtime.url)
38
41
  const injectPath = fullUrl.href.slice(runtime.url.length)
39
42
 
40
43
  const method = args.request
41
44
  const body = args.data
42
45
 
46
+ if (args.verbose) {
47
+ result += `> ${method} ${injectPath} HTTP/1.1\n`
48
+ }
49
+
43
50
  const headers = {}
44
51
  for (const header of args.header || []) {
45
52
  const [name, value] = header.split(':')
46
53
  headers[name] = value
54
+
55
+ if (args.verbose) {
56
+ result += `> ${name}: ${value}\n`
57
+ }
58
+ }
59
+
60
+ if (args.verbose && args.header.length > 0) {
61
+ result += '> \n'
47
62
  }
48
63
 
49
64
  const injectOptions = { url: injectPath, method, headers, body }
50
65
 
51
66
  const response = await client.injectRuntime(runtime.pid, serviceId, injectOptions)
52
67
 
53
- let result = ''
68
+ if (args.verbose) {
69
+ result += `< HTTP/1.1 ${response.statusCode}\n`
70
+ }
54
71
  if (args.include) {
55
72
  result += `HTTP/1.1 ${response.statusCode}\n`
56
- for (const header in response.headers) {
73
+ }
74
+
75
+ for (const header in response.headers) {
76
+ if (args.verbose) {
77
+ result += `< ${header}: ${response.headers[header]}\n`
78
+ }
79
+ if (args.include) {
57
80
  result += `${header}: ${response.headers[header]}\n`
58
81
  }
82
+ }
83
+
84
+ if (args.verbose) {
85
+ result += '< \n'
86
+ }
87
+ if (args.include) {
59
88
  result += '\n'
60
89
  }
90
+
61
91
  result += await response.body.text()
62
92
 
63
93
  if (args.output) {
@@ -204,12 +204,14 @@ class RuntimeApiClient {
204
204
  return webSocketStream
205
205
  }
206
206
 
207
- async getRuntimeLogsStream (pid, logsId) {
207
+ async getRuntimeLogsStream (pid, logsId, options = {}) {
208
+ const runtimePID = options.runtimePID ?? pid
208
209
  const client = this.#getUndiciClient(pid)
209
210
 
210
211
  const { statusCode, body } = await client.request({
211
212
  path: '/api/v1/logs/' + logsId,
212
- method: 'GET'
213
+ method: 'GET',
214
+ query: { pid: runtimePID }
213
215
  })
214
216
 
215
217
  if (statusCode !== 200) {
@@ -220,12 +222,14 @@ class RuntimeApiClient {
220
222
  return body
221
223
  }
222
224
 
223
- async getRuntimeAllLogsStream (pid) {
225
+ async getRuntimeAllLogsStream (pid, options = {}) {
226
+ const runtimePID = options.runtimePID ?? pid
224
227
  const client = this.#getUndiciClient(pid)
225
228
 
226
229
  const { statusCode, body } = await client.request({
227
230
  path: '/api/v1/logs/all',
228
- method: 'GET'
231
+ method: 'GET',
232
+ query: { pid: runtimePID }
229
233
  })
230
234
 
231
235
  if (statusCode !== 200) {
@@ -236,12 +240,14 @@ class RuntimeApiClient {
236
240
  return body
237
241
  }
238
242
 
239
- async getRuntimeLogIndexes (pid) {
243
+ async getRuntimeLogIndexes (pid, options = {}) {
244
+ const all = options.all ?? false
240
245
  const client = this.#getUndiciClient(pid)
241
246
 
242
247
  const { statusCode, body } = await client.request({
243
248
  path: '/api/v1/logs/indexes',
244
- method: 'GET'
249
+ method: 'GET',
250
+ query: { all }
245
251
  })
246
252
 
247
253
  if (statusCode !== 200) {
@@ -249,8 +255,10 @@ class RuntimeApiClient {
249
255
  throw new errors.FailedToGetRuntimeLogIndexes(error)
250
256
  }
251
257
 
252
- const { indexes } = await body.json()
253
- return indexes
258
+ const result = await body.json()
259
+ if (all) return result
260
+
261
+ return result.indexes
254
262
  }
255
263
 
256
264
  async injectRuntime (pid, serviceId, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "1.33.0",
3
+ "version": "1.35.1",
4
4
  "description": "Platformatic Control",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -17,14 +17,14 @@
17
17
  },
18
18
  "homepage": "https://github.com/platformatic/platformatic#readme",
19
19
  "devDependencies": {
20
- "borp": "^0.10.0",
20
+ "borp": "^0.11.0",
21
21
  "desm": "^1.3.1",
22
22
  "execa": "^8.0.1",
23
23
  "snazzy": "^9.0.0",
24
24
  "split2": "^4.2.0",
25
25
  "standard": "^17.1.0",
26
26
  "tsd": "^0.31.0",
27
- "@platformatic/runtime": "1.33.0"
27
+ "@platformatic/runtime": "1.35.1"
28
28
  },
29
29
  "dependencies": {
30
30
  "@fastify/error": "^3.4.1",