node-consul-service 1.0.24 → 1.0.26
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.cjs.js +23 -7
- package/dist/index.esm.js +23 -7
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -19432,8 +19432,16 @@ async function callService(serviceName, options = {}) {
|
|
|
19432
19432
|
|
|
19433
19433
|
async function dataLink(data, schema) {
|
|
19434
19434
|
const result = [...data];
|
|
19435
|
-
await Promise.all(schema.map(async ({ filed, service, path, cacheGetter }) => {
|
|
19436
|
-
|
|
19435
|
+
await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
|
|
19436
|
+
var _a;
|
|
19437
|
+
const uniqueIds = Array.from(new Set(data.flatMap(item => {
|
|
19438
|
+
const value = item[filed];
|
|
19439
|
+
if (typeof value === "string")
|
|
19440
|
+
return [value];
|
|
19441
|
+
if (Array.isArray(value))
|
|
19442
|
+
return value.filter(v => typeof v === "string");
|
|
19443
|
+
return [];
|
|
19444
|
+
})));
|
|
19437
19445
|
if (uniqueIds.length === 0)
|
|
19438
19446
|
return;
|
|
19439
19447
|
let cacheMap = new Map();
|
|
@@ -19451,15 +19459,17 @@ async function dataLink(data, schema) {
|
|
|
19451
19459
|
}
|
|
19452
19460
|
});
|
|
19453
19461
|
}
|
|
19454
|
-
if (
|
|
19462
|
+
if (idsToFetch.length > 0) {
|
|
19455
19463
|
try {
|
|
19456
19464
|
const response = await callService(service, {
|
|
19457
19465
|
method: "POST",
|
|
19458
19466
|
path,
|
|
19467
|
+
headers,
|
|
19459
19468
|
data: { ids: idsToFetch },
|
|
19460
19469
|
});
|
|
19461
|
-
|
|
19462
|
-
|
|
19470
|
+
// ✅ لاحظ الفرق هنا
|
|
19471
|
+
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
19472
|
+
for (const item of response.data.data) {
|
|
19463
19473
|
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19464
19474
|
cacheMap.set(item._id, item);
|
|
19465
19475
|
}
|
|
@@ -19471,8 +19481,14 @@ async function dataLink(data, schema) {
|
|
|
19471
19481
|
}
|
|
19472
19482
|
}
|
|
19473
19483
|
for (const item of result) {
|
|
19474
|
-
|
|
19475
|
-
|
|
19484
|
+
const value = item[filed];
|
|
19485
|
+
if (typeof value === "string") {
|
|
19486
|
+
if (cacheMap.has(value)) {
|
|
19487
|
+
item[filed] = cacheMap.get(value);
|
|
19488
|
+
}
|
|
19489
|
+
}
|
|
19490
|
+
else if (Array.isArray(value)) {
|
|
19491
|
+
item[filed] = value.map(id => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; });
|
|
19476
19492
|
}
|
|
19477
19493
|
}
|
|
19478
19494
|
}));
|
package/dist/index.esm.js
CHANGED
|
@@ -19430,8 +19430,16 @@ async function callService(serviceName, options = {}) {
|
|
|
19430
19430
|
|
|
19431
19431
|
async function dataLink(data, schema) {
|
|
19432
19432
|
const result = [...data];
|
|
19433
|
-
await Promise.all(schema.map(async ({ filed, service, path, cacheGetter }) => {
|
|
19434
|
-
|
|
19433
|
+
await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
|
|
19434
|
+
var _a;
|
|
19435
|
+
const uniqueIds = Array.from(new Set(data.flatMap(item => {
|
|
19436
|
+
const value = item[filed];
|
|
19437
|
+
if (typeof value === "string")
|
|
19438
|
+
return [value];
|
|
19439
|
+
if (Array.isArray(value))
|
|
19440
|
+
return value.filter(v => typeof v === "string");
|
|
19441
|
+
return [];
|
|
19442
|
+
})));
|
|
19435
19443
|
if (uniqueIds.length === 0)
|
|
19436
19444
|
return;
|
|
19437
19445
|
let cacheMap = new Map();
|
|
@@ -19449,15 +19457,17 @@ async function dataLink(data, schema) {
|
|
|
19449
19457
|
}
|
|
19450
19458
|
});
|
|
19451
19459
|
}
|
|
19452
|
-
if (
|
|
19460
|
+
if (idsToFetch.length > 0) {
|
|
19453
19461
|
try {
|
|
19454
19462
|
const response = await callService(service, {
|
|
19455
19463
|
method: "POST",
|
|
19456
19464
|
path,
|
|
19465
|
+
headers,
|
|
19457
19466
|
data: { ids: idsToFetch },
|
|
19458
19467
|
});
|
|
19459
|
-
|
|
19460
|
-
|
|
19468
|
+
// ✅ لاحظ الفرق هنا
|
|
19469
|
+
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
19470
|
+
for (const item of response.data.data) {
|
|
19461
19471
|
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19462
19472
|
cacheMap.set(item._id, item);
|
|
19463
19473
|
}
|
|
@@ -19469,8 +19479,14 @@ async function dataLink(data, schema) {
|
|
|
19469
19479
|
}
|
|
19470
19480
|
}
|
|
19471
19481
|
for (const item of result) {
|
|
19472
|
-
|
|
19473
|
-
|
|
19482
|
+
const value = item[filed];
|
|
19483
|
+
if (typeof value === "string") {
|
|
19484
|
+
if (cacheMap.has(value)) {
|
|
19485
|
+
item[filed] = cacheMap.get(value);
|
|
19486
|
+
}
|
|
19487
|
+
}
|
|
19488
|
+
else if (Array.isArray(value)) {
|
|
19489
|
+
item[filed] = value.map(id => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; });
|
|
19474
19490
|
}
|
|
19475
19491
|
}
|
|
19476
19492
|
}));
|