@swydo/byol 2.0.11 → 2.0.14

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 CHANGED
@@ -3,12 +3,36 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## 2.0.11 (2021-10-13)
6
+ ## 2.0.14 (2022-04-04)
7
7
 
8
8
 
9
9
  ### Bug Fixes
10
10
 
11
- * **byol-cli:** fix invoke command when passing template or env path ([#291](https://github.com/Swydo/byol/issues/291)) ([29f97e3](https://github.com/Swydo/byol/commit/29f97e329c633273004c264399266d607a25f5c2))
11
+ * **byol:** add timeout delay to print all the logs ([#356](https://github.com/Swydo/byol/issues/356)) ([937393b](https://github.com/Swydo/byol/commit/937393bed0bd8c88e4776619d27f954e7077cc71))
12
+
13
+
14
+
15
+
16
+
17
+ ## 2.0.13 (2021-10-25)
18
+
19
+ **Note:** Version bump only for package @swydo/byol
20
+
21
+
22
+
23
+
24
+
25
+ ## 2.0.12 (2021-10-13)
26
+
27
+ **Note:** Version bump only for package @swydo/byol
28
+
29
+
30
+
31
+
32
+
33
+ ## 2.0.11 (2021-10-13)
34
+
35
+ **Note:** Version bump only for package @swydo/byol
12
36
 
13
37
 
14
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swydo/byol",
3
- "version": "2.0.11",
3
+ "version": "2.0.14",
4
4
  "description": "Bring Your Own Lambda",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -27,5 +27,5 @@
27
27
  "peerDependencies": {
28
28
  "aws-xray-sdk-core": "^3.0.0"
29
29
  },
30
- "gitHead": "29f97e329c633273004c264399266d607a25f5c2"
30
+ "gitHead": "937393bed0bd8c88e4776619d27f954e7077cc71"
31
31
  }
@@ -17,7 +17,7 @@ function hasXRay() {
17
17
  }
18
18
 
19
19
  async function execute(handler, event, awsContext) {
20
- return new Promise(((resolve, reject) => {
20
+ const handlerResult = await new Promise(((resolve, reject) => {
21
21
  const maybePromise = handler(event, awsContext, (err, res) => {
22
22
  if (err) {
23
23
  reject(err);
@@ -36,6 +36,12 @@ async function execute(handler, event, awsContext) {
36
36
  .catch((err) => reject(err));
37
37
  }
38
38
  }));
39
+
40
+ // Timeout delay is required in order to print console logs
41
+ // that are omitted otherwise
42
+ await new Promise((resolve) => setTimeout(resolve, 10));
43
+
44
+ return handlerResult;
39
45
  }
40
46
 
41
47
  async function executeWithXRay(segmentName, handler, event, awsContext) {
@@ -45,6 +45,7 @@ async function invokeFunction(functionName, event, {
45
45
  requestId,
46
46
  keepAlive = false,
47
47
  profile = 'default',
48
+ invocationType = 'RequestResponse',
48
49
  } = {}) {
49
50
  const resource = getFunctionResource(templatePath, functionName);
50
51
  const environment = {
@@ -55,7 +56,6 @@ async function invokeFunction(functionName, event, {
55
56
  Properties: {
56
57
  Handler: handler,
57
58
  CodeUri: codeUri = '.',
58
- EventInvokeConfig: eventInvokeConfig,
59
59
  },
60
60
  } = resource;
61
61
 
@@ -74,17 +74,13 @@ async function invokeFunction(functionName, event, {
74
74
  };
75
75
 
76
76
  let result;
77
- let invocationType;
78
-
79
- if (eventInvokeConfig) {
77
+ if (invocationType === 'Event') {
80
78
  invokeHandler(options);
81
- invocationType = 'Event';
82
79
  } else {
83
80
  result = await invokeHandler(options);
84
- invocationType = 'RequestResponse';
85
81
  }
86
82
 
87
- return { result, invocationType };
83
+ return { result };
88
84
  }
89
85
 
90
86
  module.exports = {
@@ -28,7 +28,7 @@ describe('invokeFunction', function () {
28
28
  foo: 'foo',
29
29
  };
30
30
 
31
- const { result, invocationType } = await invokeFunction(
31
+ const { result } = await invokeFunction(
32
32
  'GoodFunction',
33
33
  event,
34
34
  { templatePath },
@@ -37,7 +37,6 @@ describe('invokeFunction', function () {
37
37
  expect(result).to.be.an('object');
38
38
  expect(result).to.have.property('env');
39
39
  expect(result).to.have.property('args');
40
- expect(invocationType).to.equal('RequestResponse');
41
40
  });
42
41
 
43
42
  it('invokes the non-async function\'s handler', async function () {
@@ -46,7 +45,7 @@ describe('invokeFunction', function () {
46
45
  foo: 'foo',
47
46
  };
48
47
 
49
- const { result, invocationType } = await invokeFunction(
48
+ const { result } = await invokeFunction(
50
49
  'GoodCallbackFunction',
51
50
  event,
52
51
  { templatePath },
@@ -55,7 +54,6 @@ describe('invokeFunction', function () {
55
54
  expect(result).to.be.an('object');
56
55
  expect(result).to.have.property('env');
57
56
  expect(result).to.have.property('args');
58
- expect(invocationType).to.equal('RequestResponse');
59
57
  });
60
58
 
61
59
  it('invokes the function\'s handler with the given event', async function () {
@@ -64,7 +62,7 @@ describe('invokeFunction', function () {
64
62
  foo: 'foo',
65
63
  };
66
64
 
67
- const { result, invocationType } = await invokeFunction(
65
+ const { result } = await invokeFunction(
68
66
  'GoodFunction',
69
67
  event,
70
68
  { templatePath },
@@ -73,7 +71,6 @@ describe('invokeFunction', function () {
73
71
  expect(result).to.be.an('object');
74
72
  expect(result).to.have.property('env');
75
73
  expect(result).to.have.property('args');
76
- expect(invocationType).to.equal('RequestResponse');
77
74
 
78
75
  const { args } = result;
79
76
  expect(args).to.be.an('array').with.length(2);
@@ -86,7 +83,7 @@ describe('invokeFunction', function () {
86
83
  foo: 'foo',
87
84
  };
88
85
 
89
- const { result, invocationType } = await invokeFunction(
86
+ const { result } = await invokeFunction(
90
87
  'GoodFunction',
91
88
  event,
92
89
  { templatePath },
@@ -95,7 +92,6 @@ describe('invokeFunction', function () {
95
92
  expect(result).to.be.an('object');
96
93
  expect(result).to.have.property('env');
97
94
  expect(result).to.have.property('args');
98
- expect(invocationType).to.equal('RequestResponse');
99
95
 
100
96
  const { args } = result;
101
97
  expect(args).to.be.an('array').with.length(2);
@@ -107,7 +103,7 @@ describe('invokeFunction', function () {
107
103
  const envPath = path.resolve(__dirname, '../tests/assets/goodEnv.json');
108
104
  const event = {};
109
105
 
110
- const { result, invocationType } = await invokeFunction(
106
+ const { result } = await invokeFunction(
111
107
  'GoodFunction',
112
108
  event,
113
109
  { templatePath, envPath },
@@ -116,7 +112,6 @@ describe('invokeFunction', function () {
116
112
  expect(result).to.be.an('object');
117
113
  expect(result).to.have.property('env');
118
114
  expect(result).to.have.property('args');
119
- expect(invocationType).to.equal('RequestResponse');
120
115
 
121
116
  const { env } = result;
122
117
  expect(env).to.have.property('FOO', 'FOO');
@@ -161,13 +156,13 @@ describe('invokeFunction', function () {
161
156
  foo: 'foo',
162
157
  };
163
158
 
164
- const { invocationType } = await invokeFunction(
159
+ const { result } = await invokeFunction(
165
160
  'GoodAcyncFunction',
166
161
  event,
167
- { templatePath },
162
+ { templatePath, invocationType: 'Event' },
168
163
  );
169
164
 
170
- expect(invocationType).to.equal('Event');
165
+ expect(result).to.be.equal(undefined);
171
166
  });
172
167
 
173
168
  it('rejects when an error is thrown by the handler', async function () {