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