api-def 0.14.1 → 0.14.3

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/cjs/Utils.js CHANGED
@@ -105,6 +105,10 @@ const toFormDataValue = (value) => {
105
105
  }
106
106
  return String(value);
107
107
  };
108
+ const getBlobFileName = (value) => {
109
+ const name = value.name;
110
+ return typeof name === "string" && name ? name : "blob";
111
+ };
108
112
  const toFormData = (body) => {
109
113
  if ((0, exports.isFormDataLike)(body)) {
110
114
  return body;
@@ -132,7 +136,13 @@ const toFormData = (body) => {
132
136
  }
133
137
  return;
134
138
  }
135
- formData.append(key, toFormDataValue(value));
139
+ const formValue = toFormDataValue(value);
140
+ if (isBlob(formValue)) {
141
+ formData.append(key, formValue, getBlobFileName(formValue));
142
+ }
143
+ else {
144
+ formData.append(key, formValue);
145
+ }
136
146
  };
137
147
  for (const key of Object.keys(body)) {
138
148
  appendValue(key, body[key]);
@@ -140,18 +140,7 @@ class FetchRequestBackend {
140
140
  if (requestConfig.debug) {
141
141
  console.log(`[api-def] Fetching '${url.href}' with options`, JSON.stringify(fetchOptions, null, 2));
142
142
  }
143
- let request;
144
- try {
145
- request = new Request(url.href, fetchOptions);
146
- }
147
- catch (error) {
148
- if (context.validation.bodyEncoding === "multipart/form-data") {
149
- throw Object.assign(new Error("[api-def] multipart/form-data requires a fetch-compatible FormData implementation"), {
150
- cause: error,
151
- });
152
- }
153
- throw error;
154
- }
143
+ const request = new Request(url.href, fetchOptions);
155
144
  if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
156
145
  const contentType = request.headers.get("content-type");
157
146
  if (!contentType?.toLowerCase().startsWith("multipart/form-data")) {
package/esm/Utils.js CHANGED
@@ -94,6 +94,10 @@ const toFormDataValue = (value) => {
94
94
  }
95
95
  return String(value);
96
96
  };
97
+ const getBlobFileName = (value) => {
98
+ const name = value.name;
99
+ return typeof name === "string" && name ? name : "blob";
100
+ };
97
101
  export const toFormData = (body) => {
98
102
  if (isFormDataLike(body)) {
99
103
  return body;
@@ -121,7 +125,13 @@ export const toFormData = (body) => {
121
125
  }
122
126
  return;
123
127
  }
124
- formData.append(key, toFormDataValue(value));
128
+ const formValue = toFormDataValue(value);
129
+ if (isBlob(formValue)) {
130
+ formData.append(key, formValue, getBlobFileName(formValue));
131
+ }
132
+ else {
133
+ formData.append(key, formValue);
134
+ }
125
135
  };
126
136
  for (const key of Object.keys(body)) {
127
137
  appendValue(key, body[key]);
@@ -105,18 +105,7 @@ export default class FetchRequestBackend {
105
105
  if (requestConfig.debug) {
106
106
  console.log(`[api-def] Fetching '${url.href}' with options`, JSON.stringify(fetchOptions, null, 2));
107
107
  }
108
- let request;
109
- try {
110
- request = new Request(url.href, fetchOptions);
111
- }
112
- catch (error) {
113
- if (context.validation.bodyEncoding === "multipart/form-data") {
114
- throw Object.assign(new Error("[api-def] multipart/form-data requires a fetch-compatible FormData implementation"), {
115
- cause: error,
116
- });
117
- }
118
- throw error;
119
- }
108
+ const request = new Request(url.href, fetchOptions);
120
109
  if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
121
110
  const contentType = request.headers.get("content-type");
122
111
  if (!contentType?.toLowerCase().startsWith("multipart/form-data")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.14.1",
3
+ "version": "0.14.3",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",