allserver 2.4.0 → 2.5.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/README.md CHANGED
@@ -6,8 +6,11 @@ Think of Remote Procedure Calls using exactly the same client and server code bu
6
6
 
7
7
  Should be used in (micro)services where JavaScript is able to run - your computer, Docker, k8s, virtual machines, serverless functions (Lambdas, Google Cloud Functions, Azure Functions, etc), RaspberryPI, SharedWorker, thread, you name it.
8
8
 
9
+ > Uber [moved](https://www.infoq.com/news/2023/10/uber-up-cloud-microservices/) most of its containerized microservices from µDeploy to a new multi-cloud platform named Up in preparation for migrating a considerable portion of its compute footprint to the cloud. **The company spent two years** working on making its many microservices portable to migrate between different computing infrastructures and container management platforms.
10
+
9
11
  Superpowers the `Allserver` gives you:
10
12
 
13
+ - Move your code around infrastructures, deployment types, runtimes, platforms, etc with ease.
11
14
  - Call gRPC server methods from browser/curl/Postman.
12
15
  - Run your HTTP server as gRPC with a single line change (almost).
13
16
  - Serve same logic via HTTP and gRPC (or more) simultaneously in the same node.js process.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "allserver",
3
- "version": "2.4.0",
3
+ "version": "2.5.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": {
@@ -203,8 +203,8 @@ module.exports = require("stampit")({
203
203
  this[p].transport = getTransport()({ uri });
204
204
  }
205
205
 
206
- if (before) this[p].before = [].concat(before).concat(this[p].before);
207
- if (after) this[p].after = [].concat(after).concat(this[p].after);
206
+ if (before) this[p].before = [].concat(this[p].before).concat(before).filter(isFunction);
207
+ if (after) this[p].after = [].concat(this[p].after).concat(after).filter(isFunction);
208
208
  },
209
209
 
210
210
  methods: {
@@ -335,8 +335,9 @@ module.exports = require("stampit")({
335
335
  before,
336
336
  after,
337
337
  } = {}) {
338
- if (before) before = [].concat(before);
339
- if (after) after = [].concat(after);
338
+ if (before != null) before = (Array.isArray(before) ? before : [before]).filter(isFunction);
339
+ if (after != null) after = (Array.isArray(after) ? after : [after]).filter(isFunction);
340
+
340
341
  return this.deepProps({
341
342
  [p]: {
342
343
  transport,
@@ -41,7 +41,7 @@ module.exports = require("./ClientTransport").compose({
41
41
  });
42
42
  if (typeof promise.promise === "function") promise = promise.promise(); // AWS SDK v2 adoption
43
43
  const invocationResponse = await promise;
44
- return JSON.parse(invocationResponse.Payload);
44
+ return JSON.parse(Buffer.from(invocationResponse.Payload));
45
45
  },
46
46
 
47
47
  createCallContext(defaultCtx) {
@@ -1,17 +1,20 @@
1
1
  const assert = require("assert");
2
2
 
3
- const { isObject, isBoolean, isFunction } = require("../util");
3
+ const { isObject, isBoolean, isFunction, uniq } = require("../util");
4
4
 
5
5
  module.exports = require("stampit")({
6
6
  name: "Allserver",
7
7
 
8
+ deepProps: {
9
+ before: null,
10
+ after: null,
11
+ },
12
+
8
13
  props: {
9
14
  procedures: {},
10
15
  transport: null,
11
16
  logger: console,
12
17
  introspection: true,
13
- before: null,
14
- after: null,
15
18
 
16
19
  callsCount: 0,
17
20
  },
@@ -21,8 +24,8 @@ module.exports = require("stampit")({
21
24
  this.transport = transport || this.transport || require("./HttpTransport")();
22
25
  this.logger = logger || this.logger;
23
26
  this.introspection = introspection != null ? introspection : this.introspection;
24
- this.before = before || this.before;
25
- this.after = after || this.after;
27
+ if (before) this.before = uniq([].concat(this.before).concat(before).filter(isFunction));
28
+ if (after) this.after = uniq([].concat(this.after).concat(after).filter(isFunction));
26
29
 
27
30
  this._validateProcedures();
28
31
  },
@@ -178,7 +181,13 @@ module.exports = require("stampit")({
178
181
 
179
182
  statics: {
180
183
  defaults({ procedures, transport, logger, introspection, before, after } = {}) {
181
- return this.props({ procedures, transport, logger, introspection, before, after });
184
+ if (before != null) before = (Array.isArray(before) ? before : [before]).filter(isFunction);
185
+ if (after != null) after = (Array.isArray(after) ? after : [after]).filter(isFunction);
186
+
187
+ return this.compose({
188
+ props: { procedures, transport, logger, introspection },
189
+ deepProps: { before, after },
190
+ });
182
191
  },
183
192
  },
184
193
  });
package/src/util.js CHANGED
@@ -5,4 +5,5 @@ module.exports = {
5
5
  isFunction: (o) => is(o, "function"),
6
6
  isObject: (o) => is(o, "object"),
7
7
  isPlainObject: (o) => o && o.constructor === Object,
8
+ uniq: (a) => Array.from(new Set(a)),
8
9
  };