node-consul-service 1.0.25 → 1.0.27
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 +35 -15
- package/dist/index.esm.js +35 -15
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -19430,19 +19430,30 @@ async function callService(serviceName, options = {}) {
|
|
|
19430
19430
|
}
|
|
19431
19431
|
}
|
|
19432
19432
|
|
|
19433
|
+
function normalizeId(id) {
|
|
19434
|
+
if (id && typeof id === "object" && typeof id.toString === "function") {
|
|
19435
|
+
return id.toString();
|
|
19436
|
+
}
|
|
19437
|
+
return id;
|
|
19438
|
+
}
|
|
19433
19439
|
async function dataLink(data, schema) {
|
|
19434
19440
|
const result = [...data];
|
|
19435
|
-
await Promise.all(schema.map(async ({ filed, service, path, cacheGetter }) => {
|
|
19441
|
+
await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
|
|
19436
19442
|
var _a;
|
|
19437
|
-
const
|
|
19443
|
+
const uniqueIds = Array.from(new Set(data.flatMap(item => {
|
|
19438
19444
|
const value = item[filed];
|
|
19439
|
-
if (
|
|
19440
|
-
|
|
19441
|
-
|
|
19442
|
-
|
|
19445
|
+
if (typeof value === "string" ||
|
|
19446
|
+
(value && typeof value === "object" && typeof value.toString === "function")) {
|
|
19447
|
+
return [normalizeId(value)];
|
|
19448
|
+
}
|
|
19449
|
+
if (Array.isArray(value)) {
|
|
19450
|
+
return value
|
|
19451
|
+
.filter(v => typeof v === "string" ||
|
|
19452
|
+
(v && typeof v === "object" && typeof v.toString === "function"))
|
|
19453
|
+
.map(v => normalizeId(v));
|
|
19454
|
+
}
|
|
19443
19455
|
return [];
|
|
19444
|
-
});
|
|
19445
|
-
const uniqueIds = Array.from(new Set(allIds.map(String)));
|
|
19456
|
+
})));
|
|
19446
19457
|
if (uniqueIds.length === 0)
|
|
19447
19458
|
return;
|
|
19448
19459
|
let cacheMap = new Map();
|
|
@@ -19465,12 +19476,13 @@ async function dataLink(data, schema) {
|
|
|
19465
19476
|
const response = await callService(service, {
|
|
19466
19477
|
method: "POST",
|
|
19467
19478
|
path,
|
|
19479
|
+
headers,
|
|
19468
19480
|
data: { ids: idsToFetch },
|
|
19469
19481
|
});
|
|
19470
|
-
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
|
|
19471
|
-
for (const item of response.data) {
|
|
19482
|
+
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
19483
|
+
for (const item of response.data.data) {
|
|
19472
19484
|
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19473
|
-
cacheMap.set(
|
|
19485
|
+
cacheMap.set(normalizeId(item._id), item);
|
|
19474
19486
|
}
|
|
19475
19487
|
}
|
|
19476
19488
|
}
|
|
@@ -19481,11 +19493,19 @@ async function dataLink(data, schema) {
|
|
|
19481
19493
|
}
|
|
19482
19494
|
for (const item of result) {
|
|
19483
19495
|
const value = item[filed];
|
|
19484
|
-
if (
|
|
19485
|
-
|
|
19496
|
+
if (typeof value === "string" ||
|
|
19497
|
+
(value && typeof value === "object" && typeof value.toString === "function")) {
|
|
19498
|
+
const key = normalizeId(value);
|
|
19499
|
+
if (cacheMap.has(key)) {
|
|
19500
|
+
item[filed] = cacheMap.get(key);
|
|
19501
|
+
}
|
|
19486
19502
|
}
|
|
19487
|
-
else if (value
|
|
19488
|
-
item[filed] =
|
|
19503
|
+
else if (Array.isArray(value)) {
|
|
19504
|
+
item[filed] = value.map(id => {
|
|
19505
|
+
var _a;
|
|
19506
|
+
const key = normalizeId(id);
|
|
19507
|
+
return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
|
|
19508
|
+
});
|
|
19489
19509
|
}
|
|
19490
19510
|
}
|
|
19491
19511
|
}));
|
package/dist/index.esm.js
CHANGED
|
@@ -19428,19 +19428,30 @@ async function callService(serviceName, options = {}) {
|
|
|
19428
19428
|
}
|
|
19429
19429
|
}
|
|
19430
19430
|
|
|
19431
|
+
function normalizeId(id) {
|
|
19432
|
+
if (id && typeof id === "object" && typeof id.toString === "function") {
|
|
19433
|
+
return id.toString();
|
|
19434
|
+
}
|
|
19435
|
+
return id;
|
|
19436
|
+
}
|
|
19431
19437
|
async function dataLink(data, schema) {
|
|
19432
19438
|
const result = [...data];
|
|
19433
|
-
await Promise.all(schema.map(async ({ filed, service, path, cacheGetter }) => {
|
|
19439
|
+
await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
|
|
19434
19440
|
var _a;
|
|
19435
|
-
const
|
|
19441
|
+
const uniqueIds = Array.from(new Set(data.flatMap(item => {
|
|
19436
19442
|
const value = item[filed];
|
|
19437
|
-
if (
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
|
|
19443
|
+
if (typeof value === "string" ||
|
|
19444
|
+
(value && typeof value === "object" && typeof value.toString === "function")) {
|
|
19445
|
+
return [normalizeId(value)];
|
|
19446
|
+
}
|
|
19447
|
+
if (Array.isArray(value)) {
|
|
19448
|
+
return value
|
|
19449
|
+
.filter(v => typeof v === "string" ||
|
|
19450
|
+
(v && typeof v === "object" && typeof v.toString === "function"))
|
|
19451
|
+
.map(v => normalizeId(v));
|
|
19452
|
+
}
|
|
19441
19453
|
return [];
|
|
19442
|
-
});
|
|
19443
|
-
const uniqueIds = Array.from(new Set(allIds.map(String)));
|
|
19454
|
+
})));
|
|
19444
19455
|
if (uniqueIds.length === 0)
|
|
19445
19456
|
return;
|
|
19446
19457
|
let cacheMap = new Map();
|
|
@@ -19463,12 +19474,13 @@ async function dataLink(data, schema) {
|
|
|
19463
19474
|
const response = await callService(service, {
|
|
19464
19475
|
method: "POST",
|
|
19465
19476
|
path,
|
|
19477
|
+
headers,
|
|
19466
19478
|
data: { ids: idsToFetch },
|
|
19467
19479
|
});
|
|
19468
|
-
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
|
|
19469
|
-
for (const item of response.data) {
|
|
19480
|
+
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
19481
|
+
for (const item of response.data.data) {
|
|
19470
19482
|
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19471
|
-
cacheMap.set(
|
|
19483
|
+
cacheMap.set(normalizeId(item._id), item);
|
|
19472
19484
|
}
|
|
19473
19485
|
}
|
|
19474
19486
|
}
|
|
@@ -19479,11 +19491,19 @@ async function dataLink(data, schema) {
|
|
|
19479
19491
|
}
|
|
19480
19492
|
for (const item of result) {
|
|
19481
19493
|
const value = item[filed];
|
|
19482
|
-
if (
|
|
19483
|
-
|
|
19494
|
+
if (typeof value === "string" ||
|
|
19495
|
+
(value && typeof value === "object" && typeof value.toString === "function")) {
|
|
19496
|
+
const key = normalizeId(value);
|
|
19497
|
+
if (cacheMap.has(key)) {
|
|
19498
|
+
item[filed] = cacheMap.get(key);
|
|
19499
|
+
}
|
|
19484
19500
|
}
|
|
19485
|
-
else if (value
|
|
19486
|
-
item[filed] =
|
|
19501
|
+
else if (Array.isArray(value)) {
|
|
19502
|
+
item[filed] = value.map(id => {
|
|
19503
|
+
var _a;
|
|
19504
|
+
const key = normalizeId(id);
|
|
19505
|
+
return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
|
|
19506
|
+
});
|
|
19487
19507
|
}
|
|
19488
19508
|
}
|
|
19489
19509
|
}));
|