@platformatic/itc 3.54.0 → 3.56.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/lib/index.d.ts CHANGED
@@ -32,6 +32,7 @@ export class ITC extends EventEmitter {
32
32
 
33
33
  send (name: string, message: any, options?: Record<string, any>): Promise<any>
34
34
  notify (name: string, message: any, options?: Record<string, any>): void
35
+ process (name: string, message: any, context?: Record<string, any>): Promise<any>
35
36
  handle (message: string, handler: Handler): void
36
37
  getHandler (message: string): Handler | undefined
37
38
  listen (): void
package/lib/index.js CHANGED
@@ -332,6 +332,14 @@ export class ITC extends EventEmitter {
332
332
  this._send(generateNotification(name, message, options?.meta), options)
333
333
  }
334
334
 
335
+ async process (name, message, context) {
336
+ const request = generateRequest(name, message, context?.meta)
337
+ const { error, data } = await this.#dispatchRequest(request, context)
338
+
339
+ if (error !== null) throw error
340
+ return data
341
+ }
342
+
335
343
  handle (message, handler) {
336
344
  this.#handlers.set(message, handler)
337
345
  }
@@ -399,6 +407,16 @@ export class ITC extends EventEmitter {
399
407
  }
400
408
 
401
409
  async #handleRequest (raw, context) {
410
+ const response = await this.#dispatchRequest(raw, context)
411
+
412
+ this._send(response, context)
413
+
414
+ if (this.#closeAfterCurrentRequest) {
415
+ this.close()
416
+ }
417
+ }
418
+
419
+ async #dispatchRequest (raw, context) {
402
420
  let request = null
403
421
  let handler = null
404
422
  let response = null
@@ -436,11 +454,7 @@ export class ITC extends EventEmitter {
436
454
  this.#handling = false
437
455
  }
438
456
 
439
- this._send(response, context)
440
-
441
- if (this.#closeAfterCurrentRequest) {
442
- this.close()
443
- }
457
+ return response
444
458
  }
445
459
 
446
460
  #handleResponse (response, context) {
package/lib/telemetry.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ROOT_CONTEXT, SpanKind, SpanStatusCode, context, propagation, trace } from '@opentelemetry/api'
2
+ import { getTelemetryReady, getTracerProvider } from '@platformatic/globals'
2
3
 
3
4
  let tracer = null
4
5
  let telemetryInitialization = null
@@ -67,7 +68,7 @@ function getTracer () {
67
68
  return tracer
68
69
  }
69
70
 
70
- const tracerProvider = globalThis.platformatic?.tracerProvider
71
+ const tracerProvider = getTracerProvider({ throwOnMissing: false })
71
72
  if (!tracerProvider) {
72
73
  return null
73
74
  }
@@ -81,7 +82,7 @@ export function initializeITCTelemetry () {
81
82
  return telemetryInitialization
82
83
  }
83
84
 
84
- telemetryInitialization = Promise.resolve(globalThis.platformatic?.telemetryReady)
85
+ telemetryInitialization = Promise.resolve(getTelemetryReady({ throwOnMissing: false }))
85
86
  .catch(() => {
86
87
  // Ignore telemetry initialization failures and fall back to untraced messaging.
87
88
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/itc",
3
- "version": "3.54.0",
3
+ "version": "3.56.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -26,7 +26,8 @@
26
26
  "dependencies": {
27
27
  "@fastify/error": "^4.0.0",
28
28
  "@opentelemetry/api": "^1.9.0",
29
- "@watchable/unpromise": "^1.0.2"
29
+ "@watchable/unpromise": "^1.0.2",
30
+ "@platformatic/globals": "3.56.0"
30
31
  },
31
32
  "engines": {
32
33
  "node": ">=22.19.0"