node-consul-service 1.0.54 → 1.0.56

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 CHANGED
@@ -163,7 +163,7 @@ const data = [
163
163
 
164
164
  const schema = [
165
165
  {
166
- filed: 'userId', // Field name in the original data
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
- - `filed`: Field name in the original data that contains the identifier
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
- filed: 'userId',
219
+ Field: 'userId',
220
220
  service: 'user-service',
221
221
  path: '/api/users/batch'
222
222
  },
223
223
  {
224
- filed: 'productId',
224
+ Field: 'productId',
225
225
  service: 'product-service',
226
226
  path: '/api/products/batch'
227
227
  }
@@ -1,6 +1,6 @@
1
1
  import { AxiosRequestHeaders } from "axios";
2
2
  interface LinkSchema {
3
- filed: string;
3
+ field: string;
4
4
  service: string;
5
5
  path: string;
6
6
  headers?: AxiosRequestHeaders;
@@ -11,6 +11,7 @@ interface ServiceResponse<T = any> {
11
11
  data?: T;
12
12
  message?: string;
13
13
  status?: number;
14
+ code?: string;
14
15
  }
15
16
  export declare function callService(serviceName: string, options?: CallServiceOptions): Promise<ServiceResponse>;
16
17
  export {};
package/dist/index.cjs.js CHANGED
@@ -19032,7 +19032,7 @@ const {
19032
19032
  } = axios;
19033
19033
 
19034
19034
  async function callService(serviceName, options = {}) {
19035
- var _a, _b;
19035
+ var _a, _b, _c, _d;
19036
19036
  const { method = 'GET', path = '/', data, headers, params, } = options;
19037
19037
  try {
19038
19038
  const instance = await getRandomServiceInstance(serviceName);
@@ -19051,7 +19051,8 @@ async function callService(serviceName, options = {}) {
19051
19051
  success: false,
19052
19052
  message: error.message,
19053
19053
  status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
19054
- data: (_b = error.response) === null || _b === void 0 ? void 0 : _b.data,
19054
+ code: (_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.code) !== null && _c !== void 0 ? _c : "",
19055
+ data: (_d = error.response) === null || _d === void 0 ? void 0 : _d.data,
19055
19056
  };
19056
19057
  }
19057
19058
  }
@@ -19094,12 +19095,12 @@ async function dataLink(data, schema) {
19094
19095
  const isArray = Array.isArray(data);
19095
19096
  const sourceData = isArray ? data : [data];
19096
19097
  const result = sourceData.map((item) => ({ ...item }));
19097
- await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
19098
+ await Promise.all(schema.map(async ({ field, service, path, headers, cacheGetter }) => {
19098
19099
  if (!path || !path.trim().startsWith("/")) {
19099
19100
  throw new DataLinkError(service, path, new Error(`Invalid path: "${path}". Path must start with "/"`));
19100
19101
  }
19101
19102
  const uniqueIds = Array.from(new Set(sourceData.flatMap((item) => {
19102
- const value = getValueByPath(item, filed);
19103
+ const value = getValueByPath(item, field);
19103
19104
  if (typeof value === "string") {
19104
19105
  if (value.includes(",")) {
19105
19106
  return value.split(",").map((v) => normalizeId(v.trim()));
@@ -19162,21 +19163,21 @@ async function dataLink(data, schema) {
19162
19163
  }
19163
19164
  }
19164
19165
  for (const item of result) {
19165
- const value = getValueByPath(item, filed);
19166
+ const value = getValueByPath(item, field);
19166
19167
  if (typeof value === "string") {
19167
19168
  if (value.includes(",")) {
19168
19169
  const ids = value.split(",").map((v) => normalizeId(v.trim()));
19169
- setValueByPath(item, filed, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19170
+ setValueByPath(item, field, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19170
19171
  }
19171
19172
  else {
19172
19173
  const key = normalizeId(value);
19173
19174
  if (cacheMap.has(key)) {
19174
- setValueByPath(item, filed, cacheMap.get(key));
19175
+ setValueByPath(item, field, cacheMap.get(key));
19175
19176
  }
19176
19177
  }
19177
19178
  }
19178
19179
  else if (Array.isArray(value)) {
19179
- setValueByPath(item, filed, value.map((id) => {
19180
+ setValueByPath(item, field, value.map((id) => {
19180
19181
  var _a;
19181
19182
  const key = normalizeId(id);
19182
19183
  return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
@@ -19187,7 +19188,7 @@ async function dataLink(data, schema) {
19187
19188
  typeof value.toString === "function") {
19188
19189
  const key = normalizeId(value);
19189
19190
  if (cacheMap.has(key)) {
19190
- setValueByPath(item, filed, cacheMap.get(key));
19191
+ setValueByPath(item, field, cacheMap.get(key));
19191
19192
  }
19192
19193
  }
19193
19194
  }
package/dist/index.esm.js CHANGED
@@ -19030,7 +19030,7 @@ const {
19030
19030
  } = axios;
19031
19031
 
19032
19032
  async function callService(serviceName, options = {}) {
19033
- var _a, _b;
19033
+ var _a, _b, _c, _d;
19034
19034
  const { method = 'GET', path = '/', data, headers, params, } = options;
19035
19035
  try {
19036
19036
  const instance = await getRandomServiceInstance(serviceName);
@@ -19049,7 +19049,8 @@ async function callService(serviceName, options = {}) {
19049
19049
  success: false,
19050
19050
  message: error.message,
19051
19051
  status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
19052
- data: (_b = error.response) === null || _b === void 0 ? void 0 : _b.data,
19052
+ code: (_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.code) !== null && _c !== void 0 ? _c : "",
19053
+ data: (_d = error.response) === null || _d === void 0 ? void 0 : _d.data,
19053
19054
  };
19054
19055
  }
19055
19056
  }
@@ -19092,12 +19093,12 @@ async function dataLink(data, schema) {
19092
19093
  const isArray = Array.isArray(data);
19093
19094
  const sourceData = isArray ? data : [data];
19094
19095
  const result = sourceData.map((item) => ({ ...item }));
19095
- await Promise.all(schema.map(async ({ filed, service, path, headers, cacheGetter }) => {
19096
+ await Promise.all(schema.map(async ({ field, service, path, headers, cacheGetter }) => {
19096
19097
  if (!path || !path.trim().startsWith("/")) {
19097
19098
  throw new DataLinkError(service, path, new Error(`Invalid path: "${path}". Path must start with "/"`));
19098
19099
  }
19099
19100
  const uniqueIds = Array.from(new Set(sourceData.flatMap((item) => {
19100
- const value = getValueByPath(item, filed);
19101
+ const value = getValueByPath(item, field);
19101
19102
  if (typeof value === "string") {
19102
19103
  if (value.includes(",")) {
19103
19104
  return value.split(",").map((v) => normalizeId(v.trim()));
@@ -19160,21 +19161,21 @@ async function dataLink(data, schema) {
19160
19161
  }
19161
19162
  }
19162
19163
  for (const item of result) {
19163
- const value = getValueByPath(item, filed);
19164
+ const value = getValueByPath(item, field);
19164
19165
  if (typeof value === "string") {
19165
19166
  if (value.includes(",")) {
19166
19167
  const ids = value.split(",").map((v) => normalizeId(v.trim()));
19167
- setValueByPath(item, filed, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19168
+ setValueByPath(item, field, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19168
19169
  }
19169
19170
  else {
19170
19171
  const key = normalizeId(value);
19171
19172
  if (cacheMap.has(key)) {
19172
- setValueByPath(item, filed, cacheMap.get(key));
19173
+ setValueByPath(item, field, cacheMap.get(key));
19173
19174
  }
19174
19175
  }
19175
19176
  }
19176
19177
  else if (Array.isArray(value)) {
19177
- setValueByPath(item, filed, value.map((id) => {
19178
+ setValueByPath(item, field, value.map((id) => {
19178
19179
  var _a;
19179
19180
  const key = normalizeId(id);
19180
19181
  return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
@@ -19185,7 +19186,7 @@ async function dataLink(data, schema) {
19185
19186
  typeof value.toString === "function") {
19186
19187
  const key = normalizeId(value);
19187
19188
  if (cacheMap.has(key)) {
19188
- setValueByPath(item, filed, cacheMap.get(key));
19189
+ setValueByPath(item, field, cacheMap.get(key));
19189
19190
  }
19190
19191
  }
19191
19192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-consul-service",
3
- "version": "1.0.54",
3
+ "version": "1.0.56",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",