@allthings/sdk 6.6.0 → 6.7.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/dist/cli.js +1304 -1179
- package/dist/lib.cjs.js +1304 -1179
- package/dist/lib.esm.js +1304 -1179
- package/dist/lib.umd.min.js +1 -1
- package/dist/src/rest/methods/conversation.d.ts +1 -0
- package/dist/src/rest/methods/file.d.ts +1 -0
- package/dist/src/rest/methods/group.d.ts +3 -2
- package/dist/src/rest/methods/property.d.ts +2 -1
- package/dist/src/rest/methods/registrationCode.d.ts +1 -0
- package/dist/src/rest/methods/ticket.d.ts +1 -0
- package/dist/src/rest/methods/unit.d.ts +1 -0
- package/dist/src/rest/methods/user.d.ts +8 -0
- package/dist/src/rest/methods/utilisationPeriod.d.ts +2 -1
- package/dist/src/utils/upload.d.ts +1 -0
- package/package.json +8 -8
package/dist/cli.js
CHANGED
|
@@ -13,7 +13,7 @@ var require$$4 = require('https');
|
|
|
13
13
|
var require$$5 = require('url');
|
|
14
14
|
var require$$6 = require('fs');
|
|
15
15
|
|
|
16
|
-
const version = "6.
|
|
16
|
+
const version = "6.7.0";
|
|
17
17
|
|
|
18
18
|
const REST_API_URL = 'https://api.allthings.me';
|
|
19
19
|
const OAUTH_URL = 'https://accounts.allthings.me';
|
|
@@ -875,322 +875,338 @@ function getDefaultExportFromCjs (x) {
|
|
|
875
875
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
876
876
|
}
|
|
877
877
|
|
|
878
|
-
var
|
|
879
|
-
var
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
878
|
+
var delayed_stream;
|
|
879
|
+
var hasRequiredDelayed_stream;
|
|
880
|
+
|
|
881
|
+
function requireDelayed_stream () {
|
|
882
|
+
if (hasRequiredDelayed_stream) return delayed_stream;
|
|
883
|
+
hasRequiredDelayed_stream = 1;
|
|
884
|
+
var Stream = require$$0$1.Stream;
|
|
885
|
+
var util = require$$1;
|
|
886
|
+
|
|
887
|
+
delayed_stream = DelayedStream;
|
|
888
|
+
function DelayedStream() {
|
|
889
|
+
this.source = null;
|
|
890
|
+
this.dataSize = 0;
|
|
891
|
+
this.maxDataSize = 1024 * 1024;
|
|
892
|
+
this.pauseStream = true;
|
|
893
|
+
|
|
894
|
+
this._maxDataSizeExceeded = false;
|
|
895
|
+
this._released = false;
|
|
896
|
+
this._bufferedEvents = [];
|
|
897
|
+
}
|
|
898
|
+
util.inherits(DelayedStream, Stream);
|
|
896
899
|
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
delayedStream[option] = options[option];
|
|
900
|
-
}
|
|
900
|
+
DelayedStream.create = function(source, options) {
|
|
901
|
+
var delayedStream = new this();
|
|
901
902
|
|
|
902
|
-
|
|
903
|
+
options = options || {};
|
|
904
|
+
for (var option in options) {
|
|
905
|
+
delayedStream[option] = options[option];
|
|
906
|
+
}
|
|
903
907
|
|
|
904
|
-
|
|
905
|
-
source.emit = function() {
|
|
906
|
-
delayedStream._handleEmit(arguments);
|
|
907
|
-
return realEmit.apply(source, arguments);
|
|
908
|
-
};
|
|
908
|
+
delayedStream.source = source;
|
|
909
909
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
910
|
+
var realEmit = source.emit;
|
|
911
|
+
source.emit = function() {
|
|
912
|
+
delayedStream._handleEmit(arguments);
|
|
913
|
+
return realEmit.apply(source, arguments);
|
|
914
|
+
};
|
|
914
915
|
|
|
915
|
-
|
|
916
|
-
|
|
916
|
+
source.on('error', function() {});
|
|
917
|
+
if (delayedStream.pauseStream) {
|
|
918
|
+
source.pause();
|
|
919
|
+
}
|
|
917
920
|
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
enumerable: true,
|
|
921
|
-
get: function() {
|
|
922
|
-
return this.source.readable;
|
|
923
|
-
}
|
|
924
|
-
});
|
|
921
|
+
return delayedStream;
|
|
922
|
+
};
|
|
925
923
|
|
|
926
|
-
DelayedStream
|
|
927
|
-
|
|
928
|
-
|
|
924
|
+
Object.defineProperty(DelayedStream.prototype, 'readable', {
|
|
925
|
+
configurable: true,
|
|
926
|
+
enumerable: true,
|
|
927
|
+
get: function() {
|
|
928
|
+
return this.source.readable;
|
|
929
|
+
}
|
|
930
|
+
});
|
|
929
931
|
|
|
930
|
-
DelayedStream
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
}
|
|
932
|
+
DelayedStream.prototype.setEncoding = function() {
|
|
933
|
+
return this.source.setEncoding.apply(this.source, arguments);
|
|
934
|
+
};
|
|
934
935
|
|
|
935
|
-
|
|
936
|
-
|
|
936
|
+
DelayedStream.prototype.resume = function() {
|
|
937
|
+
if (!this._released) {
|
|
938
|
+
this.release();
|
|
939
|
+
}
|
|
937
940
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
};
|
|
941
|
+
this.source.resume();
|
|
942
|
+
};
|
|
941
943
|
|
|
942
|
-
DelayedStream
|
|
943
|
-
|
|
944
|
+
DelayedStream.prototype.pause = function() {
|
|
945
|
+
this.source.pause();
|
|
946
|
+
};
|
|
944
947
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
}.bind(this));
|
|
948
|
-
this._bufferedEvents = [];
|
|
949
|
-
};
|
|
948
|
+
DelayedStream.prototype.release = function() {
|
|
949
|
+
this._released = true;
|
|
950
950
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
};
|
|
951
|
+
this._bufferedEvents.forEach(function(args) {
|
|
952
|
+
this.emit.apply(this, args);
|
|
953
|
+
}.bind(this));
|
|
954
|
+
this._bufferedEvents = [];
|
|
955
|
+
};
|
|
956
956
|
|
|
957
|
-
DelayedStream
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
957
|
+
DelayedStream.prototype.pipe = function() {
|
|
958
|
+
var r = Stream.prototype.pipe.apply(this, arguments);
|
|
959
|
+
this.resume();
|
|
960
|
+
return r;
|
|
961
|
+
};
|
|
962
962
|
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
963
|
+
DelayedStream.prototype._handleEmit = function(args) {
|
|
964
|
+
if (this._released) {
|
|
965
|
+
this.emit.apply(this, args);
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
967
968
|
|
|
968
|
-
|
|
969
|
-
|
|
969
|
+
if (args[0] === 'data') {
|
|
970
|
+
this.dataSize += args[1].length;
|
|
971
|
+
this._checkIfMaxDataSizeExceeded();
|
|
972
|
+
}
|
|
970
973
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
974
|
+
this._bufferedEvents.push(args);
|
|
975
|
+
};
|
|
975
976
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
977
|
+
DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
|
|
978
|
+
if (this._maxDataSizeExceeded) {
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
979
981
|
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
this.emit('error', new Error(message));
|
|
984
|
-
};
|
|
982
|
+
if (this.dataSize <= this.maxDataSize) {
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
985
|
|
|
986
|
-
|
|
987
|
-
var
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
this.writable = false;
|
|
993
|
-
this.readable = true;
|
|
994
|
-
this.dataSize = 0;
|
|
995
|
-
this.maxDataSize = 2 * 1024 * 1024;
|
|
996
|
-
this.pauseStreams = true;
|
|
997
|
-
|
|
998
|
-
this._released = false;
|
|
999
|
-
this._streams = [];
|
|
1000
|
-
this._currentStream = null;
|
|
1001
|
-
this._insideLoop = false;
|
|
1002
|
-
this._pendingNext = false;
|
|
986
|
+
this._maxDataSizeExceeded = true;
|
|
987
|
+
var message =
|
|
988
|
+
'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
|
|
989
|
+
this.emit('error', new Error(message));
|
|
990
|
+
};
|
|
991
|
+
return delayed_stream;
|
|
1003
992
|
}
|
|
1004
|
-
util$1.inherits(CombinedStream$1, Stream$1);
|
|
1005
993
|
|
|
1006
|
-
|
|
1007
|
-
|
|
994
|
+
var combined_stream;
|
|
995
|
+
var hasRequiredCombined_stream;
|
|
996
|
+
|
|
997
|
+
function requireCombined_stream () {
|
|
998
|
+
if (hasRequiredCombined_stream) return combined_stream;
|
|
999
|
+
hasRequiredCombined_stream = 1;
|
|
1000
|
+
var util = require$$1;
|
|
1001
|
+
var Stream = require$$0$1.Stream;
|
|
1002
|
+
var DelayedStream = requireDelayed_stream();
|
|
1003
|
+
|
|
1004
|
+
combined_stream = CombinedStream;
|
|
1005
|
+
function CombinedStream() {
|
|
1006
|
+
this.writable = false;
|
|
1007
|
+
this.readable = true;
|
|
1008
|
+
this.dataSize = 0;
|
|
1009
|
+
this.maxDataSize = 2 * 1024 * 1024;
|
|
1010
|
+
this.pauseStreams = true;
|
|
1011
|
+
|
|
1012
|
+
this._released = false;
|
|
1013
|
+
this._streams = [];
|
|
1014
|
+
this._currentStream = null;
|
|
1015
|
+
this._insideLoop = false;
|
|
1016
|
+
this._pendingNext = false;
|
|
1017
|
+
}
|
|
1018
|
+
util.inherits(CombinedStream, Stream);
|
|
1008
1019
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
combinedStream[option] = options[option];
|
|
1012
|
-
}
|
|
1020
|
+
CombinedStream.create = function(options) {
|
|
1021
|
+
var combinedStream = new this();
|
|
1013
1022
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
return (typeof stream !== 'function')
|
|
1019
|
-
&& (typeof stream !== 'string')
|
|
1020
|
-
&& (typeof stream !== 'boolean')
|
|
1021
|
-
&& (typeof stream !== 'number')
|
|
1022
|
-
&& (!Buffer.isBuffer(stream));
|
|
1023
|
-
};
|
|
1023
|
+
options = options || {};
|
|
1024
|
+
for (var option in options) {
|
|
1025
|
+
combinedStream[option] = options[option];
|
|
1026
|
+
}
|
|
1024
1027
|
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1028
|
+
return combinedStream;
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
CombinedStream.isStreamLike = function(stream) {
|
|
1032
|
+
return (typeof stream !== 'function')
|
|
1033
|
+
&& (typeof stream !== 'string')
|
|
1034
|
+
&& (typeof stream !== 'boolean')
|
|
1035
|
+
&& (typeof stream !== 'number')
|
|
1036
|
+
&& (!Buffer.isBuffer(stream));
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
CombinedStream.prototype.append = function(stream) {
|
|
1040
|
+
var isStreamLike = CombinedStream.isStreamLike(stream);
|
|
1041
|
+
|
|
1042
|
+
if (isStreamLike) {
|
|
1043
|
+
if (!(stream instanceof DelayedStream)) {
|
|
1044
|
+
var newStream = DelayedStream.create(stream, {
|
|
1045
|
+
maxDataSize: Infinity,
|
|
1046
|
+
pauseStream: this.pauseStreams,
|
|
1047
|
+
});
|
|
1048
|
+
stream.on('data', this._checkDataSize.bind(this));
|
|
1049
|
+
stream = newStream;
|
|
1050
|
+
}
|
|
1037
1051
|
|
|
1038
|
-
|
|
1052
|
+
this._handleErrors(stream);
|
|
1039
1053
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1054
|
+
if (this.pauseStreams) {
|
|
1055
|
+
stream.pause();
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1044
1058
|
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
};
|
|
1059
|
+
this._streams.push(stream);
|
|
1060
|
+
return this;
|
|
1061
|
+
};
|
|
1048
1062
|
|
|
1049
|
-
CombinedStream
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
};
|
|
1063
|
+
CombinedStream.prototype.pipe = function(dest, options) {
|
|
1064
|
+
Stream.prototype.pipe.call(this, dest, options);
|
|
1065
|
+
this.resume();
|
|
1066
|
+
return dest;
|
|
1067
|
+
};
|
|
1054
1068
|
|
|
1055
|
-
CombinedStream
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
if (this._insideLoop) {
|
|
1059
|
-
this._pendingNext = true;
|
|
1060
|
-
return; // defer call
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
this._insideLoop = true;
|
|
1064
|
-
try {
|
|
1065
|
-
do {
|
|
1066
|
-
this._pendingNext = false;
|
|
1067
|
-
this._realGetNext();
|
|
1068
|
-
} while (this._pendingNext);
|
|
1069
|
-
} finally {
|
|
1070
|
-
this._insideLoop = false;
|
|
1071
|
-
}
|
|
1072
|
-
};
|
|
1073
|
-
|
|
1074
|
-
CombinedStream$1.prototype._realGetNext = function() {
|
|
1075
|
-
var stream = this._streams.shift();
|
|
1069
|
+
CombinedStream.prototype._getNext = function() {
|
|
1070
|
+
this._currentStream = null;
|
|
1076
1071
|
|
|
1072
|
+
if (this._insideLoop) {
|
|
1073
|
+
this._pendingNext = true;
|
|
1074
|
+
return; // defer call
|
|
1075
|
+
}
|
|
1077
1076
|
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1077
|
+
this._insideLoop = true;
|
|
1078
|
+
try {
|
|
1079
|
+
do {
|
|
1080
|
+
this._pendingNext = false;
|
|
1081
|
+
this._realGetNext();
|
|
1082
|
+
} while (this._pendingNext);
|
|
1083
|
+
} finally {
|
|
1084
|
+
this._insideLoop = false;
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1082
1087
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
return;
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
var getStream = stream;
|
|
1089
|
-
getStream(function(stream) {
|
|
1090
|
-
var isStreamLike = CombinedStream$1.isStreamLike(stream);
|
|
1091
|
-
if (isStreamLike) {
|
|
1092
|
-
stream.on('data', this._checkDataSize.bind(this));
|
|
1093
|
-
this._handleErrors(stream);
|
|
1094
|
-
}
|
|
1088
|
+
CombinedStream.prototype._realGetNext = function() {
|
|
1089
|
+
var stream = this._streams.shift();
|
|
1095
1090
|
|
|
1096
|
-
this._pipeNext(stream);
|
|
1097
|
-
}.bind(this));
|
|
1098
|
-
};
|
|
1099
1091
|
|
|
1100
|
-
|
|
1101
|
-
|
|
1092
|
+
if (typeof stream == 'undefined') {
|
|
1093
|
+
this.end();
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1102
1096
|
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1097
|
+
if (typeof stream !== 'function') {
|
|
1098
|
+
this._pipeNext(stream);
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1109
1101
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1102
|
+
var getStream = stream;
|
|
1103
|
+
getStream(function(stream) {
|
|
1104
|
+
var isStreamLike = CombinedStream.isStreamLike(stream);
|
|
1105
|
+
if (isStreamLike) {
|
|
1106
|
+
stream.on('data', this._checkDataSize.bind(this));
|
|
1107
|
+
this._handleErrors(stream);
|
|
1108
|
+
}
|
|
1114
1109
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
self._emitError(err);
|
|
1119
|
-
});
|
|
1120
|
-
};
|
|
1110
|
+
this._pipeNext(stream);
|
|
1111
|
+
}.bind(this));
|
|
1112
|
+
};
|
|
1121
1113
|
|
|
1122
|
-
CombinedStream
|
|
1123
|
-
|
|
1124
|
-
};
|
|
1114
|
+
CombinedStream.prototype._pipeNext = function(stream) {
|
|
1115
|
+
this._currentStream = stream;
|
|
1125
1116
|
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1117
|
+
var isStreamLike = CombinedStream.isStreamLike(stream);
|
|
1118
|
+
if (isStreamLike) {
|
|
1119
|
+
stream.on('end', this._getNext.bind(this));
|
|
1120
|
+
stream.pipe(this, {end: false});
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1130
1123
|
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1124
|
+
var value = stream;
|
|
1125
|
+
this.write(value);
|
|
1126
|
+
this._getNext();
|
|
1127
|
+
};
|
|
1134
1128
|
|
|
1135
|
-
CombinedStream
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1129
|
+
CombinedStream.prototype._handleErrors = function(stream) {
|
|
1130
|
+
var self = this;
|
|
1131
|
+
stream.on('error', function(err) {
|
|
1132
|
+
self._emitError(err);
|
|
1133
|
+
});
|
|
1134
|
+
};
|
|
1141
1135
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
};
|
|
1136
|
+
CombinedStream.prototype.write = function(data) {
|
|
1137
|
+
this.emit('data', data);
|
|
1138
|
+
};
|
|
1145
1139
|
|
|
1146
|
-
CombinedStream
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
}
|
|
1140
|
+
CombinedStream.prototype.pause = function() {
|
|
1141
|
+
if (!this.pauseStreams) {
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1150
1144
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
};
|
|
1145
|
+
if(this.pauseStreams && this._currentStream && typeof(this._currentStream.pause) == 'function') this._currentStream.pause();
|
|
1146
|
+
this.emit('pause');
|
|
1147
|
+
};
|
|
1155
1148
|
|
|
1156
|
-
CombinedStream
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1149
|
+
CombinedStream.prototype.resume = function() {
|
|
1150
|
+
if (!this._released) {
|
|
1151
|
+
this._released = true;
|
|
1152
|
+
this.writable = true;
|
|
1153
|
+
this._getNext();
|
|
1154
|
+
}
|
|
1161
1155
|
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1156
|
+
if(this.pauseStreams && this._currentStream && typeof(this._currentStream.resume) == 'function') this._currentStream.resume();
|
|
1157
|
+
this.emit('resume');
|
|
1158
|
+
};
|
|
1159
|
+
|
|
1160
|
+
CombinedStream.prototype.end = function() {
|
|
1161
|
+
this._reset();
|
|
1162
|
+
this.emit('end');
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
CombinedStream.prototype.destroy = function() {
|
|
1166
|
+
this._reset();
|
|
1167
|
+
this.emit('close');
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
CombinedStream.prototype._reset = function() {
|
|
1171
|
+
this.writable = false;
|
|
1172
|
+
this._streams = [];
|
|
1173
|
+
this._currentStream = null;
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
CombinedStream.prototype._checkDataSize = function() {
|
|
1177
|
+
this._updateDataSize();
|
|
1178
|
+
if (this.dataSize <= this.maxDataSize) {
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1167
1181
|
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
};
|
|
1182
|
+
var message =
|
|
1183
|
+
'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
|
|
1184
|
+
this._emitError(new Error(message));
|
|
1185
|
+
};
|
|
1172
1186
|
|
|
1173
|
-
CombinedStream
|
|
1174
|
-
|
|
1187
|
+
CombinedStream.prototype._updateDataSize = function() {
|
|
1188
|
+
this.dataSize = 0;
|
|
1175
1189
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1190
|
+
var self = this;
|
|
1191
|
+
this._streams.forEach(function(stream) {
|
|
1192
|
+
if (!stream.dataSize) {
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1181
1195
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1196
|
+
self.dataSize += stream.dataSize;
|
|
1197
|
+
});
|
|
1184
1198
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
};
|
|
1199
|
+
if (this._currentStream && this._currentStream.dataSize) {
|
|
1200
|
+
this.dataSize += this._currentStream.dataSize;
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1189
1203
|
|
|
1190
|
-
CombinedStream
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
};
|
|
1204
|
+
CombinedStream.prototype._emitError = function(err) {
|
|
1205
|
+
this._reset();
|
|
1206
|
+
this.emit('error', err);
|
|
1207
|
+
};
|
|
1208
|
+
return combined_stream;
|
|
1209
|
+
}
|
|
1194
1210
|
|
|
1195
1211
|
var mimeTypes = {};
|
|
1196
1212
|
|
|
@@ -11904,11 +11920,19 @@ var require$$0 = {
|
|
|
11904
11920
|
* MIT Licensed
|
|
11905
11921
|
*/
|
|
11906
11922
|
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
|
|
11923
|
+
var mimeDb;
|
|
11924
|
+
var hasRequiredMimeDb;
|
|
11925
|
+
|
|
11926
|
+
function requireMimeDb () {
|
|
11927
|
+
if (hasRequiredMimeDb) return mimeDb;
|
|
11928
|
+
hasRequiredMimeDb = 1;
|
|
11929
|
+
/**
|
|
11930
|
+
* Module exports.
|
|
11931
|
+
*/
|
|
11910
11932
|
|
|
11911
|
-
|
|
11933
|
+
mimeDb = require$$0;
|
|
11934
|
+
return mimeDb;
|
|
11935
|
+
}
|
|
11912
11936
|
|
|
11913
11937
|
/*!
|
|
11914
11938
|
* mime-types
|
|
@@ -11917,1088 +11941,1189 @@ var mimeDb = require$$0;
|
|
|
11917
11941
|
* MIT Licensed
|
|
11918
11942
|
*/
|
|
11919
11943
|
|
|
11920
|
-
|
|
11944
|
+
var hasRequiredMimeTypes;
|
|
11945
|
+
|
|
11946
|
+
function requireMimeTypes () {
|
|
11947
|
+
if (hasRequiredMimeTypes) return mimeTypes;
|
|
11948
|
+
hasRequiredMimeTypes = 1;
|
|
11949
|
+
(function (exports) {
|
|
11950
|
+
|
|
11951
|
+
/**
|
|
11952
|
+
* Module dependencies.
|
|
11953
|
+
* @private
|
|
11954
|
+
*/
|
|
11955
|
+
|
|
11956
|
+
var db = requireMimeDb();
|
|
11957
|
+
var extname = require$$1$1.extname;
|
|
11958
|
+
|
|
11959
|
+
/**
|
|
11960
|
+
* Module variables.
|
|
11961
|
+
* @private
|
|
11962
|
+
*/
|
|
11963
|
+
|
|
11964
|
+
var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
|
|
11965
|
+
var TEXT_TYPE_REGEXP = /^text\//i;
|
|
11966
|
+
|
|
11967
|
+
/**
|
|
11968
|
+
* Module exports.
|
|
11969
|
+
* @public
|
|
11970
|
+
*/
|
|
11971
|
+
|
|
11972
|
+
exports.charset = charset;
|
|
11973
|
+
exports.charsets = { lookup: charset };
|
|
11974
|
+
exports.contentType = contentType;
|
|
11975
|
+
exports.extension = extension;
|
|
11976
|
+
exports.extensions = Object.create(null);
|
|
11977
|
+
exports.lookup = lookup;
|
|
11978
|
+
exports.types = Object.create(null);
|
|
11979
|
+
|
|
11980
|
+
// Populate the extensions/types maps
|
|
11981
|
+
populateMaps(exports.extensions, exports.types);
|
|
11982
|
+
|
|
11983
|
+
/**
|
|
11984
|
+
* Get the default charset for a MIME type.
|
|
11985
|
+
*
|
|
11986
|
+
* @param {string} type
|
|
11987
|
+
* @return {boolean|string}
|
|
11988
|
+
*/
|
|
11989
|
+
|
|
11990
|
+
function charset (type) {
|
|
11991
|
+
if (!type || typeof type !== 'string') {
|
|
11992
|
+
return false
|
|
11993
|
+
}
|
|
11994
|
+
|
|
11995
|
+
// TODO: use media-typer
|
|
11996
|
+
var match = EXTRACT_TYPE_REGEXP.exec(type);
|
|
11997
|
+
var mime = match && db[match[1].toLowerCase()];
|
|
11998
|
+
|
|
11999
|
+
if (mime && mime.charset) {
|
|
12000
|
+
return mime.charset
|
|
12001
|
+
}
|
|
12002
|
+
|
|
12003
|
+
// default text/* to utf-8
|
|
12004
|
+
if (match && TEXT_TYPE_REGEXP.test(match[1])) {
|
|
12005
|
+
return 'UTF-8'
|
|
12006
|
+
}
|
|
12007
|
+
|
|
12008
|
+
return false
|
|
12009
|
+
}
|
|
12010
|
+
|
|
12011
|
+
/**
|
|
12012
|
+
* Create a full Content-Type header given a MIME type or extension.
|
|
12013
|
+
*
|
|
12014
|
+
* @param {string} str
|
|
12015
|
+
* @return {boolean|string}
|
|
12016
|
+
*/
|
|
12017
|
+
|
|
12018
|
+
function contentType (str) {
|
|
12019
|
+
// TODO: should this even be in this module?
|
|
12020
|
+
if (!str || typeof str !== 'string') {
|
|
12021
|
+
return false
|
|
12022
|
+
}
|
|
12023
|
+
|
|
12024
|
+
var mime = str.indexOf('/') === -1
|
|
12025
|
+
? exports.lookup(str)
|
|
12026
|
+
: str;
|
|
12027
|
+
|
|
12028
|
+
if (!mime) {
|
|
12029
|
+
return false
|
|
12030
|
+
}
|
|
12031
|
+
|
|
12032
|
+
// TODO: use content-type or other module
|
|
12033
|
+
if (mime.indexOf('charset') === -1) {
|
|
12034
|
+
var charset = exports.charset(mime);
|
|
12035
|
+
if (charset) mime += '; charset=' + charset.toLowerCase();
|
|
12036
|
+
}
|
|
12037
|
+
|
|
12038
|
+
return mime
|
|
12039
|
+
}
|
|
12040
|
+
|
|
12041
|
+
/**
|
|
12042
|
+
* Get the default extension for a MIME type.
|
|
12043
|
+
*
|
|
12044
|
+
* @param {string} type
|
|
12045
|
+
* @return {boolean|string}
|
|
12046
|
+
*/
|
|
12047
|
+
|
|
12048
|
+
function extension (type) {
|
|
12049
|
+
if (!type || typeof type !== 'string') {
|
|
12050
|
+
return false
|
|
12051
|
+
}
|
|
12052
|
+
|
|
12053
|
+
// TODO: use media-typer
|
|
12054
|
+
var match = EXTRACT_TYPE_REGEXP.exec(type);
|
|
12055
|
+
|
|
12056
|
+
// get extensions
|
|
12057
|
+
var exts = match && exports.extensions[match[1].toLowerCase()];
|
|
12058
|
+
|
|
12059
|
+
if (!exts || !exts.length) {
|
|
12060
|
+
return false
|
|
12061
|
+
}
|
|
12062
|
+
|
|
12063
|
+
return exts[0]
|
|
12064
|
+
}
|
|
12065
|
+
|
|
12066
|
+
/**
|
|
12067
|
+
* Lookup the MIME type for a file path/extension.
|
|
12068
|
+
*
|
|
12069
|
+
* @param {string} path
|
|
12070
|
+
* @return {boolean|string}
|
|
12071
|
+
*/
|
|
12072
|
+
|
|
12073
|
+
function lookup (path) {
|
|
12074
|
+
if (!path || typeof path !== 'string') {
|
|
12075
|
+
return false
|
|
12076
|
+
}
|
|
12077
|
+
|
|
12078
|
+
// get the extension ("ext" or ".ext" or full path)
|
|
12079
|
+
var extension = extname('x.' + path)
|
|
12080
|
+
.toLowerCase()
|
|
12081
|
+
.substr(1);
|
|
12082
|
+
|
|
12083
|
+
if (!extension) {
|
|
12084
|
+
return false
|
|
12085
|
+
}
|
|
12086
|
+
|
|
12087
|
+
return exports.types[extension] || false
|
|
12088
|
+
}
|
|
12089
|
+
|
|
12090
|
+
/**
|
|
12091
|
+
* Populate the extensions and types maps.
|
|
12092
|
+
* @private
|
|
12093
|
+
*/
|
|
12094
|
+
|
|
12095
|
+
function populateMaps (extensions, types) {
|
|
12096
|
+
// source preference (least -> most)
|
|
12097
|
+
var preference = ['nginx', 'apache', undefined, 'iana'];
|
|
12098
|
+
|
|
12099
|
+
Object.keys(db).forEach(function forEachMimeType (type) {
|
|
12100
|
+
var mime = db[type];
|
|
12101
|
+
var exts = mime.extensions;
|
|
12102
|
+
|
|
12103
|
+
if (!exts || !exts.length) {
|
|
12104
|
+
return
|
|
12105
|
+
}
|
|
12106
|
+
|
|
12107
|
+
// mime -> extensions
|
|
12108
|
+
extensions[type] = exts;
|
|
12109
|
+
|
|
12110
|
+
// extension -> mime
|
|
12111
|
+
for (var i = 0; i < exts.length; i++) {
|
|
12112
|
+
var extension = exts[i];
|
|
12113
|
+
|
|
12114
|
+
if (types[extension]) {
|
|
12115
|
+
var from = preference.indexOf(db[types[extension]].source);
|
|
12116
|
+
var to = preference.indexOf(mime.source);
|
|
12117
|
+
|
|
12118
|
+
if (types[extension] !== 'application/octet-stream' &&
|
|
12119
|
+
(from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) {
|
|
12120
|
+
// skip the remapping
|
|
12121
|
+
continue
|
|
12122
|
+
}
|
|
12123
|
+
}
|
|
12124
|
+
|
|
12125
|
+
// set the extension -> mime
|
|
12126
|
+
types[extension] = type;
|
|
12127
|
+
}
|
|
12128
|
+
});
|
|
12129
|
+
}
|
|
12130
|
+
} (mimeTypes));
|
|
12131
|
+
return mimeTypes;
|
|
12132
|
+
}
|
|
11921
12133
|
|
|
11922
|
-
|
|
11923
|
-
|
|
11924
|
-
* @private
|
|
11925
|
-
*/
|
|
12134
|
+
var defer_1;
|
|
12135
|
+
var hasRequiredDefer;
|
|
11926
12136
|
|
|
11927
|
-
|
|
11928
|
-
|
|
12137
|
+
function requireDefer () {
|
|
12138
|
+
if (hasRequiredDefer) return defer_1;
|
|
12139
|
+
hasRequiredDefer = 1;
|
|
12140
|
+
defer_1 = defer;
|
|
11929
12141
|
|
|
11930
12142
|
/**
|
|
11931
|
-
*
|
|
11932
|
-
*
|
|
12143
|
+
* Runs provided function on next iteration of the event loop
|
|
12144
|
+
*
|
|
12145
|
+
* @param {function} fn - function to run
|
|
11933
12146
|
*/
|
|
12147
|
+
function defer(fn)
|
|
12148
|
+
{
|
|
12149
|
+
var nextTick = typeof setImmediate == 'function'
|
|
12150
|
+
? setImmediate
|
|
12151
|
+
: (
|
|
12152
|
+
typeof process == 'object' && typeof process.nextTick == 'function'
|
|
12153
|
+
? process.nextTick
|
|
12154
|
+
: null
|
|
12155
|
+
);
|
|
12156
|
+
|
|
12157
|
+
if (nextTick)
|
|
12158
|
+
{
|
|
12159
|
+
nextTick(fn);
|
|
12160
|
+
}
|
|
12161
|
+
else
|
|
12162
|
+
{
|
|
12163
|
+
setTimeout(fn, 0);
|
|
12164
|
+
}
|
|
12165
|
+
}
|
|
12166
|
+
return defer_1;
|
|
12167
|
+
}
|
|
11934
12168
|
|
|
11935
|
-
|
|
11936
|
-
|
|
11937
|
-
|
|
11938
|
-
/**
|
|
11939
|
-
* Module exports.
|
|
11940
|
-
* @public
|
|
11941
|
-
*/
|
|
12169
|
+
var async_1;
|
|
12170
|
+
var hasRequiredAsync;
|
|
11942
12171
|
|
|
11943
|
-
|
|
11944
|
-
|
|
11945
|
-
|
|
11946
|
-
|
|
11947
|
-
exports.extensions = Object.create(null);
|
|
11948
|
-
exports.lookup = lookup;
|
|
11949
|
-
exports.types = Object.create(null);
|
|
12172
|
+
function requireAsync () {
|
|
12173
|
+
if (hasRequiredAsync) return async_1;
|
|
12174
|
+
hasRequiredAsync = 1;
|
|
12175
|
+
var defer = requireDefer();
|
|
11950
12176
|
|
|
11951
|
-
//
|
|
11952
|
-
|
|
12177
|
+
// API
|
|
12178
|
+
async_1 = async;
|
|
11953
12179
|
|
|
11954
12180
|
/**
|
|
11955
|
-
*
|
|
12181
|
+
* Runs provided callback asynchronously
|
|
12182
|
+
* even if callback itself is not
|
|
11956
12183
|
*
|
|
11957
|
-
* @param
|
|
11958
|
-
* @
|
|
12184
|
+
* @param {function} callback - callback to invoke
|
|
12185
|
+
* @returns {function} - augmented callback
|
|
11959
12186
|
*/
|
|
12187
|
+
function async(callback)
|
|
12188
|
+
{
|
|
12189
|
+
var isAsync = false;
|
|
12190
|
+
|
|
12191
|
+
// check if async happened
|
|
12192
|
+
defer(function() { isAsync = true; });
|
|
12193
|
+
|
|
12194
|
+
return function async_callback(err, result)
|
|
12195
|
+
{
|
|
12196
|
+
if (isAsync)
|
|
12197
|
+
{
|
|
12198
|
+
callback(err, result);
|
|
12199
|
+
}
|
|
12200
|
+
else
|
|
12201
|
+
{
|
|
12202
|
+
defer(function nextTick_callback()
|
|
12203
|
+
{
|
|
12204
|
+
callback(err, result);
|
|
12205
|
+
});
|
|
12206
|
+
}
|
|
12207
|
+
};
|
|
12208
|
+
}
|
|
12209
|
+
return async_1;
|
|
12210
|
+
}
|
|
11960
12211
|
|
|
11961
|
-
|
|
11962
|
-
|
|
11963
|
-
return false
|
|
11964
|
-
}
|
|
11965
|
-
|
|
11966
|
-
// TODO: use media-typer
|
|
11967
|
-
var match = EXTRACT_TYPE_REGEXP.exec(type);
|
|
11968
|
-
var mime = match && db[match[1].toLowerCase()];
|
|
12212
|
+
var abort_1;
|
|
12213
|
+
var hasRequiredAbort;
|
|
11969
12214
|
|
|
11970
|
-
|
|
11971
|
-
|
|
11972
|
-
|
|
12215
|
+
function requireAbort () {
|
|
12216
|
+
if (hasRequiredAbort) return abort_1;
|
|
12217
|
+
hasRequiredAbort = 1;
|
|
12218
|
+
// API
|
|
12219
|
+
abort_1 = abort;
|
|
11973
12220
|
|
|
11974
|
-
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
12221
|
+
/**
|
|
12222
|
+
* Aborts leftover active jobs
|
|
12223
|
+
*
|
|
12224
|
+
* @param {object} state - current state object
|
|
12225
|
+
*/
|
|
12226
|
+
function abort(state)
|
|
12227
|
+
{
|
|
12228
|
+
Object.keys(state.jobs).forEach(clean.bind(state));
|
|
11978
12229
|
|
|
11979
|
-
|
|
12230
|
+
// reset leftover jobs
|
|
12231
|
+
state.jobs = {};
|
|
11980
12232
|
}
|
|
11981
12233
|
|
|
11982
12234
|
/**
|
|
11983
|
-
*
|
|
12235
|
+
* Cleans up leftover job by invoking abort function for the provided job id
|
|
11984
12236
|
*
|
|
11985
|
-
* @
|
|
11986
|
-
* @
|
|
12237
|
+
* @this state
|
|
12238
|
+
* @param {string|number} key - job id to abort
|
|
11987
12239
|
*/
|
|
11988
|
-
|
|
11989
|
-
|
|
11990
|
-
|
|
11991
|
-
|
|
11992
|
-
|
|
12240
|
+
function clean(key)
|
|
12241
|
+
{
|
|
12242
|
+
if (typeof this.jobs[key] == 'function')
|
|
12243
|
+
{
|
|
12244
|
+
this.jobs[key]();
|
|
11993
12245
|
}
|
|
12246
|
+
}
|
|
12247
|
+
return abort_1;
|
|
12248
|
+
}
|
|
11994
12249
|
|
|
11995
|
-
|
|
11996
|
-
|
|
11997
|
-
: str;
|
|
11998
|
-
|
|
11999
|
-
if (!mime) {
|
|
12000
|
-
return false
|
|
12001
|
-
}
|
|
12250
|
+
var iterate_1;
|
|
12251
|
+
var hasRequiredIterate;
|
|
12002
12252
|
|
|
12003
|
-
|
|
12004
|
-
|
|
12005
|
-
|
|
12006
|
-
|
|
12007
|
-
|
|
12253
|
+
function requireIterate () {
|
|
12254
|
+
if (hasRequiredIterate) return iterate_1;
|
|
12255
|
+
hasRequiredIterate = 1;
|
|
12256
|
+
var async = requireAsync()
|
|
12257
|
+
, abort = requireAbort()
|
|
12258
|
+
;
|
|
12008
12259
|
|
|
12009
|
-
|
|
12010
|
-
|
|
12260
|
+
// API
|
|
12261
|
+
iterate_1 = iterate;
|
|
12011
12262
|
|
|
12012
12263
|
/**
|
|
12013
|
-
*
|
|
12264
|
+
* Iterates over each job object
|
|
12014
12265
|
*
|
|
12015
|
-
* @param {
|
|
12016
|
-
* @
|
|
12266
|
+
* @param {array|object} list - array or object (named list) to iterate over
|
|
12267
|
+
* @param {function} iterator - iterator to run
|
|
12268
|
+
* @param {object} state - current job status
|
|
12269
|
+
* @param {function} callback - invoked when all elements processed
|
|
12017
12270
|
*/
|
|
12271
|
+
function iterate(list, iterator, state, callback)
|
|
12272
|
+
{
|
|
12273
|
+
// store current index
|
|
12274
|
+
var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
|
|
12275
|
+
|
|
12276
|
+
state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
|
|
12277
|
+
{
|
|
12278
|
+
// don't repeat yourself
|
|
12279
|
+
// skip secondary callbacks
|
|
12280
|
+
if (!(key in state.jobs))
|
|
12281
|
+
{
|
|
12282
|
+
return;
|
|
12283
|
+
}
|
|
12018
12284
|
|
|
12019
|
-
|
|
12020
|
-
|
|
12021
|
-
return false
|
|
12022
|
-
}
|
|
12023
|
-
|
|
12024
|
-
// TODO: use media-typer
|
|
12025
|
-
var match = EXTRACT_TYPE_REGEXP.exec(type);
|
|
12026
|
-
|
|
12027
|
-
// get extensions
|
|
12028
|
-
var exts = match && exports.extensions[match[1].toLowerCase()];
|
|
12285
|
+
// clean up jobs
|
|
12286
|
+
delete state.jobs[key];
|
|
12029
12287
|
|
|
12030
|
-
|
|
12031
|
-
|
|
12032
|
-
|
|
12288
|
+
if (error)
|
|
12289
|
+
{
|
|
12290
|
+
// don't process rest of the results
|
|
12291
|
+
// stop still active jobs
|
|
12292
|
+
// and reset the list
|
|
12293
|
+
abort(state);
|
|
12294
|
+
}
|
|
12295
|
+
else
|
|
12296
|
+
{
|
|
12297
|
+
state.results[key] = output;
|
|
12298
|
+
}
|
|
12033
12299
|
|
|
12034
|
-
|
|
12300
|
+
// return salvaged results
|
|
12301
|
+
callback(error, state.results);
|
|
12302
|
+
});
|
|
12035
12303
|
}
|
|
12036
12304
|
|
|
12037
12305
|
/**
|
|
12038
|
-
*
|
|
12306
|
+
* Runs iterator over provided job element
|
|
12039
12307
|
*
|
|
12040
|
-
* @param
|
|
12041
|
-
* @
|
|
12308
|
+
* @param {function} iterator - iterator to invoke
|
|
12309
|
+
* @param {string|number} key - key/index of the element in the list of jobs
|
|
12310
|
+
* @param {mixed} item - job description
|
|
12311
|
+
* @param {function} callback - invoked after iterator is done with the job
|
|
12312
|
+
* @returns {function|mixed} - job abort function or something else
|
|
12042
12313
|
*/
|
|
12043
|
-
|
|
12044
|
-
|
|
12045
|
-
|
|
12046
|
-
|
|
12314
|
+
function runJob(iterator, key, item, callback)
|
|
12315
|
+
{
|
|
12316
|
+
var aborter;
|
|
12317
|
+
|
|
12318
|
+
// allow shortcut if iterator expects only two arguments
|
|
12319
|
+
if (iterator.length == 2)
|
|
12320
|
+
{
|
|
12321
|
+
aborter = iterator(item, async(callback));
|
|
12047
12322
|
}
|
|
12048
|
-
|
|
12049
|
-
|
|
12050
|
-
|
|
12051
|
-
|
|
12052
|
-
.substr(1);
|
|
12053
|
-
|
|
12054
|
-
if (!extension) {
|
|
12055
|
-
return false
|
|
12323
|
+
// otherwise go with full three arguments
|
|
12324
|
+
else
|
|
12325
|
+
{
|
|
12326
|
+
aborter = iterator(item, key, async(callback));
|
|
12056
12327
|
}
|
|
12057
12328
|
|
|
12058
|
-
return
|
|
12329
|
+
return aborter;
|
|
12059
12330
|
}
|
|
12331
|
+
return iterate_1;
|
|
12332
|
+
}
|
|
12060
12333
|
|
|
12061
|
-
|
|
12062
|
-
|
|
12063
|
-
* @private
|
|
12064
|
-
*/
|
|
12065
|
-
|
|
12066
|
-
function populateMaps (extensions, types) {
|
|
12067
|
-
// source preference (least -> most)
|
|
12068
|
-
var preference = ['nginx', 'apache', undefined, 'iana'];
|
|
12334
|
+
var state_1;
|
|
12335
|
+
var hasRequiredState;
|
|
12069
12336
|
|
|
12070
|
-
|
|
12071
|
-
|
|
12072
|
-
|
|
12337
|
+
function requireState () {
|
|
12338
|
+
if (hasRequiredState) return state_1;
|
|
12339
|
+
hasRequiredState = 1;
|
|
12340
|
+
// API
|
|
12341
|
+
state_1 = state;
|
|
12073
12342
|
|
|
12074
|
-
|
|
12075
|
-
|
|
12343
|
+
/**
|
|
12344
|
+
* Creates initial state object
|
|
12345
|
+
* for iteration over list
|
|
12346
|
+
*
|
|
12347
|
+
* @param {array|object} list - list to iterate over
|
|
12348
|
+
* @param {function|null} sortMethod - function to use for keys sort,
|
|
12349
|
+
* or `null` to keep them as is
|
|
12350
|
+
* @returns {object} - initial state object
|
|
12351
|
+
*/
|
|
12352
|
+
function state(list, sortMethod)
|
|
12353
|
+
{
|
|
12354
|
+
var isNamedList = !Array.isArray(list)
|
|
12355
|
+
, initState =
|
|
12356
|
+
{
|
|
12357
|
+
index : 0,
|
|
12358
|
+
keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
|
|
12359
|
+
jobs : {},
|
|
12360
|
+
results : isNamedList ? {} : [],
|
|
12361
|
+
size : isNamedList ? Object.keys(list).length : list.length
|
|
12076
12362
|
}
|
|
12363
|
+
;
|
|
12364
|
+
|
|
12365
|
+
if (sortMethod)
|
|
12366
|
+
{
|
|
12367
|
+
// sort array keys based on it's values
|
|
12368
|
+
// sort object's keys just on own merit
|
|
12369
|
+
initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
|
|
12370
|
+
{
|
|
12371
|
+
return sortMethod(list[a], list[b]);
|
|
12372
|
+
});
|
|
12373
|
+
}
|
|
12077
12374
|
|
|
12078
|
-
|
|
12079
|
-
|
|
12375
|
+
return initState;
|
|
12376
|
+
}
|
|
12377
|
+
return state_1;
|
|
12378
|
+
}
|
|
12080
12379
|
|
|
12081
|
-
|
|
12082
|
-
|
|
12083
|
-
var extension = exts[i];
|
|
12380
|
+
var terminator_1;
|
|
12381
|
+
var hasRequiredTerminator;
|
|
12084
12382
|
|
|
12085
|
-
|
|
12086
|
-
|
|
12087
|
-
|
|
12383
|
+
function requireTerminator () {
|
|
12384
|
+
if (hasRequiredTerminator) return terminator_1;
|
|
12385
|
+
hasRequiredTerminator = 1;
|
|
12386
|
+
var abort = requireAbort()
|
|
12387
|
+
, async = requireAsync()
|
|
12388
|
+
;
|
|
12088
12389
|
|
|
12089
|
-
|
|
12090
|
-
|
|
12091
|
-
// skip the remapping
|
|
12092
|
-
continue
|
|
12093
|
-
}
|
|
12094
|
-
}
|
|
12390
|
+
// API
|
|
12391
|
+
terminator_1 = terminator;
|
|
12095
12392
|
|
|
12096
|
-
|
|
12097
|
-
|
|
12098
|
-
|
|
12099
|
-
|
|
12100
|
-
|
|
12101
|
-
|
|
12102
|
-
|
|
12103
|
-
|
|
12104
|
-
|
|
12105
|
-
|
|
12106
|
-
|
|
12107
|
-
|
|
12108
|
-
* @param {function} fn - function to run
|
|
12109
|
-
*/
|
|
12110
|
-
function defer$1(fn)
|
|
12111
|
-
{
|
|
12112
|
-
var nextTick = typeof setImmediate == 'function'
|
|
12113
|
-
? setImmediate
|
|
12114
|
-
: (
|
|
12115
|
-
typeof process == 'object' && typeof process.nextTick == 'function'
|
|
12116
|
-
? process.nextTick
|
|
12117
|
-
: null
|
|
12118
|
-
);
|
|
12119
|
-
|
|
12120
|
-
if (nextTick)
|
|
12121
|
-
{
|
|
12122
|
-
nextTick(fn);
|
|
12123
|
-
}
|
|
12124
|
-
else
|
|
12125
|
-
{
|
|
12126
|
-
setTimeout(fn, 0);
|
|
12127
|
-
}
|
|
12128
|
-
}
|
|
12393
|
+
/**
|
|
12394
|
+
* Terminates jobs in the attached state context
|
|
12395
|
+
*
|
|
12396
|
+
* @this AsyncKitState#
|
|
12397
|
+
* @param {function} callback - final callback to invoke after termination
|
|
12398
|
+
*/
|
|
12399
|
+
function terminator(callback)
|
|
12400
|
+
{
|
|
12401
|
+
if (!Object.keys(this.jobs).length)
|
|
12402
|
+
{
|
|
12403
|
+
return;
|
|
12404
|
+
}
|
|
12129
12405
|
|
|
12130
|
-
|
|
12406
|
+
// fast forward iteration index
|
|
12407
|
+
this.index = this.size;
|
|
12131
12408
|
|
|
12132
|
-
//
|
|
12133
|
-
|
|
12409
|
+
// abort jobs
|
|
12410
|
+
abort(this);
|
|
12134
12411
|
|
|
12135
|
-
|
|
12136
|
-
|
|
12137
|
-
|
|
12138
|
-
|
|
12139
|
-
* @param {function} callback - callback to invoke
|
|
12140
|
-
* @returns {function} - augmented callback
|
|
12141
|
-
*/
|
|
12142
|
-
function async$2(callback)
|
|
12143
|
-
{
|
|
12144
|
-
var isAsync = false;
|
|
12145
|
-
|
|
12146
|
-
// check if async happened
|
|
12147
|
-
defer(function() { isAsync = true; });
|
|
12148
|
-
|
|
12149
|
-
return function async_callback(err, result)
|
|
12150
|
-
{
|
|
12151
|
-
if (isAsync)
|
|
12152
|
-
{
|
|
12153
|
-
callback(err, result);
|
|
12154
|
-
}
|
|
12155
|
-
else
|
|
12156
|
-
{
|
|
12157
|
-
defer(function nextTick_callback()
|
|
12158
|
-
{
|
|
12159
|
-
callback(err, result);
|
|
12160
|
-
});
|
|
12161
|
-
}
|
|
12162
|
-
};
|
|
12412
|
+
// send back results we have so far
|
|
12413
|
+
async(callback)(null, this.results);
|
|
12414
|
+
}
|
|
12415
|
+
return terminator_1;
|
|
12163
12416
|
}
|
|
12164
12417
|
|
|
12165
|
-
|
|
12166
|
-
var
|
|
12418
|
+
var parallel_1;
|
|
12419
|
+
var hasRequiredParallel;
|
|
12167
12420
|
|
|
12168
|
-
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
|
|
12172
|
-
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
Object.keys(state.jobs).forEach(clean.bind(state));
|
|
12421
|
+
function requireParallel () {
|
|
12422
|
+
if (hasRequiredParallel) return parallel_1;
|
|
12423
|
+
hasRequiredParallel = 1;
|
|
12424
|
+
var iterate = requireIterate()
|
|
12425
|
+
, initState = requireState()
|
|
12426
|
+
, terminator = requireTerminator()
|
|
12427
|
+
;
|
|
12176
12428
|
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
}
|
|
12429
|
+
// Public API
|
|
12430
|
+
parallel_1 = parallel;
|
|
12180
12431
|
|
|
12181
|
-
/**
|
|
12182
|
-
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
function
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
|
|
12191
|
-
|
|
12192
|
-
|
|
12193
|
-
|
|
12432
|
+
/**
|
|
12433
|
+
* Runs iterator over provided array elements in parallel
|
|
12434
|
+
*
|
|
12435
|
+
* @param {array|object} list - array or object (named list) to iterate over
|
|
12436
|
+
* @param {function} iterator - iterator to run
|
|
12437
|
+
* @param {function} callback - invoked when all elements processed
|
|
12438
|
+
* @returns {function} - jobs terminator
|
|
12439
|
+
*/
|
|
12440
|
+
function parallel(list, iterator, callback)
|
|
12441
|
+
{
|
|
12442
|
+
var state = initState(list);
|
|
12443
|
+
|
|
12444
|
+
while (state.index < (state['keyedList'] || list).length)
|
|
12445
|
+
{
|
|
12446
|
+
iterate(list, iterator, state, function(error, result)
|
|
12447
|
+
{
|
|
12448
|
+
if (error)
|
|
12449
|
+
{
|
|
12450
|
+
callback(error, result);
|
|
12451
|
+
return;
|
|
12452
|
+
}
|
|
12194
12453
|
|
|
12195
|
-
|
|
12196
|
-
|
|
12197
|
-
|
|
12454
|
+
// looks like it's the last one
|
|
12455
|
+
if (Object.keys(state.jobs).length === 0)
|
|
12456
|
+
{
|
|
12457
|
+
callback(null, state.results);
|
|
12458
|
+
return;
|
|
12459
|
+
}
|
|
12460
|
+
});
|
|
12198
12461
|
|
|
12199
|
-
|
|
12200
|
-
|
|
12462
|
+
state.index++;
|
|
12463
|
+
}
|
|
12201
12464
|
|
|
12202
|
-
|
|
12203
|
-
|
|
12204
|
-
|
|
12205
|
-
|
|
12206
|
-
* @param {function} iterator - iterator to run
|
|
12207
|
-
* @param {object} state - current job status
|
|
12208
|
-
* @param {function} callback - invoked when all elements processed
|
|
12209
|
-
*/
|
|
12210
|
-
function iterate$2(list, iterator, state, callback)
|
|
12211
|
-
{
|
|
12212
|
-
// store current index
|
|
12213
|
-
var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
|
|
12214
|
-
|
|
12215
|
-
state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
|
|
12216
|
-
{
|
|
12217
|
-
// don't repeat yourself
|
|
12218
|
-
// skip secondary callbacks
|
|
12219
|
-
if (!(key in state.jobs))
|
|
12220
|
-
{
|
|
12221
|
-
return;
|
|
12222
|
-
}
|
|
12465
|
+
return terminator.bind(state, callback);
|
|
12466
|
+
}
|
|
12467
|
+
return parallel_1;
|
|
12468
|
+
}
|
|
12223
12469
|
|
|
12224
|
-
|
|
12225
|
-
delete state.jobs[key];
|
|
12470
|
+
var serialOrdered = {exports: {}};
|
|
12226
12471
|
|
|
12227
|
-
|
|
12228
|
-
{
|
|
12229
|
-
// don't process rest of the results
|
|
12230
|
-
// stop still active jobs
|
|
12231
|
-
// and reset the list
|
|
12232
|
-
abort$1(state);
|
|
12233
|
-
}
|
|
12234
|
-
else
|
|
12235
|
-
{
|
|
12236
|
-
state.results[key] = output;
|
|
12237
|
-
}
|
|
12472
|
+
var hasRequiredSerialOrdered;
|
|
12238
12473
|
|
|
12239
|
-
|
|
12240
|
-
|
|
12241
|
-
|
|
12242
|
-
|
|
12474
|
+
function requireSerialOrdered () {
|
|
12475
|
+
if (hasRequiredSerialOrdered) return serialOrdered.exports;
|
|
12476
|
+
hasRequiredSerialOrdered = 1;
|
|
12477
|
+
var iterate = requireIterate()
|
|
12478
|
+
, initState = requireState()
|
|
12479
|
+
, terminator = requireTerminator()
|
|
12480
|
+
;
|
|
12243
12481
|
|
|
12244
|
-
|
|
12245
|
-
|
|
12246
|
-
|
|
12247
|
-
|
|
12248
|
-
|
|
12249
|
-
* @param {mixed} item - job description
|
|
12250
|
-
* @param {function} callback - invoked after iterator is done with the job
|
|
12251
|
-
* @returns {function|mixed} - job abort function or something else
|
|
12252
|
-
*/
|
|
12253
|
-
function runJob(iterator, key, item, callback)
|
|
12254
|
-
{
|
|
12255
|
-
var aborter;
|
|
12256
|
-
|
|
12257
|
-
// allow shortcut if iterator expects only two arguments
|
|
12258
|
-
if (iterator.length == 2)
|
|
12259
|
-
{
|
|
12260
|
-
aborter = iterator(item, async$1(callback));
|
|
12261
|
-
}
|
|
12262
|
-
// otherwise go with full three arguments
|
|
12263
|
-
else
|
|
12264
|
-
{
|
|
12265
|
-
aborter = iterator(item, key, async$1(callback));
|
|
12266
|
-
}
|
|
12267
|
-
|
|
12268
|
-
return aborter;
|
|
12269
|
-
}
|
|
12482
|
+
// Public API
|
|
12483
|
+
serialOrdered.exports = serialOrdered$1;
|
|
12484
|
+
// sorting helpers
|
|
12485
|
+
serialOrdered.exports.ascending = ascending;
|
|
12486
|
+
serialOrdered.exports.descending = descending;
|
|
12270
12487
|
|
|
12271
|
-
|
|
12272
|
-
|
|
12273
|
-
|
|
12274
|
-
|
|
12275
|
-
|
|
12276
|
-
|
|
12277
|
-
|
|
12278
|
-
|
|
12279
|
-
|
|
12280
|
-
|
|
12281
|
-
|
|
12282
|
-
|
|
12283
|
-
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12287
|
-
|
|
12288
|
-
|
|
12289
|
-
|
|
12290
|
-
|
|
12291
|
-
results : isNamedList ? {} : [],
|
|
12292
|
-
size : isNamedList ? Object.keys(list).length : list.length
|
|
12293
|
-
}
|
|
12294
|
-
;
|
|
12295
|
-
|
|
12296
|
-
if (sortMethod)
|
|
12297
|
-
{
|
|
12298
|
-
// sort array keys based on it's values
|
|
12299
|
-
// sort object's keys just on own merit
|
|
12300
|
-
initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
|
|
12301
|
-
{
|
|
12302
|
-
return sortMethod(list[a], list[b]);
|
|
12303
|
-
});
|
|
12304
|
-
}
|
|
12488
|
+
/**
|
|
12489
|
+
* Runs iterator over provided sorted array elements in series
|
|
12490
|
+
*
|
|
12491
|
+
* @param {array|object} list - array or object (named list) to iterate over
|
|
12492
|
+
* @param {function} iterator - iterator to run
|
|
12493
|
+
* @param {function} sortMethod - custom sort function
|
|
12494
|
+
* @param {function} callback - invoked when all elements processed
|
|
12495
|
+
* @returns {function} - jobs terminator
|
|
12496
|
+
*/
|
|
12497
|
+
function serialOrdered$1(list, iterator, sortMethod, callback)
|
|
12498
|
+
{
|
|
12499
|
+
var state = initState(list, sortMethod);
|
|
12500
|
+
|
|
12501
|
+
iterate(list, iterator, state, function iteratorHandler(error, result)
|
|
12502
|
+
{
|
|
12503
|
+
if (error)
|
|
12504
|
+
{
|
|
12505
|
+
callback(error, result);
|
|
12506
|
+
return;
|
|
12507
|
+
}
|
|
12305
12508
|
|
|
12306
|
-
|
|
12307
|
-
}
|
|
12509
|
+
state.index++;
|
|
12308
12510
|
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12511
|
+
// are we there yet?
|
|
12512
|
+
if (state.index < (state['keyedList'] || list).length)
|
|
12513
|
+
{
|
|
12514
|
+
iterate(list, iterator, state, iteratorHandler);
|
|
12515
|
+
return;
|
|
12516
|
+
}
|
|
12312
12517
|
|
|
12313
|
-
//
|
|
12314
|
-
|
|
12518
|
+
// done here
|
|
12519
|
+
callback(null, state.results);
|
|
12520
|
+
});
|
|
12315
12521
|
|
|
12316
|
-
|
|
12317
|
-
|
|
12318
|
-
*
|
|
12319
|
-
* @this AsyncKitState#
|
|
12320
|
-
* @param {function} callback - final callback to invoke after termination
|
|
12321
|
-
*/
|
|
12322
|
-
function terminator$2(callback)
|
|
12323
|
-
{
|
|
12324
|
-
if (!Object.keys(this.jobs).length)
|
|
12325
|
-
{
|
|
12326
|
-
return;
|
|
12327
|
-
}
|
|
12522
|
+
return terminator.bind(state, callback);
|
|
12523
|
+
}
|
|
12328
12524
|
|
|
12329
|
-
|
|
12330
|
-
|
|
12525
|
+
/*
|
|
12526
|
+
* -- Sort methods
|
|
12527
|
+
*/
|
|
12331
12528
|
|
|
12332
|
-
|
|
12333
|
-
|
|
12529
|
+
/**
|
|
12530
|
+
* sort helper to sort array elements in ascending order
|
|
12531
|
+
*
|
|
12532
|
+
* @param {mixed} a - an item to compare
|
|
12533
|
+
* @param {mixed} b - an item to compare
|
|
12534
|
+
* @returns {number} - comparison result
|
|
12535
|
+
*/
|
|
12536
|
+
function ascending(a, b)
|
|
12537
|
+
{
|
|
12538
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
12539
|
+
}
|
|
12334
12540
|
|
|
12335
|
-
|
|
12336
|
-
|
|
12541
|
+
/**
|
|
12542
|
+
* sort helper to sort array elements in descending order
|
|
12543
|
+
*
|
|
12544
|
+
* @param {mixed} a - an item to compare
|
|
12545
|
+
* @param {mixed} b - an item to compare
|
|
12546
|
+
* @returns {number} - comparison result
|
|
12547
|
+
*/
|
|
12548
|
+
function descending(a, b)
|
|
12549
|
+
{
|
|
12550
|
+
return -1 * ascending(a, b);
|
|
12551
|
+
}
|
|
12552
|
+
return serialOrdered.exports;
|
|
12337
12553
|
}
|
|
12338
12554
|
|
|
12339
|
-
var
|
|
12340
|
-
|
|
12341
|
-
, terminator$1 = terminator_1
|
|
12342
|
-
;
|
|
12343
|
-
|
|
12344
|
-
// Public API
|
|
12345
|
-
var parallel_1 = parallel;
|
|
12346
|
-
|
|
12347
|
-
/**
|
|
12348
|
-
* Runs iterator over provided array elements in parallel
|
|
12349
|
-
*
|
|
12350
|
-
* @param {array|object} list - array or object (named list) to iterate over
|
|
12351
|
-
* @param {function} iterator - iterator to run
|
|
12352
|
-
* @param {function} callback - invoked when all elements processed
|
|
12353
|
-
* @returns {function} - jobs terminator
|
|
12354
|
-
*/
|
|
12355
|
-
function parallel(list, iterator, callback)
|
|
12356
|
-
{
|
|
12357
|
-
var state = initState$1(list);
|
|
12358
|
-
|
|
12359
|
-
while (state.index < (state['keyedList'] || list).length)
|
|
12360
|
-
{
|
|
12361
|
-
iterate$1(list, iterator, state, function(error, result)
|
|
12362
|
-
{
|
|
12363
|
-
if (error)
|
|
12364
|
-
{
|
|
12365
|
-
callback(error, result);
|
|
12366
|
-
return;
|
|
12367
|
-
}
|
|
12555
|
+
var serial_1;
|
|
12556
|
+
var hasRequiredSerial;
|
|
12368
12557
|
|
|
12369
|
-
|
|
12370
|
-
|
|
12371
|
-
|
|
12372
|
-
|
|
12373
|
-
return;
|
|
12374
|
-
}
|
|
12375
|
-
});
|
|
12558
|
+
function requireSerial () {
|
|
12559
|
+
if (hasRequiredSerial) return serial_1;
|
|
12560
|
+
hasRequiredSerial = 1;
|
|
12561
|
+
var serialOrdered = requireSerialOrdered();
|
|
12376
12562
|
|
|
12377
|
-
|
|
12378
|
-
|
|
12563
|
+
// Public API
|
|
12564
|
+
serial_1 = serial;
|
|
12379
12565
|
|
|
12380
|
-
|
|
12566
|
+
/**
|
|
12567
|
+
* Runs iterator over provided array elements in series
|
|
12568
|
+
*
|
|
12569
|
+
* @param {array|object} list - array or object (named list) to iterate over
|
|
12570
|
+
* @param {function} iterator - iterator to run
|
|
12571
|
+
* @param {function} callback - invoked when all elements processed
|
|
12572
|
+
* @returns {function} - jobs terminator
|
|
12573
|
+
*/
|
|
12574
|
+
function serial(list, iterator, callback)
|
|
12575
|
+
{
|
|
12576
|
+
return serialOrdered(list, iterator, null, callback);
|
|
12577
|
+
}
|
|
12578
|
+
return serial_1;
|
|
12381
12579
|
}
|
|
12382
12580
|
|
|
12383
|
-
var
|
|
12384
|
-
|
|
12385
|
-
|
|
12386
|
-
|
|
12387
|
-
|
|
12388
|
-
|
|
12389
|
-
|
|
12390
|
-
|
|
12391
|
-
|
|
12392
|
-
|
|
12393
|
-
serialOrdered
|
|
12394
|
-
|
|
12395
|
-
|
|
12396
|
-
|
|
12397
|
-
* Runs iterator over provided sorted array elements in series
|
|
12398
|
-
*
|
|
12399
|
-
* @param {array|object} list - array or object (named list) to iterate over
|
|
12400
|
-
* @param {function} iterator - iterator to run
|
|
12401
|
-
* @param {function} sortMethod - custom sort function
|
|
12402
|
-
* @param {function} callback - invoked when all elements processed
|
|
12403
|
-
* @returns {function} - jobs terminator
|
|
12404
|
-
*/
|
|
12405
|
-
function serialOrdered$1(list, iterator, sortMethod, callback)
|
|
12406
|
-
{
|
|
12407
|
-
var state = initState(list, sortMethod);
|
|
12408
|
-
|
|
12409
|
-
iterate(list, iterator, state, function iteratorHandler(error, result)
|
|
12410
|
-
{
|
|
12411
|
-
if (error)
|
|
12412
|
-
{
|
|
12413
|
-
callback(error, result);
|
|
12414
|
-
return;
|
|
12415
|
-
}
|
|
12581
|
+
var asynckit;
|
|
12582
|
+
var hasRequiredAsynckit;
|
|
12583
|
+
|
|
12584
|
+
function requireAsynckit () {
|
|
12585
|
+
if (hasRequiredAsynckit) return asynckit;
|
|
12586
|
+
hasRequiredAsynckit = 1;
|
|
12587
|
+
asynckit =
|
|
12588
|
+
{
|
|
12589
|
+
parallel : requireParallel(),
|
|
12590
|
+
serial : requireSerial(),
|
|
12591
|
+
serialOrdered : requireSerialOrdered()
|
|
12592
|
+
};
|
|
12593
|
+
return asynckit;
|
|
12594
|
+
}
|
|
12416
12595
|
|
|
12417
|
-
|
|
12596
|
+
var populate;
|
|
12597
|
+
var hasRequiredPopulate;
|
|
12418
12598
|
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
|
|
12423
|
-
|
|
12424
|
-
}
|
|
12599
|
+
function requirePopulate () {
|
|
12600
|
+
if (hasRequiredPopulate) return populate;
|
|
12601
|
+
hasRequiredPopulate = 1;
|
|
12602
|
+
// populates missing values
|
|
12603
|
+
populate = function(dst, src) {
|
|
12425
12604
|
|
|
12426
|
-
|
|
12427
|
-
|
|
12428
|
-
|
|
12605
|
+
Object.keys(src).forEach(function(prop)
|
|
12606
|
+
{
|
|
12607
|
+
dst[prop] = dst[prop] || src[prop];
|
|
12608
|
+
});
|
|
12429
12609
|
|
|
12430
|
-
|
|
12610
|
+
return dst;
|
|
12611
|
+
};
|
|
12612
|
+
return populate;
|
|
12431
12613
|
}
|
|
12432
12614
|
|
|
12433
|
-
|
|
12434
|
-
|
|
12435
|
-
|
|
12615
|
+
var form_data;
|
|
12616
|
+
var hasRequiredForm_data;
|
|
12617
|
+
|
|
12618
|
+
function requireForm_data () {
|
|
12619
|
+
if (hasRequiredForm_data) return form_data;
|
|
12620
|
+
hasRequiredForm_data = 1;
|
|
12621
|
+
var CombinedStream = requireCombined_stream();
|
|
12622
|
+
var util = require$$1;
|
|
12623
|
+
var path = require$$1$1;
|
|
12624
|
+
var http = require$$3;
|
|
12625
|
+
var https = require$$4;
|
|
12626
|
+
var parseUrl = require$$5.parse;
|
|
12627
|
+
var fs = require$$6;
|
|
12628
|
+
var Stream = require$$0$1.Stream;
|
|
12629
|
+
var mime = requireMimeTypes();
|
|
12630
|
+
var asynckit = requireAsynckit();
|
|
12631
|
+
var populate = requirePopulate();
|
|
12632
|
+
|
|
12633
|
+
// Public API
|
|
12634
|
+
form_data = FormData;
|
|
12635
|
+
|
|
12636
|
+
// make it a Stream
|
|
12637
|
+
util.inherits(FormData, CombinedStream);
|
|
12436
12638
|
|
|
12437
|
-
/**
|
|
12438
|
-
|
|
12439
|
-
|
|
12440
|
-
|
|
12441
|
-
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
{
|
|
12446
|
-
|
|
12447
|
-
|
|
12639
|
+
/**
|
|
12640
|
+
* Create readable "multipart/form-data" streams.
|
|
12641
|
+
* Can be used to submit forms
|
|
12642
|
+
* and file uploads to other web applications.
|
|
12643
|
+
*
|
|
12644
|
+
* @constructor
|
|
12645
|
+
* @param {Object} options - Properties to be added/overriden for FormData and CombinedStream
|
|
12646
|
+
*/
|
|
12647
|
+
function FormData(options) {
|
|
12648
|
+
if (!(this instanceof FormData)) {
|
|
12649
|
+
return new FormData(options);
|
|
12650
|
+
}
|
|
12448
12651
|
|
|
12449
|
-
|
|
12450
|
-
|
|
12451
|
-
|
|
12452
|
-
* @param {mixed} a - an item to compare
|
|
12453
|
-
* @param {mixed} b - an item to compare
|
|
12454
|
-
* @returns {number} - comparison result
|
|
12455
|
-
*/
|
|
12456
|
-
function descending(a, b)
|
|
12457
|
-
{
|
|
12458
|
-
return -1 * ascending(a, b);
|
|
12459
|
-
}
|
|
12652
|
+
this._overheadLength = 0;
|
|
12653
|
+
this._valueLength = 0;
|
|
12654
|
+
this._valuesToMeasure = [];
|
|
12460
12655
|
|
|
12461
|
-
|
|
12656
|
+
CombinedStream.call(this);
|
|
12462
12657
|
|
|
12463
|
-
|
|
12658
|
+
options = options || {};
|
|
12659
|
+
for (var option in options) {
|
|
12660
|
+
this[option] = options[option];
|
|
12661
|
+
}
|
|
12662
|
+
}
|
|
12464
12663
|
|
|
12465
|
-
|
|
12466
|
-
|
|
12664
|
+
FormData.LINE_BREAK = '\r\n';
|
|
12665
|
+
FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
|
|
12467
12666
|
|
|
12468
|
-
|
|
12469
|
-
* Runs iterator over provided array elements in series
|
|
12470
|
-
*
|
|
12471
|
-
* @param {array|object} list - array or object (named list) to iterate over
|
|
12472
|
-
* @param {function} iterator - iterator to run
|
|
12473
|
-
* @param {function} callback - invoked when all elements processed
|
|
12474
|
-
* @returns {function} - jobs terminator
|
|
12475
|
-
*/
|
|
12476
|
-
function serial(list, iterator, callback)
|
|
12477
|
-
{
|
|
12478
|
-
return serialOrdered(list, iterator, null, callback);
|
|
12479
|
-
}
|
|
12667
|
+
FormData.prototype.append = function(field, value, options) {
|
|
12480
12668
|
|
|
12481
|
-
|
|
12482
|
-
{
|
|
12483
|
-
parallel : parallel_1,
|
|
12484
|
-
serial : serial_1,
|
|
12485
|
-
serialOrdered : serialOrderedExports
|
|
12486
|
-
};
|
|
12669
|
+
options = options || {};
|
|
12487
12670
|
|
|
12488
|
-
//
|
|
12489
|
-
|
|
12671
|
+
// allow filename as single option
|
|
12672
|
+
if (typeof options == 'string') {
|
|
12673
|
+
options = {filename: options};
|
|
12674
|
+
}
|
|
12490
12675
|
|
|
12491
|
-
|
|
12492
|
-
{
|
|
12493
|
-
dst[prop] = dst[prop] || src[prop];
|
|
12494
|
-
});
|
|
12676
|
+
var append = CombinedStream.prototype.append.bind(this);
|
|
12495
12677
|
|
|
12496
|
-
|
|
12497
|
-
|
|
12678
|
+
// all that streamy business can't handle numbers
|
|
12679
|
+
if (typeof value == 'number') {
|
|
12680
|
+
value = '' + value;
|
|
12681
|
+
}
|
|
12498
12682
|
|
|
12499
|
-
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
var Stream = require$$0$1.Stream;
|
|
12507
|
-
var mime = mimeTypes;
|
|
12508
|
-
var asynckit = asynckit$1;
|
|
12509
|
-
var populate = populate$1;
|
|
12510
|
-
|
|
12511
|
-
// Public API
|
|
12512
|
-
var form_data = FormData;
|
|
12513
|
-
|
|
12514
|
-
// make it a Stream
|
|
12515
|
-
util.inherits(FormData, CombinedStream);
|
|
12516
|
-
|
|
12517
|
-
/**
|
|
12518
|
-
* Create readable "multipart/form-data" streams.
|
|
12519
|
-
* Can be used to submit forms
|
|
12520
|
-
* and file uploads to other web applications.
|
|
12521
|
-
*
|
|
12522
|
-
* @constructor
|
|
12523
|
-
* @param {Object} options - Properties to be added/overriden for FormData and CombinedStream
|
|
12524
|
-
*/
|
|
12525
|
-
function FormData(options) {
|
|
12526
|
-
if (!(this instanceof FormData)) {
|
|
12527
|
-
return new FormData(options);
|
|
12528
|
-
}
|
|
12683
|
+
// https://github.com/felixge/node-form-data/issues/38
|
|
12684
|
+
if (util.isArray(value)) {
|
|
12685
|
+
// Please convert your array into string
|
|
12686
|
+
// the way web server expects it
|
|
12687
|
+
this._error(new Error('Arrays are not supported.'));
|
|
12688
|
+
return;
|
|
12689
|
+
}
|
|
12529
12690
|
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12691
|
+
var header = this._multiPartHeader(field, value, options);
|
|
12692
|
+
var footer = this._multiPartFooter();
|
|
12693
|
+
|
|
12694
|
+
append(header);
|
|
12695
|
+
append(value);
|
|
12696
|
+
append(footer);
|
|
12697
|
+
|
|
12698
|
+
// pass along options.knownLength
|
|
12699
|
+
this._trackLength(header, value, options);
|
|
12700
|
+
};
|
|
12701
|
+
|
|
12702
|
+
FormData.prototype._trackLength = function(header, value, options) {
|
|
12703
|
+
var valueLength = 0;
|
|
12704
|
+
|
|
12705
|
+
// used w/ getLengthSync(), when length is known.
|
|
12706
|
+
// e.g. for streaming directly from a remote server,
|
|
12707
|
+
// w/ a known file a size, and not wanting to wait for
|
|
12708
|
+
// incoming file to finish to get its size.
|
|
12709
|
+
if (options.knownLength != null) {
|
|
12710
|
+
valueLength += +options.knownLength;
|
|
12711
|
+
} else if (Buffer.isBuffer(value)) {
|
|
12712
|
+
valueLength = value.length;
|
|
12713
|
+
} else if (typeof value === 'string') {
|
|
12714
|
+
valueLength = Buffer.byteLength(value);
|
|
12715
|
+
}
|
|
12533
12716
|
|
|
12534
|
-
|
|
12717
|
+
this._valueLength += valueLength;
|
|
12535
12718
|
|
|
12536
|
-
|
|
12537
|
-
|
|
12538
|
-
|
|
12539
|
-
|
|
12540
|
-
}
|
|
12719
|
+
// @check why add CRLF? does this account for custom/multiple CRLFs?
|
|
12720
|
+
this._overheadLength +=
|
|
12721
|
+
Buffer.byteLength(header) +
|
|
12722
|
+
FormData.LINE_BREAK.length;
|
|
12541
12723
|
|
|
12542
|
-
|
|
12543
|
-
|
|
12724
|
+
// empty or either doesn't have path or not an http response or not a stream
|
|
12725
|
+
if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) && !(value instanceof Stream))) {
|
|
12726
|
+
return;
|
|
12727
|
+
}
|
|
12544
12728
|
|
|
12545
|
-
|
|
12729
|
+
// no need to bother with the length
|
|
12730
|
+
if (!options.knownLength) {
|
|
12731
|
+
this._valuesToMeasure.push(value);
|
|
12732
|
+
}
|
|
12733
|
+
};
|
|
12546
12734
|
|
|
12547
|
-
|
|
12735
|
+
FormData.prototype._lengthRetriever = function(value, callback) {
|
|
12548
12736
|
|
|
12549
|
-
|
|
12550
|
-
if (typeof options == 'string') {
|
|
12551
|
-
options = {filename: options};
|
|
12552
|
-
}
|
|
12737
|
+
if (value.hasOwnProperty('fd')) {
|
|
12553
12738
|
|
|
12554
|
-
|
|
12739
|
+
// take read range into a account
|
|
12740
|
+
// `end` = Infinity –> read file till the end
|
|
12741
|
+
//
|
|
12742
|
+
// TODO: Looks like there is bug in Node fs.createReadStream
|
|
12743
|
+
// it doesn't respect `end` options without `start` options
|
|
12744
|
+
// Fix it when node fixes it.
|
|
12745
|
+
// https://github.com/joyent/node/issues/7819
|
|
12746
|
+
if (value.end != undefined && value.end != Infinity && value.start != undefined) {
|
|
12555
12747
|
|
|
12556
|
-
|
|
12557
|
-
|
|
12558
|
-
|
|
12559
|
-
|
|
12748
|
+
// when end specified
|
|
12749
|
+
// no need to calculate range
|
|
12750
|
+
// inclusive, starts with 0
|
|
12751
|
+
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
|
12560
12752
|
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
|
|
12565
|
-
this._error(new Error('Arrays are not supported.'));
|
|
12566
|
-
return;
|
|
12567
|
-
}
|
|
12753
|
+
// not that fast snoopy
|
|
12754
|
+
} else {
|
|
12755
|
+
// still need to fetch file size from fs
|
|
12756
|
+
fs.stat(value.path, function(err, stat) {
|
|
12568
12757
|
|
|
12569
|
-
|
|
12570
|
-
var footer = this._multiPartFooter();
|
|
12758
|
+
var fileSize;
|
|
12571
12759
|
|
|
12572
|
-
|
|
12573
|
-
|
|
12574
|
-
|
|
12760
|
+
if (err) {
|
|
12761
|
+
callback(err);
|
|
12762
|
+
return;
|
|
12763
|
+
}
|
|
12575
12764
|
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12765
|
+
// update final size based on the range options
|
|
12766
|
+
fileSize = stat.size - (value.start ? value.start : 0);
|
|
12767
|
+
callback(null, fileSize);
|
|
12768
|
+
});
|
|
12769
|
+
}
|
|
12579
12770
|
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
|
|
12593
|
-
|
|
12594
|
-
|
|
12595
|
-
|
|
12596
|
-
|
|
12597
|
-
|
|
12598
|
-
|
|
12599
|
-
|
|
12600
|
-
|
|
12601
|
-
|
|
12602
|
-
|
|
12603
|
-
|
|
12604
|
-
|
|
12605
|
-
|
|
12771
|
+
// or http response
|
|
12772
|
+
} else if (value.hasOwnProperty('httpVersion')) {
|
|
12773
|
+
callback(null, +value.headers['content-length']);
|
|
12774
|
+
|
|
12775
|
+
// or request stream http://github.com/mikeal/request
|
|
12776
|
+
} else if (value.hasOwnProperty('httpModule')) {
|
|
12777
|
+
// wait till response come back
|
|
12778
|
+
value.on('response', function(response) {
|
|
12779
|
+
value.pause();
|
|
12780
|
+
callback(null, +response.headers['content-length']);
|
|
12781
|
+
});
|
|
12782
|
+
value.resume();
|
|
12783
|
+
|
|
12784
|
+
// something else
|
|
12785
|
+
} else {
|
|
12786
|
+
callback('Unknown stream');
|
|
12787
|
+
}
|
|
12788
|
+
};
|
|
12789
|
+
|
|
12790
|
+
FormData.prototype._multiPartHeader = function(field, value, options) {
|
|
12791
|
+
// custom header specified (as string)?
|
|
12792
|
+
// it becomes responsible for boundary
|
|
12793
|
+
// (e.g. to handle extra CRLFs on .NET servers)
|
|
12794
|
+
if (typeof options.header == 'string') {
|
|
12795
|
+
return options.header;
|
|
12796
|
+
}
|
|
12606
12797
|
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
this._valuesToMeasure.push(value);
|
|
12610
|
-
}
|
|
12611
|
-
};
|
|
12798
|
+
var contentDisposition = this._getContentDisposition(value, options);
|
|
12799
|
+
var contentType = this._getContentType(value, options);
|
|
12612
12800
|
|
|
12613
|
-
|
|
12801
|
+
var contents = '';
|
|
12802
|
+
var headers = {
|
|
12803
|
+
// add custom disposition as third element or keep it two elements if not
|
|
12804
|
+
'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
|
|
12805
|
+
// if no content type. allow it to be empty array
|
|
12806
|
+
'Content-Type': [].concat(contentType || [])
|
|
12807
|
+
};
|
|
12614
12808
|
|
|
12615
|
-
|
|
12809
|
+
// allow custom headers.
|
|
12810
|
+
if (typeof options.header == 'object') {
|
|
12811
|
+
populate(headers, options.header);
|
|
12812
|
+
}
|
|
12616
12813
|
|
|
12617
|
-
|
|
12618
|
-
|
|
12619
|
-
|
|
12620
|
-
|
|
12621
|
-
// it doesn't respect `end` options without `start` options
|
|
12622
|
-
// Fix it when node fixes it.
|
|
12623
|
-
// https://github.com/joyent/node/issues/7819
|
|
12624
|
-
if (value.end != undefined && value.end != Infinity && value.start != undefined) {
|
|
12814
|
+
var header;
|
|
12815
|
+
for (var prop in headers) {
|
|
12816
|
+
if (!headers.hasOwnProperty(prop)) continue;
|
|
12817
|
+
header = headers[prop];
|
|
12625
12818
|
|
|
12626
|
-
|
|
12627
|
-
|
|
12628
|
-
|
|
12629
|
-
|
|
12819
|
+
// skip nullish headers.
|
|
12820
|
+
if (header == null) {
|
|
12821
|
+
continue;
|
|
12822
|
+
}
|
|
12630
12823
|
|
|
12631
|
-
|
|
12632
|
-
|
|
12633
|
-
|
|
12634
|
-
|
|
12824
|
+
// convert all headers to arrays.
|
|
12825
|
+
if (!Array.isArray(header)) {
|
|
12826
|
+
header = [header];
|
|
12827
|
+
}
|
|
12635
12828
|
|
|
12636
|
-
|
|
12829
|
+
// add non-empty headers.
|
|
12830
|
+
if (header.length) {
|
|
12831
|
+
contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK;
|
|
12832
|
+
}
|
|
12833
|
+
}
|
|
12637
12834
|
|
|
12638
|
-
|
|
12639
|
-
|
|
12640
|
-
|
|
12641
|
-
|
|
12835
|
+
return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
|
|
12836
|
+
};
|
|
12837
|
+
|
|
12838
|
+
FormData.prototype._getContentDisposition = function(value, options) {
|
|
12839
|
+
|
|
12840
|
+
var filename
|
|
12841
|
+
, contentDisposition
|
|
12842
|
+
;
|
|
12843
|
+
|
|
12844
|
+
if (typeof options.filepath === 'string') {
|
|
12845
|
+
// custom filepath for relative paths
|
|
12846
|
+
filename = path.normalize(options.filepath).replace(/\\/g, '/');
|
|
12847
|
+
} else if (options.filename || value.name || value.path) {
|
|
12848
|
+
// custom filename take precedence
|
|
12849
|
+
// formidable and the browser add a name property
|
|
12850
|
+
// fs- and request- streams have path property
|
|
12851
|
+
filename = path.basename(options.filename || value.name || value.path);
|
|
12852
|
+
} else if (value.readable && value.hasOwnProperty('httpVersion')) {
|
|
12853
|
+
// or try http response
|
|
12854
|
+
filename = path.basename(value.client._httpMessage.path || '');
|
|
12855
|
+
}
|
|
12642
12856
|
|
|
12643
|
-
|
|
12644
|
-
|
|
12645
|
-
|
|
12646
|
-
});
|
|
12647
|
-
}
|
|
12857
|
+
if (filename) {
|
|
12858
|
+
contentDisposition = 'filename="' + filename + '"';
|
|
12859
|
+
}
|
|
12648
12860
|
|
|
12649
|
-
|
|
12650
|
-
|
|
12651
|
-
callback(null, +value.headers['content-length']);
|
|
12861
|
+
return contentDisposition;
|
|
12862
|
+
};
|
|
12652
12863
|
|
|
12653
|
-
|
|
12654
|
-
} else if (value.hasOwnProperty('httpModule')) {
|
|
12655
|
-
// wait till response come back
|
|
12656
|
-
value.on('response', function(response) {
|
|
12657
|
-
value.pause();
|
|
12658
|
-
callback(null, +response.headers['content-length']);
|
|
12659
|
-
});
|
|
12660
|
-
value.resume();
|
|
12864
|
+
FormData.prototype._getContentType = function(value, options) {
|
|
12661
12865
|
|
|
12662
|
-
|
|
12663
|
-
|
|
12664
|
-
callback('Unknown stream');
|
|
12665
|
-
}
|
|
12666
|
-
};
|
|
12866
|
+
// use custom content-type above all
|
|
12867
|
+
var contentType = options.contentType;
|
|
12667
12868
|
|
|
12668
|
-
|
|
12669
|
-
|
|
12670
|
-
|
|
12671
|
-
|
|
12672
|
-
if (typeof options.header == 'string') {
|
|
12673
|
-
return options.header;
|
|
12674
|
-
}
|
|
12675
|
-
|
|
12676
|
-
var contentDisposition = this._getContentDisposition(value, options);
|
|
12677
|
-
var contentType = this._getContentType(value, options);
|
|
12678
|
-
|
|
12679
|
-
var contents = '';
|
|
12680
|
-
var headers = {
|
|
12681
|
-
// add custom disposition as third element or keep it two elements if not
|
|
12682
|
-
'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
|
|
12683
|
-
// if no content type. allow it to be empty array
|
|
12684
|
-
'Content-Type': [].concat(contentType || [])
|
|
12685
|
-
};
|
|
12686
|
-
|
|
12687
|
-
// allow custom headers.
|
|
12688
|
-
if (typeof options.header == 'object') {
|
|
12689
|
-
populate(headers, options.header);
|
|
12690
|
-
}
|
|
12691
|
-
|
|
12692
|
-
var header;
|
|
12693
|
-
for (var prop in headers) {
|
|
12694
|
-
if (!headers.hasOwnProperty(prop)) continue;
|
|
12695
|
-
header = headers[prop];
|
|
12696
|
-
|
|
12697
|
-
// skip nullish headers.
|
|
12698
|
-
if (header == null) {
|
|
12699
|
-
continue;
|
|
12700
|
-
}
|
|
12869
|
+
// or try `name` from formidable, browser
|
|
12870
|
+
if (!contentType && value.name) {
|
|
12871
|
+
contentType = mime.lookup(value.name);
|
|
12872
|
+
}
|
|
12701
12873
|
|
|
12702
|
-
|
|
12703
|
-
|
|
12704
|
-
|
|
12705
|
-
|
|
12874
|
+
// or try `path` from fs-, request- streams
|
|
12875
|
+
if (!contentType && value.path) {
|
|
12876
|
+
contentType = mime.lookup(value.path);
|
|
12877
|
+
}
|
|
12706
12878
|
|
|
12707
|
-
|
|
12708
|
-
|
|
12709
|
-
|
|
12710
|
-
|
|
12711
|
-
}
|
|
12879
|
+
// or if it's http-reponse
|
|
12880
|
+
if (!contentType && value.readable && value.hasOwnProperty('httpVersion')) {
|
|
12881
|
+
contentType = value.headers['content-type'];
|
|
12882
|
+
}
|
|
12712
12883
|
|
|
12713
|
-
|
|
12714
|
-
|
|
12884
|
+
// or guess it from the filepath or filename
|
|
12885
|
+
if (!contentType && (options.filepath || options.filename)) {
|
|
12886
|
+
contentType = mime.lookup(options.filepath || options.filename);
|
|
12887
|
+
}
|
|
12715
12888
|
|
|
12716
|
-
|
|
12717
|
-
|
|
12718
|
-
|
|
12719
|
-
|
|
12720
|
-
;
|
|
12721
|
-
|
|
12722
|
-
if (typeof options.filepath === 'string') {
|
|
12723
|
-
// custom filepath for relative paths
|
|
12724
|
-
filename = path.normalize(options.filepath).replace(/\\/g, '/');
|
|
12725
|
-
} else if (options.filename || value.name || value.path) {
|
|
12726
|
-
// custom filename take precedence
|
|
12727
|
-
// formidable and the browser add a name property
|
|
12728
|
-
// fs- and request- streams have path property
|
|
12729
|
-
filename = path.basename(options.filename || value.name || value.path);
|
|
12730
|
-
} else if (value.readable && value.hasOwnProperty('httpVersion')) {
|
|
12731
|
-
// or try http response
|
|
12732
|
-
filename = path.basename(value.client._httpMessage.path || '');
|
|
12733
|
-
}
|
|
12734
|
-
|
|
12735
|
-
if (filename) {
|
|
12736
|
-
contentDisposition = 'filename="' + filename + '"';
|
|
12737
|
-
}
|
|
12738
|
-
|
|
12739
|
-
return contentDisposition;
|
|
12740
|
-
};
|
|
12889
|
+
// fallback to the default content type if `value` is not simple value
|
|
12890
|
+
if (!contentType && typeof value == 'object') {
|
|
12891
|
+
contentType = FormData.DEFAULT_CONTENT_TYPE;
|
|
12892
|
+
}
|
|
12741
12893
|
|
|
12742
|
-
|
|
12894
|
+
return contentType;
|
|
12895
|
+
};
|
|
12743
12896
|
|
|
12744
|
-
|
|
12745
|
-
|
|
12897
|
+
FormData.prototype._multiPartFooter = function() {
|
|
12898
|
+
return function(next) {
|
|
12899
|
+
var footer = FormData.LINE_BREAK;
|
|
12746
12900
|
|
|
12747
|
-
|
|
12748
|
-
|
|
12749
|
-
|
|
12750
|
-
|
|
12901
|
+
var lastPart = (this._streams.length === 0);
|
|
12902
|
+
if (lastPart) {
|
|
12903
|
+
footer += this._lastBoundary();
|
|
12904
|
+
}
|
|
12751
12905
|
|
|
12752
|
-
|
|
12753
|
-
|
|
12754
|
-
|
|
12755
|
-
}
|
|
12906
|
+
next(footer);
|
|
12907
|
+
}.bind(this);
|
|
12908
|
+
};
|
|
12756
12909
|
|
|
12757
|
-
|
|
12758
|
-
|
|
12759
|
-
|
|
12760
|
-
}
|
|
12910
|
+
FormData.prototype._lastBoundary = function() {
|
|
12911
|
+
return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
|
|
12912
|
+
};
|
|
12761
12913
|
|
|
12762
|
-
|
|
12763
|
-
|
|
12764
|
-
|
|
12765
|
-
|
|
12914
|
+
FormData.prototype.getHeaders = function(userHeaders) {
|
|
12915
|
+
var header;
|
|
12916
|
+
var formHeaders = {
|
|
12917
|
+
'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
|
|
12918
|
+
};
|
|
12766
12919
|
|
|
12767
|
-
|
|
12768
|
-
|
|
12769
|
-
|
|
12770
|
-
|
|
12920
|
+
for (header in userHeaders) {
|
|
12921
|
+
if (userHeaders.hasOwnProperty(header)) {
|
|
12922
|
+
formHeaders[header.toLowerCase()] = userHeaders[header];
|
|
12923
|
+
}
|
|
12924
|
+
}
|
|
12771
12925
|
|
|
12772
|
-
|
|
12773
|
-
};
|
|
12926
|
+
return formHeaders;
|
|
12927
|
+
};
|
|
12774
12928
|
|
|
12775
|
-
FormData.prototype.
|
|
12776
|
-
|
|
12777
|
-
|
|
12929
|
+
FormData.prototype.setBoundary = function(boundary) {
|
|
12930
|
+
this._boundary = boundary;
|
|
12931
|
+
};
|
|
12778
12932
|
|
|
12779
|
-
|
|
12780
|
-
|
|
12781
|
-
|
|
12782
|
-
|
|
12933
|
+
FormData.prototype.getBoundary = function() {
|
|
12934
|
+
if (!this._boundary) {
|
|
12935
|
+
this._generateBoundary();
|
|
12936
|
+
}
|
|
12783
12937
|
|
|
12784
|
-
|
|
12785
|
-
|
|
12786
|
-
};
|
|
12938
|
+
return this._boundary;
|
|
12939
|
+
};
|
|
12787
12940
|
|
|
12788
|
-
FormData.prototype.
|
|
12789
|
-
|
|
12790
|
-
|
|
12941
|
+
FormData.prototype.getBuffer = function() {
|
|
12942
|
+
var dataBuffer = new Buffer.alloc( 0 );
|
|
12943
|
+
var boundary = this.getBoundary();
|
|
12791
12944
|
|
|
12792
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
|
|
12796
|
-
};
|
|
12945
|
+
// Create the form content. Add Line breaks to the end of data.
|
|
12946
|
+
for (var i = 0, len = this._streams.length; i < len; i++) {
|
|
12947
|
+
if (typeof this._streams[i] !== 'function') {
|
|
12797
12948
|
|
|
12798
|
-
|
|
12799
|
-
|
|
12800
|
-
|
|
12801
|
-
|
|
12802
|
-
|
|
12949
|
+
// Add content to the buffer.
|
|
12950
|
+
if(Buffer.isBuffer(this._streams[i])) {
|
|
12951
|
+
dataBuffer = Buffer.concat( [dataBuffer, this._streams[i]]);
|
|
12952
|
+
}else {
|
|
12953
|
+
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(this._streams[i])]);
|
|
12954
|
+
}
|
|
12803
12955
|
|
|
12804
|
-
|
|
12805
|
-
|
|
12956
|
+
// Add break after content.
|
|
12957
|
+
if (typeof this._streams[i] !== 'string' || this._streams[i].substring( 2, boundary.length + 2 ) !== boundary) {
|
|
12958
|
+
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(FormData.LINE_BREAK)] );
|
|
12959
|
+
}
|
|
12960
|
+
}
|
|
12961
|
+
}
|
|
12806
12962
|
|
|
12807
|
-
|
|
12808
|
-
|
|
12809
|
-
};
|
|
12963
|
+
// Add the footer and return the Buffer object.
|
|
12964
|
+
return Buffer.concat( [dataBuffer, Buffer.from(this._lastBoundary())] );
|
|
12965
|
+
};
|
|
12810
12966
|
|
|
12811
|
-
FormData.prototype.
|
|
12812
|
-
|
|
12813
|
-
|
|
12814
|
-
|
|
12967
|
+
FormData.prototype._generateBoundary = function() {
|
|
12968
|
+
// This generates a 50 character boundary similar to those used by Firefox.
|
|
12969
|
+
// They are optimized for boyer-moore parsing.
|
|
12970
|
+
var boundary = '--------------------------';
|
|
12971
|
+
for (var i = 0; i < 24; i++) {
|
|
12972
|
+
boundary += Math.floor(Math.random() * 10).toString(16);
|
|
12973
|
+
}
|
|
12815
12974
|
|
|
12816
|
-
|
|
12817
|
-
};
|
|
12975
|
+
this._boundary = boundary;
|
|
12976
|
+
};
|
|
12818
12977
|
|
|
12819
|
-
|
|
12820
|
-
|
|
12821
|
-
|
|
12822
|
-
|
|
12823
|
-
|
|
12824
|
-
for (var i = 0, len = this._streams.length; i < len; i++) {
|
|
12825
|
-
if (typeof this._streams[i] !== 'function') {
|
|
12826
|
-
|
|
12827
|
-
// Add content to the buffer.
|
|
12828
|
-
if(Buffer.isBuffer(this._streams[i])) {
|
|
12829
|
-
dataBuffer = Buffer.concat( [dataBuffer, this._streams[i]]);
|
|
12830
|
-
}else {
|
|
12831
|
-
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(this._streams[i])]);
|
|
12832
|
-
}
|
|
12833
|
-
|
|
12834
|
-
// Add break after content.
|
|
12835
|
-
if (typeof this._streams[i] !== 'string' || this._streams[i].substring( 2, boundary.length + 2 ) !== boundary) {
|
|
12836
|
-
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(FormData.LINE_BREAK)] );
|
|
12837
|
-
}
|
|
12838
|
-
}
|
|
12839
|
-
}
|
|
12978
|
+
// Note: getLengthSync DOESN'T calculate streams length
|
|
12979
|
+
// As workaround one can calculate file size manually
|
|
12980
|
+
// and add it as knownLength option
|
|
12981
|
+
FormData.prototype.getLengthSync = function() {
|
|
12982
|
+
var knownLength = this._overheadLength + this._valueLength;
|
|
12840
12983
|
|
|
12841
|
-
|
|
12842
|
-
|
|
12843
|
-
|
|
12984
|
+
// Don't get confused, there are 3 "internal" streams for each keyval pair
|
|
12985
|
+
// so it basically checks if there is any value added to the form
|
|
12986
|
+
if (this._streams.length) {
|
|
12987
|
+
knownLength += this._lastBoundary().length;
|
|
12988
|
+
}
|
|
12844
12989
|
|
|
12845
|
-
|
|
12846
|
-
|
|
12847
|
-
|
|
12848
|
-
|
|
12849
|
-
|
|
12850
|
-
|
|
12851
|
-
|
|
12990
|
+
// https://github.com/form-data/form-data/issues/40
|
|
12991
|
+
if (!this.hasKnownLength()) {
|
|
12992
|
+
// Some async length retrievers are present
|
|
12993
|
+
// therefore synchronous length calculation is false.
|
|
12994
|
+
// Please use getLength(callback) to get proper length
|
|
12995
|
+
this._error(new Error('Cannot calculate proper length in synchronous way.'));
|
|
12996
|
+
}
|
|
12852
12997
|
|
|
12853
|
-
|
|
12854
|
-
};
|
|
12998
|
+
return knownLength;
|
|
12999
|
+
};
|
|
12855
13000
|
|
|
12856
|
-
//
|
|
12857
|
-
//
|
|
12858
|
-
//
|
|
12859
|
-
FormData.prototype.
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
// Don't get confused, there are 3 "internal" streams for each keyval pair
|
|
12863
|
-
// so it basically checks if there is any value added to the form
|
|
12864
|
-
if (this._streams.length) {
|
|
12865
|
-
knownLength += this._lastBoundary().length;
|
|
12866
|
-
}
|
|
12867
|
-
|
|
12868
|
-
// https://github.com/form-data/form-data/issues/40
|
|
12869
|
-
if (!this.hasKnownLength()) {
|
|
12870
|
-
// Some async length retrievers are present
|
|
12871
|
-
// therefore synchronous length calculation is false.
|
|
12872
|
-
// Please use getLength(callback) to get proper length
|
|
12873
|
-
this._error(new Error('Cannot calculate proper length in synchronous way.'));
|
|
12874
|
-
}
|
|
12875
|
-
|
|
12876
|
-
return knownLength;
|
|
12877
|
-
};
|
|
13001
|
+
// Public API to check if length of added values is known
|
|
13002
|
+
// https://github.com/form-data/form-data/issues/196
|
|
13003
|
+
// https://github.com/form-data/form-data/issues/262
|
|
13004
|
+
FormData.prototype.hasKnownLength = function() {
|
|
13005
|
+
var hasKnownLength = true;
|
|
12878
13006
|
|
|
12879
|
-
|
|
12880
|
-
|
|
12881
|
-
|
|
12882
|
-
FormData.prototype.hasKnownLength = function() {
|
|
12883
|
-
var hasKnownLength = true;
|
|
13007
|
+
if (this._valuesToMeasure.length) {
|
|
13008
|
+
hasKnownLength = false;
|
|
13009
|
+
}
|
|
12884
13010
|
|
|
12885
|
-
|
|
12886
|
-
|
|
12887
|
-
}
|
|
13011
|
+
return hasKnownLength;
|
|
13012
|
+
};
|
|
12888
13013
|
|
|
12889
|
-
|
|
12890
|
-
|
|
13014
|
+
FormData.prototype.getLength = function(cb) {
|
|
13015
|
+
var knownLength = this._overheadLength + this._valueLength;
|
|
12891
13016
|
|
|
12892
|
-
|
|
12893
|
-
|
|
13017
|
+
if (this._streams.length) {
|
|
13018
|
+
knownLength += this._lastBoundary().length;
|
|
13019
|
+
}
|
|
12894
13020
|
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
13021
|
+
if (!this._valuesToMeasure.length) {
|
|
13022
|
+
process.nextTick(cb.bind(this, null, knownLength));
|
|
13023
|
+
return;
|
|
13024
|
+
}
|
|
12898
13025
|
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
|
|
12902
|
-
|
|
13026
|
+
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
|
|
13027
|
+
if (err) {
|
|
13028
|
+
cb(err);
|
|
13029
|
+
return;
|
|
13030
|
+
}
|
|
12903
13031
|
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
|
|
12907
|
-
return;
|
|
12908
|
-
}
|
|
13032
|
+
values.forEach(function(length) {
|
|
13033
|
+
knownLength += length;
|
|
13034
|
+
});
|
|
12909
13035
|
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
|
|
13036
|
+
cb(null, knownLength);
|
|
13037
|
+
});
|
|
13038
|
+
};
|
|
13039
|
+
|
|
13040
|
+
FormData.prototype.submit = function(params, cb) {
|
|
13041
|
+
var request
|
|
13042
|
+
, options
|
|
13043
|
+
, defaults = {method: 'post'}
|
|
13044
|
+
;
|
|
13045
|
+
|
|
13046
|
+
// parse provided url if it's string
|
|
13047
|
+
// or treat it as options object
|
|
13048
|
+
if (typeof params == 'string') {
|
|
13049
|
+
|
|
13050
|
+
params = parseUrl(params);
|
|
13051
|
+
options = populate({
|
|
13052
|
+
port: params.port,
|
|
13053
|
+
path: params.pathname,
|
|
13054
|
+
host: params.hostname,
|
|
13055
|
+
protocol: params.protocol
|
|
13056
|
+
}, defaults);
|
|
13057
|
+
|
|
13058
|
+
// use custom params
|
|
13059
|
+
} else {
|
|
13060
|
+
|
|
13061
|
+
options = populate(params, defaults);
|
|
13062
|
+
// if no port provided use default one
|
|
13063
|
+
if (!options.port) {
|
|
13064
|
+
options.port = options.protocol == 'https:' ? 443 : 80;
|
|
13065
|
+
}
|
|
13066
|
+
}
|
|
12913
13067
|
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
};
|
|
13068
|
+
// put that good code in getHeaders to some use
|
|
13069
|
+
options.headers = this.getHeaders(params.headers);
|
|
12917
13070
|
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
|
|
12924
|
-
// parse provided url if it's string
|
|
12925
|
-
// or treat it as options object
|
|
12926
|
-
if (typeof params == 'string') {
|
|
12927
|
-
|
|
12928
|
-
params = parseUrl(params);
|
|
12929
|
-
options = populate({
|
|
12930
|
-
port: params.port,
|
|
12931
|
-
path: params.pathname,
|
|
12932
|
-
host: params.hostname,
|
|
12933
|
-
protocol: params.protocol
|
|
12934
|
-
}, defaults);
|
|
12935
|
-
|
|
12936
|
-
// use custom params
|
|
12937
|
-
} else {
|
|
12938
|
-
|
|
12939
|
-
options = populate(params, defaults);
|
|
12940
|
-
// if no port provided use default one
|
|
12941
|
-
if (!options.port) {
|
|
12942
|
-
options.port = options.protocol == 'https:' ? 443 : 80;
|
|
12943
|
-
}
|
|
12944
|
-
}
|
|
12945
|
-
|
|
12946
|
-
// put that good code in getHeaders to some use
|
|
12947
|
-
options.headers = this.getHeaders(params.headers);
|
|
12948
|
-
|
|
12949
|
-
// https if specified, fallback to http in any other case
|
|
12950
|
-
if (options.protocol == 'https:') {
|
|
12951
|
-
request = https.request(options);
|
|
12952
|
-
} else {
|
|
12953
|
-
request = http.request(options);
|
|
12954
|
-
}
|
|
12955
|
-
|
|
12956
|
-
// get content length and fire away
|
|
12957
|
-
this.getLength(function(err, length) {
|
|
12958
|
-
if (err && err !== 'Unknown stream') {
|
|
12959
|
-
this._error(err);
|
|
12960
|
-
return;
|
|
12961
|
-
}
|
|
13071
|
+
// https if specified, fallback to http in any other case
|
|
13072
|
+
if (options.protocol == 'https:') {
|
|
13073
|
+
request = https.request(options);
|
|
13074
|
+
} else {
|
|
13075
|
+
request = http.request(options);
|
|
13076
|
+
}
|
|
12962
13077
|
|
|
12963
|
-
|
|
12964
|
-
|
|
12965
|
-
|
|
12966
|
-
|
|
13078
|
+
// get content length and fire away
|
|
13079
|
+
this.getLength(function(err, length) {
|
|
13080
|
+
if (err && err !== 'Unknown stream') {
|
|
13081
|
+
this._error(err);
|
|
13082
|
+
return;
|
|
13083
|
+
}
|
|
12967
13084
|
|
|
12968
|
-
|
|
12969
|
-
|
|
12970
|
-
|
|
13085
|
+
// add content length
|
|
13086
|
+
if (length) {
|
|
13087
|
+
request.setHeader('Content-Length', length);
|
|
13088
|
+
}
|
|
12971
13089
|
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
13090
|
+
this.pipe(request);
|
|
13091
|
+
if (cb) {
|
|
13092
|
+
var onResponse;
|
|
12975
13093
|
|
|
12976
|
-
|
|
12977
|
-
|
|
13094
|
+
var callback = function (error, responce) {
|
|
13095
|
+
request.removeListener('error', callback);
|
|
13096
|
+
request.removeListener('response', onResponse);
|
|
12978
13097
|
|
|
12979
|
-
|
|
13098
|
+
return cb.call(this, error, responce);
|
|
13099
|
+
};
|
|
12980
13100
|
|
|
12981
|
-
|
|
12982
|
-
request.on('response', onResponse);
|
|
12983
|
-
}
|
|
12984
|
-
}.bind(this));
|
|
13101
|
+
onResponse = callback.bind(this, null);
|
|
12985
13102
|
|
|
12986
|
-
|
|
12987
|
-
|
|
13103
|
+
request.on('error', callback);
|
|
13104
|
+
request.on('response', onResponse);
|
|
13105
|
+
}
|
|
13106
|
+
}.bind(this));
|
|
12988
13107
|
|
|
12989
|
-
|
|
12990
|
-
|
|
12991
|
-
this.error = err;
|
|
12992
|
-
this.pause();
|
|
12993
|
-
this.emit('error', err);
|
|
12994
|
-
}
|
|
12995
|
-
};
|
|
13108
|
+
return request;
|
|
13109
|
+
};
|
|
12996
13110
|
|
|
12997
|
-
FormData.prototype.
|
|
12998
|
-
|
|
12999
|
-
|
|
13111
|
+
FormData.prototype._error = function(err) {
|
|
13112
|
+
if (!this.error) {
|
|
13113
|
+
this.error = err;
|
|
13114
|
+
this.pause();
|
|
13115
|
+
this.emit('error', err);
|
|
13116
|
+
}
|
|
13117
|
+
};
|
|
13118
|
+
|
|
13119
|
+
FormData.prototype.toString = function () {
|
|
13120
|
+
return '[object FormData]';
|
|
13121
|
+
};
|
|
13122
|
+
return form_data;
|
|
13123
|
+
}
|
|
13000
13124
|
|
|
13001
|
-
var
|
|
13125
|
+
var form_dataExports = requireForm_data();
|
|
13126
|
+
var FormDataModule = /*@__PURE__*/getDefaultExportFromCjs(form_dataExports);
|
|
13002
13127
|
|
|
13003
13128
|
const GRANT_TYPE$1 = 'client_credentials';
|
|
13004
13129
|
const castClientOptionsToRequestParams = (clientOptions) => {
|