@karmaniverous/jsonmap 0.2.6 → 0.2.7
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.
|
@@ -98,32 +98,27 @@ class JsonMap {
|
|
|
98
98
|
*/
|
|
99
99
|
async #transform(node, input, output) {
|
|
100
100
|
let path = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
|
101
|
-
console.debug('#transform params:\n', {
|
|
102
|
-
node,
|
|
103
|
-
input,
|
|
104
|
-
output,
|
|
105
|
-
path
|
|
106
|
-
});
|
|
101
|
+
// console.debug('#transform params:\n', { node, input, output, path });
|
|
107
102
|
|
|
108
103
|
// Checks if the current node is an object and has a '$' key
|
|
109
104
|
if ((0, _lodash8.default)(node) && (0, _lodash14.default)(node) === 1 && '$' in node) {
|
|
110
105
|
// Retrieves the transformations to be applied (can be an array or a single object)
|
|
111
106
|
const transformations = (0, _lodash.default)(node['$']);
|
|
112
|
-
console.debug('transformations:\n', transformations);
|
|
107
|
+
// console.debug('transformations:\n', transformations);
|
|
113
108
|
|
|
114
109
|
// Array to store the results of the transformations
|
|
115
110
|
let results = [];
|
|
116
111
|
|
|
117
112
|
// Iterates over each transformation
|
|
118
113
|
for (const transformation of transformations) {
|
|
119
|
-
console.debug('processing transformation:\n', transformation);
|
|
114
|
+
// console.debug('processing transformation:\n', transformation);
|
|
120
115
|
|
|
121
116
|
// Resolves the object path for the transformation
|
|
122
117
|
const {
|
|
123
118
|
obj: methodObj,
|
|
124
119
|
path: methodPath
|
|
125
120
|
} = this.#resolvePath(transformation.method, results);
|
|
126
|
-
console.debug('methodObj:\n', methodObj, '\nmethodPath:\n', methodPath);
|
|
121
|
+
// console.debug('methodObj:\n', methodObj, '\nmethodPath:\n', methodPath);
|
|
127
122
|
|
|
128
123
|
// Resolves the parameter paths for the transformation
|
|
129
124
|
const params = (0, _lodash.default)(transformation.params).map(param => {
|
|
@@ -133,11 +128,11 @@ class JsonMap {
|
|
|
133
128
|
} = this.#resolvePath(param, results);
|
|
134
129
|
return paramObj ? paramPath ? (0, _lodash3.default)(paramObj, paramPath) : paramObj : paramPath;
|
|
135
130
|
});
|
|
136
|
-
console.debug('resolved transformation params:\n', params);
|
|
131
|
+
// console.debug('resolved transformation params:\n', params);
|
|
137
132
|
|
|
138
133
|
// Calls the specified method on the resolved object with the resolved parameters
|
|
139
134
|
const result = await (0, _lodash4.default)(methodObj, methodPath, ...params);
|
|
140
|
-
console.debug('transformation result:\n', result);
|
|
135
|
+
// console.debug('transformation result:\n', result);
|
|
141
136
|
|
|
142
137
|
// Stores the result of the transformation
|
|
143
138
|
results.unshift(result);
|
|
@@ -145,7 +140,8 @@ class JsonMap {
|
|
|
145
140
|
|
|
146
141
|
// Sets the output at the specified path to the last result of the transformations & returns.
|
|
147
142
|
(0, _lodash13.default)(output, path, results[0]);
|
|
148
|
-
console.debug('updated output:\n', output);
|
|
143
|
+
// console.debug('updated output:\n', output);
|
|
144
|
+
|
|
149
145
|
return results[0];
|
|
150
146
|
}
|
|
151
147
|
|
package/lib/JsonMap/JsonMap.js
CHANGED
|
@@ -101,27 +101,27 @@ class JsonMap {
|
|
|
101
101
|
* @private
|
|
102
102
|
*/
|
|
103
103
|
async #transform(node, input, output, path = '') {
|
|
104
|
-
console.debug('#transform params:\n', { node, input, output, path });
|
|
104
|
+
// console.debug('#transform params:\n', { node, input, output, path });
|
|
105
105
|
|
|
106
106
|
// Checks if the current node is an object and has a '$' key
|
|
107
107
|
if (isPlainObject(node) && size(node) === 1 && '$' in node) {
|
|
108
108
|
// Retrieves the transformations to be applied (can be an array or a single object)
|
|
109
109
|
const transformations = castArray(node['$']);
|
|
110
|
-
console.debug('transformations:\n', transformations);
|
|
110
|
+
// console.debug('transformations:\n', transformations);
|
|
111
111
|
|
|
112
112
|
// Array to store the results of the transformations
|
|
113
113
|
let results = [];
|
|
114
114
|
|
|
115
115
|
// Iterates over each transformation
|
|
116
116
|
for (const transformation of transformations) {
|
|
117
|
-
console.debug('processing transformation:\n', transformation);
|
|
117
|
+
// console.debug('processing transformation:\n', transformation);
|
|
118
118
|
|
|
119
119
|
// Resolves the object path for the transformation
|
|
120
120
|
const { obj: methodObj, path: methodPath } = this.#resolvePath(
|
|
121
121
|
transformation.method,
|
|
122
122
|
results
|
|
123
123
|
);
|
|
124
|
-
console.debug('methodObj:\n', methodObj, '\nmethodPath:\n', methodPath);
|
|
124
|
+
// console.debug('methodObj:\n', methodObj, '\nmethodPath:\n', methodPath);
|
|
125
125
|
|
|
126
126
|
// Resolves the parameter paths for the transformation
|
|
127
127
|
const params = castArray(transformation.params).map((param) => {
|
|
@@ -135,11 +135,11 @@ class JsonMap {
|
|
|
135
135
|
: paramObj
|
|
136
136
|
: paramPath;
|
|
137
137
|
});
|
|
138
|
-
console.debug('resolved transformation params:\n', params);
|
|
138
|
+
// console.debug('resolved transformation params:\n', params);
|
|
139
139
|
|
|
140
140
|
// Calls the specified method on the resolved object with the resolved parameters
|
|
141
141
|
const result = await invoke(methodObj, methodPath, ...params);
|
|
142
|
-
console.debug('transformation result:\n', result);
|
|
142
|
+
// console.debug('transformation result:\n', result);
|
|
143
143
|
|
|
144
144
|
// Stores the result of the transformation
|
|
145
145
|
results.unshift(result);
|
|
@@ -147,7 +147,7 @@ class JsonMap {
|
|
|
147
147
|
|
|
148
148
|
// Sets the output at the specified path to the last result of the transformations & returns.
|
|
149
149
|
set(output, path, results[0]);
|
|
150
|
-
console.debug('updated output:\n', output);
|
|
150
|
+
// console.debug('updated output:\n', output);
|
|
151
151
|
|
|
152
152
|
return results[0];
|
|
153
153
|
}
|