workbox-streams
Advanced tools
Comparing version 3.6.2 to 4.0.0-alpha.0
@@ -6,20 +6,12 @@ this.workbox = this.workbox || {}; | ||
try { | ||
self.workbox.v['workbox:streams:3.6.2'] = 1; | ||
self.workbox.v['workbox:streams:4.0.0-alpha.0'] = 1; | ||
} catch (e) {} // eslint-disable-line | ||
/* | ||
Copyright 2018 Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
Copyright 2018 Google LLC | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ | ||
/** | ||
@@ -34,2 +26,3 @@ * Takes either a Response, a ReadableStream, or a | ||
*/ | ||
function _getReaderFromSource(source) { | ||
@@ -42,10 +35,9 @@ if (source.body && source.body.getReader) { | ||
return source.getReader(); | ||
} | ||
// TODO: This should be possible to do by constructing a ReadableStream, but | ||
} // TODO: This should be possible to do by constructing a ReadableStream, but | ||
// I can't get it to work. As a hack, construct a new Response, and use the | ||
// reader associated with its body. | ||
return new Response(source).body.getReader(); | ||
} | ||
/** | ||
@@ -64,2 +56,4 @@ * Takes multiple source Promises, each of which could resolve to a Response, a | ||
*/ | ||
function concatenate(sourcePromises) { | ||
@@ -79,3 +73,2 @@ { | ||
}); | ||
let fullyStreamedResolve; | ||
@@ -87,3 +80,2 @@ let fullyStreamedReject; | ||
}); | ||
let i = 0; | ||
@@ -100,2 +92,3 @@ const logMessages = []; | ||
i++; | ||
if (i >= readerPromises.length) { | ||
@@ -105,2 +98,3 @@ // Log all the messages in the group at once in a single group. | ||
logger_mjs.logger.groupCollapsed(`Concatenating ${readerPromises.length} sources.`); | ||
for (const message of logMessages) { | ||
@@ -113,2 +107,3 @@ if (Array.isArray(message)) { | ||
} | ||
logger_mjs.logger.log('Finished reading all sources.'); | ||
@@ -131,2 +126,3 @@ logger_mjs.logger.groupEnd(); | ||
} | ||
fullyStreamedReject(error); | ||
@@ -144,22 +140,17 @@ throw error; | ||
} | ||
}); | ||
return { done, stream }; | ||
return { | ||
done, | ||
stream | ||
}; | ||
} | ||
/* | ||
Copyright 2018 Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
Copyright 2018 Google LLC | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ | ||
/** | ||
@@ -178,8 +169,11 @@ * This is a utility method that determines whether the current browser supports | ||
*/ | ||
function createHeaders(headersInit = {}) { | ||
// See https://github.com/GoogleChrome/workbox/issues/1461 | ||
const headers = new Headers(headersInit); | ||
if (!headers.has('content-type')) { | ||
headers.set('content-type', 'text/html'); | ||
} | ||
return headers; | ||
@@ -189,16 +183,8 @@ } | ||
/* | ||
Copyright 2018 Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
Copyright 2018 Google LLC | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ | ||
/** | ||
@@ -221,28 +207,26 @@ * Takes multiple source Promises, each of which could resolve to a Response, a | ||
*/ | ||
function concatenateToResponse(sourcePromises, headersInit) { | ||
const { done, stream } = concatenate(sourcePromises); | ||
const { | ||
done, | ||
stream | ||
} = concatenate(sourcePromises); | ||
const headers = createHeaders(headersInit); | ||
const response = new Response(stream, { headers }); | ||
return { done, response }; | ||
const response = new Response(stream, { | ||
headers | ||
}); | ||
return { | ||
done, | ||
response | ||
}; | ||
} | ||
/* | ||
Copyright 2018 Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
Copyright 2018 Google LLC | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ | ||
let cachedIsSupported = undefined; | ||
/** | ||
@@ -259,2 +243,3 @@ * This is a utility method that determines whether the current browser supports | ||
*/ | ||
function isSupported() { | ||
@@ -264,3 +249,6 @@ if (cachedIsSupported === undefined) { | ||
try { | ||
new ReadableStream({ start() {} }); | ||
new ReadableStream({ | ||
start() {} | ||
}); | ||
cachedIsSupported = true; | ||
@@ -276,16 +264,8 @@ } catch (error) { | ||
/* | ||
Copyright 2018 Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
Copyright 2018 Google LLC | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ | ||
/** | ||
@@ -308,80 +288,66 @@ * A shortcut to create a strategy that could be dropped-in to Workbox's router. | ||
*/ | ||
function strategy(sourceFunctions, headersInit) { | ||
return (() => { | ||
var _ref = babelHelpers.asyncToGenerator(function* ({ event, url, params }) { | ||
if (isSupported()) { | ||
const { done, response } = concatenateToResponse(sourceFunctions.map(function (sourceFunction) { | ||
return sourceFunction({ event, url, params }); | ||
}), headersInit); | ||
event.waitUntil(done); | ||
return response; | ||
} | ||
return async ({ | ||
event, | ||
url, | ||
params | ||
}) => { | ||
if (isSupported()) { | ||
const { | ||
done, | ||
response | ||
} = concatenateToResponse(sourceFunctions.map(fn => fn({ | ||
event, | ||
url, | ||
params | ||
})), headersInit); | ||
event.waitUntil(done); | ||
return response; | ||
} | ||
{ | ||
logger_mjs.logger.log(`The current browser doesn't support creating response ` + `streams. Falling back to non-streaming response instead.`); | ||
} | ||
{ | ||
logger_mjs.logger.log(`The current browser doesn't support creating response ` + `streams. Falling back to non-streaming response instead.`); | ||
} // Fallback to waiting for everything to finish, and concatenating the | ||
// responses. | ||
// Fallback to waiting for everything to finish, and concatenating the | ||
// responses. | ||
const parts = yield Promise.all(sourceFunctions.map(function (sourceFunction) { | ||
return sourceFunction({ event, url, params }); | ||
}).map((() => { | ||
var _ref2 = babelHelpers.asyncToGenerator(function* (responsePromise) { | ||
const response = yield responsePromise; | ||
if (response instanceof Response) { | ||
return response.blob(); | ||
} | ||
// Otherwise, assume it's something like a string which can be used | ||
// as-is when constructing the final composite blob. | ||
return response; | ||
}); | ||
const parts = await Promise.all(sourceFunctions.map(sourceFunction => sourceFunction({ | ||
event, | ||
url, | ||
params | ||
})).map(async responsePromise => { | ||
const response = await responsePromise; | ||
return function (_x2) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
})())); | ||
if (response instanceof Response) { | ||
return response.blob(); | ||
} // Otherwise, assume it's something like a string which can be used | ||
// as-is when constructing the final composite blob. | ||
const headers = createHeaders(headersInit); | ||
// Constructing a new Response from a Blob source is well-supported. | ||
// So is constructing a new Blob from multiple source Blobs or strings. | ||
return new Response(new Blob(parts), { headers }); | ||
return response; | ||
})); | ||
const headers = createHeaders(headersInit); // Constructing a new Response from a Blob source is well-supported. | ||
// So is constructing a new Blob from multiple source Blobs or strings. | ||
return new Response(new Blob(parts), { | ||
headers | ||
}); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
})(); | ||
}; | ||
} | ||
/* | ||
Copyright 2018 Google Inc. | ||
Copyright 2018 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ | ||
/* | ||
Copyright 2018 Google Inc. | ||
Copyright 2018 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ | ||
@@ -388,0 +354,0 @@ |
@@ -1,3 +0,3 @@ | ||
this.workbox=this.workbox||{},this.workbox.streams=function(e){"use strict";try{self.workbox.v["workbox:streams:3.6.2"]=1}catch(e){}function n(e){const n=e.map(e=>Promise.resolve(e).then(e=>(e=e).body&&e.body.getReader?e.body.getReader():e.getReader?e.getReader():new Response(e).body.getReader()));var t;let r,s;let o=0;return{done:new Promise((e,n)=>{r=e,s=n}),stream:new ReadableStream({pull(e){return n[o].then(e=>e.read()).then(t=>{if(t.done)return++o>=n.length?(e.close(),void r()):this.pull(e);e.enqueue(t.value)}).catch(e=>{throw s(e),e})},cancel(){r()}})}}function t(e={}){const n=new Headers(e);return n.has("content-type")||n.set("content-type","text/html"),n}function r(e,r){const{done:s,stream:o}=n(e),u=t(r);return{done:s,response:new Response(o,{headers:u})}}let s=void 0;function o(){if(void 0===s)try{new ReadableStream({start(){}}),s=!0}catch(e){s=!1}return s}return e.concatenate=n,e.concatenateToResponse=r,e.isSupported=o,e.strategy=function(e,n){return s=babelHelpers.asyncToGenerator(function*({event:s,url:u,params:i}){if(o()){const{done:t,response:o}=r(e.map(function(e){return e({event:s,url:u,params:i})}),n);return s.waitUntil(t),o}const c=yield Promise.all(e.map(function(e){return e({event:s,url:u,params:i})}).map((a=babelHelpers.asyncToGenerator(function*(e){const n=yield e;return n instanceof Response?n.blob():n}),function(e){return a.apply(this,arguments)})));var a;const l=t(n);return new Response(new Blob(c),{headers:l})}),function(e){return s.apply(this,arguments)};var s},e}({}); | ||
this.workbox=this.workbox||{},this.workbox.streams=function(e){"use strict";try{self.workbox.v["workbox:streams:4.0.0-alpha.0"]=1}catch(e){}function n(e){const n=e.map(e=>Promise.resolve(e).then(e=>(function(e){return e.body&&e.body.getReader?e.body.getReader():e.getReader?e.getReader():new Response(e).body.getReader()})(e)));let t,r;const s=new Promise((e,n)=>{t=e,r=n});let o=0;return{done:s,stream:new ReadableStream({pull(e){return n[o].then(e=>e.read()).then(r=>{if(r.done)return++o>=n.length?(e.close(),void t()):this.pull(e);e.enqueue(r.value)}).catch(e=>{throw r(e),e})},cancel(){t()}})}}function t(e={}){const n=new Headers(e);return n.has("content-type")||n.set("content-type","text/html"),n}function r(e,r){const{done:s,stream:o}=n(e),a=t(r);return{done:s,response:new Response(o,{headers:a})}}let s=void 0;function o(){if(void 0===s)try{new ReadableStream({start(){}}),s=!0}catch(e){s=!1}return s}return e.concatenate=n,e.concatenateToResponse=r,e.isSupported=o,e.strategy=function(e,n){return async({event:s,url:a,params:c})=>{if(o()){const{done:t,response:o}=r(e.map(e=>e({event:s,url:a,params:c})),n);return s.waitUntil(t),o}const i=await Promise.all(e.map(e=>e({event:s,url:a,params:c})).map(async e=>{const n=await e;return n instanceof Response?n.blob():n})),u=t(n);return new Response(new Blob(i),{headers:u})}},e}({}); | ||
//# sourceMappingURL=workbox-streams.prod.js.map |
{ | ||
"name": "workbox-streams", | ||
"version": "3.6.2", | ||
"license": "Apache-2.0", | ||
"version": "4.0.0-alpha.0", | ||
"license": "MIT", | ||
"author": "Google's Web DevRel Team", | ||
@@ -30,4 +30,5 @@ "description": "A library that makes it easier to work with Streams in the browser.", | ||
"dependencies": { | ||
"workbox-core": "^3.6.2" | ||
} | ||
"workbox-core": "^4.0.0-alpha.0" | ||
}, | ||
"gitHead": "db1fb73fd32fbd5cbf42e246e6144011a5c6edc2" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 6 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
17
37827
7
60
620
1
+ Addedworkbox-core@4.3.1(transitive)
- Removedworkbox-core@3.6.3(transitive)
Updatedworkbox-core@^4.0.0-alpha.0