1 module spasm.bindings.xhr; 2 3 import spasm.types; 4 import spasm.bindings.dom; 5 import spasm.bindings.fetch; 6 import spasm.bindings.fileapi; 7 import spasm.bindings.html; 8 9 @safe: 10 nothrow: 11 12 struct FormData { 13 nothrow: 14 JsHandle handle; 15 alias handle this; 16 this(Handle h) { 17 this.handle = JsHandle(h); 18 } 19 void append()(string name, string value) { 20 FormData_append__string_string(this.handle, name, value); 21 } 22 void append()(string name, scope ref Blob blobValue, string filename) { 23 FormData_append__string_Handle_string(this.handle, name, blobValue.handle, filename); 24 } 25 void append()(string name, scope ref Blob blobValue) { 26 FormData_append_0(this.handle, name, blobValue.handle); 27 } 28 void delete_()(string name) { 29 FormData_delete(this.handle, name); 30 } 31 auto get()(string name) { 32 return FormData_get(this.handle, name); 33 } 34 auto getAll()(string name) { 35 return Sequence!(FormDataEntryValue)(FormData_getAll(this.handle, name)); 36 } 37 auto has()(string name) { 38 return FormData_has(this.handle, name); 39 } 40 void set()(string name, string value) { 41 FormData_set__string_string(this.handle, name, value); 42 } 43 void set()(string name, scope ref Blob blobValue, string filename) { 44 FormData_set__string_Handle_string(this.handle, name, blobValue.handle, filename); 45 } 46 void set()(string name, scope ref Blob blobValue) { 47 FormData_set_0(this.handle, name, blobValue.handle); 48 } 49 } 50 alias FormDataEntryValue = SumType!(File, string); 51 struct ProgressEvent { 52 nothrow: 53 spasm.bindings.dom.Event _parent; 54 alias _parent this; 55 this(Handle h) { 56 _parent = .Event(h); 57 } 58 auto lengthComputable()() { 59 return ProgressEvent_lengthComputable_Get(this._parent); 60 } 61 auto loaded()() { 62 return ProgressEvent_loaded_Get(this._parent); 63 } 64 auto total()() { 65 return ProgressEvent_total_Get(this._parent); 66 } 67 } 68 struct ProgressEventInit { 69 nothrow: 70 spasm.bindings.dom.EventInit _parent; 71 alias _parent this; 72 this(Handle h) { 73 _parent = .EventInit(h); 74 } 75 static auto create() { 76 return ProgressEventInit(spasm_add__object()); 77 } 78 void lengthComputable()(bool lengthComputable) { 79 ProgressEventInit_lengthComputable_Set(this._parent, lengthComputable); 80 } 81 auto lengthComputable()() { 82 return ProgressEventInit_lengthComputable_Get(this._parent); 83 } 84 void loaded()(uint loaded) { 85 ProgressEventInit_loaded_Set(this._parent, loaded); 86 } 87 auto loaded()() { 88 return ProgressEventInit_loaded_Get(this._parent); 89 } 90 void total()(uint total) { 91 ProgressEventInit_total_Set(this._parent, total); 92 } 93 auto total()() { 94 return ProgressEventInit_total_Get(this._parent); 95 } 96 } 97 struct XMLHttpRequest { 98 nothrow: 99 spasm.bindings.xhr.XMLHttpRequestEventTarget _parent; 100 alias _parent this; 101 this(Handle h) { 102 _parent = .XMLHttpRequestEventTarget(h); 103 } 104 void onreadystatechange()(EventHandler onreadystatechange) { 105 XMLHttpRequest_onreadystatechange_Set(this._parent, onreadystatechange); 106 } 107 auto onreadystatechange()() { 108 return XMLHttpRequest_onreadystatechange_Get(this._parent); 109 } 110 enum ushort UNSENT = 0; 111 enum ushort OPENED = 1; 112 enum ushort HEADERS_RECEIVED = 2; 113 enum ushort LOADING = 3; 114 enum ushort DONE = 4; 115 auto readyState()() { 116 return XMLHttpRequest_readyState_Get(this._parent); 117 } 118 void open()(string method, string url) { 119 XMLHttpRequest_open__string_string(this._parent, method, url); 120 } 121 void open(T3, T4)(string method, string url, bool async, scope auto ref Optional!(T3) username /* = no!(string) */, scope auto ref Optional!(T4) password /* = no!(string) */) if (isTOrPointer!(T3, string) && isTOrPointer!(T4, string)) { 122 XMLHttpRequest_open__string_string_bool_optional_string_optional_string(this._parent, method, url, async, !username.empty, username.front, !password.empty, password.front); 123 } 124 void open(T3)(string method, string url, bool async, scope auto ref Optional!(T3) username /* = no!(string) */) if (isTOrPointer!(T3, string)) { 125 XMLHttpRequest_open_0(this._parent, method, url, async, !username.empty, username.front); 126 } 127 void open()(string method, string url, bool async) { 128 XMLHttpRequest_open_1(this._parent, method, url, async); 129 } 130 void setRequestHeader()(string name, string value) { 131 XMLHttpRequest_setRequestHeader(this._parent, name, value); 132 } 133 void timeout()(uint timeout) { 134 XMLHttpRequest_timeout_Set(this._parent, timeout); 135 } 136 auto timeout()() { 137 return XMLHttpRequest_timeout_Get(this._parent); 138 } 139 void withCredentials()(bool withCredentials) { 140 XMLHttpRequest_withCredentials_Set(this._parent, withCredentials); 141 } 142 auto withCredentials()() { 143 return XMLHttpRequest_withCredentials_Get(this._parent); 144 } 145 auto upload()() { 146 return XMLHttpRequestUpload(XMLHttpRequest_upload_Get(this._parent)); 147 } 148 void send(T0)(scope auto ref Optional!(T0) body_ /* = no!(SumType!(Document, BodyInit)) */) if (isTOrPointer!(T0, SumType!(Document, BodyInit))) { 149 XMLHttpRequest_send(this._parent, !body_.empty, *body_.frontRef); 150 } 151 void send()() { 152 XMLHttpRequest_send_0(this._parent); 153 } 154 void abort()() { 155 XMLHttpRequest_abort(this._parent); 156 } 157 auto responseURL()() { 158 return XMLHttpRequest_responseURL_Get(this._parent); 159 } 160 auto status()() { 161 return XMLHttpRequest_status_Get(this._parent); 162 } 163 auto statusText()() { 164 return XMLHttpRequest_statusText_Get(this._parent); 165 } 166 auto getResponseHeader()(string name) { 167 return XMLHttpRequest_getResponseHeader(this._parent, name); 168 } 169 auto getAllResponseHeaders()() { 170 return XMLHttpRequest_getAllResponseHeaders(this._parent); 171 } 172 void overrideMimeType()(string mime) { 173 XMLHttpRequest_overrideMimeType(this._parent, mime); 174 } 175 void responseType()(XMLHttpRequestResponseType responseType) { 176 XMLHttpRequest_responseType_Set(this._parent, responseType); 177 } 178 auto responseType()() { 179 return XMLHttpRequest_responseType_Get(this._parent); 180 } 181 auto response()() { 182 return Any(XMLHttpRequest_response_Get(this._parent)); 183 } 184 auto responseText()() { 185 return XMLHttpRequest_responseText_Get(this._parent); 186 } 187 auto responseXML()() { 188 return XMLHttpRequest_responseXML_Get(this._parent); 189 } 190 } 191 struct XMLHttpRequestEventTarget { 192 nothrow: 193 spasm.bindings.dom.EventTarget _parent; 194 alias _parent this; 195 this(Handle h) { 196 _parent = .EventTarget(h); 197 } 198 void onloadstart()(EventHandler onloadstart) { 199 XMLHttpRequestEventTarget_onloadstart_Set(this._parent, onloadstart); 200 } 201 auto onloadstart()() { 202 return XMLHttpRequestEventTarget_onloadstart_Get(this._parent); 203 } 204 void onprogress()(EventHandler onprogress) { 205 XMLHttpRequestEventTarget_onprogress_Set(this._parent, onprogress); 206 } 207 auto onprogress()() { 208 return XMLHttpRequestEventTarget_onprogress_Get(this._parent); 209 } 210 void onabort()(EventHandler onabort) { 211 XMLHttpRequestEventTarget_onabort_Set(this._parent, onabort); 212 } 213 auto onabort()() { 214 return XMLHttpRequestEventTarget_onabort_Get(this._parent); 215 } 216 void onerror()(EventHandler onerror) { 217 XMLHttpRequestEventTarget_onerror_Set(this._parent, onerror); 218 } 219 auto onerror()() { 220 return XMLHttpRequestEventTarget_onerror_Get(this._parent); 221 } 222 void onload()(EventHandler onload) { 223 XMLHttpRequestEventTarget_onload_Set(this._parent, onload); 224 } 225 auto onload()() { 226 return XMLHttpRequestEventTarget_onload_Get(this._parent); 227 } 228 void ontimeout()(EventHandler ontimeout) { 229 XMLHttpRequestEventTarget_ontimeout_Set(this._parent, ontimeout); 230 } 231 auto ontimeout()() { 232 return XMLHttpRequestEventTarget_ontimeout_Get(this._parent); 233 } 234 void onloadend()(EventHandler onloadend) { 235 XMLHttpRequestEventTarget_onloadend_Set(this._parent, onloadend); 236 } 237 auto onloadend()() { 238 return XMLHttpRequestEventTarget_onloadend_Get(this._parent); 239 } 240 } 241 enum XMLHttpRequestResponseType { 242 none, 243 arraybuffer, 244 blob, 245 document, 246 json, 247 text 248 } 249 struct XMLHttpRequestUpload { 250 nothrow: 251 spasm.bindings.xhr.XMLHttpRequestEventTarget _parent; 252 alias _parent this; 253 this(Handle h) { 254 _parent = .XMLHttpRequestEventTarget(h); 255 } 256 } 257 258 259 extern (C) void FormData_append__string_string(Handle, string, string); 260 extern (C) void FormData_append__string_Handle_string(Handle, string, Handle, string); 261 extern (C) void FormData_append_0(Handle, string, Handle); 262 extern (C) void FormData_delete(Handle, string); 263 extern (C) Optional!(FormDataEntryValue) FormData_get(Handle, string); 264 extern (C) Handle FormData_getAll(Handle, string); 265 extern (C) bool FormData_has(Handle, string); 266 extern (C) void FormData_set__string_string(Handle, string, string); 267 extern (C) void FormData_set__string_Handle_string(Handle, string, Handle, string); 268 extern (C) void FormData_set_0(Handle, string, Handle); 269 extern (C) bool ProgressEvent_lengthComputable_Get(Handle); 270 extern (C) uint ProgressEvent_loaded_Get(Handle); 271 extern (C) uint ProgressEvent_total_Get(Handle); 272 extern (C) void ProgressEventInit_lengthComputable_Set(Handle, bool); 273 extern (C) bool ProgressEventInit_lengthComputable_Get(Handle); 274 extern (C) void ProgressEventInit_loaded_Set(Handle, uint); 275 extern (C) uint ProgressEventInit_loaded_Get(Handle); 276 extern (C) void ProgressEventInit_total_Set(Handle, uint); 277 extern (C) uint ProgressEventInit_total_Get(Handle); 278 extern (C) void XMLHttpRequest_onreadystatechange_Set(Handle, EventHandler); 279 extern (C) EventHandler XMLHttpRequest_onreadystatechange_Get(Handle); 280 extern (C) ushort XMLHttpRequest_readyState_Get(Handle); 281 extern (C) void XMLHttpRequest_open__string_string(Handle, string, string); 282 extern (C) void XMLHttpRequest_open__string_string_bool_optional_string_optional_string(Handle, string, string, bool, bool, string, bool, string); 283 extern (C) void XMLHttpRequest_open_0(Handle, string, string, bool, bool, string); 284 extern (C) void XMLHttpRequest_open_1(Handle, string, string, bool); 285 extern (C) void XMLHttpRequest_setRequestHeader(Handle, string, string); 286 extern (C) void XMLHttpRequest_timeout_Set(Handle, uint); 287 extern (C) uint XMLHttpRequest_timeout_Get(Handle); 288 extern (C) void XMLHttpRequest_withCredentials_Set(Handle, bool); 289 extern (C) bool XMLHttpRequest_withCredentials_Get(Handle); 290 extern (C) Handle XMLHttpRequest_upload_Get(Handle); 291 extern (C) void XMLHttpRequest_send(Handle, bool, scope ref SumType!(Document, BodyInit)); 292 extern (C) void XMLHttpRequest_send_0(Handle); 293 extern (C) void XMLHttpRequest_abort(Handle); 294 extern (C) string XMLHttpRequest_responseURL_Get(Handle); 295 extern (C) ushort XMLHttpRequest_status_Get(Handle); 296 extern (C) string XMLHttpRequest_statusText_Get(Handle); 297 extern (C) Optional!(string) XMLHttpRequest_getResponseHeader(Handle, string); 298 extern (C) string XMLHttpRequest_getAllResponseHeaders(Handle); 299 extern (C) void XMLHttpRequest_overrideMimeType(Handle, string); 300 extern (C) void XMLHttpRequest_responseType_Set(Handle, XMLHttpRequestResponseType); 301 extern (C) XMLHttpRequestResponseType XMLHttpRequest_responseType_Get(Handle); 302 extern (C) Handle XMLHttpRequest_response_Get(Handle); 303 extern (C) string XMLHttpRequest_responseText_Get(Handle); 304 extern (C) Optional!(Document) XMLHttpRequest_responseXML_Get(Handle); 305 extern (C) void XMLHttpRequestEventTarget_onloadstart_Set(Handle, EventHandler); 306 extern (C) EventHandler XMLHttpRequestEventTarget_onloadstart_Get(Handle); 307 extern (C) void XMLHttpRequestEventTarget_onprogress_Set(Handle, EventHandler); 308 extern (C) EventHandler XMLHttpRequestEventTarget_onprogress_Get(Handle); 309 extern (C) void XMLHttpRequestEventTarget_onabort_Set(Handle, EventHandler); 310 extern (C) EventHandler XMLHttpRequestEventTarget_onabort_Get(Handle); 311 extern (C) void XMLHttpRequestEventTarget_onerror_Set(Handle, EventHandler); 312 extern (C) EventHandler XMLHttpRequestEventTarget_onerror_Get(Handle); 313 extern (C) void XMLHttpRequestEventTarget_onload_Set(Handle, EventHandler); 314 extern (C) EventHandler XMLHttpRequestEventTarget_onload_Get(Handle); 315 extern (C) void XMLHttpRequestEventTarget_ontimeout_Set(Handle, EventHandler); 316 extern (C) EventHandler XMLHttpRequestEventTarget_ontimeout_Get(Handle); 317 extern (C) void XMLHttpRequestEventTarget_onloadend_Set(Handle, EventHandler); 318 extern (C) EventHandler XMLHttpRequestEventTarget_onloadend_Get(Handle);