@jaypie/fabric 0.2.2 → 0.2.4

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.
@@ -106,10 +106,10 @@ function tryParseJson(value) {
106
106
  return value;
107
107
  }
108
108
  /**
109
- * Unwrap arrays and objects to get to the scalar value
109
+ * Unwrap arrays to get to the scalar value
110
110
  * - Single-element arrays unwrap to their element
111
- * - Objects with value property unwrap to that value
112
- * - Recursively unwraps nested structures
111
+ * - Objects pass through as-is (handled by individual fabric functions)
112
+ * - Recursively unwraps nested arrays
113
113
  */
114
114
  function unwrapToScalar(value) {
115
115
  if (value === undefined || value === null) {
@@ -125,14 +125,6 @@ function unwrapToScalar(value) {
125
125
  }
126
126
  throw new BadRequestError("Cannot convert multi-value array to scalar");
127
127
  }
128
- // Unwrap objects with value property
129
- if (typeof value === "object") {
130
- const obj = value;
131
- if ("value" in obj) {
132
- return unwrapToScalar(obj.value);
133
- }
134
- throw new BadRequestError("Object must have a value attribute");
135
- }
136
128
  return value;
137
129
  }
138
130
  /**
@@ -275,6 +267,9 @@ function fabricString(value) {
275
267
  }
276
268
  return String(prepared);
277
269
  }
270
+ if (typeof prepared === "object") {
271
+ return JSON.stringify(prepared);
272
+ }
278
273
  throw new BadRequestError(`Cannot convert ${typeof prepared} to String`);
279
274
  }
280
275
  /**
@@ -296,11 +291,10 @@ function fabricArray(value) {
296
291
  return [value];
297
292
  }
298
293
  /**
299
- * Convert a value to an object with a value property
294
+ * Convert a value to an object
300
295
  * - Scalars become { value: scalar }
301
296
  * - Arrays become { value: array }
302
- * - Objects with a value attribute pass through
303
- * - Objects without a value attribute throw BadRequestError
297
+ * - Objects pass through as-is (including those with or without value attribute)
304
298
  * - undefined/null become undefined
305
299
  */
306
300
  function fabricObject(value) {
@@ -309,11 +303,8 @@ function fabricObject(value) {
309
303
  }
310
304
  // Check if already an object (but not an array)
311
305
  if (typeof value === "object" && !Array.isArray(value)) {
312
- const obj = value;
313
- if ("value" in obj) {
314
- return obj;
315
- }
316
- throw new BadRequestError("Object must have a value attribute");
306
+ // Pass through any object as-is
307
+ return value;
317
308
  }
318
309
  // Scalars and arrays become { value: ... }
319
310
  return { value };