node-consul-service 1.0.51 → 1.0.52

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
@@ -19060,6 +19060,13 @@ async function callService(serviceName, options = {}) {
19060
19060
  }
19061
19061
  }
19062
19062
 
19063
+ function normalizeId(id) {
19064
+ if (id && typeof id === "object" && typeof id.toString === "function") {
19065
+ return id.toString();
19066
+ }
19067
+ return id;
19068
+ }
19069
+
19063
19070
  class DataLinkError extends Error {
19064
19071
  constructor(service, path, originalError) {
19065
19072
  super(`DataLinkError: Failed to fetch from ${service}:${path}`);
@@ -19072,11 +19079,20 @@ class DataLinkError extends Error {
19072
19079
  }
19073
19080
  }
19074
19081
  }
19075
- function normalizeId(id) {
19076
- if (id && typeof id === "object" && typeof id.toString === "function") {
19077
- return id.toString();
19078
- }
19079
- return id;
19082
+ // 🛠 أدوات التعامل مع المسارات
19083
+ function getValueByPath(obj, path) {
19084
+ return path.split(".").reduce((acc, key) => acc === null || acc === void 0 ? void 0 : acc[key], obj);
19085
+ }
19086
+ function setValueByPath(obj, path, value) {
19087
+ const keys = path.split(".");
19088
+ const lastKey = keys.pop();
19089
+ const target = keys.reduce((acc, key) => {
19090
+ if (!acc[key])
19091
+ acc[key] = {};
19092
+ return acc[key];
19093
+ }, obj);
19094
+ if (lastKey)
19095
+ target[lastKey] = value;
19080
19096
  }
19081
19097
  async function dataLink(data, schema) {
19082
19098
  const isArray = Array.isArray(data);
@@ -19088,7 +19104,7 @@ async function dataLink(data, schema) {
19088
19104
  throw new DataLinkError(service, path, new Error(`Invalid path: "${path}". Path must start with "/"`));
19089
19105
  }
19090
19106
  const uniqueIds = Array.from(new Set(sourceData.flatMap((item) => {
19091
- const value = item[filed];
19107
+ const value = getValueByPath(item, filed);
19092
19108
  if (typeof value === "string") {
19093
19109
  if (value.includes(",")) {
19094
19110
  return value.split(",").map((v) => normalizeId(v.trim()));
@@ -19110,7 +19126,6 @@ async function dataLink(data, schema) {
19110
19126
  }
19111
19127
  return [];
19112
19128
  })));
19113
- console.log("🚀 ~ schema.map ~ uniqueIds:", uniqueIds);
19114
19129
  if (uniqueIds.length === 0)
19115
19130
  return;
19116
19131
  let cacheMap = new Map();
@@ -19152,32 +19167,32 @@ async function dataLink(data, schema) {
19152
19167
  }
19153
19168
  }
19154
19169
  for (const item of result) {
19155
- const value = item[filed];
19170
+ const value = getValueByPath(item, filed);
19156
19171
  if (typeof value === "string") {
19157
19172
  if (value.includes(",")) {
19158
19173
  const ids = value.split(",").map((v) => normalizeId(v.trim()));
19159
- item[filed] = ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; });
19174
+ setValueByPath(item, filed, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19160
19175
  }
19161
19176
  else {
19162
19177
  const key = normalizeId(value);
19163
19178
  if (cacheMap.has(key)) {
19164
- item[filed] = cacheMap.get(key);
19179
+ setValueByPath(item, filed, cacheMap.get(key));
19165
19180
  }
19166
19181
  }
19167
19182
  }
19168
19183
  else if (Array.isArray(value)) {
19169
- item[filed] = value.map((id) => {
19184
+ setValueByPath(item, filed, value.map((id) => {
19170
19185
  var _a;
19171
19186
  const key = normalizeId(id);
19172
19187
  return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
19173
- });
19188
+ }));
19174
19189
  }
19175
19190
  else if (value &&
19176
19191
  typeof value === "object" &&
19177
19192
  typeof value.toString === "function") {
19178
19193
  const key = normalizeId(value);
19179
19194
  if (cacheMap.has(key)) {
19180
- item[filed] = cacheMap.get(key);
19195
+ setValueByPath(item, filed, cacheMap.get(key));
19181
19196
  }
19182
19197
  }
19183
19198
  }
package/dist/index.esm.js CHANGED
@@ -19058,6 +19058,13 @@ async function callService(serviceName, options = {}) {
19058
19058
  }
19059
19059
  }
19060
19060
 
19061
+ function normalizeId(id) {
19062
+ if (id && typeof id === "object" && typeof id.toString === "function") {
19063
+ return id.toString();
19064
+ }
19065
+ return id;
19066
+ }
19067
+
19061
19068
  class DataLinkError extends Error {
19062
19069
  constructor(service, path, originalError) {
19063
19070
  super(`DataLinkError: Failed to fetch from ${service}:${path}`);
@@ -19070,11 +19077,20 @@ class DataLinkError extends Error {
19070
19077
  }
19071
19078
  }
19072
19079
  }
19073
- function normalizeId(id) {
19074
- if (id && typeof id === "object" && typeof id.toString === "function") {
19075
- return id.toString();
19076
- }
19077
- return id;
19080
+ // 🛠 أدوات التعامل مع المسارات
19081
+ function getValueByPath(obj, path) {
19082
+ return path.split(".").reduce((acc, key) => acc === null || acc === void 0 ? void 0 : acc[key], obj);
19083
+ }
19084
+ function setValueByPath(obj, path, value) {
19085
+ const keys = path.split(".");
19086
+ const lastKey = keys.pop();
19087
+ const target = keys.reduce((acc, key) => {
19088
+ if (!acc[key])
19089
+ acc[key] = {};
19090
+ return acc[key];
19091
+ }, obj);
19092
+ if (lastKey)
19093
+ target[lastKey] = value;
19078
19094
  }
19079
19095
  async function dataLink(data, schema) {
19080
19096
  const isArray = Array.isArray(data);
@@ -19086,7 +19102,7 @@ async function dataLink(data, schema) {
19086
19102
  throw new DataLinkError(service, path, new Error(`Invalid path: "${path}". Path must start with "/"`));
19087
19103
  }
19088
19104
  const uniqueIds = Array.from(new Set(sourceData.flatMap((item) => {
19089
- const value = item[filed];
19105
+ const value = getValueByPath(item, filed);
19090
19106
  if (typeof value === "string") {
19091
19107
  if (value.includes(",")) {
19092
19108
  return value.split(",").map((v) => normalizeId(v.trim()));
@@ -19108,7 +19124,6 @@ async function dataLink(data, schema) {
19108
19124
  }
19109
19125
  return [];
19110
19126
  })));
19111
- console.log("🚀 ~ schema.map ~ uniqueIds:", uniqueIds);
19112
19127
  if (uniqueIds.length === 0)
19113
19128
  return;
19114
19129
  let cacheMap = new Map();
@@ -19150,32 +19165,32 @@ async function dataLink(data, schema) {
19150
19165
  }
19151
19166
  }
19152
19167
  for (const item of result) {
19153
- const value = item[filed];
19168
+ const value = getValueByPath(item, filed);
19154
19169
  if (typeof value === "string") {
19155
19170
  if (value.includes(",")) {
19156
19171
  const ids = value.split(",").map((v) => normalizeId(v.trim()));
19157
- item[filed] = ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; });
19172
+ setValueByPath(item, filed, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19158
19173
  }
19159
19174
  else {
19160
19175
  const key = normalizeId(value);
19161
19176
  if (cacheMap.has(key)) {
19162
- item[filed] = cacheMap.get(key);
19177
+ setValueByPath(item, filed, cacheMap.get(key));
19163
19178
  }
19164
19179
  }
19165
19180
  }
19166
19181
  else if (Array.isArray(value)) {
19167
- item[filed] = value.map((id) => {
19182
+ setValueByPath(item, filed, value.map((id) => {
19168
19183
  var _a;
19169
19184
  const key = normalizeId(id);
19170
19185
  return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
19171
- });
19186
+ }));
19172
19187
  }
19173
19188
  else if (value &&
19174
19189
  typeof value === "object" &&
19175
19190
  typeof value.toString === "function") {
19176
19191
  const key = normalizeId(value);
19177
19192
  if (cacheMap.has(key)) {
19178
- item[filed] = cacheMap.get(key);
19193
+ setValueByPath(item, filed, cacheMap.get(key));
19179
19194
  }
19180
19195
  }
19181
19196
  }
@@ -0,0 +1 @@
1
+ export declare function normalizeId(id: any): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-consul-service",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",