@karmaniverous/jsonmap 0.2.4 → 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,21 +97,32 @@ 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
128
|
const params = (0, _lodash.default)(transformation.params).map(param => {
|
|
@@ -121,9 +132,11 @@ class JsonMap {
|
|
|
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
|
|
package/lib/JsonMap/JsonMap.js
CHANGED
|
@@ -100,21 +100,27 @@ 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
126
|
const params = castArray(transformation.params).map((param) => {
|
|
@@ -128,9 +134,11 @@ class JsonMap {
|
|
|
128
134
|
: paramObj
|
|
129
135
|
: paramPath;
|
|
130
136
|
});
|
|
137
|
+
console.debug('resolved transformation params:\n', params);
|
|
131
138
|
|
|
132
139
|
// Calls the specified method on the resolved object with the resolved parameters
|
|
133
140
|
const result = await invoke(methodObj, methodPath, ...params);
|
|
141
|
+
console.debug('transformation result:\n', result);
|
|
134
142
|
|
|
135
143
|
// Stores the result of the transformation
|
|
136
144
|
results.unshift(result);
|
|
@@ -138,6 +146,8 @@ class JsonMap {
|
|
|
138
146
|
|
|
139
147
|
// Sets the output at the specified path to the last result of the transformations & returns.
|
|
140
148
|
set(output, path, results[0]);
|
|
149
|
+
console.debug('updated output:\n', output);
|
|
150
|
+
|
|
141
151
|
return results[0];
|
|
142
152
|
}
|
|
143
153
|
|