node-consul-service 1.0.26 → 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 CHANGED
@@ -19430,16 +19430,28 @@ 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
19441
  await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
19436
19442
  var _a;
19437
19443
  const uniqueIds = Array.from(new Set(data.flatMap(item => {
19438
19444
  const value = item[filed];
19439
- if (typeof value === "string")
19440
- return [value];
19441
- if (Array.isArray(value))
19442
- return value.filter(v => typeof v === "string");
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
19456
  })));
19445
19457
  if (uniqueIds.length === 0)
@@ -19467,11 +19479,10 @@ async function dataLink(data, schema) {
19467
19479
  headers,
19468
19480
  data: { ids: idsToFetch },
19469
19481
  });
19470
- // ✅ لاحظ الفرق هنا
19471
19482
  if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
19472
19483
  for (const item of response.data.data) {
19473
19484
  if (item === null || item === void 0 ? void 0 : item._id) {
19474
- cacheMap.set(item._id, item);
19485
+ cacheMap.set(normalizeId(item._id), item);
19475
19486
  }
19476
19487
  }
19477
19488
  }
@@ -19482,13 +19493,19 @@ async function dataLink(data, schema) {
19482
19493
  }
19483
19494
  for (const item of result) {
19484
19495
  const value = item[filed];
19485
- if (typeof value === "string") {
19486
- if (cacheMap.has(value)) {
19487
- item[filed] = cacheMap.get(value);
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);
19488
19501
  }
19489
19502
  }
19490
19503
  else if (Array.isArray(value)) {
19491
- item[filed] = value.map(id => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : 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
+ });
19492
19509
  }
19493
19510
  }
19494
19511
  }));
package/dist/index.esm.js CHANGED
@@ -19428,16 +19428,28 @@ 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
19439
  await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
19434
19440
  var _a;
19435
19441
  const uniqueIds = Array.from(new Set(data.flatMap(item => {
19436
19442
  const value = item[filed];
19437
- if (typeof value === "string")
19438
- return [value];
19439
- if (Array.isArray(value))
19440
- return value.filter(v => typeof v === "string");
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
19454
  })));
19443
19455
  if (uniqueIds.length === 0)
@@ -19465,11 +19477,10 @@ async function dataLink(data, schema) {
19465
19477
  headers,
19466
19478
  data: { ids: idsToFetch },
19467
19479
  });
19468
- // ✅ لاحظ الفرق هنا
19469
19480
  if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
19470
19481
  for (const item of response.data.data) {
19471
19482
  if (item === null || item === void 0 ? void 0 : item._id) {
19472
- cacheMap.set(item._id, item);
19483
+ cacheMap.set(normalizeId(item._id), item);
19473
19484
  }
19474
19485
  }
19475
19486
  }
@@ -19480,13 +19491,19 @@ async function dataLink(data, schema) {
19480
19491
  }
19481
19492
  for (const item of result) {
19482
19493
  const value = item[filed];
19483
- if (typeof value === "string") {
19484
- if (cacheMap.has(value)) {
19485
- item[filed] = cacheMap.get(value);
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);
19486
19499
  }
19487
19500
  }
19488
19501
  else if (Array.isArray(value)) {
19489
- item[filed] = value.map(id => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; });
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
+ });
19490
19507
  }
19491
19508
  }
19492
19509
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-consul-service",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",