Skip to content

Commit 73d15e7

Browse files
authored
feat: reduce transitive dependency size (#129)
replaces `lodash` imports with specific function module imports see #128
1 parent 3619b6f commit 73d15e7

29 files changed

+192
-167
lines changed

lib/Activity.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import _ from 'lodash';
1+
import isBoolean from 'lodash/isBoolean';
2+
import isObject from 'lodash/isObject';
23
import ActivityDescriptor from './descriptors/ActivityDescriptor';
34

45
const validateOptions = require('./util/Tools').validateOptions;
@@ -28,7 +29,7 @@ class Activity {
2829
* @param {ActivityDescriptor} descriptor
2930
*/
3031
constructor(worker, descriptor) {
31-
if (!_.isObject(worker)) {
32+
if (!isObject(worker)) {
3233
throw new TypeError('Failed to create an Activity. <Worker>worker is a required parameter.');
3334
}
3435

@@ -100,7 +101,7 @@ class Activity {
100101
*/
101102
setAsCurrent(options = {}) {
102103
const types = {
103-
rejectPendingReservations: (val) => _.isBoolean(val)
104+
rejectPendingReservations: (val) => isBoolean(val)
104105
};
105106
if (!validateOptions(options, types)) {
106107
throw new TypeError(`Failed to set activity=${this.sid}. The options passed in did not match the required types.`);

lib/Channel.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import _ from 'lodash';
1+
import isObject from 'lodash/isObject';
2+
import isString from 'lodash/isString';
23
import { EventEmitter } from 'events';
34
import WorkerChannelDescriptor from './descriptors/WorkerChannelDescriptor';
45
import Worker from './Worker';
@@ -140,11 +141,11 @@ class Channel extends EventEmitter {
140141
* @private
141142
*/
142143
_emitEvent(eventType, rawEventData) {
143-
if (!_.isString(eventType)) {
144+
if (!isString(eventType)) {
144145
throw new TypeError('Error calling _emitEvent(). <string>eventType is a required parameter.');
145146
}
146147

147-
if (!_.isObject(rawEventData)) {
148+
if (!isObject(rawEventData)) {
148149
throw new TypeError('Error calling method _emitEvent(). <object>rawEventData is a required parameter.');
149150
}
150151

lib/Reservation.js

+61-57
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import _ from 'lodash';
1+
import isBoolean from 'lodash/isBoolean';
2+
import isInteger from 'lodash/isInteger';
3+
import isObject from 'lodash/isObject';
4+
import isString from 'lodash/isString';
5+
import upperFirst from 'lodash/upperFirst';
26
import { API_V1,
37
API_V2,
48
RESERVATION_STATUS_ACCEPTED,
@@ -214,7 +218,7 @@ class Reservation extends EventEmitter {
214218
};
215219

216220
// validate the provided options
217-
const types = { activitySid: (val) => _.isString(val) };
221+
const types = { activitySid: (val) => isString(val) };
218222
if (!validateOptions(options, types)) {
219223
throw new TypeError(`Failed to issue Instruction:reject on Reservation sid=${this.sid}. The options passed in did not match the required types.`);
220224
}
@@ -249,11 +253,11 @@ class Reservation extends EventEmitter {
249253
* @returns {Promise<this>} - Rejected if unable to issue Call instruction on the {@link Reservation}
250254
*/
251255
call(from, url, options = {}) {
252-
if (!_.isString(from)) {
256+
if (!isString(from)) {
253257
throw new TypeError('Error calling method call(). <string>from is a required parameter.');
254258
}
255259

256-
if (!_.isString(url)) {
260+
if (!isString(url)) {
257261
throw new TypeError('Error calling method call(). <string>url is a required parameter.');
258262
}
259263

@@ -264,11 +268,11 @@ class Reservation extends EventEmitter {
264268
CallUrl: url,
265269
};
266270
const types = {
267-
accept: (val) => _.isBoolean(val),
268-
record: (val) => _.isString(val),
269-
statusCallbackUrl: (val) => _.isString(val),
270-
timeout: (val) => _.isInteger(val),
271-
to: (val) => _.isString(val)
271+
accept: (val) => isBoolean(val),
272+
record: (val) => isString(val),
273+
statusCallbackUrl: (val) => isString(val),
274+
timeout: (val) => isInteger(val),
275+
to: (val) => isString(val)
272276
};
273277

274278
if (!validateOptions(options, types)) {
@@ -298,13 +302,13 @@ class Reservation extends EventEmitter {
298302
};
299303

300304
const types = {
301-
from: (val) => _.isString(val),
302-
to: (val) => _.isString(val),
303-
postWorkActivitySid: (val) => _.isString(val),
304-
record: (val) => _.isString(val),
305-
timeout: (val) => _.isInteger(val),
306-
statusCallbackUrl: (val) => _.isString(val),
307-
statusCallbackEvents: (val) => _.isString(val)
305+
from: (val) => isString(val),
306+
to: (val) => isString(val),
307+
postWorkActivitySid: (val) => isString(val),
308+
record: (val) => isString(val),
309+
timeout: (val) => isInteger(val),
310+
statusCallbackUrl: (val) => isString(val),
311+
statusCallbackEvents: (val) => isString(val)
308312
};
309313

310314
if (!validateOptions(options, types)) {
@@ -327,15 +331,15 @@ class Reservation extends EventEmitter {
327331
* @returns {Promise<this>} - Rejected if unable to issue Redirect instruction on the {@link Reservation}
328332
*/
329333
redirect(callSid, url, options = {}) {
330-
if (!_.isString(callSid)) {
334+
if (!isString(callSid)) {
331335
throw new TypeError('Error calling method redirect(). <string>callSid is a required parameter.');
332336
}
333-
if (!_.isString(url)) {
337+
if (!isString(url)) {
334338
throw new TypeError('Error calling method redirect(). <string>url is a required parameter.');
335339
}
336340

337341
const requestURL = this._worker.getRoutes().getRoute(RESERVATION_INSTANCE, this.sid).path;
338-
const types = { accept: (val) => _.isBoolean(val) };
342+
const types = { accept: (val) => isBoolean(val) };
339343
const requestParams = {
340344
Instruction: RESERVATION_INSTRUCTION_REDIRECT,
341345
RedirectCallSid: callSid,
@@ -362,37 +366,37 @@ class Reservation extends EventEmitter {
362366
*/
363367
conference(options = {}) {
364368
const types = {
365-
to: (val) => _.isString(val),
366-
from: (val) => _.isString(val),
367-
timeout: (val) => _.isInteger(val),
368-
statusCallback: (val) => _.isString(val),
369-
statusCallbackMethod: (val) => _.isString(val),
370-
statusCallbackEvent: (val) => _.isString(val),
371-
record: (val) => _.isString(val),
372-
muted: (val) => _.isBoolean(val),
373-
beep: (val) => _.isBoolean(val) || _.isString(val),
374-
startConferenceOnEnter: (val) => _.isBoolean(val),
375-
endConferenceOnExit: (val) => _.isBoolean(val),
376-
endConferenceOnCustomerExit: (val) => _.isBoolean(val),
377-
waitUrl: (val) => _.isString(val),
378-
waitMethod: (val) => _.isString(val),
379-
earlyMedia: (val) => _.isBoolean(val),
380-
maxParticipants: (val) => _.isInteger(val),
381-
conferenceStatusCallback: (val) => _.isString(val),
382-
conferenceStatusCallbackMethod: (val) => _.isString(val),
383-
conferenceStatusCallbackEvent: (val) => _.isString(val),
384-
conferenceRecord: (val) => _.isBoolean(val) || _.isString(val),
385-
conferenceTrim: (val) => _.isString(val),
386-
recordingChannels: (val) => _.isString(val),
387-
recordingStatusCallback: (val) => _.isString(val),
388-
recordingStatusCallbackMethod: (val) => _.isString(val),
389-
conferenceRecordingStatusCallback: (val) => _.isString(val),
390-
conferenceRecordingStatusCallbackMethod: (val) => _.isString(val),
391-
region: (val) => _.isString(val),
392-
sipAuthUsername: (val) => _.isString(val),
393-
sipAuthPassword: (val) => _.isString(val),
394-
transcribe: (val) => _.isBoolean(val),
395-
transcriptionConfiguration: (val) => _.isString(val)
369+
to: (val) => isString(val),
370+
from: (val) => isString(val),
371+
timeout: (val) => isInteger(val),
372+
statusCallback: (val) => isString(val),
373+
statusCallbackMethod: (val) => isString(val),
374+
statusCallbackEvent: (val) => isString(val),
375+
record: (val) => isString(val),
376+
muted: (val) => isBoolean(val),
377+
beep: (val) => isBoolean(val) || isString(val),
378+
startConferenceOnEnter: (val) => isBoolean(val),
379+
endConferenceOnExit: (val) => isBoolean(val),
380+
endConferenceOnCustomerExit: (val) => isBoolean(val),
381+
waitUrl: (val) => isString(val),
382+
waitMethod: (val) => isString(val),
383+
earlyMedia: (val) => isBoolean(val),
384+
maxParticipants: (val) => isInteger(val),
385+
conferenceStatusCallback: (val) => isString(val),
386+
conferenceStatusCallbackMethod: (val) => isString(val),
387+
conferenceStatusCallbackEvent: (val) => isString(val),
388+
conferenceRecord: (val) => isBoolean(val) || isString(val),
389+
conferenceTrim: (val) => isString(val),
390+
recordingChannels: (val) => isString(val),
391+
recordingStatusCallback: (val) => isString(val),
392+
recordingStatusCallbackMethod: (val) => isString(val),
393+
conferenceRecordingStatusCallback: (val) => isString(val),
394+
conferenceRecordingStatusCallbackMethod: (val) => isString(val),
395+
region: (val) => isString(val),
396+
sipAuthUsername: (val) => isString(val),
397+
sipAuthPassword: (val) => isString(val),
398+
transcribe: (val) => isBoolean(val),
399+
transcriptionConfiguration: (val) => isString(val)
396400
};
397401

398402
if (!validateOptions(options, types)) {
@@ -404,7 +408,7 @@ class Reservation extends EventEmitter {
404408
Instruction: RESERVATION_INSTRUCTION_CONFERENCE,
405409
};
406410
for (const option in options) {
407-
requestParams[_.upperFirst(option)] = options[option];
411+
requestParams[upperFirst(option)] = options[option];
408412
}
409413

410414
return this._request.post(requestURL, requestParams, API_V1).then(() => this);
@@ -417,9 +421,9 @@ class Reservation extends EventEmitter {
417421
*/
418422
updateParticipant(options) {
419423
const types = {
420-
endConferenceOnExit: (val) => _.isBoolean(val),
421-
mute: (val) => _.isBoolean(val),
422-
beepOnExit: (val) => _.isBoolean(val)
424+
endConferenceOnExit: (val) => isBoolean(val),
425+
mute: (val) => isBoolean(val),
426+
beepOnExit: (val) => isBoolean(val)
423427
};
424428

425429
if (!validateOptions(options, types)) {
@@ -433,7 +437,7 @@ class Reservation extends EventEmitter {
433437
};
434438

435439
for (const option in options) {
436-
requestParams[_.upperFirst(option)] = options[option];
440+
requestParams[upperFirst(option)] = options[option];
437441
}
438442

439443
return this._request.post(requestURL, requestParams, API_V2).then(() => this);
@@ -548,11 +552,11 @@ class Reservation extends EventEmitter {
548552
* @private
549553
*/
550554
_emitEvent(eventType, rawEventData) {
551-
if (!_.isString(eventType)) {
555+
if (!isString(eventType)) {
552556
throw new TypeError('Error calling _emitEvent(). <string>eventType is a required parameter.');
553557
}
554558

555-
if (!_.isObject(rawEventData)) {
559+
if (!isObject(rawEventData)) {
556560
throw new TypeError('Error calling method _emitEvent(). <object>rawEventData is a required parameter.');
557561
}
558562

lib/Supervisor.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import _ from 'lodash';
1+
import isObject from 'lodash/isObject';
2+
import isString from 'lodash/isString';
23
import Worker from './Worker';
34
import { API_V1, WORKER_UPDATE_OPTIONS } from './util/Constants';
45
import { TASK_RESERVATION_INSTANCE, TARGET_WORKER_INSTANCE } from './util/Routes';
@@ -22,15 +23,15 @@ class Supervisor extends Worker {
2223
* @returns Promise<void>
2324
*/
2425
monitor(taskSid, reservationSid, extraParams) {
25-
if (!_.isString(taskSid)) {
26+
if (!isString(taskSid)) {
2627
throw new TypeError('Error monitoring reservation: <string>taskSid is a required parameter');
2728
}
2829

29-
if (!_.isString(reservationSid)) {
30+
if (!isString(reservationSid)) {
3031
throw new TypeError('Error monitoring reservation: <string>reservationSid is a required parameter');
3132
}
3233

33-
if (extraParams && !_.isObject(extraParams)) {
34+
if (extraParams && !isObject(extraParams)) {
3435
throw new TypeError('Error monitoring reservation: <string>extraParams must be an object');
3536
}
3637

0 commit comments

Comments
 (0)