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