@canmingir/link-express 1.6.6 → 1.6.9

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,9 +1,64 @@
1
- name: publish
1
+ name: Publish NPM Package
2
+
2
3
  on:
3
- push:
4
- tags:
5
- - v[0-9]+.[0-9]+.[0-9]+
4
+ workflow_dispatch:
5
+ inputs:
6
+ version_type:
7
+ description: 'Version bump type'
8
+ required: true
9
+ default: 'patch'
10
+ type: choice
11
+ options:
12
+ - patch
13
+ - minor
14
+ - major
15
+ release:
16
+ types: [created]
17
+
6
18
  jobs:
7
- deploy:
8
- uses: NucleoidAI/actions/.github/workflows/publish.yml@main
9
- secrets: inherit
19
+ publish:
20
+ runs-on: ubuntu-latest
21
+ permissions:
22
+ contents: write
23
+ id-token: write
24
+
25
+ steps:
26
+ - name: Checkout code
27
+ uses: actions/checkout@v4
28
+ with:
29
+ token: ${{ secrets.PAT_TOKEN }}
30
+
31
+ - name: Setup Node.js
32
+ uses: actions/setup-node@v4
33
+ with:
34
+ node-version: '20'
35
+ registry-url: 'https://registry.npmjs.org'
36
+
37
+ - name: Configure Git
38
+ run: |
39
+ git config user.name "github-actions[bot]"
40
+ git config user.email "github-actions[bot]@users.noreply.github.com"
41
+
42
+ - name: Install dependencies
43
+ run: npm ci
44
+
45
+ - name: Bump version
46
+ id: version_bump
47
+ run: |
48
+ npm version ${{ github.event.inputs.version_type }} -m "Bump version to %s [skip ci]"
49
+ echo "new_version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
50
+ git push --follow-tags
51
+
52
+ - name: Publish to NPM
53
+ id: npm_publish
54
+ run: npm publish --access public
55
+ env:
56
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
57
+
58
+ - name: Revert version bump on failure
59
+ if: failure() && steps.version_bump.outcome == 'success'
60
+ run: |
61
+ git reset --hard HEAD~1
62
+ git tag -d v${{ steps.version_bump.outputs.new_version }}
63
+ git push --force
64
+ git push --delete origin v${{ steps.version_bump.outputs.new_version }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canmingir/link-express",
3
- "version": "1.6.6",
3
+ "version": "1.6.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "NucTeam",
@@ -43,11 +43,11 @@ class DBMetrics {
43
43
  return this.dbWriteLatency.startTimer();
44
44
  }
45
45
 
46
- startPushgateway(config = {}) {
46
+ startPushgateway(metrics = {}) {
47
47
  this.pushgatewayConfig = {
48
- url: config.url || "http://localhost:9091",
49
- jobName: config.jobName || "api",
50
- instance: config.instance || "database",
48
+ url: metrics.url || "http://localhost:9091",
49
+ jobName: metrics.pushGateway.jobName || "api",
50
+ instance: metrics.pushGateway.instance || "database",
51
51
  interval: config.interval || 15000,
52
52
  };
53
53
 
package/src/postgres.js CHANGED
@@ -8,12 +8,15 @@ const { DBMetrics } = require("./metrics/dbMetrics");
8
8
  const {
9
9
  postgres: { uri, debug = false, sync },
10
10
  project,
11
- pushGateway,
11
+ metrics,
12
12
  } = config();
13
13
 
14
- const metrics = new DBMetrics();
14
+ let dbMetrics = null;
15
15
 
16
- metrics.startPushgateway(pushGateway);
16
+ if (metrics.enabled) {
17
+ dbMetrics = new DBMetrics();
18
+ dbMetrics.startPushgateway(metrics);
19
+ }
17
20
 
18
21
  const originalDestroy = Model.prototype.destroy;
19
22
 
@@ -32,91 +35,93 @@ const sequelize = new Sequelize(process.env.PG || uri, {
32
35
  timestamps: false,
33
36
  paranoid: false,
34
37
  },
35
- hooks: {
36
- beforeFind: (options = {}) => {
37
- const timer = metrics.dbReadLatency.startTimer();
38
- options.metricsTimer = timer;
39
- options.metricsType = "read";
40
- },
41
- afterFind: (result, options = {}) => {
42
- if (options?.metricsTimer) {
43
- options.metricsTimer();
44
- metrics.dbReadOps.inc();
45
- }
46
- },
47
-
48
- beforeCreate: (instance, options = {}) => {
49
- const timer = metrics.dbWriteLatency.startTimer();
50
- options.metricsTimer = timer;
51
- options.metricsType = "write";
52
- },
53
- afterCreate: (instance, options = {}) => {
54
- if (options?.metricsTimer) {
55
- options.metricsTimer();
56
- metrics.dbWriteOps.inc();
57
- }
58
- },
59
-
60
- beforeUpdate: (instance, options = {}) => {
61
- const timer = metrics.dbWriteLatency.startTimer();
62
- options.metricsTimer = timer;
63
- options.metricsType = "write";
64
- },
65
- afterUpdate: (instance, options = {}) => {
66
- if (options?.metricsTimer) {
67
- options.metricsTimer();
68
- metrics.dbWriteOps.inc();
69
- }
70
- },
71
-
72
- beforeDestroy: (instance, options = {}) => {
73
- const timer = metrics.dbWriteLatency.startTimer();
74
- options.metricsTimer = timer;
75
- options.metricsType = "write";
76
- },
77
- afterDestroy: (instance, options = {}) => {
78
- if (options?.metricsTimer) {
79
- options.metricsTimer();
80
- metrics.dbWriteOps.inc();
38
+ hooks: metrics.enabled
39
+ ? {
40
+ beforeFind: (options = {}) => {
41
+ const timer = dbMetrics.dbReadLatency.startTimer();
42
+ options.metricsTimer = timer;
43
+ options.metricsType = "read";
44
+ },
45
+ afterFind: (result, options = {}) => {
46
+ if (options?.metricsTimer) {
47
+ options.metricsTimer();
48
+ dbMetrics.dbReadOps.inc();
49
+ }
50
+ },
51
+
52
+ beforeCreate: (instance, options = {}) => {
53
+ const timer = dbMetrics.dbWriteLatency.startTimer();
54
+ options.metricsTimer = timer;
55
+ options.metricsType = "write";
56
+ },
57
+ afterCreate: (instance, options = {}) => {
58
+ if (options?.metricsTimer) {
59
+ options.metricsTimer();
60
+ dbMetrics.dbWriteOps.inc();
61
+ }
62
+ },
63
+
64
+ beforeUpdate: (instance, options = {}) => {
65
+ const timer = dbMetrics.dbWriteLatency.startTimer();
66
+ options.metricsTimer = timer;
67
+ options.metricsType = "write";
68
+ },
69
+ afterUpdate: (instance, options = {}) => {
70
+ if (options?.metricsTimer) {
71
+ options.metricsTimer();
72
+ dbMetrics.dbWriteOps.inc();
73
+ }
74
+ },
75
+
76
+ beforeDestroy: (instance, options = {}) => {
77
+ const timer = dbMetrics.dbWriteLatency.startTimer();
78
+ options.metricsTimer = timer;
79
+ options.metricsType = "write";
80
+ },
81
+ afterDestroy: (instance, options = {}) => {
82
+ if (options?.metricsTimer) {
83
+ options.metricsTimer();
84
+ dbMetrics.dbWriteOps.inc();
85
+ }
86
+ },
87
+
88
+ beforeBulkCreate: (instances, options = {}) => {
89
+ const timer = dbMetrics.dbWriteLatency.startTimer();
90
+ options.metricsTimer = timer;
91
+ options.metricsType = "write";
92
+ },
93
+ afterBulkCreate: (instances, options = {}) => {
94
+ if (options?.metricsTimer) {
95
+ options.metricsTimer();
96
+ dbMetrics.dbWriteOps.inc(instances.length || 1);
97
+ }
98
+ },
99
+
100
+ beforeBulkUpdate: (instances, options = {}) => {
101
+ const timer = dbMetrics.dbWriteLatency.startTimer();
102
+ options.metricsTimer = timer;
103
+ options.metricsType = "write";
104
+ },
105
+ afterBulkUpdate: (instances, options = {}) => {
106
+ if (options?.metricsTimer) {
107
+ options.metricsTimer();
108
+ dbMetrics.dbWriteOps.inc(instances.length || 1);
109
+ }
110
+ },
111
+
112
+ beforeBulkDestroy: (options = {}) => {
113
+ const timer = dbMetrics.dbWriteLatency.startTimer();
114
+ options.metricsTimer = timer;
115
+ options.metricsType = "write";
116
+ },
117
+ afterBulkDestroy: (options = {}) => {
118
+ if (options?.metricsTimer) {
119
+ options.metricsTimer();
120
+ dbMetrics.dbWriteOps.inc(1);
121
+ }
122
+ },
81
123
  }
82
- },
83
-
84
- beforeBulkCreate: (instances, options = {}) => {
85
- const timer = metrics.dbWriteLatency.startTimer();
86
- options.metricsTimer = timer;
87
- options.metricsType = "write";
88
- },
89
- afterBulkCreate: (instances, options = {}) => {
90
- if (options?.metricsTimer) {
91
- options.metricsTimer();
92
- metrics.dbWriteOps.inc(instances.length || 1);
93
- }
94
- },
95
-
96
- beforeBulkUpdate: (instances, options = {}) => {
97
- const timer = metrics.dbWriteLatency.startTimer();
98
- options.metricsTimer = timer;
99
- options.metricsType = "write";
100
- },
101
- afterBulkUpdate: (instances, options = {}) => {
102
- if (options?.metricsTimer) {
103
- options.metricsTimer();
104
- metrics.dbWriteOps.inc(instances.length || 1);
105
- }
106
- },
107
-
108
- beforeBulkDestroy: (options = {}) => {
109
- const timer = metrics.dbWriteLatency.startTimer();
110
- options.metricsTimer = timer;
111
- options.metricsType = "write";
112
- },
113
- afterBulkDestroy: (options = {}) => {
114
- if (options?.metricsTimer) {
115
- options.metricsTimer();
116
- metrics.dbWriteOps.inc(1);
117
- }
118
- },
119
- },
124
+ : {},
120
125
  });
121
126
 
122
127
  const seed = async () => {