node-consul-service 1.0.66 → 1.0.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,13 +1,15 @@
1
1
  import Consul from 'consul';
2
+ import require$$6, { promises } from 'fs';
3
+ import path from 'path';
2
4
  import require$$1 from 'util';
3
5
  import stream, { Readable } from 'stream';
4
- import require$$1$1 from 'path';
5
6
  import require$$3 from 'http';
6
7
  import require$$4 from 'https';
7
8
  import require$$0$1 from 'url';
8
- import require$$6 from 'fs';
9
9
  import crypto from 'crypto';
10
10
  import require$$4$1 from 'assert';
11
+ import require$$1$1 from 'tty';
12
+ import require$$0$2 from 'os';
11
13
  import zlib from 'zlib';
12
14
  import { EventEmitter } from 'events';
13
15
 
@@ -84,6 +86,35 @@ async function deregisterService(id) {
84
86
  console.log(`🛑 Service "${id}" deregistered successfully.`);
85
87
  }
86
88
 
89
+ const LOG_DIR = '/home/log';
90
+ const LOG_FILE = path.join(LOG_DIR, 'detect.log');
91
+ // تأكد من وجود المجلد
92
+ async function ensureLogDir() {
93
+ await promises.mkdir(LOG_DIR, { recursive: true });
94
+ }
95
+ // صيغة السطر
96
+ function formatLogLine(serviceName, instance, elapsedMs) {
97
+ var _a, _b, _c, _d, _e;
98
+ const ts = new Date().toISOString();
99
+ const addr = (_b = (_a = instance.ServiceAddress) !== null && _a !== void 0 ? _a : instance.ServiceAddress) !== null && _b !== void 0 ? _b : 'unknown';
100
+ const port = (_c = instance.ServicePort) !== null && _c !== void 0 ? _c : 'unknown';
101
+ const node = (_d = instance.Node) !== null && _d !== void 0 ? _d : 'N/A';
102
+ const id = (_e = instance.ServiceID) !== null && _e !== void 0 ? _e : 'N/A';
103
+ const elapsed = elapsedMs !== undefined ? ` | Elapsed=${elapsedMs}ms` : '';
104
+ return `${ts} | ${serviceName} | ${addr}:${port} | Node=${node} | ID=${id}${elapsed}\n`;
105
+ }
106
+ // دالة تسجيل
107
+ async function appendDiscoveryLog(serviceName, instance, elapsedMs) {
108
+ try {
109
+ await ensureLogDir();
110
+ const line = formatLogLine(serviceName, instance, elapsedMs);
111
+ await promises.appendFile(LOG_FILE, line, { encoding: 'utf8' });
112
+ }
113
+ catch (err) {
114
+ console.error('❌ Failed to write discovery log:', err);
115
+ }
116
+ }
117
+
87
118
  async function listServices() {
88
119
  const services = await getClient().agent.service.list();
89
120
  return Object.values(services);
@@ -93,11 +124,16 @@ async function getServiceInstances(serviceName) {
93
124
  return services;
94
125
  }
95
126
  async function getRandomServiceInstance(serviceName) {
127
+ const start = Date.now();
96
128
  const instances = await getServiceInstances(serviceName);
97
129
  if (!instances.length)
98
130
  throw new Error(`Service "${serviceName}" not found`);
99
131
  const randomIndex = Math.floor(Math.random() * instances.length);
100
- return instances[randomIndex];
132
+ const instance = instances[randomIndex];
133
+ const elapsed = Date.now() - start;
134
+ // 📌 سجل الإنستانس والمدة المستغرقة
135
+ await appendDiscoveryLog(serviceName, instance, elapsed);
136
+ return instance;
101
137
  }
102
138
  async function getServiceUrl(serviceName) {
103
139
  const instance = await getRandomServiceInstance(serviceName);
@@ -12032,7 +12068,7 @@ function requireMimeTypes () {
12032
12068
  */
12033
12069
 
12034
12070
  var db = requireMimeDb();
12035
- var extname = require$$1$1.extname;
12071
+ var extname = path.extname;
12036
12072
 
12037
12073
  /**
12038
12074
  * Module variables.
@@ -13773,7 +13809,7 @@ function requireForm_data () {
13773
13809
  hasRequiredForm_data = 1;
13774
13810
  var CombinedStream = requireCombined_stream();
13775
13811
  var util = require$$1;
13776
- var path = require$$1$1;
13812
+ var path$1 = path;
13777
13813
  var http = require$$3;
13778
13814
  var https = require$$4;
13779
13815
  var parseUrl = require$$0$1.parse;
@@ -13997,15 +14033,15 @@ function requireForm_data () {
13997
14033
 
13998
14034
  if (typeof options.filepath === 'string') {
13999
14035
  // custom filepath for relative paths
14000
- filename = path.normalize(options.filepath).replace(/\\/g, '/');
14036
+ filename = path$1.normalize(options.filepath).replace(/\\/g, '/');
14001
14037
  } else if (options.filename || value.name || value.path) {
14002
14038
  // custom filename take precedence
14003
14039
  // formidable and the browser add a name property
14004
14040
  // fs- and request- streams have path property
14005
- filename = path.basename(options.filename || value.name || value.path);
14041
+ filename = path$1.basename(options.filename || value.name || value.path);
14006
14042
  } else if (value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
14007
14043
  // or try http response
14008
- filename = path.basename(value.client._httpMessage.path || '');
14044
+ filename = path$1.basename(value.client._httpMessage.path || '');
14009
14045
  }
14010
14046
 
14011
14047
  if (filename) {
@@ -15627,6 +15663,1196 @@ var proxyFromEnv = /*@__PURE__*/getDefaultExportFromCjs(proxyFromEnvExports);
15627
15663
 
15628
15664
  var followRedirects$1 = {exports: {}};
15629
15665
 
15666
+ var src = {exports: {}};
15667
+
15668
+ var browser = {exports: {}};
15669
+
15670
+ /**
15671
+ * Helpers.
15672
+ */
15673
+
15674
+ var ms;
15675
+ var hasRequiredMs;
15676
+
15677
+ function requireMs () {
15678
+ if (hasRequiredMs) return ms;
15679
+ hasRequiredMs = 1;
15680
+ var s = 1000;
15681
+ var m = s * 60;
15682
+ var h = m * 60;
15683
+ var d = h * 24;
15684
+ var w = d * 7;
15685
+ var y = d * 365.25;
15686
+
15687
+ /**
15688
+ * Parse or format the given `val`.
15689
+ *
15690
+ * Options:
15691
+ *
15692
+ * - `long` verbose formatting [false]
15693
+ *
15694
+ * @param {String|Number} val
15695
+ * @param {Object} [options]
15696
+ * @throws {Error} throw an error if val is not a non-empty string or a number
15697
+ * @return {String|Number}
15698
+ * @api public
15699
+ */
15700
+
15701
+ ms = function (val, options) {
15702
+ options = options || {};
15703
+ var type = typeof val;
15704
+ if (type === 'string' && val.length > 0) {
15705
+ return parse(val);
15706
+ } else if (type === 'number' && isFinite(val)) {
15707
+ return options.long ? fmtLong(val) : fmtShort(val);
15708
+ }
15709
+ throw new Error(
15710
+ 'val is not a non-empty string or a valid number. val=' +
15711
+ JSON.stringify(val)
15712
+ );
15713
+ };
15714
+
15715
+ /**
15716
+ * Parse the given `str` and return milliseconds.
15717
+ *
15718
+ * @param {String} str
15719
+ * @return {Number}
15720
+ * @api private
15721
+ */
15722
+
15723
+ function parse(str) {
15724
+ str = String(str);
15725
+ if (str.length > 100) {
15726
+ return;
15727
+ }
15728
+ 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(
15729
+ str
15730
+ );
15731
+ if (!match) {
15732
+ return;
15733
+ }
15734
+ var n = parseFloat(match[1]);
15735
+ var type = (match[2] || 'ms').toLowerCase();
15736
+ switch (type) {
15737
+ case 'years':
15738
+ case 'year':
15739
+ case 'yrs':
15740
+ case 'yr':
15741
+ case 'y':
15742
+ return n * y;
15743
+ case 'weeks':
15744
+ case 'week':
15745
+ case 'w':
15746
+ return n * w;
15747
+ case 'days':
15748
+ case 'day':
15749
+ case 'd':
15750
+ return n * d;
15751
+ case 'hours':
15752
+ case 'hour':
15753
+ case 'hrs':
15754
+ case 'hr':
15755
+ case 'h':
15756
+ return n * h;
15757
+ case 'minutes':
15758
+ case 'minute':
15759
+ case 'mins':
15760
+ case 'min':
15761
+ case 'm':
15762
+ return n * m;
15763
+ case 'seconds':
15764
+ case 'second':
15765
+ case 'secs':
15766
+ case 'sec':
15767
+ case 's':
15768
+ return n * s;
15769
+ case 'milliseconds':
15770
+ case 'millisecond':
15771
+ case 'msecs':
15772
+ case 'msec':
15773
+ case 'ms':
15774
+ return n;
15775
+ default:
15776
+ return undefined;
15777
+ }
15778
+ }
15779
+
15780
+ /**
15781
+ * Short format for `ms`.
15782
+ *
15783
+ * @param {Number} ms
15784
+ * @return {String}
15785
+ * @api private
15786
+ */
15787
+
15788
+ function fmtShort(ms) {
15789
+ var msAbs = Math.abs(ms);
15790
+ if (msAbs >= d) {
15791
+ return Math.round(ms / d) + 'd';
15792
+ }
15793
+ if (msAbs >= h) {
15794
+ return Math.round(ms / h) + 'h';
15795
+ }
15796
+ if (msAbs >= m) {
15797
+ return Math.round(ms / m) + 'm';
15798
+ }
15799
+ if (msAbs >= s) {
15800
+ return Math.round(ms / s) + 's';
15801
+ }
15802
+ return ms + 'ms';
15803
+ }
15804
+
15805
+ /**
15806
+ * Long format for `ms`.
15807
+ *
15808
+ * @param {Number} ms
15809
+ * @return {String}
15810
+ * @api private
15811
+ */
15812
+
15813
+ function fmtLong(ms) {
15814
+ var msAbs = Math.abs(ms);
15815
+ if (msAbs >= d) {
15816
+ return plural(ms, msAbs, d, 'day');
15817
+ }
15818
+ if (msAbs >= h) {
15819
+ return plural(ms, msAbs, h, 'hour');
15820
+ }
15821
+ if (msAbs >= m) {
15822
+ return plural(ms, msAbs, m, 'minute');
15823
+ }
15824
+ if (msAbs >= s) {
15825
+ return plural(ms, msAbs, s, 'second');
15826
+ }
15827
+ return ms + ' ms';
15828
+ }
15829
+
15830
+ /**
15831
+ * Pluralization helper.
15832
+ */
15833
+
15834
+ function plural(ms, msAbs, n, name) {
15835
+ var isPlural = msAbs >= n * 1.5;
15836
+ return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
15837
+ }
15838
+ return ms;
15839
+ }
15840
+
15841
+ var common;
15842
+ var hasRequiredCommon;
15843
+
15844
+ function requireCommon () {
15845
+ if (hasRequiredCommon) return common;
15846
+ hasRequiredCommon = 1;
15847
+ /**
15848
+ * This is the common logic for both the Node.js and web browser
15849
+ * implementations of `debug()`.
15850
+ */
15851
+
15852
+ function setup(env) {
15853
+ createDebug.debug = createDebug;
15854
+ createDebug.default = createDebug;
15855
+ createDebug.coerce = coerce;
15856
+ createDebug.disable = disable;
15857
+ createDebug.enable = enable;
15858
+ createDebug.enabled = enabled;
15859
+ createDebug.humanize = requireMs();
15860
+ createDebug.destroy = destroy;
15861
+
15862
+ Object.keys(env).forEach(key => {
15863
+ createDebug[key] = env[key];
15864
+ });
15865
+
15866
+ /**
15867
+ * The currently active debug mode names, and names to skip.
15868
+ */
15869
+
15870
+ createDebug.names = [];
15871
+ createDebug.skips = [];
15872
+
15873
+ /**
15874
+ * Map of special "%n" handling functions, for the debug "format" argument.
15875
+ *
15876
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
15877
+ */
15878
+ createDebug.formatters = {};
15879
+
15880
+ /**
15881
+ * Selects a color for a debug namespace
15882
+ * @param {String} namespace The namespace string for the debug instance to be colored
15883
+ * @return {Number|String} An ANSI color code for the given namespace
15884
+ * @api private
15885
+ */
15886
+ function selectColor(namespace) {
15887
+ let hash = 0;
15888
+
15889
+ for (let i = 0; i < namespace.length; i++) {
15890
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
15891
+ hash |= 0; // Convert to 32bit integer
15892
+ }
15893
+
15894
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
15895
+ }
15896
+ createDebug.selectColor = selectColor;
15897
+
15898
+ /**
15899
+ * Create a debugger with the given `namespace`.
15900
+ *
15901
+ * @param {String} namespace
15902
+ * @return {Function}
15903
+ * @api public
15904
+ */
15905
+ function createDebug(namespace) {
15906
+ let prevTime;
15907
+ let enableOverride = null;
15908
+ let namespacesCache;
15909
+ let enabledCache;
15910
+
15911
+ function debug(...args) {
15912
+ // Disabled?
15913
+ if (!debug.enabled) {
15914
+ return;
15915
+ }
15916
+
15917
+ const self = debug;
15918
+
15919
+ // Set `diff` timestamp
15920
+ const curr = Number(new Date());
15921
+ const ms = curr - (prevTime || curr);
15922
+ self.diff = ms;
15923
+ self.prev = prevTime;
15924
+ self.curr = curr;
15925
+ prevTime = curr;
15926
+
15927
+ args[0] = createDebug.coerce(args[0]);
15928
+
15929
+ if (typeof args[0] !== 'string') {
15930
+ // Anything else let's inspect with %O
15931
+ args.unshift('%O');
15932
+ }
15933
+
15934
+ // Apply any `formatters` transformations
15935
+ let index = 0;
15936
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
15937
+ // If we encounter an escaped % then don't increase the array index
15938
+ if (match === '%%') {
15939
+ return '%';
15940
+ }
15941
+ index++;
15942
+ const formatter = createDebug.formatters[format];
15943
+ if (typeof formatter === 'function') {
15944
+ const val = args[index];
15945
+ match = formatter.call(self, val);
15946
+
15947
+ // Now we need to remove `args[index]` since it's inlined in the `format`
15948
+ args.splice(index, 1);
15949
+ index--;
15950
+ }
15951
+ return match;
15952
+ });
15953
+
15954
+ // Apply env-specific formatting (colors, etc.)
15955
+ createDebug.formatArgs.call(self, args);
15956
+
15957
+ const logFn = self.log || createDebug.log;
15958
+ logFn.apply(self, args);
15959
+ }
15960
+
15961
+ debug.namespace = namespace;
15962
+ debug.useColors = createDebug.useColors();
15963
+ debug.color = createDebug.selectColor(namespace);
15964
+ debug.extend = extend;
15965
+ debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
15966
+
15967
+ Object.defineProperty(debug, 'enabled', {
15968
+ enumerable: true,
15969
+ configurable: false,
15970
+ get: () => {
15971
+ if (enableOverride !== null) {
15972
+ return enableOverride;
15973
+ }
15974
+ if (namespacesCache !== createDebug.namespaces) {
15975
+ namespacesCache = createDebug.namespaces;
15976
+ enabledCache = createDebug.enabled(namespace);
15977
+ }
15978
+
15979
+ return enabledCache;
15980
+ },
15981
+ set: v => {
15982
+ enableOverride = v;
15983
+ }
15984
+ });
15985
+
15986
+ // Env-specific initialization logic for debug instances
15987
+ if (typeof createDebug.init === 'function') {
15988
+ createDebug.init(debug);
15989
+ }
15990
+
15991
+ return debug;
15992
+ }
15993
+
15994
+ function extend(namespace, delimiter) {
15995
+ const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
15996
+ newDebug.log = this.log;
15997
+ return newDebug;
15998
+ }
15999
+
16000
+ /**
16001
+ * Enables a debug mode by namespaces. This can include modes
16002
+ * separated by a colon and wildcards.
16003
+ *
16004
+ * @param {String} namespaces
16005
+ * @api public
16006
+ */
16007
+ function enable(namespaces) {
16008
+ createDebug.save(namespaces);
16009
+ createDebug.namespaces = namespaces;
16010
+
16011
+ createDebug.names = [];
16012
+ createDebug.skips = [];
16013
+
16014
+ let i;
16015
+ const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
16016
+ const len = split.length;
16017
+
16018
+ for (i = 0; i < len; i++) {
16019
+ if (!split[i]) {
16020
+ // ignore empty strings
16021
+ continue;
16022
+ }
16023
+
16024
+ namespaces = split[i].replace(/\*/g, '.*?');
16025
+
16026
+ if (namespaces[0] === '-') {
16027
+ createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
16028
+ } else {
16029
+ createDebug.names.push(new RegExp('^' + namespaces + '$'));
16030
+ }
16031
+ }
16032
+ }
16033
+
16034
+ /**
16035
+ * Disable debug output.
16036
+ *
16037
+ * @return {String} namespaces
16038
+ * @api public
16039
+ */
16040
+ function disable() {
16041
+ const namespaces = [
16042
+ ...createDebug.names.map(toNamespace),
16043
+ ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
16044
+ ].join(',');
16045
+ createDebug.enable('');
16046
+ return namespaces;
16047
+ }
16048
+
16049
+ /**
16050
+ * Returns true if the given mode name is enabled, false otherwise.
16051
+ *
16052
+ * @param {String} name
16053
+ * @return {Boolean}
16054
+ * @api public
16055
+ */
16056
+ function enabled(name) {
16057
+ if (name[name.length - 1] === '*') {
16058
+ return true;
16059
+ }
16060
+
16061
+ let i;
16062
+ let len;
16063
+
16064
+ for (i = 0, len = createDebug.skips.length; i < len; i++) {
16065
+ if (createDebug.skips[i].test(name)) {
16066
+ return false;
16067
+ }
16068
+ }
16069
+
16070
+ for (i = 0, len = createDebug.names.length; i < len; i++) {
16071
+ if (createDebug.names[i].test(name)) {
16072
+ return true;
16073
+ }
16074
+ }
16075
+
16076
+ return false;
16077
+ }
16078
+
16079
+ /**
16080
+ * Convert regexp to namespace
16081
+ *
16082
+ * @param {RegExp} regxep
16083
+ * @return {String} namespace
16084
+ * @api private
16085
+ */
16086
+ function toNamespace(regexp) {
16087
+ return regexp.toString()
16088
+ .substring(2, regexp.toString().length - 2)
16089
+ .replace(/\.\*\?$/, '*');
16090
+ }
16091
+
16092
+ /**
16093
+ * Coerce `val`.
16094
+ *
16095
+ * @param {Mixed} val
16096
+ * @return {Mixed}
16097
+ * @api private
16098
+ */
16099
+ function coerce(val) {
16100
+ if (val instanceof Error) {
16101
+ return val.stack || val.message;
16102
+ }
16103
+ return val;
16104
+ }
16105
+
16106
+ /**
16107
+ * XXX DO NOT USE. This is a temporary stub function.
16108
+ * XXX It WILL be removed in the next major release.
16109
+ */
16110
+ function destroy() {
16111
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
16112
+ }
16113
+
16114
+ createDebug.enable(createDebug.load());
16115
+
16116
+ return createDebug;
16117
+ }
16118
+
16119
+ common = setup;
16120
+ return common;
16121
+ }
16122
+
16123
+ /* eslint-env browser */
16124
+
16125
+ var hasRequiredBrowser;
16126
+
16127
+ function requireBrowser () {
16128
+ if (hasRequiredBrowser) return browser.exports;
16129
+ hasRequiredBrowser = 1;
16130
+ (function (module, exports) {
16131
+ /**
16132
+ * This is the web browser implementation of `debug()`.
16133
+ */
16134
+
16135
+ exports.formatArgs = formatArgs;
16136
+ exports.save = save;
16137
+ exports.load = load;
16138
+ exports.useColors = useColors;
16139
+ exports.storage = localstorage();
16140
+ exports.destroy = (() => {
16141
+ let warned = false;
16142
+
16143
+ return () => {
16144
+ if (!warned) {
16145
+ warned = true;
16146
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
16147
+ }
16148
+ };
16149
+ })();
16150
+
16151
+ /**
16152
+ * Colors.
16153
+ */
16154
+
16155
+ exports.colors = [
16156
+ '#0000CC',
16157
+ '#0000FF',
16158
+ '#0033CC',
16159
+ '#0033FF',
16160
+ '#0066CC',
16161
+ '#0066FF',
16162
+ '#0099CC',
16163
+ '#0099FF',
16164
+ '#00CC00',
16165
+ '#00CC33',
16166
+ '#00CC66',
16167
+ '#00CC99',
16168
+ '#00CCCC',
16169
+ '#00CCFF',
16170
+ '#3300CC',
16171
+ '#3300FF',
16172
+ '#3333CC',
16173
+ '#3333FF',
16174
+ '#3366CC',
16175
+ '#3366FF',
16176
+ '#3399CC',
16177
+ '#3399FF',
16178
+ '#33CC00',
16179
+ '#33CC33',
16180
+ '#33CC66',
16181
+ '#33CC99',
16182
+ '#33CCCC',
16183
+ '#33CCFF',
16184
+ '#6600CC',
16185
+ '#6600FF',
16186
+ '#6633CC',
16187
+ '#6633FF',
16188
+ '#66CC00',
16189
+ '#66CC33',
16190
+ '#9900CC',
16191
+ '#9900FF',
16192
+ '#9933CC',
16193
+ '#9933FF',
16194
+ '#99CC00',
16195
+ '#99CC33',
16196
+ '#CC0000',
16197
+ '#CC0033',
16198
+ '#CC0066',
16199
+ '#CC0099',
16200
+ '#CC00CC',
16201
+ '#CC00FF',
16202
+ '#CC3300',
16203
+ '#CC3333',
16204
+ '#CC3366',
16205
+ '#CC3399',
16206
+ '#CC33CC',
16207
+ '#CC33FF',
16208
+ '#CC6600',
16209
+ '#CC6633',
16210
+ '#CC9900',
16211
+ '#CC9933',
16212
+ '#CCCC00',
16213
+ '#CCCC33',
16214
+ '#FF0000',
16215
+ '#FF0033',
16216
+ '#FF0066',
16217
+ '#FF0099',
16218
+ '#FF00CC',
16219
+ '#FF00FF',
16220
+ '#FF3300',
16221
+ '#FF3333',
16222
+ '#FF3366',
16223
+ '#FF3399',
16224
+ '#FF33CC',
16225
+ '#FF33FF',
16226
+ '#FF6600',
16227
+ '#FF6633',
16228
+ '#FF9900',
16229
+ '#FF9933',
16230
+ '#FFCC00',
16231
+ '#FFCC33'
16232
+ ];
16233
+
16234
+ /**
16235
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
16236
+ * and the Firebug extension (any Firefox version) are known
16237
+ * to support "%c" CSS customizations.
16238
+ *
16239
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
16240
+ */
16241
+
16242
+ // eslint-disable-next-line complexity
16243
+ function useColors() {
16244
+ // NB: In an Electron preload script, document will be defined but not fully
16245
+ // initialized. Since we know we're in Chrome, we'll just detect this case
16246
+ // explicitly
16247
+ if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
16248
+ return true;
16249
+ }
16250
+
16251
+ // Internet Explorer and Edge do not support colors.
16252
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
16253
+ return false;
16254
+ }
16255
+
16256
+ let m;
16257
+
16258
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
16259
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
16260
+ return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
16261
+ // Is firebug? http://stackoverflow.com/a/398120/376773
16262
+ (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
16263
+ // Is firefox >= v31?
16264
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
16265
+ (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
16266
+ // Double check webkit in userAgent just in case we are in a worker
16267
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
16268
+ }
16269
+
16270
+ /**
16271
+ * Colorize log arguments if enabled.
16272
+ *
16273
+ * @api public
16274
+ */
16275
+
16276
+ function formatArgs(args) {
16277
+ args[0] = (this.useColors ? '%c' : '') +
16278
+ this.namespace +
16279
+ (this.useColors ? ' %c' : ' ') +
16280
+ args[0] +
16281
+ (this.useColors ? '%c ' : ' ') +
16282
+ '+' + module.exports.humanize(this.diff);
16283
+
16284
+ if (!this.useColors) {
16285
+ return;
16286
+ }
16287
+
16288
+ const c = 'color: ' + this.color;
16289
+ args.splice(1, 0, c, 'color: inherit');
16290
+
16291
+ // The final "%c" is somewhat tricky, because there could be other
16292
+ // arguments passed either before or after the %c, so we need to
16293
+ // figure out the correct index to insert the CSS into
16294
+ let index = 0;
16295
+ let lastC = 0;
16296
+ args[0].replace(/%[a-zA-Z%]/g, match => {
16297
+ if (match === '%%') {
16298
+ return;
16299
+ }
16300
+ index++;
16301
+ if (match === '%c') {
16302
+ // We only are interested in the *last* %c
16303
+ // (the user may have provided their own)
16304
+ lastC = index;
16305
+ }
16306
+ });
16307
+
16308
+ args.splice(lastC, 0, c);
16309
+ }
16310
+
16311
+ /**
16312
+ * Invokes `console.debug()` when available.
16313
+ * No-op when `console.debug` is not a "function".
16314
+ * If `console.debug` is not available, falls back
16315
+ * to `console.log`.
16316
+ *
16317
+ * @api public
16318
+ */
16319
+ exports.log = console.debug || console.log || (() => {});
16320
+
16321
+ /**
16322
+ * Save `namespaces`.
16323
+ *
16324
+ * @param {String} namespaces
16325
+ * @api private
16326
+ */
16327
+ function save(namespaces) {
16328
+ try {
16329
+ if (namespaces) {
16330
+ exports.storage.setItem('debug', namespaces);
16331
+ } else {
16332
+ exports.storage.removeItem('debug');
16333
+ }
16334
+ } catch (error) {
16335
+ // Swallow
16336
+ // XXX (@Qix-) should we be logging these?
16337
+ }
16338
+ }
16339
+
16340
+ /**
16341
+ * Load `namespaces`.
16342
+ *
16343
+ * @return {String} returns the previously persisted debug modes
16344
+ * @api private
16345
+ */
16346
+ function load() {
16347
+ let r;
16348
+ try {
16349
+ r = exports.storage.getItem('debug');
16350
+ } catch (error) {
16351
+ // Swallow
16352
+ // XXX (@Qix-) should we be logging these?
16353
+ }
16354
+
16355
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
16356
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
16357
+ r = process.env.DEBUG;
16358
+ }
16359
+
16360
+ return r;
16361
+ }
16362
+
16363
+ /**
16364
+ * Localstorage attempts to return the localstorage.
16365
+ *
16366
+ * This is necessary because safari throws
16367
+ * when a user disables cookies/localstorage
16368
+ * and you attempt to access it.
16369
+ *
16370
+ * @return {LocalStorage}
16371
+ * @api private
16372
+ */
16373
+
16374
+ function localstorage() {
16375
+ try {
16376
+ // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
16377
+ // The Browser also has localStorage in the global context.
16378
+ return localStorage;
16379
+ } catch (error) {
16380
+ // Swallow
16381
+ // XXX (@Qix-) should we be logging these?
16382
+ }
16383
+ }
16384
+
16385
+ module.exports = requireCommon()(exports);
16386
+
16387
+ const {formatters} = module.exports;
16388
+
16389
+ /**
16390
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
16391
+ */
16392
+
16393
+ formatters.j = function (v) {
16394
+ try {
16395
+ return JSON.stringify(v);
16396
+ } catch (error) {
16397
+ return '[UnexpectedJSONParseError]: ' + error.message;
16398
+ }
16399
+ };
16400
+ } (browser, browser.exports));
16401
+ return browser.exports;
16402
+ }
16403
+
16404
+ var node = {exports: {}};
16405
+
16406
+ var hasFlag;
16407
+ var hasRequiredHasFlag;
16408
+
16409
+ function requireHasFlag () {
16410
+ if (hasRequiredHasFlag) return hasFlag;
16411
+ hasRequiredHasFlag = 1;
16412
+
16413
+ hasFlag = (flag, argv = process.argv) => {
16414
+ const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
16415
+ const position = argv.indexOf(prefix + flag);
16416
+ const terminatorPosition = argv.indexOf('--');
16417
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
16418
+ };
16419
+ return hasFlag;
16420
+ }
16421
+
16422
+ var supportsColor_1;
16423
+ var hasRequiredSupportsColor;
16424
+
16425
+ function requireSupportsColor () {
16426
+ if (hasRequiredSupportsColor) return supportsColor_1;
16427
+ hasRequiredSupportsColor = 1;
16428
+ const os = require$$0$2;
16429
+ const tty = require$$1$1;
16430
+ const hasFlag = requireHasFlag();
16431
+
16432
+ const {env} = process;
16433
+
16434
+ let forceColor;
16435
+ if (hasFlag('no-color') ||
16436
+ hasFlag('no-colors') ||
16437
+ hasFlag('color=false') ||
16438
+ hasFlag('color=never')) {
16439
+ forceColor = 0;
16440
+ } else if (hasFlag('color') ||
16441
+ hasFlag('colors') ||
16442
+ hasFlag('color=true') ||
16443
+ hasFlag('color=always')) {
16444
+ forceColor = 1;
16445
+ }
16446
+
16447
+ if ('FORCE_COLOR' in env) {
16448
+ if (env.FORCE_COLOR === 'true') {
16449
+ forceColor = 1;
16450
+ } else if (env.FORCE_COLOR === 'false') {
16451
+ forceColor = 0;
16452
+ } else {
16453
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
16454
+ }
16455
+ }
16456
+
16457
+ function translateLevel(level) {
16458
+ if (level === 0) {
16459
+ return false;
16460
+ }
16461
+
16462
+ return {
16463
+ level,
16464
+ hasBasic: true,
16465
+ has256: level >= 2,
16466
+ has16m: level >= 3
16467
+ };
16468
+ }
16469
+
16470
+ function supportsColor(haveStream, streamIsTTY) {
16471
+ if (forceColor === 0) {
16472
+ return 0;
16473
+ }
16474
+
16475
+ if (hasFlag('color=16m') ||
16476
+ hasFlag('color=full') ||
16477
+ hasFlag('color=truecolor')) {
16478
+ return 3;
16479
+ }
16480
+
16481
+ if (hasFlag('color=256')) {
16482
+ return 2;
16483
+ }
16484
+
16485
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
16486
+ return 0;
16487
+ }
16488
+
16489
+ const min = forceColor || 0;
16490
+
16491
+ if (env.TERM === 'dumb') {
16492
+ return min;
16493
+ }
16494
+
16495
+ if (process.platform === 'win32') {
16496
+ // Windows 10 build 10586 is the first Windows release that supports 256 colors.
16497
+ // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
16498
+ const osRelease = os.release().split('.');
16499
+ if (
16500
+ Number(osRelease[0]) >= 10 &&
16501
+ Number(osRelease[2]) >= 10586
16502
+ ) {
16503
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
16504
+ }
16505
+
16506
+ return 1;
16507
+ }
16508
+
16509
+ if ('CI' in env) {
16510
+ if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
16511
+ return 1;
16512
+ }
16513
+
16514
+ return min;
16515
+ }
16516
+
16517
+ if ('TEAMCITY_VERSION' in env) {
16518
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
16519
+ }
16520
+
16521
+ if (env.COLORTERM === 'truecolor') {
16522
+ return 3;
16523
+ }
16524
+
16525
+ if ('TERM_PROGRAM' in env) {
16526
+ const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
16527
+
16528
+ switch (env.TERM_PROGRAM) {
16529
+ case 'iTerm.app':
16530
+ return version >= 3 ? 3 : 2;
16531
+ case 'Apple_Terminal':
16532
+ return 2;
16533
+ // No default
16534
+ }
16535
+ }
16536
+
16537
+ if (/-256(color)?$/i.test(env.TERM)) {
16538
+ return 2;
16539
+ }
16540
+
16541
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
16542
+ return 1;
16543
+ }
16544
+
16545
+ if ('COLORTERM' in env) {
16546
+ return 1;
16547
+ }
16548
+
16549
+ return min;
16550
+ }
16551
+
16552
+ function getSupportLevel(stream) {
16553
+ const level = supportsColor(stream, stream && stream.isTTY);
16554
+ return translateLevel(level);
16555
+ }
16556
+
16557
+ supportsColor_1 = {
16558
+ supportsColor: getSupportLevel,
16559
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
16560
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
16561
+ };
16562
+ return supportsColor_1;
16563
+ }
16564
+
16565
+ /**
16566
+ * Module dependencies.
16567
+ */
16568
+
16569
+ var hasRequiredNode;
16570
+
16571
+ function requireNode () {
16572
+ if (hasRequiredNode) return node.exports;
16573
+ hasRequiredNode = 1;
16574
+ (function (module, exports) {
16575
+ const tty = require$$1$1;
16576
+ const util = require$$1;
16577
+
16578
+ /**
16579
+ * This is the Node.js implementation of `debug()`.
16580
+ */
16581
+
16582
+ exports.init = init;
16583
+ exports.log = log;
16584
+ exports.formatArgs = formatArgs;
16585
+ exports.save = save;
16586
+ exports.load = load;
16587
+ exports.useColors = useColors;
16588
+ exports.destroy = util.deprecate(
16589
+ () => {},
16590
+ 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
16591
+ );
16592
+
16593
+ /**
16594
+ * Colors.
16595
+ */
16596
+
16597
+ exports.colors = [6, 2, 3, 4, 5, 1];
16598
+
16599
+ try {
16600
+ // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
16601
+ // eslint-disable-next-line import/no-extraneous-dependencies
16602
+ const supportsColor = requireSupportsColor();
16603
+
16604
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
16605
+ exports.colors = [
16606
+ 20,
16607
+ 21,
16608
+ 26,
16609
+ 27,
16610
+ 32,
16611
+ 33,
16612
+ 38,
16613
+ 39,
16614
+ 40,
16615
+ 41,
16616
+ 42,
16617
+ 43,
16618
+ 44,
16619
+ 45,
16620
+ 56,
16621
+ 57,
16622
+ 62,
16623
+ 63,
16624
+ 68,
16625
+ 69,
16626
+ 74,
16627
+ 75,
16628
+ 76,
16629
+ 77,
16630
+ 78,
16631
+ 79,
16632
+ 80,
16633
+ 81,
16634
+ 92,
16635
+ 93,
16636
+ 98,
16637
+ 99,
16638
+ 112,
16639
+ 113,
16640
+ 128,
16641
+ 129,
16642
+ 134,
16643
+ 135,
16644
+ 148,
16645
+ 149,
16646
+ 160,
16647
+ 161,
16648
+ 162,
16649
+ 163,
16650
+ 164,
16651
+ 165,
16652
+ 166,
16653
+ 167,
16654
+ 168,
16655
+ 169,
16656
+ 170,
16657
+ 171,
16658
+ 172,
16659
+ 173,
16660
+ 178,
16661
+ 179,
16662
+ 184,
16663
+ 185,
16664
+ 196,
16665
+ 197,
16666
+ 198,
16667
+ 199,
16668
+ 200,
16669
+ 201,
16670
+ 202,
16671
+ 203,
16672
+ 204,
16673
+ 205,
16674
+ 206,
16675
+ 207,
16676
+ 208,
16677
+ 209,
16678
+ 214,
16679
+ 215,
16680
+ 220,
16681
+ 221
16682
+ ];
16683
+ }
16684
+ } catch (error) {
16685
+ // Swallow - we only care if `supports-color` is available; it doesn't have to be.
16686
+ }
16687
+
16688
+ /**
16689
+ * Build up the default `inspectOpts` object from the environment variables.
16690
+ *
16691
+ * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
16692
+ */
16693
+
16694
+ exports.inspectOpts = Object.keys(process.env).filter(key => {
16695
+ return /^debug_/i.test(key);
16696
+ }).reduce((obj, key) => {
16697
+ // Camel-case
16698
+ const prop = key
16699
+ .substring(6)
16700
+ .toLowerCase()
16701
+ .replace(/_([a-z])/g, (_, k) => {
16702
+ return k.toUpperCase();
16703
+ });
16704
+
16705
+ // Coerce string value into JS value
16706
+ let val = process.env[key];
16707
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
16708
+ val = true;
16709
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
16710
+ val = false;
16711
+ } else if (val === 'null') {
16712
+ val = null;
16713
+ } else {
16714
+ val = Number(val);
16715
+ }
16716
+
16717
+ obj[prop] = val;
16718
+ return obj;
16719
+ }, {});
16720
+
16721
+ /**
16722
+ * Is stdout a TTY? Colored output is enabled when `true`.
16723
+ */
16724
+
16725
+ function useColors() {
16726
+ return 'colors' in exports.inspectOpts ?
16727
+ Boolean(exports.inspectOpts.colors) :
16728
+ tty.isatty(process.stderr.fd);
16729
+ }
16730
+
16731
+ /**
16732
+ * Adds ANSI color escape codes if enabled.
16733
+ *
16734
+ * @api public
16735
+ */
16736
+
16737
+ function formatArgs(args) {
16738
+ const {namespace: name, useColors} = this;
16739
+
16740
+ if (useColors) {
16741
+ const c = this.color;
16742
+ const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
16743
+ const prefix = ` ${colorCode};1m${name} \u001B[0m`;
16744
+
16745
+ args[0] = prefix + args[0].split('\n').join('\n' + prefix);
16746
+ args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
16747
+ } else {
16748
+ args[0] = getDate() + name + ' ' + args[0];
16749
+ }
16750
+ }
16751
+
16752
+ function getDate() {
16753
+ if (exports.inspectOpts.hideDate) {
16754
+ return '';
16755
+ }
16756
+ return new Date().toISOString() + ' ';
16757
+ }
16758
+
16759
+ /**
16760
+ * Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
16761
+ */
16762
+
16763
+ function log(...args) {
16764
+ return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
16765
+ }
16766
+
16767
+ /**
16768
+ * Save `namespaces`.
16769
+ *
16770
+ * @param {String} namespaces
16771
+ * @api private
16772
+ */
16773
+ function save(namespaces) {
16774
+ if (namespaces) {
16775
+ process.env.DEBUG = namespaces;
16776
+ } else {
16777
+ // If you set a process.env field to null or undefined, it gets cast to the
16778
+ // string 'null' or 'undefined'. Just delete instead.
16779
+ delete process.env.DEBUG;
16780
+ }
16781
+ }
16782
+
16783
+ /**
16784
+ * Load `namespaces`.
16785
+ *
16786
+ * @return {String} returns the previously persisted debug modes
16787
+ * @api private
16788
+ */
16789
+
16790
+ function load() {
16791
+ return process.env.DEBUG;
16792
+ }
16793
+
16794
+ /**
16795
+ * Init logic for `debug` instances.
16796
+ *
16797
+ * Create a new `inspectOpts` object in case `useColors` is set
16798
+ * differently for a particular `debug` instance.
16799
+ */
16800
+
16801
+ function init(debug) {
16802
+ debug.inspectOpts = {};
16803
+
16804
+ const keys = Object.keys(exports.inspectOpts);
16805
+ for (let i = 0; i < keys.length; i++) {
16806
+ debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
16807
+ }
16808
+ }
16809
+
16810
+ module.exports = requireCommon()(exports);
16811
+
16812
+ const {formatters} = module.exports;
16813
+
16814
+ /**
16815
+ * Map %o to `util.inspect()`, all on a single line.
16816
+ */
16817
+
16818
+ formatters.o = function (v) {
16819
+ this.inspectOpts.colors = this.useColors;
16820
+ return util.inspect(v, this.inspectOpts)
16821
+ .split('\n')
16822
+ .map(str => str.trim())
16823
+ .join(' ');
16824
+ };
16825
+
16826
+ /**
16827
+ * Map %O to `util.inspect()`, allowing multiple lines if needed.
16828
+ */
16829
+
16830
+ formatters.O = function (v) {
16831
+ this.inspectOpts.colors = this.useColors;
16832
+ return util.inspect(v, this.inspectOpts);
16833
+ };
16834
+ } (node, node.exports));
16835
+ return node.exports;
16836
+ }
16837
+
16838
+ /**
16839
+ * Detect Electron renderer / nwjs process, which is node, but we should
16840
+ * treat as a browser.
16841
+ */
16842
+
16843
+ var hasRequiredSrc;
16844
+
16845
+ function requireSrc () {
16846
+ if (hasRequiredSrc) return src.exports;
16847
+ hasRequiredSrc = 1;
16848
+ if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
16849
+ src.exports = requireBrowser();
16850
+ } else {
16851
+ src.exports = requireNode();
16852
+ }
16853
+ return src.exports;
16854
+ }
16855
+
15630
16856
  var debug_1;
15631
16857
  var hasRequiredDebug;
15632
16858
 
@@ -15639,7 +16865,7 @@ function requireDebug () {
15639
16865
  if (!debug) {
15640
16866
  try {
15641
16867
  /* eslint global-require: off */
15642
- debug = require("debug")("follow-redirects");
16868
+ debug = requireSrc()("follow-redirects");
15643
16869
  }
15644
16870
  catch (error) { /* */ }
15645
16871
  if (typeof debug !== "function") {
@@ -19084,9 +20310,6 @@ function setValueByPath(obj, path, value) {
19084
20310
  }
19085
20311
 
19086
20312
  function applyResolvedValues(item, field, cacheMap) {
19087
- console.log("🚀 ~ applyResolvedValues ~ cacheMap:", cacheMap);
19088
- console.log("🚀 ~ applyResolvedValues ~ field:", field);
19089
- console.log("🚀 ~ applyResolvedValues ~ item:", item);
19090
20313
  // لو القيمة مش موجودة أصلاً، ما نعملش أي حاجة
19091
20314
  if (!hasValueAtPath(item, field))
19092
20315
  return;
@@ -19101,7 +20324,6 @@ function applyResolvedValues(item, field, cacheMap) {
19101
20324
  }
19102
20325
  else {
19103
20326
  const id = normalizeId(value);
19104
- console.log("🚀 ~ applyResolvedValues ~ id:", id);
19105
20327
  if (cacheMap.has(id))
19106
20328
  setValueByPath(item, field, cacheMap.get(id));
19107
20329
  }
@@ -19109,9 +20331,7 @@ function applyResolvedValues(item, field, cacheMap) {
19109
20331
  else if (Array.isArray(value)) {
19110
20332
  setValueByPath(item, field, value.map((id) => {
19111
20333
  var _a;
19112
- console.log("🚀 ~ applyResolvedValues ~ id:", id);
19113
20334
  const key = normalizeId(id);
19114
- console.log("🚀 ~ applyResolvedValues ~ cacheMap:", cacheMap);
19115
20335
  return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
19116
20336
  }));
19117
20337
  }