@devua-lab/error-serialization 1.0.3 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -27,7 +27,7 @@ __export(index_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(index_exports);
29
29
 
30
- // src/contants.ts
30
+ // src/constants.ts
31
31
  var ErrorPriority = {
32
32
  /**
33
33
  * Fallback priority for unhandled errors
@@ -164,7 +164,8 @@ var AxiosErrorPlugin = class extends ErrorPlugin {
164
164
  }
165
165
  /**
166
166
  * Recursively flattens a nested object into a flat record with dot-separated keys.
167
- * Traverses nested objects but keeps arrays (like string[]) as leaf values.
167
+ * Traverses nested objects but keeps arrays as leaf values.
168
+ * If an array has exactly one element, it returns the element itself.
168
169
  */
169
170
  flatten(obj, prefix = "") {
170
171
  return Object.keys(obj).reduce((acc, k) => {
@@ -176,7 +177,11 @@ var AxiosErrorPlugin = class extends ErrorPlugin {
176
177
  this.flatten(value, path)
177
178
  );
178
179
  } else {
179
- acc[path] = value;
180
+ if (Array.isArray(value) && value.length === 1) {
181
+ acc[path] = value[0];
182
+ } else {
183
+ acc[path] = value;
184
+ }
180
185
  }
181
186
  return acc;
182
187
  }, {});
package/dist/index.d.cts CHANGED
@@ -156,6 +156,9 @@ declare class ErrorSerializer {
156
156
  * Plugin for handling Axios errors and extracting server-side data.
157
157
  * Supports extraction of messages, error codes, and recursive validation errors
158
158
  * which are automatically flattened into a dot-notation structure.
159
+ *
160
+ * Special behavior: If a validation field contains an array with a single value,
161
+ * it will be extracted as a direct value instead of an array.
159
162
  */
160
163
  declare class AxiosErrorPlugin extends ErrorPlugin<AxiosError> {
161
164
  /**
@@ -174,7 +177,8 @@ declare class AxiosErrorPlugin extends ErrorPlugin<AxiosError> {
174
177
  serialize(error: AxiosError): AppErrorResponse;
175
178
  /**
176
179
  * Recursively flattens a nested object into a flat record with dot-separated keys.
177
- * Traverses nested objects but keeps arrays (like string[]) as leaf values.
180
+ * Traverses nested objects but keeps arrays as leaf values.
181
+ * If an array has exactly one element, it returns the element itself.
178
182
  */
179
183
  private flatten;
180
184
  }
package/dist/index.d.ts CHANGED
@@ -156,6 +156,9 @@ declare class ErrorSerializer {
156
156
  * Plugin for handling Axios errors and extracting server-side data.
157
157
  * Supports extraction of messages, error codes, and recursive validation errors
158
158
  * which are automatically flattened into a dot-notation structure.
159
+ *
160
+ * Special behavior: If a validation field contains an array with a single value,
161
+ * it will be extracted as a direct value instead of an array.
159
162
  */
160
163
  declare class AxiosErrorPlugin extends ErrorPlugin<AxiosError> {
161
164
  /**
@@ -174,7 +177,8 @@ declare class AxiosErrorPlugin extends ErrorPlugin<AxiosError> {
174
177
  serialize(error: AxiosError): AppErrorResponse;
175
178
  /**
176
179
  * Recursively flattens a nested object into a flat record with dot-separated keys.
177
- * Traverses nested objects but keeps arrays (like string[]) as leaf values.
180
+ * Traverses nested objects but keeps arrays as leaf values.
181
+ * If an array has exactly one element, it returns the element itself.
178
182
  */
179
183
  private flatten;
180
184
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // src/contants.ts
1
+ // src/constants.ts
2
2
  var ErrorPriority = {
3
3
  /**
4
4
  * Fallback priority for unhandled errors
@@ -135,7 +135,8 @@ var AxiosErrorPlugin = class extends ErrorPlugin {
135
135
  }
136
136
  /**
137
137
  * Recursively flattens a nested object into a flat record with dot-separated keys.
138
- * Traverses nested objects but keeps arrays (like string[]) as leaf values.
138
+ * Traverses nested objects but keeps arrays as leaf values.
139
+ * If an array has exactly one element, it returns the element itself.
139
140
  */
140
141
  flatten(obj, prefix = "") {
141
142
  return Object.keys(obj).reduce((acc, k) => {
@@ -147,7 +148,11 @@ var AxiosErrorPlugin = class extends ErrorPlugin {
147
148
  this.flatten(value, path)
148
149
  );
149
150
  } else {
150
- acc[path] = value;
151
+ if (Array.isArray(value) && value.length === 1) {
152
+ acc[path] = value[0];
153
+ } else {
154
+ acc[path] = value;
155
+ }
151
156
  }
152
157
  return acc;
153
158
  }, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devua-lab/error-serialization",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",