@loaders.gl/core 3.4.10 → 3.4.12
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 -112
- 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/lib/fetch/read-file.d.ts +1 -1
- package/dist/lib/fetch/read-file.d.ts.map +1 -1
- package/dist/null-worker.js +1 -1
- package/package.json +4 -6
- package/dist/bundle.js +0 -5
- package/dist/core-addons/write-file-browser.js +0 -60
- package/dist/index.js +0 -104
- 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 -46
- package/dist/iterators/make-stream/make-node-stream.js +0 -82
- package/dist/javascript-utils/is-type.js +0 -41
- package/dist/lib/api/encode.js +0 -120
- package/dist/lib/api/load-in-batches.js +0 -33
- package/dist/lib/api/load.js +0 -42
- 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 -59
- package/dist/lib/api/parse.js +0 -82
- 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 -253
- 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 -27
- 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 -126
- package/dist/lib/filesystems/filesystem.js +0 -2
- package/dist/lib/filesystems/read-array-buffer.js +0 -29
- package/dist/lib/init.js +0 -16
- package/dist/lib/loader-utils/check-errors.js +0 -30
- package/dist/lib/loader-utils/get-data.js +0 -129
- 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 -43
- package/dist/lib/loader-utils/option-utils.js +0 -160
- package/dist/lib/progress/fetch-progress.js +0 -59
- 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 -56
- package/dist/workers/null-worker.js +0 -5
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* FileSystem adapter for a browser FileList.
|
|
5
|
-
* Holds a list of browser 'File' objects.
|
|
6
|
-
*/
|
|
7
|
-
class BrowserFileSystem {
|
|
8
|
-
/**
|
|
9
|
-
* A FileSystem API wrapper around a list of browser 'File' objects
|
|
10
|
-
* @param files
|
|
11
|
-
* @param options
|
|
12
|
-
*/
|
|
13
|
-
constructor(files, options) {
|
|
14
|
-
this.files = {};
|
|
15
|
-
this.lowerCaseFiles = {};
|
|
16
|
-
this.usedFiles = {};
|
|
17
|
-
this._fetch = options?.fetch || fetch;
|
|
18
|
-
for (let i = 0; i < files.length; ++i) {
|
|
19
|
-
const file = files[i];
|
|
20
|
-
this.files[file.name] = file;
|
|
21
|
-
this.lowerCaseFiles[file.name.toLowerCase()] = file;
|
|
22
|
-
this.usedFiles[file.name] = false;
|
|
23
|
-
}
|
|
24
|
-
this.fetch = this.fetch.bind(this);
|
|
25
|
-
}
|
|
26
|
-
// implements IFileSystem
|
|
27
|
-
/**
|
|
28
|
-
* Implementation of fetch against this file system
|
|
29
|
-
* Delegates to global fetch for http{s}:// or data://
|
|
30
|
-
*/
|
|
31
|
-
async fetch(path, options) {
|
|
32
|
-
// Fallback to handle https:/http:/data: etc fetches
|
|
33
|
-
if (path.includes('://')) {
|
|
34
|
-
return this._fetch(path, options);
|
|
35
|
-
}
|
|
36
|
-
// Local fetches are served from the list of files
|
|
37
|
-
const file = this.files[path];
|
|
38
|
-
if (!file) {
|
|
39
|
-
return new Response(path, { status: 400, statusText: 'NOT FOUND' });
|
|
40
|
-
}
|
|
41
|
-
const headers = new Headers(options?.headers);
|
|
42
|
-
const range = headers.get('Range');
|
|
43
|
-
const bytes = range && /bytes=($1)-($2)/.exec(range);
|
|
44
|
-
if (bytes) {
|
|
45
|
-
const start = parseInt(bytes[1]);
|
|
46
|
-
const end = parseInt(bytes[2]);
|
|
47
|
-
// The trick when reading File objects is to read successive "slices" of the File
|
|
48
|
-
// Per spec https://w3c.github.io/FileAPI/, slicing a File should only update the start and end fields
|
|
49
|
-
// Actually reading from file should happen in `readAsArrayBuffer` (and as far we can tell it does)
|
|
50
|
-
const data = await file.slice(start, end).arrayBuffer();
|
|
51
|
-
const response = new Response(data);
|
|
52
|
-
Object.defineProperty(response, 'url', { value: path });
|
|
53
|
-
return response;
|
|
54
|
-
}
|
|
55
|
-
// return makeResponse()
|
|
56
|
-
const response = new Response(file);
|
|
57
|
-
Object.defineProperty(response, 'url', { value: path });
|
|
58
|
-
return response;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* List filenames in this filesystem
|
|
62
|
-
* @param dirname
|
|
63
|
-
* @returns
|
|
64
|
-
*/
|
|
65
|
-
async readdir(dirname) {
|
|
66
|
-
const files = [];
|
|
67
|
-
for (const path in this.files) {
|
|
68
|
-
files.push(path);
|
|
69
|
-
}
|
|
70
|
-
// TODO filter by dirname
|
|
71
|
-
return files;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Return information (size) about files in this file system
|
|
75
|
-
*/
|
|
76
|
-
async stat(path, options) {
|
|
77
|
-
const file = this.files[path];
|
|
78
|
-
if (!file) {
|
|
79
|
-
throw new Error(path);
|
|
80
|
-
}
|
|
81
|
-
return { size: file.size };
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Just removes the file from the list
|
|
85
|
-
*/
|
|
86
|
-
async unlink(path) {
|
|
87
|
-
delete this.files[path];
|
|
88
|
-
delete this.lowerCaseFiles[path];
|
|
89
|
-
this.usedFiles[path] = true;
|
|
90
|
-
}
|
|
91
|
-
// implements IRandomAccessFileSystem
|
|
92
|
-
// RANDOM ACCESS
|
|
93
|
-
async open(pathname, flags, mode) {
|
|
94
|
-
return this.files[pathname];
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Read a range into a buffer
|
|
98
|
-
* @todo - handle position memory
|
|
99
|
-
* @param buffer is the buffer that the data (read from the fd) will be written to.
|
|
100
|
-
* @param offset is the offset in the buffer to start writing at.
|
|
101
|
-
* @param length is an integer specifying the number of bytes to read.
|
|
102
|
-
* @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.
|
|
103
|
-
*/
|
|
104
|
-
async read(fd, buffer, offset = 0, length = buffer.byteLength, position = null) {
|
|
105
|
-
const file = fd;
|
|
106
|
-
const startPosition = 0; // position
|
|
107
|
-
const arrayBuffer = await file.slice(startPosition, startPosition + length).arrayBuffer();
|
|
108
|
-
// copy into target buffer
|
|
109
|
-
return { bytesRead: length, buffer: arrayBuffer };
|
|
110
|
-
}
|
|
111
|
-
async close(fd) {
|
|
112
|
-
// NO OP
|
|
113
|
-
}
|
|
114
|
-
// fstat(fd: number): Promise<object>; // Stat
|
|
115
|
-
// PRIVATE
|
|
116
|
-
// Supports case independent paths, and file usage tracking
|
|
117
|
-
_getFile(path, used) {
|
|
118
|
-
// Prefer case match, but fall back to case indepent.
|
|
119
|
-
const file = this.files[path] || this.lowerCaseFiles[path];
|
|
120
|
-
if (file && used) {
|
|
121
|
-
this.usedFiles[path] = true;
|
|
122
|
-
}
|
|
123
|
-
return file;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
exports.default = 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,16 +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__ : 'latest';
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
if (!globalThis.loaders) {
|
|
9
|
-
log_1.log.log(1, `loaders.gl ${version}`)();
|
|
10
|
-
globalThis.loaders = Object.assign(globalThis.loaders || {}, {
|
|
11
|
-
VERSION: version,
|
|
12
|
-
log: log_1.log
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
exports.default = globalThis.loaders;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkFetchResponseStatusSync = exports.checkFetchResponseStatus = void 0;
|
|
4
|
-
async function checkFetchResponseStatus(response) {
|
|
5
|
-
if (!response.ok) {
|
|
6
|
-
let errorMessage = `fetch failed ${response.status} ${response.statusText}`;
|
|
7
|
-
try {
|
|
8
|
-
const text = await response.text();
|
|
9
|
-
if (text) {
|
|
10
|
-
errorMessage += `: ${getErrorText(text)}`;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
// ignore error
|
|
15
|
-
}
|
|
16
|
-
throw new Error(errorMessage);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.checkFetchResponseStatus = checkFetchResponseStatus;
|
|
20
|
-
function checkFetchResponseStatusSync(response) {
|
|
21
|
-
if (!response.ok) {
|
|
22
|
-
throw new Error(`fetch failed ${response.status}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.checkFetchResponseStatusSync = checkFetchResponseStatusSync;
|
|
26
|
-
function getErrorText(text) {
|
|
27
|
-
// Look for HTML error texts
|
|
28
|
-
const matches = text.match('<pre>(.*)</pre>');
|
|
29
|
-
return matches ? matches[1] : ` ${text.slice(0, 10)}...`;
|
|
30
|
-
}
|
|
@@ -1,129 +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
|
-
return data[Symbol.asyncIterator]();
|
|
92
|
-
}
|
|
93
|
-
return getIterableFromData(data);
|
|
94
|
-
}
|
|
95
|
-
exports.getAsyncIterableFromData = getAsyncIterableFromData;
|
|
96
|
-
async function getReadableStream(data) {
|
|
97
|
-
if ((0, is_type_1.isReadableStream)(data)) {
|
|
98
|
-
return data;
|
|
99
|
-
}
|
|
100
|
-
if ((0, is_type_1.isResponse)(data)) {
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
return data.body;
|
|
103
|
-
}
|
|
104
|
-
const response = await (0, response_utils_1.makeResponse)(data);
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
return response.body;
|
|
107
|
-
}
|
|
108
|
-
exports.getReadableStream = getReadableStream;
|
|
109
|
-
// HELPERS
|
|
110
|
-
function getIterableFromData(data) {
|
|
111
|
-
// generate an iterator that emits a single chunk
|
|
112
|
-
if (ArrayBuffer.isView(data)) {
|
|
113
|
-
return (function* oneChunk() {
|
|
114
|
-
yield data.buffer;
|
|
115
|
-
})();
|
|
116
|
-
}
|
|
117
|
-
if (data instanceof ArrayBuffer) {
|
|
118
|
-
return (function* oneChunk() {
|
|
119
|
-
yield data;
|
|
120
|
-
})();
|
|
121
|
-
}
|
|
122
|
-
if ((0, is_type_1.isIterator)(data)) {
|
|
123
|
-
return data;
|
|
124
|
-
}
|
|
125
|
-
if ((0, is_type_1.isIterable)(data)) {
|
|
126
|
-
return data[Symbol.iterator]();
|
|
127
|
-
}
|
|
128
|
-
throw new Error(ERR_DATA);
|
|
129
|
-
}
|
|
@@ -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 fetchOptions = options || globalOptions;
|
|
16
|
-
// options.fetch can be a function
|
|
17
|
-
if (typeof fetchOptions.fetch === 'function') {
|
|
18
|
-
return fetchOptions.fetch;
|
|
19
|
-
}
|
|
20
|
-
// options.fetch can be an options object
|
|
21
|
-
if ((0, is_type_1.isObject)(fetchOptions.fetch)) {
|
|
22
|
-
return (url) => (0, fetch_file_1.fetchFile)(url, fetchOptions);
|
|
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 non-array loader is force selected, but only on top-level (context === null)
|
|
44
|
-
if (!context && 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 : null;
|
|
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;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeLoader = exports.isLoaderObject = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
function isLoaderObject(loader) {
|
|
6
|
-
if (!loader) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
if (Array.isArray(loader)) {
|
|
10
|
-
loader = loader[0];
|
|
11
|
-
}
|
|
12
|
-
const hasExtensions = Array.isArray(loader?.extensions);
|
|
13
|
-
/* Now handled by types and worker loaders do not have these
|
|
14
|
-
let hasParser =
|
|
15
|
-
loader.parseTextSync ||
|
|
16
|
-
loader.parseSync ||
|
|
17
|
-
loader.parse ||
|
|
18
|
-
loader.parseStream || // TODO Remove, Replace with parseInBatches
|
|
19
|
-
loader.parseInBatches;
|
|
20
|
-
*/
|
|
21
|
-
return hasExtensions;
|
|
22
|
-
}
|
|
23
|
-
exports.isLoaderObject = isLoaderObject;
|
|
24
|
-
function normalizeLoader(loader) {
|
|
25
|
-
// This error is fairly easy to trigger by mixing up import statements etc
|
|
26
|
-
// So we make an exception and add a developer error message for this case
|
|
27
|
-
// To help new users from getting stuck here
|
|
28
|
-
(0, loader_utils_1.assert)(loader, 'null loader');
|
|
29
|
-
(0, loader_utils_1.assert)(isLoaderObject(loader), 'invalid loader');
|
|
30
|
-
// NORMALIZE [LOADER, OPTIONS] => LOADER
|
|
31
|
-
// If [loader, options], create a new loaders object with options merged in
|
|
32
|
-
let options;
|
|
33
|
-
if (Array.isArray(loader)) {
|
|
34
|
-
options = loader[1];
|
|
35
|
-
loader = loader[0];
|
|
36
|
-
loader = {
|
|
37
|
-
...loader,
|
|
38
|
-
options: { ...loader.options, ...options }
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
// NORMALIZE text and binary flags
|
|
42
|
-
// Ensure at least one of text/binary flags are properly set
|
|
43
|
-
// @ts-expect-error
|
|
44
|
-
if (loader?.parseTextSync || loader?.parseText) {
|
|
45
|
-
loader.text = true;
|
|
46
|
-
}
|
|
47
|
-
if (!loader.text) {
|
|
48
|
-
loader.binary = true;
|
|
49
|
-
}
|
|
50
|
-
return loader;
|
|
51
|
-
}
|
|
52
|
-
exports.normalizeLoader = normalizeLoader;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REMOVED_LOADER_OPTIONS = exports.DEFAULT_LOADER_OPTIONS = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const loggers_1 = require("./loggers");
|
|
6
|
-
exports.DEFAULT_LOADER_OPTIONS = {
|
|
7
|
-
// baseUri
|
|
8
|
-
fetch: null,
|
|
9
|
-
mimeType: undefined,
|
|
10
|
-
nothrow: false,
|
|
11
|
-
log: new loggers_1.ConsoleLog(),
|
|
12
|
-
CDN: 'https://unpkg.com/@loaders.gl',
|
|
13
|
-
worker: true,
|
|
14
|
-
maxConcurrency: 3,
|
|
15
|
-
maxMobileConcurrency: 1,
|
|
16
|
-
reuseWorkers: loader_utils_1.isBrowser,
|
|
17
|
-
_nodeWorkers: false,
|
|
18
|
-
_workerType: '',
|
|
19
|
-
limit: 0,
|
|
20
|
-
_limitMB: 0,
|
|
21
|
-
batchSize: 'auto',
|
|
22
|
-
batchDebounceMs: 0,
|
|
23
|
-
metadata: false,
|
|
24
|
-
transforms: []
|
|
25
|
-
};
|
|
26
|
-
exports.REMOVED_LOADER_OPTIONS = {
|
|
27
|
-
throws: 'nothrow',
|
|
28
|
-
dataType: '(no longer used)',
|
|
29
|
-
uri: 'baseUri',
|
|
30
|
-
// Warn if fetch options are used on top-level
|
|
31
|
-
method: 'fetch.method',
|
|
32
|
-
headers: 'fetch.headers',
|
|
33
|
-
body: 'fetch.body',
|
|
34
|
-
mode: 'fetch.mode',
|
|
35
|
-
credentials: 'fetch.credentials',
|
|
36
|
-
cache: 'fetch.cache',
|
|
37
|
-
redirect: 'fetch.redirect',
|
|
38
|
-
referrer: 'fetch.referrer',
|
|
39
|
-
referrerPolicy: 'fetch.referrerPolicy',
|
|
40
|
-
integrity: 'fetch.integrity',
|
|
41
|
-
keepalive: 'fetch.keepalive',
|
|
42
|
-
signal: 'fetch.signal'
|
|
43
|
-
};
|