node-consul-service 1.0.18 → 1.0.19

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.
Files changed (2) hide show
  1. package/README.md +32 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -64,7 +64,39 @@ const instances = await getServiceInstances('service-name');
64
64
 
65
65
  // Get a random instance of a service
66
66
  const instance = await getRandomServiceInstance('service-name');
67
+
68
+ ### dataLink Function
69
+ This function is used to link data from different services. It aggregates data from multiple sources and links them based on common identifiers.
70
+
71
+ ```javascript
72
+ const { dataLink } = require('node-consul-service');
73
+
74
+ // Example of using dataLink
75
+ const data = [
76
+ { userId: '123', name: 'John' },
77
+ { userId: '456', name: 'Jane' }
78
+ ];
79
+
80
+ const schema = [
81
+ {
82
+ filed: 'userId', // Field name in the original data
83
+ service: 'user-service', // Target service name
84
+ path: '/api/users/batch', // API endpoint path
85
+ cacheGetter: async (ids) => {
86
+ // Optional function to get data from cache
87
+ return await cache.getUsers(ids);
88
+ }
89
+ }
90
+ ];
91
+
92
+ const result = await dataLink(data, schema);
67
93
  ```
68
94
 
95
+ #### Schema Properties
96
+ - `filed`: Field name in the original data that contains the identifier
97
+ - `service`: Name of the service to be called
98
+ - `path`: API endpoint path in the target service
99
+ - `cacheGetter`: Optional function to get data from cache before calling the service
100
+
69
101
  ### License
70
102
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-consul-service",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",