node-consul-service 1.0.53 → 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 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;
package/dist/index.cjs.js CHANGED
@@ -19033,7 +19033,7 @@ const {
19033
19033
 
19034
19034
  async function callService(serviceName, options = {}) {
19035
19035
  var _a, _b;
19036
- const { method = 'GET', path = '/hello', data, headers, params, } = options;
19036
+ const { method = 'GET', path = '/', data, headers, params, } = options;
19037
19037
  try {
19038
19038
  const instance = await getRandomServiceInstance(serviceName);
19039
19039
  const url = `http://${instance.ServiceAddress}:${instance.ServicePort}${path}`;
@@ -19094,13 +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 ({ filed, service, path, headers, cacheGetter }) => {
19098
- var _a;
19097
+ await Promise.all(schema.map(async ({ field, service, path, headers, cacheGetter }) => {
19099
19098
  if (!path || !path.trim().startsWith("/")) {
19100
19099
  throw new DataLinkError(service, path, new Error(`Invalid path: "${path}". Path must start with "/"`));
19101
19100
  }
19102
19101
  const uniqueIds = Array.from(new Set(sourceData.flatMap((item) => {
19103
- const value = getValueByPath(item, filed);
19102
+ const value = getValueByPath(item, field);
19104
19103
  if (typeof value === "string") {
19105
19104
  if (value.includes(",")) {
19106
19105
  return value.split(",").map((v) => normalizeId(v.trim()));
@@ -19147,8 +19146,8 @@ async function dataLink(data, schema) {
19147
19146
  headers,
19148
19147
  data: { ids: idsToFetch },
19149
19148
  });
19150
- if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
19151
- for (const item of response.data.data) {
19149
+ if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
19150
+ for (const item of response.data) {
19152
19151
  if (item === null || item === void 0 ? void 0 : item._id) {
19153
19152
  cacheMap.set(normalizeId(item._id), item);
19154
19153
  }
@@ -19163,21 +19162,21 @@ async function dataLink(data, schema) {
19163
19162
  }
19164
19163
  }
19165
19164
  for (const item of result) {
19166
- const value = getValueByPath(item, filed);
19165
+ const value = getValueByPath(item, field);
19167
19166
  if (typeof value === "string") {
19168
19167
  if (value.includes(",")) {
19169
19168
  const ids = value.split(",").map((v) => normalizeId(v.trim()));
19170
- setValueByPath(item, filed, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19169
+ setValueByPath(item, field, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19171
19170
  }
19172
19171
  else {
19173
19172
  const key = normalizeId(value);
19174
19173
  if (cacheMap.has(key)) {
19175
- setValueByPath(item, filed, cacheMap.get(key));
19174
+ setValueByPath(item, field, cacheMap.get(key));
19176
19175
  }
19177
19176
  }
19178
19177
  }
19179
19178
  else if (Array.isArray(value)) {
19180
- setValueByPath(item, filed, value.map((id) => {
19179
+ setValueByPath(item, field, value.map((id) => {
19181
19180
  var _a;
19182
19181
  const key = normalizeId(id);
19183
19182
  return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
@@ -19188,7 +19187,7 @@ async function dataLink(data, schema) {
19188
19187
  typeof value.toString === "function") {
19189
19188
  const key = normalizeId(value);
19190
19189
  if (cacheMap.has(key)) {
19191
- setValueByPath(item, filed, cacheMap.get(key));
19190
+ setValueByPath(item, field, cacheMap.get(key));
19192
19191
  }
19193
19192
  }
19194
19193
  }
package/dist/index.esm.js CHANGED
@@ -19031,7 +19031,7 @@ const {
19031
19031
 
19032
19032
  async function callService(serviceName, options = {}) {
19033
19033
  var _a, _b;
19034
- const { method = 'GET', path = '/hello', data, headers, params, } = options;
19034
+ const { method = 'GET', path = '/', data, headers, params, } = options;
19035
19035
  try {
19036
19036
  const instance = await getRandomServiceInstance(serviceName);
19037
19037
  const url = `http://${instance.ServiceAddress}:${instance.ServicePort}${path}`;
@@ -19092,13 +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 ({ filed, service, path, headers, cacheGetter }) => {
19096
- var _a;
19095
+ await Promise.all(schema.map(async ({ field, service, path, headers, cacheGetter }) => {
19097
19096
  if (!path || !path.trim().startsWith("/")) {
19098
19097
  throw new DataLinkError(service, path, new Error(`Invalid path: "${path}". Path must start with "/"`));
19099
19098
  }
19100
19099
  const uniqueIds = Array.from(new Set(sourceData.flatMap((item) => {
19101
- const value = getValueByPath(item, filed);
19100
+ const value = getValueByPath(item, field);
19102
19101
  if (typeof value === "string") {
19103
19102
  if (value.includes(",")) {
19104
19103
  return value.split(",").map((v) => normalizeId(v.trim()));
@@ -19145,8 +19144,8 @@ async function dataLink(data, schema) {
19145
19144
  headers,
19146
19145
  data: { ids: idsToFetch },
19147
19146
  });
19148
- if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)) {
19149
- for (const item of response.data.data) {
19147
+ if ((response === null || response === void 0 ? void 0 : response.success) && Array.isArray(response.data)) {
19148
+ for (const item of response.data) {
19150
19149
  if (item === null || item === void 0 ? void 0 : item._id) {
19151
19150
  cacheMap.set(normalizeId(item._id), item);
19152
19151
  }
@@ -19161,21 +19160,21 @@ async function dataLink(data, schema) {
19161
19160
  }
19162
19161
  }
19163
19162
  for (const item of result) {
19164
- const value = getValueByPath(item, filed);
19163
+ const value = getValueByPath(item, field);
19165
19164
  if (typeof value === "string") {
19166
19165
  if (value.includes(",")) {
19167
19166
  const ids = value.split(",").map((v) => normalizeId(v.trim()));
19168
- setValueByPath(item, filed, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19167
+ setValueByPath(item, field, ids.map((id) => { var _a; return (_a = cacheMap.get(id)) !== null && _a !== void 0 ? _a : id; }));
19169
19168
  }
19170
19169
  else {
19171
19170
  const key = normalizeId(value);
19172
19171
  if (cacheMap.has(key)) {
19173
- setValueByPath(item, filed, cacheMap.get(key));
19172
+ setValueByPath(item, field, cacheMap.get(key));
19174
19173
  }
19175
19174
  }
19176
19175
  }
19177
19176
  else if (Array.isArray(value)) {
19178
- setValueByPath(item, filed, value.map((id) => {
19177
+ setValueByPath(item, field, value.map((id) => {
19179
19178
  var _a;
19180
19179
  const key = normalizeId(id);
19181
19180
  return (_a = cacheMap.get(key)) !== null && _a !== void 0 ? _a : id;
@@ -19186,7 +19185,7 @@ async function dataLink(data, schema) {
19186
19185
  typeof value.toString === "function") {
19187
19186
  const key = normalizeId(value);
19188
19187
  if (cacheMap.has(key)) {
19189
- setValueByPath(item, filed, cacheMap.get(key));
19188
+ setValueByPath(item, field, cacheMap.get(key));
19190
19189
  }
19191
19190
  }
19192
19191
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-consul-service",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",