@naturalcycles/backend-lib 4.4.0 → 4.4.3

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.
@@ -19,7 +19,7 @@ export declare class HttpDB extends BaseCommonDB implements CommonDB {
19
19
  getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
20
20
  runQuery<ROW extends ObjectWithId>(query: DBQuery<ROW>, opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
21
21
  runQueryCount<ROW extends ObjectWithId>(query: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>;
22
- saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions): Promise<void>;
22
+ saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
23
23
  deleteByIds(table: string, ids: string[], opt?: CommonDBOptions): Promise<number>;
24
24
  deleteByQuery<ROW extends ObjectWithId>(query: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>;
25
25
  streamQuery<ROW extends ObjectWithId>(_q: DBQuery<ROW>, _opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
@@ -1,6 +1,5 @@
1
1
  import { CommonLogger } from '@naturalcycles/js-lib';
2
- import { Severity } from '@sentry/node';
3
- import type { Breadcrumb, NodeOptions } from '@sentry/node';
2
+ import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node';
4
3
  import type * as SentryLib from '@sentry/node';
5
4
  import { BackendErrorRequestHandler, BackendRequestHandler } from '../index';
6
5
  export interface SentrySharedServiceCfg extends NodeOptions {
@@ -34,7 +33,7 @@ export declare class SentrySharedService {
34
33
  /**
35
34
  * Returns "eventId"
36
35
  */
37
- captureMessage(msg: string, level?: Severity): string;
36
+ captureMessage(msg: string, level?: SeverityLevel): string;
38
37
  addBreadcrumb(breadcrumb: Breadcrumb): void;
39
38
  /**
40
39
  * Currently it will only use `logger.error` ("error" level) and ignore `log` and `warn`.
@@ -4,16 +4,14 @@ exports.SentrySharedService = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
7
- const node_1 = require("@sentry/node");
8
7
  const index_1 = require("../index");
9
8
  const sentrySeverityMap = {
10
- [node_1.Severity.Debug]: 'log',
11
- [node_1.Severity.Log]: 'log',
12
- [node_1.Severity.Info]: 'log',
13
- [node_1.Severity.Warning]: 'warn',
14
- [node_1.Severity.Error]: 'error',
15
- [node_1.Severity.Critical]: 'error',
16
- [node_1.Severity.Fatal]: 'error',
9
+ debug: 'log',
10
+ info: 'log',
11
+ log: 'log',
12
+ warning: 'warn',
13
+ error: 'error',
14
+ fatal: 'error',
17
15
  };
18
16
  class SentrySharedService {
19
17
  constructor(sentryServiceCfg) {
@@ -35,8 +35,6 @@ function getServerStatusData(projectDir = process.cwd(), extra) {
35
35
  }
36
36
  exports.getServerStatusData = getServerStatusData;
37
37
  function getStartedStr() {
38
- const serverStarted = (0, js_lib_1.localTime)().subtract(process.uptime(), 'second');
39
- const s1 = serverStarted.toPretty();
40
- const s2 = (0, js_lib_1._ms)(Date.now() - serverStarted.unix() * 1000);
41
- return `${s1} (${s2} ago)`;
38
+ const started = (0, js_lib_1.localTime)().subtract(process.uptime(), 'second');
39
+ return `${started.toPretty()} (${started.fromNow()})`;
42
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "4.4.0",
3
+ "version": "4.4.3",
4
4
  "scripts": {
5
5
  "prepare": "husky install && patch-package",
6
6
  "serve": "APP_ENV=dev nodemon",
@@ -13,7 +13,7 @@
13
13
  "deploy-health-check-debug2": "yarn tsn ./src/bin/deploy-health-check.ts --url https://api-master2.naturalcycles.com --thresholdUnhealthy 5"
14
14
  },
15
15
  "peerDependencies": {
16
- "@sentry/node": "^6.5.1"
16
+ "@sentry/node": "^7.0.0"
17
17
  },
18
18
  "dependencies": {
19
19
  "@naturalcycles/db-lib": "^8.0.2",
@@ -40,13 +40,12 @@
40
40
  "devDependencies": {
41
41
  "@naturalcycles/bench-lib": "^1.0.7",
42
42
  "@naturalcycles/dev-lib": "^12.0.3",
43
- "@sentry/node": "^6.5.1",
43
+ "@sentry/node": "^7.0.0",
44
44
  "@types/ejs": "^3.0.0",
45
45
  "@types/js-yaml": "^4.0.0",
46
46
  "@types/node": "^17.0.0",
47
- "esbuild-register": "^3.1.2",
48
47
  "fastify": "^3.20.1",
49
- "jest": "^27.0.1",
48
+ "jest": "^28.0.3",
50
49
  "nodemon": "^2.0.14",
51
50
  "patch-package": "^6.2.1",
52
51
  "prettier": "^2.0.0",
package/src/db/httpDB.ts CHANGED
@@ -92,10 +92,10 @@ export class HttpDB extends BaseCommonDB implements CommonDB {
92
92
  .json()
93
93
  }
94
94
 
95
- override async saveBatch<ROW extends ObjectWithId>(
95
+ override async saveBatch<ROW extends Partial<ObjectWithId>>(
96
96
  table: string,
97
97
  rows: ROW[],
98
- opt?: CommonDBSaveOptions,
98
+ opt?: CommonDBSaveOptions<ROW>,
99
99
  ): Promise<void> {
100
100
  await this.got.put(`saveBatch`, {
101
101
  json: {
@@ -1,20 +1,18 @@
1
1
  import { _anyToError, _Memo, CommonLogger, CommonLogLevel } from '@naturalcycles/js-lib'
2
2
  import { inspectAny, inspectAnyStringifyFn } from '@naturalcycles/nodejs-lib'
3
- import { Severity } from '@sentry/node'
4
- import type { Breadcrumb, NodeOptions } from '@sentry/node'
3
+ import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
5
4
  import type * as SentryLib from '@sentry/node'
6
5
  import { BackendErrorRequestHandler, BackendRequestHandler, getRequestLogger } from '../index'
7
6
 
8
7
  export interface SentrySharedServiceCfg extends NodeOptions {}
9
8
 
10
- const sentrySeverityMap: Record<Severity, CommonLogLevel> = {
11
- [Severity.Debug]: 'log',
12
- [Severity.Log]: 'log',
13
- [Severity.Info]: 'log',
14
- [Severity.Warning]: 'warn',
15
- [Severity.Error]: 'error',
16
- [Severity.Critical]: 'error',
17
- [Severity.Fatal]: 'error',
9
+ const sentrySeverityMap: Record<SeverityLevel, CommonLogLevel> = {
10
+ debug: 'log',
11
+ info: 'log',
12
+ log: 'log',
13
+ warning: 'warn',
14
+ error: 'error',
15
+ fatal: 'error',
18
16
  }
19
17
 
20
18
  export class SentrySharedService {
@@ -106,7 +104,7 @@ export class SentrySharedService {
106
104
  /**
107
105
  * Returns "eventId"
108
106
  */
109
- captureMessage(msg: string, level?: Severity): string {
107
+ captureMessage(msg: string, level?: SeverityLevel): string {
110
108
  getRequestLogger()[sentrySeverityMap[level!] || 'log']('captureMessage:', msg)
111
109
  return this.sentry().captureMessage(msg, level)
112
110
  }
@@ -61,7 +61,7 @@ export function bodyParserTimeoutMiddleware(
61
61
  */
62
62
  export function clearBodyParserTimeout(): BackendRequestHandler {
63
63
  return (req, res, next) => {
64
- clearTimeout(req.bodyParserTimeout!)
64
+ clearTimeout(req.bodyParserTimeout)
65
65
  next()
66
66
  }
67
67
  }
@@ -72,7 +72,7 @@ export function requestTimeoutMiddleware(
72
72
  )
73
73
  }, timeoutSeconds * 1000)
74
74
 
75
- onFinished(res, () => clearTimeout(req.requestTimeout!))
75
+ onFinished(res, () => clearTimeout(req.requestTimeout))
76
76
 
77
77
  next()
78
78
  }
@@ -110,7 +110,7 @@ export function customRequestTimeoutMiddleware(
110
110
  }
111
111
  }, timeoutSeconds * 1000)
112
112
 
113
- onFinished(res, () => clearTimeout(req.requestTimeout!))
113
+ onFinished(res, () => clearTimeout(req.requestTimeout))
114
114
 
115
115
  next()
116
116
  }
@@ -1,4 +1,4 @@
1
- import { _filterFalsyValues, _ms, localTime } from '@naturalcycles/js-lib'
1
+ import { _filterFalsyValues, localTime } from '@naturalcycles/js-lib'
2
2
  import { memoryUsageFull, processSharedUtil } from '@naturalcycles/nodejs-lib'
3
3
  import { getDeployInfo } from './deployInfo.util'
4
4
  import { BackendRequestHandler } from './server.model'
@@ -39,9 +39,6 @@ export function getServerStatusData(
39
39
  }
40
40
 
41
41
  function getStartedStr(): string {
42
- const serverStarted = localTime().subtract(process.uptime(), 'second')
43
-
44
- const s1 = serverStarted.toPretty()
45
- const s2 = _ms(Date.now() - serverStarted.unix() * 1000)
46
- return `${s1} (${s2} ago)`
42
+ const started = localTime().subtract(process.uptime(), 'second')
43
+ return `${started.toPretty()} (${started.fromNow()})`
47
44
  }