@avtechno/sfr 1.0.11 → 1.0.12

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.
@@ -131,7 +131,6 @@ export class SFRPipeline {
131
131
  Object.entries(handlers).forEach(([method, handler_map]) => {
132
132
  for (const [name, handler] of Object.entries(handler_map).filter(([k]) => validators[k])) {
133
133
  const dir = `${base_dir}/${namespace}/${name}`;
134
- console.log(dir);
135
134
  const validator = validators[name];
136
135
  const validator_type = typeof validator !== "function" ? "joi" : "multer";
137
136
  /* bind validators */
@@ -143,9 +142,12 @@ export class SFRPipeline {
143
142
  if (is_public) {
144
143
  //if(!req.session.user)return res.status(401).json({error : "Session not found."});
145
144
  }
146
- error = template(validator, method === "GET" ? req.query : req.body);
147
- if (error)
148
- return res.status(400).json({ error });
145
+ const validator_keys = Object.keys(validator);
146
+ if (validator_keys.length) {
147
+ error = template(validator, method === "GET" ? req.query : req.body);
148
+ if (error)
149
+ return res.status(400).json({ error });
150
+ }
149
151
  next();
150
152
  });
151
153
  }
@@ -197,22 +199,24 @@ export class SFRPipeline {
197
199
  const validator = validators[name];
198
200
  //const validator_type = typeof validator !== "function" ? "joi" : "multer"; // TODO: Dynamically update parameter content based on validator type.
199
201
  let validator_fn = function (msg) {
200
- const error = template(validator, msg.content);
201
- if (error) {
202
- if (mq instanceof TargetedMQ) {
203
- if (error) {
204
- switch (pattern) {
205
- case "Request-Reply":
206
- mq.reply(msg, { error });
207
- break;
208
- default: mq.channel.reject(msg, false);
202
+ const validator_keys = Object.keys(validator);
203
+ if (validator_keys.length) {
204
+ const error = template(validator, msg.content);
205
+ if (error) {
206
+ if (mq instanceof TargetedMQ) {
207
+ if (error) {
208
+ switch (pattern) {
209
+ case "Request-Reply":
210
+ mq.reply(msg, { error });
211
+ break;
212
+ default: mq.channel.reject(msg, false);
213
+ }
209
214
  }
210
215
  }
216
+ if (mq instanceof BroadcastMQ)
217
+ mq.channel.reject(msg, false);
218
+ return; //Return immediately to avoid executing handler fn (which may contain reply or ack calls.)
211
219
  }
212
- if (mq instanceof BroadcastMQ) {
213
- mq.channel.reject(msg, false);
214
- }
215
- return; //Return immediately to avoid executing handler fn (which may contain reply or ack calls.)
216
220
  }
217
221
  handler.fn(msg);
218
222
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avtechno/sfr",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "An opinionated way of writing services using ExpressJS.",
5
5
  "type": "module",
6
6
  "files": [
@@ -137,7 +137,7 @@ export class SFRPipeline {
137
137
  Object.entries(handlers).forEach(([method, handler_map]) => {
138
138
  for (const [name, handler] of Object.entries(handler_map).filter(([k]) => validators[k])) {
139
139
  const dir = `${base_dir}/${namespace}/${name}`;
140
- console.log(dir)
140
+
141
141
  const validator = validators[name];
142
142
  const validator_type = typeof validator !== "function" ? "joi" : "multer";
143
143
 
@@ -146,13 +146,16 @@ export class SFRPipeline {
146
146
  case "joi": {
147
147
  comms[method.toLowerCase() as RESTRequestType](dir, (req, res, next) => {
148
148
  let error: string | boolean = true;
149
-
149
+
150
150
  if (is_public) {
151
151
  //if(!req.session.user)return res.status(401).json({error : "Session not found."});
152
152
  }
153
-
154
- error = template(validator, method === "GET" ? req.query : req.body);
155
- if (error) return res.status(400).json({ error });
153
+
154
+ const validator_keys = Object.keys(validator);
155
+ if(validator_keys.length){
156
+ error = template(validator, method === "GET" ? req.query : req.body);
157
+ if (error) return res.status(400).json({ error });
158
+ }
156
159
  next();
157
160
  });
158
161
  } break;
@@ -207,25 +210,28 @@ export class SFRPipeline {
207
210
  //const validator_type = typeof validator !== "function" ? "joi" : "multer"; // TODO: Dynamically update parameter content based on validator type.
208
211
 
209
212
  let validator_fn = function (msg: ConsumeMessage) {
210
- const error = template(validator, msg.content);
211
-
212
- if (error) {
213
- if (mq instanceof TargetedMQ) {
214
- if (error) {
215
- switch (pattern) {
216
- case "Request-Reply": mq.reply(msg, { error }); break;
217
- default: mq.channel.reject(msg, false);
213
+ const validator_keys = Object.keys(validator);
214
+
215
+ if(validator_keys.length){
216
+ const error = template(validator, msg.content);
217
+
218
+ if (error) {
219
+ if (mq instanceof TargetedMQ) {
220
+ if (error) {
221
+ switch (pattern) {
222
+ case "Request-Reply": mq.reply(msg, { error }); break;
223
+ default: mq.channel.reject(msg, false);
224
+ }
218
225
  }
219
226
  }
220
- }
221
227
 
222
- if (mq instanceof BroadcastMQ) {
223
- mq.channel.reject(msg, false);
224
- }
228
+ if (mq instanceof BroadcastMQ)mq.channel.reject(msg, false);
225
229
 
226
- return; //Return immediately to avoid executing handler fn (which may contain reply or ack calls.)
230
+ return; //Return immediately to avoid executing handler fn (which may contain reply or ack calls.)
231
+ }
227
232
  }
228
233
 
234
+
229
235
  handler.fn(msg);
230
236
  }
231
237