Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/JsonMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,17 @@ class JsonMap {
output: Json,
path = '',
): Promise<Json> {
console.debug('#transform params:\n', { node, input, output, path });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While removing these debug logs solves the problem of excessive noise, it also removes valuable debugging information that could be useful in the future.

Consider making these logs conditional instead of removing them entirely. This could be achieved by:

  1. Adding a debug flag to JsonMapOptions to control logging.
  2. Using a lightweight logging library like debug, which allows enabling logs via an environment variable (e.g., DEBUG=jsonmap:*).

This would provide the flexibility to enable logging during development or troubleshooting without affecting production performance.


// Checks if the current node is an object and has only a '$' key
if (node instanceof Object && _.size(node) === 1 && '$' in node) {
// Retrieves the transformations to be applied (can be an array or a single object)
const transformations = _.castArray(
node.$ as JsonMapTransform | JsonMapTransform[],
);
console.debug('transformations:\n', transformations);

// Array to store the results of the transformations
const results: Json = [];

// Iterates over each transformation
for (const transformation of transformations) {
console.debug('processing transformation:\n', transformation);

// Resolves the object path for the transformation
const { obj: methodObj, path: methodPath } = this.#resolvePath(
transformation.method,
Expand All @@ -136,26 +130,20 @@ class JsonMap {
},
);

console.debug('resolved transformation params:\n', params);

// Calls the specified method on the resolved object with the resolved parameters
const result = (await _.invoke(
methodObj,
methodPath as string,
...params,
)) as Json;

console.debug('transformation result:\n', result);

// Stores the result of the transformation
results.unshift(result);
}

// Sets the output at the specified path to the last result of the transformations & returns.
_.set(output as object, path, results[0]);

console.debug('updated output:\n', output);

return results[0];
}

Expand Down