@webqit/webflo 0.11.30 → 0.11.31

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 CHANGED
@@ -12,7 +12,7 @@
12
12
  "vanila-javascript"
13
13
  ],
14
14
  "homepage": "https://webqit.io/tooling/webflo",
15
- "version": "0.11.30",
15
+ "version": "0.11.31",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -298,7 +298,7 @@ export default class Runtime {
298
298
  // ------------
299
299
  // Rendering
300
300
  // ------------
301
- if (finalResponse.ok && finalResponse.headers.contentType === 'application/json') {
301
+ if (finalResponse.ok && (finalResponse.headers.contentType === 'application/json' || finalResponse.headers.contentType.startsWith('multipart/form-data'))) {
302
302
  client.render && await client.render(httpEvent, finalResponse);
303
303
  } else if (!finalResponse.ok) {
304
304
  if ([404, 500].includes(finalResponse.status)) {
@@ -317,8 +317,13 @@ export default class Runtime {
317
317
  }
318
318
 
319
319
  // Initiates remote fetch and sets the status
320
- remoteFetch(request, ...args) {
321
- let href = typeof request === 'string' ? request : (request.url || request.href);
320
+ async remoteFetch(request, ...args) {
321
+ let href = request;
322
+ if (request instanceof Request) {
323
+ href = request.url;
324
+ } else if (request instanceof self.URL) {
325
+ href = request.href;
326
+ }
322
327
  Observer.set(this.network, 'remote', href);
323
328
  let _response = fetch(request, ...args);
324
329
  // This catch() is NOT intended to handle failure of the fetch
@@ -45,7 +45,7 @@ export default class RuntimeClient {
45
45
 
46
46
  // Renderer
47
47
  async render(httpEvent, response) {
48
- let data = await response.json();
48
+ let data = await response.jsonfy();
49
49
  const router = new Router(this.cx, httpEvent.url.pathname);
50
50
  return router.route('render', httpEvent, data, async (httpEvent, data) => {
51
51
  // --------
@@ -401,7 +401,7 @@ async function bundle(gen, outfile, asModule = false) {
401
401
  }
402
402
  }
403
403
  // Remove moduleFile build
404
- Fs.unlinkSync(bundlingConfig.entryPoints[0]);
404
+ //Fs.unlinkSync(bundlingConfig.entryPoints[0]);
405
405
  removals.forEach(file => Fs.existsSync(file) && Fs.unlinkSync(file));
406
406
  if (waiting) waiting.stop();
407
407
  // ----------------
@@ -99,12 +99,7 @@ export default class Worker {
99
99
  event.respondWith((async (req, evt) => {
100
100
  let requestingClient = await self.clients.get(event.clientId);
101
101
  this.workport.setCurrentClient(requestingClient);
102
- const requestInit = [
103
- 'method', 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity',
104
- ].reduce((init, prop) => ({ [prop]: req[prop], ...init }), {});
105
- if (!['GET', 'HEAD'].includes(req.method)) {
106
- requestInit.body = await req.text();
107
- }
102
+ const [ url, requestInit ] = await Request.rip(req);
108
103
  // Now, the following is key:
109
104
  // The browser likes to use "force-cache" for "navigate" requests, when, e.g: re-entering your site with the back button
110
105
  // Problem here, force-cache forces out JSON not HTML as per webflo's design.
@@ -112,7 +107,7 @@ export default class Worker {
112
107
  if (req.cache === 'force-cache'/* && req.mode === 'navigate' - even webflo client init call also comes with that... needs investigation */) {
113
108
  requestInit.cache = 'default';
114
109
  }
115
- return this.go(req.url, requestInit, { event: evt });
110
+ return this.go(url, requestInit, { event: evt });
116
111
  })(event.request, event));
117
112
  });
118
113
 
@@ -164,7 +164,7 @@ export default class Runtime {
164
164
  const requestInit = { method: request.method, headers: request.headers };
165
165
  if (request.method !== 'GET' && request.method !== 'HEAD') {
166
166
  requestInit.body = await new Promise((resolve, reject) => {
167
- var formidable = new Formidable.IncomingForm({ multiples: true, allowEmptyFiles: false, keepExtensions: true });
167
+ var formidable = new Formidable.IncomingForm({ multiples: true, allowEmptyFiles: true, keepExtensions: true });
168
168
  formidable.parse(request, (error, fields, files) => {
169
169
  if (error) {
170
170
  reject(error);
@@ -371,7 +371,13 @@ export default class Runtime {
371
371
 
372
372
  // Initiates remote fetch and sets the status
373
373
  remoteFetch(request, ...args) {
374
- Observer.set(this.network, 'remote', true);
374
+ let href = request;
375
+ if (request instanceof Request) {
376
+ href = request.url;
377
+ } else if (request instanceof self.URL) {
378
+ href = request.href;
379
+ }
380
+ Observer.set(this.network, 'remote', href);
375
381
  let _response = fetch(request, ...args);
376
382
  // This catch() is NOT intended to handle failure of the fetch
377
383
  _response.catch(e => Observer.set(this.network, 'error', e.message));
@@ -515,7 +521,7 @@ export default class Runtime {
515
521
  log.push(style.keyword(e.request.method));
516
522
  log.push(style.url(e.request.url));
517
523
  if (response.attrs.hint) log.push(`(${style.comment(response.attrs.hint)})`);
518
- if (response.headers.contentType) log.push(`(${style.comment(response.headers.contentType)})`);
524
+ if (response.headers.contentType) log.push(`(${style.comment(response.headers.contentType)}--)`);
519
525
  if (response.headers.get('Content-Encoding')) log.push(`(${style.comment(response.headers.get('Content-Encoding'))})`);
520
526
  if (errorCode) log.push(style.err(`${errorCode} ${response.statusText}`));
521
527
  else log.push(style.val(`${statusCode} ${response.statusText}`));
@@ -70,7 +70,7 @@ export default class RuntimeClient {
70
70
 
71
71
  // Renderer
72
72
  async render(httpEvent, router, response) {
73
- let data = await response.json();
73
+ let data = await response.jsonfy();
74
74
  let rendering = await router.route('render', httpEvent, data, async (httpEvent, data) => {
75
75
  var renderFile, pathnameSplit = httpEvent.url.pathname.split('/');
76
76
  while ((renderFile = Path.join(this.cx.CWD, this.cx.layout.PUBLIC_DIR, './' + pathnameSplit.join('/'), 'index.html'))
@@ -71,6 +71,17 @@ const xHeaders = whatwagHeaders => class extends whatwagHeaders {
71
71
  return this.get('Content-Type');
72
72
  }
73
73
 
74
+ static compat(headers) {
75
+ if (!(headers instanceof this) && !headers.json) {
76
+ const descs = getAllPropertyDescriptors(new this);
77
+ Object.keys(descs).forEach(key => {
78
+ if (typeof key === 'symbol' || (key in headers)) return;
79
+ Object.defineProperty(headers, key, descs[key]);
80
+ });
81
+ }
82
+ return headers;
83
+ }
84
+
74
85
  }
75
86
 
76
87
  export default xHeaders;
@@ -12,17 +12,8 @@ const xHttpMessage = (whatwagHttpMessage, Headers, FormData) => {
12
12
  const HttpMessage = class extends whatwagHttpMessage {
13
13
 
14
14
  constructor(input, init, bodyAttrs) {
15
- if (('headers' in init) && !(init.headers instanceof Headers)) {
16
- init = { ...init };
17
- init.headers = new Headers(init.headers);
18
- arguments[1] = init;
19
- }
20
- if (_isEmpty(init)) {
21
- super(input);
22
- } else {
23
- super(input, init);
24
- }
25
- this._headers = init.headers;
15
+ if (init.headers) { init = { ...init, headers: new Headers(init.headers) }; }
16
+ super(input, init);
26
17
  if (bodyAttrs.headers) {
27
18
  this.headers.json(bodyAttrs.headers);
28
19
  }
@@ -36,10 +27,8 @@ const xHttpMessage = (whatwagHttpMessage, Headers, FormData) => {
36
27
  }
37
28
 
38
29
  get headers() {
39
- if (!this._headers) {
40
- this._headers = new Headers(super.headers);
41
- }
42
- return this._headers;
30
+ Headers.compat(super.headers);
31
+ return super.headers;
43
32
  }
44
33
 
45
34
  get attrs() {
@@ -126,10 +115,13 @@ export default xHttpMessage;
126
115
  export function encodeBody(body, FormData, Blob) {
127
116
  const detailsObj = { body, input: body };
128
117
  const encodeFormData = (detailsObj, formData) => {
129
- if (!FormData.encode) return;
130
- let [ body, headers ] = FormData.encode(formData);
131
- detailsObj.body = body;
132
- detailsObj.headers = headers;
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;
133
125
  }
134
126
  if (_isString(body) || _isNumber(body)) {
135
127
  detailsObj.inputType = 'text';
@@ -62,11 +62,21 @@ const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHtt
62
62
  return 'referrer' in this.attrs ? this.attrs.referrer : super.referrer;
63
63
  }
64
64
 
65
- static compat(request, url = null) {
65
+ static async rip(request) {
66
+ const requestInit = [
67
+ 'method', 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity',
68
+ ].reduce((init, prop) => ({ [prop]: request[prop], ...init }), {});
69
+ if (!['GET', 'HEAD'].includes(request.method)) {
70
+ requestInit.body = await request.text();
71
+ }
72
+ return [ request.url, requestInit ];
73
+ }
74
+
75
+ static compat(request) {
76
+ if (request instanceof this) return request;
66
77
  if (request instanceof whatwagRequest) {
67
78
  return Object.setPrototypeOf(request, new this);
68
79
  }
69
- return new this(url, request);
70
80
  }
71
81
 
72
82
  };
@@ -58,10 +58,10 @@ const xResponse = (whatwagResponse, Headers, FormData, Blob) => class extends xH
58
58
  }
59
59
 
60
60
  static compat(response) {
61
+ if (response instanceof this) return response;
61
62
  if (response instanceof whatwagResponse) {
62
63
  return Object.setPrototypeOf(response, new this);
63
64
  }
64
- return new this(response);
65
65
  }
66
66
 
67
67
  };
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  /**
4
4
  * imports
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  /**
4
4
  * imports
package/src/webflo.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  /**
4
4
  * @imports