@webqit/webflo 0.11.39 → 0.11.40
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/package.json +2 -3
- package/src/Context.js +3 -3
- package/src/config-pi/deployment/Layout.js +0 -1
- package/src/runtime-pi/{RuntimeClient.js → Application.js} +2 -2
- package/src/runtime-pi/HttpEvent.js +106 -0
- package/src/runtime-pi/Router.js +2 -3
- package/src/runtime-pi/Runtime.js +3 -3
- package/src/runtime-pi/client/{RuntimeClient.js → Application.js} +12 -4
- package/src/runtime-pi/client/Router.js +4 -3
- package/src/runtime-pi/client/Runtime.js +37 -59
- package/src/runtime-pi/client/Url.js +3 -3
- package/src/runtime-pi/client/Workport.js +1 -1
- package/src/runtime-pi/client/{Storage.js → createStorage.js} +3 -3
- package/src/runtime-pi/client/generate.js +5 -3
- package/src/runtime-pi/client/index.js +4 -4
- package/src/runtime-pi/client/worker/{WorkerClient.js → Application.js} +12 -8
- package/src/runtime-pi/client/worker/{Worker.js → Runtime.js} +25 -27
- package/src/runtime-pi/client/worker/index.js +6 -6
- package/src/runtime-pi/server/{RuntimeClient.js → Application.js} +8 -8
- package/src/runtime-pi/server/Router.js +3 -2
- package/src/runtime-pi/server/Runtime.js +41 -98
- package/src/runtime-pi/server/index.js +4 -4
- package/src/runtime-pi/util-http.js +70 -0
- package/src/runtime-pi/util-url.js +147 -0
- package/src/runtime-pi/xFormData.js +10 -46
- package/src/runtime-pi/xHeaders.js +2 -11
- package/src/runtime-pi/xRequest.js +29 -42
- package/src/runtime-pi/xRequestHeaders.js +20 -23
- package/src/runtime-pi/xResponse.js +19 -15
- package/src/runtime-pi/xResponseHeaders.js +41 -43
- package/src/runtime-pi/xURL.js +71 -77
- package/src/runtime-pi/xfetch.js +15 -6
- package/src/runtime-pi/xxHttpMessage.js +102 -0
- package/src/runtime-pi/client/whatwag.js +0 -27
- package/src/runtime-pi/server/whatwag.js +0 -35
- package/src/runtime-pi/util.js +0 -162
- package/src/runtime-pi/xHttpEvent.js +0 -101
- package/src/runtime-pi/xHttpMessage.js +0 -171
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isArray, _isEmpty, _isNumber, _isObject, _isPlainArray, _isPlainObject, _isString } from '@webqit/util/js/index.js';
|
|
6
|
-
import { formDataType } from './xFormData.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The _Request Mixin
|
|
10
|
-
*/
|
|
11
|
-
const xHttpMessage = (whatwagHttpMessage, Headers, FormData) => {
|
|
12
|
-
const HttpMessage = class extends whatwagHttpMessage {
|
|
13
|
-
|
|
14
|
-
constructor(input, init, bodyAttrs) {
|
|
15
|
-
if (init.headers) { init = { ...init, headers: new Headers(init.headers) }; }
|
|
16
|
-
super(input, init);
|
|
17
|
-
if (bodyAttrs.headers) {
|
|
18
|
-
this.headers.json(bodyAttrs.headers);
|
|
19
|
-
}
|
|
20
|
-
let attrs = {};
|
|
21
|
-
Object.defineProperty(this, 'attrs', { get: () => attrs });
|
|
22
|
-
Object.defineProperty(this, 'bodyAttrs', { get: () => bodyAttrs });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
clone() {
|
|
26
|
-
return new this.constructor(super.clone());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get headers() {
|
|
30
|
-
Headers.compat(super.headers);
|
|
31
|
-
return super.headers;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get attrs() {
|
|
35
|
-
return this.attrs;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get url() {
|
|
39
|
-
return 'url' in this.attrs ? this.attrs.url : super.url;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async arrayBuffer() {
|
|
43
|
-
if (this.bodyAttrs.arrayBuffer) {
|
|
44
|
-
return this.bodyAttrs.arrayBuffer;
|
|
45
|
-
}
|
|
46
|
-
return super.arrayBuffer();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async blob() {
|
|
50
|
-
if (this.bodyAttrs.blob) {
|
|
51
|
-
return this.bodyAttrs.blob;
|
|
52
|
-
}
|
|
53
|
-
return super.blob();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async formData() {
|
|
57
|
-
if (this.bodyAttrs.formData) {
|
|
58
|
-
return this.bodyAttrs.formData;
|
|
59
|
-
}
|
|
60
|
-
const formData = await super.formData();
|
|
61
|
-
formData.tee = FormData.prototype.tee.bind(formData);
|
|
62
|
-
formData.json = FormData.prototype.json.bind(formData);
|
|
63
|
-
return formData;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async json() {
|
|
67
|
-
if (this.bodyAttrs.json) {
|
|
68
|
-
return this.bodyAttrs.json;
|
|
69
|
-
}
|
|
70
|
-
return super.json();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async text() {
|
|
74
|
-
if (this.bodyAttrs.text) {
|
|
75
|
-
return this.bodyAttrs.text;
|
|
76
|
-
}
|
|
77
|
-
return super.text();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Resolve
|
|
81
|
-
jsonfy(force = false) {
|
|
82
|
-
if (!this.bodyAttrs.jsonfied || force) {
|
|
83
|
-
this.bodyAttrs.jsonfied = new Promise(async (resolve, reject) => {
|
|
84
|
-
var messageInstance = this, jsonfied, contentType = messageInstance.headers.get('content-type') || '';
|
|
85
|
-
var type = contentType === 'application/json' || this.bodyAttrs.json ? 'json' : (
|
|
86
|
-
contentType === 'application/x-www-form-urlencoded' || contentType.startsWith('multipart/form-data') || this.bodyAttrs.formData ? 'formData' : (
|
|
87
|
-
contentType === 'text/plain' ? 'plain' : 'other'
|
|
88
|
-
)
|
|
89
|
-
);
|
|
90
|
-
try {
|
|
91
|
-
if (type === 'formData') {
|
|
92
|
-
jsonfied = (await messageInstance.formData()).json();
|
|
93
|
-
} else {
|
|
94
|
-
jsonfied = type === 'json' ? await messageInstance.json() : (
|
|
95
|
-
type === 'plain' ? await messageInstance.text() : messageInstance.body
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
resolve(jsonfied);
|
|
99
|
-
} catch(e) {
|
|
100
|
-
reject(e);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return this.bodyAttrs.jsonfied;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
};
|
|
108
|
-
// ----------
|
|
109
|
-
HttpMessage.Headers = Headers;
|
|
110
|
-
// ----------
|
|
111
|
-
return HttpMessage;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export default xHttpMessage;
|
|
115
|
-
export function encodeBody(body, FormData, Blob) {
|
|
116
|
-
const detailsObj = { body, input: body };
|
|
117
|
-
const encodeFormData = (detailsObj, formData) => {
|
|
118
|
-
if (FormData.encode) {
|
|
119
|
-
let [ body, headers ] = FormData.encode(formData);
|
|
120
|
-
detailsObj.body = body;
|
|
121
|
-
detailsObj.headers = headers;
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
detailsObj.body = formData;
|
|
125
|
-
}
|
|
126
|
-
if (_isString(body) || _isNumber(body)) {
|
|
127
|
-
detailsObj.inputType = 'text';
|
|
128
|
-
detailsObj.text = body;
|
|
129
|
-
detailsObj.headers = {
|
|
130
|
-
contentLength: (body + '').length,
|
|
131
|
-
};
|
|
132
|
-
return detailsObj;
|
|
133
|
-
}
|
|
134
|
-
detailsObj.inputType = formDataType(body);
|
|
135
|
-
if ([ 'Blob', 'File' ].includes(detailsObj.inputType)) {
|
|
136
|
-
detailsObj.blob = body;
|
|
137
|
-
detailsObj.headers = {
|
|
138
|
-
contentType: body.type,
|
|
139
|
-
contentLength: body.size,
|
|
140
|
-
};
|
|
141
|
-
} else if ([ 'Uint8Array', 'Uint16Array', 'Uint32Array', 'ArrayBuffer' ].includes(detailsObj.inputType)) {
|
|
142
|
-
detailsObj.arrayBuffer = body;
|
|
143
|
-
detailsObj.headers = {
|
|
144
|
-
contentLength: body.byteLength,
|
|
145
|
-
};
|
|
146
|
-
} else if (detailsObj.inputType === 'FormData') {
|
|
147
|
-
detailsObj.formData = body;
|
|
148
|
-
encodeFormData(detailsObj, body);
|
|
149
|
-
} else if ((_isObject(body) && _isPlainObject(body)) || (_isArray(body) && _isPlainArray(body))) {
|
|
150
|
-
detailsObj.inputType = 'object';
|
|
151
|
-
// Deserialize object while detecting if multipart
|
|
152
|
-
var hasBlobs, formData = new FormData;
|
|
153
|
-
formData.json(body, (path, value, objectType) => {
|
|
154
|
-
hasBlobs = hasBlobs || objectType;
|
|
155
|
-
return true;
|
|
156
|
-
});
|
|
157
|
-
if (hasBlobs) {
|
|
158
|
-
detailsObj.formData = formData;
|
|
159
|
-
encodeFormData(detailsObj, formData);
|
|
160
|
-
} else {
|
|
161
|
-
detailsObj.json = body;
|
|
162
|
-
detailsObj.body = JSON.stringify(body);
|
|
163
|
-
detailsObj.headers = {
|
|
164
|
-
contentType: 'application/json',
|
|
165
|
-
contentLength: (new Blob([ detailsObj.body ])).size, // Buffer.byteLength(detailsObj.body, 'utf8') isn't cross-environment
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
detailsObj.jsonfied = body;
|
|
169
|
-
}
|
|
170
|
-
return detailsObj;
|
|
171
|
-
}
|