@loaders.gl/core 4.0.0-alpha.23 → 4.0.0-alpha.24
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.min.js +40 -100
- package/dist/es5/lib/init.js +1 -1
- package/dist/es5/null-loader.js +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/null-loader.js +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/package.json +4 -7
- package/dist/bundle.js +0 -5
- package/dist/core-addons/write-file-browser.js +0 -60
- package/dist/index.js +0 -105
- package/dist/iterators/batch-iterators/timed-batch-iterator.js +0 -22
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js +0 -27
- package/dist/iterators/make-iterator/make-blob-iterator.js +0 -21
- package/dist/iterators/make-iterator/make-iterator.js +0 -37
- package/dist/iterators/make-iterator/make-stream-iterator.js +0 -96
- package/dist/iterators/make-iterator/make-string-iterator.js +0 -24
- package/dist/iterators/make-stream/make-dom-stream.js +0 -47
- package/dist/iterators/make-stream/make-node-stream.js +0 -85
- package/dist/javascript-utils/is-type.js +0 -41
- package/dist/lib/api/encode-table.js +0 -54
- package/dist/lib/api/encode.js +0 -121
- package/dist/lib/api/load-in-batches.js +0 -40
- package/dist/lib/api/load.js +0 -43
- package/dist/lib/api/loader-options.js +0 -7
- package/dist/lib/api/parse-in-batches.js +0 -117
- package/dist/lib/api/parse-sync.js +0 -54
- package/dist/lib/api/parse.js +0 -87
- package/dist/lib/api/register-loaders.js +0 -35
- package/dist/lib/api/save.js +0 -15
- package/dist/lib/api/select-loader.js +0 -258
- package/dist/lib/common.js +0 -2
- package/dist/lib/fetch/fetch-error-message.js +0 -25
- package/dist/lib/fetch/fetch-file.js +0 -61
- package/dist/lib/fetch/fetch-file.node.js +0 -57
- package/dist/lib/fetch/read-array-buffer.js +0 -41
- package/dist/lib/fetch/read-file.js +0 -29
- package/dist/lib/fetch/write-file.js +0 -22
- package/dist/lib/filesystems/browser-filesystem.js +0 -127
- package/dist/lib/filesystems/read-array-buffer.js +0 -29
- package/dist/lib/init.js +0 -17
- package/dist/lib/loader-utils/check-errors.js +0 -46
- package/dist/lib/loader-utils/get-data.js +0 -130
- package/dist/lib/loader-utils/get-fetch-function.js +0 -31
- package/dist/lib/loader-utils/loader-context.js +0 -59
- package/dist/lib/loader-utils/loggers.js +0 -41
- package/dist/lib/loader-utils/normalize-loader.js +0 -52
- package/dist/lib/loader-utils/option-defaults.js +0 -44
- package/dist/lib/loader-utils/option-utils.js +0 -162
- package/dist/lib/progress/fetch-progress.js +0 -60
- package/dist/lib/utils/log.js +0 -6
- package/dist/lib/utils/mime-type-utils.js +0 -42
- package/dist/lib/utils/resource-utils.js +0 -90
- package/dist/lib/utils/response-utils.js +0 -115
- package/dist/lib/utils/url-utils.js +0 -14
- package/dist/null-loader.js +0 -51
- package/dist/workers/null-worker.js +0 -5
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.fetchFileNode = void 0;
|
|
5
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
-
/**
|
|
7
|
-
* Enables
|
|
8
|
-
* @param url
|
|
9
|
-
* @param options
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
async function fetchFileNode(url, options) {
|
|
13
|
-
// Support `file://` protocol
|
|
14
|
-
const FILE_PROTOCOL_REGEX = /^file:\/\//;
|
|
15
|
-
url.replace(FILE_PROTOCOL_REGEX, '/');
|
|
16
|
-
const noqueryUrl = url.split('?')[0];
|
|
17
|
-
try {
|
|
18
|
-
// Now open the stream
|
|
19
|
-
const body = await new Promise((resolve, reject) => {
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
const stream = loader_utils_1.fs.createReadStream(noqueryUrl, { encoding: null });
|
|
22
|
-
stream.once('readable', () => resolve(stream));
|
|
23
|
-
stream.on('error', (error) => reject(error));
|
|
24
|
-
});
|
|
25
|
-
const status = 200;
|
|
26
|
-
const statusText = 'OK';
|
|
27
|
-
const headers = getHeadersForFile(noqueryUrl);
|
|
28
|
-
// @ts-expect-error
|
|
29
|
-
const response = new Response(body, { headers, status, statusText });
|
|
30
|
-
Object.defineProperty(response, 'url', { value: url });
|
|
31
|
-
return response;
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
const errorMessage = error.message;
|
|
35
|
-
const status = 400;
|
|
36
|
-
const statusText = errorMessage;
|
|
37
|
-
const headers = {};
|
|
38
|
-
const response = new Response(errorMessage, { headers, status, statusText });
|
|
39
|
-
Object.defineProperty(response, 'url', { value: url });
|
|
40
|
-
return response;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.fetchFileNode = fetchFileNode;
|
|
44
|
-
function getHeadersForFile(noqueryUrl) {
|
|
45
|
-
const headers = {};
|
|
46
|
-
// Fix up content length if we can for best progress experience
|
|
47
|
-
if (!headers['content-length']) {
|
|
48
|
-
const stats = loader_utils_1.fs.statSync(noqueryUrl);
|
|
49
|
-
headers['content-length'] = stats.size;
|
|
50
|
-
}
|
|
51
|
-
// Automatically decompress gzipped files with .gz extension
|
|
52
|
-
if (noqueryUrl.endsWith('.gz')) {
|
|
53
|
-
noqueryUrl = noqueryUrl.slice(0, -3);
|
|
54
|
-
headers['content-encoding'] = 'gzip';
|
|
55
|
-
}
|
|
56
|
-
return new Headers(headers);
|
|
57
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readBlob = exports.readArrayBuffer = void 0;
|
|
4
|
-
//
|
|
5
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
-
/**
|
|
7
|
-
* Reads a chunk from a random access file
|
|
8
|
-
* @param file
|
|
9
|
-
* @param start
|
|
10
|
-
* @param length
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
async function readArrayBuffer(file, start, length) {
|
|
14
|
-
if (typeof file === 'number') {
|
|
15
|
-
return await loader_utils_1.fs._readToArrayBuffer(file, start, length);
|
|
16
|
-
}
|
|
17
|
-
// TODO - we can do better for ArrayBuffer and string
|
|
18
|
-
if (!(file instanceof Blob)) {
|
|
19
|
-
file = new Blob([file]);
|
|
20
|
-
}
|
|
21
|
-
const slice = file.slice(start, start + length);
|
|
22
|
-
return await readBlob(slice);
|
|
23
|
-
}
|
|
24
|
-
exports.readArrayBuffer = readArrayBuffer;
|
|
25
|
-
/**
|
|
26
|
-
* Read a slice of a Blob or File, without loading the entire file into memory
|
|
27
|
-
* The trick when reading File objects is to read successive "slices" of the File
|
|
28
|
-
* Per spec https://w3c.github.io/FileAPI/, slicing a File only updates the start and end fields
|
|
29
|
-
* Actually reading from file happens in `readAsArrayBuffer`
|
|
30
|
-
* @param blob to read
|
|
31
|
-
*/
|
|
32
|
-
async function readBlob(blob) {
|
|
33
|
-
return await new Promise((resolve, reject) => {
|
|
34
|
-
const fileReader = new FileReader();
|
|
35
|
-
fileReader.onload = (event) => resolve(event?.target?.result);
|
|
36
|
-
// TODO - reject with a proper Error
|
|
37
|
-
fileReader.onerror = (error) => reject(error);
|
|
38
|
-
fileReader.readAsArrayBuffer(blob);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
exports.readBlob = readBlob;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readFileSync = void 0;
|
|
4
|
-
// File read
|
|
5
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
-
const loader_utils_2 = require("@loaders.gl/loader-utils");
|
|
7
|
-
// TODO - this is not tested
|
|
8
|
-
// const isDataURL = (url) => url.startsWith('data:');
|
|
9
|
-
/**
|
|
10
|
-
* In a few cases (data URIs, node.js) "files" can be read synchronously
|
|
11
|
-
*/
|
|
12
|
-
function readFileSync(url, options = {}) {
|
|
13
|
-
url = (0, loader_utils_1.resolvePath)(url);
|
|
14
|
-
// Only support this if we can also support sync data URL decoding in browser
|
|
15
|
-
// if (isDataURL(url)) {
|
|
16
|
-
// return decodeDataUri(url);
|
|
17
|
-
// }
|
|
18
|
-
if (!loader_utils_1.isBrowser) {
|
|
19
|
-
const buffer = loader_utils_1.fs.readFileSync(url, options);
|
|
20
|
-
return typeof buffer !== 'string' ? (0, loader_utils_1.toArrayBuffer)(buffer) : buffer;
|
|
21
|
-
}
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
if (!options.nothrow) {
|
|
24
|
-
// throw new Error('Cant load URI synchronously');
|
|
25
|
-
(0, loader_utils_2.assert)(false);
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
exports.readFileSync = readFileSync;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeFileSync = exports.writeFile = void 0;
|
|
4
|
-
// file write
|
|
5
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
-
const loader_utils_2 = require("@loaders.gl/loader-utils");
|
|
7
|
-
async function writeFile(filePath, arrayBufferOrString, options) {
|
|
8
|
-
filePath = (0, loader_utils_1.resolvePath)(filePath);
|
|
9
|
-
if (!loader_utils_1.isBrowser) {
|
|
10
|
-
await loader_utils_2.fs.writeFile(filePath, (0, loader_utils_2.toBuffer)(arrayBufferOrString), { flag: 'w' });
|
|
11
|
-
}
|
|
12
|
-
(0, loader_utils_1.assert)(false);
|
|
13
|
-
}
|
|
14
|
-
exports.writeFile = writeFile;
|
|
15
|
-
function writeFileSync(filePath, arrayBufferOrString, options) {
|
|
16
|
-
filePath = (0, loader_utils_1.resolvePath)(filePath);
|
|
17
|
-
if (!loader_utils_1.isBrowser) {
|
|
18
|
-
loader_utils_2.fs.writeFileSync(filePath, (0, loader_utils_2.toBuffer)(arrayBufferOrString), { flag: 'w' });
|
|
19
|
-
}
|
|
20
|
-
(0, loader_utils_1.assert)(false);
|
|
21
|
-
}
|
|
22
|
-
exports.writeFileSync = writeFileSync;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BrowserFileSystem = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* FileSystem adapter for a browser FileList.
|
|
6
|
-
* Holds a list of browser 'File' objects.
|
|
7
|
-
*/
|
|
8
|
-
class BrowserFileSystem {
|
|
9
|
-
/**
|
|
10
|
-
* A FileSystem API wrapper around a list of browser 'File' objects
|
|
11
|
-
* @param files
|
|
12
|
-
* @param options
|
|
13
|
-
*/
|
|
14
|
-
constructor(files, options) {
|
|
15
|
-
this.files = {};
|
|
16
|
-
this.lowerCaseFiles = {};
|
|
17
|
-
this.usedFiles = {};
|
|
18
|
-
this._fetch = options?.fetch || fetch;
|
|
19
|
-
for (let i = 0; i < files.length; ++i) {
|
|
20
|
-
const file = files[i];
|
|
21
|
-
this.files[file.name] = file;
|
|
22
|
-
this.lowerCaseFiles[file.name.toLowerCase()] = file;
|
|
23
|
-
this.usedFiles[file.name] = false;
|
|
24
|
-
}
|
|
25
|
-
this.fetch = this.fetch.bind(this);
|
|
26
|
-
}
|
|
27
|
-
// implements IFileSystem
|
|
28
|
-
/**
|
|
29
|
-
* Implementation of fetch against this file system
|
|
30
|
-
* Delegates to global fetch for http{s}:// or data://
|
|
31
|
-
*/
|
|
32
|
-
async fetch(path, options) {
|
|
33
|
-
// Fallback to handle https:/http:/data: etc fetches
|
|
34
|
-
if (path.includes('://')) {
|
|
35
|
-
return this._fetch(path, options);
|
|
36
|
-
}
|
|
37
|
-
// Local fetches are served from the list of files
|
|
38
|
-
const file = this.files[path];
|
|
39
|
-
if (!file) {
|
|
40
|
-
return new Response(path, { status: 400, statusText: 'NOT FOUND' });
|
|
41
|
-
}
|
|
42
|
-
const headers = new Headers(options?.headers);
|
|
43
|
-
const range = headers.get('Range');
|
|
44
|
-
const bytes = range && /bytes=($1)-($2)/.exec(range);
|
|
45
|
-
if (bytes) {
|
|
46
|
-
const start = parseInt(bytes[1]);
|
|
47
|
-
const end = parseInt(bytes[2]);
|
|
48
|
-
// The trick when reading File objects is to read successive "slices" of the File
|
|
49
|
-
// Per spec https://w3c.github.io/FileAPI/, slicing a File should only update the start and end fields
|
|
50
|
-
// Actually reading from file should happen in `readAsArrayBuffer` (and as far we can tell it does)
|
|
51
|
-
const data = await file.slice(start, end).arrayBuffer();
|
|
52
|
-
const response = new Response(data);
|
|
53
|
-
Object.defineProperty(response, 'url', { value: path });
|
|
54
|
-
return response;
|
|
55
|
-
}
|
|
56
|
-
// return makeResponse()
|
|
57
|
-
const response = new Response(file);
|
|
58
|
-
Object.defineProperty(response, 'url', { value: path });
|
|
59
|
-
return response;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* List filenames in this filesystem
|
|
63
|
-
* @param dirname
|
|
64
|
-
* @returns
|
|
65
|
-
*/
|
|
66
|
-
async readdir(dirname) {
|
|
67
|
-
const files = [];
|
|
68
|
-
for (const path in this.files) {
|
|
69
|
-
files.push(path);
|
|
70
|
-
}
|
|
71
|
-
// TODO filter by dirname
|
|
72
|
-
return files;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Return information (size) about files in this file system
|
|
76
|
-
*/
|
|
77
|
-
async stat(path, options) {
|
|
78
|
-
const file = this.files[path];
|
|
79
|
-
if (!file) {
|
|
80
|
-
throw new Error(path);
|
|
81
|
-
}
|
|
82
|
-
return { size: file.size };
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Just removes the file from the list
|
|
86
|
-
*/
|
|
87
|
-
async unlink(path) {
|
|
88
|
-
delete this.files[path];
|
|
89
|
-
delete this.lowerCaseFiles[path];
|
|
90
|
-
this.usedFiles[path] = true;
|
|
91
|
-
}
|
|
92
|
-
// implements IRandomAccessFileSystem
|
|
93
|
-
// RANDOM ACCESS
|
|
94
|
-
async open(pathname, flags, mode) {
|
|
95
|
-
return this.files[pathname];
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Read a range into a buffer
|
|
99
|
-
* @todo - handle position memory
|
|
100
|
-
* @param buffer is the buffer that the data (read from the fd) will be written to.
|
|
101
|
-
* @param offset is the offset in the buffer to start writing at.
|
|
102
|
-
* @param length is an integer specifying the number of bytes to read.
|
|
103
|
-
* @param position is an argument specifying where to begin reading from in the file. If position is null, data will be read from the current file position, and the file position will be updated. If position is an integer, the file position will remain unchanged.
|
|
104
|
-
*/
|
|
105
|
-
async read(fd, buffer, offset = 0, length = buffer.byteLength, position = null) {
|
|
106
|
-
const file = fd;
|
|
107
|
-
const startPosition = 0; // position
|
|
108
|
-
const arrayBuffer = await file.slice(startPosition, startPosition + length).arrayBuffer();
|
|
109
|
-
// copy into target buffer
|
|
110
|
-
return { bytesRead: length, buffer: arrayBuffer };
|
|
111
|
-
}
|
|
112
|
-
async close(fd) {
|
|
113
|
-
// NO OP
|
|
114
|
-
}
|
|
115
|
-
// fstat(fd: number): Promise<object>; // Stat
|
|
116
|
-
// PRIVATE
|
|
117
|
-
// Supports case independent paths, and file usage tracking
|
|
118
|
-
_getFile(path, used) {
|
|
119
|
-
// Prefer case match, but fall back to case independent.
|
|
120
|
-
const file = this.files[path] || this.lowerCaseFiles[path];
|
|
121
|
-
if (file && used) {
|
|
122
|
-
this.usedFiles[path] = true;
|
|
123
|
-
}
|
|
124
|
-
return file;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.BrowserFileSystem = BrowserFileSystem;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Random-Access read
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.readArrayBuffer = void 0;
|
|
5
|
-
async function readArrayBuffer(file, start, length) {
|
|
6
|
-
if (file instanceof Blob) {
|
|
7
|
-
const slice = file.slice(start, start + length);
|
|
8
|
-
return await slice.arrayBuffer();
|
|
9
|
-
}
|
|
10
|
-
return await file.read(start, start + length);
|
|
11
|
-
}
|
|
12
|
-
exports.readArrayBuffer = readArrayBuffer;
|
|
13
|
-
/**
|
|
14
|
-
* Read a slice of a Blob or File, without loading the entire file into memory
|
|
15
|
-
* The trick when reading File objects is to read successive "slices" of the File
|
|
16
|
-
* Per spec https://w3c.github.io/FileAPI/, slicing a File only updates the start and end fields
|
|
17
|
-
* Actually reading from file happens in `readAsArrayBuffer`
|
|
18
|
-
* @param blob to read
|
|
19
|
-
export async function readBlob(blob: Blob): Promise<ArrayBuffer> {
|
|
20
|
-
return await new Promise((resolve, reject) => {
|
|
21
|
-
const fileReader = new FileReader();
|
|
22
|
-
fileReader.onload = (event: ProgressEvent<FileReader>) =>
|
|
23
|
-
resolve(event?.target?.result as ArrayBuffer);
|
|
24
|
-
// TODO - reject with a proper Error
|
|
25
|
-
fileReader.onerror = (error: ProgressEvent<FileReader>) => reject(error);
|
|
26
|
-
fileReader.readAsArrayBuffer(blob);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
*/
|
package/dist/lib/init.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// loaders.gl, MIT license
|
|
4
|
-
const log_1 = require("./utils/log");
|
|
5
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
6
|
-
const version = typeof __VERSION__ !== 'undefined' ? __VERSION__ : '';
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
if (!globalThis.loaders) {
|
|
9
|
-
log_1.log.log(1, `loaders.gl ${version}`)();
|
|
10
|
-
// @ts-ignore TS2339: Property 'loaders' does not exist on type 'Window & typeof globalThis'.
|
|
11
|
-
globalThis.loaders = Object.assign(globalThis.loaders || {}, {
|
|
12
|
-
VERSION: version,
|
|
13
|
-
log: log_1.log
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
exports.default = globalThis.loaders;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.checkFetchResponseStatusSync = exports.checkFetchResponseStatus = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Check reponse status, if not OK extract error message and throw error
|
|
7
|
-
* @param response
|
|
8
|
-
*/
|
|
9
|
-
async function checkFetchResponseStatus(response) {
|
|
10
|
-
if (!response.ok) {
|
|
11
|
-
let errorMessage = `fetch failed ${response.status} ${response.statusText}`;
|
|
12
|
-
try {
|
|
13
|
-
const text = await response.text();
|
|
14
|
-
if (text) {
|
|
15
|
-
errorMessage += `: ${getErrorText(text)}`;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
// ignore error
|
|
20
|
-
}
|
|
21
|
-
throw new Error(errorMessage);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.checkFetchResponseStatus = checkFetchResponseStatus;
|
|
25
|
-
/**
|
|
26
|
-
* Check response status synchronously, if not OK extract error message and throw error
|
|
27
|
-
* Not able to extract as good an error message as the async version
|
|
28
|
-
* @param response
|
|
29
|
-
*/
|
|
30
|
-
function checkFetchResponseStatusSync(response) {
|
|
31
|
-
if (!response.ok) {
|
|
32
|
-
throw new Error(`fetch failed ${response.status}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.checkFetchResponseStatusSync = checkFetchResponseStatusSync;
|
|
36
|
-
/**
|
|
37
|
-
* Ad-hoc error message extractor
|
|
38
|
-
* @todo Handle XML, JSON, etc
|
|
39
|
-
* @param text
|
|
40
|
-
* @returns
|
|
41
|
-
*/
|
|
42
|
-
function getErrorText(text) {
|
|
43
|
-
// Look for HTML error texts
|
|
44
|
-
const matches = /<pre>(.*)<\/pre>/.exec(text);
|
|
45
|
-
return matches ? matches[1] : ` ${text.slice(0, 10)}...`;
|
|
46
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getReadableStream = exports.getAsyncIterableFromData = exports.getArrayBufferOrStringFromData = exports.getArrayBufferOrStringFromDataSync = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const is_type_1 = require("../../javascript-utils/is-type");
|
|
6
|
-
const make_iterator_1 = require("../../iterators/make-iterator/make-iterator");
|
|
7
|
-
const response_utils_1 = require("../utils/response-utils");
|
|
8
|
-
const ERR_DATA = 'Cannot convert supplied data type';
|
|
9
|
-
// eslint-disable-next-line complexity
|
|
10
|
-
function getArrayBufferOrStringFromDataSync(data, loader, options) {
|
|
11
|
-
if (loader.text && typeof data === 'string') {
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
if ((0, is_type_1.isBuffer)(data)) {
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
data = data.buffer;
|
|
17
|
-
}
|
|
18
|
-
if (data instanceof ArrayBuffer) {
|
|
19
|
-
const arrayBuffer = data;
|
|
20
|
-
if (loader.text && !loader.binary) {
|
|
21
|
-
const textDecoder = new TextDecoder('utf8');
|
|
22
|
-
return textDecoder.decode(arrayBuffer);
|
|
23
|
-
}
|
|
24
|
-
return arrayBuffer;
|
|
25
|
-
}
|
|
26
|
-
// We may need to handle offsets
|
|
27
|
-
if (ArrayBuffer.isView(data)) {
|
|
28
|
-
// TextDecoder is invoked on typed arrays and will handle offsets
|
|
29
|
-
if (loader.text && !loader.binary) {
|
|
30
|
-
const textDecoder = new TextDecoder('utf8');
|
|
31
|
-
return textDecoder.decode(data);
|
|
32
|
-
}
|
|
33
|
-
let arrayBuffer = data.buffer;
|
|
34
|
-
// Since we are returning the underlying arrayBuffer, we must create a new copy
|
|
35
|
-
// if this typed array / Buffer is a partial view into the ArryayBuffer
|
|
36
|
-
// TODO - this is a potentially unnecessary copy
|
|
37
|
-
const byteLength = data.byteLength || data.length;
|
|
38
|
-
if (data.byteOffset !== 0 || byteLength !== arrayBuffer.byteLength) {
|
|
39
|
-
// console.warn(`loaders.gl copying arraybuffer of length ${byteLength}`);
|
|
40
|
-
arrayBuffer = arrayBuffer.slice(data.byteOffset, data.byteOffset + byteLength);
|
|
41
|
-
}
|
|
42
|
-
return arrayBuffer;
|
|
43
|
-
}
|
|
44
|
-
throw new Error(ERR_DATA);
|
|
45
|
-
}
|
|
46
|
-
exports.getArrayBufferOrStringFromDataSync = getArrayBufferOrStringFromDataSync;
|
|
47
|
-
// Convert async iterator to a promise
|
|
48
|
-
async function getArrayBufferOrStringFromData(data, loader, options) {
|
|
49
|
-
const isArrayBuffer = data instanceof ArrayBuffer || ArrayBuffer.isView(data);
|
|
50
|
-
if (typeof data === 'string' || isArrayBuffer) {
|
|
51
|
-
return getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
52
|
-
}
|
|
53
|
-
// Blobs and files are FileReader compatible
|
|
54
|
-
if ((0, is_type_1.isBlob)(data)) {
|
|
55
|
-
data = await (0, response_utils_1.makeResponse)(data);
|
|
56
|
-
}
|
|
57
|
-
if ((0, is_type_1.isResponse)(data)) {
|
|
58
|
-
const response = data;
|
|
59
|
-
await (0, response_utils_1.checkResponse)(response);
|
|
60
|
-
return loader.binary ? await response.arrayBuffer() : await response.text();
|
|
61
|
-
}
|
|
62
|
-
if ((0, is_type_1.isReadableStream)(data)) {
|
|
63
|
-
// @ts-expect-error TS2559 options type
|
|
64
|
-
data = (0, make_iterator_1.makeIterator)(data, options);
|
|
65
|
-
}
|
|
66
|
-
if ((0, is_type_1.isIterable)(data) || (0, is_type_1.isAsyncIterable)(data)) {
|
|
67
|
-
// Assume arrayBuffer iterator - attempt to concatenate
|
|
68
|
-
return (0, loader_utils_1.concatenateArrayBuffersAsync)(data);
|
|
69
|
-
}
|
|
70
|
-
throw new Error(ERR_DATA);
|
|
71
|
-
}
|
|
72
|
-
exports.getArrayBufferOrStringFromData = getArrayBufferOrStringFromData;
|
|
73
|
-
async function getAsyncIterableFromData(data, options) {
|
|
74
|
-
if ((0, is_type_1.isIterator)(data)) {
|
|
75
|
-
return data;
|
|
76
|
-
}
|
|
77
|
-
if ((0, is_type_1.isResponse)(data)) {
|
|
78
|
-
const response = data;
|
|
79
|
-
// Note Since this function is not async, we currently can't load error message, just status
|
|
80
|
-
await (0, response_utils_1.checkResponse)(response);
|
|
81
|
-
// TODO - bug in polyfill, body can be a Promise under Node.js
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
83
|
-
const body = await response.body;
|
|
84
|
-
// TODO - body can be null?
|
|
85
|
-
return (0, make_iterator_1.makeIterator)(body, options);
|
|
86
|
-
}
|
|
87
|
-
if ((0, is_type_1.isBlob)(data) || (0, is_type_1.isReadableStream)(data)) {
|
|
88
|
-
return (0, make_iterator_1.makeIterator)(data, options);
|
|
89
|
-
}
|
|
90
|
-
if ((0, is_type_1.isAsyncIterable)(data)) {
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
return data[Symbol.asyncIterator]();
|
|
93
|
-
}
|
|
94
|
-
return getIterableFromData(data);
|
|
95
|
-
}
|
|
96
|
-
exports.getAsyncIterableFromData = getAsyncIterableFromData;
|
|
97
|
-
async function getReadableStream(data) {
|
|
98
|
-
if ((0, is_type_1.isReadableStream)(data)) {
|
|
99
|
-
return data;
|
|
100
|
-
}
|
|
101
|
-
if ((0, is_type_1.isResponse)(data)) {
|
|
102
|
-
// @ts-ignore
|
|
103
|
-
return data.body;
|
|
104
|
-
}
|
|
105
|
-
const response = await (0, response_utils_1.makeResponse)(data);
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
return response.body;
|
|
108
|
-
}
|
|
109
|
-
exports.getReadableStream = getReadableStream;
|
|
110
|
-
// HELPERS
|
|
111
|
-
function getIterableFromData(data) {
|
|
112
|
-
// generate an iterator that emits a single chunk
|
|
113
|
-
if (ArrayBuffer.isView(data)) {
|
|
114
|
-
return (function* oneChunk() {
|
|
115
|
-
yield data.buffer;
|
|
116
|
-
})();
|
|
117
|
-
}
|
|
118
|
-
if (data instanceof ArrayBuffer) {
|
|
119
|
-
return (function* oneChunk() {
|
|
120
|
-
yield data;
|
|
121
|
-
})();
|
|
122
|
-
}
|
|
123
|
-
if ((0, is_type_1.isIterator)(data)) {
|
|
124
|
-
return data;
|
|
125
|
-
}
|
|
126
|
-
if ((0, is_type_1.isIterable)(data)) {
|
|
127
|
-
return data[Symbol.iterator]();
|
|
128
|
-
}
|
|
129
|
-
throw new Error(ERR_DATA);
|
|
130
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getFetchFunction = void 0;
|
|
5
|
-
const is_type_1 = require("../../javascript-utils/is-type");
|
|
6
|
-
const fetch_file_1 = require("../fetch/fetch-file");
|
|
7
|
-
const option_utils_1 = require("./option-utils");
|
|
8
|
-
/**
|
|
9
|
-
* Gets the current fetch function from options and context
|
|
10
|
-
* @param options
|
|
11
|
-
* @param context
|
|
12
|
-
*/
|
|
13
|
-
function getFetchFunction(options, context) {
|
|
14
|
-
const globalOptions = (0, option_utils_1.getGlobalLoaderOptions)();
|
|
15
|
-
const loaderOptions = options || globalOptions;
|
|
16
|
-
// options.fetch can be a function
|
|
17
|
-
if (typeof loaderOptions.fetch === 'function') {
|
|
18
|
-
return loaderOptions.fetch;
|
|
19
|
-
}
|
|
20
|
-
// options.fetch can be an options object
|
|
21
|
-
if ((0, is_type_1.isObject)(loaderOptions.fetch)) {
|
|
22
|
-
return (url) => (0, fetch_file_1.fetchFile)(url, loaderOptions.fetch);
|
|
23
|
-
}
|
|
24
|
-
// else refer to context (from parent loader) if available
|
|
25
|
-
if (context?.fetch) {
|
|
26
|
-
return context?.fetch;
|
|
27
|
-
}
|
|
28
|
-
// else return the default fetch function
|
|
29
|
-
return fetch_file_1.fetchFile;
|
|
30
|
-
}
|
|
31
|
-
exports.getFetchFunction = getFetchFunction;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLoadersFromContext = exports.getLoaderContext = void 0;
|
|
4
|
-
const get_fetch_function_1 = require("./get-fetch-function");
|
|
5
|
-
const url_utils_1 = require("../utils/url-utils");
|
|
6
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
7
|
-
/**
|
|
8
|
-
* "sub" loaders invoked by other loaders get a "context" injected on `this`
|
|
9
|
-
* The context will inject core methods like `parse` and contain information
|
|
10
|
-
* about loaders and options passed in to the top-level `parse` call.
|
|
11
|
-
*
|
|
12
|
-
* @param context
|
|
13
|
-
* @param options
|
|
14
|
-
* @param previousContext
|
|
15
|
-
*/
|
|
16
|
-
function getLoaderContext(context, options, parentContext) {
|
|
17
|
-
// For recursive calls, we already have a context
|
|
18
|
-
// TODO - add any additional loaders to context?
|
|
19
|
-
if (parentContext) {
|
|
20
|
-
return parentContext;
|
|
21
|
-
}
|
|
22
|
-
const newContext = {
|
|
23
|
-
fetch: (0, get_fetch_function_1.getFetchFunction)(options, context),
|
|
24
|
-
...context
|
|
25
|
-
};
|
|
26
|
-
// Parse URLs so that subloaders can easily generate correct strings
|
|
27
|
-
if (newContext.url) {
|
|
28
|
-
const baseUrl = (0, url_utils_1.stripQueryString)(newContext.url);
|
|
29
|
-
newContext.baseUrl = baseUrl;
|
|
30
|
-
newContext.queryString = (0, url_utils_1.extractQueryString)(newContext.url);
|
|
31
|
-
newContext.filename = loader_utils_1.path.filename(baseUrl);
|
|
32
|
-
newContext.baseUrl = loader_utils_1.path.dirname(baseUrl);
|
|
33
|
-
}
|
|
34
|
-
// Recursive loading does not use single loader
|
|
35
|
-
if (!Array.isArray(newContext.loaders)) {
|
|
36
|
-
newContext.loaders = null;
|
|
37
|
-
}
|
|
38
|
-
return newContext;
|
|
39
|
-
}
|
|
40
|
-
exports.getLoaderContext = getLoaderContext;
|
|
41
|
-
// eslint-disable-next-line complexity
|
|
42
|
-
function getLoadersFromContext(loaders, context) {
|
|
43
|
-
// A single loader (non-array) indicates no selection desired. Force select.
|
|
44
|
-
if (loaders && !Array.isArray(loaders)) {
|
|
45
|
-
return loaders;
|
|
46
|
-
}
|
|
47
|
-
// Create a merged list
|
|
48
|
-
let candidateLoaders;
|
|
49
|
-
if (loaders) {
|
|
50
|
-
candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
51
|
-
}
|
|
52
|
-
if (context && context.loaders) {
|
|
53
|
-
const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];
|
|
54
|
-
candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
|
|
55
|
-
}
|
|
56
|
-
// If no loaders, return null to look in globally registered loaders
|
|
57
|
-
return candidateLoaders && candidateLoaders.length ? candidateLoaders : undefined;
|
|
58
|
-
}
|
|
59
|
-
exports.getLoadersFromContext = getLoadersFromContext;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConsoleLog = exports.NullLog = exports.probeLog = void 0;
|
|
4
|
-
// probe.gl Log compatible loggers
|
|
5
|
-
const log_1 = require("@probe.gl/log");
|
|
6
|
-
exports.probeLog = new log_1.Log({ id: 'loaders.gl' });
|
|
7
|
-
// Logs nothing
|
|
8
|
-
class NullLog {
|
|
9
|
-
log() {
|
|
10
|
-
return () => { };
|
|
11
|
-
}
|
|
12
|
-
info() {
|
|
13
|
-
return () => { };
|
|
14
|
-
}
|
|
15
|
-
warn() {
|
|
16
|
-
return () => { };
|
|
17
|
-
}
|
|
18
|
-
error() {
|
|
19
|
-
return () => { };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.NullLog = NullLog;
|
|
23
|
-
// Logs to console
|
|
24
|
-
class ConsoleLog {
|
|
25
|
-
constructor() {
|
|
26
|
-
this.console = console; // eslint-disable-line
|
|
27
|
-
}
|
|
28
|
-
log(...args) {
|
|
29
|
-
return this.console.log.bind(this.console, ...args);
|
|
30
|
-
}
|
|
31
|
-
info(...args) {
|
|
32
|
-
return this.console.info.bind(this.console, ...args);
|
|
33
|
-
}
|
|
34
|
-
warn(...args) {
|
|
35
|
-
return this.console.warn.bind(this.console, ...args);
|
|
36
|
-
}
|
|
37
|
-
error(...args) {
|
|
38
|
-
return this.console.error.bind(this.console, ...args);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.ConsoleLog = ConsoleLog;
|