From 6c82468fa260fd15440c584e70f90b41ef85ecfc Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 16 Apr 2024 07:58:33 +0200 Subject: [PATCH 1/5] fix: correctly get and set top level `contentType` property --- CHANGELOG.md | 4 +++- index.js | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbb8a624..7dc1f5aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,12 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed -- Enable `bun.js` by catching `NotImplemented` error (Fixes [#570](https://github.com/siimon/prom-client/issues/570)) +- Correctly read and set `contentType` top level export ### Added +- Enable `bun.js` by catching `NotImplemented` error (Fixes [#570](https://github.com/siimon/prom-client/issues/570)) + [unreleased]: https://github.com/siimon/prom-client/compare/v15.1.0...HEAD ## [15.1.1] - 2024-03-26 diff --git a/index.js b/index.js index 7f6e167a..2683d481 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,14 @@ exports.register = require('./lib/registry').globalRegistry; exports.Registry = require('./lib/registry'); -exports.contentType = require('./lib/registry').globalRegistry.contentType; +Object.defineProperty(exports, 'contentType', { + configurable: false, + enumerable: true, + get: () => exports.register.contentType, + set: value => { + exports.register.setContentType(value); + }, +}); exports.prometheusContentType = require('./lib/registry').PROMETHEUS_CONTENT_TYPE; exports.openMetricsContentType = From 378366e35e5ba63cdbe73db17bf9a653632f9463 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 16 Apr 2024 08:05:12 +0200 Subject: [PATCH 2/5] types --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 13e0051e..ce016c09 100644 --- a/index.d.ts +++ b/index.d.ts @@ -104,8 +104,8 @@ export type Collector = () => void; export const register: Registry; /** - * HTTP Content-Type for metrics response headers, defaults to Prometheus text - * format. + * HTTP Content-Type for metrics response headers for the default registry, + * defaults to Prometheus text format. */ export const contentType: RegistryContentType; From 801541f372fadfb8b1286fffc27f2fb99cf21f44 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 16 Apr 2024 08:06:51 +0200 Subject: [PATCH 3/5] make registry one readonly --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index ed8d9294..99d12677 100644 --- a/index.d.ts +++ b/index.d.ts @@ -81,7 +81,7 @@ export class Registry { /** * Gets the Content-Type of the metrics for use in the response headers. */ - contentType: RegistryContentType; + readonly contentType: RegistryContentType; /** * Set the content type of a registry. Used to change between Prometheus and From c921cac2078a9b5898ff5b21188a0268ec351ea0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 16 Apr 2024 08:07:48 +0200 Subject: [PATCH 4/5] shorthand over arrow --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2683d481..27680099 100644 --- a/index.js +++ b/index.js @@ -10,8 +10,10 @@ exports.Registry = require('./lib/registry'); Object.defineProperty(exports, 'contentType', { configurable: false, enumerable: true, - get: () => exports.register.contentType, - set: value => { + get() { + return exports.register.contentType; + }, + set(value) { exports.register.setContentType(value); }, }); From f835a70bc408871a735967f8343aeb3199bd3a88 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 16 Apr 2024 08:08:53 +0200 Subject: [PATCH 5/5] reuse export --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 27680099..f78105fc 100644 --- a/index.js +++ b/index.js @@ -17,10 +17,8 @@ Object.defineProperty(exports, 'contentType', { exports.register.setContentType(value); }, }); -exports.prometheusContentType = - require('./lib/registry').PROMETHEUS_CONTENT_TYPE; -exports.openMetricsContentType = - require('./lib/registry').OPENMETRICS_CONTENT_TYPE; +exports.prometheusContentType = exports.Registry.PROMETHEUS_CONTENT_TYPE; +exports.openMetricsContentType = exports.Registry.OPENMETRICS_CONTENT_TYPE; exports.validateMetricName = require('./lib/validation').validateMetricName; exports.Counter = require('./lib/counter');