@waku/core 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -2
- package/bundle/browser-2f1afe46.js +726 -0
- package/bundle/index.js +9166 -12074
- package/bundle/lib/base_protocol.js +108 -0
- package/bundle/lib/message/topic_only_message.js +3 -2
- package/bundle/lib/message/version_0.js +3 -2
- package/bundle/peer_exchange-1229c8b0.js +4302 -0
- package/bundle/{topic_only_message-ece0fef9.js → topic_only_message-e8406994.js} +12 -8
- package/bundle/{version_0-b1fc527d.js → version_0-e9a6cfb0.js} +35 -35
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +21 -0
- package/dist/lib/base_protocol.js +33 -0
- package/dist/lib/base_protocol.js.map +1 -0
- package/dist/lib/connection_manager.d.ts +31 -0
- package/dist/lib/connection_manager.js +146 -0
- package/dist/lib/connection_manager.js.map +1 -0
- package/dist/lib/filter/filter_rpc.d.ts +8 -8
- package/dist/lib/filter/filter_rpc.js +6 -6
- package/dist/lib/filter/index.d.ts +5 -22
- package/dist/lib/filter/index.js +31 -86
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/group_by.d.ts +1 -1
- package/dist/lib/group_by.js.map +1 -1
- package/dist/lib/keep_alive_manager.d.ts +17 -0
- package/dist/lib/keep_alive_manager.js +62 -0
- package/dist/lib/keep_alive_manager.js.map +1 -0
- package/dist/lib/light_push/index.d.ts +3 -19
- package/dist/lib/light_push/index.js +13 -39
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/push_rpc.d.ts +5 -5
- package/dist/lib/light_push/push_rpc.js +6 -6
- package/dist/lib/message/topic_only_message.d.ts +5 -3
- package/dist/lib/message/topic_only_message.js +8 -5
- package/dist/lib/message/topic_only_message.js.map +1 -1
- package/dist/lib/message/version_0.d.ts +12 -12
- package/dist/lib/message/version_0.js +29 -30
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/predefined_bootstrap_nodes.js +1 -1
- package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
- package/dist/lib/relay/index.d.ts +4 -18
- package/dist/lib/relay/index.js +47 -26
- package/dist/lib/relay/index.js.map +1 -1
- package/dist/lib/relay/message_validator.d.ts +4 -0
- package/dist/lib/relay/message_validator.js +25 -0
- package/dist/lib/relay/message_validator.js.map +1 -0
- package/dist/lib/store/history_rpc.d.ts +4 -4
- package/dist/lib/store/history_rpc.js +9 -9
- package/dist/lib/store/history_rpc.js.map +1 -1
- package/dist/lib/store/index.d.ts +4 -25
- package/dist/lib/store/index.js +20 -37
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/to_proto_message.js +3 -2
- package/dist/lib/to_proto_message.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js +12 -23
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.d.ts +8 -15
- package/dist/lib/waku.js +34 -97
- package/dist/lib/waku.js.map +1 -1
- package/package.json +50 -61
- package/src/index.ts +11 -3
- package/src/lib/base_protocol.ts +47 -0
- package/src/lib/connection_manager.ts +220 -0
- package/src/lib/filter/filter_rpc.ts +10 -10
- package/src/lib/filter/index.ts +52 -147
- package/src/lib/group_by.ts +1 -1
- package/src/lib/keep_alive_manager.ts +89 -0
- package/src/lib/light_push/index.ts +17 -78
- package/src/lib/light_push/push_rpc.ts +9 -9
- package/src/lib/message/topic_only_message.ts +11 -5
- package/src/lib/message/version_0.ts +42 -37
- package/src/lib/predefined_bootstrap_nodes.ts +1 -1
- package/src/lib/relay/index.ts +77 -52
- package/src/lib/relay/message_validator.ts +35 -0
- package/src/lib/store/history_rpc.ts +12 -12
- package/src/lib/store/index.ts +30 -84
- package/src/lib/to_proto_message.ts +3 -2
- package/src/lib/wait_for_remote_peer.ts +13 -29
- package/src/lib/waku.ts +54 -136
- package/bundle/peer_exchange-53df2b11.js +0 -11824
- package/dist/lib/random_subset.d.ts +0 -4
- package/dist/lib/random_subset.js +0 -25
- package/dist/lib/random_subset.js.map +0 -1
- package/src/lib/random_subset.ts +0 -30
@@ -0,0 +1,726 @@
|
|
1
|
+
var browserExports = {};
|
2
|
+
var browser = {
|
3
|
+
get exports(){ return browserExports; },
|
4
|
+
set exports(v){ browserExports = v; },
|
5
|
+
};
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Helpers.
|
9
|
+
*/
|
10
|
+
|
11
|
+
var ms;
|
12
|
+
var hasRequiredMs;
|
13
|
+
|
14
|
+
function requireMs () {
|
15
|
+
if (hasRequiredMs) return ms;
|
16
|
+
hasRequiredMs = 1;
|
17
|
+
var s = 1000;
|
18
|
+
var m = s * 60;
|
19
|
+
var h = m * 60;
|
20
|
+
var d = h * 24;
|
21
|
+
var w = d * 7;
|
22
|
+
var y = d * 365.25;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Parse or format the given `val`.
|
26
|
+
*
|
27
|
+
* Options:
|
28
|
+
*
|
29
|
+
* - `long` verbose formatting [false]
|
30
|
+
*
|
31
|
+
* @param {String|Number} val
|
32
|
+
* @param {Object} [options]
|
33
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
34
|
+
* @return {String|Number}
|
35
|
+
* @api public
|
36
|
+
*/
|
37
|
+
|
38
|
+
ms = function(val, options) {
|
39
|
+
options = options || {};
|
40
|
+
var type = typeof val;
|
41
|
+
if (type === 'string' && val.length > 0) {
|
42
|
+
return parse(val);
|
43
|
+
} else if (type === 'number' && isFinite(val)) {
|
44
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
45
|
+
}
|
46
|
+
throw new Error(
|
47
|
+
'val is not a non-empty string or a valid number. val=' +
|
48
|
+
JSON.stringify(val)
|
49
|
+
);
|
50
|
+
};
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Parse the given `str` and return milliseconds.
|
54
|
+
*
|
55
|
+
* @param {String} str
|
56
|
+
* @return {Number}
|
57
|
+
* @api private
|
58
|
+
*/
|
59
|
+
|
60
|
+
function parse(str) {
|
61
|
+
str = String(str);
|
62
|
+
if (str.length > 100) {
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
66
|
+
str
|
67
|
+
);
|
68
|
+
if (!match) {
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
var n = parseFloat(match[1]);
|
72
|
+
var type = (match[2] || 'ms').toLowerCase();
|
73
|
+
switch (type) {
|
74
|
+
case 'years':
|
75
|
+
case 'year':
|
76
|
+
case 'yrs':
|
77
|
+
case 'yr':
|
78
|
+
case 'y':
|
79
|
+
return n * y;
|
80
|
+
case 'weeks':
|
81
|
+
case 'week':
|
82
|
+
case 'w':
|
83
|
+
return n * w;
|
84
|
+
case 'days':
|
85
|
+
case 'day':
|
86
|
+
case 'd':
|
87
|
+
return n * d;
|
88
|
+
case 'hours':
|
89
|
+
case 'hour':
|
90
|
+
case 'hrs':
|
91
|
+
case 'hr':
|
92
|
+
case 'h':
|
93
|
+
return n * h;
|
94
|
+
case 'minutes':
|
95
|
+
case 'minute':
|
96
|
+
case 'mins':
|
97
|
+
case 'min':
|
98
|
+
case 'm':
|
99
|
+
return n * m;
|
100
|
+
case 'seconds':
|
101
|
+
case 'second':
|
102
|
+
case 'secs':
|
103
|
+
case 'sec':
|
104
|
+
case 's':
|
105
|
+
return n * s;
|
106
|
+
case 'milliseconds':
|
107
|
+
case 'millisecond':
|
108
|
+
case 'msecs':
|
109
|
+
case 'msec':
|
110
|
+
case 'ms':
|
111
|
+
return n;
|
112
|
+
default:
|
113
|
+
return undefined;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Short format for `ms`.
|
119
|
+
*
|
120
|
+
* @param {Number} ms
|
121
|
+
* @return {String}
|
122
|
+
* @api private
|
123
|
+
*/
|
124
|
+
|
125
|
+
function fmtShort(ms) {
|
126
|
+
var msAbs = Math.abs(ms);
|
127
|
+
if (msAbs >= d) {
|
128
|
+
return Math.round(ms / d) + 'd';
|
129
|
+
}
|
130
|
+
if (msAbs >= h) {
|
131
|
+
return Math.round(ms / h) + 'h';
|
132
|
+
}
|
133
|
+
if (msAbs >= m) {
|
134
|
+
return Math.round(ms / m) + 'm';
|
135
|
+
}
|
136
|
+
if (msAbs >= s) {
|
137
|
+
return Math.round(ms / s) + 's';
|
138
|
+
}
|
139
|
+
return ms + 'ms';
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Long format for `ms`.
|
144
|
+
*
|
145
|
+
* @param {Number} ms
|
146
|
+
* @return {String}
|
147
|
+
* @api private
|
148
|
+
*/
|
149
|
+
|
150
|
+
function fmtLong(ms) {
|
151
|
+
var msAbs = Math.abs(ms);
|
152
|
+
if (msAbs >= d) {
|
153
|
+
return plural(ms, msAbs, d, 'day');
|
154
|
+
}
|
155
|
+
if (msAbs >= h) {
|
156
|
+
return plural(ms, msAbs, h, 'hour');
|
157
|
+
}
|
158
|
+
if (msAbs >= m) {
|
159
|
+
return plural(ms, msAbs, m, 'minute');
|
160
|
+
}
|
161
|
+
if (msAbs >= s) {
|
162
|
+
return plural(ms, msAbs, s, 'second');
|
163
|
+
}
|
164
|
+
return ms + ' ms';
|
165
|
+
}
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Pluralization helper.
|
169
|
+
*/
|
170
|
+
|
171
|
+
function plural(ms, msAbs, n, name) {
|
172
|
+
var isPlural = msAbs >= n * 1.5;
|
173
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
174
|
+
}
|
175
|
+
return ms;
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* This is the common logic for both the Node.js and web browser
|
180
|
+
* implementations of `debug()`.
|
181
|
+
*/
|
182
|
+
|
183
|
+
function setup(env) {
|
184
|
+
createDebug.debug = createDebug;
|
185
|
+
createDebug.default = createDebug;
|
186
|
+
createDebug.coerce = coerce;
|
187
|
+
createDebug.disable = disable;
|
188
|
+
createDebug.enable = enable;
|
189
|
+
createDebug.enabled = enabled;
|
190
|
+
createDebug.humanize = requireMs();
|
191
|
+
createDebug.destroy = destroy;
|
192
|
+
|
193
|
+
Object.keys(env).forEach(key => {
|
194
|
+
createDebug[key] = env[key];
|
195
|
+
});
|
196
|
+
|
197
|
+
/**
|
198
|
+
* The currently active debug mode names, and names to skip.
|
199
|
+
*/
|
200
|
+
|
201
|
+
createDebug.names = [];
|
202
|
+
createDebug.skips = [];
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
206
|
+
*
|
207
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
208
|
+
*/
|
209
|
+
createDebug.formatters = {};
|
210
|
+
|
211
|
+
/**
|
212
|
+
* Selects a color for a debug namespace
|
213
|
+
* @param {String} namespace The namespace string for the debug instance to be colored
|
214
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
215
|
+
* @api private
|
216
|
+
*/
|
217
|
+
function selectColor(namespace) {
|
218
|
+
let hash = 0;
|
219
|
+
|
220
|
+
for (let i = 0; i < namespace.length; i++) {
|
221
|
+
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
222
|
+
hash |= 0; // Convert to 32bit integer
|
223
|
+
}
|
224
|
+
|
225
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
226
|
+
}
|
227
|
+
createDebug.selectColor = selectColor;
|
228
|
+
|
229
|
+
/**
|
230
|
+
* Create a debugger with the given `namespace`.
|
231
|
+
*
|
232
|
+
* @param {String} namespace
|
233
|
+
* @return {Function}
|
234
|
+
* @api public
|
235
|
+
*/
|
236
|
+
function createDebug(namespace) {
|
237
|
+
let prevTime;
|
238
|
+
let enableOverride = null;
|
239
|
+
let namespacesCache;
|
240
|
+
let enabledCache;
|
241
|
+
|
242
|
+
function debug(...args) {
|
243
|
+
// Disabled?
|
244
|
+
if (!debug.enabled) {
|
245
|
+
return;
|
246
|
+
}
|
247
|
+
|
248
|
+
const self = debug;
|
249
|
+
|
250
|
+
// Set `diff` timestamp
|
251
|
+
const curr = Number(new Date());
|
252
|
+
const ms = curr - (prevTime || curr);
|
253
|
+
self.diff = ms;
|
254
|
+
self.prev = prevTime;
|
255
|
+
self.curr = curr;
|
256
|
+
prevTime = curr;
|
257
|
+
|
258
|
+
args[0] = createDebug.coerce(args[0]);
|
259
|
+
|
260
|
+
if (typeof args[0] !== 'string') {
|
261
|
+
// Anything else let's inspect with %O
|
262
|
+
args.unshift('%O');
|
263
|
+
}
|
264
|
+
|
265
|
+
// Apply any `formatters` transformations
|
266
|
+
let index = 0;
|
267
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
268
|
+
// If we encounter an escaped % then don't increase the array index
|
269
|
+
if (match === '%%') {
|
270
|
+
return '%';
|
271
|
+
}
|
272
|
+
index++;
|
273
|
+
const formatter = createDebug.formatters[format];
|
274
|
+
if (typeof formatter === 'function') {
|
275
|
+
const val = args[index];
|
276
|
+
match = formatter.call(self, val);
|
277
|
+
|
278
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
279
|
+
args.splice(index, 1);
|
280
|
+
index--;
|
281
|
+
}
|
282
|
+
return match;
|
283
|
+
});
|
284
|
+
|
285
|
+
// Apply env-specific formatting (colors, etc.)
|
286
|
+
createDebug.formatArgs.call(self, args);
|
287
|
+
|
288
|
+
const logFn = self.log || createDebug.log;
|
289
|
+
logFn.apply(self, args);
|
290
|
+
}
|
291
|
+
|
292
|
+
debug.namespace = namespace;
|
293
|
+
debug.useColors = createDebug.useColors();
|
294
|
+
debug.color = createDebug.selectColor(namespace);
|
295
|
+
debug.extend = extend;
|
296
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
297
|
+
|
298
|
+
Object.defineProperty(debug, 'enabled', {
|
299
|
+
enumerable: true,
|
300
|
+
configurable: false,
|
301
|
+
get: () => {
|
302
|
+
if (enableOverride !== null) {
|
303
|
+
return enableOverride;
|
304
|
+
}
|
305
|
+
if (namespacesCache !== createDebug.namespaces) {
|
306
|
+
namespacesCache = createDebug.namespaces;
|
307
|
+
enabledCache = createDebug.enabled(namespace);
|
308
|
+
}
|
309
|
+
|
310
|
+
return enabledCache;
|
311
|
+
},
|
312
|
+
set: v => {
|
313
|
+
enableOverride = v;
|
314
|
+
}
|
315
|
+
});
|
316
|
+
|
317
|
+
// Env-specific initialization logic for debug instances
|
318
|
+
if (typeof createDebug.init === 'function') {
|
319
|
+
createDebug.init(debug);
|
320
|
+
}
|
321
|
+
|
322
|
+
return debug;
|
323
|
+
}
|
324
|
+
|
325
|
+
function extend(namespace, delimiter) {
|
326
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
327
|
+
newDebug.log = this.log;
|
328
|
+
return newDebug;
|
329
|
+
}
|
330
|
+
|
331
|
+
/**
|
332
|
+
* Enables a debug mode by namespaces. This can include modes
|
333
|
+
* separated by a colon and wildcards.
|
334
|
+
*
|
335
|
+
* @param {String} namespaces
|
336
|
+
* @api public
|
337
|
+
*/
|
338
|
+
function enable(namespaces) {
|
339
|
+
createDebug.save(namespaces);
|
340
|
+
createDebug.namespaces = namespaces;
|
341
|
+
|
342
|
+
createDebug.names = [];
|
343
|
+
createDebug.skips = [];
|
344
|
+
|
345
|
+
let i;
|
346
|
+
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
347
|
+
const len = split.length;
|
348
|
+
|
349
|
+
for (i = 0; i < len; i++) {
|
350
|
+
if (!split[i]) {
|
351
|
+
// ignore empty strings
|
352
|
+
continue;
|
353
|
+
}
|
354
|
+
|
355
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
356
|
+
|
357
|
+
if (namespaces[0] === '-') {
|
358
|
+
createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
|
359
|
+
} else {
|
360
|
+
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
361
|
+
}
|
362
|
+
}
|
363
|
+
}
|
364
|
+
|
365
|
+
/**
|
366
|
+
* Disable debug output.
|
367
|
+
*
|
368
|
+
* @return {String} namespaces
|
369
|
+
* @api public
|
370
|
+
*/
|
371
|
+
function disable() {
|
372
|
+
const namespaces = [
|
373
|
+
...createDebug.names.map(toNamespace),
|
374
|
+
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
375
|
+
].join(',');
|
376
|
+
createDebug.enable('');
|
377
|
+
return namespaces;
|
378
|
+
}
|
379
|
+
|
380
|
+
/**
|
381
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
382
|
+
*
|
383
|
+
* @param {String} name
|
384
|
+
* @return {Boolean}
|
385
|
+
* @api public
|
386
|
+
*/
|
387
|
+
function enabled(name) {
|
388
|
+
if (name[name.length - 1] === '*') {
|
389
|
+
return true;
|
390
|
+
}
|
391
|
+
|
392
|
+
let i;
|
393
|
+
let len;
|
394
|
+
|
395
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
396
|
+
if (createDebug.skips[i].test(name)) {
|
397
|
+
return false;
|
398
|
+
}
|
399
|
+
}
|
400
|
+
|
401
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
402
|
+
if (createDebug.names[i].test(name)) {
|
403
|
+
return true;
|
404
|
+
}
|
405
|
+
}
|
406
|
+
|
407
|
+
return false;
|
408
|
+
}
|
409
|
+
|
410
|
+
/**
|
411
|
+
* Convert regexp to namespace
|
412
|
+
*
|
413
|
+
* @param {RegExp} regxep
|
414
|
+
* @return {String} namespace
|
415
|
+
* @api private
|
416
|
+
*/
|
417
|
+
function toNamespace(regexp) {
|
418
|
+
return regexp.toString()
|
419
|
+
.substring(2, regexp.toString().length - 2)
|
420
|
+
.replace(/\.\*\?$/, '*');
|
421
|
+
}
|
422
|
+
|
423
|
+
/**
|
424
|
+
* Coerce `val`.
|
425
|
+
*
|
426
|
+
* @param {Mixed} val
|
427
|
+
* @return {Mixed}
|
428
|
+
* @api private
|
429
|
+
*/
|
430
|
+
function coerce(val) {
|
431
|
+
if (val instanceof Error) {
|
432
|
+
return val.stack || val.message;
|
433
|
+
}
|
434
|
+
return val;
|
435
|
+
}
|
436
|
+
|
437
|
+
/**
|
438
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
439
|
+
* XXX It WILL be removed in the next major release.
|
440
|
+
*/
|
441
|
+
function destroy() {
|
442
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
443
|
+
}
|
444
|
+
|
445
|
+
createDebug.enable(createDebug.load());
|
446
|
+
|
447
|
+
return createDebug;
|
448
|
+
}
|
449
|
+
|
450
|
+
var common = setup;
|
451
|
+
|
452
|
+
/* eslint-env browser */
|
453
|
+
|
454
|
+
(function (module, exports) {
|
455
|
+
/**
|
456
|
+
* This is the web browser implementation of `debug()`.
|
457
|
+
*/
|
458
|
+
|
459
|
+
exports.formatArgs = formatArgs;
|
460
|
+
exports.save = save;
|
461
|
+
exports.load = load;
|
462
|
+
exports.useColors = useColors;
|
463
|
+
exports.storage = localstorage();
|
464
|
+
exports.destroy = (() => {
|
465
|
+
let warned = false;
|
466
|
+
|
467
|
+
return () => {
|
468
|
+
if (!warned) {
|
469
|
+
warned = true;
|
470
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
471
|
+
}
|
472
|
+
};
|
473
|
+
})();
|
474
|
+
|
475
|
+
/**
|
476
|
+
* Colors.
|
477
|
+
*/
|
478
|
+
|
479
|
+
exports.colors = [
|
480
|
+
'#0000CC',
|
481
|
+
'#0000FF',
|
482
|
+
'#0033CC',
|
483
|
+
'#0033FF',
|
484
|
+
'#0066CC',
|
485
|
+
'#0066FF',
|
486
|
+
'#0099CC',
|
487
|
+
'#0099FF',
|
488
|
+
'#00CC00',
|
489
|
+
'#00CC33',
|
490
|
+
'#00CC66',
|
491
|
+
'#00CC99',
|
492
|
+
'#00CCCC',
|
493
|
+
'#00CCFF',
|
494
|
+
'#3300CC',
|
495
|
+
'#3300FF',
|
496
|
+
'#3333CC',
|
497
|
+
'#3333FF',
|
498
|
+
'#3366CC',
|
499
|
+
'#3366FF',
|
500
|
+
'#3399CC',
|
501
|
+
'#3399FF',
|
502
|
+
'#33CC00',
|
503
|
+
'#33CC33',
|
504
|
+
'#33CC66',
|
505
|
+
'#33CC99',
|
506
|
+
'#33CCCC',
|
507
|
+
'#33CCFF',
|
508
|
+
'#6600CC',
|
509
|
+
'#6600FF',
|
510
|
+
'#6633CC',
|
511
|
+
'#6633FF',
|
512
|
+
'#66CC00',
|
513
|
+
'#66CC33',
|
514
|
+
'#9900CC',
|
515
|
+
'#9900FF',
|
516
|
+
'#9933CC',
|
517
|
+
'#9933FF',
|
518
|
+
'#99CC00',
|
519
|
+
'#99CC33',
|
520
|
+
'#CC0000',
|
521
|
+
'#CC0033',
|
522
|
+
'#CC0066',
|
523
|
+
'#CC0099',
|
524
|
+
'#CC00CC',
|
525
|
+
'#CC00FF',
|
526
|
+
'#CC3300',
|
527
|
+
'#CC3333',
|
528
|
+
'#CC3366',
|
529
|
+
'#CC3399',
|
530
|
+
'#CC33CC',
|
531
|
+
'#CC33FF',
|
532
|
+
'#CC6600',
|
533
|
+
'#CC6633',
|
534
|
+
'#CC9900',
|
535
|
+
'#CC9933',
|
536
|
+
'#CCCC00',
|
537
|
+
'#CCCC33',
|
538
|
+
'#FF0000',
|
539
|
+
'#FF0033',
|
540
|
+
'#FF0066',
|
541
|
+
'#FF0099',
|
542
|
+
'#FF00CC',
|
543
|
+
'#FF00FF',
|
544
|
+
'#FF3300',
|
545
|
+
'#FF3333',
|
546
|
+
'#FF3366',
|
547
|
+
'#FF3399',
|
548
|
+
'#FF33CC',
|
549
|
+
'#FF33FF',
|
550
|
+
'#FF6600',
|
551
|
+
'#FF6633',
|
552
|
+
'#FF9900',
|
553
|
+
'#FF9933',
|
554
|
+
'#FFCC00',
|
555
|
+
'#FFCC33'
|
556
|
+
];
|
557
|
+
|
558
|
+
/**
|
559
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
560
|
+
* and the Firebug extension (any Firefox version) are known
|
561
|
+
* to support "%c" CSS customizations.
|
562
|
+
*
|
563
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
564
|
+
*/
|
565
|
+
|
566
|
+
// eslint-disable-next-line complexity
|
567
|
+
function useColors() {
|
568
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
569
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
570
|
+
// explicitly
|
571
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
572
|
+
return true;
|
573
|
+
}
|
574
|
+
|
575
|
+
// Internet Explorer and Edge do not support colors.
|
576
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
577
|
+
return false;
|
578
|
+
}
|
579
|
+
|
580
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
581
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
582
|
+
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
583
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
584
|
+
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
585
|
+
// Is firefox >= v31?
|
586
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
587
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
588
|
+
// Double check webkit in userAgent just in case we are in a worker
|
589
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
590
|
+
}
|
591
|
+
|
592
|
+
/**
|
593
|
+
* Colorize log arguments if enabled.
|
594
|
+
*
|
595
|
+
* @api public
|
596
|
+
*/
|
597
|
+
|
598
|
+
function formatArgs(args) {
|
599
|
+
args[0] = (this.useColors ? '%c' : '') +
|
600
|
+
this.namespace +
|
601
|
+
(this.useColors ? ' %c' : ' ') +
|
602
|
+
args[0] +
|
603
|
+
(this.useColors ? '%c ' : ' ') +
|
604
|
+
'+' + module.exports.humanize(this.diff);
|
605
|
+
|
606
|
+
if (!this.useColors) {
|
607
|
+
return;
|
608
|
+
}
|
609
|
+
|
610
|
+
const c = 'color: ' + this.color;
|
611
|
+
args.splice(1, 0, c, 'color: inherit');
|
612
|
+
|
613
|
+
// The final "%c" is somewhat tricky, because there could be other
|
614
|
+
// arguments passed either before or after the %c, so we need to
|
615
|
+
// figure out the correct index to insert the CSS into
|
616
|
+
let index = 0;
|
617
|
+
let lastC = 0;
|
618
|
+
args[0].replace(/%[a-zA-Z%]/g, match => {
|
619
|
+
if (match === '%%') {
|
620
|
+
return;
|
621
|
+
}
|
622
|
+
index++;
|
623
|
+
if (match === '%c') {
|
624
|
+
// We only are interested in the *last* %c
|
625
|
+
// (the user may have provided their own)
|
626
|
+
lastC = index;
|
627
|
+
}
|
628
|
+
});
|
629
|
+
|
630
|
+
args.splice(lastC, 0, c);
|
631
|
+
}
|
632
|
+
|
633
|
+
/**
|
634
|
+
* Invokes `console.debug()` when available.
|
635
|
+
* No-op when `console.debug` is not a "function".
|
636
|
+
* If `console.debug` is not available, falls back
|
637
|
+
* to `console.log`.
|
638
|
+
*
|
639
|
+
* @api public
|
640
|
+
*/
|
641
|
+
exports.log = console.debug || console.log || (() => {});
|
642
|
+
|
643
|
+
/**
|
644
|
+
* Save `namespaces`.
|
645
|
+
*
|
646
|
+
* @param {String} namespaces
|
647
|
+
* @api private
|
648
|
+
*/
|
649
|
+
function save(namespaces) {
|
650
|
+
try {
|
651
|
+
if (namespaces) {
|
652
|
+
exports.storage.setItem('debug', namespaces);
|
653
|
+
} else {
|
654
|
+
exports.storage.removeItem('debug');
|
655
|
+
}
|
656
|
+
} catch (error) {
|
657
|
+
// Swallow
|
658
|
+
// XXX (@Qix-) should we be logging these?
|
659
|
+
}
|
660
|
+
}
|
661
|
+
|
662
|
+
/**
|
663
|
+
* Load `namespaces`.
|
664
|
+
*
|
665
|
+
* @return {String} returns the previously persisted debug modes
|
666
|
+
* @api private
|
667
|
+
*/
|
668
|
+
function load() {
|
669
|
+
let r;
|
670
|
+
try {
|
671
|
+
r = exports.storage.getItem('debug');
|
672
|
+
} catch (error) {
|
673
|
+
// Swallow
|
674
|
+
// XXX (@Qix-) should we be logging these?
|
675
|
+
}
|
676
|
+
|
677
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
678
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
679
|
+
r = process.env.DEBUG;
|
680
|
+
}
|
681
|
+
|
682
|
+
return r;
|
683
|
+
}
|
684
|
+
|
685
|
+
/**
|
686
|
+
* Localstorage attempts to return the localstorage.
|
687
|
+
*
|
688
|
+
* This is necessary because safari throws
|
689
|
+
* when a user disables cookies/localstorage
|
690
|
+
* and you attempt to access it.
|
691
|
+
*
|
692
|
+
* @return {LocalStorage}
|
693
|
+
* @api private
|
694
|
+
*/
|
695
|
+
|
696
|
+
function localstorage() {
|
697
|
+
try {
|
698
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
699
|
+
// The Browser also has localStorage in the global context.
|
700
|
+
return localStorage;
|
701
|
+
} catch (error) {
|
702
|
+
// Swallow
|
703
|
+
// XXX (@Qix-) should we be logging these?
|
704
|
+
}
|
705
|
+
}
|
706
|
+
|
707
|
+
module.exports = common(exports);
|
708
|
+
|
709
|
+
const {formatters} = module.exports;
|
710
|
+
|
711
|
+
/**
|
712
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
713
|
+
*/
|
714
|
+
|
715
|
+
formatters.j = function (v) {
|
716
|
+
try {
|
717
|
+
return JSON.stringify(v);
|
718
|
+
} catch (error) {
|
719
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
720
|
+
}
|
721
|
+
};
|
722
|
+
} (browser, browserExports));
|
723
|
+
|
724
|
+
var debug = browserExports;
|
725
|
+
|
726
|
+
export { debug as d };
|