@promster/fastify 7.0.6 → 8.0.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.
@@ -1,10 +1,8 @@
1
- /// <reference types="node" />
2
- import type { TPromsterOptions } from '@promster/types';
3
1
  import type { TRequestRecorder } from '@promster/metrics';
4
- import { FastifyRequest } from 'fastify';
2
+ import type { FastifyInstance, FastifyRequest } from 'fastify';
5
3
  declare const extractPath: (req: FastifyRequest) => string;
6
4
  declare const getRequestRecorder: () => TRequestRecorder;
7
5
  declare const signalIsUp: () => void;
8
6
  declare const signalIsNotUp: () => void;
9
- declare const plugin: import("fastify").FastifyPluginAsync<TPromsterOptions, import("http").Server>;
7
+ declare const plugin: (fastify: FastifyInstance, options: TPromsterOptions) => Promise<void>;
10
8
  export { plugin, getRequestRecorder, signalIsUp, signalIsNotUp, extractPath };
@@ -13,7 +13,7 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
13
13
 
14
14
  var pkg = {
15
15
  name: "@promster/fastify",
16
- version: "7.0.6",
16
+ version: "8.0.0",
17
17
  description: "Fastify server integrations of promster",
18
18
  main: "dist/promster-fastify.cjs.js",
19
19
  typings: "dist/promster-fastify.cjs.d.ts",
@@ -29,8 +29,8 @@ var pkg = {
29
29
  access: "public"
30
30
  },
31
31
  engines: {
32
- node: ">=14",
33
- npm: ">=6"
32
+ node: ">=16",
33
+ npm: ">=8"
34
34
  },
35
35
  repository: {
36
36
  type: "git",
@@ -49,44 +49,39 @@ var pkg = {
49
49
  "prometheus"
50
50
  ],
51
51
  dependencies: {
52
- "@promster/metrics": "^9.1.5",
53
- "fastify-plugin": "^3.0.1",
52
+ "@promster/metrics": "^10.0.0",
53
+ "fastify-plugin": "^4.4.0",
54
54
  "merge-options": "3.0.4",
55
- "parse-prometheus-text-format": "1.1.1"
55
+ "parse-prometheus-text-format": "1.1.1",
56
+ "@promster/server": "workspace:*"
56
57
  },
57
58
  devDependencies: {
58
- fastify: "3.27.4"
59
+ fastify: "4.21.0"
59
60
  }
60
61
  };
61
62
 
62
63
  let recordRequest;
63
64
  let upMetric;
64
-
65
- const extractPath = req => // @ts-expect-error
65
+ const extractPath = req =>
66
+ // @ts-expect-error
66
67
  req.raw.originalUrl || req.raw.url;
67
-
68
68
  const getRequestRecorder = () => recordRequest;
69
-
70
69
  const signalIsUp = () => {
71
70
  if (!upMetric) {
72
71
  return;
73
72
  }
74
-
75
73
  upMetric.forEach(upMetricType => {
76
74
  upMetricType.set(1);
77
75
  });
78
76
  };
79
-
80
77
  const signalIsNotUp = () => {
81
78
  if (!upMetric) {
82
79
  return;
83
80
  }
84
-
85
81
  upMetric.forEach(upMetricType => {
86
82
  upMetricType.set(0);
87
83
  });
88
84
  };
89
-
90
85
  const createPlugin = async (fastify, options) => {
91
86
  const allDefaultedOptions = merge__default["default"](metrics.createHttpMetrics.defaultOptions, metrics.createGcMetrics.defaultOptions, metrics.createRequestRecorder.defaultOptions, metrics.createGcObserver.defaultOptions, metrics.defaultNormalizers, options);
92
87
  const shouldSkipMetricsByEnvironment = metrics.skipMetricsInEnvironment(allDefaultedOptions);
@@ -95,14 +90,12 @@ const createPlugin = async (fastify, options) => {
95
90
  const observeGc = metrics.createGcObserver(gcMetrics, allDefaultedOptions);
96
91
  recordRequest = metrics.createRequestRecorder(httpMetrics, allDefaultedOptions);
97
92
  upMetric = gcMetrics === null || gcMetrics === void 0 ? void 0 : gcMetrics.up;
98
-
99
93
  if (!shouldSkipMetricsByEnvironment) {
100
94
  observeGc();
101
95
  }
102
-
103
96
  fastify.decorate('Prometheus', metrics.Prometheus);
104
- fastify.decorate('recordRequest', recordRequest); // eslint-disable-next-line @typescript-eslint/ban-types
105
-
97
+ fastify.decorate('recordRequest', recordRequest);
98
+ // eslint-disable-next-line @typescript-eslint/ban-types
106
99
  fastify.decorateRequest('__promsterTiming__', null);
107
100
  fastify.addHook('onRequest', async (request, _) => {
108
101
  // @ts-expect-error
@@ -110,7 +103,6 @@ const createPlugin = async (fastify, options) => {
110
103
  });
111
104
  fastify.addHook('onResponse', async (request, reply) => {
112
105
  var _request$raw$method, _allDefaultedOptions$, _request$headers$cont, _reply$getHeader, _allDefaultedOptions$2;
113
-
114
106
  const labels = Object.assign({}, {
115
107
  method: allDefaultedOptions.normalizeMethod((_request$raw$method = request.raw.method) !== null && _request$raw$method !== void 0 ? _request$raw$method : '', {
116
108
  req: request,
@@ -128,7 +120,6 @@ const createPlugin = async (fastify, options) => {
128
120
  const requestContentLength = Number((_request$headers$cont = request.headers['content-length']) !== null && _request$headers$cont !== void 0 ? _request$headers$cont : 0);
129
121
  const responseContentLength = Number((_reply$getHeader = reply.getHeader('content-length')) !== null && _reply$getHeader !== void 0 ? _reply$getHeader : 0);
130
122
  const shouldSkipByRequest = (_allDefaultedOptions$2 = allDefaultedOptions.skip) === null || _allDefaultedOptions$2 === void 0 ? void 0 : _allDefaultedOptions$2.call(allDefaultedOptions, request, reply, labels);
131
-
132
123
  if (!shouldSkipByRequest && !shouldSkipMetricsByEnvironment) {
133
124
  // @ts-expect-error
134
125
  recordRequest(request.__promsterTiming__, {
@@ -139,7 +130,6 @@ const createPlugin = async (fastify, options) => {
139
130
  }
140
131
  });
141
132
  };
142
-
143
133
  const plugin = fastifyPlugin__default["default"](createPlugin, {
144
134
  fastify: '>= 1.6.0',
145
135
  name: pkg.name
@@ -13,7 +13,7 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
13
13
 
14
14
  var pkg = {
15
15
  name: "@promster/fastify",
16
- version: "7.0.6",
16
+ version: "8.0.0",
17
17
  description: "Fastify server integrations of promster",
18
18
  main: "dist/promster-fastify.cjs.js",
19
19
  typings: "dist/promster-fastify.cjs.d.ts",
@@ -29,8 +29,8 @@ var pkg = {
29
29
  access: "public"
30
30
  },
31
31
  engines: {
32
- node: ">=14",
33
- npm: ">=6"
32
+ node: ">=16",
33
+ npm: ">=8"
34
34
  },
35
35
  repository: {
36
36
  type: "git",
@@ -49,44 +49,39 @@ var pkg = {
49
49
  "prometheus"
50
50
  ],
51
51
  dependencies: {
52
- "@promster/metrics": "^9.1.5",
53
- "fastify-plugin": "^3.0.1",
52
+ "@promster/metrics": "^10.0.0",
53
+ "fastify-plugin": "^4.4.0",
54
54
  "merge-options": "3.0.4",
55
- "parse-prometheus-text-format": "1.1.1"
55
+ "parse-prometheus-text-format": "1.1.1",
56
+ "@promster/server": "workspace:*"
56
57
  },
57
58
  devDependencies: {
58
- fastify: "3.27.4"
59
+ fastify: "4.21.0"
59
60
  }
60
61
  };
61
62
 
62
63
  let recordRequest;
63
64
  let upMetric;
64
-
65
- const extractPath = req => // @ts-expect-error
65
+ const extractPath = req =>
66
+ // @ts-expect-error
66
67
  req.raw.originalUrl || req.raw.url;
67
-
68
68
  const getRequestRecorder = () => recordRequest;
69
-
70
69
  const signalIsUp = () => {
71
70
  if (!upMetric) {
72
71
  return;
73
72
  }
74
-
75
73
  upMetric.forEach(upMetricType => {
76
74
  upMetricType.set(1);
77
75
  });
78
76
  };
79
-
80
77
  const signalIsNotUp = () => {
81
78
  if (!upMetric) {
82
79
  return;
83
80
  }
84
-
85
81
  upMetric.forEach(upMetricType => {
86
82
  upMetricType.set(0);
87
83
  });
88
84
  };
89
-
90
85
  const createPlugin = async (fastify, options) => {
91
86
  const allDefaultedOptions = merge__default["default"](metrics.createHttpMetrics.defaultOptions, metrics.createGcMetrics.defaultOptions, metrics.createRequestRecorder.defaultOptions, metrics.createGcObserver.defaultOptions, metrics.defaultNormalizers, options);
92
87
  const shouldSkipMetricsByEnvironment = metrics.skipMetricsInEnvironment(allDefaultedOptions);
@@ -95,14 +90,12 @@ const createPlugin = async (fastify, options) => {
95
90
  const observeGc = metrics.createGcObserver(gcMetrics, allDefaultedOptions);
96
91
  recordRequest = metrics.createRequestRecorder(httpMetrics, allDefaultedOptions);
97
92
  upMetric = gcMetrics === null || gcMetrics === void 0 ? void 0 : gcMetrics.up;
98
-
99
93
  if (!shouldSkipMetricsByEnvironment) {
100
94
  observeGc();
101
95
  }
102
-
103
96
  fastify.decorate('Prometheus', metrics.Prometheus);
104
- fastify.decorate('recordRequest', recordRequest); // eslint-disable-next-line @typescript-eslint/ban-types
105
-
97
+ fastify.decorate('recordRequest', recordRequest);
98
+ // eslint-disable-next-line @typescript-eslint/ban-types
106
99
  fastify.decorateRequest('__promsterTiming__', null);
107
100
  fastify.addHook('onRequest', async (request, _) => {
108
101
  // @ts-expect-error
@@ -110,7 +103,6 @@ const createPlugin = async (fastify, options) => {
110
103
  });
111
104
  fastify.addHook('onResponse', async (request, reply) => {
112
105
  var _request$raw$method, _allDefaultedOptions$, _request$headers$cont, _reply$getHeader, _allDefaultedOptions$2;
113
-
114
106
  const labels = Object.assign({}, {
115
107
  method: allDefaultedOptions.normalizeMethod((_request$raw$method = request.raw.method) !== null && _request$raw$method !== void 0 ? _request$raw$method : '', {
116
108
  req: request,
@@ -128,7 +120,6 @@ const createPlugin = async (fastify, options) => {
128
120
  const requestContentLength = Number((_request$headers$cont = request.headers['content-length']) !== null && _request$headers$cont !== void 0 ? _request$headers$cont : 0);
129
121
  const responseContentLength = Number((_reply$getHeader = reply.getHeader('content-length')) !== null && _reply$getHeader !== void 0 ? _reply$getHeader : 0);
130
122
  const shouldSkipByRequest = (_allDefaultedOptions$2 = allDefaultedOptions.skip) === null || _allDefaultedOptions$2 === void 0 ? void 0 : _allDefaultedOptions$2.call(allDefaultedOptions, request, reply, labels);
131
-
132
123
  if (!shouldSkipByRequest && !shouldSkipMetricsByEnvironment) {
133
124
  // @ts-expect-error
134
125
  recordRequest(request.__promsterTiming__, {
@@ -139,7 +130,6 @@ const createPlugin = async (fastify, options) => {
139
130
  }
140
131
  });
141
132
  };
142
-
143
133
  const plugin = fastifyPlugin__default["default"](createPlugin, {
144
134
  fastify: '>= 1.6.0',
145
135
  name: pkg.name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promster/fastify",
3
- "version": "7.0.6",
3
+ "version": "8.0.0",
4
4
  "description": "Fastify server integrations of promster",
5
5
  "main": "dist/promster-fastify.cjs.js",
6
6
  "typings": "dist/promster-fastify.cjs.d.ts",
@@ -16,8 +16,8 @@
16
16
  "access": "public"
17
17
  },
18
18
  "engines": {
19
- "node": ">=14",
20
- "npm": ">=6"
19
+ "node": ">=16",
20
+ "npm": ">=8"
21
21
  },
22
22
  "repository": {
23
23
  "type": "git",
@@ -36,12 +36,13 @@
36
36
  "prometheus"
37
37
  ],
38
38
  "dependencies": {
39
- "@promster/metrics": "^9.1.5",
40
- "fastify-plugin": "^3.0.1",
39
+ "@promster/metrics": "^10.0.0",
40
+ "fastify-plugin": "^4.4.0",
41
41
  "merge-options": "3.0.4",
42
- "parse-prometheus-text-format": "1.1.1"
42
+ "parse-prometheus-text-format": "1.1.1",
43
+ "@promster/server": "8.0.0"
43
44
  },
44
45
  "devDependencies": {
45
- "fastify": "3.27.4"
46
+ "fastify": "4.21.0"
46
47
  }
47
- }
48
+ }