@loaders.gl/core 3.1.0-alpha.4 → 3.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +3380 -0
- package/dist/core-addons/write-file-browser.d.ts +1 -0
- package/dist/core-addons/write-file-browser.d.ts.map +1 -0
- package/dist/core-addons/write-file-browser.js +60 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +56 -56
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js +14 -119
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js +17 -53
- package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js +12 -53
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-iterator.js +1 -1
- package/dist/es5/iterators/make-iterator/make-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js +24 -161
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-string-iterator.js +13 -41
- package/dist/es5/iterators/make-iterator/make-string-iterator.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-dom-stream.js +24 -69
- package/dist/es5/iterators/make-stream/make-dom-stream.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-node-stream.js +53 -189
- package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/es5/javascript-utils/is-type.js +18 -58
- package/dist/es5/javascript-utils/is-type.js.map +1 -1
- package/dist/es5/lib/api/encode.js +46 -242
- package/dist/es5/lib/api/encode.js.map +1 -1
- package/dist/es5/lib/api/load-in-batches.js +9 -52
- package/dist/es5/lib/api/load-in-batches.js.map +1 -1
- package/dist/es5/lib/api/load.js +15 -60
- package/dist/es5/lib/api/load.js.map +1 -1
- package/dist/es5/lib/api/parse-in-batches.js +81 -333
- package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
- package/dist/es5/lib/api/parse-sync.js +11 -15
- package/dist/es5/lib/api/parse-sync.js.map +1 -1
- package/dist/es5/lib/api/parse.js +50 -142
- package/dist/es5/lib/api/parse.js.map +1 -1
- package/dist/es5/lib/api/register-loaders.js +8 -30
- package/dist/es5/lib/api/register-loaders.js.map +1 -1
- package/dist/es5/lib/api/save.js +4 -37
- package/dist/es5/lib/api/save.js.map +1 -1
- package/dist/es5/lib/api/select-loader.js +74 -209
- package/dist/es5/lib/api/select-loader.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-error-message.js +13 -55
- package/dist/es5/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-file.js +10 -47
- package/dist/es5/lib/fetch/fetch-file.js.map +1 -1
- package/dist/es5/lib/fetch/read-array-buffer.js +19 -80
- package/dist/es5/lib/fetch/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/fetch/read-file.js +2 -3
- package/dist/es5/lib/fetch/read-file.js.map +1 -1
- package/dist/es5/lib/fetch/write-file.js +9 -38
- package/dist/es5/lib/fetch/write-file.js.map +1 -1
- package/dist/es5/lib/filesystems/browser-filesystem.js +77 -266
- package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/es5/lib/filesystems/read-array-buffer.js +6 -43
- package/dist/es5/lib/filesystems/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/init.js +1 -1
- package/dist/es5/lib/init.js.map +1 -1
- package/dist/es5/lib/loader-utils/check-errors.js +12 -50
- package/dist/es5/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-data.js +71 -238
- package/dist/es5/lib/loader-utils/get-data.js.map +1 -1
- package/dist/es5/lib/loader-utils/loader-context.js +8 -19
- package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/es5/lib/loader-utils/loggers.js +36 -81
- package/dist/es5/lib/loader-utils/loggers.js.map +1 -1
- package/dist/es5/lib/loader-utils/normalize-loader.js +7 -13
- package/dist/es5/lib/loader-utils/normalize-loader.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-defaults.js +2 -2
- package/dist/es5/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-utils.js +51 -85
- package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/es5/lib/progress/fetch-progress.js +49 -150
- package/dist/es5/lib/progress/fetch-progress.js.map +1 -1
- package/dist/es5/lib/utils/mime-type-utils.js +4 -4
- package/dist/es5/lib/utils/mime-type-utils.js.map +1 -1
- package/dist/es5/lib/utils/resource-utils.js +4 -4
- package/dist/es5/lib/utils/resource-utils.js.map +1 -1
- package/dist/es5/lib/utils/response-utils.js +88 -215
- package/dist/es5/lib/utils/response-utils.js.map +1 -1
- package/dist/es5/null-loader.js +10 -137
- package/dist/es5/null-loader.js.map +1 -1
- package/dist/esm/lib/api/encode.js +1 -1
- package/dist/esm/lib/api/encode.js.map +1 -1
- package/dist/esm/lib/api/parse-sync.js +1 -1
- package/dist/esm/lib/api/parse-sync.js.map +1 -1
- package/dist/esm/lib/api/parse.js +1 -1
- package/dist/esm/lib/api/parse.js.map +1 -1
- package/dist/esm/lib/api/register-loaders.js.map +1 -1
- package/dist/esm/lib/api/select-loader.js +4 -4
- package/dist/esm/lib/api/select-loader.js.map +1 -1
- package/dist/esm/lib/fetch/fetch-error-message.js +2 -2
- package/dist/esm/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/lib/init.js.map +1 -1
- package/dist/esm/lib/loader-utils/check-errors.js +4 -4
- package/dist/esm/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/esm/lib/loader-utils/option-utils.js +5 -5
- package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/esm/lib/utils/response-utils.js +7 -7
- package/dist/esm/lib/utils/response-utils.js.map +1 -1
- package/dist/esm/null-loader.js +1 -1
- package/dist/esm/null-loader.js.map +1 -1
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +106 -0
- package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts +5 -0
- package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts.map +1 -0
- package/dist/iterators/batch-iterators/timed-batch-iterator.js +22 -0
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +9 -0
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js +27 -0
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts +9 -0
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-blob-iterator.js +21 -0
- package/dist/iterators/make-iterator/make-iterator.d.ts +19 -0
- package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-iterator.js +37 -0
- package/dist/iterators/make-iterator/make-stream-iterator.d.ts +11 -0
- package/dist/iterators/make-iterator/make-stream-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-stream-iterator.js +96 -0
- package/dist/iterators/make-iterator/make-string-iterator.d.ts +9 -0
- package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-string-iterator.js +24 -0
- package/dist/iterators/make-stream/make-dom-stream.d.ts +9 -0
- package/dist/iterators/make-stream/make-dom-stream.d.ts.map +1 -0
- package/dist/iterators/make-stream/make-dom-stream.js +41 -0
- package/dist/iterators/make-stream/make-node-stream.d.ts +7 -0
- package/dist/iterators/make-stream/make-node-stream.d.ts.map +1 -0
- package/dist/iterators/make-stream/make-node-stream.js +58 -0
- package/dist/iterators/make-stream/make-stream.d.ts +9 -0
- package/dist/iterators/make-stream/make-stream.d.ts.map +1 -0
- package/dist/iterators/make-stream/make-stream.js +16 -0
- package/dist/javascript-utils/is-type.d.ts +22 -0
- package/dist/javascript-utils/is-type.d.ts.map +1 -0
- package/dist/javascript-utils/is-type.js +41 -0
- package/dist/lib/api/encode.d.ts +26 -0
- package/dist/lib/api/encode.d.ts.map +1 -0
- package/dist/lib/api/encode.js +111 -0
- package/dist/lib/api/load-in-batches.d.ts +13 -0
- package/dist/lib/api/load-in-batches.d.ts.map +1 -0
- package/dist/lib/api/load-in-batches.js +33 -0
- package/dist/lib/api/load.d.ts +12 -0
- package/dist/lib/api/load.d.ts.map +1 -0
- package/dist/lib/api/load.js +41 -0
- package/dist/lib/api/parse-in-batches.d.ts +10 -0
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -0
- package/dist/lib/api/parse-in-batches.js +120 -0
- package/dist/lib/api/parse-sync.d.ts +10 -0
- package/dist/lib/api/parse-sync.d.ts.map +1 -0
- package/dist/lib/api/parse-sync.js +59 -0
- package/dist/lib/api/parse.d.ts +10 -0
- package/dist/lib/api/parse.d.ts.map +1 -0
- package/dist/lib/api/parse.js +74 -0
- package/dist/lib/api/register-loaders.d.ts +7 -0
- package/dist/lib/api/register-loaders.d.ts.map +1 -0
- package/dist/lib/api/register-loaders.js +35 -0
- package/dist/lib/api/save.d.ts +4 -0
- package/dist/lib/api/save.d.ts.map +1 -0
- package/dist/lib/api/save.js +15 -0
- package/dist/lib/api/select-loader.d.ts +22 -0
- package/dist/lib/api/select-loader.d.ts.map +1 -0
- package/dist/lib/api/select-loader.js +239 -0
- package/dist/lib/api/set-loader-options.d.ts +6 -0
- package/dist/lib/api/set-loader-options.d.ts.map +1 -0
- package/dist/lib/api/set-loader-options.js +12 -0
- package/dist/lib/common.d.ts +2 -0
- package/dist/lib/common.d.ts.map +1 -0
- package/dist/lib/common.js +2 -0
- package/dist/lib/fetch/fetch-error-message.d.ts +3 -0
- package/dist/lib/fetch/fetch-error-message.d.ts.map +1 -0
- package/dist/lib/fetch/fetch-error-message.js +25 -0
- package/dist/lib/fetch/fetch-file.d.ts +13 -0
- package/dist/lib/fetch/fetch-file.d.ts.map +1 -0
- package/dist/lib/fetch/fetch-file.js +27 -0
- package/dist/lib/fetch/read-array-buffer.d.ts +17 -0
- package/dist/lib/fetch/read-array-buffer.d.ts.map +1 -0
- package/dist/lib/fetch/read-array-buffer.js +41 -0
- package/dist/lib/fetch/read-file.d.ts +5 -0
- package/dist/lib/fetch/read-file.d.ts.map +1 -0
- package/dist/lib/fetch/read-file.js +29 -0
- package/dist/lib/fetch/write-file.d.ts +3 -0
- package/dist/lib/fetch/write-file.d.ts.map +1 -0
- package/dist/lib/fetch/write-file.js +22 -0
- package/dist/lib/filesystems/browser-filesystem.d.ts +58 -0
- package/dist/lib/filesystems/browser-filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/browser-filesystem.js +126 -0
- package/dist/lib/filesystems/filesystem.d.ts +46 -0
- package/dist/lib/filesystems/filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/filesystem.js +2 -0
- package/dist/lib/filesystems/read-array-buffer.d.ts +19 -0
- package/dist/lib/filesystems/read-array-buffer.d.ts.map +1 -0
- package/dist/lib/filesystems/read-array-buffer.js +29 -0
- package/dist/lib/init.d.ts +3 -0
- package/dist/lib/init.d.ts.map +1 -0
- package/dist/lib/init.js +10 -0
- package/dist/lib/loader-utils/check-errors.d.ts +3 -0
- package/dist/lib/loader-utils/check-errors.d.ts.map +1 -0
- package/dist/lib/loader-utils/check-errors.js +30 -0
- package/dist/lib/loader-utils/get-data.d.ts +6 -0
- package/dist/lib/loader-utils/get-data.d.ts.map +1 -0
- package/dist/lib/loader-utils/get-data.js +129 -0
- package/dist/lib/loader-utils/loader-context.d.ts +13 -0
- package/dist/lib/loader-utils/loader-context.d.ts.map +1 -0
- package/dist/lib/loader-utils/loader-context.js +49 -0
- package/dist/lib/loader-utils/loggers.d.ts +16 -0
- package/dist/lib/loader-utils/loggers.d.ts.map +1 -0
- package/dist/lib/loader-utils/loggers.js +41 -0
- package/dist/lib/loader-utils/normalize-loader.d.ts +4 -0
- package/dist/lib/loader-utils/normalize-loader.d.ts.map +1 -0
- package/dist/lib/loader-utils/normalize-loader.js +52 -0
- package/dist/lib/loader-utils/option-defaults.d.ts +20 -0
- package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -0
- package/dist/lib/loader-utils/option-defaults.js +41 -0
- package/dist/lib/loader-utils/option-utils.d.ts +36 -0
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -0
- package/dist/lib/loader-utils/option-utils.js +177 -0
- package/dist/lib/progress/fetch-progress.d.ts +6 -0
- package/dist/lib/progress/fetch-progress.d.ts.map +1 -0
- package/dist/lib/progress/fetch-progress.js +59 -0
- package/dist/lib/utils/mime-type-utils.d.ts +20 -0
- package/dist/lib/utils/mime-type-utils.d.ts.map +1 -0
- package/dist/lib/utils/mime-type-utils.js +42 -0
- package/dist/lib/utils/resource-utils.d.ts +21 -0
- package/dist/lib/utils/resource-utils.d.ts.map +1 -0
- package/dist/lib/utils/resource-utils.js +78 -0
- package/dist/lib/utils/response-utils.d.ts +18 -0
- package/dist/lib/utils/response-utils.d.ts.map +1 -0
- package/dist/lib/utils/response-utils.js +114 -0
- package/dist/null-loader.d.ts +10 -0
- package/dist/null-loader.d.ts.map +1 -0
- package/dist/null-loader.js +44 -0
- package/dist/null-worker.js +178 -2
- package/dist/workers/null-worker.d.ts +2 -0
- package/dist/workers/null-worker.d.ts.map +1 -0
- package/dist/workers/null-worker.js +5 -0
- package/package.json +7 -7
- package/src/lib/api/encode.ts +1 -0
- package/src/lib/api/register-loaders.ts +2 -1
- package/src/lib/{init.js → init.ts} +0 -0
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/null-worker.js.map +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REMOVED_LOADER_OPTIONS = exports.DEFAULT_LOADER_OPTIONS = void 0;
|
|
4
|
+
const loggers_1 = require("./loggers");
|
|
5
|
+
exports.DEFAULT_LOADER_OPTIONS = {
|
|
6
|
+
// baseUri
|
|
7
|
+
fetch: null,
|
|
8
|
+
mimeType: undefined,
|
|
9
|
+
nothrow: false,
|
|
10
|
+
log: new loggers_1.ConsoleLog(),
|
|
11
|
+
CDN: 'https://unpkg.com/@loaders.gl',
|
|
12
|
+
worker: true,
|
|
13
|
+
maxConcurrency: 3,
|
|
14
|
+
maxMobileConcurrency: 1,
|
|
15
|
+
reuseWorkers: true,
|
|
16
|
+
_workerType: '',
|
|
17
|
+
limit: 0,
|
|
18
|
+
_limitMB: 0,
|
|
19
|
+
batchSize: 'auto',
|
|
20
|
+
batchDebounceMs: 0,
|
|
21
|
+
metadata: false,
|
|
22
|
+
transforms: []
|
|
23
|
+
};
|
|
24
|
+
exports.REMOVED_LOADER_OPTIONS = {
|
|
25
|
+
throws: 'nothrow',
|
|
26
|
+
dataType: '(no longer used)',
|
|
27
|
+
uri: 'baseUri',
|
|
28
|
+
// Warn if fetch options are used on top-level
|
|
29
|
+
method: 'fetch.method',
|
|
30
|
+
headers: 'fetch.headers',
|
|
31
|
+
body: 'fetch.body',
|
|
32
|
+
mode: 'fetch.mode',
|
|
33
|
+
credentials: 'fetch.credentials',
|
|
34
|
+
cache: 'fetch.cache',
|
|
35
|
+
redirect: 'fetch.redirect',
|
|
36
|
+
referrer: 'fetch.referrer',
|
|
37
|
+
referrerPolicy: 'fetch.referrerPolicy',
|
|
38
|
+
integrity: 'fetch.integrity',
|
|
39
|
+
keepalive: 'fetch.keepalive',
|
|
40
|
+
signal: 'fetch.signal'
|
|
41
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Loader, LoaderContext, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Global state for loaders.gl. Stored on `global.loaders._state`
|
|
4
|
+
*/
|
|
5
|
+
declare type GlobalLoaderState = {
|
|
6
|
+
loaderRegistry: Loader[];
|
|
7
|
+
globalOptions: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Helper for safely accessing global loaders.gl variables
|
|
13
|
+
* Wraps initialization of global variable in function to defeat overly aggressive tree-shakers
|
|
14
|
+
*/
|
|
15
|
+
export declare function getGlobalLoaderState(): GlobalLoaderState;
|
|
16
|
+
/**
|
|
17
|
+
* Set global loader options
|
|
18
|
+
* @param options
|
|
19
|
+
*/
|
|
20
|
+
export declare function setGlobalOptions(options: object): void;
|
|
21
|
+
/**
|
|
22
|
+
* Merges options with global opts and loader defaults, also injects baseUri
|
|
23
|
+
* @param options
|
|
24
|
+
* @param loader
|
|
25
|
+
* @param loaders
|
|
26
|
+
* @param url
|
|
27
|
+
*/
|
|
28
|
+
export declare function normalizeOptions(options: object, loader: Loader, loaders?: Loader[], url?: string): object;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the current fetch function from options and context
|
|
31
|
+
* @param options
|
|
32
|
+
* @param context
|
|
33
|
+
*/
|
|
34
|
+
export declare function getFetchFunction(options?: LoaderOptions, context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>): any;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=option-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/option-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAKnF;;GAEG;AACH,aAAK,iBAAiB,GAAG;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,aAAa,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CASxD;AAWD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAItD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,OAuB/E"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFetchFunction = exports.normalizeOptions = exports.setGlobalOptions = exports.getGlobalLoaderState = void 0;
|
|
4
|
+
const is_type_1 = require("../../javascript-utils/is-type");
|
|
5
|
+
const fetch_file_1 = require("../fetch/fetch-file");
|
|
6
|
+
const loggers_1 = require("./loggers");
|
|
7
|
+
const option_defaults_1 = require("./option-defaults");
|
|
8
|
+
/**
|
|
9
|
+
* Helper for safely accessing global loaders.gl variables
|
|
10
|
+
* Wraps initialization of global variable in function to defeat overly aggressive tree-shakers
|
|
11
|
+
*/
|
|
12
|
+
function getGlobalLoaderState() {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
const { loaders } = globalThis;
|
|
17
|
+
// Add _state object to keep separate from modules added to globalThis.loaders
|
|
18
|
+
loaders._state = loaders._state || {};
|
|
19
|
+
return loaders._state;
|
|
20
|
+
}
|
|
21
|
+
exports.getGlobalLoaderState = getGlobalLoaderState;
|
|
22
|
+
// Store global loader options on the global object to increase chances of cross loaders-version interoperability
|
|
23
|
+
// NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks
|
|
24
|
+
const getGlobalLoaderOptions = () => {
|
|
25
|
+
const state = getGlobalLoaderState();
|
|
26
|
+
// Ensure all default loader options from this library are mentioned
|
|
27
|
+
state.globalOptions = state.globalOptions || { ...option_defaults_1.DEFAULT_LOADER_OPTIONS };
|
|
28
|
+
return state.globalOptions;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Set global loader options
|
|
32
|
+
* @param options
|
|
33
|
+
*/
|
|
34
|
+
function setGlobalOptions(options) {
|
|
35
|
+
const state = getGlobalLoaderState();
|
|
36
|
+
const globalOptions = getGlobalLoaderOptions();
|
|
37
|
+
state.globalOptions = normalizeOptionsInternal(globalOptions, options);
|
|
38
|
+
}
|
|
39
|
+
exports.setGlobalOptions = setGlobalOptions;
|
|
40
|
+
/**
|
|
41
|
+
* Merges options with global opts and loader defaults, also injects baseUri
|
|
42
|
+
* @param options
|
|
43
|
+
* @param loader
|
|
44
|
+
* @param loaders
|
|
45
|
+
* @param url
|
|
46
|
+
*/
|
|
47
|
+
function normalizeOptions(options, loader, loaders, url) {
|
|
48
|
+
loaders = loaders || [];
|
|
49
|
+
loaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
50
|
+
validateOptions(options, loaders);
|
|
51
|
+
return normalizeOptionsInternal(loader, options, url);
|
|
52
|
+
}
|
|
53
|
+
exports.normalizeOptions = normalizeOptions;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the current fetch function from options and context
|
|
56
|
+
* @param options
|
|
57
|
+
* @param context
|
|
58
|
+
*/
|
|
59
|
+
function getFetchFunction(options, context) {
|
|
60
|
+
const globalOptions = getGlobalLoaderOptions();
|
|
61
|
+
const fetchOptions = options || globalOptions;
|
|
62
|
+
// options.fetch can be a function
|
|
63
|
+
if (typeof fetchOptions.fetch === 'function') {
|
|
64
|
+
return fetchOptions.fetch;
|
|
65
|
+
}
|
|
66
|
+
// options.fetch can be an options object
|
|
67
|
+
if ((0, is_type_1.isObject)(fetchOptions.fetch)) {
|
|
68
|
+
return (url) => (0, fetch_file_1.fetchFile)(url, fetchOptions);
|
|
69
|
+
}
|
|
70
|
+
// else refer to context (from parent loader) if available
|
|
71
|
+
if (context?.fetch) {
|
|
72
|
+
return context?.fetch;
|
|
73
|
+
}
|
|
74
|
+
// else return the default fetch function
|
|
75
|
+
return fetch_file_1.fetchFile;
|
|
76
|
+
}
|
|
77
|
+
exports.getFetchFunction = getFetchFunction;
|
|
78
|
+
// VALIDATE OPTIONS
|
|
79
|
+
/**
|
|
80
|
+
* Warn for unsupported options
|
|
81
|
+
* @param options
|
|
82
|
+
* @param loaders
|
|
83
|
+
*/
|
|
84
|
+
function validateOptions(options, loaders) {
|
|
85
|
+
// Check top level options
|
|
86
|
+
validateOptionsObject(options, null, option_defaults_1.DEFAULT_LOADER_OPTIONS, option_defaults_1.REMOVED_LOADER_OPTIONS, loaders);
|
|
87
|
+
for (const loader of loaders) {
|
|
88
|
+
// Get the scoped, loader specific options from the user supplied options
|
|
89
|
+
const idOptions = (options && options[loader.id]) || {};
|
|
90
|
+
// Get scoped, loader specific default and deprecated options from the selected loader
|
|
91
|
+
const loaderOptions = (loader.options && loader.options[loader.id]) || {};
|
|
92
|
+
const deprecatedOptions = (loader.deprecatedOptions && loader.deprecatedOptions[loader.id]) || {};
|
|
93
|
+
// Validate loader specific options
|
|
94
|
+
validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// eslint-disable-next-line max-params, complexity
|
|
98
|
+
function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, loaders) {
|
|
99
|
+
const loaderName = id || 'Top level';
|
|
100
|
+
const prefix = id ? `${id}.` : '';
|
|
101
|
+
for (const key in options) {
|
|
102
|
+
// If top level option value is an object it could options for a loader, so ignore
|
|
103
|
+
const isSubOptions = !id && (0, is_type_1.isObject)(options[key]);
|
|
104
|
+
const isBaseUriOption = key === 'baseUri' && !id;
|
|
105
|
+
const isWorkerUrlOption = key === 'workerUrl' && id;
|
|
106
|
+
// <loader>.workerUrl requires special handling as it is now auto-generated and no longer specified as a default option.
|
|
107
|
+
if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
|
|
108
|
+
// Issue deprecation warnings
|
|
109
|
+
if (key in deprecatedOptions) {
|
|
110
|
+
loggers_1.probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' no longer supported, use \'${deprecatedOptions[key]}\'`)();
|
|
111
|
+
}
|
|
112
|
+
else if (!isSubOptions) {
|
|
113
|
+
const suggestion = findSimilarOption(key, loaders);
|
|
114
|
+
loggers_1.probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' not recognized. ${suggestion}`)();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function findSimilarOption(optionKey, loaders) {
|
|
120
|
+
const lowerCaseOptionKey = optionKey.toLowerCase();
|
|
121
|
+
let bestSuggestion = '';
|
|
122
|
+
for (const loader of loaders) {
|
|
123
|
+
for (const key in loader.options) {
|
|
124
|
+
if (optionKey === key) {
|
|
125
|
+
return `Did you mean \'${loader.id}.${key}\'?`;
|
|
126
|
+
}
|
|
127
|
+
const lowerCaseKey = key.toLowerCase();
|
|
128
|
+
const isPartialMatch = lowerCaseOptionKey.startsWith(lowerCaseKey) || lowerCaseKey.startsWith(lowerCaseOptionKey);
|
|
129
|
+
if (isPartialMatch) {
|
|
130
|
+
bestSuggestion = bestSuggestion || `Did you mean \'${loader.id}.${key}\'?`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return bestSuggestion;
|
|
135
|
+
}
|
|
136
|
+
function normalizeOptionsInternal(loader, options, url) {
|
|
137
|
+
const loaderDefaultOptions = loader.options || {};
|
|
138
|
+
const mergedOptions = { ...loaderDefaultOptions };
|
|
139
|
+
addUrlOptions(mergedOptions, url);
|
|
140
|
+
// LOGGING: options.log can be set to `null` to defeat logging
|
|
141
|
+
if (mergedOptions.log === null) {
|
|
142
|
+
mergedOptions.log = new loggers_1.NullLog();
|
|
143
|
+
}
|
|
144
|
+
mergeNestedFields(mergedOptions, getGlobalLoaderOptions());
|
|
145
|
+
mergeNestedFields(mergedOptions, options);
|
|
146
|
+
return mergedOptions;
|
|
147
|
+
}
|
|
148
|
+
// Merge nested options objects
|
|
149
|
+
function mergeNestedFields(mergedOptions, options) {
|
|
150
|
+
for (const key in options) {
|
|
151
|
+
// Check for nested options
|
|
152
|
+
// object in options => either no key in defaultOptions or object in defaultOptions
|
|
153
|
+
if (key in options) {
|
|
154
|
+
const value = options[key];
|
|
155
|
+
if ((0, is_type_1.isPureObject)(value) && (0, is_type_1.isPureObject)(mergedOptions[key])) {
|
|
156
|
+
mergedOptions[key] = {
|
|
157
|
+
...mergedOptions[key],
|
|
158
|
+
...options[key]
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
mergedOptions[key] = options[key];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// else: No need to merge nested opts, and the initial merge already copied over the nested options
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Harvest information from the url
|
|
169
|
+
// TODO - baseUri should be a directory, i.e. remove file component from baseUri
|
|
170
|
+
// TODO - extract extension?
|
|
171
|
+
// TODO - extract query parameters?
|
|
172
|
+
// TODO - should these be injected on context instead of options?
|
|
173
|
+
function addUrlOptions(options, url) {
|
|
174
|
+
if (url && !('baseUri' in options)) {
|
|
175
|
+
options.baseUri = url;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intercepts the Response stream and creates a new Response
|
|
3
|
+
*/
|
|
4
|
+
export default function fetchProgress(response: Response | Promise<Response>, onProgress: any, // TODO better callback types
|
|
5
|
+
onDone?: () => void, onError?: () => void): Promise<Response>;
|
|
6
|
+
//# sourceMappingURL=fetch-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-progress.d.ts","sourceRoot":"","sources":["../../../src/lib/progress/fetch-progress.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAA8B,aAAa,CACzC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,EACtC,UAAU,EAAE,GAAG,EAAE,6BAA6B;AAC9C,MAAM,aAAW,EACjB,OAAO,aAAW,qBA+BnB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Forked from github AnthumChris/fetch-progress-indicators under MIT license
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/**
|
|
5
|
+
* Intercepts the Response stream and creates a new Response
|
|
6
|
+
*/
|
|
7
|
+
async function fetchProgress(response, onProgress, // TODO better callback types
|
|
8
|
+
onDone = () => { }, onError = () => { }) {
|
|
9
|
+
response = await response;
|
|
10
|
+
if (!response.ok) {
|
|
11
|
+
// ERROR checking needs to be done separately
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
const body = response.body;
|
|
15
|
+
if (!body) {
|
|
16
|
+
// 'ReadableStream not yet supported in this browser.
|
|
17
|
+
return response;
|
|
18
|
+
}
|
|
19
|
+
const contentLength = response.headers.get('content-length') || 0;
|
|
20
|
+
const totalBytes = contentLength && parseInt(contentLength);
|
|
21
|
+
if (!(contentLength > 0)) {
|
|
22
|
+
return response;
|
|
23
|
+
}
|
|
24
|
+
// Currently override only implemented in browser
|
|
25
|
+
if (typeof ReadableStream === 'undefined' || !body.getReader) {
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
// Create a new stream that invisbly wraps original stream
|
|
29
|
+
const progressStream = new ReadableStream({
|
|
30
|
+
async start(controller) {
|
|
31
|
+
const reader = body.getReader();
|
|
32
|
+
await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return new Response(progressStream);
|
|
36
|
+
}
|
|
37
|
+
exports.default = fetchProgress;
|
|
38
|
+
// Forward to original streams controller
|
|
39
|
+
// TODO - this causes a crazy deep "async stack"... rewrite as async iterator?
|
|
40
|
+
// eslint-disable-next-line max-params
|
|
41
|
+
async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
|
|
42
|
+
try {
|
|
43
|
+
const { done, value } = await reader.read();
|
|
44
|
+
if (done) {
|
|
45
|
+
onDone();
|
|
46
|
+
controller.close();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
loadedBytes += value.byteLength;
|
|
50
|
+
const percent = Math.round((loadedBytes / totalBytes) * 100);
|
|
51
|
+
onProgress(percent, { loadedBytes, totalBytes });
|
|
52
|
+
controller.enqueue(value);
|
|
53
|
+
await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
controller.error(error);
|
|
57
|
+
onError(error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove extra data like `charset` from MIME types
|
|
3
|
+
* @param mimeString
|
|
4
|
+
* @returns A clean MIME type, or an empty string
|
|
5
|
+
*
|
|
6
|
+
* @todo - handle more advanced MIMETYpes, multiple types
|
|
7
|
+
* @todo - extract charset etc
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseMIMEType(mimeString: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Extract MIME type from data URL
|
|
12
|
+
*
|
|
13
|
+
* @param mimeString
|
|
14
|
+
* @returns A clean MIME type, or an empty string
|
|
15
|
+
*
|
|
16
|
+
* @todo - handle more advanced MIMETYpes, multiple types
|
|
17
|
+
* @todo - extract charset etc
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseMIMETypeFromURL(url: string): string;
|
|
20
|
+
//# sourceMappingURL=mime-type-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime-type-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/mime-type-utils.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAOxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOxD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO - build/integrate proper MIME type parsing
|
|
3
|
+
// https://mimesniff.spec.whatwg.org/
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.parseMIMETypeFromURL = exports.parseMIMEType = void 0;
|
|
6
|
+
const DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
|
|
7
|
+
const MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
|
|
8
|
+
/**
|
|
9
|
+
* Remove extra data like `charset` from MIME types
|
|
10
|
+
* @param mimeString
|
|
11
|
+
* @returns A clean MIME type, or an empty string
|
|
12
|
+
*
|
|
13
|
+
* @todo - handle more advanced MIMETYpes, multiple types
|
|
14
|
+
* @todo - extract charset etc
|
|
15
|
+
*/
|
|
16
|
+
function parseMIMEType(mimeString) {
|
|
17
|
+
// If resource is a data url, extract any embedded mime type
|
|
18
|
+
const matches = MIME_TYPE_PATTERN.exec(mimeString);
|
|
19
|
+
if (matches) {
|
|
20
|
+
return matches[1];
|
|
21
|
+
}
|
|
22
|
+
return mimeString;
|
|
23
|
+
}
|
|
24
|
+
exports.parseMIMEType = parseMIMEType;
|
|
25
|
+
/**
|
|
26
|
+
* Extract MIME type from data URL
|
|
27
|
+
*
|
|
28
|
+
* @param mimeString
|
|
29
|
+
* @returns A clean MIME type, or an empty string
|
|
30
|
+
*
|
|
31
|
+
* @todo - handle more advanced MIMETYpes, multiple types
|
|
32
|
+
* @todo - extract charset etc
|
|
33
|
+
*/
|
|
34
|
+
function parseMIMETypeFromURL(url) {
|
|
35
|
+
// If resource is a data URL, extract any embedded mime type
|
|
36
|
+
const matches = DATA_URL_PATTERN.exec(url);
|
|
37
|
+
if (matches) {
|
|
38
|
+
return matches[1];
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
exports.parseMIMETypeFromURL = parseMIMETypeFromURL;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns an object with `url` and (MIME) `type` fields
|
|
3
|
+
* If it cannot determine url or type, the corresponding value will be an empty string
|
|
4
|
+
*
|
|
5
|
+
* @param resource Any type, but only Responses, string URLs and data URLs are processed
|
|
6
|
+
*
|
|
7
|
+
* @todo string parameters are assumed to be URLs
|
|
8
|
+
*/
|
|
9
|
+
export declare function getResourceUrlAndType(resource: any): {
|
|
10
|
+
url: string;
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Returns (approximate) content length for a resource if it can be determined.
|
|
15
|
+
* Returns -1 if content length cannot be determined.
|
|
16
|
+
* @param resource
|
|
17
|
+
|
|
18
|
+
* @note string parameters are NOT assumed to be URLs
|
|
19
|
+
*/
|
|
20
|
+
export declare function getResourceContentLength(resource: any): number;
|
|
21
|
+
//# sourceMappingURL=resource-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/resource-utils.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,GAAG,GAAG;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAmChF;AAED;;;;;;IAMI;AACJ,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,MAAM,CAkB9D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getResourceContentLength = exports.getResourceUrlAndType = void 0;
|
|
4
|
+
const is_type_1 = require("../../javascript-utils/is-type");
|
|
5
|
+
const mime_type_utils_1 = require("./mime-type-utils");
|
|
6
|
+
const QUERY_STRING_PATTERN = /\?.*/;
|
|
7
|
+
/**
|
|
8
|
+
* Returns an object with `url` and (MIME) `type` fields
|
|
9
|
+
* If it cannot determine url or type, the corresponding value will be an empty string
|
|
10
|
+
*
|
|
11
|
+
* @param resource Any type, but only Responses, string URLs and data URLs are processed
|
|
12
|
+
*
|
|
13
|
+
* @todo string parameters are assumed to be URLs
|
|
14
|
+
*/
|
|
15
|
+
function getResourceUrlAndType(resource) {
|
|
16
|
+
// If resource is a response, it contains the information directly
|
|
17
|
+
if ((0, is_type_1.isResponse)(resource)) {
|
|
18
|
+
const url = stripQueryString(resource.url || '');
|
|
19
|
+
const contentTypeHeader = resource.headers.get('content-type') || '';
|
|
20
|
+
return {
|
|
21
|
+
url,
|
|
22
|
+
type: (0, mime_type_utils_1.parseMIMEType)(contentTypeHeader) || (0, mime_type_utils_1.parseMIMETypeFromURL)(url)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// If the resource is a Blob or a File (subclass of Blob)
|
|
26
|
+
if ((0, is_type_1.isBlob)(resource)) {
|
|
27
|
+
return {
|
|
28
|
+
// File objects have a "name" property. Blob objects don't have any
|
|
29
|
+
// url (name) information
|
|
30
|
+
url: stripQueryString(resource.name || ''),
|
|
31
|
+
type: resource.type || ''
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (typeof resource === 'string') {
|
|
35
|
+
return {
|
|
36
|
+
// TODO this could mess up data URL but it doesn't matter as it is just used for inference
|
|
37
|
+
url: stripQueryString(resource),
|
|
38
|
+
// If a data url
|
|
39
|
+
type: (0, mime_type_utils_1.parseMIMETypeFromURL)(resource)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// Unknown
|
|
43
|
+
return {
|
|
44
|
+
url: '',
|
|
45
|
+
type: ''
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.getResourceUrlAndType = getResourceUrlAndType;
|
|
49
|
+
/**
|
|
50
|
+
* Returns (approximate) content length for a resource if it can be determined.
|
|
51
|
+
* Returns -1 if content length cannot be determined.
|
|
52
|
+
* @param resource
|
|
53
|
+
|
|
54
|
+
* @note string parameters are NOT assumed to be URLs
|
|
55
|
+
*/
|
|
56
|
+
function getResourceContentLength(resource) {
|
|
57
|
+
if ((0, is_type_1.isResponse)(resource)) {
|
|
58
|
+
return resource.headers['content-length'] || -1;
|
|
59
|
+
}
|
|
60
|
+
if ((0, is_type_1.isBlob)(resource)) {
|
|
61
|
+
return resource.size;
|
|
62
|
+
}
|
|
63
|
+
if (typeof resource === 'string') {
|
|
64
|
+
// TODO - handle data URL?
|
|
65
|
+
return resource.length;
|
|
66
|
+
}
|
|
67
|
+
if (resource instanceof ArrayBuffer) {
|
|
68
|
+
return resource.byteLength;
|
|
69
|
+
}
|
|
70
|
+
if (ArrayBuffer.isView(resource)) {
|
|
71
|
+
return resource.byteLength;
|
|
72
|
+
}
|
|
73
|
+
return -1;
|
|
74
|
+
}
|
|
75
|
+
exports.getResourceContentLength = getResourceContentLength;
|
|
76
|
+
function stripQueryString(url) {
|
|
77
|
+
return url.replace(QUERY_STRING_PATTERN, '');
|
|
78
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a Response object
|
|
3
|
+
* Adds content-length header when possible
|
|
4
|
+
*
|
|
5
|
+
* @param resource
|
|
6
|
+
*/
|
|
7
|
+
export declare function makeResponse(resource: any): Promise<Response>;
|
|
8
|
+
/**
|
|
9
|
+
* Checks response status (async) and throws a helpful error message if status is not OK.
|
|
10
|
+
* @param response
|
|
11
|
+
*/
|
|
12
|
+
export declare function checkResponse(response: Response): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Checks response status (sync) and throws a helpful error message if status is not OK.
|
|
15
|
+
* @param response
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkResponseSync(response: Response): void;
|
|
18
|
+
//# sourceMappingURL=response-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/response-utils.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsCnE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAKrE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAM1D"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkResponseSync = exports.checkResponse = exports.makeResponse = void 0;
|
|
4
|
+
const is_type_1 = require("../../javascript-utils/is-type");
|
|
5
|
+
const resource_utils_1 = require("./resource-utils");
|
|
6
|
+
/**
|
|
7
|
+
* Returns a Response object
|
|
8
|
+
* Adds content-length header when possible
|
|
9
|
+
*
|
|
10
|
+
* @param resource
|
|
11
|
+
*/
|
|
12
|
+
async function makeResponse(resource) {
|
|
13
|
+
if ((0, is_type_1.isResponse)(resource)) {
|
|
14
|
+
return resource;
|
|
15
|
+
}
|
|
16
|
+
// Add content-length header if possible
|
|
17
|
+
const headers = {};
|
|
18
|
+
const contentLength = (0, resource_utils_1.getResourceContentLength)(resource);
|
|
19
|
+
if (contentLength >= 0) {
|
|
20
|
+
headers['content-length'] = String(contentLength);
|
|
21
|
+
}
|
|
22
|
+
// `new Response(File)` does not preserve content-type and URL
|
|
23
|
+
// so we add them here
|
|
24
|
+
const { url, type } = (0, resource_utils_1.getResourceUrlAndType)(resource);
|
|
25
|
+
if (type) {
|
|
26
|
+
headers['content-type'] = type;
|
|
27
|
+
}
|
|
28
|
+
// Add a custom header with initial bytes if available
|
|
29
|
+
const initialDataUrl = await getInitialDataUrl(resource);
|
|
30
|
+
if (initialDataUrl) {
|
|
31
|
+
headers['x-first-bytes'] = initialDataUrl;
|
|
32
|
+
}
|
|
33
|
+
// TODO - is this the best way of handling strings?
|
|
34
|
+
// Maybe package as data URL instead?
|
|
35
|
+
if (typeof resource === 'string') {
|
|
36
|
+
// Convert to ArrayBuffer to avoid Response treating it as a URL
|
|
37
|
+
resource = new TextEncoder().encode(resource);
|
|
38
|
+
}
|
|
39
|
+
// Attempt to create a Response from the resource, adding headers and setting url
|
|
40
|
+
const response = new Response(resource, { headers });
|
|
41
|
+
// We can't control `Response.url` via constructor, use a property override to record URL.
|
|
42
|
+
Object.defineProperty(response, 'url', { value: url });
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
exports.makeResponse = makeResponse;
|
|
46
|
+
/**
|
|
47
|
+
* Checks response status (async) and throws a helpful error message if status is not OK.
|
|
48
|
+
* @param response
|
|
49
|
+
*/
|
|
50
|
+
async function checkResponse(response) {
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
const message = await getResponseError(response);
|
|
53
|
+
throw new Error(message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.checkResponse = checkResponse;
|
|
57
|
+
/**
|
|
58
|
+
* Checks response status (sync) and throws a helpful error message if status is not OK.
|
|
59
|
+
* @param response
|
|
60
|
+
*/
|
|
61
|
+
function checkResponseSync(response) {
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
let message = `${response.status} ${response.statusText}`;
|
|
64
|
+
message = message.length > 60 ? `${message.slice(60)}...` : message;
|
|
65
|
+
throw new Error(message);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.checkResponseSync = checkResponseSync;
|
|
69
|
+
// HELPERS
|
|
70
|
+
async function getResponseError(response) {
|
|
71
|
+
let message = `Failed to fetch resource ${response.url} (${response.status}): `;
|
|
72
|
+
try {
|
|
73
|
+
const contentType = response.headers.get('Content-Type');
|
|
74
|
+
let text = response.statusText;
|
|
75
|
+
if (contentType.includes('application/json')) {
|
|
76
|
+
text += ` ${await response.text()}`;
|
|
77
|
+
}
|
|
78
|
+
message += text;
|
|
79
|
+
message = message.length > 60 ? `${message.slice(60)}...` : message;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
// eslint forbids return in a finally statement, so we just catch here
|
|
83
|
+
}
|
|
84
|
+
return message;
|
|
85
|
+
}
|
|
86
|
+
async function getInitialDataUrl(resource) {
|
|
87
|
+
const INITIAL_DATA_LENGTH = 5;
|
|
88
|
+
if (typeof resource === 'string') {
|
|
89
|
+
return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
|
|
90
|
+
}
|
|
91
|
+
if (resource instanceof Blob) {
|
|
92
|
+
const blobSlice = resource.slice(0, 5);
|
|
93
|
+
return await new Promise((resolve) => {
|
|
94
|
+
const reader = new FileReader();
|
|
95
|
+
reader.onload = (event) => resolve(event?.target?.result);
|
|
96
|
+
reader.readAsDataURL(blobSlice);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (resource instanceof ArrayBuffer) {
|
|
100
|
+
const slice = resource.slice(0, INITIAL_DATA_LENGTH);
|
|
101
|
+
const base64 = arrayBufferToBase64(slice);
|
|
102
|
+
return `data:base64,${base64}`;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
// https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string
|
|
107
|
+
function arrayBufferToBase64(buffer) {
|
|
108
|
+
let binary = '';
|
|
109
|
+
const bytes = new Uint8Array(buffer);
|
|
110
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
111
|
+
binary += String.fromCharCode(bytes[i]);
|
|
112
|
+
}
|
|
113
|
+
return btoa(binary);
|
|
114
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Loader, LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Loads any data and returns null (or optionally passes through data unparsed)
|
|
4
|
+
*/
|
|
5
|
+
export declare const NullWorkerLoader: Loader;
|
|
6
|
+
/**
|
|
7
|
+
* Loads any data and returns null (or optionally passes through data unparsed)
|
|
8
|
+
*/
|
|
9
|
+
export declare const NullLoader: LoaderWithParser;
|
|
10
|
+
//# sourceMappingURL=null-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null-loader.d.ts","sourceRoot":"","sources":["../src/null-loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAY9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,gBAkBxB,CAAC"}
|