@radiantabyss/vue 3.3.17 → 3.3.18

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Request.js +15 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiantabyss/vue",
3
- "version": "3.3.17",
3
+ "version": "3.3.18",
4
4
  "author": "radiantabyss.com",
5
5
  "license": "ISC",
6
6
  "eslintConfig": {
package/src/Request.js CHANGED
@@ -88,20 +88,27 @@ const buildParams = (obj, prefix = '', params = new URLSearchParams()) => {
88
88
  return params;
89
89
  }
90
90
 
91
- //recursively remove keys whose value is undefined or null so they aren't sent to the server
92
- const stripEmpty = (value) => {
91
+ //recursively drop undefined values; null is dropped too, or sent as an empty string when null_as_empty
92
+ //is set (form bodies can't carry null, and `key=` lets the backend read it as null to clear a field)
93
+ const cleanPayload = (value, null_as_empty) => {
94
+ const isDropped = (v) => v === undefined || (v === null && !null_as_empty);
95
+
96
+ if ( value === null ) {
97
+ return null_as_empty ? '' : value;
98
+ }
99
+
93
100
  if ( Array.isArray(value) ) {
94
- return value.map(stripEmpty);
101
+ return value.filter((v) => !isDropped(v)).map((v) => cleanPayload(v, null_as_empty));
95
102
  }
96
103
 
97
- if ( value !== null && typeof value === 'object' && !(value instanceof Blob) ) {
104
+ if ( typeof value === 'object' && !(value instanceof Blob) ) {
98
105
  const cleaned = {};
99
106
  for ( let key in value ) {
100
- if ( value[key] === undefined || value[key] === null ) {
107
+ if ( isDropped(value[key]) ) {
101
108
  continue;
102
109
  }
103
110
 
104
- cleaned[key] = stripEmpty(value[key]);
111
+ cleaned[key] = cleanPayload(value[key], null_as_empty);
105
112
  }
106
113
 
107
114
  return cleaned;
@@ -170,8 +177,8 @@ const request = function(method, edge, payload = {}, display_errors = false, bas
170
177
  current[edge] = _cancel;
171
178
  }
172
179
 
173
- //drop undefined/null keys before serializing
174
- payload = stripEmpty(payload);
180
+ //drop undefined keys; GET drops null too, POST sends it as an empty value
181
+ payload = cleanPayload(payload, method != 'GET');
175
182
 
176
183
  let data;
177
184
  let url = base_url + edge;