@naturalcycles/backend-lib 8.0.2 → 8.0.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.
Files changed (90) hide show
  1. package/cfg/tsconfig.json +2 -1
  2. package/dist/admin/adminMiddleware.d.ts +3 -3
  3. package/dist/admin/base.admin.service.d.ts +1 -1
  4. package/dist/admin/base.admin.service.js +2 -0
  5. package/dist/admin/firebase.shared.service.js +1 -0
  6. package/dist/admin/secureHeaderMiddleware.d.ts +2 -2
  7. package/dist/db/httpDB.d.ts +4 -3
  8. package/dist/db/httpDB.js +13 -11
  9. package/dist/db/httpDBRequestHandler.d.ts +4 -3
  10. package/dist/db/index.d.ts +2 -1
  11. package/dist/deploy/backend.cfg.util.d.ts +1 -1
  12. package/dist/deploy/deploy.util.d.ts +2 -2
  13. package/dist/deploy/deployGae.d.ts +2 -2
  14. package/dist/deploy/deployPrepare.d.ts +1 -1
  15. package/dist/deploy/index.d.ts +5 -3
  16. package/dist/env/env.shared.service.d.ts +1 -1
  17. package/dist/env/env.shared.service.js +2 -0
  18. package/dist/sentry/sentry.shared.service.d.ts +1 -1
  19. package/dist/sentry/sentry.shared.service.js +1 -0
  20. package/dist/server/asyncLocalStorageMiddleware.d.ts +2 -2
  21. package/dist/server/basicAuthMiddleware.d.ts +2 -2
  22. package/dist/server/bodyParserTimeoutMiddleware.d.ts +1 -1
  23. package/dist/server/createDefaultApp.d.ts +2 -2
  24. package/dist/server/createDefaultApp.model.d.ts +5 -5
  25. package/dist/server/genericErrorMiddleware.d.ts +3 -3
  26. package/dist/server/getDefaultRouter.d.ts +1 -1
  27. package/dist/server/logMiddleware.d.ts +2 -2
  28. package/dist/server/methodOverrideMiddleware.d.ts +1 -1
  29. package/dist/server/notFoundMiddleware.d.ts +1 -1
  30. package/dist/server/okMiddleware.d.ts +1 -1
  31. package/dist/server/request.log.util.d.ts +1 -1
  32. package/dist/server/request.util.d.ts +1 -1
  33. package/dist/server/requestTimeoutMiddleware.d.ts +2 -2
  34. package/dist/server/safeJsonMiddleware.d.ts +1 -1
  35. package/dist/server/server.util.d.ts +1 -1
  36. package/dist/server/serverStatsMiddleware.d.ts +1 -1
  37. package/dist/server/serverStatusMiddleware.d.ts +1 -1
  38. package/dist/server/simpleRequestLoggerMiddleware.d.ts +1 -1
  39. package/dist/server/startServer.d.ts +2 -2
  40. package/dist/server/startServer.js +2 -0
  41. package/dist/server/startServer.model.d.ts +4 -4
  42. package/dist/server/validation/validateMiddleware.d.ts +5 -4
  43. package/dist/server/validation/validateMiddleware.js +1 -1
  44. package/dist/server/validation/validateRequest.d.ts +2 -2
  45. package/dist/server/validation/validateRequest.js +1 -1
  46. package/dist/server/validation/zodValidateMiddleware.d.ts +3 -3
  47. package/dist/server/validation/zodValidateMiddleware.js +2 -1
  48. package/dist/testing/express.test.service.d.ts +3 -3
  49. package/dist/testing/index.d.ts +2 -1
  50. package/package.json +1 -1
  51. package/src/admin/adminMiddleware.ts +3 -3
  52. package/src/admin/base.admin.service.ts +1 -1
  53. package/src/admin/secureHeaderMiddleware.ts +4 -3
  54. package/src/db/httpDB.ts +5 -6
  55. package/src/db/httpDBRequestHandler.ts +5 -9
  56. package/src/db/index.ts +2 -1
  57. package/src/deploy/backend.cfg.util.ts +1 -1
  58. package/src/deploy/deploy.util.ts +2 -2
  59. package/src/deploy/deployGae.ts +4 -2
  60. package/src/deploy/deployHealthCheck.ts +4 -9
  61. package/src/deploy/deployPrepare.ts +1 -1
  62. package/src/deploy/index.ts +5 -3
  63. package/src/env/env.shared.service.ts +2 -1
  64. package/src/sentry/sentry.shared.service.ts +4 -9
  65. package/src/server/asyncLocalStorageMiddleware.ts +3 -2
  66. package/src/server/basicAuthMiddleware.ts +3 -2
  67. package/src/server/bodyParserTimeoutMiddleware.ts +2 -1
  68. package/src/server/createDefaultApp.model.ts +5 -5
  69. package/src/server/createDefaultApp.ts +3 -2
  70. package/src/server/genericErrorMiddleware.ts +4 -10
  71. package/src/server/getDefaultRouter.ts +1 -1
  72. package/src/server/logMiddleware.ts +2 -2
  73. package/src/server/methodOverrideMiddleware.ts +1 -1
  74. package/src/server/notFoundMiddleware.ts +1 -1
  75. package/src/server/okMiddleware.ts +1 -1
  76. package/src/server/request.log.util.ts +2 -2
  77. package/src/server/request.util.ts +1 -1
  78. package/src/server/requestTimeoutMiddleware.ts +4 -9
  79. package/src/server/safeJsonMiddleware.ts +1 -1
  80. package/src/server/server.util.ts +3 -3
  81. package/src/server/serverStatsMiddleware.ts +3 -2
  82. package/src/server/serverStatusMiddleware.ts +1 -1
  83. package/src/server/simpleRequestLoggerMiddleware.ts +4 -2
  84. package/src/server/startServer.model.ts +4 -4
  85. package/src/server/startServer.ts +2 -2
  86. package/src/server/validation/validateMiddleware.ts +7 -5
  87. package/src/server/validation/validateRequest.ts +8 -3
  88. package/src/server/validation/zodValidateMiddleware.ts +6 -4
  89. package/src/testing/express.test.service.ts +7 -5
  90. package/src/testing/index.ts +2 -1
package/cfg/tsconfig.json CHANGED
@@ -27,7 +27,7 @@
27
27
  // Otherwise since es2022 it defaults to true
28
28
  // and starts to produce different/unexpected behavior
29
29
  // https://angular.schule/blog/2022-11-use-define-for-class-fields
30
- "useDefineForClassFields": false,
30
+ "useDefineForClassFields": true,
31
31
  "importHelpers": true,
32
32
 
33
33
  // Strictness
@@ -38,6 +38,7 @@
38
38
  "suppressImplicitAnyIndexErrors": false,
39
39
  "noImplicitOverride": true,
40
40
  "noUncheckedIndexedAccess": true,
41
+ "noUncheckedSideEffectImports": true,
41
42
  "noPropertyAccessFromIndexSignature": true,
42
43
 
43
44
  // Enabled should be faster, but will catch less errors
@@ -1,6 +1,6 @@
1
- import { BackendRequestHandler } from '../server/server.model';
2
- import { BaseAdminService } from './base.admin.service';
3
- import { FirebaseSharedServiceCfg } from './firebase.shared.service';
1
+ import type { BackendRequestHandler } from '../server/server.model';
2
+ import type { BaseAdminService } from './base.admin.service';
3
+ import type { FirebaseSharedServiceCfg } from './firebase.shared.service';
4
4
  export interface RequireAdminCfg {
5
5
  /**
6
6
  * @default '/login.html'
@@ -1,5 +1,5 @@
1
1
  import type FirebaseAdmin from 'firebase-admin';
2
- import { BackendRequest, BackendRequestHandler } from '../server/server.model';
2
+ import type { BackendRequest, BackendRequestHandler } from '../server/server.model';
3
3
  export interface AdminServiceCfg {
4
4
  /**
5
5
  * @default 'admin_token'
@@ -11,6 +11,7 @@ const adminInfoDisabled = () => ({
11
11
  * Base implementation based on Firebase Auth tokens passed as 'admin_token' cookie.
12
12
  */
13
13
  class BaseAdminService {
14
+ firebaseAuth;
14
15
  constructor(firebaseAuth, cfg) {
15
16
  this.firebaseAuth = firebaseAuth;
16
17
  this.cfg = {
@@ -19,6 +20,7 @@ class BaseAdminService {
19
20
  ...cfg,
20
21
  };
21
22
  }
23
+ cfg;
22
24
  adminInfoDisabled() {
23
25
  return {
24
26
  email: 'authDisabled',
@@ -4,6 +4,7 @@ exports.FirebaseSharedService = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  class FirebaseSharedService {
7
+ cfg;
7
8
  constructor(cfg) {
8
9
  this.cfg = cfg;
9
10
  }
@@ -1,5 +1,5 @@
1
- import { AdminMiddleware, RequireAdminCfg } from './adminMiddleware';
2
- import { BaseAdminService } from './base.admin.service';
1
+ import type { AdminMiddleware, RequireAdminCfg } from './adminMiddleware';
2
+ import type { BaseAdminService } from './base.admin.service';
3
3
  export interface SecureHeaderMiddlewareCfg extends RequireAdminCfg {
4
4
  adminService: BaseAdminService;
5
5
  /**
@@ -1,6 +1,7 @@
1
- import { BaseCommonDB, CommonDB, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBSupport, DBQuery, RunQueryResult } from '@naturalcycles/db-lib';
2
- import { FetcherOptions, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
3
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
1
+ import type { CommonDB, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBSupport, DBQuery, RunQueryResult } from '@naturalcycles/db-lib';
2
+ import { BaseCommonDB } from '@naturalcycles/db-lib';
3
+ import type { FetcherOptions, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
4
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
4
5
  export interface HttpDBCfg extends FetcherOptions {
5
6
  baseUrl: string;
6
7
  }
package/dist/db/httpDB.js CHANGED
@@ -8,25 +8,27 @@ const js_lib_1 = require("@naturalcycles/js-lib");
8
8
  * Implementation of CommonDB that proxies all requests via HTTP to "httpDBRequestHandler".
9
9
  */
10
10
  class HttpDB extends db_lib_1.BaseCommonDB {
11
+ cfg;
12
+ support = {
13
+ ...db_lib_1.commonDBFullSupport,
14
+ streaming: false,
15
+ createTable: false,
16
+ bufferValues: false,
17
+ updateSaveMethod: false,
18
+ insertSaveMethod: false,
19
+ transactions: false,
20
+ patchByQuery: false,
21
+ increment: false,
22
+ };
11
23
  constructor(cfg) {
12
24
  super();
13
25
  this.cfg = cfg;
14
- this.support = {
15
- ...db_lib_1.commonDBFullSupport,
16
- streaming: false,
17
- createTable: false,
18
- bufferValues: false,
19
- updateSaveMethod: false,
20
- insertSaveMethod: false,
21
- transactions: false,
22
- patchByQuery: false,
23
- increment: false,
24
- };
25
26
  this.setCfg(cfg);
26
27
  }
27
28
  setCfg(cfg) {
28
29
  this.fetcher = (0, js_lib_1.getFetcher)(cfg);
29
30
  }
31
+ fetcher;
30
32
  async ping() {
31
33
  await this.fetcher.getVoid(`ping`);
32
34
  }
@@ -1,6 +1,7 @@
1
- import { CommonDB, CommonDBOptions, CommonDBSaveOptions, DBQuery } from '@naturalcycles/db-lib';
2
- import { ObjectWithId } from '@naturalcycles/js-lib';
3
- import { BackendRouter } from '..';
1
+ import type { CommonDB, CommonDBOptions, CommonDBSaveOptions } from '@naturalcycles/db-lib';
2
+ import { DBQuery } from '@naturalcycles/db-lib';
3
+ import type { ObjectWithId } from '@naturalcycles/js-lib';
4
+ import type { BackendRouter } from '..';
4
5
  export interface GetByIdsInput {
5
6
  table: string;
6
7
  ids: string[];
@@ -1,4 +1,5 @@
1
- import { HttpDB, HttpDBCfg } from './httpDB';
1
+ import type { HttpDBCfg } from './httpDB';
2
+ import { HttpDB } from './httpDB';
2
3
  import { httpDBRequestHandler } from './httpDBRequestHandler';
3
4
  export type { HttpDBCfg };
4
5
  export { HttpDB, httpDBRequestHandler };
@@ -1,4 +1,4 @@
1
- import { StringMap } from '@naturalcycles/js-lib';
1
+ import type { StringMap } from '@naturalcycles/js-lib';
2
2
  export interface BackendCfg {
3
3
  gaeProject: string;
4
4
  gaeProjectByBranch?: StringMap;
@@ -1,5 +1,5 @@
1
- import { BackendCfg } from './backend.cfg.util';
2
- import { AppYaml, DeployInfo } from './deploy.model';
1
+ import type { BackendCfg } from './backend.cfg.util';
2
+ import type { AppYaml, DeployInfo } from './deploy.model';
3
3
  export declare function createAndSaveDeployInfo(backendCfg: BackendCfg, targetDir: string): Promise<DeployInfo>;
4
4
  export declare function createDeployInfo(backendCfg: BackendCfg, overrideBranch?: string): Promise<DeployInfo>;
5
5
  export declare function createAndSaveAppYaml(backendCfg: BackendCfg, deployInfo: DeployInfo, projectDir: string, targetDir: string, appYamlPassEnv?: string): AppYaml;
@@ -1,5 +1,5 @@
1
- import { DeployHealthCheckOptions } from './deployHealthCheck';
2
- import { DeployPrepareOptions } from './deployPrepare';
1
+ import type { DeployHealthCheckOptions } from './deployHealthCheck';
2
+ import type { DeployPrepareOptions } from './deployPrepare';
3
3
  export interface DeployGaeOptions extends DeployPrepareOptions, DeployHealthCheckOptions {
4
4
  }
5
5
  export declare function deployGae(opt?: DeployGaeOptions): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { DeployInfo } from './deploy.model';
1
+ import type { DeployInfo } from './deploy.model';
2
2
  export interface DeployPrepareOptions {
3
3
  projectDir?: string;
4
4
  targetDir?: string;
@@ -1,8 +1,10 @@
1
- import { BackendCfg, getBackendCfg } from './backend.cfg.util';
2
- import { DeployInfo } from './deploy.model';
1
+ import type { BackendCfg } from './backend.cfg.util';
2
+ import { getBackendCfg } from './backend.cfg.util';
3
+ import type { DeployInfo } from './deploy.model';
3
4
  import { createAppYaml, createDeployInfo } from './deploy.util';
4
5
  import { deployGae } from './deployGae';
5
- import { deployHealthCheck, DeployHealthCheckOptions } from './deployHealthCheck';
6
+ import type { DeployHealthCheckOptions } from './deployHealthCheck';
7
+ import { deployHealthCheck } from './deployHealthCheck';
6
8
  import { deployPrepare } from './deployPrepare';
7
9
  export type { BackendCfg, DeployHealthCheckOptions, DeployInfo };
8
10
  export { createAppYaml, createDeployInfo, deployGae, deployHealthCheck, deployPrepare, getBackendCfg, };
@@ -1,4 +1,4 @@
1
- import { StringMap } from '@naturalcycles/js-lib';
1
+ import type { StringMap } from '@naturalcycles/js-lib';
2
2
  export interface BaseEnv {
3
3
  name: string;
4
4
  }
@@ -7,6 +7,8 @@ class EnvSharedService {
7
7
  constructor(cfg) {
8
8
  this.envMap = (0, js_lib_1._by)(cfg.environments, e => e.name);
9
9
  }
10
+ envMap;
11
+ env;
10
12
  init() {
11
13
  this.getEnv();
12
14
  }
@@ -1,4 +1,4 @@
1
- import { CommonLogger, Primitive, StringMap } from '@naturalcycles/js-lib';
1
+ import type { CommonLogger, Primitive, StringMap } from '@naturalcycles/js-lib';
2
2
  import type { Breadcrumb, SeverityLevel } from '@sentry/node';
3
3
  import type * as SentryLib from '@sentry/node';
4
4
  export interface SentrySharedServiceCfg {
@@ -28,6 +28,7 @@ class SentrySharedService {
28
28
  constructor(sentryServiceCfg) {
29
29
  this.sentry = sentryServiceCfg.sentry;
30
30
  }
31
+ sentry;
31
32
  /**
32
33
  * For GDPR reasons we never send more information than just User ID.
33
34
  */
@@ -1,5 +1,5 @@
1
- import { CommonLogger } from '@naturalcycles/js-lib';
2
- import { BackendRequest, BackendRequestHandler } from './server.model';
1
+ import type { CommonLogger } from '@naturalcycles/js-lib';
2
+ import type { BackendRequest, BackendRequestHandler } from './server.model';
3
3
  export interface RequestLocalStorage {
4
4
  req: BackendRequest;
5
5
  }
@@ -1,5 +1,5 @@
1
- import { StringMap } from '@naturalcycles/js-lib';
2
- import { BackendRequestHandler } from './server.model';
1
+ import type { StringMap } from '@naturalcycles/js-lib';
2
+ import type { BackendRequestHandler } from './server.model';
3
3
  export interface BasicAuthMiddlewareCfg {
4
4
  /**
5
5
  * Map from login (Sting) to password (String).
@@ -1,4 +1,4 @@
1
- import { BackendRequestHandler } from '../index';
1
+ import type { BackendRequestHandler } from '../index';
2
2
  export interface BodyParserTimeoutMiddlewareCfg {
3
3
  /**
4
4
  * @default 10
@@ -1,3 +1,3 @@
1
- import { BackendApplication } from '..';
2
- import { DefaultAppCfg } from './createDefaultApp.model';
1
+ import type { BackendApplication } from '..';
2
+ import type { DefaultAppCfg } from './createDefaultApp.model';
3
3
  export declare function createDefaultApp(cfg: DefaultAppCfg): BackendApplication;
@@ -1,8 +1,8 @@
1
- import { Options, OptionsJson, OptionsUrlencoded } from 'body-parser';
2
- import { CorsOptions } from 'cors';
3
- import { SentrySharedService } from '../sentry/sentry.shared.service';
4
- import { GenericErrorMiddlewareCfg } from './genericErrorMiddleware';
5
- import { BackendRequestHandler } from './server.model';
1
+ import type { Options, OptionsJson, OptionsUrlencoded } from 'body-parser';
2
+ import type { CorsOptions } from 'cors';
3
+ import type { SentrySharedService } from '../sentry/sentry.shared.service';
4
+ import type { GenericErrorMiddlewareCfg } from './genericErrorMiddleware';
5
+ import type { BackendRequestHandler } from './server.model';
6
6
  /**
7
7
  * Plain RequestHandler can be provided - then it's mounted to /
8
8
  * Otherwise `path` can be provided to specify mounting point.
@@ -1,6 +1,6 @@
1
- import { ErrorObject } from '@naturalcycles/js-lib';
2
- import { SentrySharedService } from '../sentry/sentry.shared.service';
3
- import { BackendErrorRequestHandler, BackendRequest, BackendResponse } from './server.model';
1
+ import type { ErrorObject } from '@naturalcycles/js-lib';
2
+ import type { SentrySharedService } from '../sentry/sentry.shared.service';
3
+ import type { BackendErrorRequestHandler, BackendRequest, BackendResponse } from './server.model';
4
4
  export interface GenericErrorMiddlewareCfg {
5
5
  sentryService?: SentrySharedService;
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { BackendRequestHandler, BackendRouter } from './server.model';
1
+ import type { BackendRequestHandler, BackendRouter } from './server.model';
2
2
  /**
3
3
  * Convenience method.
4
4
  */
@@ -1,5 +1,5 @@
1
- import { CommonLogger } from '@naturalcycles/js-lib';
2
- import { BackendRequestHandler } from './server.model';
1
+ import type { CommonLogger } from '@naturalcycles/js-lib';
2
+ import type { BackendRequestHandler } from './server.model';
3
3
  /**
4
4
  * Logger that logs in AppEngine format.
5
5
  * To be used in outside-of-request situations (otherwise req.log should be used).
@@ -1,4 +1,4 @@
1
- import { BackendRequestHandler } from './server.model';
1
+ import type { BackendRequestHandler } from './server.model';
2
2
  export interface MethodOverrideMiddlewareCfg {
3
3
  /**
4
4
  * @default _method
@@ -1,2 +1,2 @@
1
- import { BackendRequestHandler } from './server.model';
1
+ import type { BackendRequestHandler } from './server.model';
2
2
  export declare function notFoundMiddleware(): BackendRequestHandler;
@@ -1,2 +1,2 @@
1
- import { BackendRequestHandler } from './server.model';
1
+ import type { BackendRequestHandler } from './server.model';
2
2
  export declare function okMiddleware(): BackendRequestHandler;
@@ -1,3 +1,3 @@
1
- import { BackendRequest } from './server.model';
1
+ import type { BackendRequest } from './server.model';
2
2
  export declare function logRequest(req: BackendRequest, statusCode: number, ...tokens: any[]): void;
3
3
  export declare function coloredHttpCode(statusCode: number): string;
@@ -1,4 +1,4 @@
1
- import { BackendRequest } from './server.model';
1
+ import type { BackendRequest } from './server.model';
2
2
  /**
3
3
  * Returns e.g:
4
4
  *
@@ -1,5 +1,5 @@
1
- import { NumberOfSeconds } from '@naturalcycles/js-lib';
2
- import { BackendRequest, BackendRequestHandler, BackendResponse } from '../index';
1
+ import type { NumberOfSeconds } from '@naturalcycles/js-lib';
2
+ import type { BackendRequest, BackendRequestHandler, BackendResponse } from '../index';
3
3
  export interface RequestTimeoutMiddlewareCfg {
4
4
  /**
5
5
  * @default 120
@@ -1,4 +1,4 @@
1
- import { BackendRequestHandler } from './server.model';
1
+ import type { BackendRequestHandler } from './server.model';
2
2
  /**
3
3
  * Replaces express's built-in req.json() function with the safe one,
4
4
  * protected from circular references.
@@ -1,4 +1,4 @@
1
- import { Server } from 'node:http';
1
+ import type { Server } from 'node:http';
2
2
  export interface DestroyableServer extends Server {
3
3
  destroy: () => Promise<void>;
4
4
  }
@@ -1,4 +1,4 @@
1
- import { BackendRequestHandler } from '../index';
1
+ import type { BackendRequestHandler } from '../index';
2
2
  /**
3
3
  * Depends on serverStatsMiddleware to work.
4
4
  *
@@ -1,3 +1,3 @@
1
- import { BackendRequestHandler } from './server.model';
1
+ import type { BackendRequestHandler } from './server.model';
2
2
  export declare function serverStatusMiddleware(projectDir?: string, extra?: any): BackendRequestHandler;
3
3
  export declare function getServerStatusData(projectDir?: string, extra?: any): Record<string, any>;
@@ -1,4 +1,4 @@
1
- import { BackendRequestHandler } from '../index';
1
+ import type { BackendRequestHandler } from '../index';
2
2
  export interface SimpleRequestLoggerMiddlewareCfg {
3
3
  /**
4
4
  * @default false
@@ -1,5 +1,5 @@
1
- import { Server } from 'node:http';
2
- import { StartServerCfg, StartServerData } from './startServer.model';
1
+ import type { Server } from 'node:http';
2
+ import type { StartServerCfg, StartServerData } from './startServer.model';
3
3
  export declare class BackendServer {
4
4
  private cfg;
5
5
  constructor(cfg: StartServerCfg);
@@ -9,9 +9,11 @@ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
9
9
  const index_1 = require("../index");
10
10
  const { NODE_OPTIONS, APP_ENV } = process.env;
11
11
  class BackendServer {
12
+ cfg;
12
13
  constructor(cfg) {
13
14
  this.cfg = cfg;
14
15
  }
16
+ server;
15
17
  async start() {
16
18
  const { port: cfgPort, expressApp = (0, index_1.createDefaultApp)(this.cfg), registerUncaughtExceptionHandlers = true, } = this.cfg;
17
19
  // 1. Register error handlers, etc.
@@ -1,7 +1,7 @@
1
- import { Server } from 'node:http';
2
- import { SentrySharedService } from '../sentry/sentry.shared.service';
3
- import { DefaultAppCfg } from './createDefaultApp.model';
4
- import { BackendApplication } from './server.model';
1
+ import type { Server } from 'node:http';
2
+ import type { SentrySharedService } from '../sentry/sentry.shared.service';
3
+ import type { DefaultAppCfg } from './createDefaultApp.model';
4
+ import type { BackendApplication } from './server.model';
5
5
  /**
6
6
  * If DefaultAppCfg.resources is passed and `expressApp` is not passed - it will call createDefaultApp(cfg).
7
7
  */
@@ -1,7 +1,8 @@
1
- import { JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib';
2
- import { AjvSchema, AjvValidationError } from '@naturalcycles/nodejs-lib';
3
- import { BackendRequestHandler } from '../server.model';
4
- import { ReqValidationOptions } from './validateRequest';
1
+ import type { JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib';
2
+ import type { AjvValidationError } from '@naturalcycles/nodejs-lib';
3
+ import { AjvSchema } from '@naturalcycles/nodejs-lib';
4
+ import type { BackendRequestHandler } from '../server.model';
5
+ import type { ReqValidationOptions } from './validateRequest';
5
6
  export declare function validateBody(schema: JsonSchema | JsonSchemaBuilder | AjvSchema, opt?: ReqValidationOptions<AjvValidationError>): BackendRequestHandler;
6
7
  export declare function validateParams(schema: JsonSchema | JsonSchemaBuilder | AjvSchema, opt?: ReqValidationOptions<AjvValidationError>): BackendRequestHandler;
7
8
  export declare function validateQuery(schema: JsonSchema | JsonSchemaBuilder | AjvSchema, opt?: ReqValidationOptions<AjvValidationError>): BackendRequestHandler;
@@ -31,7 +31,7 @@ function validateObject(prop, schema, opt = {}) {
31
31
  });
32
32
  const reportPredicate = typeof opt.report === 'function' ? opt.report : () => opt.report;
33
33
  return (req, _res, next) => {
34
- const error = ajvSchema.getValidationError(req[prop]);
34
+ const error = ajvSchema.getValidationError(req[prop] || {});
35
35
  if (error) {
36
36
  const report = reportPredicate(error);
37
37
  if (opt.redactPaths) {
@@ -1,5 +1,5 @@
1
- import { AnySchema, JoiValidationError } from '@naturalcycles/nodejs-lib';
2
- import { BackendRequest } from '../server.model';
1
+ import type { AnySchema, JoiValidationError } from '@naturalcycles/nodejs-lib';
2
+ import type { BackendRequest } from '../server.model';
3
3
  export interface ReqValidationOptions<ERR extends Error> {
4
4
  /**
5
5
  * Pass a 'dot-paths' (e.g `pw`, or `input.pw`) that needs to be redacted from the output, in case of error.
@@ -42,7 +42,7 @@ class ValidateRequest {
42
42
  return this.validate(req, 'headers', schema, options);
43
43
  }
44
44
  validate(req, reqProperty, schema, opt = {}) {
45
- const { value, error } = (0, nodejs_lib_1.getValidationResult)(req[reqProperty], schema, `request ${reqProperty}`);
45
+ const { value, error } = (0, nodejs_lib_1.getValidationResult)(req[reqProperty] || {}, schema, `request ${reqProperty}`);
46
46
  if (error) {
47
47
  let report;
48
48
  if (typeof opt.report === 'boolean') {
@@ -1,6 +1,6 @@
1
- import { ZodSchema, ZodValidationError } from '@naturalcycles/js-lib';
2
- import { BackendRequestHandler } from '../server.model';
3
- import { ReqValidationOptions } from './validateRequest';
1
+ import type { ZodSchema, ZodValidationError } from '@naturalcycles/js-lib/dist/zod/index.js';
2
+ import type { BackendRequestHandler } from '../server.model';
3
+ import type { ReqValidationOptions } from './validateRequest';
4
4
  /**
5
5
  * Validates req property (body, params or query).
6
6
  * Supports Joi schema or AjvSchema (from nodejs-lib).
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.zodReqValidate = zodReqValidate;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
+ const index_js_1 = require("@naturalcycles/js-lib/dist/zod/index.js");
5
6
  const REDACTED = 'REDACTED';
6
7
  /**
7
8
  * Validates req property (body, params or query).
@@ -12,7 +13,7 @@ const REDACTED = 'REDACTED';
12
13
  function zodReqValidate(prop, schema, opt = {}) {
13
14
  const reportPredicate = typeof opt.report === 'function' ? opt.report : () => opt.report;
14
15
  return (req, _res, next) => {
15
- const { error } = (0, js_lib_1.zSafeValidate)(req[prop], schema);
16
+ const { error } = (0, index_js_1.zSafeValidate)(req[prop] || {}, schema);
16
17
  if (!error) {
17
18
  return next();
18
19
  }
@@ -1,6 +1,6 @@
1
- import { Fetcher, FetcherOptions } from '@naturalcycles/js-lib';
2
- import { BackendApplication, DefaultAppCfg } from '../index';
3
- import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model';
1
+ import type { Fetcher, FetcherOptions } from '@naturalcycles/js-lib';
2
+ import type { BackendApplication, DefaultAppCfg } from '../index';
3
+ import type { BackendRequestHandlerCfg } from '../server/createDefaultApp.model';
4
4
  export interface ExpressApp extends Fetcher {
5
5
  close: () => Promise<void>;
6
6
  }
@@ -1,3 +1,4 @@
1
- import { ExpressApp, expressTestService } from './express.test.service';
1
+ import type { ExpressApp } from './express.test.service';
2
+ import { expressTestService } from './express.test.service';
2
3
  export type { ExpressApp };
3
4
  export { expressTestService };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "8.0.2",
3
+ "version": "8.0.4",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
@@ -1,9 +1,9 @@
1
1
  import { _memoFn, AppError } from '@naturalcycles/js-lib'
2
2
  import { fs2 } from '@naturalcycles/nodejs-lib'
3
3
  import ejs from 'ejs'
4
- import { BackendRequestHandler } from '../server/server.model'
5
- import { BaseAdminService } from './base.admin.service'
6
- import { FirebaseSharedServiceCfg } from './firebase.shared.service'
4
+ import type { BackendRequestHandler } from '../server/server.model'
5
+ import type { BaseAdminService } from './base.admin.service'
6
+ import type { FirebaseSharedServiceCfg } from './firebase.shared.service'
7
7
 
8
8
  export interface RequireAdminCfg {
9
9
  /**
@@ -1,7 +1,7 @@
1
1
  import { _assert, AppError } from '@naturalcycles/js-lib'
2
2
  import { dimGrey, green, red } from '@naturalcycles/nodejs-lib'
3
3
  import type FirebaseAdmin from 'firebase-admin'
4
- import { BackendRequest, BackendRequestHandler } from '../server/server.model'
4
+ import type { BackendRequest, BackendRequestHandler } from '../server/server.model'
5
5
 
6
6
  export interface AdminServiceCfg {
7
7
  /**
@@ -1,8 +1,9 @@
1
1
  import { AppError } from '@naturalcycles/js-lib'
2
2
  import { timingSafeStringEqual } from '@naturalcycles/nodejs-lib'
3
- import { BackendRequestHandler } from '../server/server.model'
4
- import { AdminMiddleware, RequireAdminCfg, requireAdminPermissions } from './adminMiddleware'
5
- import { BaseAdminService } from './base.admin.service'
3
+ import type { BackendRequestHandler } from '../server/server.model'
4
+ import type { AdminMiddleware, RequireAdminCfg } from './adminMiddleware'
5
+ import { requireAdminPermissions } from './adminMiddleware'
6
+ import type { BaseAdminService } from './base.admin.service'
6
7
 
7
8
  export interface SecureHeaderMiddlewareCfg extends RequireAdminCfg {
8
9
  adminService: BaseAdminService
package/src/db/httpDB.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { Readable } from 'node:stream'
2
- import {
3
- BaseCommonDB,
2
+ import type {
4
3
  CommonDB,
5
- commonDBFullSupport,
6
4
  CommonDBOptions,
7
5
  CommonDBSaveOptions,
8
6
  CommonDBStreamOptions,
@@ -10,14 +8,15 @@ import {
10
8
  DBQuery,
11
9
  RunQueryResult,
12
10
  } from '@naturalcycles/db-lib'
13
- import {
11
+ import { BaseCommonDB, commonDBFullSupport } from '@naturalcycles/db-lib'
12
+ import type {
14
13
  Fetcher,
15
14
  FetcherOptions,
16
- getFetcher,
17
15
  JsonSchemaRootObject,
18
16
  ObjectWithId,
19
17
  } from '@naturalcycles/js-lib'
20
- import { ReadableTyped } from '@naturalcycles/nodejs-lib'
18
+ import { getFetcher } from '@naturalcycles/js-lib'
19
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
21
20
 
22
21
  export interface HttpDBCfg extends FetcherOptions {
23
22
  baseUrl: string
@@ -1,18 +1,14 @@
1
- import {
2
- CommonDB,
3
- CommonDBOptions,
4
- CommonDBSaveOptions,
5
- DBQuery,
6
- InMemoryDB,
7
- } from '@naturalcycles/db-lib'
1
+ import type { CommonDB, CommonDBOptions, CommonDBSaveOptions } from '@naturalcycles/db-lib'
2
+ import { DBQuery, InMemoryDB } from '@naturalcycles/db-lib'
8
3
  import {
9
4
  commonDBOptionsSchema,
10
5
  commonDBSaveOptionsSchema,
11
6
  dbQuerySchema,
12
7
  } from '@naturalcycles/db-lib/dist/validation'
13
- import { ObjectWithId } from '@naturalcycles/js-lib'
8
+ import type { ObjectWithId } from '@naturalcycles/js-lib'
14
9
  import { anyObjectSchema, arraySchema, objectSchema, stringSchema } from '@naturalcycles/nodejs-lib'
15
- import { BackendRouter, getDefaultRouter, validateRequest } from '..'
10
+ import type { BackendRouter } from '..'
11
+ import { getDefaultRouter, validateRequest } from '..'
16
12
 
17
13
  export interface GetByIdsInput {
18
14
  table: string
package/src/db/index.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { HttpDB, HttpDBCfg } from './httpDB'
1
+ import type { HttpDBCfg } from './httpDB'
2
+ import { HttpDB } from './httpDB'
2
3
  import { httpDBRequestHandler } from './httpDBRequestHandler'
3
4
 
4
5
  export type { HttpDBCfg }
@@ -1,4 +1,4 @@
1
- import { StringMap } from '@naturalcycles/js-lib'
1
+ import type { StringMap } from '@naturalcycles/js-lib'
2
2
  import { AjvSchema, fs2, requireFileToExist } from '@naturalcycles/nodejs-lib'
3
3
  import { resourcesDir } from '../paths.cnst'
4
4
 
@@ -1,7 +1,7 @@
1
1
  import { _assert, _mapValues, _merge, _truncate, localTime } from '@naturalcycles/js-lib'
2
2
  import { dimGrey, fs2, sha256, white } from '@naturalcycles/nodejs-lib'
3
- import { BackendCfg } from './backend.cfg.util'
4
- import { AppYaml, DeployInfo } from './deploy.model'
3
+ import type { BackendCfg } from './backend.cfg.util'
4
+ import type { AppYaml, DeployInfo } from './deploy.model'
5
5
 
6
6
  const APP_YAML_DEFAULT = (): AppYaml => ({
7
7
  runtime: 'nodejs22',
@@ -2,8 +2,10 @@ import { _anyToError, _objectAssign, pRetry } from '@naturalcycles/js-lib'
2
2
  import { appendToGithubSummary, exec2 } from '@naturalcycles/nodejs-lib'
3
3
  import { getBackendCfg } from './backend.cfg.util'
4
4
  import { createDeployInfo } from './deploy.util'
5
- import { deployHealthCheck, DeployHealthCheckOptions } from './deployHealthCheck'
6
- import { deployPrepare, DeployPrepareOptions } from './deployPrepare'
5
+ import type { DeployHealthCheckOptions } from './deployHealthCheck'
6
+ import { deployHealthCheck } from './deployHealthCheck'
7
+ import type { DeployPrepareOptions } from './deployPrepare'
8
+ import { deployPrepare } from './deployPrepare'
7
9
 
8
10
  export interface DeployGaeOptions extends DeployPrepareOptions, DeployHealthCheckOptions {}
9
11
 
@@ -1,12 +1,7 @@
1
- import { inspect, InspectOptions } from 'node:util'
2
- import {
3
- _filterFalsyValues,
4
- _ms,
5
- _since,
6
- getFetcher,
7
- pDelay,
8
- UnixTimestampMillis,
9
- } from '@naturalcycles/js-lib'
1
+ import type { InspectOptions } from 'node:util'
2
+ import { inspect } from 'node:util'
3
+ import type { UnixTimestampMillis } from '@naturalcycles/js-lib'
4
+ import { _filterFalsyValues, _ms, _since, getFetcher, pDelay } from '@naturalcycles/js-lib'
10
5
  import { dimGrey, exec2, red } from '@naturalcycles/nodejs-lib'
11
6
  import { coloredHttpCode } from '../server/request.log.util'
12
7
 
@@ -1,7 +1,7 @@
1
1
  import { dimGrey, fs2, kpySync } from '@naturalcycles/nodejs-lib'
2
2
  import { srcDir } from '../paths.cnst'
3
3
  import { getBackendCfg } from './backend.cfg.util'
4
- import { DeployInfo } from './deploy.model'
4
+ import type { DeployInfo } from './deploy.model'
5
5
  import { createAndSaveAppYaml, createAndSaveDeployInfo } from './deploy.util'
6
6
 
7
7
  export interface DeployPrepareOptions {
@@ -1,8 +1,10 @@
1
- import { BackendCfg, getBackendCfg } from './backend.cfg.util'
2
- import { DeployInfo } from './deploy.model'
1
+ import type { BackendCfg } from './backend.cfg.util'
2
+ import { getBackendCfg } from './backend.cfg.util'
3
+ import type { DeployInfo } from './deploy.model'
3
4
  import { createAppYaml, createDeployInfo } from './deploy.util'
4
5
  import { deployGae } from './deployGae'
5
- import { deployHealthCheck, DeployHealthCheckOptions } from './deployHealthCheck'
6
+ import type { DeployHealthCheckOptions } from './deployHealthCheck'
7
+ import { deployHealthCheck } from './deployHealthCheck'
6
8
  import { deployPrepare } from './deployPrepare'
7
9
 
8
10
  export type { BackendCfg, DeployHealthCheckOptions, DeployInfo }
@@ -1,4 +1,5 @@
1
- import { _assert, _by, StringMap } from '@naturalcycles/js-lib'
1
+ import type { StringMap } from '@naturalcycles/js-lib'
2
+ import { _assert, _by } from '@naturalcycles/js-lib'
2
3
  import { dimGrey } from '@naturalcycles/nodejs-lib'
3
4
 
4
5
  export interface BaseEnv {
@@ -1,12 +1,7 @@
1
- import {
2
- _anyToError,
3
- _isErrorObject,
4
- CommonLogger,
5
- CommonLogLevel,
6
- Primitive,
7
- StringMap,
8
- } from '@naturalcycles/js-lib'
9
- import { _inspect, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
1
+ import type { CommonLogger, CommonLogLevel, Primitive, StringMap } from '@naturalcycles/js-lib'
2
+ import { _anyToError, _isErrorObject } from '@naturalcycles/js-lib'
3
+ import type { InspectAnyOptions } from '@naturalcycles/nodejs-lib'
4
+ import { _inspect } from '@naturalcycles/nodejs-lib'
10
5
  import type { Breadcrumb, SeverityLevel } from '@sentry/node'
11
6
  import type * as SentryLib from '@sentry/node'
12
7
  import { getRequestLogger } from '../index'
@@ -1,7 +1,8 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks'
2
- import { _lazyValue, CommonLogger } from '@naturalcycles/js-lib'
2
+ import type { CommonLogger } from '@naturalcycles/js-lib'
3
+ import { _lazyValue } from '@naturalcycles/js-lib'
3
4
  import { ciLogger, devLogger, gaeLogger } from './logMiddleware'
4
- import { BackendRequest, BackendRequestHandler } from './server.model'
5
+ import type { BackendRequest, BackendRequestHandler } from './server.model'
5
6
 
6
7
  const { GAE_INSTANCE, CI } = process.env
7
8
  const isGAE = !!GAE_INSTANCE
@@ -1,6 +1,7 @@
1
- import { _split, StringMap } from '@naturalcycles/js-lib'
1
+ import type { StringMap } from '@naturalcycles/js-lib'
2
+ import { _split } from '@naturalcycles/js-lib'
2
3
  import { base64ToString, timingSafeStringEqual } from '@naturalcycles/nodejs-lib'
3
- import { BackendRequestHandler } from './server.model'
4
+ import type { BackendRequestHandler } from './server.model'
4
5
 
5
6
  export interface BasicAuthMiddlewareCfg {
6
7
  /**
@@ -1,5 +1,6 @@
1
1
  import { AppError } from '@naturalcycles/js-lib'
2
- import { BackendRequestHandler, respondWithError } from '../index'
2
+ import type { BackendRequestHandler } from '../index'
3
+ import { respondWithError } from '../index'
3
4
 
4
5
  export interface BodyParserTimeoutMiddlewareCfg {
5
6
  /**
@@ -1,8 +1,8 @@
1
- import { Options, OptionsJson, OptionsUrlencoded } from 'body-parser'
2
- import { CorsOptions } from 'cors'
3
- import { SentrySharedService } from '../sentry/sentry.shared.service'
4
- import { GenericErrorMiddlewareCfg } from './genericErrorMiddleware'
5
- import { BackendRequestHandler } from './server.model'
1
+ import type { Options, OptionsJson, OptionsUrlencoded } from 'body-parser'
2
+ import type { CorsOptions } from 'cors'
3
+ import type { SentrySharedService } from '../sentry/sentry.shared.service'
4
+ import type { GenericErrorMiddlewareCfg } from './genericErrorMiddleware'
5
+ import type { BackendRequestHandler } from './server.model'
6
6
 
7
7
  /**
8
8
  * Plain RequestHandler can be provided - then it's mounted to /
@@ -1,9 +1,10 @@
1
1
  import cookieParser = require('cookie-parser')
2
2
  import cors = require('cors')
3
3
  import express = require('express')
4
- import { BackendApplication, isGAE, methodOverrideMiddleware } from '..'
4
+ import type { BackendApplication } from '..'
5
+ import { isGAE, methodOverrideMiddleware } from '..'
5
6
  import { asyncLocalStorageMiddleware } from './asyncLocalStorageMiddleware'
6
- import {
7
+ import type {
7
8
  BackendRequestHandlerCfg,
8
9
  BackendRequestHandlerWithPath,
9
10
  DefaultAppCfg,
@@ -1,13 +1,7 @@
1
- import {
2
- _anyToError,
3
- _errorLikeToErrorObject,
4
- _filterUndefinedValues,
5
- AppError,
6
- BackendErrorResponseObject,
7
- ErrorObject,
8
- } from '@naturalcycles/js-lib'
9
- import { SentrySharedService } from '../sentry/sentry.shared.service'
10
- import { BackendErrorRequestHandler, BackendRequest, BackendResponse } from './server.model'
1
+ import type { AppError, BackendErrorResponseObject, ErrorObject } from '@naturalcycles/js-lib'
2
+ import { _anyToError, _errorLikeToErrorObject, _filterUndefinedValues } from '@naturalcycles/js-lib'
3
+ import type { SentrySharedService } from '../sentry/sentry.shared.service'
4
+ import type { BackendErrorRequestHandler, BackendRequest, BackendResponse } from './server.model'
11
5
 
12
6
  export interface GenericErrorMiddlewareCfg {
13
7
  sentryService?: SentrySharedService
@@ -1,5 +1,5 @@
1
1
  import { Router } from 'express'
2
- import { BackendRequestHandler, BackendRouter } from './server.model'
2
+ import type { BackendRequestHandler, BackendRouter } from './server.model'
3
3
 
4
4
  /**
5
5
  * Convenience method.
@@ -1,7 +1,7 @@
1
1
  import { inspect } from 'node:util'
2
- import { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
2
+ import type { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
3
3
  import { _inspect, dimGrey } from '@naturalcycles/nodejs-lib'
4
- import { BackendRequestHandler } from './server.model'
4
+ import type { BackendRequestHandler } from './server.model'
5
5
 
6
6
  const { GOOGLE_CLOUD_PROJECT, GAE_INSTANCE, APP_ENV } = process.env
7
7
  const isGAE = !!GAE_INSTANCE
@@ -1,4 +1,4 @@
1
- import { BackendRequestHandler } from './server.model'
1
+ import type { BackendRequestHandler } from './server.model'
2
2
 
3
3
  export interface MethodOverrideMiddlewareCfg {
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { getRequestEndpoint } from './request.util'
2
- import { BackendRequestHandler } from './server.model'
2
+ import type { BackendRequestHandler } from './server.model'
3
3
 
4
4
  export function notFoundMiddleware(): BackendRequestHandler {
5
5
  return (req, res) => {
@@ -1,4 +1,4 @@
1
- import { BackendRequestHandler } from './server.model'
1
+ import type { BackendRequestHandler } from './server.model'
2
2
 
3
3
  export function okMiddleware(): BackendRequestHandler {
4
4
  return (_req, res) => {
@@ -1,6 +1,6 @@
1
- import { CommonLogLevel } from '@naturalcycles/js-lib'
1
+ import type { CommonLogLevel } from '@naturalcycles/js-lib'
2
2
  import { boldGrey, green, red, yellow } from '@naturalcycles/nodejs-lib'
3
- import { BackendRequest } from './server.model'
3
+ import type { BackendRequest } from './server.model'
4
4
 
5
5
  export function logRequest(req: BackendRequest, statusCode: number, ...tokens: any[]): void {
6
6
  req[logLevel(statusCode)](
@@ -1,4 +1,4 @@
1
- import { BackendRequest } from './server.model'
1
+ import type { BackendRequest } from './server.model'
2
2
 
3
3
  /**
4
4
  * Returns e.g:
@@ -1,12 +1,7 @@
1
- import { _ms, AppError, NumberOfSeconds } from '@naturalcycles/js-lib'
2
- import {
3
- BackendRequest,
4
- BackendRequestHandler,
5
- BackendResponse,
6
- getRequestEndpoint,
7
- onFinished,
8
- respondWithError,
9
- } from '../index'
1
+ import type { NumberOfSeconds } from '@naturalcycles/js-lib'
2
+ import { _ms, AppError } from '@naturalcycles/js-lib'
3
+ import type { BackendRequest, BackendRequestHandler, BackendResponse } from '../index'
4
+ import { getRequestEndpoint, onFinished, respondWithError } from '../index'
10
5
 
11
6
  export interface RequestTimeoutMiddlewareCfg {
12
7
  /**
@@ -1,5 +1,5 @@
1
1
  import { _safeJsonStringify } from '@naturalcycles/js-lib'
2
- import { BackendRequestHandler, BackendResponse } from './server.model'
2
+ import type { BackendRequestHandler, BackendResponse } from './server.model'
3
3
 
4
4
  /**
5
5
  * Replaces express's built-in req.json() function with the safe one,
@@ -1,6 +1,6 @@
1
- import { Server } from 'node:http'
2
- import { Socket } from 'node:net'
3
- import { StringMap } from '@naturalcycles/js-lib'
1
+ import type { Server } from 'node:http'
2
+ import type { Socket } from 'node:net'
3
+ import type { StringMap } from '@naturalcycles/js-lib'
4
4
 
5
5
  export interface DestroyableServer extends Server {
6
6
  destroy: () => Promise<void>
@@ -1,3 +1,4 @@
1
+ import type { StringMap } from '@naturalcycles/js-lib'
1
2
  import {
2
3
  _get,
3
4
  _mapValues,
@@ -9,9 +10,9 @@ import {
9
10
  _stringMapValues,
10
11
  _sum,
11
12
  NumberStack,
12
- StringMap,
13
13
  } from '@naturalcycles/js-lib'
14
- import { BackendRequestHandler, onFinished } from '../index'
14
+ import type { BackendRequestHandler } from '../index'
15
+ import { onFinished } from '../index'
15
16
  import { getRequestEndpoint } from './request.util'
16
17
 
17
18
  const { GAE_INSTANCE } = process.env
@@ -1,7 +1,7 @@
1
1
  import { _filterNullishValues, localTime } from '@naturalcycles/js-lib'
2
2
  import { memoryUsageFull, processSharedUtil } from '@naturalcycles/nodejs-lib'
3
3
  import { getDeployInfo } from './deployInfo.util'
4
- import { BackendRequestHandler } from './server.model'
4
+ import type { BackendRequestHandler } from './server.model'
5
5
 
6
6
  const { versions, arch, platform } = process
7
7
  const { GAE_APPLICATION, GAE_SERVICE, GAE_VERSION, K_SERVICE, K_REVISION, APP_ENV, NODE_OPTIONS } =
@@ -1,6 +1,8 @@
1
- import { _since, UnixTimestampMillis } from '@naturalcycles/js-lib'
1
+ import type { UnixTimestampMillis } from '@naturalcycles/js-lib'
2
+ import { _since } from '@naturalcycles/js-lib'
2
3
  import { boldGrey, dimGrey } from '@naturalcycles/nodejs-lib'
3
- import { BackendRequestHandler, onFinished } from '../index'
4
+ import type { BackendRequestHandler } from '../index'
5
+ import { onFinished } from '../index'
4
6
  import { logRequest } from './request.log.util'
5
7
 
6
8
  const { APP_ENV } = process.env
@@ -1,7 +1,7 @@
1
- import { Server } from 'node:http'
2
- import { SentrySharedService } from '../sentry/sentry.shared.service'
3
- import { DefaultAppCfg } from './createDefaultApp.model'
4
- import { BackendApplication } from './server.model'
1
+ import type { Server } from 'node:http'
2
+ import type { SentrySharedService } from '../sentry/sentry.shared.service'
3
+ import type { DefaultAppCfg } from './createDefaultApp.model'
4
+ import type { BackendApplication } from './server.model'
5
5
 
6
6
  /**
7
7
  * If DefaultAppCfg.resources is passed and `expressApp` is not passed - it will call createDefaultApp(cfg).
@@ -1,9 +1,9 @@
1
- import { Server } from 'node:http'
1
+ import type { Server } from 'node:http'
2
2
  import os from 'node:os'
3
3
  import { _Memo, _ms } from '@naturalcycles/js-lib'
4
4
  import { boldGrey, dimGrey, white } from '@naturalcycles/nodejs-lib'
5
5
  import { createDefaultApp } from '../index'
6
- import { StartServerCfg, StartServerData } from './startServer.model'
6
+ import type { StartServerCfg, StartServerData } from './startServer.model'
7
7
 
8
8
  const { NODE_OPTIONS, APP_ENV } = process.env
9
9
 
@@ -1,7 +1,9 @@
1
- import { _get, AppError, JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib'
2
- import { AjvSchema, AjvValidationError } from '@naturalcycles/nodejs-lib'
3
- import { BackendRequestHandler } from '../server.model'
4
- import { ReqValidationOptions } from './validateRequest'
1
+ import type { JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib'
2
+ import { _get, AppError } from '@naturalcycles/js-lib'
3
+ import type { AjvValidationError } from '@naturalcycles/nodejs-lib'
4
+ import { AjvSchema } from '@naturalcycles/nodejs-lib'
5
+ import type { BackendRequestHandler } from '../server.model'
6
+ import type { ReqValidationOptions } from './validateRequest'
5
7
 
6
8
  const REDACTED = 'REDACTED'
7
9
 
@@ -52,7 +54,7 @@ function validateObject(
52
54
  typeof opt.report === 'function' ? opt.report : () => opt.report as boolean | undefined
53
55
 
54
56
  return (req, _res, next) => {
55
- const error = ajvSchema.getValidationError(req[prop])
57
+ const error = ajvSchema.getValidationError(req[prop] || {})
56
58
  if (error) {
57
59
  const report = reportPredicate(error)
58
60
 
@@ -1,6 +1,7 @@
1
1
  import { _get, AppError } from '@naturalcycles/js-lib'
2
- import { AnySchema, getValidationResult, JoiValidationError } from '@naturalcycles/nodejs-lib'
3
- import { BackendRequest } from '../server.model'
2
+ import type { AnySchema, JoiValidationError } from '@naturalcycles/nodejs-lib'
3
+ import { getValidationResult } from '@naturalcycles/nodejs-lib'
4
+ import type { BackendRequest } from '../server.model'
4
5
 
5
6
  const REDACTED = 'REDACTED'
6
7
 
@@ -89,7 +90,11 @@ class ValidateRequest {
89
90
  schema: AnySchema<T>,
90
91
  opt: ReqValidationOptions<JoiValidationError> = {},
91
92
  ): T {
92
- const { value, error } = getValidationResult(req[reqProperty], schema, `request ${reqProperty}`)
93
+ const { value, error } = getValidationResult(
94
+ req[reqProperty] || {},
95
+ schema,
96
+ `request ${reqProperty}`,
97
+ )
93
98
  if (error) {
94
99
  let report: boolean | undefined
95
100
  if (typeof opt.report === 'boolean') {
@@ -1,6 +1,8 @@
1
- import { _get, AppError, ZodSchema, ZodValidationError, zSafeValidate } from '@naturalcycles/js-lib'
2
- import { BackendRequestHandler } from '../server.model'
3
- import { ReqValidationOptions } from './validateRequest'
1
+ import { _get, AppError } from '@naturalcycles/js-lib'
2
+ import type { ZodSchema, ZodValidationError } from '@naturalcycles/js-lib/dist/zod/index.js'
3
+ import { zSafeValidate } from '@naturalcycles/js-lib/dist/zod/index.js'
4
+ import type { BackendRequestHandler } from '../server.model'
5
+ import type { ReqValidationOptions } from './validateRequest'
4
6
 
5
7
  const REDACTED = 'REDACTED'
6
8
 
@@ -19,7 +21,7 @@ export function zodReqValidate(
19
21
  typeof opt.report === 'function' ? opt.report : () => opt.report as boolean | undefined
20
22
 
21
23
  return (req, _res, next) => {
22
- const { error } = zSafeValidate(req[prop], schema)
24
+ const { error } = zSafeValidate(req[prop] || {}, schema)
23
25
  if (!error) {
24
26
  return next()
25
27
  }
@@ -1,8 +1,10 @@
1
- import { Server } from 'node:http'
2
- import { AddressInfo } from 'node:net'
3
- import { Fetcher, FetcherOptions, FetchFunction, getFetcher, pDelay } from '@naturalcycles/js-lib'
4
- import { BackendApplication, createDefaultApp, DefaultAppCfg } from '../index'
5
- import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model'
1
+ import type { Server } from 'node:http'
2
+ import type { AddressInfo } from 'node:net'
3
+ import type { Fetcher, FetcherOptions, FetchFunction } from '@naturalcycles/js-lib'
4
+ import { getFetcher, pDelay } from '@naturalcycles/js-lib'
5
+ import type { BackendApplication, DefaultAppCfg } from '../index'
6
+ import { createDefaultApp } from '../index'
7
+ import type { BackendRequestHandlerCfg } from '../server/createDefaultApp.model'
6
8
 
7
9
  const nativeFetchFn: FetchFunction = async (url, init) => await globalThis.fetch(url, init)
8
10
 
@@ -1,4 +1,5 @@
1
- import { ExpressApp, expressTestService } from './express.test.service'
1
+ import type { ExpressApp } from './express.test.service'
2
+ import { expressTestService } from './express.test.service'
2
3
 
3
4
  export type { ExpressApp }
4
5