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