node-consul-service 1.0.23 → 1.0.25
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/consul/dataLink.d.ts +2 -0
- package/dist/index.cjs.js +18 -5
- package/dist/index.esm.js +18 -5
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { AxiosRequestHeaders } from "axios";
|
|
1
2
|
interface LinkSchema {
|
|
2
3
|
filed: string;
|
|
3
4
|
service: string;
|
|
4
5
|
path: string;
|
|
6
|
+
headers?: AxiosRequestHeaders;
|
|
5
7
|
cacheGetter?: (ids: string[]) => Promise<(any | null)[]>;
|
|
6
8
|
}
|
|
7
9
|
export declare function dataLink(data: any[], schema: LinkSchema[]): Promise<any[]>;
|
package/dist/index.cjs.js
CHANGED
|
@@ -19433,7 +19433,16 @@ async function callService(serviceName, options = {}) {
|
|
|
19433
19433
|
async function dataLink(data, schema) {
|
|
19434
19434
|
const result = [...data];
|
|
19435
19435
|
await Promise.all(schema.map(async ({ filed, service, path, cacheGetter }) => {
|
|
19436
|
-
|
|
19436
|
+
var _a;
|
|
19437
|
+
const allIds = data.flatMap(item => {
|
|
19438
|
+
const value = item[filed];
|
|
19439
|
+
if (Array.isArray(value))
|
|
19440
|
+
return value;
|
|
19441
|
+
if (value != null)
|
|
19442
|
+
return [value];
|
|
19443
|
+
return [];
|
|
19444
|
+
});
|
|
19445
|
+
const uniqueIds = Array.from(new Set(allIds.map(String)));
|
|
19437
19446
|
if (uniqueIds.length === 0)
|
|
19438
19447
|
return;
|
|
19439
19448
|
let cacheMap = new Map();
|
|
@@ -19451,7 +19460,7 @@ async function dataLink(data, schema) {
|
|
|
19451
19460
|
}
|
|
19452
19461
|
});
|
|
19453
19462
|
}
|
|
19454
|
-
if (
|
|
19463
|
+
if (idsToFetch.length > 0) {
|
|
19455
19464
|
try {
|
|
19456
19465
|
const response = await callService(service, {
|
|
19457
19466
|
method: "POST",
|
|
@@ -19461,7 +19470,7 @@ async function dataLink(data, schema) {
|
|
|
19461
19470
|
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
|
|
19462
19471
|
for (const item of response.data) {
|
|
19463
19472
|
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19464
|
-
cacheMap.set(item._id, item);
|
|
19473
|
+
cacheMap.set(String(item._id), item);
|
|
19465
19474
|
}
|
|
19466
19475
|
}
|
|
19467
19476
|
}
|
|
@@ -19471,8 +19480,12 @@ async function dataLink(data, schema) {
|
|
|
19471
19480
|
}
|
|
19472
19481
|
}
|
|
19473
19482
|
for (const item of result) {
|
|
19474
|
-
|
|
19475
|
-
|
|
19483
|
+
const value = item[filed];
|
|
19484
|
+
if (Array.isArray(value)) {
|
|
19485
|
+
item[filed] = value.map(id => { var _a; return (_a = cacheMap.get(String(id))) !== null && _a !== void 0 ? _a : id; });
|
|
19486
|
+
}
|
|
19487
|
+
else if (value != null) {
|
|
19488
|
+
item[filed] = (_a = cacheMap.get(String(value))) !== null && _a !== void 0 ? _a : value;
|
|
19476
19489
|
}
|
|
19477
19490
|
}
|
|
19478
19491
|
}));
|
package/dist/index.esm.js
CHANGED
|
@@ -19431,7 +19431,16 @@ async function callService(serviceName, options = {}) {
|
|
|
19431
19431
|
async function dataLink(data, schema) {
|
|
19432
19432
|
const result = [...data];
|
|
19433
19433
|
await Promise.all(schema.map(async ({ filed, service, path, cacheGetter }) => {
|
|
19434
|
-
|
|
19434
|
+
var _a;
|
|
19435
|
+
const allIds = data.flatMap(item => {
|
|
19436
|
+
const value = item[filed];
|
|
19437
|
+
if (Array.isArray(value))
|
|
19438
|
+
return value;
|
|
19439
|
+
if (value != null)
|
|
19440
|
+
return [value];
|
|
19441
|
+
return [];
|
|
19442
|
+
});
|
|
19443
|
+
const uniqueIds = Array.from(new Set(allIds.map(String)));
|
|
19435
19444
|
if (uniqueIds.length === 0)
|
|
19436
19445
|
return;
|
|
19437
19446
|
let cacheMap = new Map();
|
|
@@ -19449,7 +19458,7 @@ async function dataLink(data, schema) {
|
|
|
19449
19458
|
}
|
|
19450
19459
|
});
|
|
19451
19460
|
}
|
|
19452
|
-
if (
|
|
19461
|
+
if (idsToFetch.length > 0) {
|
|
19453
19462
|
try {
|
|
19454
19463
|
const response = await callService(service, {
|
|
19455
19464
|
method: "POST",
|
|
@@ -19459,7 +19468,7 @@ async function dataLink(data, schema) {
|
|
|
19459
19468
|
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
|
|
19460
19469
|
for (const item of response.data) {
|
|
19461
19470
|
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19462
|
-
cacheMap.set(item._id, item);
|
|
19471
|
+
cacheMap.set(String(item._id), item);
|
|
19463
19472
|
}
|
|
19464
19473
|
}
|
|
19465
19474
|
}
|
|
@@ -19469,8 +19478,12 @@ async function dataLink(data, schema) {
|
|
|
19469
19478
|
}
|
|
19470
19479
|
}
|
|
19471
19480
|
for (const item of result) {
|
|
19472
|
-
|
|
19473
|
-
|
|
19481
|
+
const value = item[filed];
|
|
19482
|
+
if (Array.isArray(value)) {
|
|
19483
|
+
item[filed] = value.map(id => { var _a; return (_a = cacheMap.get(String(id))) !== null && _a !== void 0 ? _a : id; });
|
|
19484
|
+
}
|
|
19485
|
+
else if (value != null) {
|
|
19486
|
+
item[filed] = (_a = cacheMap.get(String(value))) !== null && _a !== void 0 ? _a : value;
|
|
19474
19487
|
}
|
|
19475
19488
|
}
|
|
19476
19489
|
}));
|