@platformatic/control 3.0.0-alpha.5 → 3.0.0-alpha.8

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/eslint.config.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import neostandard from 'neostandard'
2
2
 
3
- export default neostandard({})
3
+ export default neostandard()
package/lib/errors.d.ts CHANGED
@@ -3,18 +3,18 @@ import { FastifyError } from '@fastify/error'
3
3
  export declare const ERROR_PREFIX: string
4
4
 
5
5
  export declare const RuntimeNotFound: (value: string) => FastifyError
6
- export declare const ServiceNotFound: (value: string) => FastifyError
6
+ export declare const ApplicationNotFound: (value: string) => FastifyError
7
7
  export declare const MissingRequestURL: (value: string) => FastifyError
8
8
  export declare const FailedToGetRuntimeMetadata: (value: string) => FastifyError
9
- export declare const FailedToGetRuntimeServices: (value: string) => FastifyError
9
+ export declare const FailedToGetRuntimeApplications: (value: string) => FastifyError
10
10
  export declare const FailedToGetRuntimeEnv: (value: string) => FastifyError
11
11
  export declare const FailedToGetRuntimeOpenapi: (value: string) => FastifyError
12
12
  export declare const FailedToStreamRuntimeLogs: (value: string) => FastifyError
13
13
  export declare const FailedToStopRuntime: (value: string) => FastifyError
14
14
  export declare const FailedToReloadRuntime: (value: string) => FastifyError
15
15
  export declare const FailedToGetRuntimeConfig: (value: string) => FastifyError
16
- export declare const FailedToGetRuntimeServiceEnv: (value: string) => FastifyError
17
- export declare const FailedToGetRuntimeServiceConfig: (value: string) => FastifyError
16
+ export declare const FailedToGetRuntimeApplicationEnv: (value: string) => FastifyError
17
+ export declare const FailedToGetRuntimeApplicationConfig: (value: string) => FastifyError
18
18
  export declare const FailedToGetRuntimeHistoryLogs: (value: string) => FastifyError
19
19
  export declare const FailedToGetRuntimeAllLogs: (value: string) => FastifyError
20
20
  export declare const FailedToGetRuntimeLogIndexes: (value: string) => FastifyError
package/lib/errors.js CHANGED
@@ -4,7 +4,7 @@ export const ERROR_PREFIX = 'PLT_CTR'
4
4
 
5
5
  export const RuntimeNotFound = createError(`${ERROR_PREFIX}_RUNTIME_NOT_FOUND`, 'Runtime not found.')
6
6
 
7
- export const ServiceNotFound = createError(`${ERROR_PREFIX}_SERVICE_NOT_FOUND`, 'Service not found.')
7
+ export const ApplicationNotFound = createError(`${ERROR_PREFIX}_APPLICATION_NOT_FOUND`, 'Application not found.')
8
8
 
9
9
  export const MissingRequestURL = createError(`${ERROR_PREFIX}_MISSING_REQUEST_URL`, 'Request URL is required.')
10
10
 
@@ -13,9 +13,9 @@ export const FailedToGetRuntimeMetadata = createError(
13
13
  'Failed to get runtime metadata %s.'
14
14
  )
15
15
 
16
- export const FailedToGetRuntimeServices = createError(
17
- `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICES`,
18
- 'Failed to get runtime services %s.'
16
+ export const FailedToGetRuntimeApplications = createError(
17
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_APPLICATIONS`,
18
+ 'Failed to get runtime applications %s.'
19
19
  )
20
20
 
21
21
  export const FailedToGetRuntimeEnv = createError(
@@ -48,14 +48,14 @@ export const FailedToGetRuntimeConfig = createError(
48
48
  'Failed to get runtime config %s.'
49
49
  )
50
50
 
51
- export const FailedToGetRuntimeServiceEnv = createError(
52
- `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_ENV`,
53
- 'Failed to get runtime service environment variables %s.'
51
+ export const FailedToGetRuntimeApplicationEnv = createError(
52
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_APPLICATION_ENV`,
53
+ 'Failed to get runtime application environment variables %s.'
54
54
  )
55
55
 
56
- export const FailedToGetRuntimeServiceConfig = createError(
57
- `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_CONFIG`,
58
- 'Failed to get runtime service config %s.'
56
+ export const FailedToGetRuntimeApplicationConfig = createError(
57
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_APPLICATION_CONFIG`,
58
+ 'Failed to get runtime application config %s.'
59
59
  )
60
60
 
61
61
  export const FailedToGetRuntimeHistoryLogs = createError(
@@ -77,3 +77,23 @@ export const FailedToGetRuntimeMetrics = createError(
77
77
  `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_METRICS`,
78
78
  'Failed to get runtime metrics %s.'
79
79
  )
80
+
81
+ export const ProfilingAlreadyStarted = createError(
82
+ `${ERROR_PREFIX}_PROFILING_ALREADY_STARTED`,
83
+ 'Profiling is already started for service "%s".'
84
+ )
85
+
86
+ export const ProfilingNotStarted = createError(
87
+ `${ERROR_PREFIX}_PROFILING_NOT_STARTED`,
88
+ 'Profiling not started for service "%s".'
89
+ )
90
+
91
+ export const FailedToStartProfiling = createError(
92
+ `${ERROR_PREFIX}_FAILED_TO_START_PROFILING`,
93
+ 'Failed to start profiling for service "%s": %s'
94
+ )
95
+
96
+ export const FailedToStopProfiling = createError(
97
+ `${ERROR_PREFIX}_FAILED_TO_STOP_PROFILING`,
98
+ 'Failed to stop profiling for service "%s": %s'
99
+ )
package/lib/index.d.ts CHANGED
@@ -18,12 +18,12 @@ export interface RuntimeDependency {
18
18
  local: boolean
19
19
  }
20
20
 
21
- export interface RuntimeServiceBase {
21
+ export interface RuntimeApplicationBase {
22
22
  id: string
23
23
  status: string
24
24
  }
25
25
 
26
- export interface RuntimeService {
26
+ export interface RuntimeApplication {
27
27
  id: string
28
28
  type: string
29
29
  status: string
@@ -49,10 +49,10 @@ export interface Runtime {
49
49
  platformaticVersion: string
50
50
  }
51
51
 
52
- export interface RuntimeServices {
52
+ export interface RuntimeApplications {
53
53
  entrypoint: string
54
54
  production: boolean
55
- services: (RuntimeService | RuntimeServiceBase)[]
55
+ applications: (RuntimeApplication | RuntimeApplicationBase)[]
56
56
  }
57
57
 
58
58
  export interface MetricValue {
@@ -71,7 +71,7 @@ export interface MetricValue {
71
71
  patch?: number
72
72
  le?: number | string
73
73
  kind?: string
74
- serviceId: string
74
+ applicationId: string
75
75
  workerId?: number
76
76
  dispatcher_stats_url?: string
77
77
  }
@@ -96,12 +96,12 @@ export class RuntimeApiClient {
96
96
  getMatchingRuntime (options?: { pid?: string; name?: string }): Promise<Runtime>
97
97
  getRuntimes (): Promise<Runtime[]>
98
98
  getRuntimeMetadata (pid: number): Promise<Runtime>
99
- getRuntimeServices (pid: number): Promise<RuntimeServices>
99
+ getRuntimeApplications (pid: number): Promise<RuntimeApplications>
100
100
  getRuntimeConfig (pid: number): Promise<Record<string, unknown>>
101
- getRuntimeServiceConfig (pid: number, serviceId?: string): Promise<Record<string, unknown>>
101
+ getRuntimeApplicationConfig (pid: number, applicationId?: string): Promise<Record<string, unknown>>
102
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>>
103
+ getRuntimeOpenapi (pid: number, applicationId: string): Promise<Record<string, unknown>>
104
+ getRuntimeApplicationEnv (pid: number, applicationId: string): Promise<Record<string, string>>
105
105
  reloadRuntime (pid: number, options?: object): Promise<ChildProcess>
106
106
  restartRuntime (pid: number): Promise<void>
107
107
  stopRuntime (pid: number): Promise<void>
@@ -116,7 +116,7 @@ export class RuntimeApiClient {
116
116
  getRuntimeLogIndexes (pid: number, options?: { all?: boolean }): Promise<LogIndexes[]>
117
117
  injectRuntime (
118
118
  pid: number,
119
- serviceId: string,
119
+ applicationId: string,
120
120
  options: {
121
121
  url: string
122
122
  method: string
package/lib/index.js CHANGED
@@ -7,7 +7,11 @@ import { Readable } from 'node:stream'
7
7
  import { Client } from 'undici'
8
8
  import WebSocket from 'ws'
9
9
  import {
10
+ ApplicationNotFound,
10
11
  FailedToGetRuntimeAllLogs,
12
+ FailedToGetRuntimeApplicationConfig,
13
+ FailedToGetRuntimeApplicationEnv,
14
+ FailedToGetRuntimeApplications,
11
15
  FailedToGetRuntimeConfig,
12
16
  FailedToGetRuntimeEnv,
13
17
  FailedToGetRuntimeHistoryLogs,
@@ -15,14 +19,14 @@ import {
15
19
  FailedToGetRuntimeMetadata,
16
20
  FailedToGetRuntimeMetrics,
17
21
  FailedToGetRuntimeOpenapi,
18
- FailedToGetRuntimeServiceConfig,
19
- FailedToGetRuntimeServiceEnv,
20
- FailedToGetRuntimeServices,
21
22
  FailedToReloadRuntime,
23
+ FailedToStartProfiling,
24
+ FailedToStopProfiling,
22
25
  FailedToStopRuntime,
23
26
  FailedToStreamRuntimeLogs,
24
- RuntimeNotFound,
25
- ServiceNotFound
27
+ ProfilingAlreadyStarted,
28
+ ProfilingNotStarted,
29
+ RuntimeNotFound
26
30
  } from './errors.js'
27
31
 
28
32
  const PLATFORMATIC_TMP_DIR = join(tmpdir(), 'platformatic', 'runtimes')
@@ -146,21 +150,21 @@ export class RuntimeApiClient {
146
150
  return metadata
147
151
  }
148
152
 
149
- async getRuntimeServices (pid) {
153
+ async getRuntimeApplications (pid) {
150
154
  const client = this.#getUndiciClient(pid)
151
155
 
152
156
  const { statusCode, body } = await client.request({
153
- path: '/api/v1/services',
157
+ path: '/api/v1/applications',
154
158
  method: 'GET'
155
159
  })
156
160
 
157
161
  if (statusCode !== 200) {
158
162
  const error = await body.text()
159
- throw new FailedToGetRuntimeServices(error)
163
+ throw new FailedToGetRuntimeApplications(error)
160
164
  }
161
165
 
162
- const runtimeServices = await body.json()
163
- return runtimeServices
166
+ const runtimeApplications = await body.json()
167
+ return runtimeApplications
164
168
  }
165
169
 
166
170
  async getRuntimeConfig (pid) {
@@ -180,11 +184,11 @@ export class RuntimeApiClient {
180
184
  return runtimeConfig
181
185
  }
182
186
 
183
- async getRuntimeServiceConfig (pid, serviceId) {
187
+ async getRuntimeApplicationConfig (pid, applicationId) {
184
188
  const client = this.#getUndiciClient(pid)
185
189
 
186
190
  const { statusCode, body } = await client.request({
187
- path: `/api/v1/services/${serviceId}/config`,
191
+ path: `/api/v1/applications/${applicationId}/config`,
188
192
  method: 'GET'
189
193
  })
190
194
 
@@ -198,17 +202,17 @@ export class RuntimeApiClient {
198
202
  }
199
203
 
200
204
  if (
201
- jsonError?.code === 'PLT_RUNTIME_SERVICE_NOT_FOUND' ||
202
- jsonError?.code === 'PLT_RUNTIME_SERVICE_WORKER_NOT_FOUND'
205
+ jsonError?.code === 'PLT_RUNTIME_APPLICATION_NOT_FOUND' ||
206
+ jsonError?.code === 'PLT_RUNTIME_APPLICATION_WORKER_NOT_FOUND'
203
207
  ) {
204
- throw new ServiceNotFound(error)
208
+ throw new ApplicationNotFound(error)
205
209
  }
206
210
 
207
- throw new FailedToGetRuntimeServiceConfig(error)
211
+ throw new FailedToGetRuntimeApplicationConfig(error)
208
212
  }
209
213
 
210
- const serviceConfig = await body.json()
211
- return serviceConfig
214
+ const applicationConfig = await body.json()
215
+ return applicationConfig
212
216
  }
213
217
 
214
218
  async getRuntimeEnv (pid) {
@@ -228,11 +232,11 @@ export class RuntimeApiClient {
228
232
  return runtimeEnv
229
233
  }
230
234
 
231
- async getRuntimeOpenapi (pid, serviceId) {
235
+ async getRuntimeOpenapi (pid, applicationId) {
232
236
  const client = this.#getUndiciClient(pid)
233
237
 
234
238
  const { statusCode, body } = await client.request({
235
- path: `/api/v1/services/${serviceId}/openapi-schema`,
239
+ path: `/api/v1/applications/${applicationId}/openapi-schema`,
236
240
  method: 'GET'
237
241
  })
238
242
 
@@ -245,11 +249,11 @@ export class RuntimeApiClient {
245
249
  return openapi
246
250
  }
247
251
 
248
- async getRuntimeServiceEnv (pid, serviceId) {
252
+ async getRuntimeApplicationEnv (pid, applicationId) {
249
253
  const client = this.#getUndiciClient(pid)
250
254
 
251
255
  const { statusCode, body } = await client.request({
252
- path: `/api/v1/services/${serviceId}/env`,
256
+ path: `/api/v1/applications/${applicationId}/env`,
253
257
  method: 'GET'
254
258
  })
255
259
 
@@ -263,17 +267,90 @@ export class RuntimeApiClient {
263
267
  }
264
268
 
265
269
  if (
266
- jsonError?.code === 'PLT_RUNTIME_SERVICE_NOT_FOUND' ||
267
- jsonError?.code === 'PLT_RUNTIME_SERVICE_WORKER_NOT_FOUND'
270
+ jsonError?.code === 'PLT_RUNTIME_APPLICATION_NOT_FOUND' ||
271
+ jsonError?.code === 'PLT_RUNTIME_APPLICATION_WORKER_NOT_FOUND'
268
272
  ) {
269
- throw new ServiceNotFound(error)
273
+ throw new ApplicationNotFound(error)
270
274
  }
271
275
 
272
- throw new FailedToGetRuntimeServiceEnv(error)
276
+ throw new FailedToGetRuntimeApplicationEnv(error)
273
277
  }
274
278
 
275
- const serviceConfig = await body.json()
276
- return serviceConfig
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
+
329
+ if (statusCode !== 200) {
330
+ const error = await body.text()
331
+ let jsonError
332
+ try {
333
+ jsonError = JSON.parse(error)
334
+ } catch {
335
+ // No-op
336
+ }
337
+
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)
343
+ }
344
+
345
+ if (code === 'PLT_PPROF_PROFILING_NOT_STARTED') {
346
+ throw new ProfilingNotStarted(applicationId)
347
+ }
348
+
349
+ throw new FailedToStopProfiling(applicationId, message)
350
+ }
351
+
352
+ // Return the binary profile data as ArrayBuffer
353
+ return await body.arrayBuffer()
277
354
  }
278
355
 
279
356
  async reloadRuntime (pid, options = {}) {
@@ -429,11 +506,11 @@ export class RuntimeApiClient {
429
506
  return result.indexes
430
507
  }
431
508
 
432
- async injectRuntime (pid, serviceId, options) {
509
+ async injectRuntime (pid, applicationId, options) {
433
510
  const client = this.#getUndiciClient(pid)
434
511
 
435
512
  const response = await client.request({
436
- path: `/api/v1/services/${serviceId}/proxy` + options.url,
513
+ path: `/api/v1/applications/${applicationId}/proxy` + options.url,
437
514
  method: options.method,
438
515
  headers: options.headers,
439
516
  query: options.query,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "3.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.8",
4
4
  "description": "Platformatic Control",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -16,15 +16,15 @@
16
16
  },
17
17
  "homepage": "https://github.com/platformatic/platformatic#readme",
18
18
  "devDependencies": {
19
- "borp": "^0.20.0",
19
+ "cleaner-spec-reporter": "^0.5.0",
20
20
  "eslint": "9",
21
21
  "execa": "^9.0.0",
22
22
  "neostandard": "^0.12.0",
23
23
  "split2": "^4.2.0",
24
- "tsd": "^0.32.0",
24
+ "tsd": "^0.33.0",
25
25
  "typescript": "^5.5.4",
26
- "@platformatic/service": "3.0.0-alpha.5",
27
- "@platformatic/runtime": "3.0.0-alpha.5"
26
+ "@platformatic/service": "3.0.0-alpha.8",
27
+ "@platformatic/runtime": "3.0.0-alpha.8"
28
28
  },
29
29
  "dependencies": {
30
30
  "@fastify/error": "^4.0.0",
@@ -34,14 +34,14 @@
34
34
  "table": "^6.8.1",
35
35
  "undici": "^7.0.0",
36
36
  "ws": "^8.16.0",
37
- "@platformatic/foundation": "3.0.0-alpha.5"
37
+ "@platformatic/foundation": "3.0.0-alpha.8"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=22.18.0"
41
41
  },
42
42
  "scripts": {
43
- "test": "pnpm run lint && pnpm run unit && tsd --files test/index.test-d.ts",
44
- "unit": "borp --concurrency=1 --timeout=1200000",
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
  }