@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.
- package/dist/sfr-pipeline.mjs +21 -17
- package/package.json +1 -1
- package/src/sfr-pipeline.mts +24 -18
package/dist/sfr-pipeline.mjs
CHANGED
|
@@ -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
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
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
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
package/src/sfr-pipeline.mts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
155
|
-
if
|
|
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
|
|
211
|
-
|
|
212
|
-
if
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
223
|
-
mq.channel.reject(msg, false);
|
|
224
|
-
}
|
|
228
|
+
if (mq instanceof BroadcastMQ)mq.channel.reject(msg, false);
|
|
225
229
|
|
|
226
|
-
|
|
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
|
|