sinzmise-cetastories 2.0.0-1731114112124 → 2.0.0-1731116663626
Sign up to get free protection for your applications and to get access to all the features.
- package/404/index.html +1 -4033
- package/about/index.html +1 -4041
- package/album/index.html +1 -4050
- package/archives/2021/12/index.html +1 -3917
- package/archives/2021/index.html +1 -3917
- package/archives/2022/12/index.html +1 -3917
- package/archives/2022/index.html +1 -3917
- package/archives/2023/01/index.html +1 -4072
- package/archives/2023/02/index.html +1 -3917
- package/archives/2023/03/index.html +1 -4063
- package/archives/2023/04/index.html +1 -3992
- package/archives/2023/07/index.html +1 -4217
- package/archives/2023/08/index.html +1 -4067
- package/archives/2023/09/index.html +1 -3917
- package/archives/2023/10/index.html +1 -3917
- package/archives/2023/11/index.html +1 -3917
- package/archives/2023/12/index.html +1 -3918
- package/archives/2023/index.html +1 -4591
- package/archives/2023/page/2/index.html +1 -4572
- package/archives/2023/page/3/index.html +1 -3930
- package/archives/2024/01/index.html +1 -4142
- package/archives/2024/02/index.html +1 -3922
- package/archives/2024/03/index.html +1 -3916
- package/archives/2024/04/index.html +1 -3997
- package/archives/2024/05/index.html +1 -4065
- package/archives/2024/06/index.html +1 -3917
- package/archives/2024/07/index.html +1 -3917
- package/archives/2024/08/index.html +1 -3992
- package/archives/2024/09/index.html +1 -3917
- package/archives/2024/10/index.html +1 -3984
- package/archives/2024/index.html +1 -4576
- package/archives/2024/page/2/index.html +1 -4433
- package/archives/index.html +1 -4560
- package/archives/page/2/index.html +1 -4560
- package/archives/page/3/index.html +1 -4560
- package/archives/page/4/index.html +1 -4560
- package/archives/page/5/index.html +1 -4560
- package/assets/algolia/algoliasearch.js +3 -7182
- package/assets/algolia/algoliasearchLite.js +3 -4445
- package/atom.xml +31 -31
- package/bbs/bbs.html +1 -4012
- package/bbs/bbs.js +2 -12
- package/bbs/index.html +1 -4031
- package/categories/index.html +1 -4050
- package/categories//344/270/252/344/272/272/345/260/217/350/256/260/index.html +1 -4570
- package/categories//344/270/252/344/272/272/345/260/217/350/256/260/page/2/index.html +1 -4485
- package/categories//346/255/214/346/233/262/346/224/266/351/233/206/index.html +1 -3920
- package/categories//346/270/270/346/210/217/347/233/270/345/205/263/index.html +1 -4148
- package/categories//347/253/231/347/202/271/346/212/230/350/205/276/index.html +1 -4610
- package/categories//347/253/231/347/202/271/346/212/230/350/205/276/page/2/index.html +1 -4148
- package/categories//351/241/271/347/233/256/346/212/230/350/205/276/index.html +1 -4072
- package/charts/index.html +1 -4039
- package/comments/index.html +1 -4052
- package/css/custom2.css +2 -3
- package/css/first.css +2 -1868
- package/css/pace/big-counter.css +2 -39
- package/css/pace/corner-indicator.css +2 -72
- package/css/pace/flash.css +2 -76
- package/css/pace/mac-osx.css +2 -86
- package/css/pace/pace.css +2 -50
- package/css/plane.css +2 -59
- package/css/style.css +2 -8585
- package/css/tags.css +2 -3516
- package/essay/index.html +1 -4050
- package/fcircle/index.html +1 -4075
- package/games +2 -2
- package/index.html +1 -4717
- package/js/app.js +2 -1341
- package/js/autoload.js +2 -62
- package/js/ceta/fancybox.css +2 -2
- package/js/ceta/fancybox.umd.js +2 -2
- package/js/ceta/iconfontInkss.js +2 -1
- package/js/ceta/message.css +2 -6
- package/js/ceta/message.js +2 -6
- package/js/clock.js +2 -1
- package/js/kslink.js +2 -38
- package/js/newyear.js +2 -76
- package/js/plane.js +2 -2200
- package/js/plugins/aplayer.js +2 -186
- package/js/plugins/parallax.js +2 -191
- package/js/plugins/rightMenus.js +2 -623
- package/js/plugins/tags/contributors.js +2 -92
- package/js/plugins/tags/friends.js +2 -93
- package/js/plugins/tags/sites.js +2 -96
- package/js/search/algolia.js +2 -239
- package/js/search/hexo.js +2 -195
- package/js/search/meilisearch.js +2 -220
- package/js/txmap.js +2 -248
- package/link/index.html +1 -6180
- package/load.html +1 -294
- package/maps/assets/algolia/algoliasearch.js.map +1 -0
- package/maps/assets/algolia/algoliasearchLite.js.map +1 -0
- package/maps/bbs/bbs.js.map +1 -0
- package/maps/css/custom2.css.map +1 -0
- package/maps/css/first.css.map +1 -0
- package/maps/css/pace/big-counter.css.map +1 -0
- package/maps/css/pace/corner-indicator.css.map +1 -0
- package/maps/css/pace/flash.css.map +1 -0
- package/maps/css/pace/mac-osx.css.map +1 -0
- package/maps/css/pace/pace.css.map +1 -0
- package/maps/css/plane.css.map +1 -0
- package/maps/css/style.css.map +1 -0
- package/maps/css/tags.css.map +1 -0
- package/maps/js/app.js.map +1 -0
- package/maps/js/autoload.js.map +1 -0
- package/maps/js/ceta/fancybox.css.map +1 -0
- package/maps/js/ceta/fancybox.umd.js.map +1 -0
- package/maps/js/ceta/iconfontInkss.js.map +1 -0
- package/maps/js/ceta/message.css.map +1 -0
- package/maps/js/ceta/message.js.map +1 -0
- package/maps/js/clock.js.map +1 -0
- package/maps/js/kslink.js.map +1 -0
- package/maps/js/newyear.js.map +1 -0
- package/maps/js/plane.js.map +1 -0
- package/maps/js/plugins/aplayer.js.map +1 -0
- package/maps/js/plugins/parallax.js.map +1 -0
- package/maps/js/plugins/rightMenus.js.map +1 -0
- package/maps/js/plugins/tags/contributors.js.map +1 -0
- package/maps/js/plugins/tags/friends.js.map +1 -0
- package/maps/js/plugins/tags/sites.js.map +1 -0
- package/maps/js/search/algolia.js.map +1 -0
- package/maps/js/search/hexo.js.map +1 -0
- package/maps/js/search/meilisearch.js.map +1 -0
- package/maps/js/txmap.js.map +1 -0
- package/maps/sw.js.map +1 -0
- package/maps/weichuncai/css/style.css.map +1 -0
- package/maps/weichuncai/js/common.js.map +1 -0
- package/maps/weichuncai/js/jquery.js.map +1 -0
- package/maps/weichuncai/wcc-config.js.map +1 -0
- package/music/index.html +1 -4033
- package/package.json +1 -1
- package/page/2/index.html +1 -4578
- package/page/3/index.html +1 -4575
- package/page/4/index.html +1 -4572
- package/page/5/index.html +1 -3924
- package/posts/10021/index.html +5 -4130
- package/posts/10045/index.html +1 -4224
- package/posts/10733/index.html +1 -4125
- package/posts/10996/index.html +5 -4127
- package/posts/12779/index.html +1 -4134
- package/posts/13624/index.html +1 -4179
- package/posts/15688/index.html +1 -4133
- package/posts/15748/index.html +5 -4121
- package/posts/15799/index.html +1 -4130
- package/posts/15842/index.html +5 -4121
- package/posts/16107/index.html +1 -4111
- package/posts/18063/index.html +1 -4124
- package/posts/20412/index.html +1 -4134
- package/posts/21375/index.html +1 -4124
- package/posts/22945/index.html +4 -4169
- package/posts/23021/index.html +1 -4104
- package/posts/27531/index.html +5 -4121
- package/posts/28536/index.html +1 -4116
- package/posts/28733/index.html +1 -4168
- package/posts/29196/index.html +1 -4106
- package/posts/38917/index.html +1 -4144
- package/posts/38964/index.html +1 -4208
- package/posts/42487/index.html +1 -4135
- package/posts/42580/index.html +1 -4128
- package/posts/45875/index.html +1 -4118
- package/posts/46640/index.html +1 -4147
- package/posts/48762/index.html +1 -4109
- package/posts/50710/index.html +1 -4114
- package/posts/52677/index.html +1 -4125
- package/posts/53662/index.html +1 -4123
- package/posts/54386/index.html +1 -4116
- package/posts/54481/index.html +1 -4133
- package/posts/54787/index.html +5 -4124
- package/posts/56467/index.html +1 -4121
- package/posts/57692/index.html +1 -4143
- package/posts/58203/index.html +1 -4116
- package/posts/61417/index.html +1 -4117
- package/posts/61712/index.html +1 -4113
- package/posts/646/index.html +1 -4106
- package/posts/64856/index.html +1 -4120
- package/posts/64935/index.html +1 -4120
- package/search.xml +70 -70
- package/seas/index.html +1 -4050
- package/sw.js +2 -798
- package/tags/Flash/347/233/270/345/205/263/index.html +1 -3924
- package/tags/Steam/346/270/270/346/210/217/index.html +1 -3924
- package/tags/Windows/350/275/257/344/273/266/index.html +1 -3997
- package/tags/index.html +1 -4033
- package/tags//344/270/252/344/272/272/345/260/217/350/256/260/index.html +1 -4570
- package/tags//344/270/252/344/272/272/345/260/217/350/256/260/page/2/index.html +1 -4485
- package/tags//345/205/266/345/256/203/346/270/270/346/210/217/index.html +1 -4073
- package/tags//345/212/240/350/275/275/345/212/250/347/224/273/index.html +1 -3924
- package/tags//346/202/254/346/265/256/345/256/240/347/211/251-/347/234/213/346/235/277/345/250/230/index.html +1 -3925
- package/tags//346/255/214/346/233/262/346/224/266/351/233/206/index.html +1 -3920
- package/tags//346/270/270/346/210/217/347/233/270/345/205/263/index.html +1 -4148
- package/tags//347/253/231/347/202/271/345/272/225/351/203/250/351/255/224/346/224/271/index.html +1 -3924
- package/tags//347/253/231/347/202/271/346/212/230/350/205/276/index.html +1 -4610
- package/tags//347/253/231/347/202/271/346/212/230/350/205/276/page/2/index.html +1 -4148
- package/tags//350/207/252/345/273/272/351/203/250/347/275/262/index.html +1 -4224
- package/tags//351/241/265/351/235/242/351/255/224/346/224/271/index.html +1 -4075
- package/tags//351/241/271/347/233/256/346/212/230/350/205/276/index.html +1 -4072
- package/update/index.html +1 -4112
- package/weichuncai/css/style.css +2 -25
- package/weichuncai/js/common.js +2 -449
- package/weichuncai/js/jquery.js +2 -139
- package/weichuncai/wcc-config.js +2 -17
@@ -1,399 +1,5 @@
|
|
1
1
|
/*! algoliasearch 3.35.1 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
|
2
|
-
|
3
|
-
(function (process){
|
4
|
-
/**
|
5
|
-
* This is the web browser implementation of `debug()`.
|
6
|
-
*
|
7
|
-
* Expose `debug()` as the module.
|
8
|
-
*/
|
9
|
-
|
10
|
-
exports = module.exports = require(2);
|
11
|
-
exports.log = log;
|
12
|
-
exports.formatArgs = formatArgs;
|
13
|
-
exports.save = save;
|
14
|
-
exports.load = load;
|
15
|
-
exports.useColors = useColors;
|
16
|
-
exports.storage = 'undefined' != typeof chrome
|
17
|
-
&& 'undefined' != typeof chrome.storage
|
18
|
-
? chrome.storage.local
|
19
|
-
: localstorage();
|
20
|
-
|
21
|
-
/**
|
22
|
-
* Colors.
|
23
|
-
*/
|
24
|
-
|
25
|
-
exports.colors = [
|
26
|
-
'lightseagreen',
|
27
|
-
'forestgreen',
|
28
|
-
'goldenrod',
|
29
|
-
'dodgerblue',
|
30
|
-
'darkorchid',
|
31
|
-
'crimson'
|
32
|
-
];
|
33
|
-
|
34
|
-
/**
|
35
|
-
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
36
|
-
* and the Firebug extension (any Firefox version) are known
|
37
|
-
* to support "%c" CSS customizations.
|
38
|
-
*
|
39
|
-
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
40
|
-
*/
|
41
|
-
|
42
|
-
function useColors() {
|
43
|
-
// NB: In an Electron preload script, document will be defined but not fully
|
44
|
-
// initialized. Since we know we're in Chrome, we'll just detect this case
|
45
|
-
// explicitly
|
46
|
-
if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {
|
47
|
-
return true;
|
48
|
-
}
|
49
|
-
|
50
|
-
// is webkit? http://stackoverflow.com/a/16459606/376773
|
51
|
-
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
52
|
-
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
53
|
-
// is firebug? http://stackoverflow.com/a/398120/376773
|
54
|
-
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
55
|
-
// is firefox >= v31?
|
56
|
-
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
57
|
-
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
58
|
-
// double check webkit in userAgent just in case we are in a worker
|
59
|
-
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
60
|
-
}
|
61
|
-
|
62
|
-
/**
|
63
|
-
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
64
|
-
*/
|
65
|
-
|
66
|
-
exports.formatters.j = function(v) {
|
67
|
-
try {
|
68
|
-
return JSON.stringify(v);
|
69
|
-
} catch (err) {
|
70
|
-
return '[UnexpectedJSONParseError]: ' + err.message;
|
71
|
-
}
|
72
|
-
};
|
73
|
-
|
74
|
-
|
75
|
-
/**
|
76
|
-
* Colorize log arguments if enabled.
|
77
|
-
*
|
78
|
-
* @api public
|
79
|
-
*/
|
80
|
-
|
81
|
-
function formatArgs(args) {
|
82
|
-
var useColors = this.useColors;
|
83
|
-
|
84
|
-
args[0] = (useColors ? '%c' : '')
|
85
|
-
+ this.namespace
|
86
|
-
+ (useColors ? ' %c' : ' ')
|
87
|
-
+ args[0]
|
88
|
-
+ (useColors ? '%c ' : ' ')
|
89
|
-
+ '+' + exports.humanize(this.diff);
|
90
|
-
|
91
|
-
if (!useColors) return;
|
92
|
-
|
93
|
-
var c = 'color: ' + this.color;
|
94
|
-
args.splice(1, 0, c, 'color: inherit')
|
95
|
-
|
96
|
-
// the final "%c" is somewhat tricky, because there could be other
|
97
|
-
// arguments passed either before or after the %c, so we need to
|
98
|
-
// figure out the correct index to insert the CSS into
|
99
|
-
var index = 0;
|
100
|
-
var lastC = 0;
|
101
|
-
args[0].replace(/%[a-zA-Z%]/g, function(match) {
|
102
|
-
if ('%%' === match) return;
|
103
|
-
index++;
|
104
|
-
if ('%c' === match) {
|
105
|
-
// we only are interested in the *last* %c
|
106
|
-
// (the user may have provided their own)
|
107
|
-
lastC = index;
|
108
|
-
}
|
109
|
-
});
|
110
|
-
|
111
|
-
args.splice(lastC, 0, c);
|
112
|
-
}
|
113
|
-
|
114
|
-
/**
|
115
|
-
* Invokes `console.log()` when available.
|
116
|
-
* No-op when `console.log` is not a "function".
|
117
|
-
*
|
118
|
-
* @api public
|
119
|
-
*/
|
120
|
-
|
121
|
-
function log() {
|
122
|
-
// this hackery is required for IE8/9, where
|
123
|
-
// the `console.log` function doesn't have 'apply'
|
124
|
-
return 'object' === typeof console
|
125
|
-
&& console.log
|
126
|
-
&& Function.prototype.apply.call(console.log, console, arguments);
|
127
|
-
}
|
128
|
-
|
129
|
-
/**
|
130
|
-
* Save `namespaces`.
|
131
|
-
*
|
132
|
-
* @param {String} namespaces
|
133
|
-
* @api private
|
134
|
-
*/
|
135
|
-
|
136
|
-
function save(namespaces) {
|
137
|
-
try {
|
138
|
-
if (null == namespaces) {
|
139
|
-
exports.storage.removeItem('debug');
|
140
|
-
} else {
|
141
|
-
exports.storage.debug = namespaces;
|
142
|
-
}
|
143
|
-
} catch(e) {}
|
144
|
-
}
|
145
|
-
|
146
|
-
/**
|
147
|
-
* Load `namespaces`.
|
148
|
-
*
|
149
|
-
* @return {String} returns the previously persisted debug modes
|
150
|
-
* @api private
|
151
|
-
*/
|
152
|
-
|
153
|
-
function load() {
|
154
|
-
var r;
|
155
|
-
try {
|
156
|
-
r = exports.storage.debug;
|
157
|
-
} catch(e) {}
|
158
|
-
|
159
|
-
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
160
|
-
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
161
|
-
r = process.env.DEBUG;
|
162
|
-
}
|
163
|
-
|
164
|
-
return r;
|
165
|
-
}
|
166
|
-
|
167
|
-
/**
|
168
|
-
* Enable namespaces listed in `localStorage.debug` initially.
|
169
|
-
*/
|
170
|
-
|
171
|
-
exports.enable(load());
|
172
|
-
|
173
|
-
/**
|
174
|
-
* Localstorage attempts to return the localstorage.
|
175
|
-
*
|
176
|
-
* This is necessary because safari throws
|
177
|
-
* when a user disables cookies/localstorage
|
178
|
-
* and you attempt to access it.
|
179
|
-
*
|
180
|
-
* @return {LocalStorage}
|
181
|
-
* @api private
|
182
|
-
*/
|
183
|
-
|
184
|
-
function localstorage() {
|
185
|
-
try {
|
186
|
-
return window.localStorage;
|
187
|
-
} catch (e) {}
|
188
|
-
}
|
189
|
-
|
190
|
-
}).call(this,require(11))
|
191
|
-
},{"11":11,"2":2}],2:[function(require,module,exports){
|
192
|
-
|
193
|
-
/**
|
194
|
-
* This is the common logic for both the Node.js and web browser
|
195
|
-
* implementations of `debug()`.
|
196
|
-
*
|
197
|
-
* Expose `debug()` as the module.
|
198
|
-
*/
|
199
|
-
|
200
|
-
exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
|
201
|
-
exports.coerce = coerce;
|
202
|
-
exports.disable = disable;
|
203
|
-
exports.enable = enable;
|
204
|
-
exports.enabled = enabled;
|
205
|
-
exports.humanize = require(8);
|
206
|
-
|
207
|
-
/**
|
208
|
-
* The currently active debug mode names, and names to skip.
|
209
|
-
*/
|
210
|
-
|
211
|
-
exports.names = [];
|
212
|
-
exports.skips = [];
|
213
|
-
|
214
|
-
/**
|
215
|
-
* Map of special "%n" handling functions, for the debug "format" argument.
|
216
|
-
*
|
217
|
-
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
218
|
-
*/
|
219
|
-
|
220
|
-
exports.formatters = {};
|
221
|
-
|
222
|
-
/**
|
223
|
-
* Previous log timestamp.
|
224
|
-
*/
|
225
|
-
|
226
|
-
var prevTime;
|
227
|
-
|
228
|
-
/**
|
229
|
-
* Select a color.
|
230
|
-
* @param {String} namespace
|
231
|
-
* @return {Number}
|
232
|
-
* @api private
|
233
|
-
*/
|
234
|
-
|
235
|
-
function selectColor(namespace) {
|
236
|
-
var hash = 0, i;
|
237
|
-
|
238
|
-
for (i in namespace) {
|
239
|
-
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
240
|
-
hash |= 0; // Convert to 32bit integer
|
241
|
-
}
|
242
|
-
|
243
|
-
return exports.colors[Math.abs(hash) % exports.colors.length];
|
244
|
-
}
|
245
|
-
|
246
|
-
/**
|
247
|
-
* Create a debugger with the given `namespace`.
|
248
|
-
*
|
249
|
-
* @param {String} namespace
|
250
|
-
* @return {Function}
|
251
|
-
* @api public
|
252
|
-
*/
|
253
|
-
|
254
|
-
function createDebug(namespace) {
|
255
|
-
|
256
|
-
function debug() {
|
257
|
-
// disabled?
|
258
|
-
if (!debug.enabled) return;
|
259
|
-
|
260
|
-
var self = debug;
|
261
|
-
|
262
|
-
// set `diff` timestamp
|
263
|
-
var curr = +new Date();
|
264
|
-
var ms = curr - (prevTime || curr);
|
265
|
-
self.diff = ms;
|
266
|
-
self.prev = prevTime;
|
267
|
-
self.curr = curr;
|
268
|
-
prevTime = curr;
|
269
|
-
|
270
|
-
// turn the `arguments` into a proper Array
|
271
|
-
var args = new Array(arguments.length);
|
272
|
-
for (var i = 0; i < args.length; i++) {
|
273
|
-
args[i] = arguments[i];
|
274
|
-
}
|
275
|
-
|
276
|
-
args[0] = exports.coerce(args[0]);
|
277
|
-
|
278
|
-
if ('string' !== typeof args[0]) {
|
279
|
-
// anything else let's inspect with %O
|
280
|
-
args.unshift('%O');
|
281
|
-
}
|
282
|
-
|
283
|
-
// apply any `formatters` transformations
|
284
|
-
var index = 0;
|
285
|
-
args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
|
286
|
-
// if we encounter an escaped % then don't increase the array index
|
287
|
-
if (match === '%%') return match;
|
288
|
-
index++;
|
289
|
-
var formatter = exports.formatters[format];
|
290
|
-
if ('function' === typeof formatter) {
|
291
|
-
var val = args[index];
|
292
|
-
match = formatter.call(self, val);
|
293
|
-
|
294
|
-
// now we need to remove `args[index]` since it's inlined in the `format`
|
295
|
-
args.splice(index, 1);
|
296
|
-
index--;
|
297
|
-
}
|
298
|
-
return match;
|
299
|
-
});
|
300
|
-
|
301
|
-
// apply env-specific formatting (colors, etc.)
|
302
|
-
exports.formatArgs.call(self, args);
|
303
|
-
|
304
|
-
var logFn = debug.log || exports.log || console.log.bind(console);
|
305
|
-
logFn.apply(self, args);
|
306
|
-
}
|
307
|
-
|
308
|
-
debug.namespace = namespace;
|
309
|
-
debug.enabled = exports.enabled(namespace);
|
310
|
-
debug.useColors = exports.useColors();
|
311
|
-
debug.color = selectColor(namespace);
|
312
|
-
|
313
|
-
// env-specific initialization logic for debug instances
|
314
|
-
if ('function' === typeof exports.init) {
|
315
|
-
exports.init(debug);
|
316
|
-
}
|
317
|
-
|
318
|
-
return debug;
|
319
|
-
}
|
320
|
-
|
321
|
-
/**
|
322
|
-
* Enables a debug mode by namespaces. This can include modes
|
323
|
-
* separated by a colon and wildcards.
|
324
|
-
*
|
325
|
-
* @param {String} namespaces
|
326
|
-
* @api public
|
327
|
-
*/
|
328
|
-
|
329
|
-
function enable(namespaces) {
|
330
|
-
exports.save(namespaces);
|
331
|
-
|
332
|
-
exports.names = [];
|
333
|
-
exports.skips = [];
|
334
|
-
|
335
|
-
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
336
|
-
var len = split.length;
|
337
|
-
|
338
|
-
for (var i = 0; i < len; i++) {
|
339
|
-
if (!split[i]) continue; // ignore empty strings
|
340
|
-
namespaces = split[i].replace(/\*/g, '.*?');
|
341
|
-
if (namespaces[0] === '-') {
|
342
|
-
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
343
|
-
} else {
|
344
|
-
exports.names.push(new RegExp('^' + namespaces + '$'));
|
345
|
-
}
|
346
|
-
}
|
347
|
-
}
|
348
|
-
|
349
|
-
/**
|
350
|
-
* Disable debug output.
|
351
|
-
*
|
352
|
-
* @api public
|
353
|
-
*/
|
354
|
-
|
355
|
-
function disable() {
|
356
|
-
exports.enable('');
|
357
|
-
}
|
358
|
-
|
359
|
-
/**
|
360
|
-
* Returns true if the given mode name is enabled, false otherwise.
|
361
|
-
*
|
362
|
-
* @param {String} name
|
363
|
-
* @return {Boolean}
|
364
|
-
* @api public
|
365
|
-
*/
|
366
|
-
|
367
|
-
function enabled(name) {
|
368
|
-
var i, len;
|
369
|
-
for (i = 0, len = exports.skips.length; i < len; i++) {
|
370
|
-
if (exports.skips[i].test(name)) {
|
371
|
-
return false;
|
372
|
-
}
|
373
|
-
}
|
374
|
-
for (i = 0, len = exports.names.length; i < len; i++) {
|
375
|
-
if (exports.names[i].test(name)) {
|
376
|
-
return true;
|
377
|
-
}
|
378
|
-
}
|
379
|
-
return false;
|
380
|
-
}
|
381
|
-
|
382
|
-
/**
|
383
|
-
* Coerce `val`.
|
384
|
-
*
|
385
|
-
* @param {Mixed} val
|
386
|
-
* @return {Mixed}
|
387
|
-
* @api private
|
388
|
-
*/
|
389
|
-
|
390
|
-
function coerce(val) {
|
391
|
-
if (val instanceof Error) return val.stack || val.message;
|
392
|
-
return val;
|
393
|
-
}
|
394
|
-
|
395
|
-
},{"8":8}],3:[function(require,module,exports){
|
396
|
-
(function (process,global){
|
2
|
+
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).algoliasearch=e()}}((function(){return function e(t,r,o){function n(a,s){if(!r[a]){if(!t[a]){var c="function"==typeof require&&require;if(!s&&c)return c(a,!0);if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var l=r[a]={exports:{}};t[a][0].call(l.exports,(function(e){var r=t[a][1][e];return n(r||e)}),l,l.exports,e,t,r,o)}return r[a].exports}for(var i="function"==typeof require&&require,a=0;a<o.length;a++)n(o[a]);return n}({1:[function(e,t,r){(function(o){function n(){var e;try{e=r.storage.debug}catch(e){}return!e&&void 0!==o&&"env"in o&&(e=o.env.DEBUG),e}(r=t.exports=e(2)).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},r.formatArgs=function(e){var t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+r.humanize(this.diff),!t)return;var o="color: "+this.color;e.splice(1,0,o,"color: inherit");var n=0,i=0;e[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(n++,"%c"===e&&(i=n))})),e.splice(i,0,o)},r.save=function(e){try{null==e?r.storage.removeItem("debug"):r.storage.debug=e}catch(e){}},r.load=n,r.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},r.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),r.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],r.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},r.enable(n())}).call(this,e(11))},{11:11,2:2}],2:[function(e,t,r){var o;function n(e){function t(){if(t.enabled){var e=t,n=+new Date,i=n-(o||n);e.diff=i,e.prev=o,e.curr=n,o=n;for(var a=new Array(arguments.length),s=0;s<a.length;s++)a[s]=arguments[s];a[0]=r.coerce(a[0]),"string"!=typeof a[0]&&a.unshift("%O");var c=0;a[0]=a[0].replace(/%([a-zA-Z%])/g,(function(t,o){if("%%"===t)return t;c++;var n=r.formatters[o];if("function"==typeof n){var i=a[c];t=n.call(e,i),a.splice(c,1),c--}return t})),r.formatArgs.call(e,a),(t.log||r.log||console.log.bind(console)).apply(e,a)}}return t.namespace=e,t.enabled=r.enabled(e),t.useColors=r.useColors(),t.color=function(e){var t,o=0;for(t in e)o=(o<<5)-o+e.charCodeAt(t),o|=0;return r.colors[Math.abs(o)%r.colors.length]}(e),"function"==typeof r.init&&r.init(t),t}(r=t.exports=n.debug=n.default=n).coerce=function(e){return e instanceof Error?e.stack||e.message:e},r.disable=function(){r.enable("")},r.enable=function(e){r.save(e),r.names=[],r.skips=[];for(var t=("string"==typeof e?e:"").split(/[\s,]+/),o=t.length,n=0;n<o;n++)t[n]&&("-"===(e=t[n].replace(/\*/g,".*?"))[0]?r.skips.push(new RegExp("^"+e.substr(1)+"$")):r.names.push(new RegExp("^"+e+"$")))},r.enabled=function(e){var t,o;for(t=0,o=r.skips.length;t<o;t++)if(r.skips[t].test(e))return!1;for(t=0,o=r.names.length;t<o;t++)if(r.names[t].test(e))return!0;return!1},r.humanize=e(8),r.names=[],r.skips=[],r.formatters={}},{8:8}],3:[function(e,t,r){(function(o,n){
|
397
3
|
/*!
|
398
4
|
* @overview es6-promise - a tiny implementation of Promises/A+.
|
399
5
|
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
|
@@ -401,4053 +7,5 @@ function coerce(val) {
|
|
401
7
|
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
|
402
8
|
* @version 4.1.1
|
403
9
|
*/
|
404
|
-
|
405
|
-
|
406
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
407
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
408
|
-
(global.ES6Promise = factory());
|
409
|
-
}(this, (function () { 'use strict';
|
410
|
-
|
411
|
-
function objectOrFunction(x) {
|
412
|
-
var type = typeof x;
|
413
|
-
return x !== null && (type === 'object' || type === 'function');
|
414
|
-
}
|
415
|
-
|
416
|
-
function isFunction(x) {
|
417
|
-
return typeof x === 'function';
|
418
|
-
}
|
419
|
-
|
420
|
-
var _isArray = undefined;
|
421
|
-
if (Array.isArray) {
|
422
|
-
_isArray = Array.isArray;
|
423
|
-
} else {
|
424
|
-
_isArray = function (x) {
|
425
|
-
return Object.prototype.toString.call(x) === '[object Array]';
|
426
|
-
};
|
427
|
-
}
|
428
|
-
|
429
|
-
var isArray = _isArray;
|
430
|
-
|
431
|
-
var len = 0;
|
432
|
-
var vertxNext = undefined;
|
433
|
-
var customSchedulerFn = undefined;
|
434
|
-
|
435
|
-
var asap = function asap(callback, arg) {
|
436
|
-
queue[len] = callback;
|
437
|
-
queue[len + 1] = arg;
|
438
|
-
len += 2;
|
439
|
-
if (len === 2) {
|
440
|
-
// If len is 2, that means that we need to schedule an async flush.
|
441
|
-
// If additional callbacks are queued before the queue is flushed, they
|
442
|
-
// will be processed by this flush that we are scheduling.
|
443
|
-
if (customSchedulerFn) {
|
444
|
-
customSchedulerFn(flush);
|
445
|
-
} else {
|
446
|
-
scheduleFlush();
|
447
|
-
}
|
448
|
-
}
|
449
|
-
};
|
450
|
-
|
451
|
-
function setScheduler(scheduleFn) {
|
452
|
-
customSchedulerFn = scheduleFn;
|
453
|
-
}
|
454
|
-
|
455
|
-
function setAsap(asapFn) {
|
456
|
-
asap = asapFn;
|
457
|
-
}
|
458
|
-
|
459
|
-
var browserWindow = typeof window !== 'undefined' ? window : undefined;
|
460
|
-
var browserGlobal = browserWindow || {};
|
461
|
-
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
462
|
-
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]';
|
463
|
-
|
464
|
-
// test for web worker but not in IE10
|
465
|
-
var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
|
466
|
-
|
467
|
-
// node
|
468
|
-
function useNextTick() {
|
469
|
-
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
470
|
-
// see https://github.com/cujojs/when/issues/410 for details
|
471
|
-
return function () {
|
472
|
-
return process.nextTick(flush);
|
473
|
-
};
|
474
|
-
}
|
475
|
-
|
476
|
-
// vertx
|
477
|
-
function useVertxTimer() {
|
478
|
-
if (typeof vertxNext !== 'undefined') {
|
479
|
-
return function () {
|
480
|
-
vertxNext(flush);
|
481
|
-
};
|
482
|
-
}
|
483
|
-
|
484
|
-
return useSetTimeout();
|
485
|
-
}
|
486
|
-
|
487
|
-
function useMutationObserver() {
|
488
|
-
var iterations = 0;
|
489
|
-
var observer = new BrowserMutationObserver(flush);
|
490
|
-
var node = document.createTextNode('');
|
491
|
-
observer.observe(node, { characterData: true });
|
492
|
-
|
493
|
-
return function () {
|
494
|
-
node.data = iterations = ++iterations % 2;
|
495
|
-
};
|
496
|
-
}
|
497
|
-
|
498
|
-
// web worker
|
499
|
-
function useMessageChannel() {
|
500
|
-
var channel = new MessageChannel();
|
501
|
-
channel.port1.onmessage = flush;
|
502
|
-
return function () {
|
503
|
-
return channel.port2.postMessage(0);
|
504
|
-
};
|
505
|
-
}
|
506
|
-
|
507
|
-
function useSetTimeout() {
|
508
|
-
// Store setTimeout reference so es6-promise will be unaffected by
|
509
|
-
// other code modifying setTimeout (like sinon.useFakeTimers())
|
510
|
-
var globalSetTimeout = setTimeout;
|
511
|
-
return function () {
|
512
|
-
return globalSetTimeout(flush, 1);
|
513
|
-
};
|
514
|
-
}
|
515
|
-
|
516
|
-
var queue = new Array(1000);
|
517
|
-
function flush() {
|
518
|
-
for (var i = 0; i < len; i += 2) {
|
519
|
-
var callback = queue[i];
|
520
|
-
var arg = queue[i + 1];
|
521
|
-
|
522
|
-
callback(arg);
|
523
|
-
|
524
|
-
queue[i] = undefined;
|
525
|
-
queue[i + 1] = undefined;
|
526
|
-
}
|
527
|
-
|
528
|
-
len = 0;
|
529
|
-
}
|
530
|
-
|
531
|
-
function attemptVertx() {
|
532
|
-
try {
|
533
|
-
var r = require;
|
534
|
-
var vertx = r('vertx');
|
535
|
-
vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
536
|
-
return useVertxTimer();
|
537
|
-
} catch (e) {
|
538
|
-
return useSetTimeout();
|
539
|
-
}
|
540
|
-
}
|
541
|
-
|
542
|
-
var scheduleFlush = undefined;
|
543
|
-
// Decide what async method to use to triggering processing of queued callbacks:
|
544
|
-
if (isNode) {
|
545
|
-
scheduleFlush = useNextTick();
|
546
|
-
} else if (BrowserMutationObserver) {
|
547
|
-
scheduleFlush = useMutationObserver();
|
548
|
-
} else if (isWorker) {
|
549
|
-
scheduleFlush = useMessageChannel();
|
550
|
-
} else if (browserWindow === undefined && typeof require === 'function') {
|
551
|
-
scheduleFlush = attemptVertx();
|
552
|
-
} else {
|
553
|
-
scheduleFlush = useSetTimeout();
|
554
|
-
}
|
555
|
-
|
556
|
-
function then(onFulfillment, onRejection) {
|
557
|
-
var _arguments = arguments;
|
558
|
-
|
559
|
-
var parent = this;
|
560
|
-
|
561
|
-
var child = new this.constructor(noop);
|
562
|
-
|
563
|
-
if (child[PROMISE_ID] === undefined) {
|
564
|
-
makePromise(child);
|
565
|
-
}
|
566
|
-
|
567
|
-
var _state = parent._state;
|
568
|
-
|
569
|
-
if (_state) {
|
570
|
-
(function () {
|
571
|
-
var callback = _arguments[_state - 1];
|
572
|
-
asap(function () {
|
573
|
-
return invokeCallback(_state, child, callback, parent._result);
|
574
|
-
});
|
575
|
-
})();
|
576
|
-
} else {
|
577
|
-
subscribe(parent, child, onFulfillment, onRejection);
|
578
|
-
}
|
579
|
-
|
580
|
-
return child;
|
581
|
-
}
|
582
|
-
|
583
|
-
/**
|
584
|
-
`Promise.resolve` returns a promise that will become resolved with the
|
585
|
-
passed `value`. It is shorthand for the following:
|
586
|
-
|
587
|
-
```javascript
|
588
|
-
let promise = new Promise(function(resolve, reject){
|
589
|
-
resolve(1);
|
590
|
-
});
|
591
|
-
|
592
|
-
promise.then(function(value){
|
593
|
-
// value === 1
|
594
|
-
});
|
595
|
-
```
|
596
|
-
|
597
|
-
Instead of writing the above, your code now simply becomes the following:
|
598
|
-
|
599
|
-
```javascript
|
600
|
-
let promise = Promise.resolve(1);
|
601
|
-
|
602
|
-
promise.then(function(value){
|
603
|
-
// value === 1
|
604
|
-
});
|
605
|
-
```
|
606
|
-
|
607
|
-
@method resolve
|
608
|
-
@static
|
609
|
-
@param {Any} value value that the returned promise will be resolved with
|
610
|
-
Useful for tooling.
|
611
|
-
@return {Promise} a promise that will become fulfilled with the given
|
612
|
-
`value`
|
613
|
-
*/
|
614
|
-
function resolve$1(object) {
|
615
|
-
/*jshint validthis:true */
|
616
|
-
var Constructor = this;
|
617
|
-
|
618
|
-
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
619
|
-
return object;
|
620
|
-
}
|
621
|
-
|
622
|
-
var promise = new Constructor(noop);
|
623
|
-
resolve(promise, object);
|
624
|
-
return promise;
|
625
|
-
}
|
626
|
-
|
627
|
-
var PROMISE_ID = Math.random().toString(36).substring(16);
|
628
|
-
|
629
|
-
function noop() {}
|
630
|
-
|
631
|
-
var PENDING = void 0;
|
632
|
-
var FULFILLED = 1;
|
633
|
-
var REJECTED = 2;
|
634
|
-
|
635
|
-
var GET_THEN_ERROR = new ErrorObject();
|
636
|
-
|
637
|
-
function selfFulfillment() {
|
638
|
-
return new TypeError("You cannot resolve a promise with itself");
|
639
|
-
}
|
640
|
-
|
641
|
-
function cannotReturnOwn() {
|
642
|
-
return new TypeError('A promises callback cannot return that same promise.');
|
643
|
-
}
|
644
|
-
|
645
|
-
function getThen(promise) {
|
646
|
-
try {
|
647
|
-
return promise.then;
|
648
|
-
} catch (error) {
|
649
|
-
GET_THEN_ERROR.error = error;
|
650
|
-
return GET_THEN_ERROR;
|
651
|
-
}
|
652
|
-
}
|
653
|
-
|
654
|
-
function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {
|
655
|
-
try {
|
656
|
-
then$$1.call(value, fulfillmentHandler, rejectionHandler);
|
657
|
-
} catch (e) {
|
658
|
-
return e;
|
659
|
-
}
|
660
|
-
}
|
661
|
-
|
662
|
-
function handleForeignThenable(promise, thenable, then$$1) {
|
663
|
-
asap(function (promise) {
|
664
|
-
var sealed = false;
|
665
|
-
var error = tryThen(then$$1, thenable, function (value) {
|
666
|
-
if (sealed) {
|
667
|
-
return;
|
668
|
-
}
|
669
|
-
sealed = true;
|
670
|
-
if (thenable !== value) {
|
671
|
-
resolve(promise, value);
|
672
|
-
} else {
|
673
|
-
fulfill(promise, value);
|
674
|
-
}
|
675
|
-
}, function (reason) {
|
676
|
-
if (sealed) {
|
677
|
-
return;
|
678
|
-
}
|
679
|
-
sealed = true;
|
680
|
-
|
681
|
-
reject(promise, reason);
|
682
|
-
}, 'Settle: ' + (promise._label || ' unknown promise'));
|
683
|
-
|
684
|
-
if (!sealed && error) {
|
685
|
-
sealed = true;
|
686
|
-
reject(promise, error);
|
687
|
-
}
|
688
|
-
}, promise);
|
689
|
-
}
|
690
|
-
|
691
|
-
function handleOwnThenable(promise, thenable) {
|
692
|
-
if (thenable._state === FULFILLED) {
|
693
|
-
fulfill(promise, thenable._result);
|
694
|
-
} else if (thenable._state === REJECTED) {
|
695
|
-
reject(promise, thenable._result);
|
696
|
-
} else {
|
697
|
-
subscribe(thenable, undefined, function (value) {
|
698
|
-
return resolve(promise, value);
|
699
|
-
}, function (reason) {
|
700
|
-
return reject(promise, reason);
|
701
|
-
});
|
702
|
-
}
|
703
|
-
}
|
704
|
-
|
705
|
-
function handleMaybeThenable(promise, maybeThenable, then$$1) {
|
706
|
-
if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) {
|
707
|
-
handleOwnThenable(promise, maybeThenable);
|
708
|
-
} else {
|
709
|
-
if (then$$1 === GET_THEN_ERROR) {
|
710
|
-
reject(promise, GET_THEN_ERROR.error);
|
711
|
-
GET_THEN_ERROR.error = null;
|
712
|
-
} else if (then$$1 === undefined) {
|
713
|
-
fulfill(promise, maybeThenable);
|
714
|
-
} else if (isFunction(then$$1)) {
|
715
|
-
handleForeignThenable(promise, maybeThenable, then$$1);
|
716
|
-
} else {
|
717
|
-
fulfill(promise, maybeThenable);
|
718
|
-
}
|
719
|
-
}
|
720
|
-
}
|
721
|
-
|
722
|
-
function resolve(promise, value) {
|
723
|
-
if (promise === value) {
|
724
|
-
reject(promise, selfFulfillment());
|
725
|
-
} else if (objectOrFunction(value)) {
|
726
|
-
handleMaybeThenable(promise, value, getThen(value));
|
727
|
-
} else {
|
728
|
-
fulfill(promise, value);
|
729
|
-
}
|
730
|
-
}
|
731
|
-
|
732
|
-
function publishRejection(promise) {
|
733
|
-
if (promise._onerror) {
|
734
|
-
promise._onerror(promise._result);
|
735
|
-
}
|
736
|
-
|
737
|
-
publish(promise);
|
738
|
-
}
|
739
|
-
|
740
|
-
function fulfill(promise, value) {
|
741
|
-
if (promise._state !== PENDING) {
|
742
|
-
return;
|
743
|
-
}
|
744
|
-
|
745
|
-
promise._result = value;
|
746
|
-
promise._state = FULFILLED;
|
747
|
-
|
748
|
-
if (promise._subscribers.length !== 0) {
|
749
|
-
asap(publish, promise);
|
750
|
-
}
|
751
|
-
}
|
752
|
-
|
753
|
-
function reject(promise, reason) {
|
754
|
-
if (promise._state !== PENDING) {
|
755
|
-
return;
|
756
|
-
}
|
757
|
-
promise._state = REJECTED;
|
758
|
-
promise._result = reason;
|
759
|
-
|
760
|
-
asap(publishRejection, promise);
|
761
|
-
}
|
762
|
-
|
763
|
-
function subscribe(parent, child, onFulfillment, onRejection) {
|
764
|
-
var _subscribers = parent._subscribers;
|
765
|
-
var length = _subscribers.length;
|
766
|
-
|
767
|
-
parent._onerror = null;
|
768
|
-
|
769
|
-
_subscribers[length] = child;
|
770
|
-
_subscribers[length + FULFILLED] = onFulfillment;
|
771
|
-
_subscribers[length + REJECTED] = onRejection;
|
772
|
-
|
773
|
-
if (length === 0 && parent._state) {
|
774
|
-
asap(publish, parent);
|
775
|
-
}
|
776
|
-
}
|
777
|
-
|
778
|
-
function publish(promise) {
|
779
|
-
var subscribers = promise._subscribers;
|
780
|
-
var settled = promise._state;
|
781
|
-
|
782
|
-
if (subscribers.length === 0) {
|
783
|
-
return;
|
784
|
-
}
|
785
|
-
|
786
|
-
var child = undefined,
|
787
|
-
callback = undefined,
|
788
|
-
detail = promise._result;
|
789
|
-
|
790
|
-
for (var i = 0; i < subscribers.length; i += 3) {
|
791
|
-
child = subscribers[i];
|
792
|
-
callback = subscribers[i + settled];
|
793
|
-
|
794
|
-
if (child) {
|
795
|
-
invokeCallback(settled, child, callback, detail);
|
796
|
-
} else {
|
797
|
-
callback(detail);
|
798
|
-
}
|
799
|
-
}
|
800
|
-
|
801
|
-
promise._subscribers.length = 0;
|
802
|
-
}
|
803
|
-
|
804
|
-
function ErrorObject() {
|
805
|
-
this.error = null;
|
806
|
-
}
|
807
|
-
|
808
|
-
var TRY_CATCH_ERROR = new ErrorObject();
|
809
|
-
|
810
|
-
function tryCatch(callback, detail) {
|
811
|
-
try {
|
812
|
-
return callback(detail);
|
813
|
-
} catch (e) {
|
814
|
-
TRY_CATCH_ERROR.error = e;
|
815
|
-
return TRY_CATCH_ERROR;
|
816
|
-
}
|
817
|
-
}
|
818
|
-
|
819
|
-
function invokeCallback(settled, promise, callback, detail) {
|
820
|
-
var hasCallback = isFunction(callback),
|
821
|
-
value = undefined,
|
822
|
-
error = undefined,
|
823
|
-
succeeded = undefined,
|
824
|
-
failed = undefined;
|
825
|
-
|
826
|
-
if (hasCallback) {
|
827
|
-
value = tryCatch(callback, detail);
|
828
|
-
|
829
|
-
if (value === TRY_CATCH_ERROR) {
|
830
|
-
failed = true;
|
831
|
-
error = value.error;
|
832
|
-
value.error = null;
|
833
|
-
} else {
|
834
|
-
succeeded = true;
|
835
|
-
}
|
836
|
-
|
837
|
-
if (promise === value) {
|
838
|
-
reject(promise, cannotReturnOwn());
|
839
|
-
return;
|
840
|
-
}
|
841
|
-
} else {
|
842
|
-
value = detail;
|
843
|
-
succeeded = true;
|
844
|
-
}
|
845
|
-
|
846
|
-
if (promise._state !== PENDING) {
|
847
|
-
// noop
|
848
|
-
} else if (hasCallback && succeeded) {
|
849
|
-
resolve(promise, value);
|
850
|
-
} else if (failed) {
|
851
|
-
reject(promise, error);
|
852
|
-
} else if (settled === FULFILLED) {
|
853
|
-
fulfill(promise, value);
|
854
|
-
} else if (settled === REJECTED) {
|
855
|
-
reject(promise, value);
|
856
|
-
}
|
857
|
-
}
|
858
|
-
|
859
|
-
function initializePromise(promise, resolver) {
|
860
|
-
try {
|
861
|
-
resolver(function resolvePromise(value) {
|
862
|
-
resolve(promise, value);
|
863
|
-
}, function rejectPromise(reason) {
|
864
|
-
reject(promise, reason);
|
865
|
-
});
|
866
|
-
} catch (e) {
|
867
|
-
reject(promise, e);
|
868
|
-
}
|
869
|
-
}
|
870
|
-
|
871
|
-
var id = 0;
|
872
|
-
function nextId() {
|
873
|
-
return id++;
|
874
|
-
}
|
875
|
-
|
876
|
-
function makePromise(promise) {
|
877
|
-
promise[PROMISE_ID] = id++;
|
878
|
-
promise._state = undefined;
|
879
|
-
promise._result = undefined;
|
880
|
-
promise._subscribers = [];
|
881
|
-
}
|
882
|
-
|
883
|
-
function Enumerator$1(Constructor, input) {
|
884
|
-
this._instanceConstructor = Constructor;
|
885
|
-
this.promise = new Constructor(noop);
|
886
|
-
|
887
|
-
if (!this.promise[PROMISE_ID]) {
|
888
|
-
makePromise(this.promise);
|
889
|
-
}
|
890
|
-
|
891
|
-
if (isArray(input)) {
|
892
|
-
this.length = input.length;
|
893
|
-
this._remaining = input.length;
|
894
|
-
|
895
|
-
this._result = new Array(this.length);
|
896
|
-
|
897
|
-
if (this.length === 0) {
|
898
|
-
fulfill(this.promise, this._result);
|
899
|
-
} else {
|
900
|
-
this.length = this.length || 0;
|
901
|
-
this._enumerate(input);
|
902
|
-
if (this._remaining === 0) {
|
903
|
-
fulfill(this.promise, this._result);
|
904
|
-
}
|
905
|
-
}
|
906
|
-
} else {
|
907
|
-
reject(this.promise, validationError());
|
908
|
-
}
|
909
|
-
}
|
910
|
-
|
911
|
-
function validationError() {
|
912
|
-
return new Error('Array Methods must be provided an Array');
|
913
|
-
}
|
914
|
-
|
915
|
-
Enumerator$1.prototype._enumerate = function (input) {
|
916
|
-
for (var i = 0; this._state === PENDING && i < input.length; i++) {
|
917
|
-
this._eachEntry(input[i], i);
|
918
|
-
}
|
919
|
-
};
|
920
|
-
|
921
|
-
Enumerator$1.prototype._eachEntry = function (entry, i) {
|
922
|
-
var c = this._instanceConstructor;
|
923
|
-
var resolve$$1 = c.resolve;
|
924
|
-
|
925
|
-
if (resolve$$1 === resolve$1) {
|
926
|
-
var _then = getThen(entry);
|
927
|
-
|
928
|
-
if (_then === then && entry._state !== PENDING) {
|
929
|
-
this._settledAt(entry._state, i, entry._result);
|
930
|
-
} else if (typeof _then !== 'function') {
|
931
|
-
this._remaining--;
|
932
|
-
this._result[i] = entry;
|
933
|
-
} else if (c === Promise$2) {
|
934
|
-
var promise = new c(noop);
|
935
|
-
handleMaybeThenable(promise, entry, _then);
|
936
|
-
this._willSettleAt(promise, i);
|
937
|
-
} else {
|
938
|
-
this._willSettleAt(new c(function (resolve$$1) {
|
939
|
-
return resolve$$1(entry);
|
940
|
-
}), i);
|
941
|
-
}
|
942
|
-
} else {
|
943
|
-
this._willSettleAt(resolve$$1(entry), i);
|
944
|
-
}
|
945
|
-
};
|
946
|
-
|
947
|
-
Enumerator$1.prototype._settledAt = function (state, i, value) {
|
948
|
-
var promise = this.promise;
|
949
|
-
|
950
|
-
if (promise._state === PENDING) {
|
951
|
-
this._remaining--;
|
952
|
-
|
953
|
-
if (state === REJECTED) {
|
954
|
-
reject(promise, value);
|
955
|
-
} else {
|
956
|
-
this._result[i] = value;
|
957
|
-
}
|
958
|
-
}
|
959
|
-
|
960
|
-
if (this._remaining === 0) {
|
961
|
-
fulfill(promise, this._result);
|
962
|
-
}
|
963
|
-
};
|
964
|
-
|
965
|
-
Enumerator$1.prototype._willSettleAt = function (promise, i) {
|
966
|
-
var enumerator = this;
|
967
|
-
|
968
|
-
subscribe(promise, undefined, function (value) {
|
969
|
-
return enumerator._settledAt(FULFILLED, i, value);
|
970
|
-
}, function (reason) {
|
971
|
-
return enumerator._settledAt(REJECTED, i, reason);
|
972
|
-
});
|
973
|
-
};
|
974
|
-
|
975
|
-
/**
|
976
|
-
`Promise.all` accepts an array of promises, and returns a new promise which
|
977
|
-
is fulfilled with an array of fulfillment values for the passed promises, or
|
978
|
-
rejected with the reason of the first passed promise to be rejected. It casts all
|
979
|
-
elements of the passed iterable to promises as it runs this algorithm.
|
980
|
-
|
981
|
-
Example:
|
982
|
-
|
983
|
-
```javascript
|
984
|
-
let promise1 = resolve(1);
|
985
|
-
let promise2 = resolve(2);
|
986
|
-
let promise3 = resolve(3);
|
987
|
-
let promises = [ promise1, promise2, promise3 ];
|
988
|
-
|
989
|
-
Promise.all(promises).then(function(array){
|
990
|
-
// The array here would be [ 1, 2, 3 ];
|
991
|
-
});
|
992
|
-
```
|
993
|
-
|
994
|
-
If any of the `promises` given to `all` are rejected, the first promise
|
995
|
-
that is rejected will be given as an argument to the returned promises's
|
996
|
-
rejection handler. For example:
|
997
|
-
|
998
|
-
Example:
|
999
|
-
|
1000
|
-
```javascript
|
1001
|
-
let promise1 = resolve(1);
|
1002
|
-
let promise2 = reject(new Error("2"));
|
1003
|
-
let promise3 = reject(new Error("3"));
|
1004
|
-
let promises = [ promise1, promise2, promise3 ];
|
1005
|
-
|
1006
|
-
Promise.all(promises).then(function(array){
|
1007
|
-
// Code here never runs because there are rejected promises!
|
1008
|
-
}, function(error) {
|
1009
|
-
// error.message === "2"
|
1010
|
-
});
|
1011
|
-
```
|
1012
|
-
|
1013
|
-
@method all
|
1014
|
-
@static
|
1015
|
-
@param {Array} entries array of promises
|
1016
|
-
@param {String} label optional string for labeling the promise.
|
1017
|
-
Useful for tooling.
|
1018
|
-
@return {Promise} promise that is fulfilled when all `promises` have been
|
1019
|
-
fulfilled, or rejected if any of them become rejected.
|
1020
|
-
@static
|
1021
|
-
*/
|
1022
|
-
function all$1(entries) {
|
1023
|
-
return new Enumerator$1(this, entries).promise;
|
1024
|
-
}
|
1025
|
-
|
1026
|
-
/**
|
1027
|
-
`Promise.race` returns a new promise which is settled in the same way as the
|
1028
|
-
first passed promise to settle.
|
1029
|
-
|
1030
|
-
Example:
|
1031
|
-
|
1032
|
-
```javascript
|
1033
|
-
let promise1 = new Promise(function(resolve, reject){
|
1034
|
-
setTimeout(function(){
|
1035
|
-
resolve('promise 1');
|
1036
|
-
}, 200);
|
1037
|
-
});
|
1038
|
-
|
1039
|
-
let promise2 = new Promise(function(resolve, reject){
|
1040
|
-
setTimeout(function(){
|
1041
|
-
resolve('promise 2');
|
1042
|
-
}, 100);
|
1043
|
-
});
|
1044
|
-
|
1045
|
-
Promise.race([promise1, promise2]).then(function(result){
|
1046
|
-
// result === 'promise 2' because it was resolved before promise1
|
1047
|
-
// was resolved.
|
1048
|
-
});
|
1049
|
-
```
|
1050
|
-
|
1051
|
-
`Promise.race` is deterministic in that only the state of the first
|
1052
|
-
settled promise matters. For example, even if other promises given to the
|
1053
|
-
`promises` array argument are resolved, but the first settled promise has
|
1054
|
-
become rejected before the other promises became fulfilled, the returned
|
1055
|
-
promise will become rejected:
|
1056
|
-
|
1057
|
-
```javascript
|
1058
|
-
let promise1 = new Promise(function(resolve, reject){
|
1059
|
-
setTimeout(function(){
|
1060
|
-
resolve('promise 1');
|
1061
|
-
}, 200);
|
1062
|
-
});
|
1063
|
-
|
1064
|
-
let promise2 = new Promise(function(resolve, reject){
|
1065
|
-
setTimeout(function(){
|
1066
|
-
reject(new Error('promise 2'));
|
1067
|
-
}, 100);
|
1068
|
-
});
|
1069
|
-
|
1070
|
-
Promise.race([promise1, promise2]).then(function(result){
|
1071
|
-
// Code here never runs
|
1072
|
-
}, function(reason){
|
1073
|
-
// reason.message === 'promise 2' because promise 2 became rejected before
|
1074
|
-
// promise 1 became fulfilled
|
1075
|
-
});
|
1076
|
-
```
|
1077
|
-
|
1078
|
-
An example real-world use case is implementing timeouts:
|
1079
|
-
|
1080
|
-
```javascript
|
1081
|
-
Promise.race([ajax('foo.json'), timeout(5000)])
|
1082
|
-
```
|
1083
|
-
|
1084
|
-
@method race
|
1085
|
-
@static
|
1086
|
-
@param {Array} promises array of promises to observe
|
1087
|
-
Useful for tooling.
|
1088
|
-
@return {Promise} a promise which settles in the same way as the first passed
|
1089
|
-
promise to settle.
|
1090
|
-
*/
|
1091
|
-
function race$1(entries) {
|
1092
|
-
/*jshint validthis:true */
|
1093
|
-
var Constructor = this;
|
1094
|
-
|
1095
|
-
if (!isArray(entries)) {
|
1096
|
-
return new Constructor(function (_, reject) {
|
1097
|
-
return reject(new TypeError('You must pass an array to race.'));
|
1098
|
-
});
|
1099
|
-
} else {
|
1100
|
-
return new Constructor(function (resolve, reject) {
|
1101
|
-
var length = entries.length;
|
1102
|
-
for (var i = 0; i < length; i++) {
|
1103
|
-
Constructor.resolve(entries[i]).then(resolve, reject);
|
1104
|
-
}
|
1105
|
-
});
|
1106
|
-
}
|
1107
|
-
}
|
1108
|
-
|
1109
|
-
/**
|
1110
|
-
`Promise.reject` returns a promise rejected with the passed `reason`.
|
1111
|
-
It is shorthand for the following:
|
1112
|
-
|
1113
|
-
```javascript
|
1114
|
-
let promise = new Promise(function(resolve, reject){
|
1115
|
-
reject(new Error('WHOOPS'));
|
1116
|
-
});
|
1117
|
-
|
1118
|
-
promise.then(function(value){
|
1119
|
-
// Code here doesn't run because the promise is rejected!
|
1120
|
-
}, function(reason){
|
1121
|
-
// reason.message === 'WHOOPS'
|
1122
|
-
});
|
1123
|
-
```
|
1124
|
-
|
1125
|
-
Instead of writing the above, your code now simply becomes the following:
|
1126
|
-
|
1127
|
-
```javascript
|
1128
|
-
let promise = Promise.reject(new Error('WHOOPS'));
|
1129
|
-
|
1130
|
-
promise.then(function(value){
|
1131
|
-
// Code here doesn't run because the promise is rejected!
|
1132
|
-
}, function(reason){
|
1133
|
-
// reason.message === 'WHOOPS'
|
1134
|
-
});
|
1135
|
-
```
|
1136
|
-
|
1137
|
-
@method reject
|
1138
|
-
@static
|
1139
|
-
@param {Any} reason value that the returned promise will be rejected with.
|
1140
|
-
Useful for tooling.
|
1141
|
-
@return {Promise} a promise rejected with the given `reason`.
|
1142
|
-
*/
|
1143
|
-
function reject$1(reason) {
|
1144
|
-
/*jshint validthis:true */
|
1145
|
-
var Constructor = this;
|
1146
|
-
var promise = new Constructor(noop);
|
1147
|
-
reject(promise, reason);
|
1148
|
-
return promise;
|
1149
|
-
}
|
1150
|
-
|
1151
|
-
function needsResolver() {
|
1152
|
-
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
1153
|
-
}
|
1154
|
-
|
1155
|
-
function needsNew() {
|
1156
|
-
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
1157
|
-
}
|
1158
|
-
|
1159
|
-
/**
|
1160
|
-
Promise objects represent the eventual result of an asynchronous operation. The
|
1161
|
-
primary way of interacting with a promise is through its `then` method, which
|
1162
|
-
registers callbacks to receive either a promise's eventual value or the reason
|
1163
|
-
why the promise cannot be fulfilled.
|
1164
|
-
|
1165
|
-
Terminology
|
1166
|
-
-----------
|
1167
|
-
|
1168
|
-
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
1169
|
-
- `thenable` is an object or function that defines a `then` method.
|
1170
|
-
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
1171
|
-
- `exception` is a value that is thrown using the throw statement.
|
1172
|
-
- `reason` is a value that indicates why a promise was rejected.
|
1173
|
-
- `settled` the final resting state of a promise, fulfilled or rejected.
|
1174
|
-
|
1175
|
-
A promise can be in one of three states: pending, fulfilled, or rejected.
|
1176
|
-
|
1177
|
-
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
1178
|
-
state. Promises that are rejected have a rejection reason and are in the
|
1179
|
-
rejected state. A fulfillment value is never a thenable.
|
1180
|
-
|
1181
|
-
Promises can also be said to *resolve* a value. If this value is also a
|
1182
|
-
promise, then the original promise's settled state will match the value's
|
1183
|
-
settled state. So a promise that *resolves* a promise that rejects will
|
1184
|
-
itself reject, and a promise that *resolves* a promise that fulfills will
|
1185
|
-
itself fulfill.
|
1186
|
-
|
1187
|
-
|
1188
|
-
Basic Usage:
|
1189
|
-
------------
|
1190
|
-
|
1191
|
-
```js
|
1192
|
-
let promise = new Promise(function(resolve, reject) {
|
1193
|
-
// on success
|
1194
|
-
resolve(value);
|
1195
|
-
|
1196
|
-
// on failure
|
1197
|
-
reject(reason);
|
1198
|
-
});
|
1199
|
-
|
1200
|
-
promise.then(function(value) {
|
1201
|
-
// on fulfillment
|
1202
|
-
}, function(reason) {
|
1203
|
-
// on rejection
|
1204
|
-
});
|
1205
|
-
```
|
1206
|
-
|
1207
|
-
Advanced Usage:
|
1208
|
-
---------------
|
1209
|
-
|
1210
|
-
Promises shine when abstracting away asynchronous interactions such as
|
1211
|
-
`XMLHttpRequest`s.
|
1212
|
-
|
1213
|
-
```js
|
1214
|
-
function getJSON(url) {
|
1215
|
-
return new Promise(function(resolve, reject){
|
1216
|
-
let xhr = new XMLHttpRequest();
|
1217
|
-
|
1218
|
-
xhr.open('GET', url);
|
1219
|
-
xhr.onreadystatechange = handler;
|
1220
|
-
xhr.responseType = 'json';
|
1221
|
-
xhr.setRequestHeader('Accept', 'application/json');
|
1222
|
-
xhr.send();
|
1223
|
-
|
1224
|
-
function handler() {
|
1225
|
-
if (this.readyState === this.DONE) {
|
1226
|
-
if (this.status === 200) {
|
1227
|
-
resolve(this.response);
|
1228
|
-
} else {
|
1229
|
-
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
1230
|
-
}
|
1231
|
-
}
|
1232
|
-
};
|
1233
|
-
});
|
1234
|
-
}
|
1235
|
-
|
1236
|
-
getJSON('/posts.json').then(function(json) {
|
1237
|
-
// on fulfillment
|
1238
|
-
}, function(reason) {
|
1239
|
-
// on rejection
|
1240
|
-
});
|
1241
|
-
```
|
1242
|
-
|
1243
|
-
Unlike callbacks, promises are great composable primitives.
|
1244
|
-
|
1245
|
-
```js
|
1246
|
-
Promise.all([
|
1247
|
-
getJSON('/posts'),
|
1248
|
-
getJSON('/comments')
|
1249
|
-
]).then(function(values){
|
1250
|
-
values[0] // => postsJSON
|
1251
|
-
values[1] // => commentsJSON
|
1252
|
-
|
1253
|
-
return values;
|
1254
|
-
});
|
1255
|
-
```
|
1256
|
-
|
1257
|
-
@class Promise
|
1258
|
-
@param {function} resolver
|
1259
|
-
Useful for tooling.
|
1260
|
-
@constructor
|
1261
|
-
*/
|
1262
|
-
function Promise$2(resolver) {
|
1263
|
-
this[PROMISE_ID] = nextId();
|
1264
|
-
this._result = this._state = undefined;
|
1265
|
-
this._subscribers = [];
|
1266
|
-
|
1267
|
-
if (noop !== resolver) {
|
1268
|
-
typeof resolver !== 'function' && needsResolver();
|
1269
|
-
this instanceof Promise$2 ? initializePromise(this, resolver) : needsNew();
|
1270
|
-
}
|
1271
|
-
}
|
1272
|
-
|
1273
|
-
Promise$2.all = all$1;
|
1274
|
-
Promise$2.race = race$1;
|
1275
|
-
Promise$2.resolve = resolve$1;
|
1276
|
-
Promise$2.reject = reject$1;
|
1277
|
-
Promise$2._setScheduler = setScheduler;
|
1278
|
-
Promise$2._setAsap = setAsap;
|
1279
|
-
Promise$2._asap = asap;
|
1280
|
-
|
1281
|
-
Promise$2.prototype = {
|
1282
|
-
constructor: Promise$2,
|
1283
|
-
|
1284
|
-
/**
|
1285
|
-
The primary way of interacting with a promise is through its `then` method,
|
1286
|
-
which registers callbacks to receive either a promise's eventual value or the
|
1287
|
-
reason why the promise cannot be fulfilled.
|
1288
|
-
|
1289
|
-
```js
|
1290
|
-
findUser().then(function(user){
|
1291
|
-
// user is available
|
1292
|
-
}, function(reason){
|
1293
|
-
// user is unavailable, and you are given the reason why
|
1294
|
-
});
|
1295
|
-
```
|
1296
|
-
|
1297
|
-
Chaining
|
1298
|
-
--------
|
1299
|
-
|
1300
|
-
The return value of `then` is itself a promise. This second, 'downstream'
|
1301
|
-
promise is resolved with the return value of the first promise's fulfillment
|
1302
|
-
or rejection handler, or rejected if the handler throws an exception.
|
1303
|
-
|
1304
|
-
```js
|
1305
|
-
findUser().then(function (user) {
|
1306
|
-
return user.name;
|
1307
|
-
}, function (reason) {
|
1308
|
-
return 'default name';
|
1309
|
-
}).then(function (userName) {
|
1310
|
-
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
1311
|
-
// will be `'default name'`
|
1312
|
-
});
|
1313
|
-
|
1314
|
-
findUser().then(function (user) {
|
1315
|
-
throw new Error('Found user, but still unhappy');
|
1316
|
-
}, function (reason) {
|
1317
|
-
throw new Error('`findUser` rejected and we're unhappy');
|
1318
|
-
}).then(function (value) {
|
1319
|
-
// never reached
|
1320
|
-
}, function (reason) {
|
1321
|
-
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
1322
|
-
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
1323
|
-
});
|
1324
|
-
```
|
1325
|
-
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
1326
|
-
|
1327
|
-
```js
|
1328
|
-
findUser().then(function (user) {
|
1329
|
-
throw new PedagogicalException('Upstream error');
|
1330
|
-
}).then(function (value) {
|
1331
|
-
// never reached
|
1332
|
-
}).then(function (value) {
|
1333
|
-
// never reached
|
1334
|
-
}, function (reason) {
|
1335
|
-
// The `PedgagocialException` is propagated all the way down to here
|
1336
|
-
});
|
1337
|
-
```
|
1338
|
-
|
1339
|
-
Assimilation
|
1340
|
-
------------
|
1341
|
-
|
1342
|
-
Sometimes the value you want to propagate to a downstream promise can only be
|
1343
|
-
retrieved asynchronously. This can be achieved by returning a promise in the
|
1344
|
-
fulfillment or rejection handler. The downstream promise will then be pending
|
1345
|
-
until the returned promise is settled. This is called *assimilation*.
|
1346
|
-
|
1347
|
-
```js
|
1348
|
-
findUser().then(function (user) {
|
1349
|
-
return findCommentsByAuthor(user);
|
1350
|
-
}).then(function (comments) {
|
1351
|
-
// The user's comments are now available
|
1352
|
-
});
|
1353
|
-
```
|
1354
|
-
|
1355
|
-
If the assimliated promise rejects, then the downstream promise will also reject.
|
1356
|
-
|
1357
|
-
```js
|
1358
|
-
findUser().then(function (user) {
|
1359
|
-
return findCommentsByAuthor(user);
|
1360
|
-
}).then(function (comments) {
|
1361
|
-
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
1362
|
-
}, function (reason) {
|
1363
|
-
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
1364
|
-
});
|
1365
|
-
```
|
1366
|
-
|
1367
|
-
Simple Example
|
1368
|
-
--------------
|
1369
|
-
|
1370
|
-
Synchronous Example
|
1371
|
-
|
1372
|
-
```javascript
|
1373
|
-
let result;
|
1374
|
-
|
1375
|
-
try {
|
1376
|
-
result = findResult();
|
1377
|
-
// success
|
1378
|
-
} catch(reason) {
|
1379
|
-
// failure
|
1380
|
-
}
|
1381
|
-
```
|
1382
|
-
|
1383
|
-
Errback Example
|
1384
|
-
|
1385
|
-
```js
|
1386
|
-
findResult(function(result, err){
|
1387
|
-
if (err) {
|
1388
|
-
// failure
|
1389
|
-
} else {
|
1390
|
-
// success
|
1391
|
-
}
|
1392
|
-
});
|
1393
|
-
```
|
1394
|
-
|
1395
|
-
Promise Example;
|
1396
|
-
|
1397
|
-
```javascript
|
1398
|
-
findResult().then(function(result){
|
1399
|
-
// success
|
1400
|
-
}, function(reason){
|
1401
|
-
// failure
|
1402
|
-
});
|
1403
|
-
```
|
1404
|
-
|
1405
|
-
Advanced Example
|
1406
|
-
--------------
|
1407
|
-
|
1408
|
-
Synchronous Example
|
1409
|
-
|
1410
|
-
```javascript
|
1411
|
-
let author, books;
|
1412
|
-
|
1413
|
-
try {
|
1414
|
-
author = findAuthor();
|
1415
|
-
books = findBooksByAuthor(author);
|
1416
|
-
// success
|
1417
|
-
} catch(reason) {
|
1418
|
-
// failure
|
1419
|
-
}
|
1420
|
-
```
|
1421
|
-
|
1422
|
-
Errback Example
|
1423
|
-
|
1424
|
-
```js
|
1425
|
-
|
1426
|
-
function foundBooks(books) {
|
1427
|
-
|
1428
|
-
}
|
1429
|
-
|
1430
|
-
function failure(reason) {
|
1431
|
-
|
1432
|
-
}
|
1433
|
-
|
1434
|
-
findAuthor(function(author, err){
|
1435
|
-
if (err) {
|
1436
|
-
failure(err);
|
1437
|
-
// failure
|
1438
|
-
} else {
|
1439
|
-
try {
|
1440
|
-
findBoooksByAuthor(author, function(books, err) {
|
1441
|
-
if (err) {
|
1442
|
-
failure(err);
|
1443
|
-
} else {
|
1444
|
-
try {
|
1445
|
-
foundBooks(books);
|
1446
|
-
} catch(reason) {
|
1447
|
-
failure(reason);
|
1448
|
-
}
|
1449
|
-
}
|
1450
|
-
});
|
1451
|
-
} catch(error) {
|
1452
|
-
failure(err);
|
1453
|
-
}
|
1454
|
-
// success
|
1455
|
-
}
|
1456
|
-
});
|
1457
|
-
```
|
1458
|
-
|
1459
|
-
Promise Example;
|
1460
|
-
|
1461
|
-
```javascript
|
1462
|
-
findAuthor().
|
1463
|
-
then(findBooksByAuthor).
|
1464
|
-
then(function(books){
|
1465
|
-
// found books
|
1466
|
-
}).catch(function(reason){
|
1467
|
-
// something went wrong
|
1468
|
-
});
|
1469
|
-
```
|
1470
|
-
|
1471
|
-
@method then
|
1472
|
-
@param {Function} onFulfilled
|
1473
|
-
@param {Function} onRejected
|
1474
|
-
Useful for tooling.
|
1475
|
-
@return {Promise}
|
1476
|
-
*/
|
1477
|
-
then: then,
|
1478
|
-
|
1479
|
-
/**
|
1480
|
-
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
1481
|
-
as the catch block of a try/catch statement.
|
1482
|
-
|
1483
|
-
```js
|
1484
|
-
function findAuthor(){
|
1485
|
-
throw new Error('couldn't find that author');
|
1486
|
-
}
|
1487
|
-
|
1488
|
-
// synchronous
|
1489
|
-
try {
|
1490
|
-
findAuthor();
|
1491
|
-
} catch(reason) {
|
1492
|
-
// something went wrong
|
1493
|
-
}
|
1494
|
-
|
1495
|
-
// async with promises
|
1496
|
-
findAuthor().catch(function(reason){
|
1497
|
-
// something went wrong
|
1498
|
-
});
|
1499
|
-
```
|
1500
|
-
|
1501
|
-
@method catch
|
1502
|
-
@param {Function} onRejection
|
1503
|
-
Useful for tooling.
|
1504
|
-
@return {Promise}
|
1505
|
-
*/
|
1506
|
-
'catch': function _catch(onRejection) {
|
1507
|
-
return this.then(null, onRejection);
|
1508
|
-
}
|
1509
|
-
};
|
1510
|
-
|
1511
|
-
/*global self*/
|
1512
|
-
function polyfill$1() {
|
1513
|
-
var local = undefined;
|
1514
|
-
|
1515
|
-
if (typeof global !== 'undefined') {
|
1516
|
-
local = global;
|
1517
|
-
} else if (typeof self !== 'undefined') {
|
1518
|
-
local = self;
|
1519
|
-
} else {
|
1520
|
-
try {
|
1521
|
-
local = Function('return this')();
|
1522
|
-
} catch (e) {
|
1523
|
-
throw new Error('polyfill failed because global object is unavailable in this environment');
|
1524
|
-
}
|
1525
|
-
}
|
1526
|
-
|
1527
|
-
var P = local.Promise;
|
1528
|
-
|
1529
|
-
if (P) {
|
1530
|
-
var promiseToString = null;
|
1531
|
-
try {
|
1532
|
-
promiseToString = Object.prototype.toString.call(P.resolve());
|
1533
|
-
} catch (e) {
|
1534
|
-
// silently ignored
|
1535
|
-
}
|
1536
|
-
|
1537
|
-
if (promiseToString === '[object Promise]' && !P.cast) {
|
1538
|
-
return;
|
1539
|
-
}
|
1540
|
-
}
|
1541
|
-
|
1542
|
-
local.Promise = Promise$2;
|
1543
|
-
}
|
1544
|
-
|
1545
|
-
// Strange compat..
|
1546
|
-
Promise$2.polyfill = polyfill$1;
|
1547
|
-
Promise$2.Promise = Promise$2;
|
1548
|
-
|
1549
|
-
return Promise$2;
|
1550
|
-
|
1551
|
-
})));
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
}).call(this,require(11),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1556
|
-
},{"11":11}],4:[function(require,module,exports){
|
1557
|
-
|
1558
|
-
var hasOwn = Object.prototype.hasOwnProperty;
|
1559
|
-
var toString = Object.prototype.toString;
|
1560
|
-
|
1561
|
-
module.exports = function forEach (obj, fn, ctx) {
|
1562
|
-
if (toString.call(fn) !== '[object Function]') {
|
1563
|
-
throw new TypeError('iterator must be a function');
|
1564
|
-
}
|
1565
|
-
var l = obj.length;
|
1566
|
-
if (l === +l) {
|
1567
|
-
for (var i = 0; i < l; i++) {
|
1568
|
-
fn.call(ctx, obj[i], i, obj);
|
1569
|
-
}
|
1570
|
-
} else {
|
1571
|
-
for (var k in obj) {
|
1572
|
-
if (hasOwn.call(obj, k)) {
|
1573
|
-
fn.call(ctx, obj[k], k, obj);
|
1574
|
-
}
|
1575
|
-
}
|
1576
|
-
}
|
1577
|
-
};
|
1578
|
-
|
1579
|
-
|
1580
|
-
},{}],5:[function(require,module,exports){
|
1581
|
-
(function (global){
|
1582
|
-
var win;
|
1583
|
-
|
1584
|
-
if (typeof window !== "undefined") {
|
1585
|
-
win = window;
|
1586
|
-
} else if (typeof global !== "undefined") {
|
1587
|
-
win = global;
|
1588
|
-
} else if (typeof self !== "undefined"){
|
1589
|
-
win = self;
|
1590
|
-
} else {
|
1591
|
-
win = {};
|
1592
|
-
}
|
1593
|
-
|
1594
|
-
module.exports = win;
|
1595
|
-
|
1596
|
-
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1597
|
-
},{}],6:[function(require,module,exports){
|
1598
|
-
if (typeof Object.create === 'function') {
|
1599
|
-
// implementation from standard node.js 'util' module
|
1600
|
-
module.exports = function inherits(ctor, superCtor) {
|
1601
|
-
ctor.super_ = superCtor
|
1602
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
1603
|
-
constructor: {
|
1604
|
-
value: ctor,
|
1605
|
-
enumerable: false,
|
1606
|
-
writable: true,
|
1607
|
-
configurable: true
|
1608
|
-
}
|
1609
|
-
});
|
1610
|
-
};
|
1611
|
-
} else {
|
1612
|
-
// old school shim for old browsers
|
1613
|
-
module.exports = function inherits(ctor, superCtor) {
|
1614
|
-
ctor.super_ = superCtor
|
1615
|
-
var TempCtor = function () {}
|
1616
|
-
TempCtor.prototype = superCtor.prototype
|
1617
|
-
ctor.prototype = new TempCtor()
|
1618
|
-
ctor.prototype.constructor = ctor
|
1619
|
-
}
|
1620
|
-
}
|
1621
|
-
|
1622
|
-
},{}],7:[function(require,module,exports){
|
1623
|
-
var toString = {}.toString;
|
1624
|
-
|
1625
|
-
module.exports = Array.isArray || function (arr) {
|
1626
|
-
return toString.call(arr) == '[object Array]';
|
1627
|
-
};
|
1628
|
-
|
1629
|
-
},{}],8:[function(require,module,exports){
|
1630
|
-
/**
|
1631
|
-
* Helpers.
|
1632
|
-
*/
|
1633
|
-
|
1634
|
-
var s = 1000;
|
1635
|
-
var m = s * 60;
|
1636
|
-
var h = m * 60;
|
1637
|
-
var d = h * 24;
|
1638
|
-
var y = d * 365.25;
|
1639
|
-
|
1640
|
-
/**
|
1641
|
-
* Parse or format the given `val`.
|
1642
|
-
*
|
1643
|
-
* Options:
|
1644
|
-
*
|
1645
|
-
* - `long` verbose formatting [false]
|
1646
|
-
*
|
1647
|
-
* @param {String|Number} val
|
1648
|
-
* @param {Object} [options]
|
1649
|
-
* @throws {Error} throw an error if val is not a non-empty string or a number
|
1650
|
-
* @return {String|Number}
|
1651
|
-
* @api public
|
1652
|
-
*/
|
1653
|
-
|
1654
|
-
module.exports = function(val, options) {
|
1655
|
-
options = options || {};
|
1656
|
-
var type = typeof val;
|
1657
|
-
if (type === 'string' && val.length > 0) {
|
1658
|
-
return parse(val);
|
1659
|
-
} else if (type === 'number' && isNaN(val) === false) {
|
1660
|
-
return options.long ? fmtLong(val) : fmtShort(val);
|
1661
|
-
}
|
1662
|
-
throw new Error(
|
1663
|
-
'val is not a non-empty string or a valid number. val=' +
|
1664
|
-
JSON.stringify(val)
|
1665
|
-
);
|
1666
|
-
};
|
1667
|
-
|
1668
|
-
/**
|
1669
|
-
* Parse the given `str` and return milliseconds.
|
1670
|
-
*
|
1671
|
-
* @param {String} str
|
1672
|
-
* @return {Number}
|
1673
|
-
* @api private
|
1674
|
-
*/
|
1675
|
-
|
1676
|
-
function parse(str) {
|
1677
|
-
str = String(str);
|
1678
|
-
if (str.length > 100) {
|
1679
|
-
return;
|
1680
|
-
}
|
1681
|
-
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
|
1682
|
-
str
|
1683
|
-
);
|
1684
|
-
if (!match) {
|
1685
|
-
return;
|
1686
|
-
}
|
1687
|
-
var n = parseFloat(match[1]);
|
1688
|
-
var type = (match[2] || 'ms').toLowerCase();
|
1689
|
-
switch (type) {
|
1690
|
-
case 'years':
|
1691
|
-
case 'year':
|
1692
|
-
case 'yrs':
|
1693
|
-
case 'yr':
|
1694
|
-
case 'y':
|
1695
|
-
return n * y;
|
1696
|
-
case 'days':
|
1697
|
-
case 'day':
|
1698
|
-
case 'd':
|
1699
|
-
return n * d;
|
1700
|
-
case 'hours':
|
1701
|
-
case 'hour':
|
1702
|
-
case 'hrs':
|
1703
|
-
case 'hr':
|
1704
|
-
case 'h':
|
1705
|
-
return n * h;
|
1706
|
-
case 'minutes':
|
1707
|
-
case 'minute':
|
1708
|
-
case 'mins':
|
1709
|
-
case 'min':
|
1710
|
-
case 'm':
|
1711
|
-
return n * m;
|
1712
|
-
case 'seconds':
|
1713
|
-
case 'second':
|
1714
|
-
case 'secs':
|
1715
|
-
case 'sec':
|
1716
|
-
case 's':
|
1717
|
-
return n * s;
|
1718
|
-
case 'milliseconds':
|
1719
|
-
case 'millisecond':
|
1720
|
-
case 'msecs':
|
1721
|
-
case 'msec':
|
1722
|
-
case 'ms':
|
1723
|
-
return n;
|
1724
|
-
default:
|
1725
|
-
return undefined;
|
1726
|
-
}
|
1727
|
-
}
|
1728
|
-
|
1729
|
-
/**
|
1730
|
-
* Short format for `ms`.
|
1731
|
-
*
|
1732
|
-
* @param {Number} ms
|
1733
|
-
* @return {String}
|
1734
|
-
* @api private
|
1735
|
-
*/
|
1736
|
-
|
1737
|
-
function fmtShort(ms) {
|
1738
|
-
if (ms >= d) {
|
1739
|
-
return Math.round(ms / d) + 'd';
|
1740
|
-
}
|
1741
|
-
if (ms >= h) {
|
1742
|
-
return Math.round(ms / h) + 'h';
|
1743
|
-
}
|
1744
|
-
if (ms >= m) {
|
1745
|
-
return Math.round(ms / m) + 'm';
|
1746
|
-
}
|
1747
|
-
if (ms >= s) {
|
1748
|
-
return Math.round(ms / s) + 's';
|
1749
|
-
}
|
1750
|
-
return ms + 'ms';
|
1751
|
-
}
|
1752
|
-
|
1753
|
-
/**
|
1754
|
-
* Long format for `ms`.
|
1755
|
-
*
|
1756
|
-
* @param {Number} ms
|
1757
|
-
* @return {String}
|
1758
|
-
* @api private
|
1759
|
-
*/
|
1760
|
-
|
1761
|
-
function fmtLong(ms) {
|
1762
|
-
return plural(ms, d, 'day') ||
|
1763
|
-
plural(ms, h, 'hour') ||
|
1764
|
-
plural(ms, m, 'minute') ||
|
1765
|
-
plural(ms, s, 'second') ||
|
1766
|
-
ms + ' ms';
|
1767
|
-
}
|
1768
|
-
|
1769
|
-
/**
|
1770
|
-
* Pluralization helper.
|
1771
|
-
*/
|
1772
|
-
|
1773
|
-
function plural(ms, n, name) {
|
1774
|
-
if (ms < n) {
|
1775
|
-
return;
|
1776
|
-
}
|
1777
|
-
if (ms < n * 1.5) {
|
1778
|
-
return Math.floor(ms / n) + ' ' + name;
|
1779
|
-
}
|
1780
|
-
return Math.ceil(ms / n) + ' ' + name + 's';
|
1781
|
-
}
|
1782
|
-
|
1783
|
-
},{}],9:[function(require,module,exports){
|
1784
|
-
'use strict';
|
1785
|
-
|
1786
|
-
// modified from https://github.com/es-shims/es5-shim
|
1787
|
-
var has = Object.prototype.hasOwnProperty;
|
1788
|
-
var toStr = Object.prototype.toString;
|
1789
|
-
var slice = Array.prototype.slice;
|
1790
|
-
var isArgs = require(10);
|
1791
|
-
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
1792
|
-
var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
|
1793
|
-
var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
|
1794
|
-
var dontEnums = [
|
1795
|
-
'toString',
|
1796
|
-
'toLocaleString',
|
1797
|
-
'valueOf',
|
1798
|
-
'hasOwnProperty',
|
1799
|
-
'isPrototypeOf',
|
1800
|
-
'propertyIsEnumerable',
|
1801
|
-
'constructor'
|
1802
|
-
];
|
1803
|
-
var equalsConstructorPrototype = function (o) {
|
1804
|
-
var ctor = o.constructor;
|
1805
|
-
return ctor && ctor.prototype === o;
|
1806
|
-
};
|
1807
|
-
var excludedKeys = {
|
1808
|
-
$console: true,
|
1809
|
-
$external: true,
|
1810
|
-
$frame: true,
|
1811
|
-
$frameElement: true,
|
1812
|
-
$frames: true,
|
1813
|
-
$innerHeight: true,
|
1814
|
-
$innerWidth: true,
|
1815
|
-
$outerHeight: true,
|
1816
|
-
$outerWidth: true,
|
1817
|
-
$pageXOffset: true,
|
1818
|
-
$pageYOffset: true,
|
1819
|
-
$parent: true,
|
1820
|
-
$scrollLeft: true,
|
1821
|
-
$scrollTop: true,
|
1822
|
-
$scrollX: true,
|
1823
|
-
$scrollY: true,
|
1824
|
-
$self: true,
|
1825
|
-
$webkitIndexedDB: true,
|
1826
|
-
$webkitStorageInfo: true,
|
1827
|
-
$window: true
|
1828
|
-
};
|
1829
|
-
var hasAutomationEqualityBug = (function () {
|
1830
|
-
/* global window */
|
1831
|
-
if (typeof window === 'undefined') { return false; }
|
1832
|
-
for (var k in window) {
|
1833
|
-
try {
|
1834
|
-
if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
|
1835
|
-
try {
|
1836
|
-
equalsConstructorPrototype(window[k]);
|
1837
|
-
} catch (e) {
|
1838
|
-
return true;
|
1839
|
-
}
|
1840
|
-
}
|
1841
|
-
} catch (e) {
|
1842
|
-
return true;
|
1843
|
-
}
|
1844
|
-
}
|
1845
|
-
return false;
|
1846
|
-
}());
|
1847
|
-
var equalsConstructorPrototypeIfNotBuggy = function (o) {
|
1848
|
-
/* global window */
|
1849
|
-
if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
|
1850
|
-
return equalsConstructorPrototype(o);
|
1851
|
-
}
|
1852
|
-
try {
|
1853
|
-
return equalsConstructorPrototype(o);
|
1854
|
-
} catch (e) {
|
1855
|
-
return false;
|
1856
|
-
}
|
1857
|
-
};
|
1858
|
-
|
1859
|
-
var keysShim = function keys(object) {
|
1860
|
-
var isObject = object !== null && typeof object === 'object';
|
1861
|
-
var isFunction = toStr.call(object) === '[object Function]';
|
1862
|
-
var isArguments = isArgs(object);
|
1863
|
-
var isString = isObject && toStr.call(object) === '[object String]';
|
1864
|
-
var theKeys = [];
|
1865
|
-
|
1866
|
-
if (!isObject && !isFunction && !isArguments) {
|
1867
|
-
throw new TypeError('Object.keys called on a non-object');
|
1868
|
-
}
|
1869
|
-
|
1870
|
-
var skipProto = hasProtoEnumBug && isFunction;
|
1871
|
-
if (isString && object.length > 0 && !has.call(object, 0)) {
|
1872
|
-
for (var i = 0; i < object.length; ++i) {
|
1873
|
-
theKeys.push(String(i));
|
1874
|
-
}
|
1875
|
-
}
|
1876
|
-
|
1877
|
-
if (isArguments && object.length > 0) {
|
1878
|
-
for (var j = 0; j < object.length; ++j) {
|
1879
|
-
theKeys.push(String(j));
|
1880
|
-
}
|
1881
|
-
} else {
|
1882
|
-
for (var name in object) {
|
1883
|
-
if (!(skipProto && name === 'prototype') && has.call(object, name)) {
|
1884
|
-
theKeys.push(String(name));
|
1885
|
-
}
|
1886
|
-
}
|
1887
|
-
}
|
1888
|
-
|
1889
|
-
if (hasDontEnumBug) {
|
1890
|
-
var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
|
1891
|
-
|
1892
|
-
for (var k = 0; k < dontEnums.length; ++k) {
|
1893
|
-
if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
|
1894
|
-
theKeys.push(dontEnums[k]);
|
1895
|
-
}
|
1896
|
-
}
|
1897
|
-
}
|
1898
|
-
return theKeys;
|
1899
|
-
};
|
1900
|
-
|
1901
|
-
keysShim.shim = function shimObjectKeys() {
|
1902
|
-
if (Object.keys) {
|
1903
|
-
var keysWorksWithArguments = (function () {
|
1904
|
-
// Safari 5.0 bug
|
1905
|
-
return (Object.keys(arguments) || '').length === 2;
|
1906
|
-
}(1, 2));
|
1907
|
-
if (!keysWorksWithArguments) {
|
1908
|
-
var originalKeys = Object.keys;
|
1909
|
-
Object.keys = function keys(object) {
|
1910
|
-
if (isArgs(object)) {
|
1911
|
-
return originalKeys(slice.call(object));
|
1912
|
-
} else {
|
1913
|
-
return originalKeys(object);
|
1914
|
-
}
|
1915
|
-
};
|
1916
|
-
}
|
1917
|
-
} else {
|
1918
|
-
Object.keys = keysShim;
|
1919
|
-
}
|
1920
|
-
return Object.keys || keysShim;
|
1921
|
-
};
|
1922
|
-
|
1923
|
-
module.exports = keysShim;
|
1924
|
-
|
1925
|
-
},{"10":10}],10:[function(require,module,exports){
|
1926
|
-
'use strict';
|
1927
|
-
|
1928
|
-
var toStr = Object.prototype.toString;
|
1929
|
-
|
1930
|
-
module.exports = function isArguments(value) {
|
1931
|
-
var str = toStr.call(value);
|
1932
|
-
var isArgs = str === '[object Arguments]';
|
1933
|
-
if (!isArgs) {
|
1934
|
-
isArgs = str !== '[object Array]' &&
|
1935
|
-
value !== null &&
|
1936
|
-
typeof value === 'object' &&
|
1937
|
-
typeof value.length === 'number' &&
|
1938
|
-
value.length >= 0 &&
|
1939
|
-
toStr.call(value.callee) === '[object Function]';
|
1940
|
-
}
|
1941
|
-
return isArgs;
|
1942
|
-
};
|
1943
|
-
|
1944
|
-
},{}],11:[function(require,module,exports){
|
1945
|
-
// shim for using process in browser
|
1946
|
-
var process = module.exports = {};
|
1947
|
-
|
1948
|
-
// cached from whatever global is present so that test runners that stub it
|
1949
|
-
// don't break things. But we need to wrap it in a try catch in case it is
|
1950
|
-
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
1951
|
-
// function because try/catches deoptimize in certain engines.
|
1952
|
-
|
1953
|
-
var cachedSetTimeout;
|
1954
|
-
var cachedClearTimeout;
|
1955
|
-
|
1956
|
-
function defaultSetTimout() {
|
1957
|
-
throw new Error('setTimeout has not been defined');
|
1958
|
-
}
|
1959
|
-
function defaultClearTimeout () {
|
1960
|
-
throw new Error('clearTimeout has not been defined');
|
1961
|
-
}
|
1962
|
-
(function () {
|
1963
|
-
try {
|
1964
|
-
if (typeof setTimeout === 'function') {
|
1965
|
-
cachedSetTimeout = setTimeout;
|
1966
|
-
} else {
|
1967
|
-
cachedSetTimeout = defaultSetTimout;
|
1968
|
-
}
|
1969
|
-
} catch (e) {
|
1970
|
-
cachedSetTimeout = defaultSetTimout;
|
1971
|
-
}
|
1972
|
-
try {
|
1973
|
-
if (typeof clearTimeout === 'function') {
|
1974
|
-
cachedClearTimeout = clearTimeout;
|
1975
|
-
} else {
|
1976
|
-
cachedClearTimeout = defaultClearTimeout;
|
1977
|
-
}
|
1978
|
-
} catch (e) {
|
1979
|
-
cachedClearTimeout = defaultClearTimeout;
|
1980
|
-
}
|
1981
|
-
} ())
|
1982
|
-
function runTimeout(fun) {
|
1983
|
-
if (cachedSetTimeout === setTimeout) {
|
1984
|
-
//normal enviroments in sane situations
|
1985
|
-
return setTimeout(fun, 0);
|
1986
|
-
}
|
1987
|
-
// if setTimeout wasn't available but was latter defined
|
1988
|
-
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
1989
|
-
cachedSetTimeout = setTimeout;
|
1990
|
-
return setTimeout(fun, 0);
|
1991
|
-
}
|
1992
|
-
try {
|
1993
|
-
// when when somebody has screwed with setTimeout but no I.E. maddness
|
1994
|
-
return cachedSetTimeout(fun, 0);
|
1995
|
-
} catch(e){
|
1996
|
-
try {
|
1997
|
-
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
1998
|
-
return cachedSetTimeout.call(null, fun, 0);
|
1999
|
-
} catch(e){
|
2000
|
-
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
2001
|
-
return cachedSetTimeout.call(this, fun, 0);
|
2002
|
-
}
|
2003
|
-
}
|
2004
|
-
|
2005
|
-
|
2006
|
-
}
|
2007
|
-
function runClearTimeout(marker) {
|
2008
|
-
if (cachedClearTimeout === clearTimeout) {
|
2009
|
-
//normal enviroments in sane situations
|
2010
|
-
return clearTimeout(marker);
|
2011
|
-
}
|
2012
|
-
// if clearTimeout wasn't available but was latter defined
|
2013
|
-
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
2014
|
-
cachedClearTimeout = clearTimeout;
|
2015
|
-
return clearTimeout(marker);
|
2016
|
-
}
|
2017
|
-
try {
|
2018
|
-
// when when somebody has screwed with setTimeout but no I.E. maddness
|
2019
|
-
return cachedClearTimeout(marker);
|
2020
|
-
} catch (e){
|
2021
|
-
try {
|
2022
|
-
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
2023
|
-
return cachedClearTimeout.call(null, marker);
|
2024
|
-
} catch (e){
|
2025
|
-
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
2026
|
-
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
2027
|
-
return cachedClearTimeout.call(this, marker);
|
2028
|
-
}
|
2029
|
-
}
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
}
|
2034
|
-
var queue = [];
|
2035
|
-
var draining = false;
|
2036
|
-
var currentQueue;
|
2037
|
-
var queueIndex = -1;
|
2038
|
-
|
2039
|
-
function cleanUpNextTick() {
|
2040
|
-
if (!draining || !currentQueue) {
|
2041
|
-
return;
|
2042
|
-
}
|
2043
|
-
draining = false;
|
2044
|
-
if (currentQueue.length) {
|
2045
|
-
queue = currentQueue.concat(queue);
|
2046
|
-
} else {
|
2047
|
-
queueIndex = -1;
|
2048
|
-
}
|
2049
|
-
if (queue.length) {
|
2050
|
-
drainQueue();
|
2051
|
-
}
|
2052
|
-
}
|
2053
|
-
|
2054
|
-
function drainQueue() {
|
2055
|
-
if (draining) {
|
2056
|
-
return;
|
2057
|
-
}
|
2058
|
-
var timeout = runTimeout(cleanUpNextTick);
|
2059
|
-
draining = true;
|
2060
|
-
|
2061
|
-
var len = queue.length;
|
2062
|
-
while(len) {
|
2063
|
-
currentQueue = queue;
|
2064
|
-
queue = [];
|
2065
|
-
while (++queueIndex < len) {
|
2066
|
-
if (currentQueue) {
|
2067
|
-
currentQueue[queueIndex].run();
|
2068
|
-
}
|
2069
|
-
}
|
2070
|
-
queueIndex = -1;
|
2071
|
-
len = queue.length;
|
2072
|
-
}
|
2073
|
-
currentQueue = null;
|
2074
|
-
draining = false;
|
2075
|
-
runClearTimeout(timeout);
|
2076
|
-
}
|
2077
|
-
|
2078
|
-
process.nextTick = function (fun) {
|
2079
|
-
var args = new Array(arguments.length - 1);
|
2080
|
-
if (arguments.length > 1) {
|
2081
|
-
for (var i = 1; i < arguments.length; i++) {
|
2082
|
-
args[i - 1] = arguments[i];
|
2083
|
-
}
|
2084
|
-
}
|
2085
|
-
queue.push(new Item(fun, args));
|
2086
|
-
if (queue.length === 1 && !draining) {
|
2087
|
-
runTimeout(drainQueue);
|
2088
|
-
}
|
2089
|
-
};
|
2090
|
-
|
2091
|
-
// v8 likes predictible objects
|
2092
|
-
function Item(fun, array) {
|
2093
|
-
this.fun = fun;
|
2094
|
-
this.array = array;
|
2095
|
-
}
|
2096
|
-
Item.prototype.run = function () {
|
2097
|
-
this.fun.apply(null, this.array);
|
2098
|
-
};
|
2099
|
-
process.title = 'browser';
|
2100
|
-
process.browser = true;
|
2101
|
-
process.env = {};
|
2102
|
-
process.argv = [];
|
2103
|
-
process.version = ''; // empty string to avoid regexp issues
|
2104
|
-
process.versions = {};
|
2105
|
-
|
2106
|
-
function noop() {}
|
2107
|
-
|
2108
|
-
process.on = noop;
|
2109
|
-
process.addListener = noop;
|
2110
|
-
process.once = noop;
|
2111
|
-
process.off = noop;
|
2112
|
-
process.removeListener = noop;
|
2113
|
-
process.removeAllListeners = noop;
|
2114
|
-
process.emit = noop;
|
2115
|
-
|
2116
|
-
process.binding = function (name) {
|
2117
|
-
throw new Error('process.binding is not supported');
|
2118
|
-
};
|
2119
|
-
|
2120
|
-
process.cwd = function () { return '/' };
|
2121
|
-
process.chdir = function (dir) {
|
2122
|
-
throw new Error('process.chdir is not supported');
|
2123
|
-
};
|
2124
|
-
process.umask = function() { return 0; };
|
2125
|
-
|
2126
|
-
},{}],12:[function(require,module,exports){
|
2127
|
-
// Copyright Joyent, Inc. and other Node contributors.
|
2128
|
-
//
|
2129
|
-
// Permission is hereby granted, free of charge, to any person obtaining a
|
2130
|
-
// copy of this software and associated documentation files (the
|
2131
|
-
// "Software"), to deal in the Software without restriction, including
|
2132
|
-
// without limitation the rights to use, copy, modify, merge, publish,
|
2133
|
-
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
2134
|
-
// persons to whom the Software is furnished to do so, subject to the
|
2135
|
-
// following conditions:
|
2136
|
-
//
|
2137
|
-
// The above copyright notice and this permission notice shall be included
|
2138
|
-
// in all copies or substantial portions of the Software.
|
2139
|
-
//
|
2140
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
2141
|
-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
2142
|
-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
2143
|
-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
2144
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
2145
|
-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
2146
|
-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2147
|
-
|
2148
|
-
'use strict';
|
2149
|
-
|
2150
|
-
// If obj.hasOwnProperty has been overridden, then calling
|
2151
|
-
// obj.hasOwnProperty(prop) will break.
|
2152
|
-
// See: https://github.com/joyent/node/issues/1707
|
2153
|
-
function hasOwnProperty(obj, prop) {
|
2154
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
2155
|
-
}
|
2156
|
-
|
2157
|
-
module.exports = function(qs, sep, eq, options) {
|
2158
|
-
sep = sep || '&';
|
2159
|
-
eq = eq || '=';
|
2160
|
-
var obj = {};
|
2161
|
-
|
2162
|
-
if (typeof qs !== 'string' || qs.length === 0) {
|
2163
|
-
return obj;
|
2164
|
-
}
|
2165
|
-
|
2166
|
-
var regexp = /\+/g;
|
2167
|
-
qs = qs.split(sep);
|
2168
|
-
|
2169
|
-
var maxKeys = 1000;
|
2170
|
-
if (options && typeof options.maxKeys === 'number') {
|
2171
|
-
maxKeys = options.maxKeys;
|
2172
|
-
}
|
2173
|
-
|
2174
|
-
var len = qs.length;
|
2175
|
-
// maxKeys <= 0 means that we should not limit keys count
|
2176
|
-
if (maxKeys > 0 && len > maxKeys) {
|
2177
|
-
len = maxKeys;
|
2178
|
-
}
|
2179
|
-
|
2180
|
-
for (var i = 0; i < len; ++i) {
|
2181
|
-
var x = qs[i].replace(regexp, '%20'),
|
2182
|
-
idx = x.indexOf(eq),
|
2183
|
-
kstr, vstr, k, v;
|
2184
|
-
|
2185
|
-
if (idx >= 0) {
|
2186
|
-
kstr = x.substr(0, idx);
|
2187
|
-
vstr = x.substr(idx + 1);
|
2188
|
-
} else {
|
2189
|
-
kstr = x;
|
2190
|
-
vstr = '';
|
2191
|
-
}
|
2192
|
-
|
2193
|
-
k = decodeURIComponent(kstr);
|
2194
|
-
v = decodeURIComponent(vstr);
|
2195
|
-
|
2196
|
-
if (!hasOwnProperty(obj, k)) {
|
2197
|
-
obj[k] = v;
|
2198
|
-
} else if (isArray(obj[k])) {
|
2199
|
-
obj[k].push(v);
|
2200
|
-
} else {
|
2201
|
-
obj[k] = [obj[k], v];
|
2202
|
-
}
|
2203
|
-
}
|
2204
|
-
|
2205
|
-
return obj;
|
2206
|
-
};
|
2207
|
-
|
2208
|
-
var isArray = Array.isArray || function (xs) {
|
2209
|
-
return Object.prototype.toString.call(xs) === '[object Array]';
|
2210
|
-
};
|
2211
|
-
|
2212
|
-
},{}],13:[function(require,module,exports){
|
2213
|
-
// Copyright Joyent, Inc. and other Node contributors.
|
2214
|
-
//
|
2215
|
-
// Permission is hereby granted, free of charge, to any person obtaining a
|
2216
|
-
// copy of this software and associated documentation files (the
|
2217
|
-
// "Software"), to deal in the Software without restriction, including
|
2218
|
-
// without limitation the rights to use, copy, modify, merge, publish,
|
2219
|
-
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
2220
|
-
// persons to whom the Software is furnished to do so, subject to the
|
2221
|
-
// following conditions:
|
2222
|
-
//
|
2223
|
-
// The above copyright notice and this permission notice shall be included
|
2224
|
-
// in all copies or substantial portions of the Software.
|
2225
|
-
//
|
2226
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
2227
|
-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
2228
|
-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
2229
|
-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
2230
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
2231
|
-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
2232
|
-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2233
|
-
|
2234
|
-
'use strict';
|
2235
|
-
|
2236
|
-
var stringifyPrimitive = function(v) {
|
2237
|
-
switch (typeof v) {
|
2238
|
-
case 'string':
|
2239
|
-
return v;
|
2240
|
-
|
2241
|
-
case 'boolean':
|
2242
|
-
return v ? 'true' : 'false';
|
2243
|
-
|
2244
|
-
case 'number':
|
2245
|
-
return isFinite(v) ? v : '';
|
2246
|
-
|
2247
|
-
default:
|
2248
|
-
return '';
|
2249
|
-
}
|
2250
|
-
};
|
2251
|
-
|
2252
|
-
module.exports = function(obj, sep, eq, name) {
|
2253
|
-
sep = sep || '&';
|
2254
|
-
eq = eq || '=';
|
2255
|
-
if (obj === null) {
|
2256
|
-
obj = undefined;
|
2257
|
-
}
|
2258
|
-
|
2259
|
-
if (typeof obj === 'object') {
|
2260
|
-
return map(objectKeys(obj), function(k) {
|
2261
|
-
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
|
2262
|
-
if (isArray(obj[k])) {
|
2263
|
-
return map(obj[k], function(v) {
|
2264
|
-
return ks + encodeURIComponent(stringifyPrimitive(v));
|
2265
|
-
}).join(sep);
|
2266
|
-
} else {
|
2267
|
-
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
|
2268
|
-
}
|
2269
|
-
}).join(sep);
|
2270
|
-
|
2271
|
-
}
|
2272
|
-
|
2273
|
-
if (!name) return '';
|
2274
|
-
return encodeURIComponent(stringifyPrimitive(name)) + eq +
|
2275
|
-
encodeURIComponent(stringifyPrimitive(obj));
|
2276
|
-
};
|
2277
|
-
|
2278
|
-
var isArray = Array.isArray || function (xs) {
|
2279
|
-
return Object.prototype.toString.call(xs) === '[object Array]';
|
2280
|
-
};
|
2281
|
-
|
2282
|
-
function map (xs, f) {
|
2283
|
-
if (xs.map) return xs.map(f);
|
2284
|
-
var res = [];
|
2285
|
-
for (var i = 0; i < xs.length; i++) {
|
2286
|
-
res.push(f(xs[i], i));
|
2287
|
-
}
|
2288
|
-
return res;
|
2289
|
-
}
|
2290
|
-
|
2291
|
-
var objectKeys = Object.keys || function (obj) {
|
2292
|
-
var res = [];
|
2293
|
-
for (var key in obj) {
|
2294
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
|
2295
|
-
}
|
2296
|
-
return res;
|
2297
|
-
};
|
2298
|
-
|
2299
|
-
},{}],14:[function(require,module,exports){
|
2300
|
-
'use strict';
|
2301
|
-
|
2302
|
-
exports.decode = exports.parse = require(12);
|
2303
|
-
exports.encode = exports.stringify = require(13);
|
2304
|
-
|
2305
|
-
},{"12":12,"13":13}],15:[function(require,module,exports){
|
2306
|
-
(function (process){
|
2307
|
-
module.exports = AlgoliaSearchCore;
|
2308
|
-
|
2309
|
-
var errors = require(25);
|
2310
|
-
var exitPromise = require(26);
|
2311
|
-
var IndexCore = require(16);
|
2312
|
-
var store = require(31);
|
2313
|
-
|
2314
|
-
// We will always put the API KEY in the JSON body in case of too long API KEY,
|
2315
|
-
// to avoid query string being too long and failing in various conditions (our server limit, browser limit,
|
2316
|
-
// proxies limit)
|
2317
|
-
var MAX_API_KEY_LENGTH = 500;
|
2318
|
-
var RESET_APP_DATA_TIMER =
|
2319
|
-
process.env.RESET_APP_DATA_TIMER && parseInt(process.env.RESET_APP_DATA_TIMER, 10) ||
|
2320
|
-
60 * 2 * 1000; // after 2 minutes reset to first host
|
2321
|
-
|
2322
|
-
/*
|
2323
|
-
* Algolia Search library initialization
|
2324
|
-
* https://www.algolia.com/
|
2325
|
-
*
|
2326
|
-
* @param {string} applicationID - Your applicationID, found in your dashboard
|
2327
|
-
* @param {string} apiKey - Your API key, found in your dashboard
|
2328
|
-
* @param {Object} [opts]
|
2329
|
-
* @param {number} [opts.timeout=2000] - The request timeout set in milliseconds,
|
2330
|
-
* another request will be issued after this timeout
|
2331
|
-
* @param {string} [opts.protocol='https:'] - The protocol used to query Algolia Search API.
|
2332
|
-
* Set to 'http:' to force using http.
|
2333
|
-
* @param {Object|Array} [opts.hosts={
|
2334
|
-
* read: [this.applicationID + '-dsn.algolia.net'].concat([
|
2335
|
-
* this.applicationID + '-1.algolianet.com',
|
2336
|
-
* this.applicationID + '-2.algolianet.com',
|
2337
|
-
* this.applicationID + '-3.algolianet.com']
|
2338
|
-
* ]),
|
2339
|
-
* write: [this.applicationID + '.algolia.net'].concat([
|
2340
|
-
* this.applicationID + '-1.algolianet.com',
|
2341
|
-
* this.applicationID + '-2.algolianet.com',
|
2342
|
-
* this.applicationID + '-3.algolianet.com']
|
2343
|
-
* ]) - The hosts to use for Algolia Search API.
|
2344
|
-
* If you provide them, you will less benefit from our HA implementation
|
2345
|
-
*/
|
2346
|
-
function AlgoliaSearchCore(applicationID, apiKey, opts) {
|
2347
|
-
var debug = require(1)('algoliasearch');
|
2348
|
-
|
2349
|
-
var clone = require(22);
|
2350
|
-
var isArray = require(7);
|
2351
|
-
var map = require(27);
|
2352
|
-
|
2353
|
-
var usage = 'Usage: algoliasearch(applicationID, apiKey, opts)';
|
2354
|
-
|
2355
|
-
if (opts._allowEmptyCredentials !== true && !applicationID) {
|
2356
|
-
throw new errors.AlgoliaSearchError('Please provide an application ID. ' + usage);
|
2357
|
-
}
|
2358
|
-
|
2359
|
-
if (opts._allowEmptyCredentials !== true && !apiKey) {
|
2360
|
-
throw new errors.AlgoliaSearchError('Please provide an API key. ' + usage);
|
2361
|
-
}
|
2362
|
-
|
2363
|
-
this.applicationID = applicationID;
|
2364
|
-
this.apiKey = apiKey;
|
2365
|
-
|
2366
|
-
this.hosts = {
|
2367
|
-
read: [],
|
2368
|
-
write: []
|
2369
|
-
};
|
2370
|
-
|
2371
|
-
opts = opts || {};
|
2372
|
-
|
2373
|
-
this._timeouts = opts.timeouts || {
|
2374
|
-
connect: 1 * 1000, // 500ms connect is GPRS latency
|
2375
|
-
read: 2 * 1000,
|
2376
|
-
write: 30 * 1000
|
2377
|
-
};
|
2378
|
-
|
2379
|
-
// backward compat, if opts.timeout is passed, we use it to configure all timeouts like before
|
2380
|
-
if (opts.timeout) {
|
2381
|
-
this._timeouts.connect = this._timeouts.read = this._timeouts.write = opts.timeout;
|
2382
|
-
}
|
2383
|
-
|
2384
|
-
var protocol = opts.protocol || 'https:';
|
2385
|
-
// while we advocate for colon-at-the-end values: 'http:' for `opts.protocol`
|
2386
|
-
// we also accept `http` and `https`. It's a common error.
|
2387
|
-
if (!/:$/.test(protocol)) {
|
2388
|
-
protocol = protocol + ':';
|
2389
|
-
}
|
2390
|
-
|
2391
|
-
if (protocol !== 'http:' && protocol !== 'https:') {
|
2392
|
-
throw new errors.AlgoliaSearchError('protocol must be `http:` or `https:` (was `' + opts.protocol + '`)');
|
2393
|
-
}
|
2394
|
-
|
2395
|
-
this._checkAppIdData();
|
2396
|
-
|
2397
|
-
if (!opts.hosts) {
|
2398
|
-
var defaultHosts = map(this._shuffleResult, function(hostNumber) {
|
2399
|
-
return applicationID + '-' + hostNumber + '.algolianet.com';
|
2400
|
-
});
|
2401
|
-
|
2402
|
-
// no hosts given, compute defaults
|
2403
|
-
var mainSuffix = (opts.dsn === false ? '' : '-dsn') + '.algolia.net';
|
2404
|
-
this.hosts.read = [this.applicationID + mainSuffix].concat(defaultHosts);
|
2405
|
-
this.hosts.write = [this.applicationID + '.algolia.net'].concat(defaultHosts);
|
2406
|
-
} else if (isArray(opts.hosts)) {
|
2407
|
-
// when passing custom hosts, we need to have a different host index if the number
|
2408
|
-
// of write/read hosts are different.
|
2409
|
-
this.hosts.read = clone(opts.hosts);
|
2410
|
-
this.hosts.write = clone(opts.hosts);
|
2411
|
-
} else {
|
2412
|
-
this.hosts.read = clone(opts.hosts.read);
|
2413
|
-
this.hosts.write = clone(opts.hosts.write);
|
2414
|
-
}
|
2415
|
-
|
2416
|
-
// add protocol and lowercase hosts
|
2417
|
-
this.hosts.read = map(this.hosts.read, prepareHost(protocol));
|
2418
|
-
this.hosts.write = map(this.hosts.write, prepareHost(protocol));
|
2419
|
-
|
2420
|
-
this.extraHeaders = {};
|
2421
|
-
|
2422
|
-
// In some situations you might want to warm the cache
|
2423
|
-
this.cache = opts._cache || {};
|
2424
|
-
|
2425
|
-
this._ua = opts._ua;
|
2426
|
-
this._useCache = opts._useCache === undefined || opts._cache ? true : opts._useCache;
|
2427
|
-
this._useRequestCache = this._useCache && opts._useRequestCache;
|
2428
|
-
this._useFallback = opts.useFallback === undefined ? true : opts.useFallback;
|
2429
|
-
|
2430
|
-
this._setTimeout = opts._setTimeout;
|
2431
|
-
|
2432
|
-
debug('init done, %j', this);
|
2433
|
-
}
|
2434
|
-
|
2435
|
-
/*
|
2436
|
-
* Get the index object initialized
|
2437
|
-
*
|
2438
|
-
* @param indexName the name of index
|
2439
|
-
* @param callback the result callback with one argument (the Index instance)
|
2440
|
-
*/
|
2441
|
-
AlgoliaSearchCore.prototype.initIndex = function(indexName) {
|
2442
|
-
return new IndexCore(this, indexName);
|
2443
|
-
};
|
2444
|
-
|
2445
|
-
/**
|
2446
|
-
* Add an extra field to the HTTP request
|
2447
|
-
*
|
2448
|
-
* @param name the header field name
|
2449
|
-
* @param value the header field value
|
2450
|
-
*/
|
2451
|
-
AlgoliaSearchCore.prototype.setExtraHeader = function(name, value) {
|
2452
|
-
this.extraHeaders[name.toLowerCase()] = value;
|
2453
|
-
};
|
2454
|
-
|
2455
|
-
/**
|
2456
|
-
* Get the value of an extra HTTP header
|
2457
|
-
*
|
2458
|
-
* @param name the header field name
|
2459
|
-
*/
|
2460
|
-
AlgoliaSearchCore.prototype.getExtraHeader = function(name) {
|
2461
|
-
return this.extraHeaders[name.toLowerCase()];
|
2462
|
-
};
|
2463
|
-
|
2464
|
-
/**
|
2465
|
-
* Remove an extra field from the HTTP request
|
2466
|
-
*
|
2467
|
-
* @param name the header field name
|
2468
|
-
*/
|
2469
|
-
AlgoliaSearchCore.prototype.unsetExtraHeader = function(name) {
|
2470
|
-
delete this.extraHeaders[name.toLowerCase()];
|
2471
|
-
};
|
2472
|
-
|
2473
|
-
/**
|
2474
|
-
* Augment sent x-algolia-agent with more data, each agent part
|
2475
|
-
* is automatically separated from the others by a semicolon;
|
2476
|
-
*
|
2477
|
-
* @param algoliaAgent the agent to add
|
2478
|
-
*/
|
2479
|
-
AlgoliaSearchCore.prototype.addAlgoliaAgent = function(algoliaAgent) {
|
2480
|
-
var algoliaAgentWithDelimiter = '; ' + algoliaAgent;
|
2481
|
-
|
2482
|
-
if (this._ua.indexOf(algoliaAgentWithDelimiter) === -1) {
|
2483
|
-
this._ua += algoliaAgentWithDelimiter;
|
2484
|
-
}
|
2485
|
-
};
|
2486
|
-
|
2487
|
-
/*
|
2488
|
-
* Wrapper that try all hosts to maximize the quality of service
|
2489
|
-
*/
|
2490
|
-
AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
2491
|
-
this._checkAppIdData();
|
2492
|
-
|
2493
|
-
var requestDebug = require(1)('algoliasearch:' + initialOpts.url);
|
2494
|
-
|
2495
|
-
|
2496
|
-
var body;
|
2497
|
-
var cacheID;
|
2498
|
-
var additionalUA = initialOpts.additionalUA || '';
|
2499
|
-
var cache = initialOpts.cache;
|
2500
|
-
var client = this;
|
2501
|
-
var tries = 0;
|
2502
|
-
var usingFallback = false;
|
2503
|
-
var hasFallback = client._useFallback && client._request.fallback && initialOpts.fallback;
|
2504
|
-
var headers;
|
2505
|
-
|
2506
|
-
if (
|
2507
|
-
this.apiKey.length > MAX_API_KEY_LENGTH &&
|
2508
|
-
initialOpts.body !== undefined &&
|
2509
|
-
(initialOpts.body.params !== undefined || // index.search()
|
2510
|
-
initialOpts.body.requests !== undefined) // client.search()
|
2511
|
-
) {
|
2512
|
-
initialOpts.body.apiKey = this.apiKey;
|
2513
|
-
headers = this._computeRequestHeaders({
|
2514
|
-
additionalUA: additionalUA,
|
2515
|
-
withApiKey: false,
|
2516
|
-
headers: initialOpts.headers
|
2517
|
-
});
|
2518
|
-
} else {
|
2519
|
-
headers = this._computeRequestHeaders({
|
2520
|
-
additionalUA: additionalUA,
|
2521
|
-
headers: initialOpts.headers
|
2522
|
-
});
|
2523
|
-
}
|
2524
|
-
|
2525
|
-
if (initialOpts.body !== undefined) {
|
2526
|
-
body = safeJSONStringify(initialOpts.body);
|
2527
|
-
}
|
2528
|
-
|
2529
|
-
requestDebug('request start');
|
2530
|
-
var debugData = [];
|
2531
|
-
|
2532
|
-
|
2533
|
-
function doRequest(requester, reqOpts) {
|
2534
|
-
client._checkAppIdData();
|
2535
|
-
|
2536
|
-
var startTime = new Date();
|
2537
|
-
|
2538
|
-
if (client._useCache && !client._useRequestCache) {
|
2539
|
-
cacheID = initialOpts.url;
|
2540
|
-
}
|
2541
|
-
|
2542
|
-
// as we sometime use POST requests to pass parameters (like query='aa'),
|
2543
|
-
// the cacheID must also include the body to be different between calls
|
2544
|
-
if (client._useCache && !client._useRequestCache && body) {
|
2545
|
-
cacheID += '_body_' + reqOpts.body;
|
2546
|
-
}
|
2547
|
-
|
2548
|
-
// handle cache existence
|
2549
|
-
if (isCacheValidWithCurrentID(!client._useRequestCache, cache, cacheID)) {
|
2550
|
-
requestDebug('serving response from cache');
|
2551
|
-
|
2552
|
-
var responseText = cache[cacheID];
|
2553
|
-
|
2554
|
-
// Cache response must match the type of the original one
|
2555
|
-
return client._promise.resolve({
|
2556
|
-
body: JSON.parse(responseText),
|
2557
|
-
responseText: responseText
|
2558
|
-
});
|
2559
|
-
}
|
2560
|
-
|
2561
|
-
// if we reached max tries
|
2562
|
-
if (tries >= client.hosts[initialOpts.hostType].length) {
|
2563
|
-
if (!hasFallback || usingFallback) {
|
2564
|
-
requestDebug('could not get any response');
|
2565
|
-
// then stop
|
2566
|
-
return client._promise.reject(new errors.AlgoliaSearchError(
|
2567
|
-
'Cannot connect to the AlgoliaSearch API.' +
|
2568
|
-
' Send an email to support@algolia.com to report and resolve the issue.' +
|
2569
|
-
' Application id was: ' + client.applicationID, {debugData: debugData}
|
2570
|
-
));
|
2571
|
-
}
|
2572
|
-
|
2573
|
-
requestDebug('switching to fallback');
|
2574
|
-
|
2575
|
-
// let's try the fallback starting from here
|
2576
|
-
tries = 0;
|
2577
|
-
|
2578
|
-
// method, url and body are fallback dependent
|
2579
|
-
reqOpts.method = initialOpts.fallback.method;
|
2580
|
-
reqOpts.url = initialOpts.fallback.url;
|
2581
|
-
reqOpts.jsonBody = initialOpts.fallback.body;
|
2582
|
-
if (reqOpts.jsonBody) {
|
2583
|
-
reqOpts.body = safeJSONStringify(reqOpts.jsonBody);
|
2584
|
-
}
|
2585
|
-
// re-compute headers, they could be omitting the API KEY
|
2586
|
-
headers = client._computeRequestHeaders({
|
2587
|
-
additionalUA: additionalUA,
|
2588
|
-
headers: initialOpts.headers
|
2589
|
-
});
|
2590
|
-
|
2591
|
-
reqOpts.timeouts = client._getTimeoutsForRequest(initialOpts.hostType);
|
2592
|
-
client._setHostIndexByType(0, initialOpts.hostType);
|
2593
|
-
usingFallback = true; // the current request is now using fallback
|
2594
|
-
return doRequest(client._request.fallback, reqOpts);
|
2595
|
-
}
|
2596
|
-
|
2597
|
-
var currentHost = client._getHostByType(initialOpts.hostType);
|
2598
|
-
|
2599
|
-
var url = currentHost + reqOpts.url;
|
2600
|
-
var options = {
|
2601
|
-
body: reqOpts.body,
|
2602
|
-
jsonBody: reqOpts.jsonBody,
|
2603
|
-
method: reqOpts.method,
|
2604
|
-
headers: headers,
|
2605
|
-
timeouts: reqOpts.timeouts,
|
2606
|
-
debug: requestDebug,
|
2607
|
-
forceAuthHeaders: reqOpts.forceAuthHeaders
|
2608
|
-
};
|
2609
|
-
|
2610
|
-
requestDebug('method: %s, url: %s, headers: %j, timeouts: %d',
|
2611
|
-
options.method, url, options.headers, options.timeouts);
|
2612
|
-
|
2613
|
-
if (requester === client._request.fallback) {
|
2614
|
-
requestDebug('using fallback');
|
2615
|
-
}
|
2616
|
-
|
2617
|
-
// `requester` is any of this._request or this._request.fallback
|
2618
|
-
// thus it needs to be called using the client as context
|
2619
|
-
return requester.call(client, url, options).then(success, tryFallback);
|
2620
|
-
|
2621
|
-
function success(httpResponse) {
|
2622
|
-
// compute the status of the response,
|
2623
|
-
//
|
2624
|
-
// When in browser mode, using XDR or JSONP, we have no statusCode available
|
2625
|
-
// So we rely on our API response `status` property.
|
2626
|
-
// But `waitTask` can set a `status` property which is not the statusCode (it's the task status)
|
2627
|
-
// So we check if there's a `message` along `status` and it means it's an error
|
2628
|
-
//
|
2629
|
-
// That's the only case where we have a response.status that's not the http statusCode
|
2630
|
-
var status = httpResponse && httpResponse.body && httpResponse.body.message && httpResponse.body.status ||
|
2631
|
-
|
2632
|
-
// this is important to check the request statusCode AFTER the body eventual
|
2633
|
-
// statusCode because some implementations (jQuery XDomainRequest transport) may
|
2634
|
-
// send statusCode 200 while we had an error
|
2635
|
-
httpResponse.statusCode ||
|
2636
|
-
|
2637
|
-
// When in browser mode, using XDR or JSONP
|
2638
|
-
// we default to success when no error (no response.status && response.message)
|
2639
|
-
// If there was a JSON.parse() error then body is null and it fails
|
2640
|
-
httpResponse && httpResponse.body && 200;
|
2641
|
-
|
2642
|
-
requestDebug('received response: statusCode: %s, computed statusCode: %d, headers: %j',
|
2643
|
-
httpResponse.statusCode, status, httpResponse.headers);
|
2644
|
-
|
2645
|
-
var httpResponseOk = Math.floor(status / 100) === 2;
|
2646
|
-
|
2647
|
-
var endTime = new Date();
|
2648
|
-
debugData.push({
|
2649
|
-
currentHost: currentHost,
|
2650
|
-
headers: removeCredentials(headers),
|
2651
|
-
content: body || null,
|
2652
|
-
contentLength: body !== undefined ? body.length : null,
|
2653
|
-
method: reqOpts.method,
|
2654
|
-
timeouts: reqOpts.timeouts,
|
2655
|
-
url: reqOpts.url,
|
2656
|
-
startTime: startTime,
|
2657
|
-
endTime: endTime,
|
2658
|
-
duration: endTime - startTime,
|
2659
|
-
statusCode: status
|
2660
|
-
});
|
2661
|
-
|
2662
|
-
if (httpResponseOk) {
|
2663
|
-
if (client._useCache && !client._useRequestCache && cache) {
|
2664
|
-
cache[cacheID] = httpResponse.responseText;
|
2665
|
-
}
|
2666
|
-
|
2667
|
-
return {
|
2668
|
-
responseText: httpResponse.responseText,
|
2669
|
-
body: httpResponse.body
|
2670
|
-
};
|
2671
|
-
}
|
2672
|
-
|
2673
|
-
var shouldRetry = Math.floor(status / 100) !== 4;
|
2674
|
-
|
2675
|
-
if (shouldRetry) {
|
2676
|
-
tries += 1;
|
2677
|
-
return retryRequest();
|
2678
|
-
}
|
2679
|
-
|
2680
|
-
requestDebug('unrecoverable error');
|
2681
|
-
|
2682
|
-
// no success and no retry => fail
|
2683
|
-
var unrecoverableError = new errors.AlgoliaSearchError(
|
2684
|
-
httpResponse.body && httpResponse.body.message, {debugData: debugData, statusCode: status}
|
2685
|
-
);
|
2686
|
-
|
2687
|
-
return client._promise.reject(unrecoverableError);
|
2688
|
-
}
|
2689
|
-
|
2690
|
-
function tryFallback(err) {
|
2691
|
-
// error cases:
|
2692
|
-
// While not in fallback mode:
|
2693
|
-
// - CORS not supported
|
2694
|
-
// - network error
|
2695
|
-
// While in fallback mode:
|
2696
|
-
// - timeout
|
2697
|
-
// - network error
|
2698
|
-
// - badly formatted JSONP (script loaded, did not call our callback)
|
2699
|
-
// In both cases:
|
2700
|
-
// - uncaught exception occurs (TypeError)
|
2701
|
-
requestDebug('error: %s, stack: %s', err.message, err.stack);
|
2702
|
-
|
2703
|
-
var endTime = new Date();
|
2704
|
-
debugData.push({
|
2705
|
-
currentHost: currentHost,
|
2706
|
-
headers: removeCredentials(headers),
|
2707
|
-
content: body || null,
|
2708
|
-
contentLength: body !== undefined ? body.length : null,
|
2709
|
-
method: reqOpts.method,
|
2710
|
-
timeouts: reqOpts.timeouts,
|
2711
|
-
url: reqOpts.url,
|
2712
|
-
startTime: startTime,
|
2713
|
-
endTime: endTime,
|
2714
|
-
duration: endTime - startTime
|
2715
|
-
});
|
2716
|
-
|
2717
|
-
if (!(err instanceof errors.AlgoliaSearchError)) {
|
2718
|
-
err = new errors.Unknown(err && err.message, err);
|
2719
|
-
}
|
2720
|
-
|
2721
|
-
tries += 1;
|
2722
|
-
|
2723
|
-
// stop the request implementation when:
|
2724
|
-
if (
|
2725
|
-
// we did not generate this error,
|
2726
|
-
// it comes from a throw in some other piece of code
|
2727
|
-
err instanceof errors.Unknown ||
|
2728
|
-
|
2729
|
-
// server sent unparsable JSON
|
2730
|
-
err instanceof errors.UnparsableJSON ||
|
2731
|
-
|
2732
|
-
// max tries and already using fallback or no fallback
|
2733
|
-
tries >= client.hosts[initialOpts.hostType].length &&
|
2734
|
-
(usingFallback || !hasFallback)) {
|
2735
|
-
// stop request implementation for this command
|
2736
|
-
err.debugData = debugData;
|
2737
|
-
return client._promise.reject(err);
|
2738
|
-
}
|
2739
|
-
|
2740
|
-
// When a timeout occurred, retry by raising timeout
|
2741
|
-
if (err instanceof errors.RequestTimeout) {
|
2742
|
-
return retryRequestWithHigherTimeout();
|
2743
|
-
}
|
2744
|
-
|
2745
|
-
return retryRequest();
|
2746
|
-
}
|
2747
|
-
|
2748
|
-
function retryRequest() {
|
2749
|
-
requestDebug('retrying request');
|
2750
|
-
client._incrementHostIndex(initialOpts.hostType);
|
2751
|
-
return doRequest(requester, reqOpts);
|
2752
|
-
}
|
2753
|
-
|
2754
|
-
function retryRequestWithHigherTimeout() {
|
2755
|
-
requestDebug('retrying request with higher timeout');
|
2756
|
-
client._incrementHostIndex(initialOpts.hostType);
|
2757
|
-
client._incrementTimeoutMultipler();
|
2758
|
-
reqOpts.timeouts = client._getTimeoutsForRequest(initialOpts.hostType);
|
2759
|
-
return doRequest(requester, reqOpts);
|
2760
|
-
}
|
2761
|
-
}
|
2762
|
-
|
2763
|
-
function isCacheValidWithCurrentID(
|
2764
|
-
useRequestCache,
|
2765
|
-
currentCache,
|
2766
|
-
currentCacheID
|
2767
|
-
) {
|
2768
|
-
return (
|
2769
|
-
client._useCache &&
|
2770
|
-
useRequestCache &&
|
2771
|
-
currentCache &&
|
2772
|
-
currentCache[currentCacheID] !== undefined
|
2773
|
-
);
|
2774
|
-
}
|
2775
|
-
|
2776
|
-
|
2777
|
-
function interopCallbackReturn(request, callback) {
|
2778
|
-
if (isCacheValidWithCurrentID(client._useRequestCache, cache, cacheID)) {
|
2779
|
-
request.catch(function() {
|
2780
|
-
// Release the cache on error
|
2781
|
-
delete cache[cacheID];
|
2782
|
-
});
|
2783
|
-
}
|
2784
|
-
|
2785
|
-
if (typeof initialOpts.callback === 'function') {
|
2786
|
-
// either we have a callback
|
2787
|
-
request.then(function okCb(content) {
|
2788
|
-
exitPromise(function() {
|
2789
|
-
initialOpts.callback(null, callback(content));
|
2790
|
-
}, client._setTimeout || setTimeout);
|
2791
|
-
}, function nookCb(err) {
|
2792
|
-
exitPromise(function() {
|
2793
|
-
initialOpts.callback(err);
|
2794
|
-
}, client._setTimeout || setTimeout);
|
2795
|
-
});
|
2796
|
-
} else {
|
2797
|
-
// either we are using promises
|
2798
|
-
return request.then(callback);
|
2799
|
-
}
|
2800
|
-
}
|
2801
|
-
|
2802
|
-
if (client._useCache && client._useRequestCache) {
|
2803
|
-
cacheID = initialOpts.url;
|
2804
|
-
}
|
2805
|
-
|
2806
|
-
// as we sometime use POST requests to pass parameters (like query='aa'),
|
2807
|
-
// the cacheID must also include the body to be different between calls
|
2808
|
-
if (client._useCache && client._useRequestCache && body) {
|
2809
|
-
cacheID += '_body_' + body;
|
2810
|
-
}
|
2811
|
-
|
2812
|
-
if (isCacheValidWithCurrentID(client._useRequestCache, cache, cacheID)) {
|
2813
|
-
requestDebug('serving request from cache');
|
2814
|
-
|
2815
|
-
var maybePromiseForCache = cache[cacheID];
|
2816
|
-
|
2817
|
-
// In case the cache is warmup with value that is not a promise
|
2818
|
-
var promiseForCache = typeof maybePromiseForCache.then !== 'function'
|
2819
|
-
? client._promise.resolve({responseText: maybePromiseForCache})
|
2820
|
-
: maybePromiseForCache;
|
2821
|
-
|
2822
|
-
return interopCallbackReturn(promiseForCache, function(content) {
|
2823
|
-
// In case of the cache request, return the original value
|
2824
|
-
return JSON.parse(content.responseText);
|
2825
|
-
});
|
2826
|
-
}
|
2827
|
-
|
2828
|
-
var request = doRequest(
|
2829
|
-
client._request, {
|
2830
|
-
url: initialOpts.url,
|
2831
|
-
method: initialOpts.method,
|
2832
|
-
body: body,
|
2833
|
-
jsonBody: initialOpts.body,
|
2834
|
-
timeouts: client._getTimeoutsForRequest(initialOpts.hostType),
|
2835
|
-
forceAuthHeaders: initialOpts.forceAuthHeaders
|
2836
|
-
}
|
2837
|
-
);
|
2838
|
-
|
2839
|
-
if (client._useCache && client._useRequestCache && cache) {
|
2840
|
-
cache[cacheID] = request;
|
2841
|
-
}
|
2842
|
-
|
2843
|
-
return interopCallbackReturn(request, function(content) {
|
2844
|
-
// In case of the first request, return the JSON value
|
2845
|
-
return content.body;
|
2846
|
-
});
|
2847
|
-
};
|
2848
|
-
|
2849
|
-
/*
|
2850
|
-
* Transform search param object in query string
|
2851
|
-
* @param {object} args arguments to add to the current query string
|
2852
|
-
* @param {string} params current query string
|
2853
|
-
* @return {string} the final query string
|
2854
|
-
*/
|
2855
|
-
AlgoliaSearchCore.prototype._getSearchParams = function(args, params) {
|
2856
|
-
if (args === undefined || args === null) {
|
2857
|
-
return params;
|
2858
|
-
}
|
2859
|
-
for (var key in args) {
|
2860
|
-
if (key !== null && args[key] !== undefined && args.hasOwnProperty(key)) {
|
2861
|
-
params += params === '' ? '' : '&';
|
2862
|
-
params += key + '=' + encodeURIComponent(Object.prototype.toString.call(args[key]) === '[object Array]' ? safeJSONStringify(args[key]) : args[key]);
|
2863
|
-
}
|
2864
|
-
}
|
2865
|
-
return params;
|
2866
|
-
};
|
2867
|
-
|
2868
|
-
/**
|
2869
|
-
* Compute the headers for a request
|
2870
|
-
*
|
2871
|
-
* @param [string] options.additionalUA semi-colon separated string with other user agents to add
|
2872
|
-
* @param [boolean=true] options.withApiKey Send the api key as a header
|
2873
|
-
* @param [Object] options.headers Extra headers to send
|
2874
|
-
*/
|
2875
|
-
AlgoliaSearchCore.prototype._computeRequestHeaders = function(options) {
|
2876
|
-
var forEach = require(4);
|
2877
|
-
|
2878
|
-
var ua = options.additionalUA ?
|
2879
|
-
this._ua + '; ' + options.additionalUA :
|
2880
|
-
this._ua;
|
2881
|
-
|
2882
|
-
var requestHeaders = {
|
2883
|
-
'x-algolia-agent': ua,
|
2884
|
-
'x-algolia-application-id': this.applicationID
|
2885
|
-
};
|
2886
|
-
|
2887
|
-
// browser will inline headers in the url, node.js will use http headers
|
2888
|
-
// but in some situations, the API KEY will be too long (big secured API keys)
|
2889
|
-
// so if the request is a POST and the KEY is very long, we will be asked to not put
|
2890
|
-
// it into headers but in the JSON body
|
2891
|
-
if (options.withApiKey !== false) {
|
2892
|
-
requestHeaders['x-algolia-api-key'] = this.apiKey;
|
2893
|
-
}
|
2894
|
-
|
2895
|
-
if (this.userToken) {
|
2896
|
-
requestHeaders['x-algolia-usertoken'] = this.userToken;
|
2897
|
-
}
|
2898
|
-
|
2899
|
-
if (this.securityTags) {
|
2900
|
-
requestHeaders['x-algolia-tagfilters'] = this.securityTags;
|
2901
|
-
}
|
2902
|
-
|
2903
|
-
forEach(this.extraHeaders, function addToRequestHeaders(value, key) {
|
2904
|
-
requestHeaders[key] = value;
|
2905
|
-
});
|
2906
|
-
|
2907
|
-
if (options.headers) {
|
2908
|
-
forEach(options.headers, function addToRequestHeaders(value, key) {
|
2909
|
-
requestHeaders[key] = value;
|
2910
|
-
});
|
2911
|
-
}
|
2912
|
-
|
2913
|
-
return requestHeaders;
|
2914
|
-
};
|
2915
|
-
|
2916
|
-
/**
|
2917
|
-
* Search through multiple indices at the same time
|
2918
|
-
* @param {Object[]} queries An array of queries you want to run.
|
2919
|
-
* @param {string} queries[].indexName The index name you want to target
|
2920
|
-
* @param {string} [queries[].query] The query to issue on this index. Can also be passed into `params`
|
2921
|
-
* @param {Object} queries[].params Any search param like hitsPerPage, ..
|
2922
|
-
* @param {Function} callback Callback to be called
|
2923
|
-
* @return {Promise|undefined} Returns a promise if no callback given
|
2924
|
-
*/
|
2925
|
-
AlgoliaSearchCore.prototype.search = function(queries, opts, callback) {
|
2926
|
-
var isArray = require(7);
|
2927
|
-
var map = require(27);
|
2928
|
-
|
2929
|
-
var usage = 'Usage: client.search(arrayOfQueries[, callback])';
|
2930
|
-
|
2931
|
-
if (!isArray(queries)) {
|
2932
|
-
throw new Error(usage);
|
2933
|
-
}
|
2934
|
-
|
2935
|
-
if (typeof opts === 'function') {
|
2936
|
-
callback = opts;
|
2937
|
-
opts = {};
|
2938
|
-
} else if (opts === undefined) {
|
2939
|
-
opts = {};
|
2940
|
-
}
|
2941
|
-
|
2942
|
-
var client = this;
|
2943
|
-
|
2944
|
-
var postObj = {
|
2945
|
-
requests: map(queries, function prepareRequest(query) {
|
2946
|
-
var params = '';
|
2947
|
-
|
2948
|
-
// allow query.query
|
2949
|
-
// so we are mimicing the index.search(query, params) method
|
2950
|
-
// {indexName:, query:, params:}
|
2951
|
-
if (query.query !== undefined) {
|
2952
|
-
params += 'query=' + encodeURIComponent(query.query);
|
2953
|
-
}
|
2954
|
-
|
2955
|
-
return {
|
2956
|
-
indexName: query.indexName,
|
2957
|
-
params: client._getSearchParams(query.params, params)
|
2958
|
-
};
|
2959
|
-
})
|
2960
|
-
};
|
2961
|
-
|
2962
|
-
var JSONPParams = map(postObj.requests, function prepareJSONPParams(request, requestId) {
|
2963
|
-
return requestId + '=' +
|
2964
|
-
encodeURIComponent(
|
2965
|
-
'/1/indexes/' + encodeURIComponent(request.indexName) + '?' +
|
2966
|
-
request.params
|
2967
|
-
);
|
2968
|
-
}).join('&');
|
2969
|
-
|
2970
|
-
var url = '/1/indexes/*/queries';
|
2971
|
-
|
2972
|
-
if (opts.strategy !== undefined) {
|
2973
|
-
postObj.strategy = opts.strategy;
|
2974
|
-
}
|
2975
|
-
|
2976
|
-
return this._jsonRequest({
|
2977
|
-
cache: this.cache,
|
2978
|
-
method: 'POST',
|
2979
|
-
url: url,
|
2980
|
-
body: postObj,
|
2981
|
-
hostType: 'read',
|
2982
|
-
fallback: {
|
2983
|
-
method: 'GET',
|
2984
|
-
url: '/1/indexes/*',
|
2985
|
-
body: {
|
2986
|
-
params: JSONPParams
|
2987
|
-
}
|
2988
|
-
},
|
2989
|
-
callback: callback
|
2990
|
-
});
|
2991
|
-
};
|
2992
|
-
|
2993
|
-
/**
|
2994
|
-
* Search for facet values
|
2995
|
-
* https://www.algolia.com/doc/rest-api/search#search-for-facet-values
|
2996
|
-
* This is the top-level API for SFFV.
|
2997
|
-
*
|
2998
|
-
* @param {object[]} queries An array of queries to run.
|
2999
|
-
* @param {string} queries[].indexName Index name, name of the index to search.
|
3000
|
-
* @param {object} queries[].params Query parameters.
|
3001
|
-
* @param {string} queries[].params.facetName Facet name, name of the attribute to search for values in.
|
3002
|
-
* Must be declared as a facet
|
3003
|
-
* @param {string} queries[].params.facetQuery Query for the facet search
|
3004
|
-
* @param {string} [queries[].params.*] Any search parameter of Algolia,
|
3005
|
-
* see https://www.algolia.com/doc/api-client/javascript/search#search-parameters
|
3006
|
-
* Pagination is not supported. The page and hitsPerPage parameters will be ignored.
|
3007
|
-
*/
|
3008
|
-
AlgoliaSearchCore.prototype.searchForFacetValues = function(queries) {
|
3009
|
-
var isArray = require(7);
|
3010
|
-
var map = require(27);
|
3011
|
-
|
3012
|
-
var usage = 'Usage: client.searchForFacetValues([{indexName, params: {facetName, facetQuery, ...params}}, ...queries])'; // eslint-disable-line max-len
|
3013
|
-
|
3014
|
-
if (!isArray(queries)) {
|
3015
|
-
throw new Error(usage);
|
3016
|
-
}
|
3017
|
-
|
3018
|
-
var client = this;
|
3019
|
-
|
3020
|
-
return client._promise.all(map(queries, function performQuery(query) {
|
3021
|
-
if (
|
3022
|
-
!query ||
|
3023
|
-
query.indexName === undefined ||
|
3024
|
-
query.params.facetName === undefined ||
|
3025
|
-
query.params.facetQuery === undefined
|
3026
|
-
) {
|
3027
|
-
throw new Error(usage);
|
3028
|
-
}
|
3029
|
-
|
3030
|
-
var clone = require(22);
|
3031
|
-
var omit = require(29);
|
3032
|
-
|
3033
|
-
var indexName = query.indexName;
|
3034
|
-
var params = query.params;
|
3035
|
-
|
3036
|
-
var facetName = params.facetName;
|
3037
|
-
var filteredParams = omit(clone(params), function(keyName) {
|
3038
|
-
return keyName === 'facetName';
|
3039
|
-
});
|
3040
|
-
var searchParameters = client._getSearchParams(filteredParams, '');
|
3041
|
-
|
3042
|
-
return client._jsonRequest({
|
3043
|
-
cache: client.cache,
|
3044
|
-
method: 'POST',
|
3045
|
-
url:
|
3046
|
-
'/1/indexes/' +
|
3047
|
-
encodeURIComponent(indexName) +
|
3048
|
-
'/facets/' +
|
3049
|
-
encodeURIComponent(facetName) +
|
3050
|
-
'/query',
|
3051
|
-
hostType: 'read',
|
3052
|
-
body: {params: searchParameters}
|
3053
|
-
});
|
3054
|
-
}));
|
3055
|
-
};
|
3056
|
-
|
3057
|
-
/**
|
3058
|
-
* Set the extra security tagFilters header
|
3059
|
-
* @param {string|array} tags The list of tags defining the current security filters
|
3060
|
-
*/
|
3061
|
-
AlgoliaSearchCore.prototype.setSecurityTags = function(tags) {
|
3062
|
-
if (Object.prototype.toString.call(tags) === '[object Array]') {
|
3063
|
-
var strTags = [];
|
3064
|
-
for (var i = 0; i < tags.length; ++i) {
|
3065
|
-
if (Object.prototype.toString.call(tags[i]) === '[object Array]') {
|
3066
|
-
var oredTags = [];
|
3067
|
-
for (var j = 0; j < tags[i].length; ++j) {
|
3068
|
-
oredTags.push(tags[i][j]);
|
3069
|
-
}
|
3070
|
-
strTags.push('(' + oredTags.join(',') + ')');
|
3071
|
-
} else {
|
3072
|
-
strTags.push(tags[i]);
|
3073
|
-
}
|
3074
|
-
}
|
3075
|
-
tags = strTags.join(',');
|
3076
|
-
}
|
3077
|
-
|
3078
|
-
this.securityTags = tags;
|
3079
|
-
};
|
3080
|
-
|
3081
|
-
/**
|
3082
|
-
* Set the extra user token header
|
3083
|
-
* @param {string} userToken The token identifying a uniq user (used to apply rate limits)
|
3084
|
-
*/
|
3085
|
-
AlgoliaSearchCore.prototype.setUserToken = function(userToken) {
|
3086
|
-
this.userToken = userToken;
|
3087
|
-
};
|
3088
|
-
|
3089
|
-
/**
|
3090
|
-
* Clear all queries in client's cache
|
3091
|
-
* @return undefined
|
3092
|
-
*/
|
3093
|
-
AlgoliaSearchCore.prototype.clearCache = function() {
|
3094
|
-
this.cache = {};
|
3095
|
-
};
|
3096
|
-
|
3097
|
-
/**
|
3098
|
-
* Set the number of milliseconds a request can take before automatically being terminated.
|
3099
|
-
* @deprecated
|
3100
|
-
* @param {Number} milliseconds
|
3101
|
-
*/
|
3102
|
-
AlgoliaSearchCore.prototype.setRequestTimeout = function(milliseconds) {
|
3103
|
-
if (milliseconds) {
|
3104
|
-
this._timeouts.connect = this._timeouts.read = this._timeouts.write = milliseconds;
|
3105
|
-
}
|
3106
|
-
};
|
3107
|
-
|
3108
|
-
/**
|
3109
|
-
* Set the three different (connect, read, write) timeouts to be used when requesting
|
3110
|
-
* @param {Object} timeouts
|
3111
|
-
*/
|
3112
|
-
AlgoliaSearchCore.prototype.setTimeouts = function(timeouts) {
|
3113
|
-
this._timeouts = timeouts;
|
3114
|
-
};
|
3115
|
-
|
3116
|
-
/**
|
3117
|
-
* Get the three different (connect, read, write) timeouts to be used when requesting
|
3118
|
-
* @param {Object} timeouts
|
3119
|
-
*/
|
3120
|
-
AlgoliaSearchCore.prototype.getTimeouts = function() {
|
3121
|
-
return this._timeouts;
|
3122
|
-
};
|
3123
|
-
|
3124
|
-
AlgoliaSearchCore.prototype._getAppIdData = function() {
|
3125
|
-
var data = store.get(this.applicationID);
|
3126
|
-
if (data !== null) this._cacheAppIdData(data);
|
3127
|
-
return data;
|
3128
|
-
};
|
3129
|
-
|
3130
|
-
AlgoliaSearchCore.prototype._setAppIdData = function(data) {
|
3131
|
-
data.lastChange = (new Date()).getTime();
|
3132
|
-
this._cacheAppIdData(data);
|
3133
|
-
return store.set(this.applicationID, data);
|
3134
|
-
};
|
3135
|
-
|
3136
|
-
AlgoliaSearchCore.prototype._checkAppIdData = function() {
|
3137
|
-
var data = this._getAppIdData();
|
3138
|
-
var now = (new Date()).getTime();
|
3139
|
-
if (data === null || now - data.lastChange > RESET_APP_DATA_TIMER) {
|
3140
|
-
return this._resetInitialAppIdData(data);
|
3141
|
-
}
|
3142
|
-
|
3143
|
-
return data;
|
3144
|
-
};
|
3145
|
-
|
3146
|
-
AlgoliaSearchCore.prototype._resetInitialAppIdData = function(data) {
|
3147
|
-
var newData = data || {};
|
3148
|
-
newData.hostIndexes = {read: 0, write: 0};
|
3149
|
-
newData.timeoutMultiplier = 1;
|
3150
|
-
newData.shuffleResult = newData.shuffleResult || shuffle([1, 2, 3]);
|
3151
|
-
return this._setAppIdData(newData);
|
3152
|
-
};
|
3153
|
-
|
3154
|
-
AlgoliaSearchCore.prototype._cacheAppIdData = function(data) {
|
3155
|
-
this._hostIndexes = data.hostIndexes;
|
3156
|
-
this._timeoutMultiplier = data.timeoutMultiplier;
|
3157
|
-
this._shuffleResult = data.shuffleResult;
|
3158
|
-
};
|
3159
|
-
|
3160
|
-
AlgoliaSearchCore.prototype._partialAppIdDataUpdate = function(newData) {
|
3161
|
-
var foreach = require(4);
|
3162
|
-
var currentData = this._getAppIdData();
|
3163
|
-
foreach(newData, function(value, key) {
|
3164
|
-
currentData[key] = value;
|
3165
|
-
});
|
3166
|
-
|
3167
|
-
return this._setAppIdData(currentData);
|
3168
|
-
};
|
3169
|
-
|
3170
|
-
AlgoliaSearchCore.prototype._getHostByType = function(hostType) {
|
3171
|
-
return this.hosts[hostType][this._getHostIndexByType(hostType)];
|
3172
|
-
};
|
3173
|
-
|
3174
|
-
AlgoliaSearchCore.prototype._getTimeoutMultiplier = function() {
|
3175
|
-
return this._timeoutMultiplier;
|
3176
|
-
};
|
3177
|
-
|
3178
|
-
AlgoliaSearchCore.prototype._getHostIndexByType = function(hostType) {
|
3179
|
-
return this._hostIndexes[hostType];
|
3180
|
-
};
|
3181
|
-
|
3182
|
-
AlgoliaSearchCore.prototype._setHostIndexByType = function(hostIndex, hostType) {
|
3183
|
-
var clone = require(22);
|
3184
|
-
var newHostIndexes = clone(this._hostIndexes);
|
3185
|
-
newHostIndexes[hostType] = hostIndex;
|
3186
|
-
this._partialAppIdDataUpdate({hostIndexes: newHostIndexes});
|
3187
|
-
return hostIndex;
|
3188
|
-
};
|
3189
|
-
|
3190
|
-
AlgoliaSearchCore.prototype._incrementHostIndex = function(hostType) {
|
3191
|
-
return this._setHostIndexByType(
|
3192
|
-
(this._getHostIndexByType(hostType) + 1) % this.hosts[hostType].length, hostType
|
3193
|
-
);
|
3194
|
-
};
|
3195
|
-
|
3196
|
-
AlgoliaSearchCore.prototype._incrementTimeoutMultipler = function() {
|
3197
|
-
var timeoutMultiplier = Math.max(this._timeoutMultiplier + 1, 4);
|
3198
|
-
return this._partialAppIdDataUpdate({timeoutMultiplier: timeoutMultiplier});
|
3199
|
-
};
|
3200
|
-
|
3201
|
-
AlgoliaSearchCore.prototype._getTimeoutsForRequest = function(hostType) {
|
3202
|
-
return {
|
3203
|
-
connect: this._timeouts.connect * this._timeoutMultiplier,
|
3204
|
-
complete: this._timeouts[hostType] * this._timeoutMultiplier
|
3205
|
-
};
|
3206
|
-
};
|
3207
|
-
|
3208
|
-
function prepareHost(protocol) {
|
3209
|
-
return function prepare(host) {
|
3210
|
-
return protocol + '//' + host.toLowerCase();
|
3211
|
-
};
|
3212
|
-
}
|
3213
|
-
|
3214
|
-
// Prototype.js < 1.7, a widely used library, defines a weird
|
3215
|
-
// Array.prototype.toJSON function that will fail to stringify our content
|
3216
|
-
// appropriately
|
3217
|
-
// refs:
|
3218
|
-
// - https://groups.google.com/forum/#!topic/prototype-core/E-SAVvV_V9Q
|
3219
|
-
// - https://github.com/sstephenson/prototype/commit/038a2985a70593c1a86c230fadbdfe2e4898a48c
|
3220
|
-
// - http://stackoverflow.com/a/3148441/147079
|
3221
|
-
function safeJSONStringify(obj) {
|
3222
|
-
/* eslint no-extend-native:0 */
|
3223
|
-
|
3224
|
-
if (Array.prototype.toJSON === undefined) {
|
3225
|
-
return JSON.stringify(obj);
|
3226
|
-
}
|
3227
|
-
|
3228
|
-
var toJSON = Array.prototype.toJSON;
|
3229
|
-
delete Array.prototype.toJSON;
|
3230
|
-
var out = JSON.stringify(obj);
|
3231
|
-
Array.prototype.toJSON = toJSON;
|
3232
|
-
|
3233
|
-
return out;
|
3234
|
-
}
|
3235
|
-
|
3236
|
-
function shuffle(array) {
|
3237
|
-
var currentIndex = array.length;
|
3238
|
-
var temporaryValue;
|
3239
|
-
var randomIndex;
|
3240
|
-
|
3241
|
-
// While there remain elements to shuffle...
|
3242
|
-
while (currentIndex !== 0) {
|
3243
|
-
// Pick a remaining element...
|
3244
|
-
randomIndex = Math.floor(Math.random() * currentIndex);
|
3245
|
-
currentIndex -= 1;
|
3246
|
-
|
3247
|
-
// And swap it with the current element.
|
3248
|
-
temporaryValue = array[currentIndex];
|
3249
|
-
array[currentIndex] = array[randomIndex];
|
3250
|
-
array[randomIndex] = temporaryValue;
|
3251
|
-
}
|
3252
|
-
|
3253
|
-
return array;
|
3254
|
-
}
|
3255
|
-
|
3256
|
-
function removeCredentials(headers) {
|
3257
|
-
var newHeaders = {};
|
3258
|
-
|
3259
|
-
for (var headerName in headers) {
|
3260
|
-
if (Object.prototype.hasOwnProperty.call(headers, headerName)) {
|
3261
|
-
var value;
|
3262
|
-
|
3263
|
-
if (headerName === 'x-algolia-api-key' || headerName === 'x-algolia-application-id') {
|
3264
|
-
value = '**hidden for security purposes**';
|
3265
|
-
} else {
|
3266
|
-
value = headers[headerName];
|
3267
|
-
}
|
3268
|
-
|
3269
|
-
newHeaders[headerName] = value;
|
3270
|
-
}
|
3271
|
-
}
|
3272
|
-
|
3273
|
-
return newHeaders;
|
3274
|
-
}
|
3275
|
-
|
3276
|
-
}).call(this,require(11))
|
3277
|
-
},{"1":1,"11":11,"16":16,"22":22,"25":25,"26":26,"27":27,"29":29,"31":31,"4":4,"7":7}],16:[function(require,module,exports){
|
3278
|
-
var buildSearchMethod = require(21);
|
3279
|
-
var deprecate = require(23);
|
3280
|
-
var deprecatedMessage = require(24);
|
3281
|
-
|
3282
|
-
module.exports = IndexCore;
|
3283
|
-
|
3284
|
-
/*
|
3285
|
-
* Index class constructor.
|
3286
|
-
* You should not use this method directly but use initIndex() function
|
3287
|
-
*/
|
3288
|
-
function IndexCore(algoliasearch, indexName) {
|
3289
|
-
this.indexName = indexName;
|
3290
|
-
this.as = algoliasearch;
|
3291
|
-
this.typeAheadArgs = null;
|
3292
|
-
this.typeAheadValueOption = null;
|
3293
|
-
|
3294
|
-
// make sure every index instance has it's own cache
|
3295
|
-
this.cache = {};
|
3296
|
-
}
|
3297
|
-
|
3298
|
-
/*
|
3299
|
-
* Clear all queries in cache
|
3300
|
-
*/
|
3301
|
-
IndexCore.prototype.clearCache = function() {
|
3302
|
-
this.cache = {};
|
3303
|
-
};
|
3304
|
-
|
3305
|
-
/*
|
3306
|
-
* Search inside the index using XMLHttpRequest request (Using a POST query to
|
3307
|
-
* minimize number of OPTIONS queries: Cross-Origin Resource Sharing).
|
3308
|
-
*
|
3309
|
-
* @param {string} [query] the full text query
|
3310
|
-
* @param {object} [args] (optional) if set, contains an object with query parameters:
|
3311
|
-
* - page: (integer) Pagination parameter used to select the page to retrieve.
|
3312
|
-
* Page is zero-based and defaults to 0. Thus,
|
3313
|
-
* to retrieve the 10th page you need to set page=9
|
3314
|
-
* - hitsPerPage: (integer) Pagination parameter used to select the number of hits per page. Defaults to 20.
|
3315
|
-
* - attributesToRetrieve: a string that contains the list of object attributes
|
3316
|
-
* you want to retrieve (let you minimize the answer size).
|
3317
|
-
* Attributes are separated with a comma (for example "name,address").
|
3318
|
-
* You can also use an array (for example ["name","address"]).
|
3319
|
-
* By default, all attributes are retrieved. You can also use '*' to retrieve all
|
3320
|
-
* values when an attributesToRetrieve setting is specified for your index.
|
3321
|
-
* - attributesToHighlight: a string that contains the list of attributes you
|
3322
|
-
* want to highlight according to the query.
|
3323
|
-
* Attributes are separated by a comma. You can also use an array (for example ["name","address"]).
|
3324
|
-
* If an attribute has no match for the query, the raw value is returned.
|
3325
|
-
* By default all indexed text attributes are highlighted.
|
3326
|
-
* You can use `*` if you want to highlight all textual attributes.
|
3327
|
-
* Numerical attributes are not highlighted.
|
3328
|
-
* A matchLevel is returned for each highlighted attribute and can contain:
|
3329
|
-
* - full: if all the query terms were found in the attribute,
|
3330
|
-
* - partial: if only some of the query terms were found,
|
3331
|
-
* - none: if none of the query terms were found.
|
3332
|
-
* - attributesToSnippet: a string that contains the list of attributes to snippet alongside
|
3333
|
-
* the number of words to return (syntax is `attributeName:nbWords`).
|
3334
|
-
* Attributes are separated by a comma (Example: attributesToSnippet=name:10,content:10).
|
3335
|
-
* You can also use an array (Example: attributesToSnippet: ['name:10','content:10']).
|
3336
|
-
* By default no snippet is computed.
|
3337
|
-
* - minWordSizefor1Typo: the minimum number of characters in a query word to accept one typo in this word.
|
3338
|
-
* Defaults to 3.
|
3339
|
-
* - minWordSizefor2Typos: the minimum number of characters in a query word
|
3340
|
-
* to accept two typos in this word. Defaults to 7.
|
3341
|
-
* - getRankingInfo: if set to 1, the result hits will contain ranking
|
3342
|
-
* information in _rankingInfo attribute.
|
3343
|
-
* - aroundLatLng: search for entries around a given
|
3344
|
-
* latitude/longitude (specified as two floats separated by a comma).
|
3345
|
-
* For example aroundLatLng=47.316669,5.016670).
|
3346
|
-
* You can specify the maximum distance in meters with the aroundRadius parameter (in meters)
|
3347
|
-
* and the precision for ranking with aroundPrecision
|
3348
|
-
* (for example if you set aroundPrecision=100, two objects that are distant of
|
3349
|
-
* less than 100m will be considered as identical for "geo" ranking parameter).
|
3350
|
-
* At indexing, you should specify geoloc of an object with the _geoloc attribute
|
3351
|
-
* (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}})
|
3352
|
-
* - insideBoundingBox: search entries inside a given area defined by the two extreme points
|
3353
|
-
* of a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat,p2Lng).
|
3354
|
-
* For example insideBoundingBox=47.3165,4.9665,47.3424,5.0201).
|
3355
|
-
* At indexing, you should specify geoloc of an object with the _geoloc attribute
|
3356
|
-
* (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}})
|
3357
|
-
* - numericFilters: a string that contains the list of numeric filters you want to
|
3358
|
-
* apply separated by a comma.
|
3359
|
-
* The syntax of one filter is `attributeName` followed by `operand` followed by `value`.
|
3360
|
-
* Supported operands are `<`, `<=`, `=`, `>` and `>=`.
|
3361
|
-
* You can have multiple conditions on one attribute like for example numericFilters=price>100,price<1000.
|
3362
|
-
* You can also use an array (for example numericFilters: ["price>100","price<1000"]).
|
3363
|
-
* - tagFilters: filter the query by a set of tags. You can AND tags by separating them by commas.
|
3364
|
-
* To OR tags, you must add parentheses. For example, tags=tag1,(tag2,tag3) means tag1 AND (tag2 OR tag3).
|
3365
|
-
* You can also use an array, for example tagFilters: ["tag1",["tag2","tag3"]]
|
3366
|
-
* means tag1 AND (tag2 OR tag3).
|
3367
|
-
* At indexing, tags should be added in the _tags** attribute
|
3368
|
-
* of objects (for example {"_tags":["tag1","tag2"]}).
|
3369
|
-
* - facetFilters: filter the query by a list of facets.
|
3370
|
-
* Facets are separated by commas and each facet is encoded as `attributeName:value`.
|
3371
|
-
* For example: `facetFilters=category:Book,author:John%20Doe`.
|
3372
|
-
* You can also use an array (for example `["category:Book","author:John%20Doe"]`).
|
3373
|
-
* - facets: List of object attributes that you want to use for faceting.
|
3374
|
-
* Comma separated list: `"category,author"` or array `['category','author']`
|
3375
|
-
* Only attributes that have been added in **attributesForFaceting** index setting
|
3376
|
-
* can be used in this parameter.
|
3377
|
-
* You can also use `*` to perform faceting on all attributes specified in **attributesForFaceting**.
|
3378
|
-
* - queryType: select how the query words are interpreted, it can be one of the following value:
|
3379
|
-
* - prefixAll: all query words are interpreted as prefixes,
|
3380
|
-
* - prefixLast: only the last word is interpreted as a prefix (default behavior),
|
3381
|
-
* - prefixNone: no query word is interpreted as a prefix. This option is not recommended.
|
3382
|
-
* - optionalWords: a string that contains the list of words that should
|
3383
|
-
* be considered as optional when found in the query.
|
3384
|
-
* Comma separated and array are accepted.
|
3385
|
-
* - distinct: If set to 1, enable the distinct feature (disabled by default)
|
3386
|
-
* if the attributeForDistinct index setting is set.
|
3387
|
-
* This feature is similar to the SQL "distinct" keyword: when enabled
|
3388
|
-
* in a query with the distinct=1 parameter,
|
3389
|
-
* all hits containing a duplicate value for the attributeForDistinct attribute are removed from results.
|
3390
|
-
* For example, if the chosen attribute is show_name and several hits have
|
3391
|
-
* the same value for show_name, then only the best
|
3392
|
-
* one is kept and others are removed.
|
3393
|
-
* - restrictSearchableAttributes: List of attributes you want to use for
|
3394
|
-
* textual search (must be a subset of the attributesToIndex index setting)
|
3395
|
-
* either comma separated or as an array
|
3396
|
-
* @param {function} [callback] the result callback called with two arguments:
|
3397
|
-
* error: null or Error('message'). If false, the content contains the error.
|
3398
|
-
* content: the server answer that contains the list of results.
|
3399
|
-
*/
|
3400
|
-
IndexCore.prototype.search = buildSearchMethod('query');
|
3401
|
-
|
3402
|
-
/*
|
3403
|
-
* -- BETA --
|
3404
|
-
* Search a record similar to the query inside the index using XMLHttpRequest request (Using a POST query to
|
3405
|
-
* minimize number of OPTIONS queries: Cross-Origin Resource Sharing).
|
3406
|
-
*
|
3407
|
-
* @param {string} [query] the similar query
|
3408
|
-
* @param {object} [args] (optional) if set, contains an object with query parameters.
|
3409
|
-
* All search parameters are supported (see search function), restrictSearchableAttributes and facetFilters
|
3410
|
-
* are the two most useful to restrict the similar results and get more relevant content
|
3411
|
-
*/
|
3412
|
-
IndexCore.prototype.similarSearch = deprecate(
|
3413
|
-
buildSearchMethod('similarQuery'),
|
3414
|
-
deprecatedMessage(
|
3415
|
-
'index.similarSearch(query[, callback])',
|
3416
|
-
'index.search({ similarQuery: query }[, callback])'
|
3417
|
-
)
|
3418
|
-
);
|
3419
|
-
|
3420
|
-
/*
|
3421
|
-
* Browse index content. The response content will have a `cursor` property that you can use
|
3422
|
-
* to browse subsequent pages for this query. Use `index.browseFrom(cursor)` when you want.
|
3423
|
-
*
|
3424
|
-
* @param {string} query - The full text query
|
3425
|
-
* @param {Object} [queryParameters] - Any search query parameter
|
3426
|
-
* @param {Function} [callback] - The result callback called with two arguments
|
3427
|
-
* error: null or Error('message')
|
3428
|
-
* content: the server answer with the browse result
|
3429
|
-
* @return {Promise|undefined} Returns a promise if no callback given
|
3430
|
-
* @example
|
3431
|
-
* index.browse('cool songs', {
|
3432
|
-
* tagFilters: 'public,comments',
|
3433
|
-
* hitsPerPage: 500
|
3434
|
-
* }, callback);
|
3435
|
-
* @see {@link https://www.algolia.com/doc/rest_api#Browse|Algolia REST API Documentation}
|
3436
|
-
*/
|
3437
|
-
IndexCore.prototype.browse = function(query, queryParameters, callback) {
|
3438
|
-
var merge = require(28);
|
3439
|
-
|
3440
|
-
var indexObj = this;
|
3441
|
-
|
3442
|
-
var page;
|
3443
|
-
var hitsPerPage;
|
3444
|
-
|
3445
|
-
// we check variadic calls that are not the one defined
|
3446
|
-
// .browse()/.browse(fn)
|
3447
|
-
// => page = 0
|
3448
|
-
if (arguments.length === 0 || arguments.length === 1 && typeof arguments[0] === 'function') {
|
3449
|
-
page = 0;
|
3450
|
-
callback = arguments[0];
|
3451
|
-
query = undefined;
|
3452
|
-
} else if (typeof arguments[0] === 'number') {
|
3453
|
-
// .browse(2)/.browse(2, 10)/.browse(2, fn)/.browse(2, 10, fn)
|
3454
|
-
page = arguments[0];
|
3455
|
-
if (typeof arguments[1] === 'number') {
|
3456
|
-
hitsPerPage = arguments[1];
|
3457
|
-
} else if (typeof arguments[1] === 'function') {
|
3458
|
-
callback = arguments[1];
|
3459
|
-
hitsPerPage = undefined;
|
3460
|
-
}
|
3461
|
-
query = undefined;
|
3462
|
-
queryParameters = undefined;
|
3463
|
-
} else if (typeof arguments[0] === 'object') {
|
3464
|
-
// .browse(queryParameters)/.browse(queryParameters, cb)
|
3465
|
-
if (typeof arguments[1] === 'function') {
|
3466
|
-
callback = arguments[1];
|
3467
|
-
}
|
3468
|
-
queryParameters = arguments[0];
|
3469
|
-
query = undefined;
|
3470
|
-
} else if (typeof arguments[0] === 'string' && typeof arguments[1] === 'function') {
|
3471
|
-
// .browse(query, cb)
|
3472
|
-
callback = arguments[1];
|
3473
|
-
queryParameters = undefined;
|
3474
|
-
}
|
3475
|
-
|
3476
|
-
// otherwise it's a .browse(query)/.browse(query, queryParameters)/.browse(query, queryParameters, cb)
|
3477
|
-
|
3478
|
-
// get search query parameters combining various possible calls
|
3479
|
-
// to .browse();
|
3480
|
-
queryParameters = merge({}, queryParameters || {}, {
|
3481
|
-
page: page,
|
3482
|
-
hitsPerPage: hitsPerPage,
|
3483
|
-
query: query
|
3484
|
-
});
|
3485
|
-
|
3486
|
-
var params = this.as._getSearchParams(queryParameters, '');
|
3487
|
-
|
3488
|
-
return this.as._jsonRequest({
|
3489
|
-
method: 'POST',
|
3490
|
-
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/browse',
|
3491
|
-
body: {params: params},
|
3492
|
-
hostType: 'read',
|
3493
|
-
callback: callback
|
3494
|
-
});
|
3495
|
-
};
|
3496
|
-
|
3497
|
-
/*
|
3498
|
-
* Continue browsing from a previous position (cursor), obtained via a call to `.browse()`.
|
3499
|
-
*
|
3500
|
-
* @param {string} query - The full text query
|
3501
|
-
* @param {Object} [queryParameters] - Any search query parameter
|
3502
|
-
* @param {Function} [callback] - The result callback called with two arguments
|
3503
|
-
* error: null or Error('message')
|
3504
|
-
* content: the server answer with the browse result
|
3505
|
-
* @return {Promise|undefined} Returns a promise if no callback given
|
3506
|
-
* @example
|
3507
|
-
* index.browseFrom('14lkfsakl32', callback);
|
3508
|
-
* @see {@link https://www.algolia.com/doc/rest_api#Browse|Algolia REST API Documentation}
|
3509
|
-
*/
|
3510
|
-
IndexCore.prototype.browseFrom = function(cursor, callback) {
|
3511
|
-
return this.as._jsonRequest({
|
3512
|
-
method: 'POST',
|
3513
|
-
url: '/1/indexes/' + encodeURIComponent(this.indexName) + '/browse',
|
3514
|
-
body: {cursor: cursor},
|
3515
|
-
hostType: 'read',
|
3516
|
-
callback: callback
|
3517
|
-
});
|
3518
|
-
};
|
3519
|
-
|
3520
|
-
/*
|
3521
|
-
* Search for facet values
|
3522
|
-
* https://www.algolia.com/doc/rest-api/search#search-for-facet-values
|
3523
|
-
*
|
3524
|
-
* @param {string} params.facetName Facet name, name of the attribute to search for values in.
|
3525
|
-
* Must be declared as a facet
|
3526
|
-
* @param {string} params.facetQuery Query for the facet search
|
3527
|
-
* @param {string} [params.*] Any search parameter of Algolia,
|
3528
|
-
* see https://www.algolia.com/doc/api-client/javascript/search#search-parameters
|
3529
|
-
* Pagination is not supported. The page and hitsPerPage parameters will be ignored.
|
3530
|
-
* @param callback (optional)
|
3531
|
-
*/
|
3532
|
-
IndexCore.prototype.searchForFacetValues = function(params, callback) {
|
3533
|
-
var clone = require(22);
|
3534
|
-
var omit = require(29);
|
3535
|
-
var usage = 'Usage: index.searchForFacetValues({facetName, facetQuery, ...params}[, callback])';
|
3536
|
-
|
3537
|
-
if (params.facetName === undefined || params.facetQuery === undefined) {
|
3538
|
-
throw new Error(usage);
|
3539
|
-
}
|
3540
|
-
|
3541
|
-
var facetName = params.facetName;
|
3542
|
-
var filteredParams = omit(clone(params), function(keyName) {
|
3543
|
-
return keyName === 'facetName';
|
3544
|
-
});
|
3545
|
-
var searchParameters = this.as._getSearchParams(filteredParams, '');
|
3546
|
-
|
3547
|
-
return this.as._jsonRequest({
|
3548
|
-
method: 'POST',
|
3549
|
-
url: '/1/indexes/' +
|
3550
|
-
encodeURIComponent(this.indexName) + '/facets/' + encodeURIComponent(facetName) + '/query',
|
3551
|
-
hostType: 'read',
|
3552
|
-
body: {params: searchParameters},
|
3553
|
-
callback: callback
|
3554
|
-
});
|
3555
|
-
};
|
3556
|
-
|
3557
|
-
IndexCore.prototype.searchFacet = deprecate(function(params, callback) {
|
3558
|
-
return this.searchForFacetValues(params, callback);
|
3559
|
-
}, deprecatedMessage(
|
3560
|
-
'index.searchFacet(params[, callback])',
|
3561
|
-
'index.searchForFacetValues(params[, callback])'
|
3562
|
-
));
|
3563
|
-
|
3564
|
-
IndexCore.prototype._search = function(params, url, callback, additionalUA) {
|
3565
|
-
return this.as._jsonRequest({
|
3566
|
-
cache: this.cache,
|
3567
|
-
method: 'POST',
|
3568
|
-
url: url || '/1/indexes/' + encodeURIComponent(this.indexName) + '/query',
|
3569
|
-
body: {params: params},
|
3570
|
-
hostType: 'read',
|
3571
|
-
fallback: {
|
3572
|
-
method: 'GET',
|
3573
|
-
url: '/1/indexes/' + encodeURIComponent(this.indexName),
|
3574
|
-
body: {params: params}
|
3575
|
-
},
|
3576
|
-
callback: callback,
|
3577
|
-
additionalUA: additionalUA
|
3578
|
-
});
|
3579
|
-
};
|
3580
|
-
|
3581
|
-
/*
|
3582
|
-
* Get an object from this index
|
3583
|
-
*
|
3584
|
-
* @param objectID the unique identifier of the object to retrieve
|
3585
|
-
* @param attrs (optional) if set, contains the array of attribute names to retrieve
|
3586
|
-
* @param callback (optional) the result callback called with two arguments
|
3587
|
-
* error: null or Error('message')
|
3588
|
-
* content: the object to retrieve or the error message if a failure occurred
|
3589
|
-
*/
|
3590
|
-
IndexCore.prototype.getObject = function(objectID, attrs, callback) {
|
3591
|
-
var indexObj = this;
|
3592
|
-
|
3593
|
-
if (arguments.length === 1 || typeof attrs === 'function') {
|
3594
|
-
callback = attrs;
|
3595
|
-
attrs = undefined;
|
3596
|
-
}
|
3597
|
-
|
3598
|
-
var params = '';
|
3599
|
-
if (attrs !== undefined) {
|
3600
|
-
params = '?attributes=';
|
3601
|
-
for (var i = 0; i < attrs.length; ++i) {
|
3602
|
-
if (i !== 0) {
|
3603
|
-
params += ',';
|
3604
|
-
}
|
3605
|
-
params += attrs[i];
|
3606
|
-
}
|
3607
|
-
}
|
3608
|
-
|
3609
|
-
return this.as._jsonRequest({
|
3610
|
-
method: 'GET',
|
3611
|
-
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(objectID) + params,
|
3612
|
-
hostType: 'read',
|
3613
|
-
callback: callback
|
3614
|
-
});
|
3615
|
-
};
|
3616
|
-
|
3617
|
-
/*
|
3618
|
-
* Get several objects from this index
|
3619
|
-
*
|
3620
|
-
* @param objectIDs the array of unique identifier of objects to retrieve
|
3621
|
-
*/
|
3622
|
-
IndexCore.prototype.getObjects = function(objectIDs, attributesToRetrieve, callback) {
|
3623
|
-
var isArray = require(7);
|
3624
|
-
var map = require(27);
|
3625
|
-
|
3626
|
-
var usage = 'Usage: index.getObjects(arrayOfObjectIDs[, callback])';
|
3627
|
-
|
3628
|
-
if (!isArray(objectIDs)) {
|
3629
|
-
throw new Error(usage);
|
3630
|
-
}
|
3631
|
-
|
3632
|
-
var indexObj = this;
|
3633
|
-
|
3634
|
-
if (arguments.length === 1 || typeof attributesToRetrieve === 'function') {
|
3635
|
-
callback = attributesToRetrieve;
|
3636
|
-
attributesToRetrieve = undefined;
|
3637
|
-
}
|
3638
|
-
|
3639
|
-
var body = {
|
3640
|
-
requests: map(objectIDs, function prepareRequest(objectID) {
|
3641
|
-
var request = {
|
3642
|
-
indexName: indexObj.indexName,
|
3643
|
-
objectID: objectID
|
3644
|
-
};
|
3645
|
-
|
3646
|
-
if (attributesToRetrieve) {
|
3647
|
-
request.attributesToRetrieve = attributesToRetrieve.join(',');
|
3648
|
-
}
|
3649
|
-
|
3650
|
-
return request;
|
3651
|
-
})
|
3652
|
-
};
|
3653
|
-
|
3654
|
-
return this.as._jsonRequest({
|
3655
|
-
method: 'POST',
|
3656
|
-
url: '/1/indexes/*/objects',
|
3657
|
-
hostType: 'read',
|
3658
|
-
body: body,
|
3659
|
-
callback: callback
|
3660
|
-
});
|
3661
|
-
};
|
3662
|
-
|
3663
|
-
IndexCore.prototype.as = null;
|
3664
|
-
IndexCore.prototype.indexName = null;
|
3665
|
-
IndexCore.prototype.typeAheadArgs = null;
|
3666
|
-
IndexCore.prototype.typeAheadValueOption = null;
|
3667
|
-
|
3668
|
-
},{"21":21,"22":22,"23":23,"24":24,"27":27,"28":28,"29":29,"7":7}],17:[function(require,module,exports){
|
3669
|
-
'use strict';
|
3670
|
-
|
3671
|
-
var AlgoliaSearchCore = require(15);
|
3672
|
-
var createAlgoliasearch = require(18);
|
3673
|
-
|
3674
|
-
module.exports = createAlgoliasearch(AlgoliaSearchCore, 'Browser (lite)');
|
3675
|
-
|
3676
|
-
},{"15":15,"18":18}],18:[function(require,module,exports){
|
3677
|
-
(function (process){
|
3678
|
-
'use strict';
|
3679
|
-
|
3680
|
-
var global = require(5);
|
3681
|
-
var Promise = global.Promise || require(3).Promise;
|
3682
|
-
|
3683
|
-
// This is the standalone browser build entry point
|
3684
|
-
// Browser implementation of the Algolia Search JavaScript client,
|
3685
|
-
// using XMLHttpRequest, XDomainRequest and JSONP as fallback
|
3686
|
-
module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
3687
|
-
var inherits = require(6);
|
3688
|
-
var errors = require(25);
|
3689
|
-
var inlineHeaders = require(19);
|
3690
|
-
var jsonpRequest = require(20);
|
3691
|
-
var places = require(30);
|
3692
|
-
uaSuffix = uaSuffix || '';
|
3693
|
-
|
3694
|
-
if (process.env.NODE_ENV === 'debug') {
|
3695
|
-
require(1).enable('algoliasearch*');
|
3696
|
-
}
|
3697
|
-
|
3698
|
-
function algoliasearch(applicationID, apiKey, opts) {
|
3699
|
-
var cloneDeep = require(22);
|
3700
|
-
|
3701
|
-
opts = cloneDeep(opts || {});
|
3702
|
-
|
3703
|
-
opts._ua = opts._ua || algoliasearch.ua;
|
3704
|
-
|
3705
|
-
return new AlgoliaSearchBrowser(applicationID, apiKey, opts);
|
3706
|
-
}
|
3707
|
-
|
3708
|
-
algoliasearch.version = require(32);
|
3709
|
-
|
3710
|
-
algoliasearch.ua =
|
3711
|
-
'Algolia for JavaScript (' + algoliasearch.version + '); ' + uaSuffix;
|
3712
|
-
|
3713
|
-
algoliasearch.initPlaces = places(algoliasearch);
|
3714
|
-
|
3715
|
-
// we expose into window no matter how we are used, this will allow
|
3716
|
-
// us to easily debug any website running algolia
|
3717
|
-
global.__algolia = {
|
3718
|
-
debug: require(1),
|
3719
|
-
algoliasearch: algoliasearch
|
3720
|
-
};
|
3721
|
-
|
3722
|
-
var support = {
|
3723
|
-
hasXMLHttpRequest: 'XMLHttpRequest' in global,
|
3724
|
-
hasXDomainRequest: 'XDomainRequest' in global
|
3725
|
-
};
|
3726
|
-
|
3727
|
-
if (support.hasXMLHttpRequest) {
|
3728
|
-
support.cors = 'withCredentials' in new XMLHttpRequest();
|
3729
|
-
}
|
3730
|
-
|
3731
|
-
function AlgoliaSearchBrowser() {
|
3732
|
-
// call AlgoliaSearch constructor
|
3733
|
-
AlgoliaSearch.apply(this, arguments);
|
3734
|
-
}
|
3735
|
-
|
3736
|
-
inherits(AlgoliaSearchBrowser, AlgoliaSearch);
|
3737
|
-
|
3738
|
-
AlgoliaSearchBrowser.prototype._request = function request(url, opts) {
|
3739
|
-
return new Promise(function wrapRequest(resolve, reject) {
|
3740
|
-
// no cors or XDomainRequest, no request
|
3741
|
-
if (!support.cors && !support.hasXDomainRequest) {
|
3742
|
-
// very old browser, not supported
|
3743
|
-
reject(new errors.Network('CORS not supported'));
|
3744
|
-
return;
|
3745
|
-
}
|
3746
|
-
|
3747
|
-
url = inlineHeaders(url, opts.headers);
|
3748
|
-
|
3749
|
-
var body = opts.body;
|
3750
|
-
var req = support.cors ? new XMLHttpRequest() : new XDomainRequest();
|
3751
|
-
var reqTimeout;
|
3752
|
-
var timedOut;
|
3753
|
-
var connected = false;
|
3754
|
-
|
3755
|
-
reqTimeout = setTimeout(onTimeout, opts.timeouts.connect);
|
3756
|
-
// we set an empty onprogress listener
|
3757
|
-
// so that XDomainRequest on IE9 is not aborted
|
3758
|
-
// refs:
|
3759
|
-
// - https://github.com/algolia/algoliasearch-client-js/issues/76
|
3760
|
-
// - https://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment
|
3761
|
-
req.onprogress = onProgress;
|
3762
|
-
if ('onreadystatechange' in req) req.onreadystatechange = onReadyStateChange;
|
3763
|
-
req.onload = onLoad;
|
3764
|
-
req.onerror = onError;
|
3765
|
-
|
3766
|
-
// do not rely on default XHR async flag, as some analytics code like hotjar
|
3767
|
-
// breaks it and set it to false by default
|
3768
|
-
if (req instanceof XMLHttpRequest) {
|
3769
|
-
req.open(opts.method, url, true);
|
3770
|
-
|
3771
|
-
// The Analytics API never accepts Auth headers as query string
|
3772
|
-
// this option exists specifically for them.
|
3773
|
-
if (opts.forceAuthHeaders) {
|
3774
|
-
req.setRequestHeader(
|
3775
|
-
'x-algolia-application-id',
|
3776
|
-
opts.headers['x-algolia-application-id']
|
3777
|
-
);
|
3778
|
-
req.setRequestHeader(
|
3779
|
-
'x-algolia-api-key',
|
3780
|
-
opts.headers['x-algolia-api-key']
|
3781
|
-
);
|
3782
|
-
}
|
3783
|
-
} else {
|
3784
|
-
req.open(opts.method, url);
|
3785
|
-
}
|
3786
|
-
|
3787
|
-
// headers are meant to be sent after open
|
3788
|
-
if (support.cors) {
|
3789
|
-
if (body) {
|
3790
|
-
if (opts.method === 'POST') {
|
3791
|
-
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests
|
3792
|
-
req.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
|
3793
|
-
} else {
|
3794
|
-
req.setRequestHeader('content-type', 'application/json');
|
3795
|
-
}
|
3796
|
-
}
|
3797
|
-
req.setRequestHeader('accept', 'application/json');
|
3798
|
-
}
|
3799
|
-
|
3800
|
-
if (body) {
|
3801
|
-
req.send(body);
|
3802
|
-
} else {
|
3803
|
-
req.send();
|
3804
|
-
}
|
3805
|
-
|
3806
|
-
// event object not received in IE8, at least
|
3807
|
-
// but we do not use it, still important to note
|
3808
|
-
function onLoad(/* event */) {
|
3809
|
-
// When browser does not supports req.timeout, we can
|
3810
|
-
// have both a load and timeout event, since handled by a dumb setTimeout
|
3811
|
-
if (timedOut) {
|
3812
|
-
return;
|
3813
|
-
}
|
3814
|
-
|
3815
|
-
clearTimeout(reqTimeout);
|
3816
|
-
|
3817
|
-
var out;
|
3818
|
-
|
3819
|
-
try {
|
3820
|
-
out = {
|
3821
|
-
body: JSON.parse(req.responseText),
|
3822
|
-
responseText: req.responseText,
|
3823
|
-
statusCode: req.status,
|
3824
|
-
// XDomainRequest does not have any response headers
|
3825
|
-
headers: req.getAllResponseHeaders && req.getAllResponseHeaders() || {}
|
3826
|
-
};
|
3827
|
-
} catch (e) {
|
3828
|
-
out = new errors.UnparsableJSON({
|
3829
|
-
more: req.responseText
|
3830
|
-
});
|
3831
|
-
}
|
3832
|
-
|
3833
|
-
if (out instanceof errors.UnparsableJSON) {
|
3834
|
-
reject(out);
|
3835
|
-
} else {
|
3836
|
-
resolve(out);
|
3837
|
-
}
|
3838
|
-
}
|
3839
|
-
|
3840
|
-
function onError(event) {
|
3841
|
-
if (timedOut) {
|
3842
|
-
return;
|
3843
|
-
}
|
3844
|
-
|
3845
|
-
clearTimeout(reqTimeout);
|
3846
|
-
|
3847
|
-
// error event is trigerred both with XDR/XHR on:
|
3848
|
-
// - DNS error
|
3849
|
-
// - unallowed cross domain request
|
3850
|
-
reject(
|
3851
|
-
new errors.Network({
|
3852
|
-
more: event
|
3853
|
-
})
|
3854
|
-
);
|
3855
|
-
}
|
3856
|
-
|
3857
|
-
function onTimeout() {
|
3858
|
-
timedOut = true;
|
3859
|
-
req.abort();
|
3860
|
-
|
3861
|
-
reject(new errors.RequestTimeout());
|
3862
|
-
}
|
3863
|
-
|
3864
|
-
function onConnect() {
|
3865
|
-
connected = true;
|
3866
|
-
clearTimeout(reqTimeout);
|
3867
|
-
reqTimeout = setTimeout(onTimeout, opts.timeouts.complete);
|
3868
|
-
}
|
3869
|
-
|
3870
|
-
function onProgress() {
|
3871
|
-
if (!connected) onConnect();
|
3872
|
-
}
|
3873
|
-
|
3874
|
-
function onReadyStateChange() {
|
3875
|
-
if (!connected && req.readyState > 1) onConnect();
|
3876
|
-
}
|
3877
|
-
});
|
3878
|
-
};
|
3879
|
-
|
3880
|
-
AlgoliaSearchBrowser.prototype._request.fallback = function requestFallback(url, opts) {
|
3881
|
-
url = inlineHeaders(url, opts.headers);
|
3882
|
-
|
3883
|
-
return new Promise(function wrapJsonpRequest(resolve, reject) {
|
3884
|
-
jsonpRequest(url, opts, function jsonpRequestDone(err, content) {
|
3885
|
-
if (err) {
|
3886
|
-
reject(err);
|
3887
|
-
return;
|
3888
|
-
}
|
3889
|
-
|
3890
|
-
resolve(content);
|
3891
|
-
});
|
3892
|
-
});
|
3893
|
-
};
|
3894
|
-
|
3895
|
-
AlgoliaSearchBrowser.prototype._promise = {
|
3896
|
-
reject: function rejectPromise(val) {
|
3897
|
-
return Promise.reject(val);
|
3898
|
-
},
|
3899
|
-
resolve: function resolvePromise(val) {
|
3900
|
-
return Promise.resolve(val);
|
3901
|
-
},
|
3902
|
-
delay: function delayPromise(ms) {
|
3903
|
-
return new Promise(function resolveOnTimeout(resolve/* , reject*/) {
|
3904
|
-
setTimeout(resolve, ms);
|
3905
|
-
});
|
3906
|
-
},
|
3907
|
-
all: function all(promises) {
|
3908
|
-
return Promise.all(promises);
|
3909
|
-
}
|
3910
|
-
};
|
3911
|
-
|
3912
|
-
return algoliasearch;
|
3913
|
-
};
|
3914
|
-
|
3915
|
-
}).call(this,require(11))
|
3916
|
-
},{"1":1,"11":11,"19":19,"20":20,"22":22,"25":25,"3":3,"30":30,"32":32,"5":5,"6":6}],19:[function(require,module,exports){
|
3917
|
-
'use strict';
|
3918
|
-
|
3919
|
-
module.exports = inlineHeaders;
|
3920
|
-
|
3921
|
-
var encode = require(13);
|
3922
|
-
|
3923
|
-
function inlineHeaders(url, headers) {
|
3924
|
-
if (/\?/.test(url)) {
|
3925
|
-
url += '&';
|
3926
|
-
} else {
|
3927
|
-
url += '?';
|
3928
|
-
}
|
3929
|
-
|
3930
|
-
return url + encode(headers);
|
3931
|
-
}
|
3932
|
-
|
3933
|
-
},{"13":13}],20:[function(require,module,exports){
|
3934
|
-
'use strict';
|
3935
|
-
|
3936
|
-
module.exports = jsonpRequest;
|
3937
|
-
|
3938
|
-
var errors = require(25);
|
3939
|
-
|
3940
|
-
var JSONPCounter = 0;
|
3941
|
-
|
3942
|
-
function jsonpRequest(url, opts, cb) {
|
3943
|
-
if (opts.method !== 'GET') {
|
3944
|
-
cb(new Error('Method ' + opts.method + ' ' + url + ' is not supported by JSONP.'));
|
3945
|
-
return;
|
3946
|
-
}
|
3947
|
-
|
3948
|
-
opts.debug('JSONP: start');
|
3949
|
-
|
3950
|
-
var cbCalled = false;
|
3951
|
-
var timedOut = false;
|
3952
|
-
|
3953
|
-
JSONPCounter += 1;
|
3954
|
-
var head = document.getElementsByTagName('head')[0];
|
3955
|
-
var script = document.createElement('script');
|
3956
|
-
var cbName = 'algoliaJSONP_' + JSONPCounter;
|
3957
|
-
var done = false;
|
3958
|
-
|
3959
|
-
window[cbName] = function(data) {
|
3960
|
-
removeGlobals();
|
3961
|
-
|
3962
|
-
if (timedOut) {
|
3963
|
-
opts.debug('JSONP: Late answer, ignoring');
|
3964
|
-
return;
|
3965
|
-
}
|
3966
|
-
|
3967
|
-
cbCalled = true;
|
3968
|
-
|
3969
|
-
clean();
|
3970
|
-
|
3971
|
-
cb(null, {
|
3972
|
-
body: data,
|
3973
|
-
responseText: JSON.stringify(data)/* ,
|
3974
|
-
// We do not send the statusCode, there's no statusCode in JSONP, it will be
|
3975
|
-
// computed using data.status && data.message like with XDR
|
3976
|
-
statusCode*/
|
3977
|
-
});
|
3978
|
-
};
|
3979
|
-
|
3980
|
-
// add callback by hand
|
3981
|
-
url += '&callback=' + cbName;
|
3982
|
-
|
3983
|
-
// add body params manually
|
3984
|
-
if (opts.jsonBody && opts.jsonBody.params) {
|
3985
|
-
url += '&' + opts.jsonBody.params;
|
3986
|
-
}
|
3987
|
-
|
3988
|
-
var ontimeout = setTimeout(timeout, opts.timeouts.complete);
|
3989
|
-
|
3990
|
-
// script onreadystatechange needed only for
|
3991
|
-
// <= IE8
|
3992
|
-
// https://github.com/angular/angular.js/issues/4523
|
3993
|
-
script.onreadystatechange = readystatechange;
|
3994
|
-
script.onload = success;
|
3995
|
-
script.onerror = error;
|
3996
|
-
|
3997
|
-
script.async = true;
|
3998
|
-
script.defer = true;
|
3999
|
-
script.src = url;
|
4000
|
-
head.appendChild(script);
|
4001
|
-
|
4002
|
-
function success() {
|
4003
|
-
opts.debug('JSONP: success');
|
4004
|
-
|
4005
|
-
if (done || timedOut) {
|
4006
|
-
return;
|
4007
|
-
}
|
4008
|
-
|
4009
|
-
done = true;
|
4010
|
-
|
4011
|
-
// script loaded but did not call the fn => script loading error
|
4012
|
-
if (!cbCalled) {
|
4013
|
-
opts.debug('JSONP: Fail. Script loaded but did not call the callback');
|
4014
|
-
clean();
|
4015
|
-
cb(new errors.JSONPScriptFail());
|
4016
|
-
}
|
4017
|
-
}
|
4018
|
-
|
4019
|
-
function readystatechange() {
|
4020
|
-
if (this.readyState === 'loaded' || this.readyState === 'complete') {
|
4021
|
-
success();
|
4022
|
-
}
|
4023
|
-
}
|
4024
|
-
|
4025
|
-
function clean() {
|
4026
|
-
clearTimeout(ontimeout);
|
4027
|
-
script.onload = null;
|
4028
|
-
script.onreadystatechange = null;
|
4029
|
-
script.onerror = null;
|
4030
|
-
head.removeChild(script);
|
4031
|
-
}
|
4032
|
-
|
4033
|
-
function removeGlobals() {
|
4034
|
-
try {
|
4035
|
-
delete window[cbName];
|
4036
|
-
delete window[cbName + '_loaded'];
|
4037
|
-
} catch (e) {
|
4038
|
-
window[cbName] = window[cbName + '_loaded'] = undefined;
|
4039
|
-
}
|
4040
|
-
}
|
4041
|
-
|
4042
|
-
function timeout() {
|
4043
|
-
opts.debug('JSONP: Script timeout');
|
4044
|
-
timedOut = true;
|
4045
|
-
clean();
|
4046
|
-
cb(new errors.RequestTimeout());
|
4047
|
-
}
|
4048
|
-
|
4049
|
-
function error() {
|
4050
|
-
opts.debug('JSONP: Script error');
|
4051
|
-
|
4052
|
-
if (done || timedOut) {
|
4053
|
-
return;
|
4054
|
-
}
|
4055
|
-
|
4056
|
-
clean();
|
4057
|
-
cb(new errors.JSONPScriptError());
|
4058
|
-
}
|
4059
|
-
}
|
4060
|
-
|
4061
|
-
},{"25":25}],21:[function(require,module,exports){
|
4062
|
-
module.exports = buildSearchMethod;
|
4063
|
-
|
4064
|
-
var errors = require(25);
|
4065
|
-
|
4066
|
-
/**
|
4067
|
-
* Creates a search method to be used in clients
|
4068
|
-
* @param {string} queryParam the name of the attribute used for the query
|
4069
|
-
* @param {string} url the url
|
4070
|
-
* @return {function} the search method
|
4071
|
-
*/
|
4072
|
-
function buildSearchMethod(queryParam, url) {
|
4073
|
-
/**
|
4074
|
-
* The search method. Prepares the data and send the query to Algolia.
|
4075
|
-
* @param {string} query the string used for query search
|
4076
|
-
* @param {object} args additional parameters to send with the search
|
4077
|
-
* @param {function} [callback] the callback to be called with the client gets the answer
|
4078
|
-
* @return {undefined|Promise} If the callback is not provided then this methods returns a Promise
|
4079
|
-
*/
|
4080
|
-
return function search(query, args, callback) {
|
4081
|
-
// warn V2 users on how to search
|
4082
|
-
if (typeof query === 'function' && typeof args === 'object' ||
|
4083
|
-
typeof callback === 'object') {
|
4084
|
-
// .search(query, params, cb)
|
4085
|
-
// .search(cb, params)
|
4086
|
-
throw new errors.AlgoliaSearchError('index.search usage is index.search(query, params, cb)');
|
4087
|
-
}
|
4088
|
-
|
4089
|
-
// Normalizing the function signature
|
4090
|
-
if (arguments.length === 0 || typeof query === 'function') {
|
4091
|
-
// Usage : .search(), .search(cb)
|
4092
|
-
callback = query;
|
4093
|
-
query = '';
|
4094
|
-
} else if (arguments.length === 1 || typeof args === 'function') {
|
4095
|
-
// Usage : .search(query/args), .search(query, cb)
|
4096
|
-
callback = args;
|
4097
|
-
args = undefined;
|
4098
|
-
}
|
4099
|
-
// At this point we have 3 arguments with values
|
4100
|
-
|
4101
|
-
// Usage : .search(args) // careful: typeof null === 'object'
|
4102
|
-
if (typeof query === 'object' && query !== null) {
|
4103
|
-
args = query;
|
4104
|
-
query = undefined;
|
4105
|
-
} else if (query === undefined || query === null) { // .search(undefined/null)
|
4106
|
-
query = '';
|
4107
|
-
}
|
4108
|
-
|
4109
|
-
var params = '';
|
4110
|
-
|
4111
|
-
if (query !== undefined) {
|
4112
|
-
params += queryParam + '=' + encodeURIComponent(query);
|
4113
|
-
}
|
4114
|
-
|
4115
|
-
var additionalUA;
|
4116
|
-
if (args !== undefined) {
|
4117
|
-
if (args.additionalUA) {
|
4118
|
-
additionalUA = args.additionalUA;
|
4119
|
-
delete args.additionalUA;
|
4120
|
-
}
|
4121
|
-
// `_getSearchParams` will augment params, do not be fooled by the = versus += from previous if
|
4122
|
-
params = this.as._getSearchParams(args, params);
|
4123
|
-
}
|
4124
|
-
|
4125
|
-
|
4126
|
-
return this._search(params, url, callback, additionalUA);
|
4127
|
-
};
|
4128
|
-
}
|
4129
|
-
|
4130
|
-
},{"25":25}],22:[function(require,module,exports){
|
4131
|
-
module.exports = function clone(obj) {
|
4132
|
-
return JSON.parse(JSON.stringify(obj));
|
4133
|
-
};
|
4134
|
-
|
4135
|
-
},{}],23:[function(require,module,exports){
|
4136
|
-
module.exports = function deprecate(fn, message) {
|
4137
|
-
var warned = false;
|
4138
|
-
|
4139
|
-
function deprecated() {
|
4140
|
-
if (!warned) {
|
4141
|
-
/* eslint no-console:0 */
|
4142
|
-
console.warn(message);
|
4143
|
-
warned = true;
|
4144
|
-
}
|
4145
|
-
|
4146
|
-
return fn.apply(this, arguments);
|
4147
|
-
}
|
4148
|
-
|
4149
|
-
return deprecated;
|
4150
|
-
};
|
4151
|
-
|
4152
|
-
},{}],24:[function(require,module,exports){
|
4153
|
-
module.exports = function deprecatedMessage(previousUsage, newUsage) {
|
4154
|
-
var githubAnchorLink = previousUsage.toLowerCase()
|
4155
|
-
.replace(/[\.\(\)]/g, '');
|
4156
|
-
|
4157
|
-
return 'algoliasearch: `' + previousUsage + '` was replaced by `' + newUsage +
|
4158
|
-
'`. Please see https://github.com/algolia/algoliasearch-client-javascript/wiki/Deprecated#' + githubAnchorLink;
|
4159
|
-
};
|
4160
|
-
|
4161
|
-
},{}],25:[function(require,module,exports){
|
4162
|
-
'use strict';
|
4163
|
-
|
4164
|
-
// This file hosts our error definitions
|
4165
|
-
// We use custom error "types" so that we can act on them when we need it
|
4166
|
-
// e.g.: if error instanceof errors.UnparsableJSON then..
|
4167
|
-
|
4168
|
-
var inherits = require(6);
|
4169
|
-
|
4170
|
-
function AlgoliaSearchError(message, extraProperties) {
|
4171
|
-
var forEach = require(4);
|
4172
|
-
|
4173
|
-
var error = this;
|
4174
|
-
|
4175
|
-
// try to get a stacktrace
|
4176
|
-
if (typeof Error.captureStackTrace === 'function') {
|
4177
|
-
Error.captureStackTrace(this, this.constructor);
|
4178
|
-
} else {
|
4179
|
-
error.stack = (new Error()).stack || 'Cannot get a stacktrace, browser is too old';
|
4180
|
-
}
|
4181
|
-
|
4182
|
-
this.name = 'AlgoliaSearchError';
|
4183
|
-
this.message = message || 'Unknown error';
|
4184
|
-
|
4185
|
-
if (extraProperties) {
|
4186
|
-
forEach(extraProperties, function addToErrorObject(value, key) {
|
4187
|
-
error[key] = value;
|
4188
|
-
});
|
4189
|
-
}
|
4190
|
-
}
|
4191
|
-
|
4192
|
-
inherits(AlgoliaSearchError, Error);
|
4193
|
-
|
4194
|
-
function createCustomError(name, message) {
|
4195
|
-
function AlgoliaSearchCustomError() {
|
4196
|
-
var args = Array.prototype.slice.call(arguments, 0);
|
4197
|
-
|
4198
|
-
// custom message not set, use default
|
4199
|
-
if (typeof args[0] !== 'string') {
|
4200
|
-
args.unshift(message);
|
4201
|
-
}
|
4202
|
-
|
4203
|
-
AlgoliaSearchError.apply(this, args);
|
4204
|
-
this.name = 'AlgoliaSearch' + name + 'Error';
|
4205
|
-
}
|
4206
|
-
|
4207
|
-
inherits(AlgoliaSearchCustomError, AlgoliaSearchError);
|
4208
|
-
|
4209
|
-
return AlgoliaSearchCustomError;
|
4210
|
-
}
|
4211
|
-
|
4212
|
-
// late exports to let various fn defs and inherits take place
|
4213
|
-
module.exports = {
|
4214
|
-
AlgoliaSearchError: AlgoliaSearchError,
|
4215
|
-
UnparsableJSON: createCustomError(
|
4216
|
-
'UnparsableJSON',
|
4217
|
-
'Could not parse the incoming response as JSON, see err.more for details'
|
4218
|
-
),
|
4219
|
-
RequestTimeout: createCustomError(
|
4220
|
-
'RequestTimeout',
|
4221
|
-
'Request timed out before getting a response'
|
4222
|
-
),
|
4223
|
-
Network: createCustomError(
|
4224
|
-
'Network',
|
4225
|
-
'Network issue, see err.more for details'
|
4226
|
-
),
|
4227
|
-
JSONPScriptFail: createCustomError(
|
4228
|
-
'JSONPScriptFail',
|
4229
|
-
'<script> was loaded but did not call our provided callback'
|
4230
|
-
),
|
4231
|
-
ValidUntilNotFound: createCustomError(
|
4232
|
-
'ValidUntilNotFound',
|
4233
|
-
'The SecuredAPIKey does not have a validUntil parameter.'
|
4234
|
-
),
|
4235
|
-
JSONPScriptError: createCustomError(
|
4236
|
-
'JSONPScriptError',
|
4237
|
-
'<script> unable to load due to an `error` event on it'
|
4238
|
-
),
|
4239
|
-
ObjectNotFound: createCustomError(
|
4240
|
-
'ObjectNotFound',
|
4241
|
-
'Object not found'
|
4242
|
-
),
|
4243
|
-
Unknown: createCustomError(
|
4244
|
-
'Unknown',
|
4245
|
-
'Unknown error occured'
|
4246
|
-
)
|
4247
|
-
};
|
4248
|
-
|
4249
|
-
},{"4":4,"6":6}],26:[function(require,module,exports){
|
4250
|
-
// Parse cloud does not supports setTimeout
|
4251
|
-
// We do not store a setTimeout reference in the client everytime
|
4252
|
-
// We only fallback to a fake setTimeout when not available
|
4253
|
-
// setTimeout cannot be override globally sadly
|
4254
|
-
module.exports = function exitPromise(fn, _setTimeout) {
|
4255
|
-
_setTimeout(fn, 0);
|
4256
|
-
};
|
4257
|
-
|
4258
|
-
},{}],27:[function(require,module,exports){
|
4259
|
-
var foreach = require(4);
|
4260
|
-
|
4261
|
-
module.exports = function map(arr, fn) {
|
4262
|
-
var newArr = [];
|
4263
|
-
foreach(arr, function(item, itemIndex) {
|
4264
|
-
newArr.push(fn(item, itemIndex, arr));
|
4265
|
-
});
|
4266
|
-
return newArr;
|
4267
|
-
};
|
4268
|
-
|
4269
|
-
},{"4":4}],28:[function(require,module,exports){
|
4270
|
-
var foreach = require(4);
|
4271
|
-
|
4272
|
-
module.exports = function merge(destination/* , sources */) {
|
4273
|
-
var sources = Array.prototype.slice.call(arguments);
|
4274
|
-
|
4275
|
-
foreach(sources, function(source) {
|
4276
|
-
for (var keyName in source) {
|
4277
|
-
if (source.hasOwnProperty(keyName)) {
|
4278
|
-
if (typeof destination[keyName] === 'object' && typeof source[keyName] === 'object') {
|
4279
|
-
destination[keyName] = merge({}, destination[keyName], source[keyName]);
|
4280
|
-
} else if (source[keyName] !== undefined) {
|
4281
|
-
destination[keyName] = source[keyName];
|
4282
|
-
}
|
4283
|
-
}
|
4284
|
-
}
|
4285
|
-
});
|
4286
|
-
|
4287
|
-
return destination;
|
4288
|
-
};
|
4289
|
-
|
4290
|
-
},{"4":4}],29:[function(require,module,exports){
|
4291
|
-
module.exports = function omit(obj, test) {
|
4292
|
-
var keys = require(9);
|
4293
|
-
var foreach = require(4);
|
4294
|
-
|
4295
|
-
var filtered = {};
|
4296
|
-
|
4297
|
-
foreach(keys(obj), function doFilter(keyName) {
|
4298
|
-
if (test(keyName) !== true) {
|
4299
|
-
filtered[keyName] = obj[keyName];
|
4300
|
-
}
|
4301
|
-
});
|
4302
|
-
|
4303
|
-
return filtered;
|
4304
|
-
};
|
4305
|
-
|
4306
|
-
},{"4":4,"9":9}],30:[function(require,module,exports){
|
4307
|
-
module.exports = createPlacesClient;
|
4308
|
-
|
4309
|
-
var qs3 = require(14);
|
4310
|
-
var buildSearchMethod = require(21);
|
4311
|
-
|
4312
|
-
function createPlacesClient(algoliasearch) {
|
4313
|
-
return function places(appID, apiKey, opts) {
|
4314
|
-
var cloneDeep = require(22);
|
4315
|
-
|
4316
|
-
opts = opts && cloneDeep(opts) || {};
|
4317
|
-
opts.hosts = opts.hosts || [
|
4318
|
-
'places-dsn.algolia.net',
|
4319
|
-
'places-1.algolianet.com',
|
4320
|
-
'places-2.algolianet.com',
|
4321
|
-
'places-3.algolianet.com'
|
4322
|
-
];
|
4323
|
-
|
4324
|
-
// allow initPlaces() no arguments => community rate limited
|
4325
|
-
if (arguments.length === 0 || typeof appID === 'object' || appID === undefined) {
|
4326
|
-
appID = '';
|
4327
|
-
apiKey = '';
|
4328
|
-
opts._allowEmptyCredentials = true;
|
4329
|
-
}
|
4330
|
-
|
4331
|
-
var client = algoliasearch(appID, apiKey, opts);
|
4332
|
-
var index = client.initIndex('places');
|
4333
|
-
index.search = buildSearchMethod('query', '/1/places/query');
|
4334
|
-
index.reverse = function(options, callback) {
|
4335
|
-
var encoded = qs3.encode(options);
|
4336
|
-
|
4337
|
-
return this.as._jsonRequest({
|
4338
|
-
method: 'GET',
|
4339
|
-
url: '/1/places/reverse?' + encoded,
|
4340
|
-
hostType: 'read',
|
4341
|
-
callback: callback
|
4342
|
-
});
|
4343
|
-
};
|
4344
|
-
|
4345
|
-
index.getObject = function(objectID, callback) {
|
4346
|
-
return this.as._jsonRequest({
|
4347
|
-
method: 'GET',
|
4348
|
-
url: '/1/places/' + encodeURIComponent(objectID),
|
4349
|
-
hostType: 'read',
|
4350
|
-
callback: callback
|
4351
|
-
});
|
4352
|
-
};
|
4353
|
-
return index;
|
4354
|
-
};
|
4355
|
-
}
|
4356
|
-
|
4357
|
-
},{"14":14,"21":21,"22":22}],31:[function(require,module,exports){
|
4358
|
-
(function (global){
|
4359
|
-
var debug = require(1)('algoliasearch:src/hostIndexState.js');
|
4360
|
-
var localStorageNamespace = 'algoliasearch-client-js';
|
4361
|
-
|
4362
|
-
var store;
|
4363
|
-
var moduleStore = {
|
4364
|
-
state: {},
|
4365
|
-
set: function(key, data) {
|
4366
|
-
this.state[key] = data;
|
4367
|
-
return this.state[key];
|
4368
|
-
},
|
4369
|
-
get: function(key) {
|
4370
|
-
return this.state[key] || null;
|
4371
|
-
}
|
4372
|
-
};
|
4373
|
-
|
4374
|
-
var localStorageStore = {
|
4375
|
-
set: function(key, data) {
|
4376
|
-
moduleStore.set(key, data); // always replicate localStorageStore to moduleStore in case of failure
|
4377
|
-
|
4378
|
-
try {
|
4379
|
-
var namespace = JSON.parse(global.localStorage[localStorageNamespace]);
|
4380
|
-
namespace[key] = data;
|
4381
|
-
global.localStorage[localStorageNamespace] = JSON.stringify(namespace);
|
4382
|
-
return namespace[key];
|
4383
|
-
} catch (e) {
|
4384
|
-
return localStorageFailure(key, e);
|
4385
|
-
}
|
4386
|
-
},
|
4387
|
-
get: function(key) {
|
4388
|
-
try {
|
4389
|
-
return JSON.parse(global.localStorage[localStorageNamespace])[key] || null;
|
4390
|
-
} catch (e) {
|
4391
|
-
return localStorageFailure(key, e);
|
4392
|
-
}
|
4393
|
-
}
|
4394
|
-
};
|
4395
|
-
|
4396
|
-
function localStorageFailure(key, e) {
|
4397
|
-
debug('localStorage failed with', e);
|
4398
|
-
cleanup();
|
4399
|
-
store = moduleStore;
|
4400
|
-
return store.get(key);
|
4401
|
-
}
|
4402
|
-
|
4403
|
-
store = supportsLocalStorage() ? localStorageStore : moduleStore;
|
4404
|
-
|
4405
|
-
module.exports = {
|
4406
|
-
get: getOrSet,
|
4407
|
-
set: getOrSet,
|
4408
|
-
supportsLocalStorage: supportsLocalStorage
|
4409
|
-
};
|
4410
|
-
|
4411
|
-
function getOrSet(key, data) {
|
4412
|
-
if (arguments.length === 1) {
|
4413
|
-
return store.get(key);
|
4414
|
-
}
|
4415
|
-
|
4416
|
-
return store.set(key, data);
|
4417
|
-
}
|
4418
|
-
|
4419
|
-
function supportsLocalStorage() {
|
4420
|
-
try {
|
4421
|
-
if ('localStorage' in global &&
|
4422
|
-
global.localStorage !== null) {
|
4423
|
-
if (!global.localStorage[localStorageNamespace]) {
|
4424
|
-
// actual creation of the namespace
|
4425
|
-
global.localStorage.setItem(localStorageNamespace, JSON.stringify({}));
|
4426
|
-
}
|
4427
|
-
return true;
|
4428
|
-
}
|
4429
|
-
|
4430
|
-
return false;
|
4431
|
-
} catch (_) {
|
4432
|
-
return false;
|
4433
|
-
}
|
4434
|
-
}
|
4435
|
-
|
4436
|
-
// In case of any error on localStorage, we clean our own namespace, this should handle
|
4437
|
-
// quota errors when a lot of keys + data are used
|
4438
|
-
function cleanup() {
|
4439
|
-
try {
|
4440
|
-
global.localStorage.removeItem(localStorageNamespace);
|
4441
|
-
} catch (_) {
|
4442
|
-
// nothing to do
|
4443
|
-
}
|
4444
|
-
}
|
4445
|
-
|
4446
|
-
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
4447
|
-
},{"1":1}],32:[function(require,module,exports){
|
4448
|
-
'use strict';
|
4449
|
-
|
4450
|
-
module.exports = '3.35.1';
|
4451
|
-
|
4452
|
-
},{}]},{},[17])(17)
|
4453
|
-
});
|
10
|
+
!function(e,o){"object"==typeof r&&void 0!==t?t.exports=o():e.ES6Promise=o()}(this,(function(){"use strict";function t(e){return"function"==typeof e}var r=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},i=0,a=void 0,s=void 0,c=function(e,t){y[i]=e,y[i+1]=t,2===(i+=2)&&(s?s(m):_())};var u="undefined"!=typeof window?window:void 0,l=u||{},p=l.MutationObserver||l.WebKitMutationObserver,f="undefined"==typeof self&&void 0!==o&&"[object process]"==={}.toString.call(o),d="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function h(){var e=setTimeout;return function(){return e(m,1)}}var y=new Array(1e3);function m(){for(var e=0;e<i;e+=2){(0,y[e])(y[e+1]),y[e]=void 0,y[e+1]=void 0}i=0}var g,v,b,w,_=void 0;function x(e,t){var r=arguments,o=this,n=new this.constructor(A);void 0===n[S]&&$(n);var i,a=o._state;return a?(i=r[a-1],c((function(){return J(a,n,i,o._result)}))):P(o,n,e,t),n}function T(e){if(e&&"object"==typeof e&&e.constructor===this)return e;var t=new this(A);return q(t,e),t}f?_=function(){return o.nextTick(m)}:p?(v=0,b=new p(m),w=document.createTextNode(""),b.observe(w,{characterData:!0}),_=function(){w.data=v=++v%2}):d?((g=new MessageChannel).port1.onmessage=m,_=function(){return g.port2.postMessage(0)}):_=void 0===u&&"function"==typeof e?function(){try{var t=e("vertx");return void 0!==(a=t.runOnLoop||t.runOnContext)?function(){a(m)}:h()}catch(e){return h()}}():h();var S=Math.random().toString(36).substring(16);function A(){}var j=void 0,O=1,k=2,R=new H;function C(e){try{return e.then}catch(e){return R.error=e,R}}function I(e,r,o){r.constructor===e.constructor&&o===x&&r.constructor.resolve===T?function(e,t){t._state===O?E(e,t._result):t._state===k?U(e,t._result):P(t,void 0,(function(t){return q(e,t)}),(function(t){return U(e,t)}))}(e,r):o===R?(U(e,R.error),R.error=null):void 0===o?E(e,r):t(o)?function(e,t,r){c((function(e){var o=!1,n=function(e,t,r,o){try{e.call(t,r,o)}catch(e){return e}}(r,t,(function(r){o||(o=!0,t!==r?q(e,r):E(e,r))}),(function(t){o||(o=!0,U(e,t))}),e._label);!o&&n&&(o=!0,U(e,n))}),e)}(e,r,o):E(e,r)}function q(e,t){var r,o;e===t?U(e,new TypeError("You cannot resolve a promise with itself")):(o=typeof(r=t),null===r||"object"!==o&&"function"!==o?E(e,t):I(e,t,C(t)))}function N(e){e._onerror&&e._onerror(e._result),D(e)}function E(e,t){e._state===j&&(e._result=t,e._state=O,0!==e._subscribers.length&&c(D,e))}function U(e,t){e._state===j&&(e._state=k,e._result=t,c(N,e))}function P(e,t,r,o){var n=e._subscribers,i=n.length;e._onerror=null,n[i]=t,n[i+O]=r,n[i+k]=o,0===i&&e._state&&c(D,e)}function D(e){var t=e._subscribers,r=e._state;if(0!==t.length){for(var o=void 0,n=void 0,i=e._result,a=0;a<t.length;a+=3)o=t[a],n=t[a+r],o?J(r,o,n,i):n(i);e._subscribers.length=0}}function H(){this.error=null}var F=new H;function J(e,r,o,n){var i=t(o),a=void 0,s=void 0,c=void 0,u=void 0;if(i){if(a=function(e,t){try{return e(t)}catch(e){return F.error=e,F}}(o,n),a===F?(u=!0,s=a.error,a.error=null):c=!0,r===a)return void U(r,new TypeError("A promises callback cannot return that same promise."))}else a=n,c=!0;r._state!==j||(i&&c?q(r,a):u?U(r,s):e===O?E(r,a):e===k&&U(r,a))}var M=0;function $(e){e[S]=M++,e._state=void 0,e._result=void 0,e._subscribers=[]}function L(e,t){this._instanceConstructor=e,this.promise=new e(A),this.promise[S]||$(this.promise),r(t)?(this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?E(this.promise,this._result):(this.length=this.length||0,this._enumerate(t),0===this._remaining&&E(this.promise,this._result))):U(this.promise,new Error("Array Methods must be provided an Array"))}function B(e){this[S]=M++,this._result=this._state=void 0,this._subscribers=[],A!==e&&("function"!=typeof e&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof B?function(e,t){try{t((function(t){q(e,t)}),(function(t){U(e,t)}))}catch(t){U(e,t)}}(this,e):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}return L.prototype._enumerate=function(e){for(var t=0;this._state===j&&t<e.length;t++)this._eachEntry(e[t],t)},L.prototype._eachEntry=function(e,t){var r=this._instanceConstructor,o=r.resolve;if(o===T){var n=C(e);if(n===x&&e._state!==j)this._settledAt(e._state,t,e._result);else if("function"!=typeof n)this._remaining--,this._result[t]=e;else if(r===B){var i=new r(A);I(i,e,n),this._willSettleAt(i,t)}else this._willSettleAt(new r((function(t){return t(e)})),t)}else this._willSettleAt(o(e),t)},L.prototype._settledAt=function(e,t,r){var o=this.promise;o._state===j&&(this._remaining--,e===k?U(o,r):this._result[t]=r),0===this._remaining&&E(o,this._result)},L.prototype._willSettleAt=function(e,t){var r=this;P(e,void 0,(function(e){return r._settledAt(O,t,e)}),(function(e){return r._settledAt(k,t,e)}))},B.all=function(e){return new L(this,e).promise},B.race=function(e){var t=this;return r(e)?new t((function(r,o){for(var n=e.length,i=0;i<n;i++)t.resolve(e[i]).then(r,o)})):new t((function(e,t){return t(new TypeError("You must pass an array to race."))}))},B.resolve=T,B.reject=function(e){var t=new this(A);return U(t,e),t},B._setScheduler=function(e){s=e},B._setAsap=function(e){c=e},B._asap=c,B.prototype={constructor:B,then:x,catch:function(e){return this.then(null,e)}},B.polyfill=function(){var e=void 0;if(void 0!==n)e=n;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(e){throw new Error("polyfill failed because global object is unavailable in this environment")}var t=e.Promise;if(t){var r=null;try{r=Object.prototype.toString.call(t.resolve())}catch(e){}if("[object Promise]"===r&&!t.cast)return}e.Promise=B},B.Promise=B,B}))}).call(this,e(11),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{11:11}],4:[function(e,t,r){var o=Object.prototype.hasOwnProperty,n=Object.prototype.toString;t.exports=function(e,t,r){if("[object Function]"!==n.call(t))throw new TypeError("iterator must be a function");var i=e.length;if(i===+i)for(var a=0;a<i;a++)t.call(r,e[a],a,e);else for(var s in e)o.call(e,s)&&t.call(r,e[s],s,e)}},{}],5:[function(e,t,r){(function(e){var r;r="undefined"!=typeof window?window:void 0!==e?e:"undefined"!=typeof self?self:{},t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],6:[function(e,t,r){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},{}],7:[function(e,t,r){var o={}.toString;t.exports=Array.isArray||function(e){return"[object Array]"==o.call(e)}},{}],8:[function(e,t,r){var o=1e3,n=60*o,i=60*n,a=24*i,s=365.25*a;function c(e,t,r){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+r:Math.ceil(e/t)+" "+r+"s"}t.exports=function(e,t){t=t||{};var r,u=typeof e;if("string"===u&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return r*s;case"days":case"day":case"d":return r*a;case"hours":case"hour":case"hrs":case"hr":case"h":return r*i;case"minutes":case"minute":case"mins":case"min":case"m":return r*n;case"seconds":case"second":case"secs":case"sec":case"s":return r*o;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}(e);if("number"===u&&!1===isNaN(e))return t.long?c(r=e,a,"day")||c(r,i,"hour")||c(r,n,"minute")||c(r,o,"second")||r+" ms":function(e){if(e>=a)return Math.round(e/a)+"d";if(e>=i)return Math.round(e/i)+"h";if(e>=n)return Math.round(e/n)+"m";if(e>=o)return Math.round(e/o)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}],9:[function(e,t,r){"use strict";var o=Object.prototype.hasOwnProperty,n=Object.prototype.toString,i=Array.prototype.slice,a=e(10),s=Object.prototype.propertyIsEnumerable,c=!s.call({toString:null},"toString"),u=s.call((function(){}),"prototype"),l=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],p=function(e){var t=e.constructor;return t&&t.prototype===e},f={$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},d=function(){if("undefined"==typeof window)return!1;for(var e in window)try{if(!f["$"+e]&&o.call(window,e)&&null!==window[e]&&"object"==typeof window[e])try{p(window[e])}catch(e){return!0}}catch(e){return!0}return!1}(),h=function(e){var t=null!==e&&"object"==typeof e,r="[object Function]"===n.call(e),i=a(e),s=t&&"[object String]"===n.call(e),f=[];if(!t&&!r&&!i)throw new TypeError("Object.keys called on a non-object");var h=u&&r;if(s&&e.length>0&&!o.call(e,0))for(var y=0;y<e.length;++y)f.push(String(y));if(i&&e.length>0)for(var m=0;m<e.length;++m)f.push(String(m));else for(var g in e)h&&"prototype"===g||!o.call(e,g)||f.push(String(g));if(c)for(var v=function(e){if("undefined"==typeof window||!d)return p(e);try{return p(e)}catch(e){return!1}}(e),b=0;b<l.length;++b)v&&"constructor"===l[b]||!o.call(e,l[b])||f.push(l[b]);return f};h.shim=function(){if(Object.keys){var e=function(){return 2===(Object.keys(arguments)||"").length}(1,2);if(!e){var t=Object.keys;Object.keys=function(e){return a(e)?t(i.call(e)):t(e)}}}else Object.keys=h;return Object.keys||h},t.exports=h},{10:10}],10:[function(e,t,r){"use strict";var o=Object.prototype.toString;t.exports=function(e){var t=o.call(e),r="[object Arguments]"===t;return r||(r="[object Array]"!==t&&null!==e&&"object"==typeof e&&"number"==typeof e.length&&e.length>=0&&"[object Function]"===o.call(e.callee)),r}},{}],11:[function(e,t,r){var o,n,i=t.exports={};function a(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function c(e){if(o===setTimeout)return setTimeout(e,0);if((o===a||!o)&&setTimeout)return o=setTimeout,setTimeout(e,0);try{return o(e,0)}catch(t){try{return o.call(null,e,0)}catch(t){return o.call(this,e,0)}}}!function(){try{o="function"==typeof setTimeout?setTimeout:a}catch(e){o=a}try{n="function"==typeof clearTimeout?clearTimeout:s}catch(e){n=s}}();var u,l=[],p=!1,f=-1;function d(){p&&u&&(p=!1,u.length?l=u.concat(l):f=-1,l.length&&h())}function h(){if(!p){var e=c(d);p=!0;for(var t=l.length;t;){for(u=l,l=[];++f<t;)u&&u[f].run();f=-1,t=l.length}u=null,p=!1,function(e){if(n===clearTimeout)return clearTimeout(e);if((n===s||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(e);try{return n(e)}catch(t){try{return n.call(null,e)}catch(t){return n.call(this,e)}}}(e)}}function y(e,t){this.fun=e,this.array=t}function m(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];l.push(new y(e,t)),1!==l.length||p||c(h)},y.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=m,i.addListener=m,i.once=m,i.off=m,i.removeListener=m,i.removeAllListeners=m,i.emit=m,i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],12:[function(e,t,r){"use strict";function o(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,r,i){t=t||"&",r=r||"=";var a={};if("string"!=typeof e||0===e.length)return a;var s=/\+/g;e=e.split(t);var c=1e3;i&&"number"==typeof i.maxKeys&&(c=i.maxKeys);var u=e.length;c>0&&u>c&&(u=c);for(var l=0;l<u;++l){var p,f,d,h,y=e[l].replace(s,"%20"),m=y.indexOf(r);m>=0?(p=y.substr(0,m),f=y.substr(m+1)):(p=y,f=""),d=decodeURIComponent(p),h=decodeURIComponent(f),o(a,d)?n(a[d])?a[d].push(h):a[d]=[a[d],h]:a[d]=h}return a};var n=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},{}],13:[function(e,t,r){"use strict";var o=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,r,s){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?i(a(e),(function(a){var s=encodeURIComponent(o(a))+r;return n(e[a])?i(e[a],(function(e){return s+encodeURIComponent(o(e))})).join(t):s+encodeURIComponent(o(e[a]))})).join(t):s?encodeURIComponent(o(s))+r+encodeURIComponent(o(e)):""};var n=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function i(e,t){if(e.map)return e.map(t);for(var r=[],o=0;o<e.length;o++)r.push(t(e[o],o));return r}var a=Object.keys||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t}},{}],14:[function(e,t,r){"use strict";r.decode=r.parse=e(12),r.encode=r.stringify=e(13)},{12:12,13:13}],15:[function(e,t,r){(function(r){t.exports=c;var o=e(25),n=e(26),i=e(16),a=e(31),s=r.env.RESET_APP_DATA_TIMER&&parseInt(r.env.RESET_APP_DATA_TIMER,10)||12e4;function c(t,r,n){var i=e(1)("algoliasearch"),a=e(22),s=e(7),c=e(27),l="Usage: algoliasearch(applicationID, apiKey, opts)";if(!0!==n._allowEmptyCredentials&&!t)throw new o.AlgoliaSearchError("Please provide an application ID. "+l);if(!0!==n._allowEmptyCredentials&&!r)throw new o.AlgoliaSearchError("Please provide an API key. "+l);this.applicationID=t,this.apiKey=r,this.hosts={read:[],write:[]},n=n||{},this._timeouts=n.timeouts||{connect:1e3,read:2e3,write:3e4},n.timeout&&(this._timeouts.connect=this._timeouts.read=this._timeouts.write=n.timeout);var p=n.protocol||"https:";if(/:$/.test(p)||(p+=":"),"http:"!==p&&"https:"!==p)throw new o.AlgoliaSearchError("protocol must be `http:` or `https:` (was `"+n.protocol+"`)");if(this._checkAppIdData(),n.hosts)s(n.hosts)?(this.hosts.read=a(n.hosts),this.hosts.write=a(n.hosts)):(this.hosts.read=a(n.hosts.read),this.hosts.write=a(n.hosts.write));else{var f=c(this._shuffleResult,(function(e){return t+"-"+e+".algolianet.com"})),d=(!1===n.dsn?"":"-dsn")+".algolia.net";this.hosts.read=[this.applicationID+d].concat(f),this.hosts.write=[this.applicationID+".algolia.net"].concat(f)}this.hosts.read=c(this.hosts.read,u(p)),this.hosts.write=c(this.hosts.write,u(p)),this.extraHeaders={},this.cache=n._cache||{},this._ua=n._ua,this._useCache=!(void 0!==n._useCache&&!n._cache)||n._useCache,this._useRequestCache=this._useCache&&n._useRequestCache,this._useFallback=void 0===n.useFallback||n.useFallback,this._setTimeout=n._setTimeout,i("init done, %j",this)}function u(e){return function(t){return e+"//"+t.toLowerCase()}}function l(e){if(void 0===Array.prototype.toJSON)return JSON.stringify(e);var t=Array.prototype.toJSON;delete Array.prototype.toJSON;var r=JSON.stringify(e);return Array.prototype.toJSON=t,r}function p(e){var t={};for(var r in e){var o;if(Object.prototype.hasOwnProperty.call(e,r))o="x-algolia-api-key"===r||"x-algolia-application-id"===r?"**hidden for security purposes**":e[r],t[r]=o}return t}c.prototype.initIndex=function(e){return new i(this,e)},c.prototype.setExtraHeader=function(e,t){this.extraHeaders[e.toLowerCase()]=t},c.prototype.getExtraHeader=function(e){return this.extraHeaders[e.toLowerCase()]},c.prototype.unsetExtraHeader=function(e){delete this.extraHeaders[e.toLowerCase()]},c.prototype.addAlgoliaAgent=function(e){var t="; "+e;-1===this._ua.indexOf(t)&&(this._ua+=t)},c.prototype._jsonRequest=function(t){this._checkAppIdData();var r,i,a,s=e(1)("algoliasearch:"+t.url),c=t.additionalUA||"",u=t.cache,f=this,d=0,h=!1,y=f._useFallback&&f._request.fallback&&t.fallback;this.apiKey.length>500&&void 0!==t.body&&(void 0!==t.body.params||void 0!==t.body.requests)?(t.body.apiKey=this.apiKey,a=this._computeRequestHeaders({additionalUA:c,withApiKey:!1,headers:t.headers})):a=this._computeRequestHeaders({additionalUA:c,headers:t.headers}),void 0!==t.body&&(r=l(t.body)),s("request start");var m=[];function g(e,t,r){return f._useCache&&e&&t&&void 0!==t[r]}function v(e,r){if(g(f._useRequestCache,u,i)&&e.catch((function(){delete u[i]})),"function"!=typeof t.callback)return e.then(r);e.then((function(e){n((function(){t.callback(null,r(e))}),f._setTimeout||setTimeout)}),(function(e){n((function(){t.callback(e)}),f._setTimeout||setTimeout)}))}if(f._useCache&&f._useRequestCache&&(i=t.url),f._useCache&&f._useRequestCache&&r&&(i+="_body_"+r),g(f._useRequestCache,u,i)){s("serving request from cache");var b=u[i];return v("function"!=typeof b.then?f._promise.resolve({responseText:b}):b,(function(e){return JSON.parse(e.responseText)}))}var w=function e(n,v){f._checkAppIdData();var b=new Date;if(f._useCache&&!f._useRequestCache&&(i=t.url),f._useCache&&!f._useRequestCache&&r&&(i+="_body_"+v.body),g(!f._useRequestCache,u,i)){s("serving response from cache");var w=u[i];return f._promise.resolve({body:JSON.parse(w),responseText:w})}if(d>=f.hosts[t.hostType].length)return!y||h?(s("could not get any response"),f._promise.reject(new o.AlgoliaSearchError("Cannot connect to the AlgoliaSearch API. Send an email to support@algolia.com to report and resolve the issue. Application id was: "+f.applicationID,{debugData:m}))):(s("switching to fallback"),d=0,v.method=t.fallback.method,v.url=t.fallback.url,v.jsonBody=t.fallback.body,v.jsonBody&&(v.body=l(v.jsonBody)),a=f._computeRequestHeaders({additionalUA:c,headers:t.headers}),v.timeouts=f._getTimeoutsForRequest(t.hostType),f._setHostIndexByType(0,t.hostType),h=!0,e(f._request.fallback,v));var _=f._getHostByType(t.hostType),x=_+v.url,T={body:v.body,jsonBody:v.jsonBody,method:v.method,headers:a,timeouts:v.timeouts,debug:s,forceAuthHeaders:v.forceAuthHeaders};return s("method: %s, url: %s, headers: %j, timeouts: %d",T.method,x,T.headers,T.timeouts),n===f._request.fallback&&s("using fallback"),n.call(f,x,T).then((function(e){var t=e&&e.body&&e.body.message&&e.body.status||e.statusCode||e&&e.body&&200;s("received response: statusCode: %s, computed statusCode: %d, headers: %j",e.statusCode,t,e.headers);var n=2===Math.floor(t/100),c=new Date;if(m.push({currentHost:_,headers:p(a),content:r||null,contentLength:void 0!==r?r.length:null,method:v.method,timeouts:v.timeouts,url:v.url,startTime:b,endTime:c,duration:c-b,statusCode:t}),n)return f._useCache&&!f._useRequestCache&&u&&(u[i]=e.responseText),{responseText:e.responseText,body:e.body};if(4!==Math.floor(t/100))return d+=1,S();s("unrecoverable error");var l=new o.AlgoliaSearchError(e.body&&e.body.message,{debugData:m,statusCode:t});return f._promise.reject(l)}),(function(i){s("error: %s, stack: %s",i.message,i.stack);var c=new Date;m.push({currentHost:_,headers:p(a),content:r||null,contentLength:void 0!==r?r.length:null,method:v.method,timeouts:v.timeouts,url:v.url,startTime:b,endTime:c,duration:c-b}),i instanceof o.AlgoliaSearchError||(i=new o.Unknown(i&&i.message,i));if(d+=1,i instanceof o.Unknown||i instanceof o.UnparsableJSON||d>=f.hosts[t.hostType].length&&(h||!y))return i.debugData=m,f._promise.reject(i);if(i instanceof o.RequestTimeout)return s("retrying request with higher timeout"),f._incrementHostIndex(t.hostType),f._incrementTimeoutMultipler(),v.timeouts=f._getTimeoutsForRequest(t.hostType),e(n,v);return S()}));function S(){return s("retrying request"),f._incrementHostIndex(t.hostType),e(n,v)}}(f._request,{url:t.url,method:t.method,body:r,jsonBody:t.body,timeouts:f._getTimeoutsForRequest(t.hostType),forceAuthHeaders:t.forceAuthHeaders});return f._useCache&&f._useRequestCache&&u&&(u[i]=w),v(w,(function(e){return e.body}))},c.prototype._getSearchParams=function(e,t){if(null==e)return t;for(var r in e)null!==r&&void 0!==e[r]&&e.hasOwnProperty(r)&&(t+=""===t?"":"&",t+=r+"="+encodeURIComponent("[object Array]"===Object.prototype.toString.call(e[r])?l(e[r]):e[r]));return t},c.prototype._computeRequestHeaders=function(t){var r=e(4),o={"x-algolia-agent":t.additionalUA?this._ua+"; "+t.additionalUA:this._ua,"x-algolia-application-id":this.applicationID};return!1!==t.withApiKey&&(o["x-algolia-api-key"]=this.apiKey),this.userToken&&(o["x-algolia-usertoken"]=this.userToken),this.securityTags&&(o["x-algolia-tagfilters"]=this.securityTags),r(this.extraHeaders,(function(e,t){o[t]=e})),t.headers&&r(t.headers,(function(e,t){o[t]=e})),o},c.prototype.search=function(t,r,o){var n=e(7),i=e(27);if(!n(t))throw new Error("Usage: client.search(arrayOfQueries[, callback])");"function"==typeof r?(o=r,r={}):void 0===r&&(r={});var a=this,s={requests:i(t,(function(e){var t="";return void 0!==e.query&&(t+="query="+encodeURIComponent(e.query)),{indexName:e.indexName,params:a._getSearchParams(e.params,t)}}))},c=i(s.requests,(function(e,t){return t+"="+encodeURIComponent("/1/indexes/"+encodeURIComponent(e.indexName)+"?"+e.params)})).join("&");return void 0!==r.strategy&&(s.strategy=r.strategy),this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:s,hostType:"read",fallback:{method:"GET",url:"/1/indexes/*",body:{params:c}},callback:o})},c.prototype.searchForFacetValues=function(t){var r=e(7),o=e(27),n="Usage: client.searchForFacetValues([{indexName, params: {facetName, facetQuery, ...params}}, ...queries])";if(!r(t))throw new Error(n);var i=this;return i._promise.all(o(t,(function(t){if(!t||void 0===t.indexName||void 0===t.params.facetName||void 0===t.params.facetQuery)throw new Error(n);var r=e(22),o=e(29),a=t.indexName,s=t.params,c=s.facetName,u=o(r(s),(function(e){return"facetName"===e})),l=i._getSearchParams(u,"");return i._jsonRequest({cache:i.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/facets/"+encodeURIComponent(c)+"/query",hostType:"read",body:{params:l}})})))},c.prototype.setSecurityTags=function(e){if("[object Array]"===Object.prototype.toString.call(e)){for(var t=[],r=0;r<e.length;++r)if("[object Array]"===Object.prototype.toString.call(e[r])){for(var o=[],n=0;n<e[r].length;++n)o.push(e[r][n]);t.push("("+o.join(",")+")")}else t.push(e[r]);e=t.join(",")}this.securityTags=e},c.prototype.setUserToken=function(e){this.userToken=e},c.prototype.clearCache=function(){this.cache={}},c.prototype.setRequestTimeout=function(e){e&&(this._timeouts.connect=this._timeouts.read=this._timeouts.write=e)},c.prototype.setTimeouts=function(e){this._timeouts=e},c.prototype.getTimeouts=function(){return this._timeouts},c.prototype._getAppIdData=function(){var e=a.get(this.applicationID);return null!==e&&this._cacheAppIdData(e),e},c.prototype._setAppIdData=function(e){return e.lastChange=(new Date).getTime(),this._cacheAppIdData(e),a.set(this.applicationID,e)},c.prototype._checkAppIdData=function(){var e=this._getAppIdData(),t=(new Date).getTime();return null===e||t-e.lastChange>s?this._resetInitialAppIdData(e):e},c.prototype._resetInitialAppIdData=function(e){var t=e||{};return t.hostIndexes={read:0,write:0},t.timeoutMultiplier=1,t.shuffleResult=t.shuffleResult||function(e){var t,r,o=e.length;for(;0!==o;)r=Math.floor(Math.random()*o),t=e[o-=1],e[o]=e[r],e[r]=t;return e}([1,2,3]),this._setAppIdData(t)},c.prototype._cacheAppIdData=function(e){this._hostIndexes=e.hostIndexes,this._timeoutMultiplier=e.timeoutMultiplier,this._shuffleResult=e.shuffleResult},c.prototype._partialAppIdDataUpdate=function(t){var r=e(4),o=this._getAppIdData();return r(t,(function(e,t){o[t]=e})),this._setAppIdData(o)},c.prototype._getHostByType=function(e){return this.hosts[e][this._getHostIndexByType(e)]},c.prototype._getTimeoutMultiplier=function(){return this._timeoutMultiplier},c.prototype._getHostIndexByType=function(e){return this._hostIndexes[e]},c.prototype._setHostIndexByType=function(t,r){var o=e(22)(this._hostIndexes);return o[r]=t,this._partialAppIdDataUpdate({hostIndexes:o}),t},c.prototype._incrementHostIndex=function(e){return this._setHostIndexByType((this._getHostIndexByType(e)+1)%this.hosts[e].length,e)},c.prototype._incrementTimeoutMultipler=function(){var e=Math.max(this._timeoutMultiplier+1,4);return this._partialAppIdDataUpdate({timeoutMultiplier:e})},c.prototype._getTimeoutsForRequest=function(e){return{connect:this._timeouts.connect*this._timeoutMultiplier,complete:this._timeouts[e]*this._timeoutMultiplier}}}).call(this,e(11))},{1:1,11:11,16:16,22:22,25:25,26:26,27:27,29:29,31:31,4:4,7:7}],16:[function(e,t,r){var o=e(21),n=e(23),i=e(24);function a(e,t){this.indexName=t,this.as=e,this.typeAheadArgs=null,this.typeAheadValueOption=null,this.cache={}}t.exports=a,a.prototype.clearCache=function(){this.cache={}},a.prototype.search=o("query"),a.prototype.similarSearch=n(o("similarQuery"),i("index.similarSearch(query[, callback])","index.search({ similarQuery: query }[, callback])")),a.prototype.browse=function(t,r,o){var n,i,a=e(28);0===arguments.length||1===arguments.length&&"function"==typeof arguments[0]?(n=0,o=arguments[0],t=void 0):"number"==typeof arguments[0]?(n=arguments[0],"number"==typeof arguments[1]?i=arguments[1]:"function"==typeof arguments[1]&&(o=arguments[1],i=void 0),t=void 0,r=void 0):"object"==typeof arguments[0]?("function"==typeof arguments[1]&&(o=arguments[1]),r=arguments[0],t=void 0):"string"==typeof arguments[0]&&"function"==typeof arguments[1]&&(o=arguments[1],r=void 0),r=a({},r||{},{page:n,hitsPerPage:i,query:t});var s=this.as._getSearchParams(r,"");return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/browse",body:{params:s},hostType:"read",callback:o})},a.prototype.browseFrom=function(e,t){return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/browse",body:{cursor:e},hostType:"read",callback:t})},a.prototype.searchForFacetValues=function(t,r){var o=e(22),n=e(29);if(void 0===t.facetName||void 0===t.facetQuery)throw new Error("Usage: index.searchForFacetValues({facetName, facetQuery, ...params}[, callback])");var i=t.facetName,a=n(o(t),(function(e){return"facetName"===e})),s=this.as._getSearchParams(a,"");return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/facets/"+encodeURIComponent(i)+"/query",hostType:"read",body:{params:s},callback:r})},a.prototype.searchFacet=n((function(e,t){return this.searchForFacetValues(e,t)}),i("index.searchFacet(params[, callback])","index.searchForFacetValues(params[, callback])")),a.prototype._search=function(e,t,r,o){return this.as._jsonRequest({cache:this.cache,method:"POST",url:t||"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:{params:e},hostType:"read",fallback:{method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:{params:e}},callback:r,additionalUA:o})},a.prototype.getObject=function(e,t,r){1!==arguments.length&&"function"!=typeof t||(r=t,t=void 0);var o="";if(void 0!==t){o="?attributes=";for(var n=0;n<t.length;++n)0!==n&&(o+=","),o+=t[n]}return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/"+encodeURIComponent(e)+o,hostType:"read",callback:r})},a.prototype.getObjects=function(t,r,o){var n=e(7),i=e(27);if(!n(t))throw new Error("Usage: index.getObjects(arrayOfObjectIDs[, callback])");var a=this;1!==arguments.length&&"function"!=typeof r||(o=r,r=void 0);var s={requests:i(t,(function(e){var t={indexName:a.indexName,objectID:e};return r&&(t.attributesToRetrieve=r.join(",")),t}))};return this.as._jsonRequest({method:"POST",url:"/1/indexes/*/objects",hostType:"read",body:s,callback:o})},a.prototype.as=null,a.prototype.indexName=null,a.prototype.typeAheadArgs=null,a.prototype.typeAheadValueOption=null},{21:21,22:22,23:23,24:24,27:27,28:28,29:29,7:7}],17:[function(e,t,r){"use strict";var o=e(15),n=e(18);t.exports=n(o,"Browser (lite)")},{15:15,18:18}],18:[function(e,t,r){(function(r){"use strict";var o=e(5),n=o.Promise||e(3).Promise;t.exports=function(t,i){var a=e(6),s=e(25),c=e(19),u=e(20),l=e(30);function p(t,r,o){return(o=e(22)(o||{}))._ua=o._ua||p.ua,new d(t,r,o)}i=i||"","debug"===r.env.NODE_ENV&&e(1).enable("algoliasearch*"),p.version=e(32),p.ua="Algolia for JavaScript ("+p.version+"); "+i,p.initPlaces=l(p),o.__algolia={debug:e(1),algoliasearch:p};var f={hasXMLHttpRequest:"XMLHttpRequest"in o,hasXDomainRequest:"XDomainRequest"in o};function d(){t.apply(this,arguments)}return f.hasXMLHttpRequest&&(f.cors="withCredentials"in new XMLHttpRequest),a(d,t),d.prototype._request=function(e,t){return new n((function(r,o){if(f.cors||f.hasXDomainRequest){e=c(e,t.headers);var n,i,a=t.body,u=f.cors?new XMLHttpRequest:new XDomainRequest,l=!1;n=setTimeout(p,t.timeouts.connect),u.onprogress=function(){l||d()},"onreadystatechange"in u&&(u.onreadystatechange=function(){!l&&u.readyState>1&&d()}),u.onload=function(){if(i)return;var e;clearTimeout(n);try{e={body:JSON.parse(u.responseText),responseText:u.responseText,statusCode:u.status,headers:u.getAllResponseHeaders&&u.getAllResponseHeaders()||{}}}catch(t){e=new s.UnparsableJSON({more:u.responseText})}e instanceof s.UnparsableJSON?o(e):r(e)},u.onerror=function(e){if(i)return;clearTimeout(n),o(new s.Network({more:e}))},u instanceof XMLHttpRequest?(u.open(t.method,e,!0),t.forceAuthHeaders&&(u.setRequestHeader("x-algolia-application-id",t.headers["x-algolia-application-id"]),u.setRequestHeader("x-algolia-api-key",t.headers["x-algolia-api-key"]))):u.open(t.method,e),f.cors&&(a&&("POST"===t.method?u.setRequestHeader("content-type","application/x-www-form-urlencoded"):u.setRequestHeader("content-type","application/json")),u.setRequestHeader("accept","application/json")),a?u.send(a):u.send()}else o(new s.Network("CORS not supported"));function p(){i=!0,u.abort(),o(new s.RequestTimeout)}function d(){l=!0,clearTimeout(n),n=setTimeout(p,t.timeouts.complete)}}))},d.prototype._request.fallback=function(e,t){return e=c(e,t.headers),new n((function(r,o){u(e,t,(function(e,t){e?o(e):r(t)}))}))},d.prototype._promise={reject:function(e){return n.reject(e)},resolve:function(e){return n.resolve(e)},delay:function(e){return new n((function(t){setTimeout(t,e)}))},all:function(e){return n.all(e)}},p}}).call(this,e(11))},{1:1,11:11,19:19,20:20,22:22,25:25,3:3,30:30,32:32,5:5,6:6}],19:[function(e,t,r){"use strict";t.exports=function(e,t){/\?/.test(e)?e+="&":e+="?";return e+o(t)};var o=e(13)},{13:13}],20:[function(e,t,r){"use strict";t.exports=function(e,t,r){if("GET"!==t.method)return void r(new Error("Method "+t.method+" "+e+" is not supported by JSONP."));t.debug("JSONP: start");var i=!1,a=!1;n+=1;var s=document.getElementsByTagName("head")[0],c=document.createElement("script"),u="algoliaJSONP_"+n,l=!1;window[u]=function(e){!function(){try{delete window[u],delete window[u+"_loaded"]}catch(e){window[u]=window[u+"_loaded"]=void 0}}(),a?t.debug("JSONP: Late answer, ignoring"):(i=!0,d(),r(null,{body:e,responseText:JSON.stringify(e)}))},e+="&callback="+u,t.jsonBody&&t.jsonBody.params&&(e+="&"+t.jsonBody.params);var p=setTimeout((function(){t.debug("JSONP: Script timeout"),a=!0,d(),r(new o.RequestTimeout)}),t.timeouts.complete);function f(){t.debug("JSONP: success"),l||a||(l=!0,i||(t.debug("JSONP: Fail. Script loaded but did not call the callback"),d(),r(new o.JSONPScriptFail)))}function d(){clearTimeout(p),c.onload=null,c.onreadystatechange=null,c.onerror=null,s.removeChild(c)}c.onreadystatechange=function(){"loaded"!==this.readyState&&"complete"!==this.readyState||f()},c.onload=f,c.onerror=function(){t.debug("JSONP: Script error"),l||a||(d(),r(new o.JSONPScriptError))},c.async=!0,c.defer=!0,c.src=e,s.appendChild(c)};var o=e(25),n=0},{25:25}],21:[function(e,t,r){t.exports=function(e,t){return function(r,n,i){if("function"==typeof r&&"object"==typeof n||"object"==typeof i)throw new o.AlgoliaSearchError("index.search usage is index.search(query, params, cb)");0===arguments.length||"function"==typeof r?(i=r,r=""):1!==arguments.length&&"function"!=typeof n||(i=n,n=void 0),"object"==typeof r&&null!==r?(n=r,r=void 0):null==r&&(r="");var a,s="";return void 0!==r&&(s+=e+"="+encodeURIComponent(r)),void 0!==n&&(n.additionalUA&&(a=n.additionalUA,delete n.additionalUA),s=this.as._getSearchParams(n,s)),this._search(s,t,i,a)}};var o=e(25)},{25:25}],22:[function(e,t,r){t.exports=function(e){return JSON.parse(JSON.stringify(e))}},{}],23:[function(e,t,r){t.exports=function(e,t){var r=!1;return function(){return r||(console.warn(t),r=!0),e.apply(this,arguments)}}},{}],24:[function(e,t,r){t.exports=function(e,t){var r=e.toLowerCase().replace(/[\.\(\)]/g,"");return"algoliasearch: `"+e+"` was replaced by `"+t+"`. Please see https://github.com/algolia/algoliasearch-client-javascript/wiki/Deprecated#"+r}},{}],25:[function(e,t,r){"use strict";var o=e(6);function n(t,r){var o=e(4),n=this;"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):n.stack=(new Error).stack||"Cannot get a stacktrace, browser is too old",this.name="AlgoliaSearchError",this.message=t||"Unknown error",r&&o(r,(function(e,t){n[t]=e}))}function i(e,t){function r(){var r=Array.prototype.slice.call(arguments,0);"string"!=typeof r[0]&&r.unshift(t),n.apply(this,r),this.name="AlgoliaSearch"+e+"Error"}return o(r,n),r}o(n,Error),t.exports={AlgoliaSearchError:n,UnparsableJSON:i("UnparsableJSON","Could not parse the incoming response as JSON, see err.more for details"),RequestTimeout:i("RequestTimeout","Request timed out before getting a response"),Network:i("Network","Network issue, see err.more for details"),JSONPScriptFail:i("JSONPScriptFail","<script> was loaded but did not call our provided callback"),ValidUntilNotFound:i("ValidUntilNotFound","The SecuredAPIKey does not have a validUntil parameter."),JSONPScriptError:i("JSONPScriptError","<script> unable to load due to an `error` event on it"),ObjectNotFound:i("ObjectNotFound","Object not found"),Unknown:i("Unknown","Unknown error occured")}},{4:4,6:6}],26:[function(e,t,r){t.exports=function(e,t){t(e,0)}},{}],27:[function(e,t,r){var o=e(4);t.exports=function(e,t){var r=[];return o(e,(function(o,n){r.push(t(o,n,e))})),r}},{4:4}],28:[function(e,t,r){var o=e(4);t.exports=function e(t){var r=Array.prototype.slice.call(arguments);return o(r,(function(r){for(var o in r)r.hasOwnProperty(o)&&("object"==typeof t[o]&&"object"==typeof r[o]?t[o]=e({},t[o],r[o]):void 0!==r[o]&&(t[o]=r[o]))})),t}},{4:4}],29:[function(e,t,r){t.exports=function(t,r){var o=e(9),n=e(4),i={};return n(o(t),(function(e){!0!==r(e)&&(i[e]=t[e])})),i}},{4:4,9:9}],30:[function(e,t,r){t.exports=function(t){return function(r,i,a){var s=e(22);(a=a&&s(a)||{}).hosts=a.hosts||["places-dsn.algolia.net","places-1.algolianet.com","places-2.algolianet.com","places-3.algolianet.com"],0!==arguments.length&&"object"!=typeof r&&void 0!==r||(r="",i="",a._allowEmptyCredentials=!0);var c=t(r,i,a).initIndex("places");return c.search=n("query","/1/places/query"),c.reverse=function(e,t){var r=o.encode(e);return this.as._jsonRequest({method:"GET",url:"/1/places/reverse?"+r,hostType:"read",callback:t})},c.getObject=function(e,t){return this.as._jsonRequest({method:"GET",url:"/1/places/"+encodeURIComponent(e),hostType:"read",callback:t})},c}};var o=e(14),n=e(21)},{14:14,21:21,22:22}],31:[function(e,t,r){(function(r){var o,n=e(1)("algoliasearch:src/hostIndexState.js"),i="algoliasearch-client-js",a={state:{},set:function(e,t){return this.state[e]=t,this.state[e]},get:function(e){return this.state[e]||null}},s={set:function(e,t){a.set(e,t);try{var o=JSON.parse(r.localStorage[i]);return o[e]=t,r.localStorage[i]=JSON.stringify(o),o[e]}catch(t){return c(e,t)}},get:function(e){try{return JSON.parse(r.localStorage[i])[e]||null}catch(t){return c(e,t)}}};function c(e,t){return n("localStorage failed with",t),function(){try{r.localStorage.removeItem(i)}catch(e){}}(),(o=a).get(e)}function u(e,t){return 1===arguments.length?o.get(e):o.set(e,t)}function l(){try{return"localStorage"in r&&null!==r.localStorage&&(r.localStorage[i]||r.localStorage.setItem(i,JSON.stringify({})),!0)}catch(e){return!1}}o=l()?s:a,t.exports={get:u,set:u,supportsLocalStorage:l}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{1:1}],32:[function(e,t,r){"use strict";t.exports="3.35.1"},{}]},{},[17])(17)}));
|
11
|
+
//# sourceMappingURL=../../maps/assets/algolia/algoliasearchLite.js.map
|