@karmaniverous/jsonmap 0.2.3 → 0.2.5

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.
@@ -97,33 +97,46 @@ class JsonMap {
97
97
  */
98
98
  async #transform(node, input, output) {
99
99
  let path = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
100
+ console.debug('#transform params:\n', {
101
+ node,
102
+ input,
103
+ output,
104
+ path
105
+ });
106
+
100
107
  // Checks if the current node is an object and has a '$' key
101
108
  if ((0, _lodash8.default)(node) && (0, _lodash14.default)(node) === 1 && '$' in node) {
102
109
  // Retrieves the transformations to be applied (can be an array or a single object)
103
110
  const transformations = (0, _lodash.default)(node['$']);
111
+ console.debug('transformations:\n', transformations);
104
112
 
105
113
  // Array to store the results of the transformations
106
114
  let results = [];
107
115
 
108
116
  // Iterates over each transformation
109
117
  for (const transformation of transformations) {
118
+ console.debug('processing transformation:\n', transformation);
119
+
110
120
  // Resolves the object path for the transformation
111
121
  const {
112
122
  obj: methodObj,
113
123
  path: methodPath
114
124
  } = this.#resolvePath(transformation.method, results);
125
+ console.debug('methodObj:\n', methodObj, '\nmethodPath:\n', methodPath);
115
126
 
116
127
  // Resolves the parameter paths for the transformation
117
- const params = await Promise.all((0, _lodash.default)(transformation.params).map(param => {
128
+ const params = (0, _lodash.default)(transformation.params).map(param => {
118
129
  const {
119
130
  obj: paramObj,
120
131
  path: paramPath
121
132
  } = this.#resolvePath(param, results);
122
133
  return paramObj ? paramPath ? (0, _lodash3.default)(paramObj, paramPath) : paramObj : paramPath;
123
- }));
134
+ });
135
+ console.debug('resolved transformation params:\n', params);
124
136
 
125
137
  // Calls the specified method on the resolved object with the resolved parameters
126
138
  const result = await (0, _lodash4.default)(methodObj, methodPath, ...params);
139
+ console.debug('transformation result:\n', result);
127
140
 
128
141
  // Stores the result of the transformation
129
142
  results.unshift(result);
@@ -131,6 +144,7 @@ class JsonMap {
131
144
 
132
145
  // Sets the output at the specified path to the last result of the transformations & returns.
133
146
  (0, _lodash13.default)(output, path, results[0]);
147
+ console.debug('updated output:\n', output);
134
148
  return results[0];
135
149
  }
136
150
 
@@ -177,7 +191,9 @@ class JsonMap {
177
191
  #resolvePath(path, results) {
178
192
  // If the path is not a string, return it as is
179
193
  if (!(0, _lodash9.default)(path)) {
180
- return path;
194
+ return {
195
+ path
196
+ };
181
197
  }
182
198
 
183
199
  // Defines special patterns and their corresponding resolution functions
@@ -100,39 +100,45 @@ class JsonMap {
100
100
  * @private
101
101
  */
102
102
  async #transform(node, input, output, path = '') {
103
+ console.debug('#transform params:\n', { node, input, output, path });
104
+
103
105
  // Checks if the current node is an object and has a '$' key
104
106
  if (isPlainObject(node) && size(node) === 1 && '$' in node) {
105
107
  // Retrieves the transformations to be applied (can be an array or a single object)
106
108
  const transformations = castArray(node['$']);
109
+ console.debug('transformations:\n', transformations);
107
110
 
108
111
  // Array to store the results of the transformations
109
112
  let results = [];
110
113
 
111
114
  // Iterates over each transformation
112
115
  for (const transformation of transformations) {
116
+ console.debug('processing transformation:\n', transformation);
117
+
113
118
  // Resolves the object path for the transformation
114
119
  const { obj: methodObj, path: methodPath } = this.#resolvePath(
115
120
  transformation.method,
116
121
  results
117
122
  );
123
+ console.debug('methodObj:\n', methodObj, '\nmethodPath:\n', methodPath);
118
124
 
119
125
  // Resolves the parameter paths for the transformation
120
- const params = await Promise.all(
121
- castArray(transformation.params).map((param) => {
122
- const { obj: paramObj, path: paramPath } = this.#resolvePath(
123
- param,
124
- results
125
- );
126
- return paramObj
127
- ? paramPath
128
- ? get(paramObj, paramPath)
129
- : paramObj
130
- : paramPath;
131
- })
132
- );
126
+ const params = castArray(transformation.params).map((param) => {
127
+ const { obj: paramObj, path: paramPath } = this.#resolvePath(
128
+ param,
129
+ results
130
+ );
131
+ return paramObj
132
+ ? paramPath
133
+ ? get(paramObj, paramPath)
134
+ : paramObj
135
+ : paramPath;
136
+ });
137
+ console.debug('resolved transformation params:\n', params);
133
138
 
134
139
  // Calls the specified method on the resolved object with the resolved parameters
135
140
  const result = await invoke(methodObj, methodPath, ...params);
141
+ console.debug('transformation result:\n', result);
136
142
 
137
143
  // Stores the result of the transformation
138
144
  results.unshift(result);
@@ -140,6 +146,8 @@ class JsonMap {
140
146
 
141
147
  // Sets the output at the specified path to the last result of the transformations & returns.
142
148
  set(output, path, results[0]);
149
+ console.debug('updated output:\n', output);
150
+
143
151
  return results[0];
144
152
  }
145
153
 
@@ -191,7 +199,7 @@ class JsonMap {
191
199
  #resolvePath(path, results) {
192
200
  // If the path is not a string, return it as is
193
201
  if (!isString(path)) {
194
- return path;
202
+ return { path };
195
203
  }
196
204
 
197
205
  // Defines special patterns and their corresponding resolution functions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karmaniverous/jsonmap",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },