node-consul-service 1.0.26 → 1.0.28
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 +32 -13
- package/dist/index.esm.js +32 -13
- package/package.json +1 -1
|
@@ -6,5 +6,5 @@ interface LinkSchema {
|
|
|
6
6
|
headers?: AxiosRequestHeaders;
|
|
7
7
|
cacheGetter?: (ids: string[]) => Promise<(any | null)[]>;
|
|
8
8
|
}
|
|
9
|
-
export declare function dataLink(data: any[], schema: LinkSchema[]): Promise<any[]>;
|
|
9
|
+
export declare function dataLink(data: any[] | any, schema: LinkSchema[]): Promise<any[] | any>;
|
|
10
10
|
export {};
|
package/dist/index.cjs.js
CHANGED
|
@@ -19430,16 +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
|
-
const
|
|
19440
|
+
const isArray = Array.isArray(data);
|
|
19441
|
+
const sourceData = isArray ? data : [data];
|
|
19442
|
+
const result = [...sourceData];
|
|
19435
19443
|
await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
|
|
19436
19444
|
var _a;
|
|
19437
|
-
const uniqueIds = Array.from(new Set(
|
|
19445
|
+
const uniqueIds = Array.from(new Set(sourceData.flatMap(item => {
|
|
19438
19446
|
const value = item[filed];
|
|
19439
|
-
if (typeof value === "string"
|
|
19440
|
-
|
|
19441
|
-
|
|
19442
|
-
|
|
19447
|
+
if (typeof value === "string" ||
|
|
19448
|
+
(value && typeof value === "object" && typeof value.toString === "function")) {
|
|
19449
|
+
return [normalizeId(value)];
|
|
19450
|
+
}
|
|
19451
|
+
if (Array.isArray(value)) {
|
|
19452
|
+
return value
|
|
19453
|
+
.filter(v => typeof v === "string" ||
|
|
19454
|
+
(v && typeof v === "object" && typeof v.toString === "function"))
|
|
19455
|
+
.map(v => normalizeId(v));
|
|
19456
|
+
}
|
|
19443
19457
|
return [];
|
|
19444
19458
|
})));
|
|
19445
19459
|
if (uniqueIds.length === 0)
|
|
@@ -19467,11 +19481,10 @@ async function dataLink(data, schema) {
|
|
|
19467
19481
|
headers,
|
|
19468
19482
|
data: { ids: idsToFetch },
|
|
19469
19483
|
});
|
|
19470
|
-
// ✅ لاحظ الفرق هنا
|
|
19471
19484
|
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
19472
19485
|
for (const item of response.data.data) {
|
|
19473
19486
|
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19474
|
-
cacheMap.set(item._id, item);
|
|
19487
|
+
cacheMap.set(normalizeId(item._id), item);
|
|
19475
19488
|
}
|
|
19476
19489
|
}
|
|
19477
19490
|
}
|
|
@@ -19482,17 +19495,23 @@ async function dataLink(data, schema) {
|
|
|
19482
19495
|
}
|
|
19483
19496
|
for (const item of result) {
|
|
19484
19497
|
const value = item[filed];
|
|
19485
|
-
if (typeof value === "string"
|
|
19486
|
-
|
|
19487
|
-
|
|
19498
|
+
if (typeof value === "string" ||
|
|
19499
|
+
(value && typeof value === "object" && typeof value.toString === "function")) {
|
|
19500
|
+
const key = normalizeId(value);
|
|
19501
|
+
if (cacheMap.has(key)) {
|
|
19502
|
+
item[filed] = cacheMap.get(key);
|
|
19488
19503
|
}
|
|
19489
19504
|
}
|
|
19490
19505
|
else if (Array.isArray(value)) {
|
|
19491
|
-
item[filed] = value.map(id => {
|
|
19506
|
+
item[filed] = value.map(id => {
|
|
19507
|
+
var _a;
|
|
19508
|
+
const key = normalizeId(id);
|
|
19509
|
+
return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
|
|
19510
|
+
});
|
|
19492
19511
|
}
|
|
19493
19512
|
}
|
|
19494
19513
|
}));
|
|
19495
|
-
return result;
|
|
19514
|
+
return isArray ? result : result[0];
|
|
19496
19515
|
}
|
|
19497
19516
|
|
|
19498
19517
|
exports.callService = callService;
|
package/dist/index.esm.js
CHANGED
|
@@ -19428,16 +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
|
-
const
|
|
19438
|
+
const isArray = Array.isArray(data);
|
|
19439
|
+
const sourceData = isArray ? data : [data];
|
|
19440
|
+
const result = [...sourceData];
|
|
19433
19441
|
await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
|
|
19434
19442
|
var _a;
|
|
19435
|
-
const uniqueIds = Array.from(new Set(
|
|
19443
|
+
const uniqueIds = Array.from(new Set(sourceData.flatMap(item => {
|
|
19436
19444
|
const value = item[filed];
|
|
19437
|
-
if (typeof value === "string"
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
|
|
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
|
+
}
|
|
19441
19455
|
return [];
|
|
19442
19456
|
})));
|
|
19443
19457
|
if (uniqueIds.length === 0)
|
|
@@ -19465,11 +19479,10 @@ async function dataLink(data, schema) {
|
|
|
19465
19479
|
headers,
|
|
19466
19480
|
data: { ids: idsToFetch },
|
|
19467
19481
|
});
|
|
19468
|
-
// ✅ لاحظ الفرق هنا
|
|
19469
19482
|
if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
19470
19483
|
for (const item of response.data.data) {
|
|
19471
19484
|
if (item === null || item === void 0 ? void 0 : item._id) {
|
|
19472
|
-
cacheMap.set(item._id, item);
|
|
19485
|
+
cacheMap.set(normalizeId(item._id), item);
|
|
19473
19486
|
}
|
|
19474
19487
|
}
|
|
19475
19488
|
}
|
|
@@ -19480,17 +19493,23 @@ async function dataLink(data, schema) {
|
|
|
19480
19493
|
}
|
|
19481
19494
|
for (const item of result) {
|
|
19482
19495
|
const value = item[filed];
|
|
19483
|
-
if (typeof value === "string"
|
|
19484
|
-
|
|
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);
|
|
19486
19501
|
}
|
|
19487
19502
|
}
|
|
19488
19503
|
else if (Array.isArray(value)) {
|
|
19489
|
-
item[filed] = value.map(id => {
|
|
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
|
+
});
|
|
19490
19509
|
}
|
|
19491
19510
|
}
|
|
19492
19511
|
}));
|
|
19493
|
-
return result;
|
|
19512
|
+
return isArray ? result : result[0];
|
|
19494
19513
|
}
|
|
19495
19514
|
|
|
19496
19515
|
export { callService, dataLink, deregisterService, getRandomServiceInstance, getServiceInstances, getServiceUrl, listServices, registerService };
|