node-consul-service 1.0.54 → 1.0.55
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/README.md +4 -4
- package/dist/consul/dataLink.d.ts +1 -1
- package/dist/index.cjs.js +7 -7
- package/dist/index.esm.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -163,7 +163,7 @@ const data = [
|
|
|
163
163
|
|
|
164
164
|
const schema = [
|
|
165
165
|
{
|
|
166
|
-
|
|
166
|
+
Field: 'userId', // Field name in the original data
|
|
167
167
|
service: 'user-service', // Target service name
|
|
168
168
|
path: '/api/users/batch', // API endpoint path
|
|
169
169
|
cacheGetter: async (ids) => {
|
|
@@ -177,7 +177,7 @@ const result = await dataLink(data, schema);
|
|
|
177
177
|
```
|
|
178
178
|
|
|
179
179
|
#### Schema Properties
|
|
180
|
-
- `
|
|
180
|
+
- `Field`: Field name in the original data that contains the identifier
|
|
181
181
|
- `service`: Name of the service to be called
|
|
182
182
|
- `path`: API endpoint path in the target service
|
|
183
183
|
- `cacheGetter`: Optional function to get data from cache before calling the service
|
|
@@ -216,12 +216,12 @@ const orders = [
|
|
|
216
216
|
|
|
217
217
|
const schema = [
|
|
218
218
|
{
|
|
219
|
-
|
|
219
|
+
Field: 'userId',
|
|
220
220
|
service: 'user-service',
|
|
221
221
|
path: '/api/users/batch'
|
|
222
222
|
},
|
|
223
223
|
{
|
|
224
|
-
|
|
224
|
+
Field: 'productId',
|
|
225
225
|
service: 'product-service',
|
|
226
226
|
path: '/api/products/batch'
|
|
227
227
|
}
|
package/dist/index.cjs.js
CHANGED
|
@@ -19094,12 +19094,12 @@ async function dataLink(data, schema) {
|
|
|
19094
19094
|
const isArray = Array.isArray(data);
|
|
19095
19095
|
const sourceData = isArray ? data : [data];
|
|
19096
19096
|
const result = sourceData.map((item) => ({ ...item }));
|
|
19097
|
-
await Promise.all(schema.map(async ({
|
|
19097
|
+
await Promise.all(schema.map(async ({ field, service, path, headers, cacheGetter }) => {
|
|
19098
19098
|
if (!path || !path.trim().startsWith("/")) {
|
|
19099
19099
|
throw new DataLinkError(service, path, new Error(`Invalid path: "${path}". Path must start with "/"`));
|
|
19100
19100
|
}
|
|
19101
19101
|
const uniqueIds = Array.from(new Set(sourceData.flatMap((item) => {
|
|
19102
|
-
const value = getValueByPath(item,
|
|
19102
|
+
const value = getValueByPath(item, field);
|
|
19103
19103
|
if (typeof value === "string") {
|
|
19104
19104
|
if (value.includes(",")) {
|
|
19105
19105
|
return value.split(",").map((v) => normalizeId(v.trim()));
|
|
@@ -19162,21 +19162,21 @@ async function dataLink(data, schema) {
|
|
|
19162
19162
|
}
|
|
19163
19163
|
}
|
|
19164
19164
|
for (const item of result) {
|
|
19165
|
-
const value = getValueByPath(item,
|
|
19165
|
+
const value = getValueByPath(item, field);
|
|
19166
19166
|
if (typeof value === "string") {
|
|
19167
19167
|
if (value.includes(",")) {
|
|
19168
19168
|
const ids = value.split(",").map((v) => normalizeId(v.trim()));
|
|
19169
|
-
setValueByPath(item,
|
|
19169
|
+
setValueByPath(item, field, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
|
|
19170
19170
|
}
|
|
19171
19171
|
else {
|
|
19172
19172
|
const key = normalizeId(value);
|
|
19173
19173
|
if (cacheMap.has(key)) {
|
|
19174
|
-
setValueByPath(item,
|
|
19174
|
+
setValueByPath(item, field, cacheMap.get(key));
|
|
19175
19175
|
}
|
|
19176
19176
|
}
|
|
19177
19177
|
}
|
|
19178
19178
|
else if (Array.isArray(value)) {
|
|
19179
|
-
setValueByPath(item,
|
|
19179
|
+
setValueByPath(item, field, value.map((id) => {
|
|
19180
19180
|
var _a;
|
|
19181
19181
|
const key = normalizeId(id);
|
|
19182
19182
|
return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
|
|
@@ -19187,7 +19187,7 @@ async function dataLink(data, schema) {
|
|
|
19187
19187
|
typeof value.toString === "function") {
|
|
19188
19188
|
const key = normalizeId(value);
|
|
19189
19189
|
if (cacheMap.has(key)) {
|
|
19190
|
-
setValueByPath(item,
|
|
19190
|
+
setValueByPath(item, field, cacheMap.get(key));
|
|
19191
19191
|
}
|
|
19192
19192
|
}
|
|
19193
19193
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -19092,12 +19092,12 @@ async function dataLink(data, schema) {
|
|
|
19092
19092
|
const isArray = Array.isArray(data);
|
|
19093
19093
|
const sourceData = isArray ? data : [data];
|
|
19094
19094
|
const result = sourceData.map((item) => ({ ...item }));
|
|
19095
|
-
await Promise.all(schema.map(async ({
|
|
19095
|
+
await Promise.all(schema.map(async ({ field, service, path, headers, cacheGetter }) => {
|
|
19096
19096
|
if (!path || !path.trim().startsWith("/")) {
|
|
19097
19097
|
throw new DataLinkError(service, path, new Error(`Invalid path: "${path}". Path must start with "/"`));
|
|
19098
19098
|
}
|
|
19099
19099
|
const uniqueIds = Array.from(new Set(sourceData.flatMap((item) => {
|
|
19100
|
-
const value = getValueByPath(item,
|
|
19100
|
+
const value = getValueByPath(item, field);
|
|
19101
19101
|
if (typeof value === "string") {
|
|
19102
19102
|
if (value.includes(",")) {
|
|
19103
19103
|
return value.split(",").map((v) => normalizeId(v.trim()));
|
|
@@ -19160,21 +19160,21 @@ async function dataLink(data, schema) {
|
|
|
19160
19160
|
}
|
|
19161
19161
|
}
|
|
19162
19162
|
for (const item of result) {
|
|
19163
|
-
const value = getValueByPath(item,
|
|
19163
|
+
const value = getValueByPath(item, field);
|
|
19164
19164
|
if (typeof value === "string") {
|
|
19165
19165
|
if (value.includes(",")) {
|
|
19166
19166
|
const ids = value.split(",").map((v) => normalizeId(v.trim()));
|
|
19167
|
-
setValueByPath(item,
|
|
19167
|
+
setValueByPath(item, field, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
|
|
19168
19168
|
}
|
|
19169
19169
|
else {
|
|
19170
19170
|
const key = normalizeId(value);
|
|
19171
19171
|
if (cacheMap.has(key)) {
|
|
19172
|
-
setValueByPath(item,
|
|
19172
|
+
setValueByPath(item, field, cacheMap.get(key));
|
|
19173
19173
|
}
|
|
19174
19174
|
}
|
|
19175
19175
|
}
|
|
19176
19176
|
else if (Array.isArray(value)) {
|
|
19177
|
-
setValueByPath(item,
|
|
19177
|
+
setValueByPath(item, field, value.map((id) => {
|
|
19178
19178
|
var _a;
|
|
19179
19179
|
const key = normalizeId(id);
|
|
19180
19180
|
return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
|
|
@@ -19185,7 +19185,7 @@ async function dataLink(data, schema) {
|
|
|
19185
19185
|
typeof value.toString === "function") {
|
|
19186
19186
|
const key = normalizeId(value);
|
|
19187
19187
|
if (cacheMap.has(key)) {
|
|
19188
|
-
setValueByPath(item,
|
|
19188
|
+
setValueByPath(item, field, cacheMap.get(key));
|
|
19189
19189
|
}
|
|
19190
19190
|
}
|
|
19191
19191
|
}
|