node-consul-service 1.0.25 → 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 CHANGED
@@ -19432,17 +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 }) => {
19435
+ await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
19436
19436
  var _a;
19437
- const allIds = data.flatMap(item => {
19437
+ const uniqueIds = Array.from(new Set(data.flatMap(item => {
19438
19438
  const value = item[filed];
19439
- if (Array.isArray(value))
19440
- return value;
19441
- if (value != null)
19439
+ if (typeof value === "string")
19442
19440
  return [value];
19441
+ if (Array.isArray(value))
19442
+ return value.filter(v => typeof v === "string");
19443
19443
  return [];
19444
- });
19445
- const uniqueIds = Array.from(new Set(allIds.map(String)));
19444
+ })));
19446
19445
  if (uniqueIds.length === 0)
19447
19446
  return;
19448
19447
  let cacheMap = new Map();
@@ -19465,12 +19464,14 @@ async function dataLink(data, schema) {
19465
19464
  const response = await callService(service, {
19466
19465
  method: "POST",
19467
19466
  path,
19467
+ headers,
19468
19468
  data: { ids: idsToFetch },
19469
19469
  });
19470
- if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
19471
- for (const item of response.data) {
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) {
19472
19473
  if (item === null || item === void 0 ? void 0 : item._id) {
19473
- cacheMap.set(String(item._id), item);
19474
+ cacheMap.set(item._id, item);
19474
19475
  }
19475
19476
  }
19476
19477
  }
@@ -19481,11 +19482,13 @@ async function dataLink(data, schema) {
19481
19482
  }
19482
19483
  for (const item of result) {
19483
19484
  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; });
19485
+ if (typeof value === "string") {
19486
+ if (cacheMap.has(value)) {
19487
+ item[filed] = cacheMap.get(value);
19488
+ }
19486
19489
  }
19487
- else if (value != null) {
19488
- item[filed] = (_a = cacheMap.get(String(value))) !== null && _a !== void 0 ? _a : value;
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; });
19489
19492
  }
19490
19493
  }
19491
19494
  }));
package/dist/index.esm.js CHANGED
@@ -19430,17 +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 }) => {
19433
+ await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
19434
19434
  var _a;
19435
- const allIds = data.flatMap(item => {
19435
+ const uniqueIds = Array.from(new Set(data.flatMap(item => {
19436
19436
  const value = item[filed];
19437
- if (Array.isArray(value))
19438
- return value;
19439
- if (value != null)
19437
+ if (typeof value === "string")
19440
19438
  return [value];
19439
+ if (Array.isArray(value))
19440
+ return value.filter(v => typeof v === "string");
19441
19441
  return [];
19442
- });
19443
- const uniqueIds = Array.from(new Set(allIds.map(String)));
19442
+ })));
19444
19443
  if (uniqueIds.length === 0)
19445
19444
  return;
19446
19445
  let cacheMap = new Map();
@@ -19463,12 +19462,14 @@ async function dataLink(data, schema) {
19463
19462
  const response = await callService(service, {
19464
19463
  method: "POST",
19465
19464
  path,
19465
+ headers,
19466
19466
  data: { ids: idsToFetch },
19467
19467
  });
19468
- if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
19469
- for (const item of response.data) {
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) {
19470
19471
  if (item === null || item === void 0 ? void 0 : item._id) {
19471
- cacheMap.set(String(item._id), item);
19472
+ cacheMap.set(item._id, item);
19472
19473
  }
19473
19474
  }
19474
19475
  }
@@ -19479,11 +19480,13 @@ async function dataLink(data, schema) {
19479
19480
  }
19480
19481
  for (const item of result) {
19481
19482
  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; });
19483
+ if (typeof value === "string") {
19484
+ if (cacheMap.has(value)) {
19485
+ item[filed] = cacheMap.get(value);
19486
+ }
19484
19487
  }
19485
- else if (value != null) {
19486
- item[filed] = (_a = cacheMap.get(String(value))) !== null && _a !== void 0 ? _a : value;
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; });
19487
19490
  }
19488
19491
  }
19489
19492
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-consul-service",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",