Skip to content

Commit

Permalink
2023.4 update deps (#975)
Browse files Browse the repository at this point in the history
* Updated dependencies

eslint-config-airbnb-base: to fix the peer dependency conflict
nodemon: to fix security vulnerabilities (npm audit)

* fix no-promise-executor-return

* turn off few eslint rules

* return after early resolve
  • Loading branch information
sadiqkhoja authored Sep 14, 2023
1 parent 9298c7f commit 1a970c8
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 212 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"comma-dangle": "off",
"consistent-return": "off",
"curly": "off",
"default-param-last": "off", // TODO enable this and refactor the code
"function-call-argument-newline": "off",
"function-paren-newline": "off",
"global-require": "off",
"implicit-arrow-linebreak": "off",
"import/newline-after-import": "off",
Expand Down
5 changes: 4 additions & 1 deletion lib/data/odata.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ const submissionToOData = (fields, table, submission, options = {}) => new Promi
}

// bail out without doing any work if we are encrypted.
if (encrypted === true) return resolve({ data: result, instanceId: submission.instanceId });
if (encrypted === true) {
resolve({ data: result, instanceId: submission.instanceId });
return;
}

// we keep a dataStack, so we build an appropriate nested structure overall, and
// we can select the appropriate layer of that nesting at will.
Expand Down
5 changes: 3 additions & 2 deletions lib/external/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const { messages } = require('../formats/mail');

// a little helper to reduce transport boilerplate below:
const simpleTransport = (transport, options, callback) => (to, messageId, data) =>
new Promise((resolve, reject) =>
new Promise((resolve, reject) => {
transport.sendMail(mergeRight({ to, from: options.serviceAccount }, messages[messageId](data, options.env)), (err, info) =>
callback(err, info, resolve, reject)));
callback(err, info, resolve, reject));
});

// actual mail transport stuffs. does some wrapping work to smooth over some
// differences (ie how jsonTransport does not actually put anything anywhere).
Expand Down
116 changes: 59 additions & 57 deletions lib/util/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,63 +261,65 @@ const queryFuncs = (db, obj) => {
return result;
};

obj.stream = (s) => new Promise((resolve, reject1) => db.stream(s, stream => {
try {
const twoMinutes = 2 * 60 * 1000;
const streamTimeout = setTimeout(() => {
stream.destroy(new Error('Stream timed out.'));
}, twoMinutes);

const wrappedStream = stream.pipe(new Transform({
objectMode: true,
transform(data, encoding, cb) {
streamTimeout.refresh();
this.push(data);
cb();
},
}));

stream.on('end', () => {
// No need to propagate this one:
//
// > By default, stream.end() is called on the destination Writable stream when the source Readable stream emits 'end', so that the destination is no longer writable
// see: https://nodejs.org/api/stream.html#readablepipedestination-options
//
// Also, doing so seems to break things.

clearTimeout(streamTimeout);
});

stream.on('error', err => {
if (!wrappedStream.destroyed) wrappedStream.destroy(err);
clearTimeout(streamTimeout);
});

stream.on('close', () => {
if (!wrappedStream.destroyed) wrappedStream.destroy();
clearTimeout(streamTimeout);
});

wrappedStream.on('end', () => {
if (!stream.destroyed) stream.destroy();
clearTimeout(streamTimeout);
});

wrappedStream.on('error', err => {
if (!stream.destroyed) stream.destroy(err);
clearTimeout(streamTimeout);
});

wrappedStream.on('close', () => {
if (!stream.destroyed) stream.destroy();
clearTimeout(streamTimeout);
});

resolve(wrappedStream);
} catch (error) {
reject1(error);
}
}).catch(reject1));
obj.stream = (s) => new Promise((resolve, reject1) => {
db.stream(s, stream => {
try {
const twoMinutes = 2 * 60 * 1000;
const streamTimeout = setTimeout(() => {
stream.destroy(new Error('Stream timed out.'));
}, twoMinutes);

const wrappedStream = stream.pipe(new Transform({
objectMode: true,
transform(data, encoding, cb) {
streamTimeout.refresh();
this.push(data);
cb();
},
}));

stream.on('end', () => {
// No need to propagate this one:
//
// > By default, stream.end() is called on the destination Writable stream when the source Readable stream emits 'end', so that the destination is no longer writable
// see: https://nodejs.org/api/stream.html#readablepipedestination-options
//
// Also, doing so seems to break things.

clearTimeout(streamTimeout);
});

stream.on('error', err => {
if (!wrappedStream.destroyed) wrappedStream.destroy(err);
clearTimeout(streamTimeout);
});

stream.on('close', () => {
if (!wrappedStream.destroyed) wrappedStream.destroy();
clearTimeout(streamTimeout);
});

wrappedStream.on('end', () => {
if (!stream.destroyed) stream.destroy();
clearTimeout(streamTimeout);
});

wrappedStream.on('error', err => {
if (!stream.destroyed) stream.destroy(err);
clearTimeout(streamTimeout);
});

wrappedStream.on('close', () => {
if (!stream.destroyed) stream.destroy();
clearTimeout(streamTimeout);
});

resolve(wrappedStream);
} catch (error) {
reject1(error);
}
}).catch(reject1);
});
obj.stream.map = (f) => (strm) => PartialPipe.of(strm, mapStream(({ row }) => f(row)));
/* eslint-enable no-param-reassign */
};
Expand Down
Loading

0 comments on commit 1a970c8

Please sign in to comment.