@loaders.gl/core 4.5.3 → 5.0.0-alpha.10
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/LICENSE +14 -3
- package/dist/dist.dev.js +1789 -352
- package/dist/dist.min.js +4 -3
- package/dist/index.cjs +3087 -311
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/iterators/make-iterator/make-stream-iterator.js +48 -9
- package/dist/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/lib/api/core-api.d.ts +6 -0
- package/dist/lib/api/core-api.d.ts.map +1 -0
- package/dist/lib/api/core-api.js +23 -0
- package/dist/lib/api/core-api.js.map +1 -0
- package/dist/lib/api/create-data-source.d.ts +2 -2
- package/dist/lib/api/create-data-source.d.ts.map +1 -1
- package/dist/lib/api/create-data-source.js +36 -14
- package/dist/lib/api/create-data-source.js.map +1 -1
- package/dist/lib/api/load-in-batches.d.ts +4 -4
- package/dist/lib/api/load-in-batches.d.ts.map +1 -1
- package/dist/lib/api/load-in-batches.js +17 -6
- package/dist/lib/api/load-in-batches.js.map +1 -1
- package/dist/lib/api/load-loader.d.ts +10 -0
- package/dist/lib/api/load-loader.d.ts.map +1 -0
- package/dist/lib/api/load-loader.js +222 -0
- package/dist/lib/api/load-loader.js.map +1 -0
- package/dist/lib/api/load.d.ts +3 -3
- package/dist/lib/api/load.d.ts.map +1 -1
- package/dist/lib/api/load.js +84 -5
- package/dist/lib/api/load.js.map +1 -1
- package/dist/lib/api/parse-file.d.ts +15 -0
- package/dist/lib/api/parse-file.d.ts.map +1 -0
- package/dist/lib/api/parse-file.js +74 -0
- package/dist/lib/api/parse-file.js.map +1 -0
- package/dist/lib/api/parse-in-batches.d.ts +2 -2
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
- package/dist/lib/api/parse-in-batches.js +18 -7
- package/dist/lib/api/parse-in-batches.js.map +1 -1
- package/dist/lib/api/parse-sync.d.ts +2 -2
- package/dist/lib/api/parse-sync.d.ts.map +1 -1
- package/dist/lib/api/parse-sync.js +10 -1
- package/dist/lib/api/parse-sync.js.map +1 -1
- package/dist/lib/api/parse.d.ts +2 -2
- package/dist/lib/api/parse.d.ts.map +1 -1
- package/dist/lib/api/parse.js +34 -17
- package/dist/lib/api/parse.js.map +1 -1
- package/dist/lib/api/preload.d.ts +14 -0
- package/dist/lib/api/preload.d.ts.map +1 -0
- package/dist/lib/api/preload.js +13 -0
- package/dist/lib/api/preload.js.map +1 -0
- package/dist/lib/api/register-loaders.js +1 -1
- package/dist/lib/api/register-loaders.js.map +1 -1
- package/dist/lib/api/select-loader.d.ts.map +1 -1
- package/dist/lib/api/select-loader.js +48 -5
- package/dist/lib/api/select-loader.js.map +1 -1
- package/dist/lib/api/select-source.d.ts +3 -3
- package/dist/lib/api/select-source.d.ts.map +1 -1
- package/dist/lib/api/select-source.js +2 -5
- package/dist/lib/api/select-source.js.map +1 -1
- package/dist/lib/fetch/fetch-error-message.js +1 -1
- package/dist/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/lib/filesystems/browser-filesystem.d.ts.map +1 -1
- package/dist/lib/filesystems/browser-filesystem.js +25 -11
- package/dist/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/lib/init.js.map +1 -1
- package/dist/lib/loader-utils/check-errors.js +1 -1
- package/dist/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/lib/loader-utils/get-data.d.ts +4 -0
- package/dist/lib/loader-utils/get-data.d.ts.map +1 -1
- package/dist/lib/loader-utils/get-data.js +26 -0
- package/dist/lib/loader-utils/get-data.js.map +1 -1
- package/dist/lib/loader-utils/get-fetch-function.d.ts +1 -1
- package/dist/lib/loader-utils/get-fetch-function.d.ts.map +1 -1
- package/dist/lib/loader-utils/get-fetch-function.js +16 -10
- package/dist/lib/loader-utils/get-fetch-function.js.map +1 -1
- package/dist/lib/loader-utils/loader-context.d.ts +2 -2
- package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
- package/dist/lib/loader-utils/loader-context.js +11 -4
- package/dist/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/lib/loader-utils/loggers.d.ts +19 -0
- package/dist/lib/loader-utils/loggers.d.ts.map +1 -1
- package/dist/lib/loader-utils/loggers.js +28 -2
- package/dist/lib/loader-utils/loggers.js.map +1 -1
- package/dist/lib/loader-utils/option-defaults.d.ts +1 -0
- package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-defaults.js +5 -0
- package/dist/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/lib/loader-utils/option-utils.d.ts +7 -0
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +91 -3
- package/dist/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/lib/utils/response-utils.js +5 -14
- package/dist/lib/utils/response-utils.js.map +1 -1
- package/dist/null-loader.d.ts.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-loader.js.map +1 -1
- package/dist/null-worker-node.js +270 -42
- package/dist/null-worker.js +270 -42
- package/package.json +6 -6
- package/src/index.ts +10 -1
- package/src/iterators/make-iterator/make-stream-iterator.ts +47 -9
- package/src/lib/api/core-api.ts +25 -0
- package/src/lib/api/create-data-source.ts +53 -24
- package/src/lib/api/load-in-batches.ts +33 -21
- package/src/lib/api/load-loader.ts +306 -0
- package/src/lib/api/load.ts +160 -9
- package/src/lib/api/parse-file.ts +156 -0
- package/src/lib/api/parse-in-batches.ts +35 -8
- package/src/lib/api/parse-sync.ts +27 -2
- package/src/lib/api/parse.ts +61 -20
- package/src/lib/api/preload.ts +46 -0
- package/src/lib/api/register-loaders.ts +1 -1
- package/src/lib/api/select-loader.ts +57 -5
- package/src/lib/api/select-source.ts +7 -10
- package/src/lib/fetch/fetch-error-message.ts +1 -1
- package/src/lib/filesystems/browser-filesystem.ts +25 -11
- package/src/lib/loader-utils/check-errors.ts +1 -1
- package/src/lib/loader-utils/get-data.ts +36 -0
- package/src/lib/loader-utils/get-fetch-function.ts +17 -15
- package/src/lib/loader-utils/loader-context.ts +13 -5
- package/src/lib/loader-utils/loggers.ts +28 -2
- package/src/lib/loader-utils/option-defaults.ts +5 -0
- package/src/lib/loader-utils/option-utils.ts +106 -3
- package/src/lib/utils/response-utils.ts +5 -15
- package/src/null-loader.ts +3 -3
package/dist/index.cjs
CHANGED
|
@@ -18,21 +18,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// dist/index.js
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
FetchError: () => FetchError,
|
|
24
|
-
JSONLoader: () =>
|
|
24
|
+
JSONLoader: () => JSONLoader,
|
|
25
25
|
NullLoader: () => NullLoader,
|
|
26
26
|
NullWorkerLoader: () => NullWorkerLoader,
|
|
27
|
-
RequestScheduler: () =>
|
|
27
|
+
RequestScheduler: () => RequestScheduler,
|
|
28
28
|
_BrowserFileSystem: () => BrowserFileSystem,
|
|
29
29
|
_fetchProgress: () => fetchProgress,
|
|
30
|
-
_selectSource: () =>
|
|
30
|
+
_selectSource: () => selectSource,
|
|
31
31
|
_unregisterLoaders: () => _unregisterLoaders,
|
|
32
|
-
assert: () =>
|
|
33
|
-
concatenateArrayBuffersAsync: () =>
|
|
32
|
+
assert: () => assert,
|
|
33
|
+
concatenateArrayBuffersAsync: () => concatenateArrayBuffersAsync,
|
|
34
|
+
coreApi: () => coreApi,
|
|
34
35
|
createDataSource: () => createDataSource,
|
|
35
|
-
document: () =>
|
|
36
|
+
document: () => document_,
|
|
36
37
|
encode: () => encode,
|
|
37
38
|
encodeInBatches: () => encodeInBatches,
|
|
38
39
|
encodeSync: () => encodeSync,
|
|
@@ -43,48 +44,2231 @@ __export(dist_exports, {
|
|
|
43
44
|
encodeTextSync: () => encodeTextSync,
|
|
44
45
|
encodeURLtoURL: () => encodeURLtoURL,
|
|
45
46
|
fetchFile: () => fetchFile,
|
|
46
|
-
forEach: () =>
|
|
47
|
+
forEach: () => forEach,
|
|
47
48
|
getLoaderOptions: () => getGlobalLoaderOptions,
|
|
48
|
-
getPathPrefix: () =>
|
|
49
|
-
global: () =>
|
|
50
|
-
isAsyncIterable: () =>
|
|
51
|
-
isBrowser: () =>
|
|
52
|
-
isIterable: () =>
|
|
53
|
-
isIterator: () =>
|
|
54
|
-
isPromise: () =>
|
|
55
|
-
isPureObject: () =>
|
|
56
|
-
isReadableStream: () =>
|
|
57
|
-
isResponse: () =>
|
|
58
|
-
isWorker: () =>
|
|
59
|
-
isWritableStream: () =>
|
|
49
|
+
getPathPrefix: () => getPathPrefix,
|
|
50
|
+
global: () => global_,
|
|
51
|
+
isAsyncIterable: () => isAsyncIterable,
|
|
52
|
+
isBrowser: () => isBrowser,
|
|
53
|
+
isIterable: () => isIterable,
|
|
54
|
+
isIterator: () => isIterator,
|
|
55
|
+
isPromise: () => isPromise,
|
|
56
|
+
isPureObject: () => isPureObject,
|
|
57
|
+
isReadableStream: () => isReadableStream,
|
|
58
|
+
isResponse: () => isResponse,
|
|
59
|
+
isWorker: () => isWorker,
|
|
60
|
+
isWritableStream: () => isWritableStream,
|
|
60
61
|
load: () => load,
|
|
61
62
|
loadInBatches: () => loadInBatches,
|
|
62
63
|
makeIterator: () => makeIterator,
|
|
63
|
-
makeLineIterator: () =>
|
|
64
|
-
makeNumberedLineIterator: () =>
|
|
64
|
+
makeLineIterator: () => makeLineIterator,
|
|
65
|
+
makeNumberedLineIterator: () => makeNumberedLineIterator,
|
|
65
66
|
makeStream: () => makeStream,
|
|
66
|
-
makeTextDecoderIterator: () =>
|
|
67
|
-
makeTextEncoderIterator: () =>
|
|
67
|
+
makeTextDecoderIterator: () => makeTextDecoderIterator,
|
|
68
|
+
makeTextEncoderIterator: () => makeTextEncoderIterator,
|
|
68
69
|
parse: () => parse,
|
|
70
|
+
parseFile: () => parseFile,
|
|
69
71
|
parseInBatches: () => parseInBatches,
|
|
70
72
|
parseSync: () => parseSync,
|
|
73
|
+
preload: () => preload,
|
|
74
|
+
preloadSync: () => preloadSync,
|
|
71
75
|
readArrayBuffer: () => readArrayBuffer,
|
|
72
76
|
registerLoaders: () => registerLoaders,
|
|
73
|
-
resolvePath: () =>
|
|
77
|
+
resolvePath: () => resolvePath,
|
|
74
78
|
selectLoader: () => selectLoader,
|
|
75
79
|
selectLoaderSync: () => selectLoaderSync,
|
|
76
|
-
self: () =>
|
|
80
|
+
self: () => self_,
|
|
77
81
|
setLoaderOptions: () => setGlobalOptions,
|
|
78
|
-
setPathPrefix: () =>
|
|
79
|
-
window: () =>
|
|
82
|
+
setPathPrefix: () => setPathPrefix,
|
|
83
|
+
window: () => window_
|
|
80
84
|
});
|
|
81
|
-
module.exports = __toCommonJS(
|
|
85
|
+
module.exports = __toCommonJS(index_exports);
|
|
82
86
|
|
|
83
|
-
//
|
|
84
|
-
|
|
87
|
+
// ../loader-utils/src/lib/env-utils/assert.ts
|
|
88
|
+
function assert(condition, message) {
|
|
89
|
+
if (!condition) {
|
|
90
|
+
throw new Error(message || "loader assertion failed.");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ../loader-utils/src/lib/env-utils/globals.ts
|
|
95
|
+
var globals = {
|
|
96
|
+
self: typeof self !== "undefined" && self,
|
|
97
|
+
window: typeof window !== "undefined" && window,
|
|
98
|
+
global: typeof global !== "undefined" && global,
|
|
99
|
+
document: typeof document !== "undefined" && document
|
|
100
|
+
};
|
|
101
|
+
var self_ = globals.self || globals.window || globals.global || {};
|
|
102
|
+
var window_ = globals.window || globals.self || globals.global || {};
|
|
103
|
+
var global_ = globals.global || globals.self || globals.window || {};
|
|
104
|
+
var document_ = globals.document || {};
|
|
105
|
+
var isBrowser = (
|
|
106
|
+
// @ts-ignore process does not exist on browser
|
|
107
|
+
Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
|
|
108
|
+
);
|
|
109
|
+
var isWorker = typeof importScripts === "function";
|
|
110
|
+
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
111
|
+
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
112
|
+
|
|
113
|
+
// ../loader-utils/src/lib/log-utils/log.ts
|
|
114
|
+
var import_log = require("@probe.gl/log");
|
|
115
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
116
|
+
var version = VERSION[0] >= "0" && VERSION[0] <= "9" ? `v${VERSION}` : "";
|
|
117
|
+
function createLog() {
|
|
118
|
+
const log2 = new import_log.Log({ id: "loaders.gl" });
|
|
119
|
+
globalThis.loaders ||= {};
|
|
120
|
+
globalThis.loaders.log = log2;
|
|
121
|
+
globalThis.loaders.version = version;
|
|
122
|
+
globalThis.probe ||= {};
|
|
123
|
+
globalThis.probe.loaders = log2;
|
|
124
|
+
return log2;
|
|
125
|
+
}
|
|
126
|
+
var log = createLog();
|
|
127
|
+
|
|
128
|
+
// ../loader-utils/src/lib/javascript-utils/is-type.ts
|
|
129
|
+
var isBoolean = (value) => typeof value === "boolean";
|
|
130
|
+
var isFunction = (value) => typeof value === "function";
|
|
131
|
+
var isObject = (value) => value !== null && typeof value === "object";
|
|
132
|
+
var isPureObject = (value) => isObject(value) && value.constructor === {}.constructor;
|
|
133
|
+
var isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
|
|
134
|
+
var isArrayBufferLike = (value) => isObject(value) && typeof value.byteLength === "number" && typeof value.slice === "function";
|
|
135
|
+
var isPromise = (value) => isObject(value) && "then" in value && isFunction(value.then);
|
|
136
|
+
var isIterable = (value) => Boolean(value) && isFunction(value[Symbol.iterator]);
|
|
137
|
+
var isAsyncIterable = (value) => Boolean(value) && isFunction(value[Symbol.asyncIterator]);
|
|
138
|
+
var isIterator = (value) => Boolean(value) && isFunction(value.next);
|
|
139
|
+
var isResponse = (value) => typeof Response !== "undefined" && value instanceof Response || isObject(value) && isFunction(value.arrayBuffer) && isFunction(value.text) && isFunction(value.json);
|
|
140
|
+
var isBlob = (value) => typeof Blob !== "undefined" && value instanceof Blob;
|
|
141
|
+
var isWritableDOMStream = (value) => isObject(value) && isFunction(value.abort) && isFunction(value.getWriter);
|
|
142
|
+
var isReadableDOMStream = (value) => typeof ReadableStream !== "undefined" && value instanceof ReadableStream || isObject(value) && isFunction(value.tee) && isFunction(value.cancel) && isFunction(value.getReader);
|
|
143
|
+
var isWritableNodeStream = (value) => isObject(value) && isFunction(value.end) && isFunction(value.write) && isBoolean(value.writable);
|
|
144
|
+
var isReadableNodeStream = (value) => isObject(value) && isFunction(value.read) && isFunction(value.pipe) && isBoolean(value.readable);
|
|
145
|
+
var isReadableStream = (value) => isReadableDOMStream(value) || isReadableNodeStream(value);
|
|
146
|
+
var isWritableStream = (value) => isWritableDOMStream(value) || isWritableNodeStream(value);
|
|
147
|
+
|
|
148
|
+
// ../loader-utils/src/lib/option-utils/merge-options.ts
|
|
149
|
+
function mergeOptions(baseOptions, newOptions) {
|
|
150
|
+
return mergeOptionsRecursively(baseOptions || {}, newOptions);
|
|
151
|
+
}
|
|
152
|
+
function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
|
|
153
|
+
if (level > 3) {
|
|
154
|
+
return newOptions;
|
|
155
|
+
}
|
|
156
|
+
const options = { ...baseOptions };
|
|
157
|
+
for (const [key, newValue] of Object.entries(newOptions)) {
|
|
158
|
+
if (isPureObject(newValue)) {
|
|
159
|
+
options[key] = mergeOptionsRecursively(
|
|
160
|
+
options[key] || {},
|
|
161
|
+
newOptions[key],
|
|
162
|
+
level + 1
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
options[key] = newOptions[key];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return options;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ../loader-utils/src/lib/module-utils/js-module-utils.ts
|
|
172
|
+
function registerJSModules(modules) {
|
|
173
|
+
globalThis.loaders ||= {};
|
|
174
|
+
globalThis.loaders.modules ||= {};
|
|
175
|
+
Object.assign(globalThis.loaders.modules, modules);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ../worker-utils/src/lib/npm-tag.ts
|
|
179
|
+
var NPM_TAG = "latest";
|
|
180
|
+
|
|
181
|
+
// ../worker-utils/src/lib/env-utils/version.ts
|
|
182
|
+
function getVersion() {
|
|
183
|
+
var _a;
|
|
184
|
+
if (!((_a = globalThis._loadersgl_) == null ? void 0 : _a.version)) {
|
|
185
|
+
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
186
|
+
if (typeof __VERSION__ === "undefined") {
|
|
187
|
+
globalThis._loadersgl_.version = NPM_TAG;
|
|
188
|
+
} else {
|
|
189
|
+
globalThis._loadersgl_.version = __VERSION__;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return globalThis._loadersgl_.version;
|
|
193
|
+
}
|
|
194
|
+
var VERSION2 = getVersion();
|
|
195
|
+
|
|
196
|
+
// ../worker-utils/src/lib/env-utils/assert.ts
|
|
197
|
+
function assert2(condition, message) {
|
|
198
|
+
if (!condition) {
|
|
199
|
+
throw new Error(message || "loaders.gl assertion failed.");
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ../worker-utils/src/lib/env-utils/globals.ts
|
|
204
|
+
var globals2 = {
|
|
205
|
+
self: typeof self !== "undefined" && self,
|
|
206
|
+
window: typeof window !== "undefined" && window,
|
|
207
|
+
global: typeof global !== "undefined" && global,
|
|
208
|
+
document: typeof document !== "undefined" && document
|
|
209
|
+
};
|
|
210
|
+
var self_2 = globals2.self || globals2.window || globals2.global || {};
|
|
211
|
+
var window_2 = globals2.window || globals2.self || globals2.global || {};
|
|
212
|
+
var global_2 = globals2.global || globals2.self || globals2.window || {};
|
|
213
|
+
var document_2 = globals2.document || {};
|
|
214
|
+
var isBrowser2 = (
|
|
215
|
+
// @ts-ignore process.browser
|
|
216
|
+
typeof process !== "object" || String(process) !== "[object process]" || process.browser
|
|
217
|
+
);
|
|
218
|
+
var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
219
|
+
var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
220
|
+
var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
|
|
221
|
+
|
|
222
|
+
// ../worker-utils/src/lib/worker-farm/worker-job.ts
|
|
223
|
+
var WorkerJob = class {
|
|
224
|
+
name;
|
|
225
|
+
workerThread;
|
|
226
|
+
isRunning = true;
|
|
227
|
+
/** Promise that resolves when Job is done */
|
|
228
|
+
result;
|
|
229
|
+
_resolve = () => {
|
|
230
|
+
};
|
|
231
|
+
_reject = () => {
|
|
232
|
+
};
|
|
233
|
+
constructor(jobName, workerThread) {
|
|
234
|
+
this.name = jobName;
|
|
235
|
+
this.workerThread = workerThread;
|
|
236
|
+
this.result = new Promise((resolve2, reject) => {
|
|
237
|
+
this._resolve = resolve2;
|
|
238
|
+
this._reject = reject;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Send a message to the job's worker thread
|
|
243
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
244
|
+
*/
|
|
245
|
+
postMessage(type, payload) {
|
|
246
|
+
this.workerThread.postMessage({
|
|
247
|
+
source: "loaders.gl",
|
|
248
|
+
// Lets worker ignore unrelated messages
|
|
249
|
+
type,
|
|
250
|
+
payload
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Call to resolve the `result` Promise with the supplied value
|
|
255
|
+
*/
|
|
256
|
+
done(value) {
|
|
257
|
+
if (!this.isRunning) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.isRunning = false;
|
|
261
|
+
this._resolve(value);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Call to reject the `result` Promise with the supplied error
|
|
265
|
+
*/
|
|
266
|
+
error(error) {
|
|
267
|
+
if (!this.isRunning) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
this.isRunning = false;
|
|
271
|
+
this._reject(error);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Terminates the worker executing this job and rejects its result.
|
|
275
|
+
* @param reason Abort reason supplied by the caller, or a cross-runtime `AbortError`.
|
|
276
|
+
*/
|
|
277
|
+
abort(reason) {
|
|
278
|
+
if (!this.isRunning) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const error = reason ?? createAbortError(`Worker job "${this.name}" was aborted`);
|
|
282
|
+
this.workerThread.destroy();
|
|
283
|
+
this.error(error);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
function createAbortError(message) {
|
|
287
|
+
const error = new Error(message);
|
|
288
|
+
error.name = "AbortError";
|
|
289
|
+
return error;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ../worker-utils/src/lib/node/worker_threads-browser.ts
|
|
293
|
+
var NodeWorker = class {
|
|
294
|
+
/** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
|
|
295
|
+
constructor(...arguments_) {
|
|
296
|
+
var _a;
|
|
297
|
+
const runtimeProcess = globalThis.process;
|
|
298
|
+
const WorkerConstructor = (_a = runtimeProcess == null ? void 0 : runtimeProcess.getBuiltinModule) == null ? void 0 : _a.call(runtimeProcess, "node:worker_threads").Worker;
|
|
299
|
+
if (WorkerConstructor) {
|
|
300
|
+
return new WorkerConstructor(...arguments_);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/** No-op browser fallback matching the native Worker API. */
|
|
304
|
+
terminate() {
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
|
|
309
|
+
var workerURLCache = /* @__PURE__ */ new Map();
|
|
310
|
+
function getLoadableWorkerURL(props) {
|
|
311
|
+
assert2(props.source && !props.url || !props.source && props.url);
|
|
312
|
+
let workerURL = workerURLCache.get(props.source || props.url);
|
|
313
|
+
if (!workerURL) {
|
|
314
|
+
if (props.url) {
|
|
315
|
+
workerURL = getLoadableWorkerURLFromURL(props.url);
|
|
316
|
+
workerURLCache.set(props.url, workerURL);
|
|
317
|
+
}
|
|
318
|
+
if (props.source) {
|
|
319
|
+
workerURL = getLoadableWorkerURLFromSource(props.source);
|
|
320
|
+
workerURLCache.set(props.source, workerURL);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
assert2(workerURL);
|
|
324
|
+
return workerURL;
|
|
325
|
+
}
|
|
326
|
+
function getLoadableWorkerURLFromURL(url) {
|
|
327
|
+
if (!url.startsWith("http")) {
|
|
328
|
+
return url;
|
|
329
|
+
}
|
|
330
|
+
const workerSource = buildScriptSource(url);
|
|
331
|
+
return getLoadableWorkerURLFromSource(workerSource);
|
|
332
|
+
}
|
|
333
|
+
function getLoadableWorkerURLFromSource(workerSource) {
|
|
334
|
+
const blob = new Blob([workerSource], { type: "application/javascript" });
|
|
335
|
+
return URL.createObjectURL(blob);
|
|
336
|
+
}
|
|
337
|
+
function buildScriptSource(workerUrl) {
|
|
338
|
+
return `try {
|
|
339
|
+
importScripts('${workerUrl}');
|
|
340
|
+
} catch (error) {
|
|
341
|
+
console.error(error);
|
|
342
|
+
throw error;
|
|
343
|
+
}`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
347
|
+
function getTransferList(object, recursive = true, transfers) {
|
|
348
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
349
|
+
if (!object) {
|
|
350
|
+
} else if (isTransferable(object)) {
|
|
351
|
+
transfersSet.add(object);
|
|
352
|
+
} else if (isTransferable(object.buffer)) {
|
|
353
|
+
transfersSet.add(object.buffer);
|
|
354
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
355
|
+
} else if (recursive && typeof object === "object") {
|
|
356
|
+
for (const key in object) {
|
|
357
|
+
getTransferList(object[key], recursive, transfersSet);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
361
|
+
}
|
|
362
|
+
function isTransferable(object) {
|
|
363
|
+
if (!object) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
if (object instanceof ArrayBuffer) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
function getTransferListForWriter(object) {
|
|
381
|
+
if (object === null) {
|
|
382
|
+
return {};
|
|
383
|
+
}
|
|
384
|
+
const clone = Object.assign({}, object);
|
|
385
|
+
Object.keys(clone).forEach((key) => {
|
|
386
|
+
if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
387
|
+
clone[key] = getTransferListForWriter(object[key]);
|
|
388
|
+
} else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
|
|
389
|
+
clone[key] = {};
|
|
390
|
+
} else {
|
|
391
|
+
clone[key] = object[key];
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
return clone;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// ../worker-utils/src/lib/worker-farm/worker-thread.ts
|
|
398
|
+
var NOOP = () => {
|
|
399
|
+
};
|
|
400
|
+
var WorkerThread = class {
|
|
401
|
+
name;
|
|
402
|
+
source;
|
|
403
|
+
url;
|
|
404
|
+
/** Lazily resolves the classic worker URL used as a fallback. */
|
|
405
|
+
getUrl;
|
|
406
|
+
/** Creates a browser Worker directly. */
|
|
407
|
+
loadWorker;
|
|
408
|
+
terminated = false;
|
|
409
|
+
worker;
|
|
410
|
+
onMessage;
|
|
411
|
+
onError;
|
|
412
|
+
_loadableURL = "";
|
|
413
|
+
/** Checks if workers are supported on this platform */
|
|
414
|
+
static isSupported() {
|
|
415
|
+
return typeof Worker !== "undefined" && isBrowser2 || typeof NodeWorker !== "undefined" && !isBrowser2;
|
|
416
|
+
}
|
|
417
|
+
constructor(props) {
|
|
418
|
+
const { name, source, url, getUrl, loadWorker } = props;
|
|
419
|
+
assert2(source || url || getUrl || loadWorker);
|
|
420
|
+
this.name = name;
|
|
421
|
+
this.source = source;
|
|
422
|
+
this.url = url;
|
|
423
|
+
this.getUrl = getUrl;
|
|
424
|
+
this.loadWorker = loadWorker;
|
|
425
|
+
this.onMessage = NOOP;
|
|
426
|
+
this.onError = (error) => console.log(error);
|
|
427
|
+
this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Terminate this worker thread
|
|
431
|
+
* @note Can free up significant memory
|
|
432
|
+
*/
|
|
433
|
+
destroy() {
|
|
434
|
+
this.onMessage = NOOP;
|
|
435
|
+
this.onError = NOOP;
|
|
436
|
+
this.worker.terminate();
|
|
437
|
+
this.terminated = true;
|
|
438
|
+
}
|
|
439
|
+
/** Keeps this worker from preventing Node.js process exit while idle. */
|
|
440
|
+
unref() {
|
|
441
|
+
if (!isBrowser2 && typeof this.worker.unref === "function") {
|
|
442
|
+
this.worker.unref();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
/** Keeps this worker alive while it is actively processing a job. */
|
|
446
|
+
ref() {
|
|
447
|
+
if (!isBrowser2 && typeof this.worker.ref === "function") {
|
|
448
|
+
this.worker.ref();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
get isRunning() {
|
|
452
|
+
return Boolean(this.onMessage);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Send a message to this worker thread
|
|
456
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
457
|
+
* @param transferList If not supplied, calculated automatically by traversing data
|
|
458
|
+
*/
|
|
459
|
+
postMessage(data, transferList) {
|
|
460
|
+
transferList = transferList || getTransferList(data);
|
|
461
|
+
this.worker.postMessage(data, transferList);
|
|
462
|
+
}
|
|
463
|
+
// PRIVATE
|
|
464
|
+
/**
|
|
465
|
+
* Generate a standard Error from an ErrorEvent
|
|
466
|
+
* @param event
|
|
467
|
+
*/
|
|
468
|
+
_getErrorFromErrorEvent(event) {
|
|
469
|
+
let message = "Failed to load ";
|
|
470
|
+
message += `worker ${this.name} from ${this.url || "built-in worker factory"}. `;
|
|
471
|
+
if (event.message) {
|
|
472
|
+
message += `${event.message} in `;
|
|
473
|
+
}
|
|
474
|
+
if (event.lineno) {
|
|
475
|
+
message += `:${event.lineno}:${event.colno}`;
|
|
476
|
+
}
|
|
477
|
+
return new Error(message);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Creates a worker thread on the browser
|
|
481
|
+
*/
|
|
482
|
+
_createBrowserWorker() {
|
|
483
|
+
var _a;
|
|
484
|
+
if (this.loadWorker) {
|
|
485
|
+
try {
|
|
486
|
+
const worker2 = this.loadWorker();
|
|
487
|
+
if (worker2) {
|
|
488
|
+
return this._initializeBrowserWorker(worker2);
|
|
489
|
+
}
|
|
490
|
+
} catch (error) {
|
|
491
|
+
if (!this.source && !this.url && !this.getUrl) {
|
|
492
|
+
throw error;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const url = this.url || ((_a = this.getUrl) == null ? void 0 : _a.call(this));
|
|
497
|
+
this._loadableURL = getLoadableWorkerURL({ source: this.source, url });
|
|
498
|
+
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
499
|
+
return this._initializeBrowserWorker(worker);
|
|
500
|
+
}
|
|
501
|
+
/** Attaches protocol handlers to a browser worker. */
|
|
502
|
+
_initializeBrowserWorker(worker) {
|
|
503
|
+
worker.onmessage = (event) => {
|
|
504
|
+
if (!event.data) {
|
|
505
|
+
this.onError(new Error("No data received"));
|
|
506
|
+
} else {
|
|
507
|
+
this.onMessage(event.data);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
worker.onerror = (error) => {
|
|
511
|
+
this.onError(this._getErrorFromErrorEvent(error));
|
|
512
|
+
this.terminated = true;
|
|
513
|
+
};
|
|
514
|
+
worker.onmessageerror = (event) => console.error(event);
|
|
515
|
+
return worker;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Creates a worker thread in node.js
|
|
519
|
+
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
520
|
+
*/
|
|
521
|
+
_createNodeWorker() {
|
|
522
|
+
let worker;
|
|
523
|
+
if (this.url) {
|
|
524
|
+
const absolute = this.url.includes(":/") || this.url.startsWith("/");
|
|
525
|
+
const url = absolute ? this.url : `./${this.url}`;
|
|
526
|
+
const workerUrl = url.startsWith("file:") ? new URL(url) : url;
|
|
527
|
+
const type = this.url.endsWith(".ts") || this.url.endsWith(".mjs") ? "module" : "commonjs";
|
|
528
|
+
worker = new NodeWorker(workerUrl, { eval: false, type });
|
|
529
|
+
} else if (this.source) {
|
|
530
|
+
worker = new NodeWorker(this.source, { eval: true });
|
|
531
|
+
} else {
|
|
532
|
+
throw new Error("no worker");
|
|
533
|
+
}
|
|
534
|
+
worker.on("message", (data) => {
|
|
535
|
+
this.onMessage(data);
|
|
536
|
+
});
|
|
537
|
+
worker.on("error", (error) => {
|
|
538
|
+
this.onError(error);
|
|
539
|
+
});
|
|
540
|
+
worker.on("exit", (_code) => {
|
|
541
|
+
});
|
|
542
|
+
return worker;
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
547
|
+
var WorkerPool = class {
|
|
548
|
+
name = "unnamed";
|
|
549
|
+
source;
|
|
550
|
+
// | Function;
|
|
551
|
+
url;
|
|
552
|
+
/** Lazily resolves a classic worker fallback URL. */
|
|
553
|
+
getUrl;
|
|
554
|
+
/** Creates a browser Worker directly. */
|
|
555
|
+
loadWorker;
|
|
556
|
+
maxConcurrency = 1;
|
|
557
|
+
maxMobileConcurrency = 1;
|
|
558
|
+
onDebug = () => {
|
|
559
|
+
};
|
|
560
|
+
reuseWorkers = true;
|
|
561
|
+
props = {};
|
|
562
|
+
jobQueue = [];
|
|
563
|
+
idleQueue = [];
|
|
564
|
+
activeJobs = /* @__PURE__ */ new Set();
|
|
565
|
+
count = 0;
|
|
566
|
+
isDestroyed = false;
|
|
567
|
+
/** Checks if workers are supported on this platform */
|
|
568
|
+
static isSupported() {
|
|
569
|
+
return WorkerThread.isSupported();
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* @param processor - worker function
|
|
573
|
+
* @param maxConcurrency - max count of workers
|
|
574
|
+
*/
|
|
575
|
+
constructor(props) {
|
|
576
|
+
this.source = props.source;
|
|
577
|
+
this.url = props.url;
|
|
578
|
+
this.getUrl = props.getUrl;
|
|
579
|
+
this.loadWorker = props.loadWorker;
|
|
580
|
+
this.setProps(props);
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Terminates all workers in the pool and aborts active jobs.
|
|
584
|
+
* @param reason Optional error delivered to active jobs.
|
|
585
|
+
* @note Can free up significant memory
|
|
586
|
+
*/
|
|
587
|
+
destroy(reason = new Error("Worker pool was destroyed")) {
|
|
588
|
+
this.activeJobs.forEach((job) => job.abort(reason));
|
|
589
|
+
const queuedJobs = this.jobQueue.splice(0);
|
|
590
|
+
queuedJobs.forEach((queuedJob) => queuedJob.onReject(reason));
|
|
591
|
+
this.idleQueue.forEach((worker) => worker.destroy());
|
|
592
|
+
this.isDestroyed = true;
|
|
593
|
+
}
|
|
594
|
+
setProps(props) {
|
|
595
|
+
this.props = { ...this.props, ...props };
|
|
596
|
+
if (props.name !== void 0) {
|
|
597
|
+
this.name = props.name;
|
|
598
|
+
}
|
|
599
|
+
if (props.maxConcurrency !== void 0) {
|
|
600
|
+
this.maxConcurrency = props.maxConcurrency;
|
|
601
|
+
}
|
|
602
|
+
if (props.maxMobileConcurrency !== void 0) {
|
|
603
|
+
this.maxMobileConcurrency = props.maxMobileConcurrency;
|
|
604
|
+
}
|
|
605
|
+
if (props.reuseWorkers !== void 0) {
|
|
606
|
+
this.reuseWorkers = props.reuseWorkers;
|
|
607
|
+
}
|
|
608
|
+
if (props.onDebug !== void 0) {
|
|
609
|
+
this.onDebug = props.onDebug;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
async startJob(name, onMessage2 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
|
|
613
|
+
if (this.isDestroyed) {
|
|
614
|
+
return Promise.reject(new Error("Worker pool was destroyed"));
|
|
615
|
+
}
|
|
616
|
+
const startPromise = new Promise((onStart, onReject) => {
|
|
617
|
+
this.jobQueue.push({ name, onMessage: onMessage2, onError, onStart, onReject });
|
|
618
|
+
return this;
|
|
619
|
+
});
|
|
620
|
+
this._startQueuedJob();
|
|
621
|
+
return await startPromise;
|
|
622
|
+
}
|
|
623
|
+
// PRIVATE
|
|
624
|
+
/**
|
|
625
|
+
* Starts first queued job if worker is available or can be created
|
|
626
|
+
* Called when job is started and whenever a worker returns to the idleQueue
|
|
627
|
+
*/
|
|
628
|
+
async _startQueuedJob() {
|
|
629
|
+
if (!this.jobQueue.length) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
const workerThread = this._getAvailableWorker();
|
|
633
|
+
if (!workerThread) {
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const queuedJob = this.jobQueue.shift();
|
|
637
|
+
if (queuedJob) {
|
|
638
|
+
this.onDebug({
|
|
639
|
+
message: "Starting job",
|
|
640
|
+
name: queuedJob.name,
|
|
641
|
+
workerThread,
|
|
642
|
+
backlog: this.jobQueue.length
|
|
643
|
+
});
|
|
644
|
+
const job = new WorkerJob(queuedJob.name, workerThread);
|
|
645
|
+
this.activeJobs.add(job);
|
|
646
|
+
workerThread.ref();
|
|
647
|
+
workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
|
|
648
|
+
workerThread.onError = (error) => queuedJob.onError(job, error);
|
|
649
|
+
queuedJob.onStart(job);
|
|
650
|
+
try {
|
|
651
|
+
await job.result;
|
|
652
|
+
} catch {
|
|
653
|
+
} finally {
|
|
654
|
+
this.activeJobs.delete(job);
|
|
655
|
+
this.returnWorkerToQueue(workerThread);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Returns a worker to the idle queue
|
|
661
|
+
* Destroys the worker if
|
|
662
|
+
* - pool is destroyed
|
|
663
|
+
* - if this pool doesn't reuse workers
|
|
664
|
+
* - if maxConcurrency has been lowered
|
|
665
|
+
* @param worker
|
|
666
|
+
*/
|
|
667
|
+
returnWorkerToQueue(worker) {
|
|
668
|
+
const shouldDestroyWorker = (
|
|
669
|
+
// Aborted jobs terminate their worker immediately.
|
|
670
|
+
worker.terminated || // If the pool is destroyed, there is no reason to keep the worker around
|
|
671
|
+
this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
|
|
672
|
+
!this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
|
|
673
|
+
this.count > this._getMaxConcurrency()
|
|
674
|
+
);
|
|
675
|
+
if (shouldDestroyWorker) {
|
|
676
|
+
if (!worker.terminated) {
|
|
677
|
+
worker.destroy();
|
|
678
|
+
}
|
|
679
|
+
this.count--;
|
|
680
|
+
} else {
|
|
681
|
+
worker.unref();
|
|
682
|
+
this.idleQueue.push(worker);
|
|
683
|
+
}
|
|
684
|
+
if (!this.isDestroyed) {
|
|
685
|
+
this._startQueuedJob();
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Returns idle worker or creates new worker if maxConcurrency has not been reached
|
|
690
|
+
*/
|
|
691
|
+
_getAvailableWorker() {
|
|
692
|
+
if (this.idleQueue.length > 0) {
|
|
693
|
+
return this.idleQueue.shift() || null;
|
|
694
|
+
}
|
|
695
|
+
if (this.count < this._getMaxConcurrency()) {
|
|
696
|
+
this.count++;
|
|
697
|
+
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
698
|
+
return new WorkerThread({
|
|
699
|
+
name,
|
|
700
|
+
source: this.source,
|
|
701
|
+
url: this.url,
|
|
702
|
+
getUrl: this.getUrl,
|
|
703
|
+
loadWorker: this.loadWorker
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
return null;
|
|
707
|
+
}
|
|
708
|
+
_getMaxConcurrency() {
|
|
709
|
+
return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
// ../worker-utils/src/lib/worker-farm/worker-farm.ts
|
|
714
|
+
var DEFAULT_PROPS = {
|
|
715
|
+
maxConcurrency: 3,
|
|
716
|
+
maxMobileConcurrency: 1,
|
|
717
|
+
reuseWorkers: true,
|
|
718
|
+
onDebug: () => {
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
var loadWorkerIds = /* @__PURE__ */ new WeakMap();
|
|
722
|
+
var nextLoadWorkerId = 1;
|
|
723
|
+
var WorkerFarm = class _WorkerFarm {
|
|
724
|
+
props;
|
|
725
|
+
workerPools = /* @__PURE__ */ new Map();
|
|
726
|
+
// singleton
|
|
727
|
+
static _workerFarm;
|
|
728
|
+
/** Checks if workers are supported on this platform */
|
|
729
|
+
static isSupported() {
|
|
730
|
+
return WorkerThread.isSupported();
|
|
731
|
+
}
|
|
732
|
+
/** Get the singleton instance of the global worker farm */
|
|
733
|
+
static getWorkerFarm(props = {}) {
|
|
734
|
+
_WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
|
|
735
|
+
_WorkerFarm._workerFarm.setProps(props);
|
|
736
|
+
return _WorkerFarm._workerFarm;
|
|
737
|
+
}
|
|
738
|
+
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
739
|
+
constructor(props) {
|
|
740
|
+
this.props = { ...DEFAULT_PROPS };
|
|
741
|
+
this.setProps(props);
|
|
742
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Terminate all workers in the farm and abort active jobs.
|
|
746
|
+
* @param reason Optional error delivered to active jobs.
|
|
747
|
+
* @note Can free up significant memory
|
|
748
|
+
*/
|
|
749
|
+
destroy(reason) {
|
|
750
|
+
for (const workerPool of this.workerPools.values()) {
|
|
751
|
+
workerPool.destroy(reason);
|
|
752
|
+
}
|
|
753
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Set props used when initializing worker pools
|
|
757
|
+
* @param props
|
|
758
|
+
*/
|
|
759
|
+
setProps(props) {
|
|
760
|
+
this.props = { ...this.props, ...props };
|
|
761
|
+
for (const workerPool of this.workerPools.values()) {
|
|
762
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Returns a worker pool for the specified worker
|
|
767
|
+
* @param options Worker target used to identify and initialize the pool.
|
|
768
|
+
* @param options.name Worker name used as the base pool identity.
|
|
769
|
+
* @param options.url Worker script URL.
|
|
770
|
+
* @param options.source Inline worker source.
|
|
771
|
+
* @param options.loadWorker Built-in browser worker factory.
|
|
772
|
+
* @example
|
|
773
|
+
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
774
|
+
*/
|
|
775
|
+
getWorkerPool(options) {
|
|
776
|
+
const { name, source, url, getUrl, loadWorker } = options;
|
|
777
|
+
const workerPoolKey = getWorkerPoolKey(options);
|
|
778
|
+
let workerPool = this.workerPools.get(workerPoolKey);
|
|
779
|
+
if (!workerPool) {
|
|
780
|
+
workerPool = new WorkerPool({
|
|
781
|
+
name,
|
|
782
|
+
source,
|
|
783
|
+
url,
|
|
784
|
+
getUrl,
|
|
785
|
+
loadWorker
|
|
786
|
+
});
|
|
787
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
788
|
+
this.workerPools.set(workerPoolKey, workerPool);
|
|
789
|
+
}
|
|
790
|
+
return workerPool;
|
|
791
|
+
}
|
|
792
|
+
_getWorkerPoolProps() {
|
|
793
|
+
return {
|
|
794
|
+
maxConcurrency: this.props.maxConcurrency,
|
|
795
|
+
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
796
|
+
reuseWorkers: this.props.reuseWorkers,
|
|
797
|
+
onDebug: this.props.onDebug
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
function getWorkerPoolKey(options) {
|
|
802
|
+
const { name, source, url, urlKey, loadWorker } = options;
|
|
803
|
+
const sourceKey = source ? `source:${source}` : "";
|
|
804
|
+
const urlKeyPart = url || urlKey ? `url:${url || urlKey}` : "";
|
|
805
|
+
const loadWorkerKey = loadWorker ? `loadWorker:${getLoadWorkerId(loadWorker)}` : "";
|
|
806
|
+
return [name, sourceKey, urlKeyPart, loadWorkerKey].filter(Boolean).join("|");
|
|
807
|
+
}
|
|
808
|
+
function getLoadWorkerId(loadWorker) {
|
|
809
|
+
let loadWorkerId = loadWorkerIds.get(loadWorker);
|
|
810
|
+
if (!loadWorkerId) {
|
|
811
|
+
loadWorkerId = nextLoadWorkerId++;
|
|
812
|
+
loadWorkerIds.set(loadWorker, loadWorkerId);
|
|
813
|
+
}
|
|
814
|
+
return loadWorkerId;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// ../worker-utils/src/lib/async-queue/async-queue.ts
|
|
818
|
+
var AsyncQueue = class {
|
|
819
|
+
_values;
|
|
820
|
+
_settlers;
|
|
821
|
+
_closed;
|
|
822
|
+
constructor() {
|
|
823
|
+
this._values = [];
|
|
824
|
+
this._settlers = [];
|
|
825
|
+
this._closed = false;
|
|
826
|
+
}
|
|
827
|
+
/** Return an async iterator for this queue */
|
|
828
|
+
[Symbol.asyncIterator]() {
|
|
829
|
+
return this;
|
|
830
|
+
}
|
|
831
|
+
/** Push a new value - the async iterator will yield a promise resolved to this value */
|
|
832
|
+
push(value) {
|
|
833
|
+
return this.enqueue(value);
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Push a new value - the async iterator will yield a promise resolved to this value
|
|
837
|
+
* Add an error - the async iterator will yield a promise rejected with this value
|
|
838
|
+
*/
|
|
839
|
+
enqueue(value) {
|
|
840
|
+
if (this._closed) {
|
|
841
|
+
throw new Error("Closed");
|
|
842
|
+
}
|
|
843
|
+
if (this._settlers.length > 0) {
|
|
844
|
+
if (this._values.length > 0) {
|
|
845
|
+
throw new Error("Illegal internal state");
|
|
846
|
+
}
|
|
847
|
+
const settler = this._settlers.shift();
|
|
848
|
+
if (value instanceof Error) {
|
|
849
|
+
settler.reject(value);
|
|
850
|
+
} else {
|
|
851
|
+
settler.resolve({ value });
|
|
852
|
+
}
|
|
853
|
+
} else {
|
|
854
|
+
this._values.push(value);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
/** Indicate that we not waiting for more values - The async iterator will be done */
|
|
858
|
+
close() {
|
|
859
|
+
while (this._settlers.length > 0) {
|
|
860
|
+
const settler = this._settlers.shift();
|
|
861
|
+
settler.resolve({ done: true });
|
|
862
|
+
}
|
|
863
|
+
this._closed = true;
|
|
864
|
+
}
|
|
865
|
+
// ITERATOR IMPLEMENTATION
|
|
866
|
+
/** @returns a Promise for an IteratorResult */
|
|
867
|
+
next() {
|
|
868
|
+
if (this._values.length > 0) {
|
|
869
|
+
const value = this._values.shift();
|
|
870
|
+
if (value instanceof Error) {
|
|
871
|
+
return Promise.reject(value);
|
|
872
|
+
}
|
|
873
|
+
return Promise.resolve({ done: false, value });
|
|
874
|
+
}
|
|
875
|
+
if (this._closed) {
|
|
876
|
+
if (this._settlers.length > 0) {
|
|
877
|
+
throw new Error("Illegal internal state");
|
|
878
|
+
}
|
|
879
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
880
|
+
}
|
|
881
|
+
return new Promise((resolve2, reject) => {
|
|
882
|
+
this._settlers.push({ resolve: resolve2, reject });
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
|
|
887
|
+
// ../worker-utils/src/lib/worker-api/get-worker-url.ts
|
|
888
|
+
var warnedWorkerVersionFallbacks = /* @__PURE__ */ new Set();
|
|
889
|
+
function getWorkerName(worker) {
|
|
890
|
+
const warning = worker.version !== VERSION2 ? ` (worker-utils@${VERSION2})` : "";
|
|
891
|
+
return `${worker.name}@${worker.version}${warning}`;
|
|
892
|
+
}
|
|
893
|
+
function getCustomWorkerURL(worker, options = {}) {
|
|
894
|
+
var _a;
|
|
895
|
+
const workerOptions = options[worker.id] || {};
|
|
896
|
+
const workerFile = isBrowser2 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
897
|
+
let url = workerOptions.workerUrl;
|
|
898
|
+
if (!url && worker.id === "compression") {
|
|
899
|
+
url = options.workerUrl;
|
|
900
|
+
}
|
|
901
|
+
const workerType = options._workerType || ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._workerType);
|
|
902
|
+
if (!url && workerType === "test") {
|
|
903
|
+
if (isBrowser2) {
|
|
904
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
905
|
+
} else {
|
|
906
|
+
url = `modules/${worker.module}/src/workers/${worker.id}-worker-node.ts`;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return url || null;
|
|
910
|
+
}
|
|
911
|
+
function getWorkerURL(worker, options = {}) {
|
|
912
|
+
const customWorkerUrl = getCustomWorkerURL(worker, options);
|
|
913
|
+
const descriptorWorkerUrl = typeof worker.worker === "string" ? worker.worker : null;
|
|
914
|
+
const url = customWorkerUrl || descriptorWorkerUrl || getDefaultWorkerURL(worker, true);
|
|
915
|
+
assert2(url);
|
|
916
|
+
return url;
|
|
917
|
+
}
|
|
918
|
+
function getDefaultWorkerURL(worker, warn = false) {
|
|
919
|
+
const workerFile = isBrowser2 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
920
|
+
let version2 = worker.version;
|
|
921
|
+
if (version2 === "latest") {
|
|
922
|
+
version2 = NPM_TAG;
|
|
923
|
+
}
|
|
924
|
+
const versionTag = version2 ? `@${version2}` : "";
|
|
925
|
+
const url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
926
|
+
if (warn) {
|
|
927
|
+
warnIfUsingNpmTagFallback(worker, url);
|
|
928
|
+
}
|
|
929
|
+
return url;
|
|
930
|
+
}
|
|
931
|
+
function warnIfUsingNpmTagFallback(worker, url) {
|
|
932
|
+
if (worker.version !== "latest") {
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
const workerId = `${worker.module}:${worker.id}`;
|
|
936
|
+
if (warnedWorkerVersionFallbacks.has(workerId)) {
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
warnedWorkerVersionFallbacks.add(workerId);
|
|
940
|
+
console.warn(
|
|
941
|
+
`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// ../worker-utils/src/lib/worker-api/process-on-worker.ts
|
|
946
|
+
function canProcessOnWorker(worker, options) {
|
|
947
|
+
if (!WorkerFarm.isSupported()) {
|
|
948
|
+
return false;
|
|
949
|
+
}
|
|
950
|
+
const workerOptions = options == null ? void 0 : options[worker.id];
|
|
951
|
+
return Boolean(
|
|
952
|
+
(worker.worker || worker.loadWorker || (workerOptions == null ? void 0 : workerOptions.workerUrl)) && (options == null ? void 0 : options.worker)
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
async function processOnWorker(worker, data, options = {}, context = {}, jobContext = {}) {
|
|
956
|
+
var _a, _b, _c;
|
|
957
|
+
throwIfAborted(options.signal);
|
|
958
|
+
const name = getWorkerName(worker);
|
|
959
|
+
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
960
|
+
const workerPool = workerFarm.getWorkerPool(getWorkerPoolTarget(worker, options, name));
|
|
961
|
+
const jobName = options.jobName || worker.name;
|
|
962
|
+
const job = await workerPool.startJob(
|
|
963
|
+
jobName,
|
|
964
|
+
// eslint-disable-next-line
|
|
965
|
+
onMessage.bind(null, context)
|
|
966
|
+
);
|
|
967
|
+
const abortJob = () => job.abort(getAbortReason(options.signal));
|
|
968
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", abortJob, { once: true });
|
|
969
|
+
if ((_b = options.signal) == null ? void 0 : _b.aborted) {
|
|
970
|
+
abortJob();
|
|
971
|
+
}
|
|
972
|
+
try {
|
|
973
|
+
const { signal: _signal, ...workerOptions } = options;
|
|
974
|
+
const transferableOptions = getTransferListForWriter(workerOptions);
|
|
975
|
+
const transferableContext = getTransferListForWriter(jobContext);
|
|
976
|
+
if (job.isRunning) {
|
|
977
|
+
job.postMessage("process", {
|
|
978
|
+
input: data,
|
|
979
|
+
options: transferableOptions,
|
|
980
|
+
context: transferableContext
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
const result = await job.result;
|
|
984
|
+
return result.result;
|
|
985
|
+
} finally {
|
|
986
|
+
(_c = options.signal) == null ? void 0 : _c.removeEventListener("abort", abortJob);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
function processOnWorkerInBatches(worker, input, options = {}, context = {}, jobContext = {}) {
|
|
990
|
+
return processOnWorkerInBatchesIterator(worker, input, options, context, jobContext);
|
|
991
|
+
}
|
|
992
|
+
async function* processOnWorkerInBatchesIterator(worker, input, options, context, jobContext) {
|
|
993
|
+
var _a, _b, _c;
|
|
994
|
+
throwIfAborted(options.signal);
|
|
995
|
+
const name = getWorkerName(worker);
|
|
996
|
+
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
997
|
+
const workerPool = workerFarm.getWorkerPool(getWorkerPoolTarget(worker, options, name));
|
|
998
|
+
const outputBatches = new AsyncQueue();
|
|
999
|
+
const inputIterator = getAsyncIterator(input);
|
|
1000
|
+
let outputFinished = false;
|
|
1001
|
+
let inputFinished = false;
|
|
1002
|
+
let inputRequest = Promise.resolve();
|
|
1003
|
+
const batchJobFailed = new Error("Worker batch job failed");
|
|
1004
|
+
const finishOutput = () => {
|
|
1005
|
+
if (!outputFinished) {
|
|
1006
|
+
outputFinished = true;
|
|
1007
|
+
outputBatches.close();
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
const failOutput = (_error) => {
|
|
1011
|
+
if (!outputFinished) {
|
|
1012
|
+
outputFinished = true;
|
|
1013
|
+
outputBatches.enqueue(batchJobFailed);
|
|
1014
|
+
outputBatches.close();
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
const job = await workerPool.startJob(
|
|
1018
|
+
options.jobName || worker.name,
|
|
1019
|
+
(activeJob, type, payload) => {
|
|
1020
|
+
switch (type) {
|
|
1021
|
+
case "input-request":
|
|
1022
|
+
inputRequest = inputRequest.then(async () => {
|
|
1023
|
+
const nextBatch = await inputIterator.next();
|
|
1024
|
+
if (!activeJob.isRunning) {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
if (nextBatch.done) {
|
|
1028
|
+
inputFinished = true;
|
|
1029
|
+
activeJob.postMessage("input-done", {});
|
|
1030
|
+
} else {
|
|
1031
|
+
activeJob.postMessage("input-batch", { input: nextBatch.value });
|
|
1032
|
+
}
|
|
1033
|
+
}).catch((error) => activeJob.abort(error));
|
|
1034
|
+
break;
|
|
1035
|
+
case "output-batch":
|
|
1036
|
+
outputBatches.push(payload.result);
|
|
1037
|
+
break;
|
|
1038
|
+
case "done":
|
|
1039
|
+
activeJob.done(payload);
|
|
1040
|
+
finishOutput();
|
|
1041
|
+
break;
|
|
1042
|
+
case "error": {
|
|
1043
|
+
const error = new Error(payload.error || "Worker batch processing failed");
|
|
1044
|
+
activeJob.error(error);
|
|
1045
|
+
failOutput(error);
|
|
1046
|
+
break;
|
|
1047
|
+
}
|
|
1048
|
+
case "process":
|
|
1049
|
+
void onMessage(context, activeJob, type, payload);
|
|
1050
|
+
break;
|
|
1051
|
+
default: {
|
|
1052
|
+
const error = new Error(`Unexpected worker batch message: ${type}`);
|
|
1053
|
+
activeJob.error(error);
|
|
1054
|
+
failOutput(error);
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
);
|
|
1060
|
+
const abortJob = () => job.abort(getAbortReason(options.signal));
|
|
1061
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", abortJob, { once: true });
|
|
1062
|
+
if ((_b = options.signal) == null ? void 0 : _b.aborted) {
|
|
1063
|
+
abortJob();
|
|
1064
|
+
}
|
|
1065
|
+
void job.result.catch(failOutput);
|
|
1066
|
+
try {
|
|
1067
|
+
const { signal: _signal, ...workerOptions } = options;
|
|
1068
|
+
if (job.isRunning) {
|
|
1069
|
+
job.postMessage("process-in-batches", {
|
|
1070
|
+
options: getTransferListForWriter(workerOptions),
|
|
1071
|
+
context: getTransferListForWriter(jobContext)
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
try {
|
|
1075
|
+
for await (const outputBatch of outputBatches) {
|
|
1076
|
+
yield outputBatch;
|
|
1077
|
+
if (job.isRunning) {
|
|
1078
|
+
job.postMessage("output-ack", {});
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
if (error === batchJobFailed) {
|
|
1083
|
+
await job.result;
|
|
1084
|
+
}
|
|
1085
|
+
throw error;
|
|
1086
|
+
}
|
|
1087
|
+
await job.result;
|
|
1088
|
+
} finally {
|
|
1089
|
+
(_c = options.signal) == null ? void 0 : _c.removeEventListener("abort", abortJob);
|
|
1090
|
+
if (job.isRunning) {
|
|
1091
|
+
job.abort(createAbortError2("Worker batch iterator was closed"));
|
|
1092
|
+
}
|
|
1093
|
+
if (!inputFinished) {
|
|
1094
|
+
closeInputIterator(inputIterator);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
function throwIfAborted(signal) {
|
|
1099
|
+
if (!(signal == null ? void 0 : signal.aborted)) {
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
throw getAbortReason(signal);
|
|
1103
|
+
}
|
|
1104
|
+
function getAbortReason(signal) {
|
|
1105
|
+
return (signal == null ? void 0 : signal.reason) ?? createAbortError2("Worker job was aborted");
|
|
1106
|
+
}
|
|
1107
|
+
function createAbortError2(message) {
|
|
1108
|
+
const error = new Error(message);
|
|
1109
|
+
error.name = "AbortError";
|
|
1110
|
+
return error;
|
|
1111
|
+
}
|
|
1112
|
+
function getAsyncIterator(input) {
|
|
1113
|
+
if (Symbol.asyncIterator in input) {
|
|
1114
|
+
return input[Symbol.asyncIterator]();
|
|
1115
|
+
}
|
|
1116
|
+
return (async function* iterateSynchronously() {
|
|
1117
|
+
yield* input;
|
|
1118
|
+
})();
|
|
1119
|
+
}
|
|
1120
|
+
function closeInputIterator(inputIterator) {
|
|
1121
|
+
var _a;
|
|
1122
|
+
try {
|
|
1123
|
+
void Promise.resolve((_a = inputIterator.return) == null ? void 0 : _a.call(inputIterator)).catch(() => void 0);
|
|
1124
|
+
} catch {
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
function getWorkerPoolTarget(worker, options, name) {
|
|
1128
|
+
if (options.source) {
|
|
1129
|
+
return { name, source: options.source };
|
|
1130
|
+
}
|
|
1131
|
+
const customWorkerUrl = getCustomWorkerURL(worker, options);
|
|
1132
|
+
if (customWorkerUrl) {
|
|
1133
|
+
return { name, url: customWorkerUrl };
|
|
1134
|
+
}
|
|
1135
|
+
if (isBrowser2 && worker.loadWorker) {
|
|
1136
|
+
return {
|
|
1137
|
+
name,
|
|
1138
|
+
loadWorker: worker.loadWorker,
|
|
1139
|
+
getUrl: () => getWorkerURL(worker, options),
|
|
1140
|
+
urlKey: getDefaultWorkerURL(worker)
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
return { name, url: getWorkerURL(worker, options) };
|
|
1144
|
+
}
|
|
1145
|
+
async function onMessage(context, job, type, payload) {
|
|
1146
|
+
switch (type) {
|
|
1147
|
+
case "done":
|
|
1148
|
+
job.done(payload);
|
|
1149
|
+
break;
|
|
1150
|
+
case "error":
|
|
1151
|
+
job.error(new Error(payload.error));
|
|
1152
|
+
break;
|
|
1153
|
+
case "process":
|
|
1154
|
+
const { id, input, options } = payload;
|
|
1155
|
+
try {
|
|
1156
|
+
if (!context.process) {
|
|
1157
|
+
job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
const result = await context.process(input, options, void 0, payload.context || {});
|
|
1161
|
+
job.postMessage("done", { id, result });
|
|
1162
|
+
} catch (error) {
|
|
1163
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
1164
|
+
job.postMessage("error", { id, error: message });
|
|
1165
|
+
}
|
|
1166
|
+
break;
|
|
1167
|
+
default:
|
|
1168
|
+
console.warn(`process-on-worker: unknown message ${type}`);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// ../worker-utils/src/lib/worker-api/validate-worker-version.ts
|
|
1173
|
+
function validateWorkerVersion(worker, coreVersion = VERSION2) {
|
|
1174
|
+
assert2(worker, "no worker provided");
|
|
1175
|
+
const workerVersion = worker.version;
|
|
1176
|
+
if (!coreVersion || !workerVersion) {
|
|
1177
|
+
return false;
|
|
1178
|
+
}
|
|
1179
|
+
return true;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// ../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts
|
|
1183
|
+
function canParseWithWorker(loader, options) {
|
|
1184
|
+
var _a, _b, _c;
|
|
1185
|
+
if ((_b = (_a = options == null ? void 0 : options.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.some(
|
|
1186
|
+
(credential) => credential.type === "request" || "token" in credential && typeof credential.token === "function"
|
|
1187
|
+
))
|
|
1188
|
+
return false;
|
|
1189
|
+
const workerOptions = getWorkerOptions(options);
|
|
1190
|
+
const nodeWorkers = workerOptions._nodeWorkers;
|
|
1191
|
+
if (!isBrowser2 && !nodeWorkers) {
|
|
1192
|
+
return false;
|
|
1193
|
+
}
|
|
1194
|
+
if (loader.id === "las" && (((_c = options == null ? void 0 : options.las) == null ? void 0 : _c.shape) ?? "arrow-table") === "arrow-table") {
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1197
|
+
if (loader.id === "csv" && !shouldParseCSVWithWorker(options)) {
|
|
1198
|
+
return false;
|
|
1199
|
+
}
|
|
1200
|
+
return Boolean(canProcessOnWorker(loader, workerOptions));
|
|
1201
|
+
}
|
|
1202
|
+
function shouldParseWithWorker(loader, data, options, context, estimateLoader = loader) {
|
|
1203
|
+
var _a, _b;
|
|
1204
|
+
if (!canParseWithWorker(loader, options)) {
|
|
1205
|
+
return false;
|
|
1206
|
+
}
|
|
1207
|
+
if (((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.worker) !== "auto" || !estimateLoader.getWorkerEstimate) {
|
|
1208
|
+
return true;
|
|
1209
|
+
}
|
|
1210
|
+
try {
|
|
1211
|
+
const estimate = estimateLoader.getWorkerEstimate(data, options, context);
|
|
1212
|
+
if (estimate === void 0 || !Number.isFinite(estimate) || estimate < 0 || estimate > 1) {
|
|
1213
|
+
return true;
|
|
1214
|
+
}
|
|
1215
|
+
return estimate >= (((_b = options.core) == null ? void 0 : _b.workerThreshold) ?? 0.1);
|
|
1216
|
+
} catch {
|
|
1217
|
+
return true;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
async function parseWithWorker(loader, data, options, context, parseOnMainThread, signal) {
|
|
1221
|
+
const workerSignal = signal || getWorkerAbortSignal(options);
|
|
1222
|
+
const result = await processOnWorker(
|
|
1223
|
+
loader,
|
|
1224
|
+
data,
|
|
1225
|
+
{ ...getWorkerOptions(options, loader), signal: workerSignal },
|
|
1226
|
+
{
|
|
1227
|
+
process: async (input, processOptions, _workerContext, parseContext) => {
|
|
1228
|
+
if (!parseOnMainThread) {
|
|
1229
|
+
throw new Error("Worker not set up to parse on main thread");
|
|
1230
|
+
}
|
|
1231
|
+
const { _loaderIds, _loaderIsArray, ...workerParseContext } = parseContext || {};
|
|
1232
|
+
const mainThreadContext = context || parseContext ? { ...context, ...workerParseContext } : void 0;
|
|
1233
|
+
return await callParseOnMainThread(
|
|
1234
|
+
parseOnMainThread,
|
|
1235
|
+
input,
|
|
1236
|
+
processOptions,
|
|
1237
|
+
mainThreadContext,
|
|
1238
|
+
resolveWorkerLoaders(loader, _loaderIds, _loaderIsArray, context, options)
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
},
|
|
1242
|
+
getSerializableLoaderContext(context)
|
|
1243
|
+
);
|
|
1244
|
+
return isLoaderWithWorkerResultDeserializer(loader) ? loader.deserializeWorkerResult(result, options, context) : result;
|
|
1245
|
+
}
|
|
1246
|
+
async function* parseWithWorkerInBatches(loader, inputIterator, options, context, parseOnMainThread, signal) {
|
|
1247
|
+
const workerSignal = signal || getWorkerAbortSignal(options);
|
|
1248
|
+
const outputIterator = processOnWorkerInBatches(
|
|
1249
|
+
loader,
|
|
1250
|
+
inputIterator,
|
|
1251
|
+
{ ...getWorkerOptions(options), signal: workerSignal },
|
|
1252
|
+
{
|
|
1253
|
+
process: async (input, processOptions, _workerContext, parseContext) => {
|
|
1254
|
+
if (!parseOnMainThread) {
|
|
1255
|
+
throw new Error("Worker not set up to parse on main thread");
|
|
1256
|
+
}
|
|
1257
|
+
const { _loaderIds, _loaderIsArray, ...workerParseContext } = parseContext || {};
|
|
1258
|
+
const mainThreadContext = context || parseContext ? { ...context, ...workerParseContext } : void 0;
|
|
1259
|
+
return await callParseOnMainThread(
|
|
1260
|
+
parseOnMainThread,
|
|
1261
|
+
input,
|
|
1262
|
+
processOptions,
|
|
1263
|
+
mainThreadContext,
|
|
1264
|
+
resolveWorkerLoaders(loader, _loaderIds, _loaderIsArray, context, options)
|
|
1265
|
+
);
|
|
1266
|
+
}
|
|
1267
|
+
},
|
|
1268
|
+
getSerializableLoaderContext(context)
|
|
1269
|
+
);
|
|
1270
|
+
for await (const batch of outputIterator) {
|
|
1271
|
+
yield loader.deserializeWorkerBatch ? loader.deserializeWorkerBatch(batch, options, context) : batch;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
function getWorkerAbortSignal(options) {
|
|
1275
|
+
var _a;
|
|
1276
|
+
const parquetSignal = (_a = options == null ? void 0 : options.parquet) == null ? void 0 : _a.signal;
|
|
1277
|
+
if (typeof AbortSignal !== "undefined" && parquetSignal instanceof AbortSignal) {
|
|
1278
|
+
return parquetSignal;
|
|
1279
|
+
}
|
|
1280
|
+
return void 0;
|
|
1281
|
+
}
|
|
1282
|
+
function callParseOnMainThread(parseOnMainThread, input, options, context, loaders) {
|
|
1283
|
+
if (!loaders && parseOnMainThread.length <= 2) {
|
|
1284
|
+
return parseOnMainThread(input, options);
|
|
1285
|
+
}
|
|
1286
|
+
return parseOnMainThread(input, loaders, options, context);
|
|
1287
|
+
}
|
|
1288
|
+
function resolveWorkerLoaders(loader, loaderIds, loaderIsArray, context, options) {
|
|
1289
|
+
if (!loaderIds) return void 0;
|
|
1290
|
+
const availableLoaders = /* @__PURE__ */ new Map();
|
|
1291
|
+
const visitedLoaders = /* @__PURE__ */ new Set();
|
|
1292
|
+
for (const candidate of [loader, ...(context == null ? void 0 : context.loaders) || []]) {
|
|
1293
|
+
visitLoader(candidate);
|
|
1294
|
+
}
|
|
1295
|
+
const selectedLoaders = loaderIds.map((loaderId) => {
|
|
1296
|
+
const selectedLoader = availableLoaders.get(loaderId);
|
|
1297
|
+
if (!selectedLoader) {
|
|
1298
|
+
throw new Error(
|
|
1299
|
+
`Worker requested unknown loader "${loaderId}". Declare it in loader.subloaders or pass it in context.loaders.`
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
return selectedLoader;
|
|
1303
|
+
});
|
|
1304
|
+
return loaderIsArray ? selectedLoaders : selectedLoaders[0];
|
|
1305
|
+
function visitLoader(candidate) {
|
|
1306
|
+
var _a, _b;
|
|
1307
|
+
if (visitedLoaders.has(candidate)) return;
|
|
1308
|
+
visitedLoaders.add(candidate);
|
|
1309
|
+
availableLoaders.set(candidate.id, candidate);
|
|
1310
|
+
for (const [name, dependency] of Object.entries(candidate.subloaders || {})) {
|
|
1311
|
+
const replacement = ((_b = (_a = options == null ? void 0 : options.core) == null ? void 0 : _a.subloaders) == null ? void 0 : _b[name]) || dependency;
|
|
1312
|
+
visitLoader(replacement);
|
|
1313
|
+
availableLoaders.set(dependency.id, replacement);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
function getWorkerOptions(options = {}, loader) {
|
|
1318
|
+
const serializedOptions = JSON.parse(
|
|
1319
|
+
JSON.stringify({
|
|
1320
|
+
...options,
|
|
1321
|
+
...options.core ? { core: { ...options.core, authentications: void 0 } } : {}
|
|
1322
|
+
})
|
|
1323
|
+
);
|
|
1324
|
+
const workerOptions = {
|
|
1325
|
+
...serializedOptions.core,
|
|
1326
|
+
...serializedOptions
|
|
1327
|
+
};
|
|
1328
|
+
if (workerOptions.worker === "auto") {
|
|
1329
|
+
workerOptions.worker = true;
|
|
1330
|
+
}
|
|
1331
|
+
if (loader) {
|
|
1332
|
+
workerOptions._workerLoaderId = loader.id;
|
|
1333
|
+
}
|
|
1334
|
+
return workerOptions;
|
|
1335
|
+
}
|
|
1336
|
+
function getSerializableLoaderContext(context) {
|
|
1337
|
+
if (!context) {
|
|
1338
|
+
return {};
|
|
1339
|
+
}
|
|
1340
|
+
const { fetch: fetch2, loaders, coreApi: coreApi2, _parse, _parseSync, _parseInBatches, ...serializableContext } = context;
|
|
1341
|
+
return JSON.parse(JSON.stringify(serializableContext));
|
|
1342
|
+
}
|
|
1343
|
+
function shouldParseCSVWithWorker(options) {
|
|
1344
|
+
var _a, _b;
|
|
1345
|
+
const csvOptions = options;
|
|
1346
|
+
return (((_a = csvOptions == null ? void 0 : csvOptions.csv) == null ? void 0 : _a.shape) ?? ((_b = csvOptions == null ? void 0 : csvOptions.core) == null ? void 0 : _b.shape)) === "arrow-table";
|
|
1347
|
+
}
|
|
1348
|
+
function isLoaderWithWorkerResultDeserializer(loader) {
|
|
1349
|
+
return typeof loader.deserializeWorkerResult === "function";
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
// ../loader-utils/src/lib/worker-loader-utils/encode-with-worker.ts
|
|
1353
|
+
function canEncodeWithWorker(writer, options) {
|
|
1354
|
+
var _a, _b;
|
|
1355
|
+
if (!WorkerFarm.isSupported()) {
|
|
1356
|
+
return false;
|
|
1357
|
+
}
|
|
1358
|
+
const nodeWorkers = (options == null ? void 0 : options._nodeWorkers) ?? ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._nodeWorkers);
|
|
1359
|
+
const useWorkers = (options == null ? void 0 : options.worker) ?? ((_b = options == null ? void 0 : options.core) == null ? void 0 : _b.worker);
|
|
1360
|
+
if (!isBrowser && !nodeWorkers) {
|
|
1361
|
+
return false;
|
|
1362
|
+
}
|
|
1363
|
+
return Boolean(writer.worker && useWorkers);
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
|
|
1367
|
+
function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
|
|
1368
|
+
byteLength = byteLength || arrayBuffer1.byteLength;
|
|
1369
|
+
if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
|
|
1370
|
+
return false;
|
|
1371
|
+
}
|
|
1372
|
+
const array1 = new Uint8Array(arrayBuffer1);
|
|
1373
|
+
const array2 = new Uint8Array(arrayBuffer2);
|
|
1374
|
+
for (let i = 0; i < array1.length; ++i) {
|
|
1375
|
+
if (array1[i] !== array2[i]) {
|
|
1376
|
+
return false;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
return true;
|
|
1380
|
+
}
|
|
1381
|
+
function concatenateArrayBuffers(...sources) {
|
|
1382
|
+
return concatenateArrayBuffersFromArray(sources);
|
|
1383
|
+
}
|
|
1384
|
+
function concatenateArrayBuffersFromArray(sources) {
|
|
1385
|
+
const sourceArrays = sources.map(
|
|
1386
|
+
(source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
|
|
1387
|
+
);
|
|
1388
|
+
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
1389
|
+
const result = new Uint8Array(byteLength);
|
|
1390
|
+
let offset = 0;
|
|
1391
|
+
for (const sourceArray of sourceArrays) {
|
|
1392
|
+
result.set(sourceArray, offset);
|
|
1393
|
+
offset += sourceArray.byteLength;
|
|
1394
|
+
}
|
|
1395
|
+
return result.buffer;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
// ../loader-utils/src/lib/binary-utils/encode-array-buffer-to-base64.ts
|
|
1399
|
+
function encodeArrayBufferToBase64(arrayBuffer) {
|
|
1400
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
1401
|
+
const encodedChunks = [];
|
|
1402
|
+
const chunkByteLength = 3 * 4096;
|
|
1403
|
+
for (let byteOffset = 0; byteOffset < bytes.length; byteOffset += chunkByteLength) {
|
|
1404
|
+
encodedChunks.push(
|
|
1405
|
+
btoa(String.fromCharCode(...bytes.subarray(byteOffset, byteOffset + chunkByteLength)))
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
return encodedChunks.join("");
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
// ../loader-utils/src/lib/iterators/text-iterators.ts
|
|
1412
|
+
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
1413
|
+
const textDecoder = new TextDecoder(void 0, options);
|
|
1414
|
+
for await (const arrayBuffer of arrayBufferIterator) {
|
|
1415
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
async function* makeTextEncoderIterator(textIterator) {
|
|
1419
|
+
const textEncoder = new TextEncoder();
|
|
1420
|
+
for await (const text of textIterator) {
|
|
1421
|
+
yield typeof text === "string" ? textEncoder.encode(text).buffer : text;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
async function* makeLineIterator(textIterator) {
|
|
1425
|
+
let previous = "";
|
|
1426
|
+
for await (const textChunk of textIterator) {
|
|
1427
|
+
previous += textChunk;
|
|
1428
|
+
let eolIndex;
|
|
1429
|
+
eolIndex = previous.indexOf("\n");
|
|
1430
|
+
while (eolIndex >= 0) {
|
|
1431
|
+
const line = previous.slice(0, eolIndex + 1);
|
|
1432
|
+
previous = previous.slice(eolIndex + 1);
|
|
1433
|
+
yield line;
|
|
1434
|
+
eolIndex = previous.indexOf("\n");
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
if (previous.length > 0) {
|
|
1438
|
+
yield previous;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
async function* makeNumberedLineIterator(lineIterator) {
|
|
1442
|
+
let counter = 1;
|
|
1443
|
+
for await (const line of lineIterator) {
|
|
1444
|
+
yield { counter, line };
|
|
1445
|
+
counter++;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
1450
|
+
async function forEach(iterable, visitor) {
|
|
1451
|
+
const iterator = toAsyncIterator(iterable);
|
|
1452
|
+
while (true) {
|
|
1453
|
+
const { done, value } = await iterator.next();
|
|
1454
|
+
if (done) {
|
|
1455
|
+
if (iterator.return) {
|
|
1456
|
+
iterator.return();
|
|
1457
|
+
}
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
const cancel = visitor(value);
|
|
1461
|
+
if (cancel) {
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
async function concatenateArrayBuffersAsync(asyncIterator) {
|
|
1467
|
+
const arrayBuffers = [];
|
|
1468
|
+
for await (const chunk of asyncIterator) {
|
|
1469
|
+
arrayBuffers.push(copyToArrayBuffer(chunk));
|
|
1470
|
+
}
|
|
1471
|
+
return concatenateArrayBuffers(...arrayBuffers);
|
|
1472
|
+
}
|
|
1473
|
+
function copyToArrayBuffer(chunk) {
|
|
1474
|
+
if (chunk instanceof ArrayBuffer) {
|
|
1475
|
+
return chunk;
|
|
1476
|
+
}
|
|
1477
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
1478
|
+
const { buffer, byteOffset, byteLength } = chunk;
|
|
1479
|
+
return copyFromBuffer(buffer, byteOffset, byteLength);
|
|
1480
|
+
}
|
|
1481
|
+
return copyFromBuffer(chunk);
|
|
1482
|
+
}
|
|
1483
|
+
function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
1484
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
1485
|
+
const copy = new Uint8Array(view.length);
|
|
1486
|
+
copy.set(view);
|
|
1487
|
+
return copy.buffer;
|
|
1488
|
+
}
|
|
1489
|
+
function toAsyncIterator(iterable) {
|
|
1490
|
+
if (typeof iterable[Symbol.asyncIterator] === "function") {
|
|
1491
|
+
return iterable[Symbol.asyncIterator]();
|
|
1492
|
+
}
|
|
1493
|
+
if (typeof iterable[Symbol.iterator] === "function") {
|
|
1494
|
+
const iterator = iterable[Symbol.iterator]();
|
|
1495
|
+
return iteratorToAsyncIterator(iterator);
|
|
1496
|
+
}
|
|
1497
|
+
return iterable;
|
|
1498
|
+
}
|
|
1499
|
+
function iteratorToAsyncIterator(iterator) {
|
|
1500
|
+
return {
|
|
1501
|
+
next(value) {
|
|
1502
|
+
return Promise.resolve(iterator.next(value));
|
|
1503
|
+
},
|
|
1504
|
+
return(value) {
|
|
1505
|
+
if (typeof iterator.return === "function") {
|
|
1506
|
+
return Promise.resolve(iterator.return(value));
|
|
1507
|
+
}
|
|
1508
|
+
return Promise.resolve({ done: true, value });
|
|
1509
|
+
},
|
|
1510
|
+
throw(error) {
|
|
1511
|
+
if (typeof iterator.throw === "function") {
|
|
1512
|
+
return Promise.resolve(iterator.throw(error));
|
|
1513
|
+
}
|
|
1514
|
+
return Promise.reject(error);
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
85
1518
|
|
|
86
|
-
//
|
|
87
|
-
var
|
|
1519
|
+
// ../loader-utils/src/lib/request-utils/request-scheduler.ts
|
|
1520
|
+
var import_stats = require("@probe.gl/stats");
|
|
1521
|
+
var STAT_QUEUED_REQUESTS = "Queued Requests";
|
|
1522
|
+
var STAT_ACTIVE_REQUESTS = "Active Requests";
|
|
1523
|
+
var STAT_CANCELLED_REQUESTS = "Cancelled Requests";
|
|
1524
|
+
var STAT_QUEUED_REQUESTS_EVER = "Queued Requests Ever";
|
|
1525
|
+
var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
|
|
1526
|
+
var DEFAULT_PROPS2 = {
|
|
1527
|
+
id: "request-scheduler",
|
|
1528
|
+
/** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
|
|
1529
|
+
throttleRequests: true,
|
|
1530
|
+
/** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
|
|
1531
|
+
maxRequests: 6,
|
|
1532
|
+
/**
|
|
1533
|
+
* Specifies a debounce time, in milliseconds. All requests are queued, until no new requests have
|
|
1534
|
+
* been added to the queue for this amount of time.
|
|
1535
|
+
*/
|
|
1536
|
+
debounceTime: 0
|
|
1537
|
+
};
|
|
1538
|
+
var RequestScheduler = class {
|
|
1539
|
+
props;
|
|
1540
|
+
stats;
|
|
1541
|
+
activeRequestCount = 0;
|
|
1542
|
+
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
1543
|
+
requestQueue = [];
|
|
1544
|
+
requestMap = /* @__PURE__ */ new Map();
|
|
1545
|
+
/** Pending arrival debounce or next-tick refill; only new arrivals replace this timer. */
|
|
1546
|
+
updateTimer = null;
|
|
1547
|
+
constructor(props = {}) {
|
|
1548
|
+
this.props = { ...DEFAULT_PROPS2, ...props };
|
|
1549
|
+
this.stats = new import_stats.Stats({ id: this.props.id });
|
|
1550
|
+
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
1551
|
+
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
1552
|
+
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
1553
|
+
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
1554
|
+
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* Update scheduler props. Preserves active and queued requests.
|
|
1558
|
+
*/
|
|
1559
|
+
setProps(props) {
|
|
1560
|
+
if (props.throttleRequests !== void 0) {
|
|
1561
|
+
this.props.throttleRequests = props.throttleRequests;
|
|
1562
|
+
}
|
|
1563
|
+
if (props.maxRequests !== void 0) {
|
|
1564
|
+
this.props.maxRequests = props.maxRequests;
|
|
1565
|
+
}
|
|
1566
|
+
if (props.debounceTime !== void 0) {
|
|
1567
|
+
this.props.debounceTime = props.debounceTime;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Called by an application that wants to issue a request, without having it deeply queued by the browser
|
|
1572
|
+
*
|
|
1573
|
+
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
1574
|
+
* The promise resolves to an object that contains a `done` method.
|
|
1575
|
+
* When the application's request has completed (or failed), the application must call the `done` function
|
|
1576
|
+
*
|
|
1577
|
+
* @param handle
|
|
1578
|
+
* @param getPriority will be called when request "slots" open up,
|
|
1579
|
+
* allowing the caller to update priority or cancel the request
|
|
1580
|
+
* Highest priority executes first, priority < 0 cancels the request
|
|
1581
|
+
* @returns a promise
|
|
1582
|
+
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
1583
|
+
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
1584
|
+
* In this case the application should not issue the request
|
|
1585
|
+
*/
|
|
1586
|
+
scheduleRequest(handle, getPriority = () => 0) {
|
|
1587
|
+
if (!this.props.throttleRequests) {
|
|
1588
|
+
return Promise.resolve({ done: () => {
|
|
1589
|
+
} });
|
|
1590
|
+
}
|
|
1591
|
+
if (this.requestMap.has(handle)) {
|
|
1592
|
+
return this.requestMap.get(handle);
|
|
1593
|
+
}
|
|
1594
|
+
const request = { handle, priority: 0, getPriority };
|
|
1595
|
+
const promise = new Promise((resolve2) => {
|
|
1596
|
+
request.resolve = resolve2;
|
|
1597
|
+
return request;
|
|
1598
|
+
});
|
|
1599
|
+
this.requestQueue.push(request);
|
|
1600
|
+
this.requestMap.set(handle, promise);
|
|
1601
|
+
this._issueNewRequests();
|
|
1602
|
+
return promise;
|
|
1603
|
+
}
|
|
1604
|
+
// PRIVATE
|
|
1605
|
+
_issueRequest(request) {
|
|
1606
|
+
const { handle, resolve: resolve2 } = request;
|
|
1607
|
+
let isDone = false;
|
|
1608
|
+
const done = () => {
|
|
1609
|
+
if (!isDone) {
|
|
1610
|
+
isDone = true;
|
|
1611
|
+
this.requestMap.delete(handle);
|
|
1612
|
+
this.activeRequestCount--;
|
|
1613
|
+
this.scheduleRefill();
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
this.activeRequestCount++;
|
|
1617
|
+
return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
|
|
1618
|
+
}
|
|
1619
|
+
/** Refills freed slots on the next tick while preserving any pending arrival debounce. */
|
|
1620
|
+
scheduleRefill() {
|
|
1621
|
+
if (this.updateTimer !== null) {
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), 0);
|
|
1625
|
+
}
|
|
1626
|
+
/** Restarts the quiet period when a new request enters the queue. */
|
|
1627
|
+
_issueNewRequests() {
|
|
1628
|
+
if (this.updateTimer !== null) {
|
|
1629
|
+
clearTimeout(this.updateTimer);
|
|
1630
|
+
}
|
|
1631
|
+
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
|
|
1632
|
+
}
|
|
1633
|
+
/** Clears timer ownership before updating priorities and dispatching queued requests. */
|
|
1634
|
+
_issueNewRequestsAsync() {
|
|
1635
|
+
if (this.updateTimer !== null) {
|
|
1636
|
+
clearTimeout(this.updateTimer);
|
|
1637
|
+
}
|
|
1638
|
+
this.updateTimer = null;
|
|
1639
|
+
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
1640
|
+
if (freeSlots === 0) {
|
|
1641
|
+
return;
|
|
1642
|
+
}
|
|
1643
|
+
this._updateAllRequests();
|
|
1644
|
+
for (let i = 0; i < freeSlots; ++i) {
|
|
1645
|
+
const request = this.requestQueue.shift();
|
|
1646
|
+
if (request) {
|
|
1647
|
+
this._issueRequest(request);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
1652
|
+
_updateAllRequests() {
|
|
1653
|
+
const requestQueue = this.requestQueue;
|
|
1654
|
+
for (let i = 0; i < requestQueue.length; ++i) {
|
|
1655
|
+
const request = requestQueue[i];
|
|
1656
|
+
if (!this._updateRequest(request)) {
|
|
1657
|
+
requestQueue.splice(i, 1);
|
|
1658
|
+
this.requestMap.delete(request.handle);
|
|
1659
|
+
i--;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
1663
|
+
}
|
|
1664
|
+
/** Update a single request by calling the callback */
|
|
1665
|
+
_updateRequest(request) {
|
|
1666
|
+
request.priority = request.getPriority(request.handle);
|
|
1667
|
+
if (request.priority < 0) {
|
|
1668
|
+
request.resolve(null);
|
|
1669
|
+
return false;
|
|
1670
|
+
}
|
|
1671
|
+
return true;
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
|
|
1675
|
+
// ../loader-utils/src/lib/request-utils/authentication.ts
|
|
1676
|
+
function resolveCredentials(credentials, authentications = []) {
|
|
1677
|
+
if (credentials.every(isAuthentication)) return credentials;
|
|
1678
|
+
return credentials.map((credential, index) => {
|
|
1679
|
+
if (isAuthentication(credential)) return credential;
|
|
1680
|
+
const AuthenticationClass = authentications.find(
|
|
1681
|
+
(authentication2) => authentication2.type === (credential == null ? void 0 : credential.type)
|
|
1682
|
+
);
|
|
1683
|
+
if (!AuthenticationClass) {
|
|
1684
|
+
throw new Error(`No authentication class registered for credential at index ${index}.`);
|
|
1685
|
+
}
|
|
1686
|
+
let authentication;
|
|
1687
|
+
try {
|
|
1688
|
+
authentication = new AuthenticationClass(credential);
|
|
1689
|
+
} catch {
|
|
1690
|
+
throw new Error(`Invalid authentication configuration at index ${index}.`);
|
|
1691
|
+
}
|
|
1692
|
+
if (!isAuthentication(authentication)) {
|
|
1693
|
+
throw new Error(`Authentication class returned an invalid credential at index ${index}.`);
|
|
1694
|
+
}
|
|
1695
|
+
return authentication;
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
function resolveAuthenticationOptions(options) {
|
|
1699
|
+
var _a, _b;
|
|
1700
|
+
if (!((_b = (_a = options.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length)) return options;
|
|
1701
|
+
const credentials = resolveCredentials(options.core.credentials, options.core.authentications);
|
|
1702
|
+
if (credentials === options.core.credentials) return options;
|
|
1703
|
+
return { ...options, core: { ...options.core, credentials } };
|
|
1704
|
+
}
|
|
1705
|
+
async function resolveLoaderAuthenticationOptions(loader, url, options) {
|
|
1706
|
+
var _a, _b, _c, _d;
|
|
1707
|
+
if (!((_b = (_a = options.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) || options.core.credentials.every(isAuthentication)) {
|
|
1708
|
+
return options;
|
|
1709
|
+
}
|
|
1710
|
+
const contributions = await ((_c = loader == null ? void 0 : loader.getAuthentications) == null ? void 0 : _c.call(loader, url, options));
|
|
1711
|
+
if (!(contributions == null ? void 0 : contributions.length)) return resolveAuthenticationOptions(options);
|
|
1712
|
+
return resolveAuthenticationOptions({
|
|
1713
|
+
...options,
|
|
1714
|
+
core: {
|
|
1715
|
+
...options.core,
|
|
1716
|
+
authentications: [...((_d = options.core) == null ? void 0 : _d.authentications) || [], ...contributions]
|
|
1717
|
+
}
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
function isAuthentication(credential) {
|
|
1721
|
+
if (!credential || typeof credential !== "object") return false;
|
|
1722
|
+
if (typeof credential.id !== "string" || !Array.isArray(credential.origins)) return false;
|
|
1723
|
+
if (credential.type === "request") return typeof credential.authenticate === "function";
|
|
1724
|
+
return (credential.type === "header" || credential.type === "query-parameter") && typeof credential.name === "string" && (typeof credential.token === "string" || typeof credential.token === "function") && Array.isArray(credential.refreshStatusCodes);
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
// ../loader-utils/src/lib/request-utils/request-credentials.ts
|
|
1728
|
+
var AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
|
|
1729
|
+
var refreshPromises = /* @__PURE__ */ new WeakMap();
|
|
1730
|
+
function createAuthenticatedFetch(options) {
|
|
1731
|
+
const suppliedFetch = options.fetch || ((url, requestOptions) => fetch(url, requestOptions));
|
|
1732
|
+
const existingMetadata = suppliedFetch[AUTHENTICATED_FETCH];
|
|
1733
|
+
const credentialResolutions = new Map(existingMetadata == null ? void 0 : existingMetadata.credentialResolutions);
|
|
1734
|
+
const resolvedCredentials = resolveCredentials(
|
|
1735
|
+
options.credentials.map((credential) => credentialResolutions.get(credential) || credential),
|
|
1736
|
+
options.authentications
|
|
1737
|
+
);
|
|
1738
|
+
options.credentials.forEach((credential, index) => {
|
|
1739
|
+
credentialResolutions.set(credential, resolvedCredentials[index]);
|
|
1740
|
+
});
|
|
1741
|
+
if (!options.fetchOptions && (!resolvedCredentials.length || (existingMetadata == null ? void 0 : existingMetadata.credentials.length) === resolvedCredentials.length && resolvedCredentials.every(
|
|
1742
|
+
(credential, index) => credential === existingMetadata.credentials[index]
|
|
1743
|
+
)))
|
|
1744
|
+
return suppliedFetch;
|
|
1745
|
+
const baseFetch = (existingMetadata == null ? void 0 : existingMetadata.fetch) || suppliedFetch;
|
|
1746
|
+
const credentials = existingMetadata ? [.../* @__PURE__ */ new Set([...resolvedCredentials, ...existingMetadata.credentials])] : resolvedCredentials;
|
|
1747
|
+
const fetchOptions = mergeFetchOptions(
|
|
1748
|
+
(existingMetadata == null ? void 0 : existingMetadata.fetchOptions) || {},
|
|
1749
|
+
options.fetchOptions
|
|
1750
|
+
);
|
|
1751
|
+
const tokenCredentials = credentials.filter(
|
|
1752
|
+
(credential) => credential.type !== "request"
|
|
1753
|
+
);
|
|
1754
|
+
const requestCredentials = credentials.filter(
|
|
1755
|
+
(credential) => credential.type === "request"
|
|
1756
|
+
);
|
|
1757
|
+
for (const credential of requestCredentials) normalizeRequestOrigins(credential.origins);
|
|
1758
|
+
const authenticatedFetch = async (url, requestOptions = {}) => {
|
|
1759
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1760
|
+
requestOptions = mergeFetchOptions(fetchOptions, requestOptions);
|
|
1761
|
+
if ((_a = requestOptions.signal) == null ? void 0 : _a.aborted) throw createAbortError3();
|
|
1762
|
+
if (!credentials.length) return baseFetch(url, requestOptions);
|
|
1763
|
+
const resolvedURL = parseHTTPURL(url);
|
|
1764
|
+
const authorization = resolvedURL ? await authorizeRequest(resolvedURL, requestOptions, tokenCredentials) : { url, options: requestOptions, credentials: [] };
|
|
1765
|
+
const signedRequest = await authenticateRequest(authorization, requestCredentials, "request");
|
|
1766
|
+
const response = await baseFetch(signedRequest.url, signedRequest.options);
|
|
1767
|
+
const refreshableCredentials = [];
|
|
1768
|
+
for (const resolvedCredential of authorization.credentials) {
|
|
1769
|
+
const { credential } = resolvedCredential;
|
|
1770
|
+
if (typeof credential.token === "function" && (isReplayableRequest(requestOptions) || ((_b = credential.canReplayRequest) == null ? void 0 : _b.call(credential, url, requestOptions))) && (isReplayableRequest(signedRequest.options) || ((_c = credential.canReplayRequest) == null ? void 0 : _c.call(credential, signedRequest.url, signedRequest.options))) && (credential.refreshStatusCodes.includes(response.status) || await ((_d = credential.shouldRefresh) == null ? void 0 : _d.call(credential, response))))
|
|
1771
|
+
refreshableCredentials.push(resolvedCredential);
|
|
1772
|
+
}
|
|
1773
|
+
const shouldRetrySignature = isReplayableRequest(requestOptions) && isReplayableRequest(signedRequest.options) && signedRequest.credentials.some(
|
|
1774
|
+
(credential) => {
|
|
1775
|
+
var _a2;
|
|
1776
|
+
return (_a2 = credential.refreshStatusCodes) == null ? void 0 : _a2.includes(response.status);
|
|
1777
|
+
}
|
|
1778
|
+
);
|
|
1779
|
+
if (!refreshableCredentials.length && !shouldRetrySignature) return response;
|
|
1780
|
+
if ((_e = requestOptions.signal) == null ? void 0 : _e.aborted) throw createAbortError3();
|
|
1781
|
+
const refreshedTokens = /* @__PURE__ */ new Map();
|
|
1782
|
+
await Promise.all(
|
|
1783
|
+
refreshableCredentials.map(async ({ credential }) => {
|
|
1784
|
+
const token = await refreshCredential(credential, url, response);
|
|
1785
|
+
if (token) refreshedTokens.set(credential, token);
|
|
1786
|
+
})
|
|
1787
|
+
);
|
|
1788
|
+
if (!refreshedTokens.size && !shouldRetrySignature) return response;
|
|
1789
|
+
await ((_f = response.body) == null ? void 0 : _f.cancel().catch(() => {
|
|
1790
|
+
}));
|
|
1791
|
+
if ((_g = requestOptions.signal) == null ? void 0 : _g.aborted) throw createAbortError3();
|
|
1792
|
+
const replayAuthorization = resolvedURL ? await authorizeRequest(
|
|
1793
|
+
resolvedURL,
|
|
1794
|
+
requestOptions,
|
|
1795
|
+
tokenCredentials,
|
|
1796
|
+
refreshedTokens,
|
|
1797
|
+
authorization.credentials
|
|
1798
|
+
) : { url, options: requestOptions };
|
|
1799
|
+
const replayRequest = await authenticateRequest(
|
|
1800
|
+
replayAuthorization,
|
|
1801
|
+
requestCredentials,
|
|
1802
|
+
"retry",
|
|
1803
|
+
response
|
|
1804
|
+
);
|
|
1805
|
+
return baseFetch(replayRequest.url, replayRequest.options);
|
|
1806
|
+
};
|
|
1807
|
+
Object.defineProperty(authenticatedFetch, AUTHENTICATED_FETCH, {
|
|
1808
|
+
value: {
|
|
1809
|
+
fetch: baseFetch,
|
|
1810
|
+
credentials,
|
|
1811
|
+
credentialResolutions,
|
|
1812
|
+
fetchOptions
|
|
1813
|
+
}
|
|
1814
|
+
});
|
|
1815
|
+
return authenticatedFetch;
|
|
1816
|
+
}
|
|
1817
|
+
function mergeFetchOptions(defaultOptions, requestOptions) {
|
|
1818
|
+
const mergedOptions = { ...defaultOptions, ...requestOptions };
|
|
1819
|
+
if (defaultOptions.headers || (requestOptions == null ? void 0 : requestOptions.headers)) {
|
|
1820
|
+
const headers = new Headers(defaultOptions.headers);
|
|
1821
|
+
new Headers(requestOptions == null ? void 0 : requestOptions.headers).forEach((value, key) => headers.set(key, value));
|
|
1822
|
+
mergedOptions.headers = headers;
|
|
1823
|
+
}
|
|
1824
|
+
return mergedOptions;
|
|
1825
|
+
}
|
|
1826
|
+
async function authenticateRequest(request, credentials, reason, response) {
|
|
1827
|
+
const appliedCredentials = [];
|
|
1828
|
+
const signal = request.options.signal;
|
|
1829
|
+
for (const credential of credentials) {
|
|
1830
|
+
const origin = getRequestOrigin(request.url);
|
|
1831
|
+
if (!origin || !normalizeRequestOrigins(credential.origins).includes(origin)) continue;
|
|
1832
|
+
if (signal == null ? void 0 : signal.aborted) throw createAbortError3();
|
|
1833
|
+
const authenticatedRequest = await credential.authenticate({
|
|
1834
|
+
url: request.url,
|
|
1835
|
+
options: { ...request.options, headers: new Headers(request.options.headers) },
|
|
1836
|
+
reason,
|
|
1837
|
+
response: response ? { status: response.status, headers: new Headers(response.headers) } : void 0
|
|
1838
|
+
});
|
|
1839
|
+
if (!authenticatedRequest || typeof authenticatedRequest.url !== "string" || !authenticatedRequest.options || typeof authenticatedRequest.options !== "object") {
|
|
1840
|
+
throw new Error("Authentication callback returned an invalid request.");
|
|
1841
|
+
}
|
|
1842
|
+
request = {
|
|
1843
|
+
url: authenticatedRequest.url,
|
|
1844
|
+
options: { ...authenticatedRequest.options, ...signal ? { signal } : {} }
|
|
1845
|
+
};
|
|
1846
|
+
appliedCredentials.push(credential);
|
|
1847
|
+
}
|
|
1848
|
+
if (signal == null ? void 0 : signal.aborted) throw createAbortError3();
|
|
1849
|
+
return { ...request, credentials: appliedCredentials };
|
|
1850
|
+
}
|
|
1851
|
+
function getRequestOrigin(url) {
|
|
1852
|
+
try {
|
|
1853
|
+
const parsedURL = new URL(url);
|
|
1854
|
+
if (!parsedURL.host || parsedURL.username || parsedURL.password) return null;
|
|
1855
|
+
return parsedURL.origin !== "null" ? parsedURL.origin : `${parsedURL.protocol}//${parsedURL.host}`;
|
|
1856
|
+
} catch {
|
|
1857
|
+
return null;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
function normalizeRequestOrigins(origins) {
|
|
1861
|
+
if (!origins.length)
|
|
1862
|
+
throw new Error("Request authentication requires at least one exact origin.");
|
|
1863
|
+
return origins.map((origin) => {
|
|
1864
|
+
const resolvedOrigin = getRequestOrigin(origin);
|
|
1865
|
+
let url;
|
|
1866
|
+
try {
|
|
1867
|
+
url = new URL(origin);
|
|
1868
|
+
} catch {
|
|
1869
|
+
throw new Error("Invalid request authentication origin.");
|
|
1870
|
+
}
|
|
1871
|
+
if (!resolvedOrigin || url.pathname && url.pathname !== "/" || url.search || url.hash) {
|
|
1872
|
+
throw new Error("Invalid request authentication origin.");
|
|
1873
|
+
}
|
|
1874
|
+
return resolvedOrigin;
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
async function authorizeRequest(sourceURL, requestOptions, credentials, tokenOverrides = /* @__PURE__ */ new Map(), previousCredentials = []) {
|
|
1878
|
+
const url = new URL(sourceURL);
|
|
1879
|
+
const headers = new Headers(requestOptions.headers);
|
|
1880
|
+
const resolvedCredentials = [];
|
|
1881
|
+
const previousTokens = new Map(
|
|
1882
|
+
previousCredentials.map(({ credential, token }) => [credential, token])
|
|
1883
|
+
);
|
|
1884
|
+
for (const credential of credentials) {
|
|
1885
|
+
if (!credential.origins.includes(url.origin)) continue;
|
|
1886
|
+
const overrideToken = tokenOverrides.get(credential);
|
|
1887
|
+
const previousToken = previousTokens.get(credential);
|
|
1888
|
+
const ownsQueryParameter = credential.type === "query-parameter" && previousToken !== void 0;
|
|
1889
|
+
const ownsHeader = credential.type === "header" && previousToken !== void 0;
|
|
1890
|
+
if (credential.type === "query-parameter" && url.searchParams.has(credential.name) && !ownsQueryParameter || credential.type === "header" && headers.has(credential.name) && !ownsHeader) {
|
|
1891
|
+
continue;
|
|
1892
|
+
}
|
|
1893
|
+
const token = overrideToken ?? previousToken ?? await resolveToken(credential.token, { url: sourceURL.toString(), reason: "request" });
|
|
1894
|
+
if (!token) continue;
|
|
1895
|
+
if (credential.type === "query-parameter") {
|
|
1896
|
+
url.searchParams.set(credential.name, token);
|
|
1897
|
+
} else {
|
|
1898
|
+
headers.set(credential.name, `${credential.prefix || ""}${token}`);
|
|
1899
|
+
}
|
|
1900
|
+
resolvedCredentials.push({ credential, token });
|
|
1901
|
+
}
|
|
1902
|
+
return {
|
|
1903
|
+
url: url.toString(),
|
|
1904
|
+
options: { ...requestOptions, headers },
|
|
1905
|
+
credentials: resolvedCredentials
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
async function refreshCredential(credential, url, response) {
|
|
1909
|
+
const existingPromise = refreshPromises.get(credential);
|
|
1910
|
+
if (existingPromise) return existingPromise;
|
|
1911
|
+
const tokenProvider = credential.token;
|
|
1912
|
+
const promise = Promise.resolve(
|
|
1913
|
+
tokenProvider({
|
|
1914
|
+
url,
|
|
1915
|
+
reason: "refresh",
|
|
1916
|
+
response: { status: response.status, headers: response.headers }
|
|
1917
|
+
})
|
|
1918
|
+
).finally(() => refreshPromises.delete(credential));
|
|
1919
|
+
refreshPromises.set(credential, promise);
|
|
1920
|
+
return promise;
|
|
1921
|
+
}
|
|
1922
|
+
async function resolveToken(token, context) {
|
|
1923
|
+
return typeof token === "function" ? token(context) : token;
|
|
1924
|
+
}
|
|
1925
|
+
function parseHTTPURL(url) {
|
|
1926
|
+
try {
|
|
1927
|
+
const parsedURL = new URL(url);
|
|
1928
|
+
return ["http:", "https:"].includes(parsedURL.protocol) ? parsedURL : null;
|
|
1929
|
+
} catch {
|
|
1930
|
+
return null;
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
function isReplayableRequest(options) {
|
|
1934
|
+
const method = (options.method || "GET").toUpperCase();
|
|
1935
|
+
if (!["GET", "HEAD", "OPTIONS", "PUT", "DELETE"].includes(method)) return false;
|
|
1936
|
+
return !(options.body && typeof ReadableStream !== "undefined" && options.body instanceof ReadableStream);
|
|
1937
|
+
}
|
|
1938
|
+
function createAbortError3() {
|
|
1939
|
+
return new DOMException("The operation was aborted.", "AbortError");
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
// ../loader-utils/src/lib/path-utils/file-aliases.ts
|
|
1943
|
+
var pathPrefix = "";
|
|
1944
|
+
var fileAliases = {};
|
|
1945
|
+
function setPathPrefix(prefix) {
|
|
1946
|
+
pathPrefix = prefix;
|
|
1947
|
+
}
|
|
1948
|
+
function getPathPrefix() {
|
|
1949
|
+
return pathPrefix;
|
|
1950
|
+
}
|
|
1951
|
+
function resolvePath(filename2) {
|
|
1952
|
+
for (const alias in fileAliases) {
|
|
1953
|
+
if (filename2.startsWith(alias)) {
|
|
1954
|
+
const replacement = fileAliases[alias];
|
|
1955
|
+
filename2 = filename2.replace(alias, replacement);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
if (!filename2.startsWith("http://") && !filename2.startsWith("https://")) {
|
|
1959
|
+
filename2 = `${pathPrefix}${filename2}`;
|
|
1960
|
+
}
|
|
1961
|
+
return filename2;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
// ../loader-utils/src/lib/path-utils/path.ts
|
|
1965
|
+
var path_exports = {};
|
|
1966
|
+
__export(path_exports, {
|
|
1967
|
+
dirname: () => dirname,
|
|
1968
|
+
filename: () => filename,
|
|
1969
|
+
join: () => join,
|
|
1970
|
+
resolve: () => resolve
|
|
1971
|
+
});
|
|
1972
|
+
|
|
1973
|
+
// ../loader-utils/src/lib/path-utils/get-cwd.ts
|
|
1974
|
+
function getCWD() {
|
|
1975
|
+
var _a;
|
|
1976
|
+
if (typeof process !== "undefined" && typeof process.cwd !== "undefined") {
|
|
1977
|
+
return process.cwd();
|
|
1978
|
+
}
|
|
1979
|
+
const pathname = (_a = globalThis.location) == null ? void 0 : _a.pathname;
|
|
1980
|
+
return (pathname == null ? void 0 : pathname.slice(0, pathname.lastIndexOf("/") + 1)) || "";
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
// ../loader-utils/src/lib/path-utils/path.ts
|
|
1984
|
+
function filename(url) {
|
|
1985
|
+
const slashIndex = url ? url.lastIndexOf("/") : -1;
|
|
1986
|
+
return slashIndex >= 0 ? url.substr(slashIndex + 1) : url;
|
|
1987
|
+
}
|
|
1988
|
+
function dirname(url) {
|
|
1989
|
+
const slashIndex = url ? url.lastIndexOf("/") : -1;
|
|
1990
|
+
return slashIndex >= 0 ? url.substr(0, slashIndex) : "";
|
|
1991
|
+
}
|
|
1992
|
+
function join(...parts) {
|
|
1993
|
+
const separator = "/";
|
|
1994
|
+
parts = parts.map((part, index) => {
|
|
1995
|
+
if (index) {
|
|
1996
|
+
part = part.replace(new RegExp(`^${separator}`), "");
|
|
1997
|
+
}
|
|
1998
|
+
if (index !== parts.length - 1) {
|
|
1999
|
+
part = part.replace(new RegExp(`${separator}$`), "");
|
|
2000
|
+
}
|
|
2001
|
+
return part;
|
|
2002
|
+
});
|
|
2003
|
+
return parts.join(separator);
|
|
2004
|
+
}
|
|
2005
|
+
function resolve(...components) {
|
|
2006
|
+
const paths = [];
|
|
2007
|
+
for (let _i = 0; _i < components.length; _i++) {
|
|
2008
|
+
paths[_i] = components[_i];
|
|
2009
|
+
}
|
|
2010
|
+
let resolvedPath = "";
|
|
2011
|
+
let resolvedAbsolute = false;
|
|
2012
|
+
let cwd;
|
|
2013
|
+
for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
2014
|
+
let path;
|
|
2015
|
+
if (i >= 0) {
|
|
2016
|
+
path = paths[i];
|
|
2017
|
+
} else {
|
|
2018
|
+
if (cwd === void 0) {
|
|
2019
|
+
cwd = getCWD();
|
|
2020
|
+
}
|
|
2021
|
+
path = cwd;
|
|
2022
|
+
}
|
|
2023
|
+
if (path.length === 0) {
|
|
2024
|
+
continue;
|
|
2025
|
+
}
|
|
2026
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
2027
|
+
resolvedAbsolute = path.charCodeAt(0) === SLASH;
|
|
2028
|
+
}
|
|
2029
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
2030
|
+
if (resolvedAbsolute) {
|
|
2031
|
+
return `/${resolvedPath}`;
|
|
2032
|
+
} else if (resolvedPath.length > 0) {
|
|
2033
|
+
return resolvedPath;
|
|
2034
|
+
}
|
|
2035
|
+
return ".";
|
|
2036
|
+
}
|
|
2037
|
+
var SLASH = 47;
|
|
2038
|
+
var DOT = 46;
|
|
2039
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
2040
|
+
let res = "";
|
|
2041
|
+
let lastSlash = -1;
|
|
2042
|
+
let dots = 0;
|
|
2043
|
+
let code;
|
|
2044
|
+
let isAboveRoot = false;
|
|
2045
|
+
for (let i = 0; i <= path.length; ++i) {
|
|
2046
|
+
if (i < path.length) {
|
|
2047
|
+
code = path.charCodeAt(i);
|
|
2048
|
+
} else if (code === SLASH) {
|
|
2049
|
+
break;
|
|
2050
|
+
} else {
|
|
2051
|
+
code = SLASH;
|
|
2052
|
+
}
|
|
2053
|
+
if (code === SLASH) {
|
|
2054
|
+
if (lastSlash === i - 1 || dots === 1) {
|
|
2055
|
+
} else if (lastSlash !== i - 1 && dots === 2) {
|
|
2056
|
+
if (res.length < 2 || !isAboveRoot || res.charCodeAt(res.length - 1) !== DOT || res.charCodeAt(res.length - 2) !== DOT) {
|
|
2057
|
+
if (res.length > 2) {
|
|
2058
|
+
const start = res.length - 1;
|
|
2059
|
+
let j = start;
|
|
2060
|
+
for (; j >= 0; --j) {
|
|
2061
|
+
if (res.charCodeAt(j) === SLASH) {
|
|
2062
|
+
break;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
if (j !== start) {
|
|
2066
|
+
res = j === -1 ? "" : res.slice(0, j);
|
|
2067
|
+
lastSlash = i;
|
|
2068
|
+
dots = 0;
|
|
2069
|
+
isAboveRoot = false;
|
|
2070
|
+
continue;
|
|
2071
|
+
}
|
|
2072
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
2073
|
+
res = "";
|
|
2074
|
+
lastSlash = i;
|
|
2075
|
+
dots = 0;
|
|
2076
|
+
isAboveRoot = false;
|
|
2077
|
+
continue;
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
if (allowAboveRoot) {
|
|
2081
|
+
if (res.length > 0) {
|
|
2082
|
+
res += "/..";
|
|
2083
|
+
} else {
|
|
2084
|
+
res = "..";
|
|
2085
|
+
}
|
|
2086
|
+
isAboveRoot = true;
|
|
2087
|
+
}
|
|
2088
|
+
} else {
|
|
2089
|
+
const slice = path.slice(lastSlash + 1, i);
|
|
2090
|
+
if (res.length > 0) {
|
|
2091
|
+
res += `/${slice}`;
|
|
2092
|
+
} else {
|
|
2093
|
+
res = slice;
|
|
2094
|
+
}
|
|
2095
|
+
isAboveRoot = false;
|
|
2096
|
+
}
|
|
2097
|
+
lastSlash = i;
|
|
2098
|
+
dots = 0;
|
|
2099
|
+
} else if (code === DOT && dots !== -1) {
|
|
2100
|
+
++dots;
|
|
2101
|
+
} else {
|
|
2102
|
+
dots = -1;
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
return res;
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
// ../loader-utils/src/json-loader.ts
|
|
2109
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2110
|
+
var JSONLoader = {
|
|
2111
|
+
dataType: null,
|
|
2112
|
+
batchType: null,
|
|
2113
|
+
name: "JSON",
|
|
2114
|
+
id: "json",
|
|
2115
|
+
module: "json",
|
|
2116
|
+
version: VERSION3,
|
|
2117
|
+
encoding: "json",
|
|
2118
|
+
format: "json",
|
|
2119
|
+
extensions: ["json", "geojson"],
|
|
2120
|
+
mimeTypes: ["application/json"],
|
|
2121
|
+
category: "json",
|
|
2122
|
+
text: true,
|
|
2123
|
+
parseTextSync,
|
|
2124
|
+
parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
|
|
2125
|
+
options: {}
|
|
2126
|
+
};
|
|
2127
|
+
function parseTextSync(text) {
|
|
2128
|
+
return JSON.parse(text);
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
// ../loader-utils/src/lib/node/buffer.browser.ts
|
|
2132
|
+
function toArrayBuffer(buffer) {
|
|
2133
|
+
return buffer;
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
// ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
|
|
2137
|
+
function isBuffer(value) {
|
|
2138
|
+
return value && typeof value === "object" && value.isBuffer;
|
|
2139
|
+
}
|
|
2140
|
+
function toArrayBuffer2(data) {
|
|
2141
|
+
if (isBuffer(data)) {
|
|
2142
|
+
return toArrayBuffer(data);
|
|
2143
|
+
}
|
|
2144
|
+
if (data instanceof ArrayBuffer) {
|
|
2145
|
+
return data;
|
|
2146
|
+
}
|
|
2147
|
+
if (isSharedArrayBuffer(data)) {
|
|
2148
|
+
return copyToArrayBuffer2(data);
|
|
2149
|
+
}
|
|
2150
|
+
if (ArrayBuffer.isView(data)) {
|
|
2151
|
+
const buffer = data.buffer;
|
|
2152
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
2153
|
+
return buffer;
|
|
2154
|
+
}
|
|
2155
|
+
return buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
2156
|
+
}
|
|
2157
|
+
if (typeof data === "string") {
|
|
2158
|
+
const text = data;
|
|
2159
|
+
const uint8Array = new TextEncoder().encode(text);
|
|
2160
|
+
return uint8Array.buffer;
|
|
2161
|
+
}
|
|
2162
|
+
if (data && typeof data === "object" && data._toArrayBuffer) {
|
|
2163
|
+
return data._toArrayBuffer();
|
|
2164
|
+
}
|
|
2165
|
+
throw new Error("toArrayBuffer");
|
|
2166
|
+
}
|
|
2167
|
+
function ensureArrayBuffer(bufferSource) {
|
|
2168
|
+
if (bufferSource instanceof ArrayBuffer) {
|
|
2169
|
+
return bufferSource;
|
|
2170
|
+
}
|
|
2171
|
+
if (isSharedArrayBuffer(bufferSource)) {
|
|
2172
|
+
return copyToArrayBuffer2(bufferSource);
|
|
2173
|
+
}
|
|
2174
|
+
const { buffer, byteOffset, byteLength } = bufferSource;
|
|
2175
|
+
if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
|
|
2176
|
+
return buffer;
|
|
2177
|
+
}
|
|
2178
|
+
return copyToArrayBuffer2(buffer, byteOffset, byteLength);
|
|
2179
|
+
}
|
|
2180
|
+
function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
2181
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
2182
|
+
const copy = new Uint8Array(view.length);
|
|
2183
|
+
copy.set(view);
|
|
2184
|
+
return copy.buffer;
|
|
2185
|
+
}
|
|
2186
|
+
function toArrayBufferView(data) {
|
|
2187
|
+
if (ArrayBuffer.isView(data)) {
|
|
2188
|
+
return data;
|
|
2189
|
+
}
|
|
2190
|
+
return new Uint8Array(data);
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
// ../loader-utils/src/lib/files/blob-file.ts
|
|
2194
|
+
var BlobFile = class {
|
|
2195
|
+
handle;
|
|
2196
|
+
size;
|
|
2197
|
+
bigsize;
|
|
2198
|
+
url;
|
|
2199
|
+
constructor(blob) {
|
|
2200
|
+
this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
|
|
2201
|
+
this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
|
|
2202
|
+
this.bigsize = BigInt(this.size);
|
|
2203
|
+
this.url = blob instanceof File ? blob.name : "";
|
|
2204
|
+
}
|
|
2205
|
+
async close() {
|
|
2206
|
+
}
|
|
2207
|
+
async stat() {
|
|
2208
|
+
return {
|
|
2209
|
+
size: this.handle.size,
|
|
2210
|
+
bigsize: BigInt(this.handle.size),
|
|
2211
|
+
isDirectory: false
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
async read(start, length, signal) {
|
|
2215
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
2216
|
+
throw new Error("Request aborted");
|
|
2217
|
+
}
|
|
2218
|
+
const arrayBuffer = await this.handle.slice(Number(start), Number(start) + Number(length)).arrayBuffer();
|
|
2219
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
2220
|
+
throw new Error("Request aborted");
|
|
2221
|
+
}
|
|
2222
|
+
return arrayBuffer;
|
|
2223
|
+
}
|
|
2224
|
+
};
|
|
2225
|
+
|
|
2226
|
+
// ../loader-utils/src/lib/files/node-file-facade.ts
|
|
2227
|
+
var NOT_IMPLEMENTED = new Error("Not implemented");
|
|
2228
|
+
var NodeFileFacade = class {
|
|
2229
|
+
handle;
|
|
2230
|
+
size = 0;
|
|
2231
|
+
bigsize = 0n;
|
|
2232
|
+
url = "";
|
|
2233
|
+
constructor(url, flags, mode) {
|
|
2234
|
+
var _a;
|
|
2235
|
+
if ((_a = globalThis.loaders) == null ? void 0 : _a.NodeFile) {
|
|
2236
|
+
return new globalThis.loaders.NodeFile(url, flags, mode);
|
|
2237
|
+
}
|
|
2238
|
+
if (isBrowser) {
|
|
2239
|
+
throw new Error("Can't instantiate NodeFile in browser.");
|
|
2240
|
+
}
|
|
2241
|
+
throw new Error("Can't instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.");
|
|
2242
|
+
}
|
|
2243
|
+
/** Read data */
|
|
2244
|
+
async read(start, length) {
|
|
2245
|
+
throw NOT_IMPLEMENTED;
|
|
2246
|
+
}
|
|
2247
|
+
/** Write to file. The number of bytes written will be returned */
|
|
2248
|
+
async write(arrayBuffer, offset, length) {
|
|
2249
|
+
throw NOT_IMPLEMENTED;
|
|
2250
|
+
}
|
|
2251
|
+
/** Get information about file */
|
|
2252
|
+
async stat() {
|
|
2253
|
+
throw NOT_IMPLEMENTED;
|
|
2254
|
+
}
|
|
2255
|
+
/** Truncates the file descriptor. Only available on NodeFile. */
|
|
2256
|
+
async truncate(length) {
|
|
2257
|
+
throw NOT_IMPLEMENTED;
|
|
2258
|
+
}
|
|
2259
|
+
/** Append data to a file. Only available on NodeFile. */
|
|
2260
|
+
async append(data) {
|
|
2261
|
+
throw NOT_IMPLEMENTED;
|
|
2262
|
+
}
|
|
2263
|
+
/** Close the file */
|
|
2264
|
+
async close() {
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
|
|
2268
|
+
// ../loader-utils/src/source-types.ts
|
|
2269
|
+
function isSourceLoader(loader) {
|
|
2270
|
+
return Boolean(loader && typeof loader === "object" && "createDataSource" in loader);
|
|
2271
|
+
}
|
|
88
2272
|
|
|
89
2273
|
// dist/lib/fetch/fetch-error.js
|
|
90
2274
|
var FetchError = class extends Error {
|
|
@@ -102,9 +2286,6 @@ var FetchError = class extends Error {
|
|
|
102
2286
|
response;
|
|
103
2287
|
};
|
|
104
2288
|
|
|
105
|
-
// dist/lib/utils/resource-utils.js
|
|
106
|
-
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
107
|
-
|
|
108
2289
|
// dist/lib/utils/mime-type-utils.js
|
|
109
2290
|
var DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
|
|
110
2291
|
var MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
|
|
@@ -115,16 +2296,16 @@ function compareMIMETypes(mimeType1, mimeType2) {
|
|
|
115
2296
|
return false;
|
|
116
2297
|
}
|
|
117
2298
|
function parseMIMEType(mimeString) {
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
return
|
|
2299
|
+
const matches3 = MIME_TYPE_PATTERN.exec(mimeString);
|
|
2300
|
+
if (matches3) {
|
|
2301
|
+
return matches3[1];
|
|
121
2302
|
}
|
|
122
2303
|
return mimeString;
|
|
123
2304
|
}
|
|
124
2305
|
function parseMIMETypeFromURL(url) {
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
return
|
|
2306
|
+
const matches3 = DATA_URL_PATTERN.exec(url);
|
|
2307
|
+
if (matches3) {
|
|
2308
|
+
return matches3[1];
|
|
128
2309
|
}
|
|
129
2310
|
return "";
|
|
130
2311
|
}
|
|
@@ -132,8 +2313,8 @@ function parseMIMETypeFromURL(url) {
|
|
|
132
2313
|
// dist/lib/utils/url-utils.js
|
|
133
2314
|
var QUERY_STRING_PATTERN = /\?.*/;
|
|
134
2315
|
function extractQueryString(url) {
|
|
135
|
-
const
|
|
136
|
-
return
|
|
2316
|
+
const matches3 = url.match(QUERY_STRING_PATTERN);
|
|
2317
|
+
return matches3 && matches3[0];
|
|
137
2318
|
}
|
|
138
2319
|
function stripQueryString(url) {
|
|
139
2320
|
return url.replace(QUERY_STRING_PATTERN, "");
|
|
@@ -149,10 +2330,10 @@ function shortenUrlForDisplay(url) {
|
|
|
149
2330
|
|
|
150
2331
|
// dist/lib/utils/resource-utils.js
|
|
151
2332
|
function getResourceUrl(resource) {
|
|
152
|
-
if (
|
|
2333
|
+
if (isResponse(resource)) {
|
|
153
2334
|
return resource.url;
|
|
154
2335
|
}
|
|
155
|
-
if (
|
|
2336
|
+
if (isBlob(resource)) {
|
|
156
2337
|
const fileName = "name" in resource ? resource.name : "";
|
|
157
2338
|
return fileName || "";
|
|
158
2339
|
}
|
|
@@ -162,12 +2343,12 @@ function getResourceUrl(resource) {
|
|
|
162
2343
|
return "";
|
|
163
2344
|
}
|
|
164
2345
|
function getResourceMIMEType(resource) {
|
|
165
|
-
if (
|
|
2346
|
+
if (isResponse(resource)) {
|
|
166
2347
|
const contentTypeHeader = resource.headers.get("content-type") || "";
|
|
167
2348
|
const noQueryUrl = stripQueryString(resource.url);
|
|
168
2349
|
return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
|
|
169
2350
|
}
|
|
170
|
-
if (
|
|
2351
|
+
if (isBlob(resource)) {
|
|
171
2352
|
return resource.type || "";
|
|
172
2353
|
}
|
|
173
2354
|
if (typeof resource === "string") {
|
|
@@ -176,11 +2357,11 @@ function getResourceMIMEType(resource) {
|
|
|
176
2357
|
return "";
|
|
177
2358
|
}
|
|
178
2359
|
function getResourceContentLength(resource) {
|
|
179
|
-
if (
|
|
2360
|
+
if (isResponse(resource)) {
|
|
180
2361
|
const response = resource;
|
|
181
2362
|
return response.headers["content-length"] || -1;
|
|
182
2363
|
}
|
|
183
|
-
if (
|
|
2364
|
+
if (isBlob(resource)) {
|
|
184
2365
|
const blob = resource;
|
|
185
2366
|
return blob.size;
|
|
186
2367
|
}
|
|
@@ -198,7 +2379,7 @@ function getResourceContentLength(resource) {
|
|
|
198
2379
|
|
|
199
2380
|
// dist/lib/utils/response-utils.js
|
|
200
2381
|
async function makeResponse(resource) {
|
|
201
|
-
if (
|
|
2382
|
+
if (isResponse(resource)) {
|
|
202
2383
|
return resource;
|
|
203
2384
|
}
|
|
204
2385
|
const headers = {};
|
|
@@ -240,7 +2421,7 @@ async function getResponseError(response) {
|
|
|
240
2421
|
try {
|
|
241
2422
|
const contentType = response.headers.get("Content-Type");
|
|
242
2423
|
info.reason = !response.bodyUsed && (contentType == null ? void 0 : contentType.includes("application/json")) ? await response.json() : await response.text();
|
|
243
|
-
} catch (
|
|
2424
|
+
} catch (_error) {
|
|
244
2425
|
}
|
|
245
2426
|
return new FetchError(message, info);
|
|
246
2427
|
}
|
|
@@ -251,30 +2432,22 @@ async function getInitialDataUrl(resource) {
|
|
|
251
2432
|
}
|
|
252
2433
|
if (resource instanceof Blob) {
|
|
253
2434
|
const blobSlice = resource.slice(0, 5);
|
|
254
|
-
return await new Promise((
|
|
2435
|
+
return await new Promise((resolve2) => {
|
|
255
2436
|
const reader = new FileReader();
|
|
256
2437
|
reader.onload = (event) => {
|
|
257
2438
|
var _a;
|
|
258
|
-
return
|
|
2439
|
+
return resolve2((_a = event == null ? void 0 : event.target) == null ? void 0 : _a.result);
|
|
259
2440
|
};
|
|
260
2441
|
reader.readAsDataURL(blobSlice);
|
|
261
2442
|
});
|
|
262
2443
|
}
|
|
263
2444
|
if (resource instanceof ArrayBuffer) {
|
|
264
2445
|
const slice = resource.slice(0, INITIAL_DATA_LENGTH);
|
|
265
|
-
const base64 =
|
|
2446
|
+
const base64 = encodeArrayBufferToBase64(slice);
|
|
266
2447
|
return `data:base64,${base64}`;
|
|
267
2448
|
}
|
|
268
2449
|
return null;
|
|
269
2450
|
}
|
|
270
|
-
function arrayBufferToBase64(buffer) {
|
|
271
|
-
let binary = "";
|
|
272
|
-
const bytes = new Uint8Array(buffer);
|
|
273
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
274
|
-
binary += String.fromCharCode(bytes[i]);
|
|
275
|
-
}
|
|
276
|
-
return btoa(binary);
|
|
277
|
-
}
|
|
278
2451
|
|
|
279
2452
|
// dist/lib/fetch/fetch-file.js
|
|
280
2453
|
function isNodePath(url) {
|
|
@@ -289,7 +2462,7 @@ function isDataURL(url) {
|
|
|
289
2462
|
async function fetchFile(urlOrData, fetchOptions) {
|
|
290
2463
|
var _a, _b;
|
|
291
2464
|
if (typeof urlOrData === "string") {
|
|
292
|
-
const url =
|
|
2465
|
+
const url = resolvePath(urlOrData);
|
|
293
2466
|
if (isNodePath(url)) {
|
|
294
2467
|
if ((_a = globalThis.loaders) == null ? void 0 : _a.fetchNode) {
|
|
295
2468
|
return (_b = globalThis.loaders) == null ? void 0 : _b.fetchNode(url, fetchOptions);
|
|
@@ -309,63 +2482,87 @@ async function readArrayBuffer(file, start, length) {
|
|
|
309
2482
|
return await readBlob(slice);
|
|
310
2483
|
}
|
|
311
2484
|
async function readBlob(blob) {
|
|
312
|
-
return await new Promise((
|
|
2485
|
+
return await new Promise((resolve2, reject) => {
|
|
313
2486
|
const fileReader = new FileReader();
|
|
314
2487
|
fileReader.onload = (event) => {
|
|
315
2488
|
var _a;
|
|
316
|
-
return
|
|
2489
|
+
return resolve2((_a = event == null ? void 0 : event.target) == null ? void 0 : _a.result);
|
|
317
2490
|
};
|
|
318
2491
|
fileReader.onerror = (error) => reject(error);
|
|
319
2492
|
fileReader.readAsArrayBuffer(blob);
|
|
320
2493
|
});
|
|
321
2494
|
}
|
|
322
2495
|
|
|
323
|
-
// dist/lib/loader-utils/option-utils.js
|
|
324
|
-
var import_loader_utils5 = require("@loaders.gl/loader-utils");
|
|
325
|
-
|
|
326
2496
|
// dist/lib/loader-utils/loggers.js
|
|
327
|
-
var
|
|
328
|
-
var probeLog = new
|
|
2497
|
+
var import_log3 = require("@probe.gl/log");
|
|
2498
|
+
var probeLog = new import_log3.Log({ id: "loaders.gl" });
|
|
329
2499
|
var NullLog = class {
|
|
2500
|
+
/** Drops a log message. */
|
|
330
2501
|
log() {
|
|
331
2502
|
return () => {
|
|
332
2503
|
};
|
|
333
2504
|
}
|
|
2505
|
+
/** Drops an info message. */
|
|
334
2506
|
info() {
|
|
335
2507
|
return () => {
|
|
336
2508
|
};
|
|
337
2509
|
}
|
|
2510
|
+
/** Logs one message once; no-op for the null logger. */
|
|
2511
|
+
once() {
|
|
2512
|
+
return () => {
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2515
|
+
/** Drops a warning message. */
|
|
338
2516
|
warn() {
|
|
339
2517
|
return () => {
|
|
340
2518
|
};
|
|
341
2519
|
}
|
|
2520
|
+
/** Drops an error message. */
|
|
342
2521
|
error() {
|
|
343
2522
|
return () => {
|
|
344
2523
|
};
|
|
345
2524
|
}
|
|
346
2525
|
};
|
|
347
2526
|
var ConsoleLog = class {
|
|
2527
|
+
/** Console-like object used for message output. */
|
|
348
2528
|
console;
|
|
2529
|
+
/** Messages already emitted through `once`. */
|
|
2530
|
+
onceMessages = /* @__PURE__ */ new Set();
|
|
2531
|
+
/** Creates a console-backed logger. */
|
|
349
2532
|
constructor() {
|
|
350
2533
|
this.console = console;
|
|
351
2534
|
}
|
|
2535
|
+
/** Logs a message to the console. */
|
|
352
2536
|
log(...args) {
|
|
353
2537
|
return this.console.log.bind(this.console, ...args);
|
|
354
2538
|
}
|
|
2539
|
+
/** Logs an informational message to the console. */
|
|
355
2540
|
info(...args) {
|
|
356
2541
|
return this.console.info.bind(this.console, ...args);
|
|
357
2542
|
}
|
|
2543
|
+
/** Logs one message once to the console. */
|
|
2544
|
+
once(...args) {
|
|
2545
|
+
const message = String(args[0]);
|
|
2546
|
+
if (this.onceMessages.has(message)) {
|
|
2547
|
+
return () => {
|
|
2548
|
+
};
|
|
2549
|
+
}
|
|
2550
|
+
this.onceMessages.add(message);
|
|
2551
|
+
return this.console.info.bind(this.console, ...args);
|
|
2552
|
+
}
|
|
2553
|
+
/** Logs a warning message to the console. */
|
|
358
2554
|
warn(...args) {
|
|
359
2555
|
return this.console.warn.bind(this.console, ...args);
|
|
360
2556
|
}
|
|
2557
|
+
/** Logs an error message to the console. */
|
|
361
2558
|
error(...args) {
|
|
362
2559
|
return this.console.error.bind(this.console, ...args);
|
|
363
2560
|
}
|
|
364
2561
|
};
|
|
365
2562
|
|
|
366
2563
|
// dist/lib/loader-utils/option-defaults.js
|
|
367
|
-
var import_loader_utils4 = require("@loaders.gl/loader-utils");
|
|
368
2564
|
var DEFAULT_LOADER_OPTIONS = {
|
|
2565
|
+
searchParams: void 0,
|
|
369
2566
|
core: {
|
|
370
2567
|
baseUrl: void 0,
|
|
371
2568
|
// baseUrl
|
|
@@ -374,17 +2571,20 @@ var DEFAULT_LOADER_OPTIONS = {
|
|
|
374
2571
|
fallbackMimeType: void 0,
|
|
375
2572
|
ignoreRegisteredLoaders: void 0,
|
|
376
2573
|
nothrow: false,
|
|
2574
|
+
shape: void 0,
|
|
377
2575
|
log: new ConsoleLog(),
|
|
378
2576
|
// A probe.gl compatible (`log.log()()` syntax) that just logs to console
|
|
379
2577
|
useLocalLibraries: false,
|
|
2578
|
+
subloaders: void 0,
|
|
380
2579
|
CDN: "https://unpkg.com/@loaders.gl",
|
|
381
2580
|
worker: true,
|
|
382
2581
|
// By default, use worker if provided by loader.
|
|
2582
|
+
workerThreshold: 0.1,
|
|
383
2583
|
maxConcurrency: 3,
|
|
384
2584
|
// How many worker instances should be created for each loader.
|
|
385
2585
|
maxMobileConcurrency: 1,
|
|
386
2586
|
// How many worker instances should be created for each loader on mobile devices.
|
|
387
|
-
reuseWorkers:
|
|
2587
|
+
reuseWorkers: isBrowser,
|
|
388
2588
|
// By default reuse workers in browser (Node.js refuses to terminate if browsers are running)
|
|
389
2589
|
_nodeWorkers: false,
|
|
390
2590
|
// By default do not support node workers
|
|
@@ -419,6 +2619,7 @@ var REMOVED_LOADER_OPTIONS = {
|
|
|
419
2619
|
_worker: "core._workerType",
|
|
420
2620
|
limit: "core.limit",
|
|
421
2621
|
_limitMB: "core._limitMB",
|
|
2622
|
+
shape: "core.shape",
|
|
422
2623
|
batchSize: "core.batchSize",
|
|
423
2624
|
batchDebounceMs: "core.batchDebounceMs",
|
|
424
2625
|
metadata: "core.metadata",
|
|
@@ -454,18 +2655,42 @@ var CORE_LOADER_OPTION_KEYS = [
|
|
|
454
2655
|
"useLocalLibraries",
|
|
455
2656
|
"CDN",
|
|
456
2657
|
"worker",
|
|
2658
|
+
"workerThreshold",
|
|
457
2659
|
"maxConcurrency",
|
|
458
2660
|
"maxMobileConcurrency",
|
|
459
2661
|
"reuseWorkers",
|
|
2662
|
+
"workerTransferBufferCopy",
|
|
460
2663
|
"_nodeWorkers",
|
|
461
2664
|
"_workerType",
|
|
462
2665
|
"limit",
|
|
463
2666
|
"_limitMB",
|
|
2667
|
+
"shape",
|
|
464
2668
|
"batchSize",
|
|
465
2669
|
"batchDebounceMs",
|
|
466
2670
|
"metadata",
|
|
467
2671
|
"transforms"
|
|
468
2672
|
];
|
|
2673
|
+
function applySearchParamsToUrl(url, options) {
|
|
2674
|
+
const searchParams = options == null ? void 0 : options.searchParams;
|
|
2675
|
+
if (!searchParams || Object.keys(searchParams).length === 0 || /^(?:data|blob):/i.test(url)) {
|
|
2676
|
+
return url;
|
|
2677
|
+
}
|
|
2678
|
+
const hashIndex = url.indexOf("#");
|
|
2679
|
+
const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
|
|
2680
|
+
const urlWithoutHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url;
|
|
2681
|
+
const queryIndex = urlWithoutHash.indexOf("?");
|
|
2682
|
+
const path = queryIndex >= 0 ? urlWithoutHash.slice(0, queryIndex) : urlWithoutHash;
|
|
2683
|
+
const query = queryIndex >= 0 ? urlWithoutHash.slice(queryIndex + 1) : "";
|
|
2684
|
+
const existingSearchParams = new URLSearchParams(query);
|
|
2685
|
+
const appendedSearchParams = new URLSearchParams();
|
|
2686
|
+
for (const [key, value] of Object.entries(searchParams)) {
|
|
2687
|
+
if (!existingSearchParams.has(key)) {
|
|
2688
|
+
appendedSearchParams.set(key, String(value));
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
const serializedAppendedSearchParams = appendedSearchParams.toString();
|
|
2692
|
+
return `${path}${queryIndex >= 0 ? `?${query}` : ""}${serializedAppendedSearchParams ? `${queryIndex >= 0 ? "&" : "?"}${serializedAppendedSearchParams}` : ""}${hash}`;
|
|
2693
|
+
}
|
|
469
2694
|
function getGlobalLoaderState() {
|
|
470
2695
|
globalThis.loaders = globalThis.loaders || {};
|
|
471
2696
|
const { loaders } = globalThis;
|
|
@@ -486,13 +2711,16 @@ function setGlobalOptions(options) {
|
|
|
486
2711
|
const state = getGlobalLoaderState();
|
|
487
2712
|
const globalOptions = getGlobalLoaderOptions();
|
|
488
2713
|
state.globalOptions = normalizeOptionsInternal(globalOptions, options);
|
|
489
|
-
|
|
2714
|
+
registerJSModules(options.modules);
|
|
490
2715
|
}
|
|
491
2716
|
function normalizeOptions(options, loader, loaders, url) {
|
|
492
2717
|
loaders = loaders || [];
|
|
493
2718
|
loaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
494
2719
|
validateOptions(options, loaders);
|
|
495
|
-
|
|
2720
|
+
validateWorkerThreshold(options);
|
|
2721
|
+
const normalizedOptions = normalizeLoaderOptions(normalizeOptionsInternal(loader, options, url));
|
|
2722
|
+
validateWorkerThreshold(normalizedOptions);
|
|
2723
|
+
return normalizedOptions;
|
|
496
2724
|
}
|
|
497
2725
|
function normalizeLoaderOptions(options) {
|
|
498
2726
|
const normalized = cloneLoaderOptions(options);
|
|
@@ -516,11 +2744,18 @@ function validateOptions(options, loaders) {
|
|
|
516
2744
|
validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);
|
|
517
2745
|
}
|
|
518
2746
|
}
|
|
2747
|
+
function validateWorkerThreshold(options) {
|
|
2748
|
+
var _a;
|
|
2749
|
+
const threshold = (_a = options.core) == null ? void 0 : _a.workerThreshold;
|
|
2750
|
+
if (threshold !== void 0 && (!Number.isFinite(threshold) || threshold < 0 || threshold > 1)) {
|
|
2751
|
+
throw new Error("core.workerThreshold must be a finite number between 0 and 1");
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
519
2754
|
function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, loaders) {
|
|
520
2755
|
const loaderName = id || "Top level";
|
|
521
2756
|
const prefix = id ? `${id}.` : "";
|
|
522
2757
|
for (const key in options) {
|
|
523
|
-
const isSubOptions = !id &&
|
|
2758
|
+
const isSubOptions = !id && isObject(options[key]);
|
|
524
2759
|
const isBaseUriOption = key === "baseUri" && !id;
|
|
525
2760
|
const isWorkerUrlOption = key === "workerUrl" && id;
|
|
526
2761
|
if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
|
|
@@ -568,15 +2803,40 @@ function normalizeOptionsInternal(loader, options, url) {
|
|
|
568
2803
|
mergeNestedFields(mergedOptions, normalizeLoaderOptions(getGlobalLoaderOptions()));
|
|
569
2804
|
const userOptions = normalizeLoaderOptions(options);
|
|
570
2805
|
mergeNestedFields(mergedOptions, userOptions);
|
|
2806
|
+
applyCoreShapeDefault(mergedOptions, userOptions, loader);
|
|
571
2807
|
addUrlOptions(mergedOptions, url);
|
|
572
2808
|
addDeprecatedTopLevelOptions(mergedOptions);
|
|
573
2809
|
return mergedOptions;
|
|
574
2810
|
}
|
|
2811
|
+
function applyCoreShapeDefault(mergedOptions, userOptions, loader) {
|
|
2812
|
+
var _a, _b;
|
|
2813
|
+
const coreShape = (_a = mergedOptions.core) == null ? void 0 : _a.shape;
|
|
2814
|
+
if (coreShape === void 0) {
|
|
2815
|
+
return;
|
|
2816
|
+
}
|
|
2817
|
+
const loaderScopedDefaults = (_b = loader.options) == null ? void 0 : _b[loader.id];
|
|
2818
|
+
if (!isPureObject(loaderScopedDefaults) || !("shape" in loaderScopedDefaults)) {
|
|
2819
|
+
return;
|
|
2820
|
+
}
|
|
2821
|
+
const globalLoaderScopedOptions = getGlobalLoaderOptions()[loader.id];
|
|
2822
|
+
if (isPureObject(globalLoaderScopedOptions) && "shape" in globalLoaderScopedOptions) {
|
|
2823
|
+
return;
|
|
2824
|
+
}
|
|
2825
|
+
const userLoaderScopedOptions = userOptions[loader.id];
|
|
2826
|
+
if (isPureObject(userLoaderScopedOptions) && "shape" in userLoaderScopedOptions) {
|
|
2827
|
+
return;
|
|
2828
|
+
}
|
|
2829
|
+
const loaderScopedOptions = mergedOptions[loader.id];
|
|
2830
|
+
mergedOptions[loader.id] = {
|
|
2831
|
+
...isPureObject(loaderScopedOptions) ? loaderScopedOptions : {},
|
|
2832
|
+
shape: coreShape
|
|
2833
|
+
};
|
|
2834
|
+
}
|
|
575
2835
|
function mergeNestedFields(mergedOptions, options) {
|
|
576
2836
|
for (const key in options) {
|
|
577
2837
|
if (key in options) {
|
|
578
2838
|
const value = options[key];
|
|
579
|
-
if (
|
|
2839
|
+
if (isPureObject(value) && isPureObject(mergedOptions[key])) {
|
|
580
2840
|
mergedOptions[key] = {
|
|
581
2841
|
...mergedOptions[key],
|
|
582
2842
|
...options[key]
|
|
@@ -595,7 +2855,7 @@ function addUrlOptions(options, url) {
|
|
|
595
2855
|
const hasCoreBaseUrl = ((_a = options.core) == null ? void 0 : _a.baseUrl) !== void 0;
|
|
596
2856
|
if (!hasCoreBaseUrl) {
|
|
597
2857
|
options.core ||= {};
|
|
598
|
-
options.core.baseUrl =
|
|
2858
|
+
options.core.baseUrl = path_exports.dirname(stripQueryString(url));
|
|
599
2859
|
}
|
|
600
2860
|
}
|
|
601
2861
|
function cloneLoaderOptions(options) {
|
|
@@ -614,7 +2874,8 @@ function moveDeprecatedTopLevelOptionsToCore(options) {
|
|
|
614
2874
|
}
|
|
615
2875
|
for (const key of CORE_LOADER_OPTION_KEYS) {
|
|
616
2876
|
if (options[key] !== void 0) {
|
|
617
|
-
|
|
2877
|
+
options.core ||= {};
|
|
2878
|
+
const coreOptions = options.core;
|
|
618
2879
|
const coreRecord = coreOptions;
|
|
619
2880
|
if (coreRecord[key] === void 0) {
|
|
620
2881
|
coreRecord[key] = options[key];
|
|
@@ -642,7 +2903,6 @@ function addDeprecatedTopLevelOptions(options) {
|
|
|
642
2903
|
}
|
|
643
2904
|
|
|
644
2905
|
// dist/lib/loader-utils/normalize-loader.js
|
|
645
|
-
var import_loader_utils6 = require("@loaders.gl/loader-utils");
|
|
646
2906
|
function isLoaderObject(loader) {
|
|
647
2907
|
if (!loader) {
|
|
648
2908
|
return false;
|
|
@@ -654,8 +2914,8 @@ function isLoaderObject(loader) {
|
|
|
654
2914
|
return hasExtensions;
|
|
655
2915
|
}
|
|
656
2916
|
function normalizeLoader(loader) {
|
|
657
|
-
|
|
658
|
-
|
|
2917
|
+
assert(loader, "null loader");
|
|
2918
|
+
assert(isLoaderObject(loader), "invalid loader");
|
|
659
2919
|
let options;
|
|
660
2920
|
if (Array.isArray(loader)) {
|
|
661
2921
|
options = loader[1];
|
|
@@ -699,7 +2959,6 @@ function _unregisterLoaders() {
|
|
|
699
2959
|
}
|
|
700
2960
|
|
|
701
2961
|
// dist/lib/api/select-loader.js
|
|
702
|
-
var import_loader_utils7 = require("@loaders.gl/loader-utils");
|
|
703
2962
|
var EXT_PATTERN = /\.([^.]+)$/;
|
|
704
2963
|
async function selectLoader(data, loaders = [], options, context) {
|
|
705
2964
|
if (!validHTTPResponse(data)) {
|
|
@@ -718,7 +2977,7 @@ async function selectLoader(data, loaders = [], options, context) {
|
|
|
718
2977
|
if (loader) {
|
|
719
2978
|
return loader;
|
|
720
2979
|
}
|
|
721
|
-
if (
|
|
2980
|
+
if (isBlob(data)) {
|
|
722
2981
|
data = await data.slice(0, 10).arrayBuffer();
|
|
723
2982
|
loader = selectLoaderSync(data, loaders, normalizedOptions, context);
|
|
724
2983
|
}
|
|
@@ -765,22 +3024,33 @@ function selectLoaderInternal(data, loaders, options, context) {
|
|
|
765
3024
|
const testUrl = stripQueryString(url) || (context == null ? void 0 : context.url);
|
|
766
3025
|
let loader = null;
|
|
767
3026
|
let reason = "";
|
|
3027
|
+
const sourceType = (options == null ? void 0 : options.core) && "type" in options.core ? options.core.type : void 0;
|
|
3028
|
+
if (sourceType && sourceType !== "auto") {
|
|
3029
|
+
loader = findSourceLoaderByType(loaders, sourceType);
|
|
3030
|
+
reason = loader ? `match forced by supplied source type ${sourceType}` : "";
|
|
3031
|
+
}
|
|
768
3032
|
if ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.mimeType) {
|
|
769
3033
|
loader = findLoaderByMIMEType(loaders, (_b = options == null ? void 0 : options.core) == null ? void 0 : _b.mimeType);
|
|
770
3034
|
reason = `match forced by supplied MIME type ${(_c = options == null ? void 0 : options.core) == null ? void 0 : _c.mimeType}`;
|
|
771
3035
|
}
|
|
3036
|
+
loader = loader || findSourceLoaderByTestURL(loaders, testUrl);
|
|
3037
|
+
reason = reason || (loader ? `matched source url ${testUrl}` : "");
|
|
772
3038
|
loader = loader || findLoaderByUrl(loaders, testUrl);
|
|
773
3039
|
reason = reason || (loader ? `matched url ${testUrl}` : "");
|
|
774
3040
|
loader = loader || findLoaderByMIMEType(loaders, type);
|
|
775
3041
|
reason = reason || (loader ? `matched MIME type ${type}` : "");
|
|
776
3042
|
loader = loader || findLoaderByInitialBytes(loaders, data);
|
|
777
3043
|
reason = reason || (loader ? `matched initial data ${getFirstCharacters(data)}` : "");
|
|
3044
|
+
if (!loader && isBlob(data)) {
|
|
3045
|
+
loader = findSourceLoaderByTestData(loaders, data);
|
|
3046
|
+
reason = reason || (loader ? "matched source testData" : "");
|
|
3047
|
+
}
|
|
778
3048
|
if ((_d = options == null ? void 0 : options.core) == null ? void 0 : _d.fallbackMimeType) {
|
|
779
3049
|
loader = loader || findLoaderByMIMEType(loaders, (_e = options == null ? void 0 : options.core) == null ? void 0 : _e.fallbackMimeType);
|
|
780
3050
|
reason = reason || (loader ? `matched fallback MIME type ${type}` : "");
|
|
781
3051
|
}
|
|
782
3052
|
if (reason) {
|
|
783
|
-
|
|
3053
|
+
log.log(1, `selectLoader selected ${loader == null ? void 0 : loader.name}: ${reason}.`);
|
|
784
3054
|
}
|
|
785
3055
|
return loader;
|
|
786
3056
|
}
|
|
@@ -796,7 +3066,7 @@ function getNoValidLoaderMessage(data) {
|
|
|
796
3066
|
const url = getResourceUrl(data);
|
|
797
3067
|
const type = getResourceMIMEType(data);
|
|
798
3068
|
let message = "No valid loader found (";
|
|
799
|
-
message += url ? `${
|
|
3069
|
+
message += url ? `${path_exports.filename(url)}, ` : "no url provided, ";
|
|
800
3070
|
message += `MIME type: ${type ? `"${type}"` : "not provided"}, `;
|
|
801
3071
|
const firstCharacters = data ? getFirstCharacters(data) : "";
|
|
802
3072
|
message += firstCharacters ? ` first bytes: "${firstCharacters}"` : "first bytes: not available";
|
|
@@ -824,6 +3094,36 @@ function findLoaderByExtension(loaders, extension) {
|
|
|
824
3094
|
}
|
|
825
3095
|
return null;
|
|
826
3096
|
}
|
|
3097
|
+
function findSourceLoaderByType(loaders, type) {
|
|
3098
|
+
for (const loader of loaders) {
|
|
3099
|
+
if (isSourceLoader(loader) && loader.type === type) {
|
|
3100
|
+
return loader;
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
return null;
|
|
3104
|
+
}
|
|
3105
|
+
function findSourceLoaderByTestURL(loaders, url) {
|
|
3106
|
+
if (!url) {
|
|
3107
|
+
return null;
|
|
3108
|
+
}
|
|
3109
|
+
for (const loader of loaders) {
|
|
3110
|
+
if (isSourceLoader(loader) && loader.testURL(url)) {
|
|
3111
|
+
return loader;
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
return null;
|
|
3115
|
+
}
|
|
3116
|
+
function findSourceLoaderByTestData(loaders, data) {
|
|
3117
|
+
var _a;
|
|
3118
|
+
for (const loader of loaders) {
|
|
3119
|
+
if (isSourceLoader(loader)) {
|
|
3120
|
+
if ((_a = loader.testData) == null ? void 0 : _a.call(loader, data)) {
|
|
3121
|
+
return loader;
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
return null;
|
|
3126
|
+
}
|
|
827
3127
|
function findLoaderByMIMEType(loaders, mimeType) {
|
|
828
3128
|
var _a;
|
|
829
3129
|
for (const loader of loaders) {
|
|
@@ -870,12 +3170,12 @@ function testDataAgainstBinary(data, byteOffset, loader) {
|
|
|
870
3170
|
return tests.some((test) => testBinary(data, byteOffset, loader, test));
|
|
871
3171
|
}
|
|
872
3172
|
function testBinary(data, byteOffset, loader, test) {
|
|
873
|
-
if (
|
|
874
|
-
return
|
|
3173
|
+
if (isArrayBufferLike(test)) {
|
|
3174
|
+
return compareArrayBuffers(test, data, test.byteLength);
|
|
875
3175
|
}
|
|
876
3176
|
switch (typeof test) {
|
|
877
3177
|
case "function":
|
|
878
|
-
return test(
|
|
3178
|
+
return test(ensureArrayBuffer(data));
|
|
879
3179
|
case "string":
|
|
880
3180
|
const magic = getMagicString(data, byteOffset, test.length);
|
|
881
3181
|
return test === magic;
|
|
@@ -906,15 +3206,7 @@ function getMagicString(arrayBuffer, byteOffset, length) {
|
|
|
906
3206
|
return magic;
|
|
907
3207
|
}
|
|
908
3208
|
|
|
909
|
-
// dist/lib/api/parse.js
|
|
910
|
-
var import_loader_utils14 = require("@loaders.gl/loader-utils");
|
|
911
|
-
var import_worker_utils = require("@loaders.gl/worker-utils");
|
|
912
|
-
|
|
913
|
-
// dist/lib/loader-utils/get-data.js
|
|
914
|
-
var import_loader_utils11 = require("@loaders.gl/loader-utils");
|
|
915
|
-
|
|
916
3209
|
// dist/iterators/make-iterator/make-string-iterator.js
|
|
917
|
-
var import_loader_utils8 = require("@loaders.gl/loader-utils");
|
|
918
3210
|
var DEFAULT_CHUNK_SIZE = 256 * 1024;
|
|
919
3211
|
function* makeStringIterator(string, options) {
|
|
920
3212
|
const chunkSize = (options == null ? void 0 : options.chunkSize) || DEFAULT_CHUNK_SIZE;
|
|
@@ -924,7 +3216,7 @@ function* makeStringIterator(string, options) {
|
|
|
924
3216
|
const chunkLength = Math.min(string.length - offset, chunkSize);
|
|
925
3217
|
const chunk = string.slice(offset, offset + chunkLength);
|
|
926
3218
|
offset += chunkLength;
|
|
927
|
-
yield
|
|
3219
|
+
yield ensureArrayBuffer(textEncoder.encode(chunk));
|
|
928
3220
|
}
|
|
929
3221
|
}
|
|
930
3222
|
|
|
@@ -958,37 +3250,72 @@ async function* makeBlobIterator(blob, options) {
|
|
|
958
3250
|
}
|
|
959
3251
|
|
|
960
3252
|
// dist/iterators/make-iterator/make-stream-iterator.js
|
|
961
|
-
var import_loader_utils9 = require("@loaders.gl/loader-utils");
|
|
962
3253
|
function makeStreamIterator(stream, options) {
|
|
963
|
-
return
|
|
3254
|
+
return isBrowser ? makeBrowserStreamIterator(stream, options) : makeNodeStreamIterator(stream, options);
|
|
964
3255
|
}
|
|
965
3256
|
async function* makeBrowserStreamIterator(stream, options) {
|
|
966
3257
|
const reader = stream.getReader();
|
|
967
3258
|
let nextBatchPromise;
|
|
3259
|
+
let streamFinished = false;
|
|
3260
|
+
let streamReadFailed = false;
|
|
3261
|
+
let iteratorFailed = false;
|
|
968
3262
|
try {
|
|
969
3263
|
while (true) {
|
|
970
3264
|
const currentBatchPromise = nextBatchPromise || reader.read();
|
|
971
|
-
|
|
972
|
-
|
|
3265
|
+
nextBatchPromise = void 0;
|
|
3266
|
+
let batch;
|
|
3267
|
+
try {
|
|
3268
|
+
batch = await currentBatchPromise;
|
|
3269
|
+
} catch (error) {
|
|
3270
|
+
streamReadFailed = true;
|
|
3271
|
+
throw error;
|
|
973
3272
|
}
|
|
974
|
-
const { done, value } =
|
|
3273
|
+
const { done, value } = batch;
|
|
975
3274
|
if (done) {
|
|
3275
|
+
streamFinished = true;
|
|
976
3276
|
return;
|
|
977
3277
|
}
|
|
978
|
-
|
|
3278
|
+
if (options == null ? void 0 : options._streamReadAhead) {
|
|
3279
|
+
nextBatchPromise = reader.read();
|
|
3280
|
+
void nextBatchPromise.catch(() => {
|
|
3281
|
+
});
|
|
3282
|
+
}
|
|
3283
|
+
yield toArrayBuffer2(value);
|
|
979
3284
|
}
|
|
980
3285
|
} catch (error) {
|
|
981
|
-
|
|
3286
|
+
iteratorFailed = true;
|
|
3287
|
+
throw error;
|
|
3288
|
+
} finally {
|
|
3289
|
+
let cleanupFailed = false;
|
|
3290
|
+
let cleanupError;
|
|
3291
|
+
if (!streamFinished && !streamReadFailed) {
|
|
3292
|
+
try {
|
|
3293
|
+
await reader.cancel();
|
|
3294
|
+
} catch (error) {
|
|
3295
|
+
cleanupFailed = true;
|
|
3296
|
+
cleanupError = error;
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
try {
|
|
3300
|
+
reader.releaseLock();
|
|
3301
|
+
} catch (error) {
|
|
3302
|
+
if (!cleanupFailed) {
|
|
3303
|
+
cleanupFailed = true;
|
|
3304
|
+
cleanupError = error;
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
if (!iteratorFailed && cleanupFailed) {
|
|
3308
|
+
throw cleanupError;
|
|
3309
|
+
}
|
|
982
3310
|
}
|
|
983
3311
|
}
|
|
984
3312
|
async function* makeNodeStreamIterator(stream, options) {
|
|
985
3313
|
for await (const chunk of stream) {
|
|
986
|
-
yield (
|
|
3314
|
+
yield toArrayBuffer2(chunk);
|
|
987
3315
|
}
|
|
988
3316
|
}
|
|
989
3317
|
|
|
990
3318
|
// dist/iterators/make-iterator/make-iterator.js
|
|
991
|
-
var import_loader_utils10 = require("@loaders.gl/loader-utils");
|
|
992
3319
|
function makeIterator(data, options) {
|
|
993
3320
|
if (typeof data === "string") {
|
|
994
3321
|
return makeStringIterator(data, options);
|
|
@@ -996,13 +3323,13 @@ function makeIterator(data, options) {
|
|
|
996
3323
|
if (data instanceof ArrayBuffer) {
|
|
997
3324
|
return makeArrayBufferIterator(data, options);
|
|
998
3325
|
}
|
|
999
|
-
if (
|
|
3326
|
+
if (isBlob(data)) {
|
|
1000
3327
|
return makeBlobIterator(data, options);
|
|
1001
3328
|
}
|
|
1002
|
-
if (
|
|
3329
|
+
if (isReadableStream(data)) {
|
|
1003
3330
|
return makeStreamIterator(data, options);
|
|
1004
3331
|
}
|
|
1005
|
-
if (
|
|
3332
|
+
if (isResponse(data)) {
|
|
1006
3333
|
const responseBody = data.body;
|
|
1007
3334
|
if (!responseBody) {
|
|
1008
3335
|
throw new Error("Readable stream not available on Response");
|
|
@@ -1018,46 +3345,68 @@ function getArrayBufferOrStringFromDataSync(data, loader, options) {
|
|
|
1018
3345
|
if (loader.text && typeof data === "string") {
|
|
1019
3346
|
return data;
|
|
1020
3347
|
}
|
|
1021
|
-
if (
|
|
3348
|
+
if (isBuffer(data)) {
|
|
1022
3349
|
data = data.buffer;
|
|
1023
3350
|
}
|
|
1024
|
-
if (
|
|
1025
|
-
const bufferSource =
|
|
3351
|
+
if (isArrayBufferLike(data)) {
|
|
3352
|
+
const bufferSource = toArrayBufferView(data);
|
|
1026
3353
|
if (loader.text && !loader.binary) {
|
|
1027
3354
|
const textDecoder = new TextDecoder("utf8");
|
|
1028
3355
|
return textDecoder.decode(bufferSource);
|
|
1029
3356
|
}
|
|
1030
|
-
return (
|
|
3357
|
+
return toArrayBuffer2(bufferSource);
|
|
1031
3358
|
}
|
|
1032
3359
|
throw new Error(ERR_DATA);
|
|
1033
3360
|
}
|
|
1034
3361
|
async function getArrayBufferOrStringFromData(data, loader, options) {
|
|
1035
|
-
if (typeof data === "string" ||
|
|
3362
|
+
if (typeof data === "string" || isArrayBufferLike(data)) {
|
|
1036
3363
|
return getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
1037
3364
|
}
|
|
1038
|
-
if (
|
|
3365
|
+
if (isBlob(data)) {
|
|
1039
3366
|
data = await makeResponse(data);
|
|
1040
3367
|
}
|
|
1041
|
-
if (
|
|
3368
|
+
if (isResponse(data)) {
|
|
1042
3369
|
await checkResponse(data);
|
|
1043
3370
|
return loader.binary ? await data.arrayBuffer() : await data.text();
|
|
1044
3371
|
}
|
|
1045
|
-
if (
|
|
3372
|
+
if (isReadableStream(data)) {
|
|
3373
|
+
data = makeIterator(data, options);
|
|
3374
|
+
}
|
|
3375
|
+
if (isIterable(data) || isAsyncIterable(data)) {
|
|
3376
|
+
return concatenateArrayBuffersAsync(data);
|
|
3377
|
+
}
|
|
3378
|
+
throw new Error(ERR_DATA);
|
|
3379
|
+
}
|
|
3380
|
+
async function getArrayBufferFromData(data, options) {
|
|
3381
|
+
if (typeof data === "string") {
|
|
3382
|
+
return new TextEncoder().encode(data).buffer;
|
|
3383
|
+
}
|
|
3384
|
+
if (isArrayBufferLike(data)) {
|
|
3385
|
+
return toArrayBuffer2(toArrayBufferView(data));
|
|
3386
|
+
}
|
|
3387
|
+
if (isBlob(data)) {
|
|
3388
|
+
data = await makeResponse(data);
|
|
3389
|
+
}
|
|
3390
|
+
if (isResponse(data)) {
|
|
3391
|
+
await checkResponse(data);
|
|
3392
|
+
return await data.arrayBuffer();
|
|
3393
|
+
}
|
|
3394
|
+
if (isReadableStream(data)) {
|
|
1046
3395
|
data = makeIterator(data, options);
|
|
1047
3396
|
}
|
|
1048
|
-
if (
|
|
1049
|
-
return
|
|
3397
|
+
if (isIterable(data) || isAsyncIterable(data)) {
|
|
3398
|
+
return concatenateArrayBuffersAsync(data);
|
|
1050
3399
|
}
|
|
1051
3400
|
throw new Error(ERR_DATA);
|
|
1052
3401
|
}
|
|
1053
3402
|
async function getAsyncIterableFromData(data, options) {
|
|
1054
|
-
if (
|
|
3403
|
+
if (isPromise(data)) {
|
|
1055
3404
|
data = await data;
|
|
1056
3405
|
}
|
|
1057
|
-
if (
|
|
3406
|
+
if (isIterator(data)) {
|
|
1058
3407
|
return data;
|
|
1059
3408
|
}
|
|
1060
|
-
if (
|
|
3409
|
+
if (isResponse(data)) {
|
|
1061
3410
|
await checkResponse(data);
|
|
1062
3411
|
const body = await data.body;
|
|
1063
3412
|
if (!body) {
|
|
@@ -1065,142 +3414,306 @@ async function getAsyncIterableFromData(data, options) {
|
|
|
1065
3414
|
}
|
|
1066
3415
|
return makeIterator(body, options);
|
|
1067
3416
|
}
|
|
1068
|
-
if (
|
|
3417
|
+
if (isBlob(data) || isReadableStream(data)) {
|
|
1069
3418
|
return makeIterator(data, options);
|
|
1070
3419
|
}
|
|
1071
|
-
if (
|
|
3420
|
+
if (isAsyncIterable(data)) {
|
|
1072
3421
|
return data;
|
|
1073
3422
|
}
|
|
1074
|
-
if (
|
|
3423
|
+
if (isIterable(data)) {
|
|
1075
3424
|
return data;
|
|
1076
3425
|
}
|
|
1077
3426
|
return getIterableFromData(data);
|
|
1078
3427
|
}
|
|
1079
3428
|
function getIterableFromData(data) {
|
|
1080
3429
|
if (ArrayBuffer.isView(data)) {
|
|
1081
|
-
return function* oneChunk() {
|
|
1082
|
-
yield (
|
|
1083
|
-
}();
|
|
3430
|
+
return (function* oneChunk() {
|
|
3431
|
+
yield toArrayBuffer2(data);
|
|
3432
|
+
})();
|
|
1084
3433
|
}
|
|
1085
|
-
if (
|
|
1086
|
-
return function* oneChunk() {
|
|
1087
|
-
yield (
|
|
1088
|
-
}();
|
|
3434
|
+
if (isArrayBufferLike(data)) {
|
|
3435
|
+
return (function* oneChunk() {
|
|
3436
|
+
yield toArrayBuffer2(data);
|
|
3437
|
+
})();
|
|
1089
3438
|
}
|
|
1090
|
-
if (
|
|
3439
|
+
if (isIterator(data)) {
|
|
1091
3440
|
return data;
|
|
1092
3441
|
}
|
|
1093
|
-
if (
|
|
3442
|
+
if (isIterable(data)) {
|
|
1094
3443
|
return data[Symbol.iterator]();
|
|
1095
3444
|
}
|
|
1096
3445
|
throw new Error(ERR_DATA);
|
|
1097
3446
|
}
|
|
1098
3447
|
|
|
1099
3448
|
// dist/lib/loader-utils/get-fetch-function.js
|
|
1100
|
-
var import_loader_utils12 = require("@loaders.gl/loader-utils");
|
|
1101
3449
|
function getFetchFunction(options, context) {
|
|
1102
|
-
var _a;
|
|
3450
|
+
var _a, _b, _c;
|
|
1103
3451
|
const globalOptions = getGlobalLoaderOptions();
|
|
1104
3452
|
const loaderOptions = options || globalOptions;
|
|
1105
3453
|
const fetchOption = loaderOptions.fetch ?? ((_a = loaderOptions.core) == null ? void 0 : _a.fetch);
|
|
3454
|
+
let fetchFunction;
|
|
1106
3455
|
if (typeof fetchOption === "function") {
|
|
1107
|
-
|
|
3456
|
+
fetchFunction = fetchOption;
|
|
3457
|
+
} else if (isObject(fetchOption)) {
|
|
3458
|
+
fetchFunction = (context == null ? void 0 : context.fetch) || fetchFile;
|
|
3459
|
+
} else if (context == null ? void 0 : context.fetch) {
|
|
3460
|
+
fetchFunction = context.fetch;
|
|
3461
|
+
} else {
|
|
3462
|
+
fetchFunction = fetchFile;
|
|
3463
|
+
}
|
|
3464
|
+
return createAuthenticatedFetch({
|
|
3465
|
+
fetch: fetchFunction,
|
|
3466
|
+
credentials: ((_b = loaderOptions.core) == null ? void 0 : _b.credentials) || [],
|
|
3467
|
+
authentications: (_c = loaderOptions.core) == null ? void 0 : _c.authentications,
|
|
3468
|
+
fetchOptions: isObject(fetchOption) ? fetchOption : void 0
|
|
3469
|
+
});
|
|
3470
|
+
}
|
|
3471
|
+
|
|
3472
|
+
// dist/lib/api/load-loader.js
|
|
3473
|
+
var loaderImplementationPromises = /* @__PURE__ */ new Map();
|
|
3474
|
+
var loaderImplementations = /* @__PURE__ */ new Map();
|
|
3475
|
+
async function getLoaderImplementation(loader, options, url) {
|
|
3476
|
+
var _a;
|
|
3477
|
+
if (isSourceLoader(loader)) {
|
|
3478
|
+
const source = loader.preload ? await loader.preload(url || "", options) : loader;
|
|
3479
|
+
if (!isSourceLoader(source)) {
|
|
3480
|
+
throw new Error(`${loader.id} source loader preload() did not return a runtime source loader`);
|
|
3481
|
+
}
|
|
3482
|
+
return source;
|
|
1108
3483
|
}
|
|
1109
|
-
if ((
|
|
1110
|
-
return
|
|
3484
|
+
if (isLoaderWithParser(loader)) {
|
|
3485
|
+
return loader;
|
|
1111
3486
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
3487
|
+
const implementationCacheKey = getLoaderImplementationCacheKey(loader, options);
|
|
3488
|
+
const loaderImplementation = (_a = loaderImplementations.get(loader)) == null ? void 0 : _a.get(implementationCacheKey);
|
|
3489
|
+
if (loaderImplementation) {
|
|
3490
|
+
return loaderImplementation;
|
|
3491
|
+
}
|
|
3492
|
+
let loaderImplementationPromisesForLoader = loaderImplementationPromises.get(loader);
|
|
3493
|
+
if (!loaderImplementationPromisesForLoader) {
|
|
3494
|
+
loaderImplementationPromisesForLoader = /* @__PURE__ */ new Map();
|
|
3495
|
+
loaderImplementationPromises.set(loader, loaderImplementationPromisesForLoader);
|
|
3496
|
+
}
|
|
3497
|
+
let loaderImplementationPromise = loaderImplementationPromisesForLoader.get(implementationCacheKey);
|
|
3498
|
+
if (!loaderImplementationPromise) {
|
|
3499
|
+
loaderImplementationPromise = resolveLoaderImplementation(loader, options, url).then((implementation) => {
|
|
3500
|
+
let loaderImplementationsForLoader = loaderImplementations.get(loader);
|
|
3501
|
+
if (!loaderImplementationsForLoader) {
|
|
3502
|
+
loaderImplementationsForLoader = /* @__PURE__ */ new Map();
|
|
3503
|
+
loaderImplementations.set(loader, loaderImplementationsForLoader);
|
|
3504
|
+
}
|
|
3505
|
+
loaderImplementationsForLoader.set(implementationCacheKey, implementation);
|
|
3506
|
+
return implementation;
|
|
3507
|
+
}).catch((error) => {
|
|
3508
|
+
loaderImplementationPromisesForLoader.delete(implementationCacheKey);
|
|
3509
|
+
if (loaderImplementationPromisesForLoader.size === 0) {
|
|
3510
|
+
loaderImplementationPromises.delete(loader);
|
|
3511
|
+
}
|
|
3512
|
+
throw error;
|
|
3513
|
+
});
|
|
3514
|
+
loaderImplementationPromisesForLoader.set(implementationCacheKey, loaderImplementationPromise);
|
|
1114
3515
|
}
|
|
1115
|
-
return
|
|
3516
|
+
return await loaderImplementationPromise;
|
|
1116
3517
|
}
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
3518
|
+
function getLoaderImplementationSync(loader) {
|
|
3519
|
+
var _a;
|
|
3520
|
+
if (loader.subloaders && !preparedLoaders.has(loader)) {
|
|
3521
|
+
const prepared = preparedDefaults.get(loader);
|
|
3522
|
+
if (prepared)
|
|
3523
|
+
return prepared;
|
|
3524
|
+
if (!isLoaderWithParser(loader))
|
|
3525
|
+
return null;
|
|
3526
|
+
}
|
|
3527
|
+
if (isLoaderWithParser(loader)) {
|
|
3528
|
+
return loader;
|
|
1123
3529
|
}
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
3530
|
+
const implementationCacheKey = getLoaderImplementationCacheKey(loader);
|
|
3531
|
+
return ((_a = loaderImplementations.get(loader)) == null ? void 0 : _a.get(implementationCacheKey)) || null;
|
|
3532
|
+
}
|
|
3533
|
+
function isLoaderWithParser(loader) {
|
|
3534
|
+
const candidate = loader;
|
|
3535
|
+
return Boolean(candidate.parse || candidate.parseSync || candidate.parseInBatches || candidate.parseText || candidate.parseTextSync || candidate.parseFile || candidate.parseFileInBatches);
|
|
3536
|
+
}
|
|
3537
|
+
async function resolveLoaderImplementation(loader, options, url) {
|
|
3538
|
+
if (loader.preload) {
|
|
3539
|
+
const preloadedLoader = await loader.preload(url || "", options);
|
|
3540
|
+
if (isLoaderWithParser(preloadedLoader)) {
|
|
3541
|
+
return preloadedLoader;
|
|
3542
|
+
}
|
|
3543
|
+
throw new Error(`${loader.id} loader preload() did not return a parser-bearing loader`);
|
|
1134
3544
|
}
|
|
1135
|
-
|
|
1136
|
-
|
|
3545
|
+
const implementationSpecifier = getLoaderImplementationSpecifier(loader, options);
|
|
3546
|
+
return await importLoaderImplementation(implementationSpecifier, loader.id);
|
|
3547
|
+
}
|
|
3548
|
+
function getLoaderImplementationSpecifier(loader, options) {
|
|
3549
|
+
var _a;
|
|
3550
|
+
const workerType = (options == null ? void 0 : options._workerType) || ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._workerType);
|
|
3551
|
+
if (workerType === "test") {
|
|
3552
|
+
const sourcePath = `modules/${loader.module}/src/${loader.id}-loader.ts`;
|
|
3553
|
+
if (typeof window !== "undefined") {
|
|
3554
|
+
return `/${sourcePath}`;
|
|
3555
|
+
}
|
|
3556
|
+
if (typeof process !== "undefined" && process.cwd) {
|
|
3557
|
+
return new URL(sourcePath, `file://${process.cwd()}/`).toString();
|
|
3558
|
+
}
|
|
3559
|
+
return sourcePath;
|
|
1137
3560
|
}
|
|
1138
|
-
|
|
3561
|
+
throw new Error(`${loader.id} loader does not provide a parser implementation. Import a parser-bearing loader directly, or use preload() before parse/load.`);
|
|
1139
3562
|
}
|
|
1140
|
-
function
|
|
1141
|
-
|
|
1142
|
-
|
|
3563
|
+
function getLoaderImplementationCacheKey(loader, options) {
|
|
3564
|
+
var _a;
|
|
3565
|
+
const loaderOptions = options == null ? void 0 : options[loader.id];
|
|
3566
|
+
const defaultLoaderOptions = (_a = loader.options) == null ? void 0 : _a[loader.id];
|
|
3567
|
+
return String((loaderOptions == null ? void 0 : loaderOptions.backend) || (defaultLoaderOptions == null ? void 0 : defaultLoaderOptions.backend) || "");
|
|
3568
|
+
}
|
|
3569
|
+
async function importLoaderImplementation(implementationSpecifier, loaderId) {
|
|
3570
|
+
const moduleExports = await import(
|
|
3571
|
+
/* webpackIgnore: true */
|
|
3572
|
+
/* @vite-ignore */
|
|
3573
|
+
implementationSpecifier
|
|
3574
|
+
);
|
|
3575
|
+
for (const exportValue of Object.values(moduleExports)) {
|
|
3576
|
+
if (exportValue && typeof exportValue === "object" && exportValue.id === loaderId && isLoaderWithParser(exportValue)) {
|
|
3577
|
+
return exportValue;
|
|
3578
|
+
}
|
|
1143
3579
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
3580
|
+
throw new Error(`Could not find parser implementation for ${loaderId} in ${implementationSpecifier}`);
|
|
3581
|
+
}
|
|
3582
|
+
var preparedLoaders = /* @__PURE__ */ new WeakSet();
|
|
3583
|
+
var preparedDefaults = /* @__PURE__ */ new WeakMap();
|
|
3584
|
+
var subloaderPreparations = /* @__PURE__ */ new WeakMap();
|
|
3585
|
+
async function preloadLoaderDependencies(loader, options, url) {
|
|
3586
|
+
if (preparedLoaders.has(loader))
|
|
3587
|
+
return await getLoaderImplementation(loader, options, url);
|
|
3588
|
+
validateSubloaderGraph(loader, options);
|
|
3589
|
+
return await prepareLoaderDependencies(loader, options, url);
|
|
3590
|
+
}
|
|
3591
|
+
async function prepareLoaderDependencies(loader, options, url) {
|
|
3592
|
+
if (!options) {
|
|
3593
|
+
const cached = subloaderPreparations.get(loader);
|
|
3594
|
+
if (cached)
|
|
3595
|
+
return await cached;
|
|
3596
|
+
}
|
|
3597
|
+
const preparation = bindSubloaders(loader, options, url);
|
|
3598
|
+
if (!options) {
|
|
3599
|
+
subloaderPreparations.set(loader, preparation);
|
|
3600
|
+
void preparation.catch(() => subloaderPreparations.delete(loader));
|
|
3601
|
+
}
|
|
3602
|
+
const prepared = await preparation;
|
|
3603
|
+
if (!options)
|
|
3604
|
+
preparedDefaults.set(loader, prepared);
|
|
3605
|
+
return prepared;
|
|
3606
|
+
}
|
|
3607
|
+
function getSubloaders(loader, options) {
|
|
3608
|
+
var _a;
|
|
3609
|
+
const overrides = ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.subloaders) || {};
|
|
3610
|
+
return Object.fromEntries(Object.entries(loader.subloaders || {}).map(([name, dependency]) => [
|
|
3611
|
+
name,
|
|
3612
|
+
Object.hasOwn(overrides, name) ? overrides[name] : dependency
|
|
3613
|
+
]));
|
|
3614
|
+
}
|
|
3615
|
+
function validateSubloaderGraph(loader, options) {
|
|
3616
|
+
visitLoader(loader, []);
|
|
3617
|
+
function visitLoader(currentLoader, ancestors) {
|
|
3618
|
+
if (ancestors.includes(currentLoader)) {
|
|
3619
|
+
throw new Error(`Subloader cycle: ${[...ancestors, currentLoader].map((value) => value.id).join(" -> ")}`);
|
|
3620
|
+
}
|
|
3621
|
+
for (const dependency of Object.values(getSubloaders(currentLoader, options))) {
|
|
3622
|
+
visitLoader(dependency, [...ancestors, currentLoader]);
|
|
3623
|
+
}
|
|
1147
3624
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
3625
|
+
}
|
|
3626
|
+
async function bindSubloaders(loader, options, url) {
|
|
3627
|
+
const [implementation, entries] = await Promise.all([
|
|
3628
|
+
getLoaderImplementation(loader, options, url),
|
|
3629
|
+
Promise.all(Object.entries(getSubloaders(loader, options)).map(async ([name, dependency]) => [name, await prepareLoaderDependencies(dependency, options, url)]))
|
|
3630
|
+
]);
|
|
3631
|
+
const subloaders = Object.fromEntries(entries);
|
|
3632
|
+
const defaultOptions = mergeOptions(implementation.options, options || {});
|
|
3633
|
+
defaultOptions.core = { ...defaultOptions.core, worker: false };
|
|
3634
|
+
const prepared = { ...implementation, options: defaultOptions, subloaders };
|
|
3635
|
+
delete prepared.preload;
|
|
3636
|
+
prepared.worker = false;
|
|
3637
|
+
for (const method of [
|
|
3638
|
+
"parseBlob",
|
|
3639
|
+
"createDataSource",
|
|
3640
|
+
"parse",
|
|
3641
|
+
"parseSync",
|
|
3642
|
+
"parseText",
|
|
3643
|
+
"parseTextSync",
|
|
3644
|
+
"parseInBatches",
|
|
3645
|
+
"parseFile",
|
|
3646
|
+
"parseFileInBatches",
|
|
3647
|
+
"parseUrl"
|
|
3648
|
+
]) {
|
|
3649
|
+
const parser = implementation[method];
|
|
3650
|
+
if (typeof parser === "function") {
|
|
3651
|
+
prepared[method] = (data, parseOptions, context) => {
|
|
3652
|
+
var _a, _b;
|
|
3653
|
+
const forwardedOptions = mergeOptions(options, parseOptions || {});
|
|
3654
|
+
return parser.call(implementation, data, {
|
|
3655
|
+
...forwardedOptions,
|
|
3656
|
+
core: {
|
|
3657
|
+
...forwardedOptions.core,
|
|
3658
|
+
subloaders: ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.subloaders) || ((_b = parseOptions == null ? void 0 : parseOptions.core) == null ? void 0 : _b.subloaders),
|
|
3659
|
+
worker: false
|
|
3660
|
+
},
|
|
3661
|
+
[loader.id]: { ...forwardedOptions[loader.id], subloaders }
|
|
3662
|
+
}, context);
|
|
3663
|
+
};
|
|
3664
|
+
}
|
|
1151
3665
|
}
|
|
1152
|
-
|
|
3666
|
+
preparedLoaders.add(prepared);
|
|
3667
|
+
return prepared;
|
|
1153
3668
|
}
|
|
1154
3669
|
|
|
1155
|
-
// dist/lib/api/parse.js
|
|
1156
|
-
async function
|
|
3670
|
+
// dist/lib/api/parse-file.js
|
|
3671
|
+
async function parseFile(file, loaders, options, context) {
|
|
3672
|
+
var _a, _b;
|
|
1157
3673
|
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
1158
3674
|
context = void 0;
|
|
1159
3675
|
options = loaders;
|
|
1160
3676
|
loaders = void 0;
|
|
1161
3677
|
}
|
|
1162
|
-
data = await data;
|
|
1163
3678
|
options = options || {};
|
|
1164
|
-
const url =
|
|
3679
|
+
const url = file.url || "";
|
|
1165
3680
|
const typedLoaders = loaders;
|
|
1166
3681
|
const candidateLoaders = getLoadersFromContext(typedLoaders, context);
|
|
1167
|
-
const loader = await selectLoader(
|
|
3682
|
+
const loader = await selectLoader(url, candidateLoaders, options);
|
|
1168
3683
|
if (!loader) {
|
|
1169
3684
|
return null;
|
|
1170
3685
|
}
|
|
1171
|
-
|
|
3686
|
+
if (isSourceLoader(loader)) {
|
|
3687
|
+
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parseFile().`);
|
|
3688
|
+
}
|
|
3689
|
+
const normalizedOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
3690
|
+
const authenticationLoader = !loader.getAuthentications && ((_b = (_a = normalizedOptions.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) ? await getLoaderImplementation(loader, normalizedOptions, url || (context == null ? void 0 : context.url)) : loader;
|
|
3691
|
+
const strictOptions = await resolveLoaderAuthenticationOptions(authenticationLoader, url, normalizedOptions);
|
|
1172
3692
|
context = getLoaderContext(
|
|
1173
|
-
// @ts-expect-error
|
|
3693
|
+
// @ts-expect-error candidateLoaders may be a single forced loader
|
|
1174
3694
|
{ url, _parse: parse, loaders: candidateLoaders },
|
|
1175
3695
|
strictOptions,
|
|
1176
3696
|
context || null
|
|
1177
3697
|
);
|
|
1178
|
-
return await
|
|
3698
|
+
return await parseFileWithLoader(loader, file, strictOptions, context);
|
|
1179
3699
|
}
|
|
1180
|
-
async function
|
|
1181
|
-
|
|
1182
|
-
options =
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
return await (
|
|
1195
|
-
}
|
|
1196
|
-
if (loaderWithParser.parseText && typeof data === "string") {
|
|
1197
|
-
return await loaderWithParser.parseText(data, options, context);
|
|
1198
|
-
}
|
|
1199
|
-
if (loaderWithParser.parse) {
|
|
1200
|
-
return await loaderWithParser.parse(data, options, context);
|
|
3700
|
+
async function parseFileWithLoader(loader, file, options, context) {
|
|
3701
|
+
validateWorkerVersion(loader);
|
|
3702
|
+
options = mergeOptions(loader.options, options);
|
|
3703
|
+
const loaderWithParser = await getLoaderImplementation(loader, options, context.url);
|
|
3704
|
+
if (loaderWithParser.parseFile) {
|
|
3705
|
+
return await loaderWithParser.parseFile(file, options, context);
|
|
3706
|
+
}
|
|
3707
|
+
const parseFunction = loaderWithParser.parse;
|
|
3708
|
+
if (parseFunction) {
|
|
3709
|
+
const length = file.bigsize > 0n ? Number(file.bigsize) : file.size;
|
|
3710
|
+
if (!length) {
|
|
3711
|
+
throw new Error(`${loader.id} loader - cannot fall back to parse without a file size`);
|
|
3712
|
+
}
|
|
3713
|
+
const data = await file.read(0n, length);
|
|
3714
|
+
return await parse(data, loaderWithParser, options, context);
|
|
1201
3715
|
}
|
|
1202
|
-
|
|
1203
|
-
throw new Error(`${loader.id} loader - no parser found and worker is disabled`);
|
|
3716
|
+
throw new Error(`${loader.id} loader - no file parser found`);
|
|
1204
3717
|
}
|
|
1205
3718
|
|
|
1206
3719
|
// dist/lib/api/parse-sync.js
|
|
@@ -1217,13 +3730,17 @@ function parseSync(data, loaders, options, context) {
|
|
|
1217
3730
|
if (!loader) {
|
|
1218
3731
|
return null;
|
|
1219
3732
|
}
|
|
3733
|
+
if (isSourceLoader(loader)) {
|
|
3734
|
+
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parseSync().`);
|
|
3735
|
+
}
|
|
1220
3736
|
const strictOptions = normalizeOptions(options, loader, candidateLoaders);
|
|
1221
3737
|
const url = getResourceUrl(data);
|
|
1222
3738
|
const parse2 = () => {
|
|
1223
3739
|
throw new Error("parseSync called parse (which is async");
|
|
1224
3740
|
};
|
|
1225
3741
|
context = getLoaderContext({ url, _parseSync: parse2, _parse: parse2, loaders }, strictOptions, context || null);
|
|
1226
|
-
|
|
3742
|
+
const loaderWithParser = getLoaderImplementationSync(loader);
|
|
3743
|
+
return parseWithLoaderSync(loaderWithParser || loader, data, strictOptions, context);
|
|
1227
3744
|
}
|
|
1228
3745
|
function parseWithLoaderSync(loader, data, options, context) {
|
|
1229
3746
|
data = getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
@@ -1233,13 +3750,58 @@ function parseWithLoaderSync(loader, data, options, context) {
|
|
|
1233
3750
|
if (loader.parseSync && data instanceof ArrayBuffer) {
|
|
1234
3751
|
return loader.parseSync(data, options, context);
|
|
1235
3752
|
}
|
|
3753
|
+
if (loader.preload) {
|
|
3754
|
+
throw new Error(`${loader.name} loader: 'parseSync' requires a parser-bearing loader. Import the loader implementation directly, or call preload(loader) before parseSync(). ${context.url || ""}`);
|
|
3755
|
+
}
|
|
1236
3756
|
throw new Error(`${loader.name} loader: 'parseSync' not supported by this loader, use 'parse' instead. ${context.url || ""}`);
|
|
1237
3757
|
}
|
|
1238
3758
|
|
|
3759
|
+
// ../schema-utils/src/lib/table/tables/table-accessors.ts
|
|
3760
|
+
function isTable(table) {
|
|
3761
|
+
var _a;
|
|
3762
|
+
const shape = typeof table === "object" && (table == null ? void 0 : table.shape);
|
|
3763
|
+
switch (shape) {
|
|
3764
|
+
case "array-row-table":
|
|
3765
|
+
case "object-row-table":
|
|
3766
|
+
return Array.isArray(table.data);
|
|
3767
|
+
case "geojson-table":
|
|
3768
|
+
return Array.isArray(table.features);
|
|
3769
|
+
case "columnar-table":
|
|
3770
|
+
return Boolean(table.data && typeof table.data === "object");
|
|
3771
|
+
case "arrow-table":
|
|
3772
|
+
return Boolean(((_a = table == null ? void 0 : table.data) == null ? void 0 : _a.numRows) !== void 0);
|
|
3773
|
+
default:
|
|
3774
|
+
return false;
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
function getTableLength(table) {
|
|
3778
|
+
switch (table.shape) {
|
|
3779
|
+
case "array-row-table":
|
|
3780
|
+
case "object-row-table":
|
|
3781
|
+
return table.data.length;
|
|
3782
|
+
case "geojson-table":
|
|
3783
|
+
return table.features.length;
|
|
3784
|
+
case "arrow-table":
|
|
3785
|
+
const arrowTable = table.data;
|
|
3786
|
+
return arrowTable.numRows;
|
|
3787
|
+
case "columnar-table":
|
|
3788
|
+
for (const column of Object.values(table.data)) {
|
|
3789
|
+
return column.length || 0;
|
|
3790
|
+
}
|
|
3791
|
+
return 0;
|
|
3792
|
+
default:
|
|
3793
|
+
throw new Error("table");
|
|
3794
|
+
}
|
|
3795
|
+
}
|
|
3796
|
+
|
|
3797
|
+
// ../schema-utils/src/lib/table/batches/make-table-batch-iterator.ts
|
|
3798
|
+
function makeBatchFromTable(table) {
|
|
3799
|
+
return { ...table, length: getTableLength(table), batchType: "data" };
|
|
3800
|
+
}
|
|
3801
|
+
|
|
1239
3802
|
// dist/lib/api/parse-in-batches.js
|
|
1240
|
-
var import_schema_utils = require("@loaders.gl/schema-utils");
|
|
1241
|
-
var import_loader_utils15 = require("@loaders.gl/loader-utils");
|
|
1242
3803
|
async function parseInBatches(data, loaders, options, context) {
|
|
3804
|
+
var _a, _b;
|
|
1243
3805
|
const loaderArray = Array.isArray(loaders) ? loaders : void 0;
|
|
1244
3806
|
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
1245
3807
|
context = void 0;
|
|
@@ -1253,11 +3815,14 @@ async function parseInBatches(data, loaders, options, context) {
|
|
|
1253
3815
|
if (!loader) {
|
|
1254
3816
|
return [];
|
|
1255
3817
|
}
|
|
1256
|
-
const
|
|
3818
|
+
const normalizedOptions = normalizeOptions(options, loader, loaderArray, url);
|
|
3819
|
+
const authenticationLoader = !loader.getAuthentications && ((_b = (_a = normalizedOptions.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) ? await getLoaderImplementation(loader, normalizedOptions, url || (context == null ? void 0 : context.url)) : loader;
|
|
3820
|
+
const strictOptions = await resolveLoaderAuthenticationOptions(authenticationLoader, url || "", normalizedOptions);
|
|
1257
3821
|
context = getLoaderContext({ url, _parseInBatches: parseInBatches, _parse: parse, loaders: loaderArray }, strictOptions, context || null);
|
|
1258
|
-
|
|
3822
|
+
const loaderWithParser = await getLoaderImplementation(loader, strictOptions, context.url);
|
|
3823
|
+
return await parseWithLoaderInBatches(loader, loaderWithParser, data, strictOptions, context);
|
|
1259
3824
|
}
|
|
1260
|
-
async function parseWithLoaderInBatches(loader, data, options, context) {
|
|
3825
|
+
async function parseWithLoaderInBatches(originalLoader, loader, data, options, context) {
|
|
1261
3826
|
var _a;
|
|
1262
3827
|
const outputIterator = await parseToOutputIterator(loader, data, options, context);
|
|
1263
3828
|
if (!((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.metadata)) {
|
|
@@ -1267,7 +3832,7 @@ async function parseWithLoaderInBatches(loader, data, options, context) {
|
|
|
1267
3832
|
shape: "metadata",
|
|
1268
3833
|
batchType: "metadata",
|
|
1269
3834
|
metadata: {
|
|
1270
|
-
_loader:
|
|
3835
|
+
_loader: originalLoader,
|
|
1271
3836
|
_context: context
|
|
1272
3837
|
},
|
|
1273
3838
|
// Populate with some default fields to avoid crashing
|
|
@@ -1285,12 +3850,15 @@ async function parseToOutputIterator(loader, data, options, context) {
|
|
|
1285
3850
|
const inputIterator = await getAsyncIterableFromData(data, options);
|
|
1286
3851
|
const transformedIterator = await applyInputTransforms(inputIterator, ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.transforms) || []);
|
|
1287
3852
|
if (loader.parseInBatches) {
|
|
3853
|
+
if (loader.id === "csv" && isBrowser && canParseWithWorker(loader, options)) {
|
|
3854
|
+
return parseWithWorkerInBatches(loader, transformedIterator, options, context, parse);
|
|
3855
|
+
}
|
|
1288
3856
|
return loader.parseInBatches(transformedIterator, options, context);
|
|
1289
3857
|
}
|
|
1290
3858
|
return parseChunkInBatches(transformedIterator, loader, options, context);
|
|
1291
3859
|
}
|
|
1292
3860
|
async function* parseChunkInBatches(transformedIterator, loader, options, context) {
|
|
1293
|
-
const arrayBuffer = await
|
|
3861
|
+
const arrayBuffer = await concatenateArrayBuffersAsync(transformedIterator);
|
|
1294
3862
|
const parsedData = await parse(
|
|
1295
3863
|
arrayBuffer,
|
|
1296
3864
|
loader,
|
|
@@ -1302,7 +3870,7 @@ async function* parseChunkInBatches(transformedIterator, loader, options, contex
|
|
|
1302
3870
|
yield batch;
|
|
1303
3871
|
}
|
|
1304
3872
|
function convertDataToBatch(parsedData, loader) {
|
|
1305
|
-
const batch =
|
|
3873
|
+
const batch = isTable(parsedData) ? makeBatchFromTable(parsedData) : {
|
|
1306
3874
|
shape: "unknown",
|
|
1307
3875
|
batchType: "data",
|
|
1308
3876
|
data: parsedData,
|
|
@@ -1319,8 +3887,40 @@ async function applyInputTransforms(inputIterator, transforms = []) {
|
|
|
1319
3887
|
return iteratorChain;
|
|
1320
3888
|
}
|
|
1321
3889
|
|
|
3890
|
+
// dist/lib/api/load-in-batches.js
|
|
3891
|
+
function loadInBatches(files, loaders, options, context) {
|
|
3892
|
+
let loadersArray;
|
|
3893
|
+
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
3894
|
+
context = void 0;
|
|
3895
|
+
options = loaders;
|
|
3896
|
+
loadersArray = void 0;
|
|
3897
|
+
} else {
|
|
3898
|
+
loadersArray = loaders;
|
|
3899
|
+
}
|
|
3900
|
+
if (!Array.isArray(files)) {
|
|
3901
|
+
return loadOneFileInBatches(files, loadersArray, options || {});
|
|
3902
|
+
}
|
|
3903
|
+
const promises = files.map((file) => loadOneFileInBatches(file, loadersArray, options || {}));
|
|
3904
|
+
return promises;
|
|
3905
|
+
}
|
|
3906
|
+
async function loadOneFileInBatches(file, loaders, options) {
|
|
3907
|
+
var _a, _b;
|
|
3908
|
+
if (typeof file === "string") {
|
|
3909
|
+
const url = file;
|
|
3910
|
+
const loader = await selectLoader(url, loaders, {
|
|
3911
|
+
...options,
|
|
3912
|
+
core: { ...options.core, nothrow: true }
|
|
3913
|
+
});
|
|
3914
|
+
const authenticationLoader = loader && !loader.getAuthentications && ((_b = (_a = options.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) ? await getLoaderImplementation(loader, options, url) : loader;
|
|
3915
|
+
options = await resolveLoaderAuthenticationOptions(authenticationLoader, url, options);
|
|
3916
|
+
const fetch2 = getFetchFunction(options);
|
|
3917
|
+
const response = await fetch2(applySearchParamsToUrl(url, options));
|
|
3918
|
+
return Array.isArray(loaders) ? await parseInBatches(response, loaders, options) : await parseInBatches(response, loaders, options);
|
|
3919
|
+
}
|
|
3920
|
+
return Array.isArray(loaders) ? await parseInBatches(file, loaders, options) : await parseInBatches(file, loaders, options);
|
|
3921
|
+
}
|
|
3922
|
+
|
|
1322
3923
|
// dist/lib/api/load.js
|
|
1323
|
-
var import_loader_utils16 = require("@loaders.gl/loader-utils");
|
|
1324
3924
|
async function load(url, loaders, options, context) {
|
|
1325
3925
|
var _a;
|
|
1326
3926
|
let resolvedLoaders;
|
|
@@ -1333,12 +3933,71 @@ async function load(url, loaders, options, context) {
|
|
|
1333
3933
|
resolvedLoaders = loaders;
|
|
1334
3934
|
resolvedOptions = options;
|
|
1335
3935
|
}
|
|
3936
|
+
resolvedOptions ||= getGlobalLoaderOptions();
|
|
3937
|
+
if (!Array.isArray(resolvedLoaders) && isSourceLoader(resolvedLoaders)) {
|
|
3938
|
+
const sourceLoader = await resolveSourceLoader(resolvedLoaders, url, resolvedOptions);
|
|
3939
|
+
resolvedOptions = await resolveLoaderAuthenticationOptions(resolvedLoaders.getAuthentications ? resolvedLoaders : sourceLoader, typeof url === "string" ? url : "", resolvedOptions || {});
|
|
3940
|
+
const runtimeCoreApi = {
|
|
3941
|
+
fetchFile,
|
|
3942
|
+
parse,
|
|
3943
|
+
parseFile,
|
|
3944
|
+
parseSync,
|
|
3945
|
+
parseInBatches,
|
|
3946
|
+
load,
|
|
3947
|
+
loadInBatches
|
|
3948
|
+
};
|
|
3949
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, runtimeCoreApi);
|
|
3950
|
+
}
|
|
3951
|
+
if (Array.isArray(resolvedLoaders) && resolvedLoaders.length === 1 && isSourceLoader(resolvedLoaders[0])) {
|
|
3952
|
+
const sourceLoader = await resolveSourceLoader(resolvedLoaders[0], url, resolvedOptions);
|
|
3953
|
+
resolvedOptions = await resolveLoaderAuthenticationOptions(resolvedLoaders[0].getAuthentications ? resolvedLoaders[0] : sourceLoader, typeof url === "string" ? url : "", resolvedOptions || {});
|
|
3954
|
+
const runtimeCoreApi = {
|
|
3955
|
+
fetchFile,
|
|
3956
|
+
parse,
|
|
3957
|
+
parseFile,
|
|
3958
|
+
parseSync,
|
|
3959
|
+
parseInBatches,
|
|
3960
|
+
load,
|
|
3961
|
+
loadInBatches
|
|
3962
|
+
};
|
|
3963
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, runtimeCoreApi);
|
|
3964
|
+
}
|
|
3965
|
+
if (typeof url === "string" || isBlob(url)) {
|
|
3966
|
+
const selectedLoader = await selectLoader(url, resolvedLoaders, {
|
|
3967
|
+
...resolvedOptions,
|
|
3968
|
+
core: { ...resolvedOptions == null ? void 0 : resolvedOptions.core, nothrow: true }
|
|
3969
|
+
});
|
|
3970
|
+
if (selectedLoader && isSourceLoader(selectedLoader)) {
|
|
3971
|
+
const sourceLoader = await resolveSourceLoader(selectedLoader, url, resolvedOptions);
|
|
3972
|
+
resolvedOptions = await resolveLoaderAuthenticationOptions(selectedLoader.getAuthentications ? selectedLoader : sourceLoader, typeof url === "string" ? url : "", resolvedOptions || {});
|
|
3973
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, {
|
|
3974
|
+
fetchFile,
|
|
3975
|
+
parse,
|
|
3976
|
+
parseFile,
|
|
3977
|
+
parseSync,
|
|
3978
|
+
parseInBatches,
|
|
3979
|
+
load,
|
|
3980
|
+
loadInBatches
|
|
3981
|
+
});
|
|
3982
|
+
}
|
|
3983
|
+
if (selectedLoader && typeof url === "string") {
|
|
3984
|
+
const loaderImplementation = await getLoaderImplementation(selectedLoader, resolvedOptions, url);
|
|
3985
|
+
resolvedOptions = await resolveLoaderAuthenticationOptions(selectedLoader.getAuthentications ? selectedLoader : loaderImplementation, url, resolvedOptions || {});
|
|
3986
|
+
const parseUrl = loaderImplementation.parseUrl;
|
|
3987
|
+
if (parseUrl) {
|
|
3988
|
+
const requestUrl = applySearchParamsToUrl(url, resolvedOptions);
|
|
3989
|
+
return await parseUrl(requestUrl, resolvedOptions, context);
|
|
3990
|
+
}
|
|
3991
|
+
}
|
|
3992
|
+
}
|
|
3993
|
+
if (resolvedOptions)
|
|
3994
|
+
resolvedOptions = resolveAuthenticationOptions(resolvedOptions);
|
|
1336
3995
|
const fetch2 = getFetchFunction(resolvedOptions);
|
|
1337
3996
|
let data = url;
|
|
1338
3997
|
if (typeof url === "string") {
|
|
1339
|
-
data = await fetch2(url);
|
|
3998
|
+
data = await fetch2(applySearchParamsToUrl(url, resolvedOptions));
|
|
1340
3999
|
}
|
|
1341
|
-
if (
|
|
4000
|
+
if (isBlob(url)) {
|
|
1342
4001
|
data = await fetch2(url);
|
|
1343
4002
|
}
|
|
1344
4003
|
if (typeof url === "string") {
|
|
@@ -1353,44 +4012,154 @@ async function load(url, loaders, options, context) {
|
|
|
1353
4012
|
};
|
|
1354
4013
|
}
|
|
1355
4014
|
}
|
|
1356
|
-
return Array.isArray(resolvedLoaders) ? await parse(data, resolvedLoaders, resolvedOptions) : await parse(data, resolvedLoaders, resolvedOptions);
|
|
4015
|
+
return Array.isArray(resolvedLoaders) ? await parse(data, resolvedLoaders, resolvedOptions, context) : await parse(data, resolvedLoaders, resolvedOptions, context);
|
|
4016
|
+
}
|
|
4017
|
+
async function resolveSourceLoader(loader, url, options) {
|
|
4018
|
+
if (!loader.preload) {
|
|
4019
|
+
return loader;
|
|
4020
|
+
}
|
|
4021
|
+
const sourceLoader = await loader.preload(typeof url === "string" ? url : "", options);
|
|
4022
|
+
if (!isSourceLoader(sourceLoader)) {
|
|
4023
|
+
throw new Error(`${loader.id} source loader preload() did not return a runtime source loader`);
|
|
4024
|
+
}
|
|
4025
|
+
return sourceLoader;
|
|
1357
4026
|
}
|
|
1358
4027
|
|
|
1359
|
-
// dist/lib/api/
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
4028
|
+
// dist/lib/api/core-api.js
|
|
4029
|
+
var coreApi = Object.freeze({
|
|
4030
|
+
fetchFile,
|
|
4031
|
+
parse,
|
|
4032
|
+
parseFile,
|
|
4033
|
+
parseSync,
|
|
4034
|
+
parseInBatches,
|
|
4035
|
+
load,
|
|
4036
|
+
loadInBatches
|
|
4037
|
+
});
|
|
4038
|
+
|
|
4039
|
+
// dist/lib/loader-utils/loader-context.js
|
|
4040
|
+
function getLoaderContext(context, options, parentContext) {
|
|
4041
|
+
if (parentContext) {
|
|
4042
|
+
return {
|
|
4043
|
+
...parentContext,
|
|
4044
|
+
coreApi: parentContext.coreApi || context.coreApi || coreApi,
|
|
4045
|
+
_parse: parentContext._parse || context._parse,
|
|
4046
|
+
fetch: getFetchFunction(options, parentContext)
|
|
4047
|
+
};
|
|
4048
|
+
}
|
|
4049
|
+
const newContext = {
|
|
4050
|
+
...context,
|
|
4051
|
+
fetch: getFetchFunction(options, context),
|
|
4052
|
+
coreApi: context.coreApi || coreApi
|
|
4053
|
+
};
|
|
4054
|
+
if (newContext.url) {
|
|
4055
|
+
const baseUrl = stripQueryString(newContext.url);
|
|
4056
|
+
newContext.baseUrl = baseUrl;
|
|
4057
|
+
newContext.queryString = extractQueryString(newContext.url);
|
|
4058
|
+
newContext.filename = path_exports.filename(baseUrl);
|
|
4059
|
+
newContext.baseUrl = path_exports.dirname(baseUrl);
|
|
4060
|
+
}
|
|
4061
|
+
if (!Array.isArray(newContext.loaders)) {
|
|
4062
|
+
newContext.loaders = null;
|
|
4063
|
+
}
|
|
4064
|
+
return newContext;
|
|
4065
|
+
}
|
|
4066
|
+
function getLoadersFromContext(loaders, context) {
|
|
4067
|
+
if (loaders && !Array.isArray(loaders)) {
|
|
4068
|
+
return loaders;
|
|
4069
|
+
}
|
|
4070
|
+
let candidateLoaders;
|
|
4071
|
+
if (loaders) {
|
|
4072
|
+
candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
4073
|
+
}
|
|
4074
|
+
if (context && context.loaders) {
|
|
4075
|
+
const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];
|
|
4076
|
+
candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
|
|
4077
|
+
}
|
|
4078
|
+
return candidateLoaders && candidateLoaders.length ? candidateLoaders : void 0;
|
|
4079
|
+
}
|
|
4080
|
+
|
|
4081
|
+
// dist/lib/api/parse.js
|
|
4082
|
+
async function parse(data, loaders, options, context) {
|
|
4083
|
+
var _a, _b;
|
|
4084
|
+
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
1363
4085
|
context = void 0;
|
|
1364
4086
|
options = loaders;
|
|
1365
|
-
|
|
1366
|
-
} else {
|
|
1367
|
-
loadersArray = loaders;
|
|
4087
|
+
loaders = void 0;
|
|
1368
4088
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
4089
|
+
data = await data;
|
|
4090
|
+
options = options || {};
|
|
4091
|
+
const url = getResourceUrl(data);
|
|
4092
|
+
const typedLoaders = loaders;
|
|
4093
|
+
const candidateLoaders = getLoadersFromContext(typedLoaders, context);
|
|
4094
|
+
const loader = await selectLoader(data, candidateLoaders, options);
|
|
4095
|
+
if (!loader) {
|
|
4096
|
+
return null;
|
|
1372
4097
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
4098
|
+
if (isSourceLoader(loader)) {
|
|
4099
|
+
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parse().`);
|
|
4100
|
+
}
|
|
4101
|
+
const normalizedOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
4102
|
+
const authenticationLoader = !loader.getAuthentications && ((_b = (_a = normalizedOptions.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) ? await getLoaderImplementation(loader, normalizedOptions, url || (context == null ? void 0 : context.url)) : loader;
|
|
4103
|
+
const strictOptions = await resolveLoaderAuthenticationOptions(authenticationLoader, url || "", normalizedOptions);
|
|
4104
|
+
context = getLoaderContext(
|
|
4105
|
+
// @ts-expect-error
|
|
4106
|
+
{ url, _parse: parse, loaders: candidateLoaders },
|
|
4107
|
+
strictOptions,
|
|
4108
|
+
context || null
|
|
4109
|
+
);
|
|
4110
|
+
return await parseWithLoader(loader, data, strictOptions, context);
|
|
1375
4111
|
}
|
|
1376
|
-
async function
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
4112
|
+
async function parseWithLoader(loader, data, options, context) {
|
|
4113
|
+
validateWorkerVersion(loader);
|
|
4114
|
+
options = mergeOptions(loader.options, options);
|
|
4115
|
+
if (isResponse(data)) {
|
|
4116
|
+
const { ok, redirected, status, statusText, type, url } = data;
|
|
4117
|
+
const headers = Object.fromEntries(data.headers.entries());
|
|
4118
|
+
context.response = { headers, ok, redirected, status, statusText, type, url };
|
|
1381
4119
|
}
|
|
1382
|
-
|
|
4120
|
+
const loaderWithParser = await getLoaderImplementation(loader, options, context.url);
|
|
4121
|
+
if (shouldParseWithWorker(loaderWithParser, data, options, context, loader)) {
|
|
4122
|
+
data = await getArrayBufferFromData(data, options);
|
|
4123
|
+
return await parseWithWorker(loaderWithParser, data, options, context, parse);
|
|
4124
|
+
}
|
|
4125
|
+
if (isBlob(data) && loaderWithParser.parseBlob) {
|
|
4126
|
+
return await loaderWithParser.parseBlob(data, options, context);
|
|
4127
|
+
}
|
|
4128
|
+
data = await getArrayBufferOrStringFromData(data, loader, options);
|
|
4129
|
+
return await parseWithLoaderImplementation(loaderWithParser, data, options, context);
|
|
4130
|
+
}
|
|
4131
|
+
async function parseWithLoaderImplementation(loader, data, options, context) {
|
|
4132
|
+
if (loader.parseText && typeof data === "string") {
|
|
4133
|
+
return await loader.parseText(data, options, context);
|
|
4134
|
+
}
|
|
4135
|
+
if (loader.parseTextSync && typeof data === "string") {
|
|
4136
|
+
return loader.parseTextSync(data, options, context);
|
|
4137
|
+
}
|
|
4138
|
+
if (loader.parse) {
|
|
4139
|
+
return await loader.parse(data, options, context);
|
|
4140
|
+
}
|
|
4141
|
+
if (loader.parseSync) {
|
|
4142
|
+
throw new Error(`${loader.name} loader: 'parse' not available on parser-bearing sync loader. Add an async 'parse' function to this loader, or call preload(loader) before parseSync(). ${context.url || ""}`);
|
|
4143
|
+
}
|
|
4144
|
+
throw new Error(`${loader.id} loader - no parser found and worker is disabled`);
|
|
4145
|
+
}
|
|
4146
|
+
|
|
4147
|
+
// dist/lib/api/preload.js
|
|
4148
|
+
async function preload(loader, options, url) {
|
|
4149
|
+
return loader.subloaders ? await preloadLoaderDependencies(loader, options, url) : await getLoaderImplementation(loader, options, url);
|
|
4150
|
+
}
|
|
4151
|
+
function preloadSync(loader) {
|
|
4152
|
+
return getLoaderImplementationSync(loader);
|
|
1383
4153
|
}
|
|
1384
4154
|
|
|
1385
4155
|
// dist/lib/api/encode-table.js
|
|
1386
|
-
var import_loader_utils17 = require("@loaders.gl/loader-utils");
|
|
1387
4156
|
async function encodeTable(data, writer, options) {
|
|
1388
4157
|
if (writer.encode) {
|
|
1389
4158
|
return await writer.encode(data, options);
|
|
1390
4159
|
}
|
|
1391
4160
|
if (writer.encodeText) {
|
|
1392
4161
|
const text = await writer.encodeText(data, options);
|
|
1393
|
-
return
|
|
4162
|
+
return ensureArrayBuffer(new TextEncoder().encode(text));
|
|
1394
4163
|
}
|
|
1395
4164
|
if (writer.encodeInBatches) {
|
|
1396
4165
|
const batches = encodeTableInBatches(data, writer, options);
|
|
@@ -1398,7 +4167,7 @@ async function encodeTable(data, writer, options) {
|
|
|
1398
4167
|
for await (const batch of batches) {
|
|
1399
4168
|
chunks.push(batch);
|
|
1400
4169
|
}
|
|
1401
|
-
return
|
|
4170
|
+
return concatenateArrayBuffers(...chunks);
|
|
1402
4171
|
}
|
|
1403
4172
|
throw new Error("Writer could not encode data");
|
|
1404
4173
|
}
|
|
@@ -1425,16 +4194,14 @@ function getIterator(data) {
|
|
|
1425
4194
|
}
|
|
1426
4195
|
|
|
1427
4196
|
// dist/lib/api/encode.js
|
|
1428
|
-
var import_loader_utils18 = require("@loaders.gl/loader-utils");
|
|
1429
|
-
var import_worker_utils2 = require("@loaders.gl/worker-utils");
|
|
1430
4197
|
async function encode(data, writer, options_) {
|
|
1431
4198
|
const globalOptions = getGlobalLoaderOptions();
|
|
1432
4199
|
const options = { ...globalOptions, ...options_ };
|
|
1433
4200
|
if (writer.encodeURLtoURL) {
|
|
1434
4201
|
return encodeWithCommandLineTool(writer, data, options);
|
|
1435
4202
|
}
|
|
1436
|
-
if (
|
|
1437
|
-
return await
|
|
4203
|
+
if (canEncodeWithWorker(writer, options)) {
|
|
4204
|
+
return await processOnWorker(writer, data, options);
|
|
1438
4205
|
}
|
|
1439
4206
|
return await writer.encode(data, options);
|
|
1440
4207
|
}
|
|
@@ -1443,7 +4210,7 @@ function encodeSync(data, writer, options) {
|
|
|
1443
4210
|
return writer.encodeSync(data, options);
|
|
1444
4211
|
}
|
|
1445
4212
|
if (writer.encodeTextSync) {
|
|
1446
|
-
return
|
|
4213
|
+
return ensureArrayBuffer(new TextEncoder().encode(writer.encodeTextSync(data, options)));
|
|
1447
4214
|
}
|
|
1448
4215
|
throw new Error(`Writer ${writer.name} could not synchronously encode data`);
|
|
1449
4216
|
}
|
|
@@ -1478,20 +4245,20 @@ function encodeInBatches(data, writer, options) {
|
|
|
1478
4245
|
throw new Error(`Writer ${writer.name} could not encode in batches`);
|
|
1479
4246
|
}
|
|
1480
4247
|
async function encodeURLtoURL(inputUrl, outputUrl, writer, options) {
|
|
1481
|
-
inputUrl =
|
|
1482
|
-
outputUrl =
|
|
1483
|
-
if (
|
|
4248
|
+
inputUrl = resolvePath(inputUrl);
|
|
4249
|
+
outputUrl = resolvePath(outputUrl);
|
|
4250
|
+
if (isBrowser || !writer.encodeURLtoURL) {
|
|
1484
4251
|
throw new Error();
|
|
1485
4252
|
}
|
|
1486
4253
|
const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);
|
|
1487
4254
|
return outputFilename;
|
|
1488
4255
|
}
|
|
1489
4256
|
async function encodeWithCommandLineTool(writer, data, options) {
|
|
1490
|
-
if (
|
|
4257
|
+
if (isBrowser) {
|
|
1491
4258
|
throw new Error(`Writer ${writer.name} not supported in browser`);
|
|
1492
4259
|
}
|
|
1493
4260
|
const tmpInputFilename = getTemporaryFilename("input");
|
|
1494
|
-
const file = new
|
|
4261
|
+
const file = new NodeFileFacade(tmpInputFilename, "w");
|
|
1495
4262
|
await file.write(data);
|
|
1496
4263
|
const tmpOutputFilename = getTemporaryFilename("output");
|
|
1497
4264
|
const outputFilename = await encodeURLtoURL(tmpInputFilename, tmpOutputFilename, writer, options);
|
|
@@ -1502,27 +4269,41 @@ function getIterator2(data) {
|
|
|
1502
4269
|
const dataIterator = [{ ...data, start: 0, end: data.length }];
|
|
1503
4270
|
return dataIterator;
|
|
1504
4271
|
}
|
|
1505
|
-
function getTemporaryFilename(
|
|
1506
|
-
return `/tmp/${
|
|
4272
|
+
function getTemporaryFilename(filename2) {
|
|
4273
|
+
return `/tmp/${filename2}`;
|
|
1507
4274
|
}
|
|
1508
4275
|
|
|
1509
4276
|
// dist/lib/api/create-data-source.js
|
|
1510
|
-
function createDataSource(data, sources, options) {
|
|
1511
|
-
var _a;
|
|
1512
|
-
const
|
|
1513
|
-
const
|
|
4277
|
+
function createDataSource(data, sources, options = {}) {
|
|
4278
|
+
var _a, _b, _c, _d, _e;
|
|
4279
|
+
const resolvedOptions = options || {};
|
|
4280
|
+
const type = ((_a = resolvedOptions == null ? void 0 : resolvedOptions.core) == null ? void 0 : _a.type) || resolvedOptions.type || "auto";
|
|
4281
|
+
const source = sources.length === 1 ? sources[0] : type === "auto" ? selectLoaderSync(data, sources, {
|
|
4282
|
+
// `createDataSource` supports non-fetch inputs such as in-memory tables.
|
|
4283
|
+
// Selection remains best-effort for those cases.
|
|
4284
|
+
...resolvedOptions,
|
|
4285
|
+
core: { ...resolvedOptions == null ? void 0 : resolvedOptions.core, type: "auto" }
|
|
4286
|
+
}) : getSourceOfType(type, sources);
|
|
1514
4287
|
if (!source) {
|
|
1515
4288
|
throw new Error("Not a valid source type");
|
|
1516
4289
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
4290
|
+
const contributions = ((_c = (_b = resolvedOptions.core) == null ? void 0 : _b.credentials) == null ? void 0 : _c.length) ? (_d = source.getAuthentications) == null ? void 0 : _d.call(source, typeof data === "string" ? data : "", resolvedOptions) : void 0;
|
|
4291
|
+
if (contributions && "then" in contributions) {
|
|
4292
|
+
void contributions.catch(() => {
|
|
4293
|
+
});
|
|
4294
|
+
throw new Error("Use load() with an asynchronous getAuthentications() hook.");
|
|
4295
|
+
}
|
|
4296
|
+
const authenticatedOptions = resolveAuthenticationOptions((contributions == null ? void 0 : contributions.length) ? {
|
|
4297
|
+
...resolvedOptions,
|
|
4298
|
+
core: {
|
|
4299
|
+
...resolvedOptions.core,
|
|
4300
|
+
authentications: [
|
|
4301
|
+
...((_e = resolvedOptions.core) == null ? void 0 : _e.authentications) || [],
|
|
4302
|
+
...contributions || []
|
|
4303
|
+
]
|
|
1523
4304
|
}
|
|
1524
|
-
}
|
|
1525
|
-
return
|
|
4305
|
+
} : resolvedOptions);
|
|
4306
|
+
return source.createDataSource(data, authenticatedOptions, coreApi);
|
|
1526
4307
|
}
|
|
1527
4308
|
function getSourceOfType(type, sources) {
|
|
1528
4309
|
for (const service of sources) {
|
|
@@ -1534,15 +4315,11 @@ function getSourceOfType(type, sources) {
|
|
|
1534
4315
|
}
|
|
1535
4316
|
|
|
1536
4317
|
// dist/lib/api/select-source.js
|
|
1537
|
-
function
|
|
4318
|
+
function selectSource(url, sources, options) {
|
|
1538
4319
|
const type = (options == null ? void 0 : options.type) || "auto";
|
|
1539
4320
|
let selectedSource = null;
|
|
1540
4321
|
if (type === "auto") {
|
|
1541
|
-
|
|
1542
|
-
if (typeof url === "string" && source.testURL && source.testURL(url)) {
|
|
1543
|
-
return source;
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
4322
|
+
selectedSource = selectLoaderSync(url, sources, { core: { nothrow: true } });
|
|
1546
4323
|
} else {
|
|
1547
4324
|
selectedSource = getSourceOfType2(type, sources);
|
|
1548
4325
|
}
|
|
@@ -1560,10 +4337,6 @@ function getSourceOfType2(type, sources) {
|
|
|
1560
4337
|
return null;
|
|
1561
4338
|
}
|
|
1562
4339
|
|
|
1563
|
-
// dist/index.js
|
|
1564
|
-
var import_loader_utils20 = require("@loaders.gl/loader-utils");
|
|
1565
|
-
var import_loader_utils21 = require("@loaders.gl/loader-utils");
|
|
1566
|
-
|
|
1567
4340
|
// dist/iterators/make-stream/make-stream.js
|
|
1568
4341
|
function makeStream(source, options) {
|
|
1569
4342
|
if (globalThis.loaders.makeNodeStream) {
|
|
@@ -1604,14 +4377,14 @@ function makeStream(source, options) {
|
|
|
1604
4377
|
}
|
|
1605
4378
|
|
|
1606
4379
|
// dist/null-loader.js
|
|
1607
|
-
var
|
|
4380
|
+
var VERSION4 = true ? "5.0.0-alpha.10" : "latest";
|
|
1608
4381
|
var NullWorkerLoader = {
|
|
1609
4382
|
dataType: null,
|
|
1610
4383
|
batchType: null,
|
|
1611
4384
|
name: "Null loader",
|
|
1612
4385
|
id: "null",
|
|
1613
4386
|
module: "core",
|
|
1614
|
-
version:
|
|
4387
|
+
version: VERSION4,
|
|
1615
4388
|
worker: true,
|
|
1616
4389
|
mimeTypes: ["application/x.empty"],
|
|
1617
4390
|
extensions: ["null"],
|
|
@@ -1626,7 +4399,7 @@ var NullLoader = {
|
|
|
1626
4399
|
name: "Null loader",
|
|
1627
4400
|
id: "null",
|
|
1628
4401
|
module: "core",
|
|
1629
|
-
version:
|
|
4402
|
+
version: VERSION4,
|
|
1630
4403
|
mimeTypes: ["application/x.empty"],
|
|
1631
4404
|
extensions: ["null"],
|
|
1632
4405
|
parse: async (arrayBuffer, options, context) => parseSync2(arrayBuffer, options || {}, context),
|
|
@@ -1645,9 +4418,6 @@ function parseSync2(arrayBuffer, options, context) {
|
|
|
1645
4418
|
return null;
|
|
1646
4419
|
}
|
|
1647
4420
|
|
|
1648
|
-
// dist/index.js
|
|
1649
|
-
var import_loader_utils22 = require("@loaders.gl/loader-utils");
|
|
1650
|
-
|
|
1651
4421
|
// dist/lib/progress/fetch-progress.js
|
|
1652
4422
|
async function fetchProgress(response, onProgress, onDone = () => {
|
|
1653
4423
|
}, onError = () => {
|
|
@@ -1696,7 +4466,6 @@ async function read(controller, reader, loadedBytes, totalBytes, onProgress, onD
|
|
|
1696
4466
|
}
|
|
1697
4467
|
|
|
1698
4468
|
// dist/lib/filesystems/browser-filesystem.js
|
|
1699
|
-
var import_loader_utils19 = require("@loaders.gl/loader-utils");
|
|
1700
4469
|
var BrowserFileSystem = class {
|
|
1701
4470
|
_fetch;
|
|
1702
4471
|
files = {};
|
|
@@ -1722,27 +4491,38 @@ var BrowserFileSystem = class {
|
|
|
1722
4491
|
* Implementation of fetch against this file system
|
|
1723
4492
|
* Delegates to global fetch for http{s}:// or data://
|
|
1724
4493
|
*/
|
|
1725
|
-
async fetch(
|
|
1726
|
-
if (
|
|
1727
|
-
return this._fetch(
|
|
4494
|
+
async fetch(path, options) {
|
|
4495
|
+
if (path.includes("://")) {
|
|
4496
|
+
return this._fetch(path, options);
|
|
1728
4497
|
}
|
|
1729
|
-
const file = this.
|
|
4498
|
+
const file = this._getFile(path, true);
|
|
1730
4499
|
if (!file) {
|
|
1731
|
-
return new Response(
|
|
4500
|
+
return new Response(path, { status: 400, statusText: "NOT FOUND" });
|
|
1732
4501
|
}
|
|
1733
4502
|
const headers = new Headers(options == null ? void 0 : options.headers);
|
|
1734
4503
|
const range = headers.get("Range");
|
|
1735
|
-
const bytes = range && /bytes=(
|
|
4504
|
+
const bytes = range && /bytes=(\d+)-(\d+)/.exec(range);
|
|
1736
4505
|
if (bytes) {
|
|
1737
4506
|
const start = parseInt(bytes[1]);
|
|
1738
|
-
const end = parseInt(bytes[2]);
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
4507
|
+
const end = Math.min(parseInt(bytes[2]), file.size - 1);
|
|
4508
|
+
if (start > end) {
|
|
4509
|
+
const response3 = new Response(null, {
|
|
4510
|
+
status: 416,
|
|
4511
|
+
headers: { "Content-Range": `bytes */${file.size}` }
|
|
4512
|
+
});
|
|
4513
|
+
Object.defineProperty(response3, "url", { value: path });
|
|
4514
|
+
return response3;
|
|
4515
|
+
}
|
|
4516
|
+
const data = await file.slice(start, end + 1).arrayBuffer();
|
|
4517
|
+
const response2 = new Response(data, {
|
|
4518
|
+
status: 206,
|
|
4519
|
+
headers: { "Content-Range": `bytes ${start}-${end}/${file.size}` }
|
|
4520
|
+
});
|
|
4521
|
+
Object.defineProperty(response2, "url", { value: path });
|
|
1742
4522
|
return response2;
|
|
1743
4523
|
}
|
|
1744
4524
|
const response = new Response(file);
|
|
1745
|
-
Object.defineProperty(response, "url", { value:
|
|
4525
|
+
Object.defineProperty(response, "url", { value: path });
|
|
1746
4526
|
return response;
|
|
1747
4527
|
}
|
|
1748
4528
|
/**
|
|
@@ -1750,51 +4530,47 @@ var BrowserFileSystem = class {
|
|
|
1750
4530
|
* @param dirname
|
|
1751
4531
|
* @returns
|
|
1752
4532
|
*/
|
|
1753
|
-
async readdir(
|
|
4533
|
+
async readdir(dirname2) {
|
|
1754
4534
|
const files = [];
|
|
1755
|
-
for (const
|
|
1756
|
-
files.push(
|
|
4535
|
+
for (const path in this.files) {
|
|
4536
|
+
files.push(path);
|
|
1757
4537
|
}
|
|
1758
4538
|
return files;
|
|
1759
4539
|
}
|
|
1760
4540
|
/**
|
|
1761
4541
|
* Return information (size) about files in this file system
|
|
1762
4542
|
*/
|
|
1763
|
-
async stat(
|
|
1764
|
-
const file = this.
|
|
4543
|
+
async stat(path, options) {
|
|
4544
|
+
const file = this._getFile(path, false);
|
|
1765
4545
|
if (!file) {
|
|
1766
|
-
throw new Error(
|
|
4546
|
+
throw new Error(path);
|
|
1767
4547
|
}
|
|
1768
4548
|
return { size: file.size };
|
|
1769
4549
|
}
|
|
1770
4550
|
/**
|
|
1771
4551
|
* Just removes the file from the list
|
|
1772
4552
|
*/
|
|
1773
|
-
async unlink(
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
4553
|
+
async unlink(path) {
|
|
4554
|
+
const file = this._getFile(path, false);
|
|
4555
|
+
if (file) {
|
|
4556
|
+
delete this.files[file.name];
|
|
4557
|
+
delete this.lowerCaseFiles[file.name.toLowerCase()];
|
|
4558
|
+
this.usedFiles[file.name] = true;
|
|
4559
|
+
}
|
|
1777
4560
|
}
|
|
1778
4561
|
// implements IRandomAccessFileSystem
|
|
1779
4562
|
// RANDOM ACCESS
|
|
1780
4563
|
async openReadableFile(pathname, flags) {
|
|
1781
|
-
return new
|
|
4564
|
+
return new BlobFile(this._getFile(pathname, true));
|
|
1782
4565
|
}
|
|
1783
4566
|
// PRIVATE
|
|
1784
4567
|
// Supports case independent paths, and file usage tracking
|
|
1785
|
-
_getFile(
|
|
1786
|
-
const file = this.files[
|
|
4568
|
+
_getFile(path, used) {
|
|
4569
|
+
const file = this.files[path] || this.lowerCaseFiles[path.toLowerCase()];
|
|
1787
4570
|
if (file && used) {
|
|
1788
|
-
this.usedFiles[
|
|
4571
|
+
this.usedFiles[path] = true;
|
|
1789
4572
|
}
|
|
1790
4573
|
return file;
|
|
1791
4574
|
}
|
|
1792
4575
|
};
|
|
1793
|
-
|
|
1794
|
-
// dist/index.js
|
|
1795
|
-
var import_loader_utils23 = require("@loaders.gl/loader-utils");
|
|
1796
|
-
var import_loader_utils24 = require("@loaders.gl/loader-utils");
|
|
1797
|
-
var import_loader_utils25 = require("@loaders.gl/loader-utils");
|
|
1798
|
-
var import_loader_utils26 = require("@loaders.gl/loader-utils");
|
|
1799
|
-
var import_loader_utils27 = require("@loaders.gl/loader-utils");
|
|
1800
4576
|
//# sourceMappingURL=index.cjs.map
|