allserver 1.0.0 → 1.1.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.
package/Allserver.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("./src/server/Allserver");
@@ -0,0 +1 @@
1
+ module.exports = require("./src/client/ClientTransport");
package/README.md CHANGED
@@ -277,7 +277,7 @@ Allserver({
277
277
  You'd need to deal with node.js `res` yourself.
278
278
 
279
279
  ```js
280
- const procedires = {
280
+ const procedures = {
281
281
  processEntity({ someEntity }, ctx) {
282
282
  const res = ctx.http.res;
283
283
  res.statusCode = 422;
@@ -293,7 +293,7 @@ const procedires = {
293
293
  Occasionally, your HTTP method would need to access raw body of a request. This is how you do it:
294
294
 
295
295
  ```js
296
- const procedires = {
296
+ const procedures = {
297
297
  async processEntity(_, ctx) {
298
298
  const micro = ctx.allserver.transport.micro; // same as require("micro")
299
299
  const req = ctx.http.req; // node.js Request
package/Transport.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("./src/server/Transport");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "allserver",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Multi-protocol simple RPC server and [optional] client. Boilerplate-less. Opinionated. Minimalistic. DX-first.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -5,6 +5,9 @@ module.exports = {
5
5
  get Allserver() {
6
6
  return require("./server/Allserver");
7
7
  },
8
+ get Transport() {
9
+ return require("./server/Transport");
10
+ },
8
11
  get HttpTransport() {
9
12
  return require("./server/HttpTransport");
10
13
  },
@@ -20,10 +23,13 @@ module.exports = {
20
23
  get AllserverClient() {
21
24
  return require("./client/AllserverClient");
22
25
  },
23
- get GrpcClientTransport() {
24
- return require("./client/GrpcClientTransport");
26
+ get ClientTransport() {
27
+ return require("./client/ClientTransport");
25
28
  },
26
29
  get HttpClientTransport() {
27
30
  return require("./client/HttpClientTransport");
28
31
  },
32
+ get GrpcClientTransport() {
33
+ return require("./client/GrpcClientTransport");
34
+ },
29
35
  };
@@ -65,11 +65,12 @@ module.exports = require("stampit")({
65
65
  try {
66
66
  result = await ctx.procedure(ctx.arg, ctx);
67
67
  } catch (err) {
68
- this.logger.error("ALLSERVER_PROCEDURE_ERROR", err);
68
+ const code = err.code || "ALLSERVER_PROCEDURE_ERROR"
69
+ this.logger.error(code, err);
69
70
  ctx.error = err;
70
71
  ctx.result = {
71
72
  success: false,
72
- code: err.code || "ALLSERVER_PROCEDURE_ERROR",
73
+ code,
73
74
  message: `'${err.message}' error in '${ctx.procedureName}' procedure`,
74
75
  };
75
76
  await this.transport.prepareProcedureErrorReply(ctx);
@@ -102,11 +103,12 @@ module.exports = require("stampit")({
102
103
  break;
103
104
  }
104
105
  } catch (err) {
105
- this.logger.error("ALLSERVER_MIDDLEWARE_ERROR", err);
106
+ const code = err.code || "ALLSERVER_MIDDLEWARE_ERROR";
107
+ this.logger.error(code, err);
106
108
  ctx.error = err;
107
109
  ctx.result = {
108
110
  success: false,
109
- code: err.code || "ALLSERVER_MIDDLEWARE_ERROR",
111
+ code,
110
112
  message: `'${err.message}' error in '${middlewareType}' middleware`,
111
113
  };
112
114
  return;
@@ -13,7 +13,7 @@ module.exports = require("./Transport").compose({
13
13
  },
14
14
 
15
15
  methods: {
16
- async _deserializeRequest(ctx) {
16
+ async deserializeRequest(ctx) {
17
17
  const bodyBuffer = await this.micro.buffer(ctx.http.req);
18
18
  let arg = ctx.http.query;
19
19
  try {
@@ -27,7 +27,7 @@ module.exports = require("./Transport").compose({
27
27
  },
28
28
 
29
29
  async _handleRequest(ctx) {
30
- if (await this._deserializeRequest(ctx)) {
30
+ if (await this.deserializeRequest(ctx)) {
31
31
  await ctx.allserver.handleCall(ctx);
32
32
  } else {
33
33
  // HTTP protocol request was malformed (not expected structure).
@@ -10,7 +10,7 @@ module.exports = require("./Transport").compose({
10
10
  },
11
11
 
12
12
  methods: {
13
- async _deserializeRequest(ctx) {
13
+ async deserializeRequest(ctx) {
14
14
  const body = ctx.lambda.event.body;
15
15
  let arg = ctx.lambda.query;
16
16
  try {
@@ -24,7 +24,7 @@ module.exports = require("./Transport").compose({
24
24
  },
25
25
 
26
26
  async _handleRequest(ctx) {
27
- if (await this._deserializeRequest(ctx)) {
27
+ if (await this.deserializeRequest(ctx)) {
28
28
  await ctx.allserver.handleCall(ctx);
29
29
  } else {
30
30
  // HTTP protocol request was malformed (not expected structure).