@naturalcycles/backend-lib 2.60.3 → 2.60.4
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/CHANGELOG.md +7 -0
- package/dist/db/httpDB.d.ts +2 -2
- package/dist/db/httpDBRequestHandler.d.ts +2 -1
- package/dist/index.d.ts +0 -10
- package/dist/server/handlers/reqValidation.mw.js +1 -0
- package/dist/server/handlers/statusHandler.d.ts +2 -7
- package/dist/server/handlers/statusHandler.js +10 -12
- package/dist/server/startServer.js +1 -1
- package/package.json +1 -1
- package/src/db/httpDB.ts +1 -2
- package/src/db/httpDBRequestHandler.ts +1 -1
- package/src/index.ts +0 -11
- package/src/server/handlers/reqValidation.mw.ts +1 -0
- package/src/server/handlers/statusHandler.ts +9 -20
- package/src/server/startServer.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.60.4](https://github.com/NaturalCycles/backend-lib/compare/v2.60.3...v2.60.4) (2021-10-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* deps, use process.uptime in statusHandler ([8d3389d](https://github.com/NaturalCycles/backend-lib/commit/8d3389d8908954af9a375a6d7fb95aefc1b08e5f))
|
|
7
|
+
|
|
1
8
|
## [2.60.3](https://github.com/NaturalCycles/backend-lib/compare/v2.60.2...v2.60.3) (2021-10-15)
|
|
2
9
|
|
|
3
10
|
|
package/dist/db/httpDB.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { JsonSchemaRootObject } from '@naturalcycles/js-lib';
|
|
2
|
-
import { BaseCommonDB, CommonDB, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, DBQuery,
|
|
1
|
+
import { JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
|
+
import { BaseCommonDB, CommonDB, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, DBQuery, RunQueryResult } from '@naturalcycles/db-lib';
|
|
3
3
|
import { GetGotOptions, ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
4
4
|
export interface HttpDBCfg extends GetGotOptions {
|
|
5
5
|
prefixUrl: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CommonDB, CommonDBOptions, CommonDBSaveOptions, DBQuery
|
|
1
|
+
import { CommonDB, CommonDBOptions, CommonDBSaveOptions, DBQuery } from '@naturalcycles/db-lib';
|
|
2
|
+
import { ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
3
|
import { Router } from 'express';
|
|
3
4
|
export interface GetByIdsInput {
|
|
4
5
|
table: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,13 +32,3 @@ import { BackendServer, startServer } from './server/startServer';
|
|
|
32
32
|
import { StartServerCfg, StartServerData } from './server/startServer.model';
|
|
33
33
|
export type { MethodOverrideCfg, SentrySharedServiceCfg, RequestHandlerWithPath, RequestHandlerCfg, DefaultAppCfg, StartServerCfg, StartServerData, EnvSharedServiceCfg, BaseEnv, AdminMiddleware, AdminServiceCfg, AdminInfo, RequireAdminCfg, SecureHeaderMiddlewareCfg, BodyParserTimeoutCfg, RequestTimeoutCfg, SimpleRequestLoggerCfg, ReqValidationOptions, };
|
|
34
34
|
export { BackendServer, SentrySharedService, EnvSharedService, reqValidation, notFoundHandler, genericErrorHandler, methodOverride, sentryErrorHandler, createDefaultApp, startServer, catchWrapper, getDefaultRouter, isGAE, statusHandler, statusHandlerData, okHandler, getDeployInfo, onFinished, respondWithError, logRequest, FirebaseSharedService, createAdminMiddleware, BaseAdminService, loginHtml, createSecureHeaderMiddleware, bodyParserTimeout, clearBodyParserTimeout, requestTimeout, simpleRequestLogger, coloredHttpCode, getRequestContextProperty, setRequestContextProperty, requestContextMiddleware, requestIdMiddleware, REQUEST_ID_KEY, validateBody, validateParams, validateQuery, };
|
|
35
|
-
declare global {
|
|
36
|
-
namespace NodeJS {
|
|
37
|
-
interface ProcessEnv {
|
|
38
|
-
PORT?: string;
|
|
39
|
-
GAE_APPLICATION?: string;
|
|
40
|
-
GAE_SERVICE?: string;
|
|
41
|
-
GAE_VERSION?: string;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -11,6 +11,7 @@ function reqValidation(reqProperty, schema, opt = {}) {
|
|
|
11
11
|
if (opt.redactPaths) {
|
|
12
12
|
redact(opt.redactPaths, req[reqProperty], error);
|
|
13
13
|
error.data.joiValidationErrorItems.length = 0; // clears the array
|
|
14
|
+
delete error.data.annotation;
|
|
14
15
|
}
|
|
15
16
|
return next(new js_lib_1.HttpError(error.message, {
|
|
16
17
|
httpStatusCode: 400,
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { RequestHandler } from 'express';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
declare type ServerStartedCallback = () => number | undefined;
|
|
6
|
-
export declare function statusHandler(serverStartedCallback?: ServerStartedCallback, projectDir?: string, extra?: any): RequestHandler;
|
|
7
|
-
export declare function statusHandlerData(serverStartedCallback?: ServerStartedCallback, projectDir?: string, extra?: any): Record<string, any>;
|
|
8
|
-
export {};
|
|
2
|
+
export declare function statusHandler(projectDir?: string, extra?: any): RequestHandler;
|
|
3
|
+
export declare function statusHandlerData(projectDir?: string, extra?: any): Record<string, any>;
|
|
@@ -5,29 +5,28 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
5
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
6
|
const time_lib_1 = require("@naturalcycles/time-lib");
|
|
7
7
|
const deployInfo_util_1 = require("../deployInfo.util");
|
|
8
|
-
const now = Date.now();
|
|
9
|
-
const defaultServerStartedCallback = () => now;
|
|
10
8
|
const { versions } = process;
|
|
11
|
-
|
|
9
|
+
const { GAE_APPLICATION, GAE_SERVICE, GAE_VERSION } = process.env;
|
|
10
|
+
function statusHandler(projectDir, extra) {
|
|
12
11
|
return async (req, res) => {
|
|
13
|
-
res.json(statusHandlerData(
|
|
12
|
+
res.json(statusHandlerData(projectDir, extra));
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
15
|
exports.statusHandler = statusHandler;
|
|
17
|
-
function statusHandlerData(
|
|
16
|
+
function statusHandlerData(projectDir = process.cwd(), extra) {
|
|
18
17
|
const { APP_ENV } = process.env;
|
|
19
18
|
const { gitRev, gitBranch, prod, ts } = (0, deployInfo_util_1.getDeployInfo)(projectDir);
|
|
20
19
|
const deployBuildTimeUTC = time_lib_1.dayjs.unix(ts).toPretty();
|
|
21
20
|
const buildInfo = [time_lib_1.dayjs.unix(ts).toCompactTime(), gitBranch, gitRev].filter(Boolean).join('_');
|
|
22
21
|
return (0, js_lib_1._filterFalsyValues)({
|
|
23
|
-
started: getStartedStr(
|
|
22
|
+
started: getStartedStr(),
|
|
24
23
|
deployBuildTimeUTC,
|
|
25
24
|
APP_ENV,
|
|
26
25
|
prod,
|
|
27
26
|
buildInfo,
|
|
28
|
-
GAE_APPLICATION
|
|
29
|
-
GAE_SERVICE
|
|
30
|
-
GAE_VERSION
|
|
27
|
+
GAE_APPLICATION,
|
|
28
|
+
GAE_SERVICE,
|
|
29
|
+
GAE_VERSION,
|
|
31
30
|
mem: (0, nodejs_lib_1.memoryUsageFull)(),
|
|
32
31
|
cpuAvg: nodejs_lib_1.processSharedUtil.cpuAvg(),
|
|
33
32
|
// resourceUsage: process.resourceUsage?.(),
|
|
@@ -36,9 +35,8 @@ function statusHandlerData(serverStartedCallback = defaultServerStartedCallback,
|
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
37
|
exports.statusHandlerData = statusHandlerData;
|
|
39
|
-
function getStartedStr(
|
|
40
|
-
|
|
41
|
-
return 'not started yet';
|
|
38
|
+
function getStartedStr() {
|
|
39
|
+
const serverStarted = time_lib_1.dayjs.utc().subtract(process.uptime(), 's');
|
|
42
40
|
const s1 = (0, time_lib_1.dayjs)(serverStarted).toPretty();
|
|
43
41
|
const s2 = (0, time_lib_1.dayjs)(serverStarted).fromNow();
|
|
44
42
|
return `${s1} UTC (${s2})`;
|
|
@@ -22,7 +22,7 @@ class BackendServer {
|
|
|
22
22
|
process.once('SIGTERM', () => this.stop());
|
|
23
23
|
// sentryService.install()
|
|
24
24
|
// 2. Start Express Server
|
|
25
|
-
const port = Number(process.env
|
|
25
|
+
const port = Number(process.env['PORT']) || cfgPort || 8080;
|
|
26
26
|
this.server = await new Promise((resolve, reject) => {
|
|
27
27
|
const server = expressApp.listen(port, (err) => {
|
|
28
28
|
if (err)
|
package/package.json
CHANGED
package/src/db/httpDB.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'stream'
|
|
2
|
-
import { JsonSchemaRootObject } from '@naturalcycles/js-lib'
|
|
2
|
+
import { JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib'
|
|
3
3
|
import {
|
|
4
4
|
BaseCommonDB,
|
|
5
5
|
CommonDB,
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
CommonDBSaveOptions,
|
|
8
8
|
CommonDBStreamOptions,
|
|
9
9
|
DBQuery,
|
|
10
|
-
ObjectWithId,
|
|
11
10
|
RunQueryResult,
|
|
12
11
|
} from '@naturalcycles/db-lib'
|
|
13
12
|
import { getGot, GetGotOptions, Got, ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
CommonDBSaveOptions,
|
|
5
5
|
DBQuery,
|
|
6
6
|
InMemoryDB,
|
|
7
|
-
ObjectWithId,
|
|
8
7
|
} from '@naturalcycles/db-lib'
|
|
9
8
|
import {
|
|
10
9
|
commonDBOptionsSchema,
|
|
11
10
|
commonDBSaveOptionsSchema,
|
|
12
11
|
dbQuerySchema,
|
|
13
12
|
} from '@naturalcycles/db-lib/dist/validation'
|
|
13
|
+
import { ObjectWithId } from '@naturalcycles/js-lib'
|
|
14
14
|
import { anyObjectSchema, arraySchema, objectSchema, stringSchema } from '@naturalcycles/nodejs-lib'
|
|
15
15
|
import { Router } from 'express'
|
|
16
16
|
import { getDefaultRouter, reqValidation } from '..'
|
package/src/index.ts
CHANGED
|
@@ -4,27 +4,16 @@ import { dayjs } from '@naturalcycles/time-lib'
|
|
|
4
4
|
import { RequestHandler } from 'express'
|
|
5
5
|
import { getDeployInfo } from '../deployInfo.util'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @returns unix timestamp in millis
|
|
9
|
-
*/
|
|
10
|
-
type ServerStartedCallback = () => number | undefined
|
|
11
|
-
|
|
12
|
-
const now = Date.now()
|
|
13
|
-
const defaultServerStartedCallback = () => now
|
|
14
7
|
const { versions } = process
|
|
8
|
+
const { GAE_APPLICATION, GAE_SERVICE, GAE_VERSION } = process.env
|
|
15
9
|
|
|
16
|
-
export function statusHandler(
|
|
17
|
-
serverStartedCallback?: ServerStartedCallback,
|
|
18
|
-
projectDir?: string,
|
|
19
|
-
extra?: any,
|
|
20
|
-
): RequestHandler {
|
|
10
|
+
export function statusHandler(projectDir?: string, extra?: any): RequestHandler {
|
|
21
11
|
return async (req, res) => {
|
|
22
|
-
res.json(statusHandlerData(
|
|
12
|
+
res.json(statusHandlerData(projectDir, extra))
|
|
23
13
|
}
|
|
24
14
|
}
|
|
25
15
|
|
|
26
16
|
export function statusHandlerData(
|
|
27
|
-
serverStartedCallback: ServerStartedCallback = defaultServerStartedCallback,
|
|
28
17
|
projectDir: string = process.cwd(),
|
|
29
18
|
extra?: any,
|
|
30
19
|
): Record<string, any> {
|
|
@@ -34,14 +23,14 @@ export function statusHandlerData(
|
|
|
34
23
|
const buildInfo = [dayjs.unix(ts).toCompactTime(), gitBranch, gitRev].filter(Boolean).join('_')
|
|
35
24
|
|
|
36
25
|
return _filterFalsyValues({
|
|
37
|
-
started: getStartedStr(
|
|
26
|
+
started: getStartedStr(),
|
|
38
27
|
deployBuildTimeUTC,
|
|
39
28
|
APP_ENV,
|
|
40
29
|
prod,
|
|
41
30
|
buildInfo,
|
|
42
|
-
GAE_APPLICATION
|
|
43
|
-
GAE_SERVICE
|
|
44
|
-
GAE_VERSION
|
|
31
|
+
GAE_APPLICATION,
|
|
32
|
+
GAE_SERVICE,
|
|
33
|
+
GAE_VERSION,
|
|
45
34
|
mem: memoryUsageFull(),
|
|
46
35
|
cpuAvg: processSharedUtil.cpuAvg(),
|
|
47
36
|
// resourceUsage: process.resourceUsage?.(),
|
|
@@ -50,8 +39,8 @@ export function statusHandlerData(
|
|
|
50
39
|
})
|
|
51
40
|
}
|
|
52
41
|
|
|
53
|
-
function getStartedStr(
|
|
54
|
-
|
|
42
|
+
function getStartedStr(): string {
|
|
43
|
+
const serverStarted = dayjs.utc().subtract(process.uptime(), 's')
|
|
55
44
|
|
|
56
45
|
const s1 = dayjs(serverStarted).toPretty()
|
|
57
46
|
const s2 = dayjs(serverStarted).fromNow()
|
|
@@ -27,7 +27,7 @@ export class BackendServer {
|
|
|
27
27
|
// sentryService.install()
|
|
28
28
|
|
|
29
29
|
// 2. Start Express Server
|
|
30
|
-
const port = Number(process.env
|
|
30
|
+
const port = Number(process.env['PORT']) || cfgPort || 8080
|
|
31
31
|
|
|
32
32
|
this.server = await new Promise<Server>((resolve, reject) => {
|
|
33
33
|
const server = expressApp.listen(port, (err?: Error) => {
|