@loaders.gl/core 4.0.0-beta.8 → 4.0.1
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/dist/dist.dev.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/lib/utils/response-utils.d.ts +1 -1
- package/dist/lib/utils/response-utils.d.ts.map +1 -1
- package/dist/lib/utils/response-utils.js +1 -1
- package/dist/lib/utils/response-utils.js.map +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/package.json +8 -5
- package/src/lib/utils/response-utils.ts +9 -7
package/dist/dist.dev.js
CHANGED
|
@@ -1607,7 +1607,7 @@ var __exports__ = (() => {
|
|
|
1607
1607
|
try {
|
|
1608
1608
|
const contentType = response.headers.get("Content-Type");
|
|
1609
1609
|
let text = response.statusText;
|
|
1610
|
-
if (contentType
|
|
1610
|
+
if (contentType?.includes("application/json")) {
|
|
1611
1611
|
text += ` ${await response.text()}`;
|
|
1612
1612
|
}
|
|
1613
1613
|
message += text;
|
package/dist/index.cjs
CHANGED
|
@@ -216,7 +216,7 @@ async function getResponseError(response) {
|
|
|
216
216
|
try {
|
|
217
217
|
const contentType = response.headers.get("Content-Type");
|
|
218
218
|
let text = response.statusText;
|
|
219
|
-
if (contentType.includes("application/json")) {
|
|
219
|
+
if (contentType == null ? void 0 : contentType.includes("application/json")) {
|
|
220
220
|
text += ` ${await response.text()}`;
|
|
221
221
|
}
|
|
222
222
|
message += text;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @param resource
|
|
6
6
|
*/
|
|
7
|
-
export declare function makeResponse(resource:
|
|
7
|
+
export declare function makeResponse(resource: unknown): Promise<Response>;
|
|
8
8
|
/**
|
|
9
9
|
* Checks response status (async) and throws a helpful error message if status is not OK.
|
|
10
10
|
* @param response
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/response-utils.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"response-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/response-utils.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuCvE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAKrE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAM1D"}
|
|
@@ -47,7 +47,7 @@ async function getResponseError(response) {
|
|
|
47
47
|
try {
|
|
48
48
|
const contentType = response.headers.get('Content-Type');
|
|
49
49
|
let text = response.statusText;
|
|
50
|
-
if (contentType.includes('application/json')) {
|
|
50
|
+
if (contentType !== null && contentType !== void 0 && contentType.includes('application/json')) {
|
|
51
51
|
text += ` ${await response.text()}`;
|
|
52
52
|
}
|
|
53
53
|
message += text;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-utils.js","names":["isResponse","getResourceContentLength","getResourceUrl","getResourceMIMEType","makeResponse","resource","headers","contentLength","String","url","type","initialDataUrl","getInitialDataUrl","TextEncoder","encode","response","Response","Object","defineProperty","value","checkResponse","ok","message","getResponseError","Error","checkResponseSync","status","statusText","length","slice","contentType","get","text","includes","error","INITIAL_DATA_LENGTH","Blob","blobSlice","Promise","resolve","reader","FileReader","onload","event","_event$target","target","result","readAsDataURL","ArrayBuffer","base64","arrayBufferToBase64","buffer","binary","bytes","Uint8Array","i","byteLength","fromCharCode","btoa"],"sources":["../../../src/lib/utils/response-utils.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {isResponse} from '../../javascript-utils/is-type';\nimport {getResourceContentLength, getResourceUrl, getResourceMIMEType} from './resource-utils';\n\n/**\n * Returns a Response object\n * Adds content-length header when possible\n *\n * @param resource\n */\nexport async function makeResponse(resource:
|
|
1
|
+
{"version":3,"file":"response-utils.js","names":["isResponse","getResourceContentLength","getResourceUrl","getResourceMIMEType","makeResponse","resource","headers","contentLength","String","url","type","initialDataUrl","getInitialDataUrl","TextEncoder","encode","response","Response","Object","defineProperty","value","checkResponse","ok","message","getResponseError","Error","checkResponseSync","status","statusText","length","slice","contentType","get","text","includes","error","INITIAL_DATA_LENGTH","Blob","blobSlice","Promise","resolve","reader","FileReader","onload","event","_event$target","target","result","readAsDataURL","ArrayBuffer","base64","arrayBufferToBase64","buffer","binary","bytes","Uint8Array","i","byteLength","fromCharCode","btoa"],"sources":["../../../src/lib/utils/response-utils.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {isResponse} from '../../javascript-utils/is-type';\nimport {getResourceContentLength, getResourceUrl, getResourceMIMEType} from './resource-utils';\n\n/**\n * Returns a Response object\n * Adds content-length header when possible\n *\n * @param resource\n */\nexport async function makeResponse(resource: unknown): Promise<Response> {\n if (isResponse(resource)) {\n return resource as Response;\n }\n\n // Add content-length header if possible\n const headers: {[header: string]: string} = {};\n\n const contentLength = getResourceContentLength(resource);\n if (contentLength >= 0) {\n headers['content-length'] = String(contentLength);\n }\n\n // `new Response(File)` does not preserve content-type and URL\n // so we add them here\n const url = getResourceUrl(resource);\n const type = getResourceMIMEType(resource);\n if (type) {\n headers['content-type'] = type;\n }\n\n // Add a custom header with initial bytes if available\n const initialDataUrl = await getInitialDataUrl(resource);\n if (initialDataUrl) {\n headers['x-first-bytes'] = initialDataUrl;\n }\n\n // TODO - is this the best way of handling strings?\n // Maybe package as data URL instead?\n if (typeof resource === 'string') {\n // Convert to ArrayBuffer to avoid Response treating it as a URL\n resource = new TextEncoder().encode(resource);\n }\n\n // Attempt to create a Response from the resource, adding headers and setting url\n const response = new Response(resource as any, {headers});\n // We can't control `Response.url` via constructor, use a property override to record URL.\n Object.defineProperty(response, 'url', {value: url});\n return response;\n}\n\n/**\n * Checks response status (async) and throws a helpful error message if status is not OK.\n * @param response\n */\nexport async function checkResponse(response: Response): Promise<void> {\n if (!response.ok) {\n const message = await getResponseError(response);\n throw new Error(message);\n }\n}\n\n/**\n * Checks response status (sync) and throws a helpful error message if status is not OK.\n * @param response\n */\nexport function checkResponseSync(response: Response): void {\n if (!response.ok) {\n let message = `${response.status} ${response.statusText}`;\n message = message.length > 60 ? `${message.slice(0, 60)}...` : message;\n throw new Error(message);\n }\n}\n\n// HELPERS\n\nasync function getResponseError(response: Response): Promise<string> {\n let message = `Failed to fetch resource ${response.url} (${response.status}): `;\n try {\n const contentType = response.headers.get('Content-Type');\n let text = response.statusText;\n if (contentType?.includes('application/json')) {\n text += ` ${await response.text()}`;\n }\n message += text;\n message = message.length > 60 ? `${message.slice(0, 60)}...` : message;\n } catch (error) {\n // eslint forbids return in a finally statement, so we just catch here\n }\n return message;\n}\n\nasync function getInitialDataUrl(\n resource: string | Blob | ArrayBuffer | unknown\n): Promise<string | null> {\n const INITIAL_DATA_LENGTH = 5;\n if (typeof resource === 'string') {\n return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;\n }\n if (resource instanceof Blob) {\n const blobSlice = resource.slice(0, 5);\n return await new Promise((resolve) => {\n const reader = new FileReader();\n reader.onload = (event) => resolve(event?.target?.result as string);\n reader.readAsDataURL(blobSlice);\n });\n }\n if (resource instanceof ArrayBuffer) {\n const slice = resource.slice(0, INITIAL_DATA_LENGTH);\n const base64 = arrayBufferToBase64(slice);\n return `data:base64,${base64}`;\n }\n return null;\n}\n\n// https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string\nfunction arrayBufferToBase64(buffer: ArrayBuffer): string {\n let binary = '';\n const bytes = new Uint8Array(buffer);\n for (let i = 0; i < bytes.byteLength; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n"],"mappings":"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
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "The core API for working with loaders.gl loaders and writers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,10 @@
|
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"browser": {
|
|
33
33
|
"fs": false,
|
|
34
|
-
"stream": false
|
|
34
|
+
"stream": false,
|
|
35
|
+
"./src/iterators/make-stream/make-node-stream.ts": "./src/iterators/make-stream/make-dom-stream.ts",
|
|
36
|
+
"./src/iterators/make-stream/make-node-stream.js": "./src/iterators/make-stream/make-dom-stream.js",
|
|
37
|
+
"./dist/iterators/make-stream/make-node-stream.js": "./dist/iterators/make-stream/make-dom-stream.js"
|
|
35
38
|
},
|
|
36
39
|
"files": [
|
|
37
40
|
"src",
|
|
@@ -46,9 +49,9 @@
|
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
51
|
"@babel/runtime": "^7.3.1",
|
|
49
|
-
"@loaders.gl/loader-utils": "4.0.
|
|
50
|
-
"@loaders.gl/worker-utils": "4.0.
|
|
52
|
+
"@loaders.gl/loader-utils": "4.0.1",
|
|
53
|
+
"@loaders.gl/worker-utils": "4.0.1",
|
|
51
54
|
"@probe.gl/log": "^4.0.2"
|
|
52
55
|
},
|
|
53
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "765e5a26a6bf3f2cc02cabffc4a1e3665ec92a53"
|
|
54
57
|
}
|
|
@@ -10,9 +10,9 @@ import {getResourceContentLength, getResourceUrl, getResourceMIMEType} from './r
|
|
|
10
10
|
*
|
|
11
11
|
* @param resource
|
|
12
12
|
*/
|
|
13
|
-
export async function makeResponse(resource:
|
|
13
|
+
export async function makeResponse(resource: unknown): Promise<Response> {
|
|
14
14
|
if (isResponse(resource)) {
|
|
15
|
-
return resource;
|
|
15
|
+
return resource as Response;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
// Add content-length header if possible
|
|
@@ -45,7 +45,7 @@ export async function makeResponse(resource: any): Promise<Response> {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// Attempt to create a Response from the resource, adding headers and setting url
|
|
48
|
-
const response = new Response(resource, {headers});
|
|
48
|
+
const response = new Response(resource as any, {headers});
|
|
49
49
|
// We can't control `Response.url` via constructor, use a property override to record URL.
|
|
50
50
|
Object.defineProperty(response, 'url', {value: url});
|
|
51
51
|
return response;
|
|
@@ -76,12 +76,12 @@ export function checkResponseSync(response: Response): void {
|
|
|
76
76
|
|
|
77
77
|
// HELPERS
|
|
78
78
|
|
|
79
|
-
async function getResponseError(response): Promise<string> {
|
|
79
|
+
async function getResponseError(response: Response): Promise<string> {
|
|
80
80
|
let message = `Failed to fetch resource ${response.url} (${response.status}): `;
|
|
81
81
|
try {
|
|
82
82
|
const contentType = response.headers.get('Content-Type');
|
|
83
83
|
let text = response.statusText;
|
|
84
|
-
if (contentType
|
|
84
|
+
if (contentType?.includes('application/json')) {
|
|
85
85
|
text += ` ${await response.text()}`;
|
|
86
86
|
}
|
|
87
87
|
message += text;
|
|
@@ -92,7 +92,9 @@ async function getResponseError(response): Promise<string> {
|
|
|
92
92
|
return message;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
async function getInitialDataUrl(
|
|
95
|
+
async function getInitialDataUrl(
|
|
96
|
+
resource: string | Blob | ArrayBuffer | unknown
|
|
97
|
+
): Promise<string | null> {
|
|
96
98
|
const INITIAL_DATA_LENGTH = 5;
|
|
97
99
|
if (typeof resource === 'string') {
|
|
98
100
|
return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
|
|
@@ -114,7 +116,7 @@ async function getInitialDataUrl(resource): Promise<string | null> {
|
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
// https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string
|
|
117
|
-
function arrayBufferToBase64(buffer) {
|
|
119
|
+
function arrayBufferToBase64(buffer: ArrayBuffer): string {
|
|
118
120
|
let binary = '';
|
|
119
121
|
const bytes = new Uint8Array(buffer);
|
|
120
122
|
for (let i = 0; i < bytes.byteLength; i++) {
|