@naturalcycles/backend-lib 3.0.0 → 3.4.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.
@@ -7,7 +7,7 @@ const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
7
7
  const time_lib_1 = require("@naturalcycles/time-lib");
8
8
  const yaml = require("js-yaml");
9
9
  const APP_YAML_DEFAULT = () => ({
10
- runtime: 'nodejs14',
10
+ runtime: 'nodejs16',
11
11
  service: 'default',
12
12
  inbound_services: ['warmup'],
13
13
  instance_class: 'F1',
@@ -47,6 +47,7 @@ const DEFAULT_FILES = [
47
47
  'tsconfig.dist.json',
48
48
  '.gcloudignore',
49
49
  'app.yaml',
50
+ 'patches', // to allow patch-package
50
51
  ];
51
52
  const defaultFilesDir = `${paths_cnst_1.srcDir}/deploy/files-default`;
52
53
  async function deployPrepare(opt = {}) {
@@ -1,2 +1,2 @@
1
1
  import type { DeployInfo } from '../deploy';
2
- export declare const getDeployInfo: ((projectDir: string) => DeployInfo) & import("@naturalcycles/js-lib/dist/decorators/memoFn").MemoizedFunction;
2
+ export declare const getDeployInfo: ((projectDir: string) => DeployInfo) & import("@naturalcycles/js-lib").MemoizedFunction;
@@ -36,7 +36,12 @@ exports.genericErrorMiddleware = genericErrorMiddleware;
36
36
  function respondWithError(req, res, err) {
37
37
  var _a, _b;
38
38
  const { headersSent } = res;
39
- req.error(`genericErrorHandler${headersSent ? ' after headersSent' : ''}:\n`, err);
39
+ if (headersSent) {
40
+ req.error(`after headersSent`, err);
41
+ }
42
+ else {
43
+ req.error(err);
44
+ }
40
45
  const originalError = (0, js_lib_1._anyToError)(err, Error, {
41
46
  stringifyFn: nodejs_lib_1.inspectAnyStringifyFn,
42
47
  });
@@ -1,13 +1,13 @@
1
- import { Got } from '@naturalcycles/nodejs-lib';
1
+ import { GetGotOptions, Got } from '@naturalcycles/nodejs-lib';
2
2
  import { BackendApplication } from '../index';
3
3
  import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model';
4
4
  export interface ExpressApp extends Got {
5
5
  close(): Promise<void>;
6
6
  }
7
7
  declare class ExpressTestService {
8
- createAppFromResource(resource: BackendRequestHandlerCfg): ExpressApp;
9
- createAppFromResources(resources: BackendRequestHandlerCfg[]): ExpressApp;
10
- createApp(app: BackendApplication): ExpressApp;
8
+ createAppFromResource(resource: BackendRequestHandlerCfg, opt?: GetGotOptions): ExpressApp;
9
+ createAppFromResources(resources: BackendRequestHandlerCfg[], opt?: GetGotOptions): ExpressApp;
10
+ createApp(app: BackendApplication, opt?: GetGotOptions): ExpressApp;
11
11
  /**
12
12
  * Creates a "Default Express App" with provided resources.
13
13
  * Starts an http server on '127.0.0.1' and random available port.
@@ -9,17 +9,17 @@ const index_1 = require("../index");
9
9
  // await app.close()
10
10
  // })
11
11
  class ExpressTestService {
12
- createAppFromResource(resource) {
12
+ createAppFromResource(resource, opt) {
13
13
  return this.createApp((0, index_1.createDefaultApp)({
14
14
  resources: [resource],
15
- }));
15
+ }), opt);
16
16
  }
17
- createAppFromResources(resources) {
17
+ createAppFromResources(resources, opt) {
18
18
  return this.createApp((0, index_1.createDefaultApp)({
19
19
  resources,
20
- }));
20
+ }), opt);
21
21
  }
22
- createApp(app) {
22
+ createApp(app, opt) {
23
23
  const server = this.createTestServer(app);
24
24
  const { port } = server.address();
25
25
  const prefixUrl = `http://127.0.0.1:${port}`;
@@ -27,6 +27,9 @@ class ExpressTestService {
27
27
  prefixUrl,
28
28
  responseType: 'json',
29
29
  retry: 0,
30
+ logStart: true,
31
+ logFinished: true,
32
+ ...opt,
30
33
  });
31
34
  got.close = async () => {
32
35
  await new Promise(resolve => server.close(resolve));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "3.0.0",
3
+ "version": "3.4.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install && patch-package",
6
6
  "serve": "APP_ENV=dev nodemon",
@@ -45,7 +45,6 @@
45
45
  "@types/ejs": "^3.0.0",
46
46
  "@types/js-yaml": "^4.0.0",
47
47
  "@types/node": "^16.4.1",
48
- "esbuild": "^0.13.13",
49
48
  "esbuild-register": "^3.1.2",
50
49
  "fastify": "^3.20.1",
51
50
  "jest": "^27.0.1",
@@ -8,7 +8,7 @@ import { BackendCfg } from './backend.cfg.util'
8
8
  import { AppYaml, DeployInfo } from './deploy.model'
9
9
 
10
10
  const APP_YAML_DEFAULT = (): AppYaml => ({
11
- runtime: 'nodejs14',
11
+ runtime: 'nodejs16',
12
12
  service: 'default',
13
13
  inbound_services: ['warmup'],
14
14
  instance_class: 'F1',
@@ -59,6 +59,7 @@ const DEFAULT_FILES = [
59
59
  'tsconfig.dist.json',
60
60
  '.gcloudignore',
61
61
  'app.yaml',
62
+ 'patches', // to allow patch-package
62
63
  ]
63
64
 
64
65
  const defaultFilesDir = `${srcDir}/deploy/files-default`
@@ -53,7 +53,11 @@ export function genericErrorMiddleware(
53
53
  export function respondWithError(req: BackendRequest, res: BackendResponse, err: any): void {
54
54
  const { headersSent } = res
55
55
 
56
- req.error(`genericErrorHandler${headersSent ? ' after headersSent' : ''}:\n`, err)
56
+ if (headersSent) {
57
+ req.error(`after headersSent`, err)
58
+ } else {
59
+ req.error(err)
60
+ }
57
61
 
58
62
  const originalError = _anyToError(err, Error, {
59
63
  stringifyFn: inspectAnyStringifyFn,
@@ -1,6 +1,6 @@
1
1
  import { Server } from 'http'
2
2
  import { AddressInfo } from 'net'
3
- import { getGot, Got } from '@naturalcycles/nodejs-lib'
3
+ import { getGot, GetGotOptions, Got } from '@naturalcycles/nodejs-lib'
4
4
  import { BackendApplication, createDefaultApp } from '../index'
5
5
  import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model'
6
6
 
@@ -15,23 +15,25 @@ export interface ExpressApp extends Got {
15
15
  // })
16
16
 
17
17
  class ExpressTestService {
18
- createAppFromResource(resource: BackendRequestHandlerCfg): ExpressApp {
18
+ createAppFromResource(resource: BackendRequestHandlerCfg, opt?: GetGotOptions): ExpressApp {
19
19
  return this.createApp(
20
20
  createDefaultApp({
21
21
  resources: [resource],
22
22
  }),
23
+ opt,
23
24
  )
24
25
  }
25
26
 
26
- createAppFromResources(resources: BackendRequestHandlerCfg[]): ExpressApp {
27
+ createAppFromResources(resources: BackendRequestHandlerCfg[], opt?: GetGotOptions): ExpressApp {
27
28
  return this.createApp(
28
29
  createDefaultApp({
29
30
  resources,
30
31
  }),
32
+ opt,
31
33
  )
32
34
  }
33
35
 
34
- createApp(app: BackendApplication): ExpressApp {
36
+ createApp(app: BackendApplication, opt?: GetGotOptions): ExpressApp {
35
37
  const server = this.createTestServer(app)
36
38
  const { port } = server.address() as AddressInfo
37
39
  const prefixUrl = `http://127.0.0.1:${port}`
@@ -40,6 +42,9 @@ class ExpressTestService {
40
42
  prefixUrl,
41
43
  responseType: 'json',
42
44
  retry: 0,
45
+ logStart: true,
46
+ logFinished: true,
47
+ ...opt,
43
48
  }) as ExpressApp
44
49
 
45
50
  got.close = async () => {