@hybridless/hybridless 0.0.84-alpha20 → 0.0.84-alpha21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridless/hybridless",
3
- "version": "0.0.84-alpha20",
3
+ "version": "0.0.84-alpha21",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -7,7 +7,7 @@ COPY proxy.js /usr/src/hybridless-runtime/proxy.js
7
7
  # Set the working directory
8
8
  WORKDIR /usr/src/app
9
9
 
10
- RUN cd /usr/src/hybridless-runtime/ && npm i -S @hybridless/runtime-nodejs-httpd@latest
10
+ RUN cd /usr/src/hybridless-runtime/ && npm i -S cuid
11
11
 
12
12
  # Run the specified command within the container.
13
13
  ENTRYPOINT ["node", "../hybridless-runtime/proxy.js"]
@@ -7,7 +7,7 @@ COPY proxy.js /usr/src/hybridless-runtime/proxy.js
7
7
  # Set the working directory
8
8
  WORKDIR /usr/src/app
9
9
 
10
- RUN cd /usr/src/hybridless-runtime/ && npm i -S @hybridless/runtime-nodejs-httpd@latest
10
+ RUN cd /usr/src/hybridless-runtime/ && npm i -S cuid
11
11
 
12
12
  # Run the specified command within the container.
13
13
  ENTRYPOINT ["node", "../hybridless-runtime/proxy.js"]
@@ -7,7 +7,7 @@ COPY proxy.js /usr/src/hybridless-runtime/proxy.js
7
7
  # Set the working directory
8
8
  WORKDIR /usr/src/app
9
9
 
10
- RUN cd /usr/src/hybridless-runtime/ && npm i -S @hybridless/runtime-nodejs-httpd@latest
10
+ RUN cd /usr/src/hybridless-runtime/ && npm i -S cuid
11
11
 
12
12
  # Run the specified command within the container.
13
13
  ENTRYPOINT ["node", "../hybridless-runtime/proxy.js"]
@@ -5,23 +5,40 @@ process.on('SIGINT', function() {
5
5
  });
6
6
  //Execution scope
7
7
  (async () => {
8
+ //
8
9
  try {
10
+ const cuid = require('cuid');
11
+ //helper
12
+ function _buildContext(callback) {
13
+ return {
14
+ awsRequestId: `${cuid()}-${cuid()}`,
15
+ callbackWaitsForEmptyEventLoop: true,
16
+ getRemainingTimeInMillis: () => { return 0; },
17
+ done: (err, data) => callback(err, data),
18
+ fail: (err) => callback(err),
19
+ succeed: (res) => callback(null, res),
20
+ };
21
+ }
22
+ async function invoke(functionPath, input) {
23
+ return new Promise((resolve) => {
24
+ //Invoke
25
+ const context = _buildContext((err, data) => {
26
+ resolve({ err, data });
27
+ });
28
+ const resp = await (require(`${functionPath}`)[process.env.ENTRYPOINT_FUNC](input, context));
29
+ if (resp) resolve({data: resp}); //indicates sync content
30
+ });
31
+ }
9
32
  //Get inputs
10
33
  let input = {};
11
34
  console.debug(process.argv);
12
35
  try { input = JSON.parse(process.argv[2]); }
13
36
  catch (e) { console.log('[Hybridless Runtime] - Error while decoding inputEvent parameter!', e); }
14
-
15
- //Init lambda event and call it
16
- const LambdaEvent = require("@hybridless/runtime-nodejs-httpd").LambdaEvent;
17
- const functionPath = `${__dirname}/../app/${process.env.ENTRYPOINT}`;
18
- const lambda = new LambdaEvent({ payload: input }, functionPath, process.env.ENTRYPOINT_FUNC);
19
- //Callout
20
- const resp = await lambda.invoke();
21
-
37
+ //Invoke
38
+ const resp = await invoke(functionPath, input);
22
39
  //Return
23
40
  console.debug(resp);
24
- if (resp.getCode && resp.getCode() == 200) process.exit(0);
41
+ if (!resp.err && resp.data && resp.data.statusCode == 200) process.exit(0);
25
42
  else process.exit(1);
26
43
  } catch (e) {
27
44
  console.error(e);