node-consul-service 1.0.16 → 1.0.18
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 +1 -1
- package/dist/index.cjs.js +22 -10
- package/dist/index.esm.js +22 -10
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ interface LinkSchema {
|
|
|
2
2
|
filed: string;
|
|
3
3
|
service: string;
|
|
4
4
|
path: string;
|
|
5
|
-
cacheGetter?: (
|
|
5
|
+
cacheGetter?: (ids: string[]) => Promise<(any | null)[]>;
|
|
6
6
|
}
|
|
7
7
|
export declare function dataLink(data: any[], schema: LinkSchema[]): Promise<any[]>;
|
|
8
8
|
export {};
|
package/dist/index.cjs.js
CHANGED
|
@@ -19422,24 +19422,36 @@ async function dataLink(data, schema) {
|
|
|
19422
19422
|
let cacheMap = new Map();
|
|
19423
19423
|
let idsToFetch = uniqueIds;
|
|
19424
19424
|
if (cacheGetter) {
|
|
19425
|
-
const cacheResults = await
|
|
19425
|
+
const cacheResults = await cacheGetter(uniqueIds);
|
|
19426
19426
|
idsToFetch = [];
|
|
19427
19427
|
cacheResults.forEach((item, index) => {
|
|
19428
|
+
const id = uniqueIds[index];
|
|
19428
19429
|
if (item) {
|
|
19429
|
-
cacheMap.set(
|
|
19430
|
+
cacheMap.set(id, item);
|
|
19430
19431
|
}
|
|
19431
19432
|
else {
|
|
19432
|
-
idsToFetch.push(
|
|
19433
|
+
idsToFetch.push(id);
|
|
19433
19434
|
}
|
|
19434
19435
|
});
|
|
19435
19436
|
}
|
|
19436
|
-
if (idsToFetch.length > 0) {
|
|
19437
|
-
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
|
|
19441
|
-
|
|
19442
|
-
|
|
19437
|
+
if (Array.isArray(idsToFetch) && idsToFetch.length > 0) {
|
|
19438
|
+
try {
|
|
19439
|
+
const response = await callService(service, {
|
|
19440
|
+
method: "POST",
|
|
19441
|
+
path,
|
|
19442
|
+
data: { ids: idsToFetch },
|
|
19443
|
+
});
|
|
19444
|
+
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
|
|
19445
|
+
for (const item of response.data) {
|
|
19446
|
+
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19447
|
+
cacheMap.set(item._id, item);
|
|
19448
|
+
}
|
|
19449
|
+
}
|
|
19450
|
+
}
|
|
19451
|
+
}
|
|
19452
|
+
catch (error) {
|
|
19453
|
+
console.error(`❌ Failed to fetch from ${service}${path}:`, error);
|
|
19454
|
+
}
|
|
19443
19455
|
}
|
|
19444
19456
|
for (const item of result) {
|
|
19445
19457
|
if (cacheMap.has(item[filed])) {
|
package/dist/index.esm.js
CHANGED
|
@@ -19420,24 +19420,36 @@ async function dataLink(data, schema) {
|
|
|
19420
19420
|
let cacheMap = new Map();
|
|
19421
19421
|
let idsToFetch = uniqueIds;
|
|
19422
19422
|
if (cacheGetter) {
|
|
19423
|
-
const cacheResults = await
|
|
19423
|
+
const cacheResults = await cacheGetter(uniqueIds);
|
|
19424
19424
|
idsToFetch = [];
|
|
19425
19425
|
cacheResults.forEach((item, index) => {
|
|
19426
|
+
const id = uniqueIds[index];
|
|
19426
19427
|
if (item) {
|
|
19427
|
-
cacheMap.set(
|
|
19428
|
+
cacheMap.set(id, item);
|
|
19428
19429
|
}
|
|
19429
19430
|
else {
|
|
19430
|
-
idsToFetch.push(
|
|
19431
|
+
idsToFetch.push(id);
|
|
19431
19432
|
}
|
|
19432
19433
|
});
|
|
19433
19434
|
}
|
|
19434
|
-
if (idsToFetch.length > 0) {
|
|
19435
|
-
|
|
19436
|
-
|
|
19437
|
-
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
|
|
19435
|
+
if (Array.isArray(idsToFetch) && idsToFetch.length > 0) {
|
|
19436
|
+
try {
|
|
19437
|
+
const response = await callService(service, {
|
|
19438
|
+
method: "POST",
|
|
19439
|
+
path,
|
|
19440
|
+
data: { ids: idsToFetch },
|
|
19441
|
+
});
|
|
19442
|
+
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
|
|
19443
|
+
for (const item of response.data) {
|
|
19444
|
+
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19445
|
+
cacheMap.set(item._id, item);
|
|
19446
|
+
}
|
|
19447
|
+
}
|
|
19448
|
+
}
|
|
19449
|
+
}
|
|
19450
|
+
catch (error) {
|
|
19451
|
+
console.error(`❌ Failed to fetch from ${service}${path}:`, error);
|
|
19452
|
+
}
|
|
19441
19453
|
}
|
|
19442
19454
|
for (const item of result) {
|
|
19443
19455
|
if (cacheMap.has(item[filed])) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-consul-service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "rollup -c",
|
|
9
|
-
"dev": "
|
|
9
|
+
"dev": "rollup -c -w",
|
|
10
10
|
"pub": "npm run build && npm version patch && npm publish"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|