@loaders.gl/core 3.4.0-alpha.1 → 3.4.0-alpha.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/dist.min.js +461 -248
- package/dist/es5/core-addons/write-file-browser.js +0 -2
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js +65 -67
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js +13 -24
- package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js +22 -25
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js +88 -93
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-string-iterator.js +20 -24
- package/dist/es5/iterators/make-iterator/make-string-iterator.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-dom-stream.js +30 -34
- package/dist/es5/iterators/make-stream/make-dom-stream.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-node-stream.js +88 -87
- package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/es5/javascript-utils/is-type.js +0 -3
- package/dist/es5/javascript-utils/is-type.js.map +1 -1
- package/dist/es5/lib/api/encode.js +157 -166
- package/dist/es5/lib/api/encode.js.map +1 -1
- package/dist/es5/lib/api/load-in-batches.js +25 -31
- package/dist/es5/lib/api/load-in-batches.js.map +1 -1
- package/dist/es5/lib/api/load.js +35 -38
- package/dist/es5/lib/api/load.js.map +1 -1
- package/dist/es5/lib/api/loader-options.js.map +1 -1
- package/dist/es5/lib/api/parse-in-batches.js +192 -207
- package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
- package/dist/es5/lib/api/parse-sync.js +0 -7
- package/dist/es5/lib/api/parse-sync.js.map +1 -1
- package/dist/es5/lib/api/parse.js +99 -107
- package/dist/es5/lib/api/parse.js.map +1 -1
- package/dist/es5/lib/api/register-loaders.js +1 -3
- package/dist/es5/lib/api/register-loaders.js.map +1 -1
- package/dist/es5/lib/api/save.js +13 -15
- package/dist/es5/lib/api/save.js.map +1 -1
- package/dist/es5/lib/api/select-loader.js +41 -58
- package/dist/es5/lib/api/select-loader.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-error-message.js +29 -31
- package/dist/es5/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-file.js +23 -25
- package/dist/es5/lib/fetch/fetch-file.js.map +1 -1
- package/dist/es5/lib/fetch/read-array-buffer.js +41 -45
- package/dist/es5/lib/fetch/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/fetch/read-file.js +0 -3
- package/dist/es5/lib/fetch/read-file.js.map +1 -1
- package/dist/es5/lib/fetch/write-file.js +15 -17
- package/dist/es5/lib/fetch/write-file.js.map +1 -1
- package/dist/es5/lib/filesystems/browser-filesystem.js +107 -124
- package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/es5/lib/filesystems/read-array-buffer.js +19 -21
- package/dist/es5/lib/filesystems/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/init.js +1 -3
- package/dist/es5/lib/init.js.map +1 -1
- package/dist/es5/lib/loader-utils/check-errors.js +24 -26
- package/dist/es5/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-data.js +130 -145
- package/dist/es5/lib/loader-utils/get-data.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-fetch-function.js +26 -0
- package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -0
- package/dist/es5/lib/loader-utils/loader-context.js +2 -5
- package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/es5/lib/loader-utils/loggers.js +0 -2
- package/dist/es5/lib/loader-utils/loggers.js.map +1 -1
- package/dist/es5/lib/loader-utils/normalize-loader.js +0 -3
- package/dist/es5/lib/loader-utils/normalize-loader.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-defaults.js +0 -2
- package/dist/es5/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-utils.js +21 -55
- package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/es5/lib/progress/fetch-progress.js +92 -98
- package/dist/es5/lib/progress/fetch-progress.js.map +1 -1
- package/dist/es5/lib/utils/log.js +0 -1
- package/dist/es5/lib/utils/log.js.map +1 -1
- package/dist/es5/lib/utils/mime-type-utils.js +0 -3
- package/dist/es5/lib/utils/mime-type-utils.js.map +1 -1
- package/dist/es5/lib/utils/resource-utils.js +0 -4
- package/dist/es5/lib/utils/resource-utils.js.map +1 -1
- package/dist/es5/lib/utils/response-utils.js +118 -131
- package/dist/es5/lib/utils/response-utils.js.map +1 -1
- package/dist/es5/null-loader.js +57 -63
- package/dist/es5/null-loader.js.map +1 -1
- package/dist/es5/workers/null-worker.js.map +1 -1
- package/dist/esm/bundle.js +0 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/index.js +0 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/iterators/batch-iterators/timed-batch-iterator.js +0 -1
- package/dist/esm/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
- package/dist/esm/iterators/make-iterator/make-array-buffer-iterator.js +16 -17
- package/dist/esm/iterators/make-iterator/make-array-buffer-iterator.js.map +1 -1
- package/dist/esm/iterators/make-iterator/make-blob-iterator.js +0 -1
- package/dist/esm/iterators/make-iterator/make-blob-iterator.js.map +1 -1
- package/dist/esm/iterators/make-iterator/make-iterator.js +0 -1
- package/dist/esm/iterators/make-iterator/make-iterator.js.map +1 -1
- package/dist/esm/iterators/make-iterator/make-stream-iterator.js +0 -3
- package/dist/esm/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/esm/iterators/make-iterator/make-string-iterator.js +0 -2
- package/dist/esm/iterators/make-iterator/make-string-iterator.js.map +1 -1
- package/dist/esm/iterators/make-stream/make-dom-stream.js +1 -3
- package/dist/esm/iterators/make-stream/make-dom-stream.js.map +1 -1
- package/dist/esm/iterators/make-stream/make-node-stream.js +3 -2
- package/dist/esm/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/esm/javascript-utils/is-type.js +0 -4
- package/dist/esm/javascript-utils/is-type.js.map +1 -1
- package/dist/esm/lib/api/encode.js +0 -9
- package/dist/esm/lib/api/encode.js.map +1 -1
- package/dist/esm/lib/api/load-in-batches.js +1 -5
- package/dist/esm/lib/api/load-in-batches.js.map +1 -1
- package/dist/esm/lib/api/load.js +1 -6
- package/dist/esm/lib/api/load.js.map +1 -1
- package/dist/esm/lib/api/parse-in-batches.js +2 -16
- package/dist/esm/lib/api/parse-in-batches.js.map +1 -1
- package/dist/esm/lib/api/parse-sync.js +0 -8
- package/dist/esm/lib/api/parse-sync.js.map +1 -1
- package/dist/esm/lib/api/parse.js +0 -12
- package/dist/esm/lib/api/parse.js.map +1 -1
- package/dist/esm/lib/api/register-loaders.js +0 -3
- package/dist/esm/lib/api/register-loaders.js.map +1 -1
- package/dist/esm/lib/api/save.js.map +1 -1
- package/dist/esm/lib/api/select-loader.js +0 -20
- package/dist/esm/lib/api/select-loader.js.map +1 -1
- package/dist/esm/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/esm/lib/fetch/fetch-file.js +0 -1
- package/dist/esm/lib/fetch/fetch-file.js.map +1 -1
- package/dist/esm/lib/fetch/read-array-buffer.js +0 -3
- package/dist/esm/lib/fetch/read-array-buffer.js.map +1 -1
- package/dist/esm/lib/fetch/read-file.js +0 -4
- package/dist/esm/lib/fetch/read-file.js.map +1 -1
- package/dist/esm/lib/fetch/write-file.js +0 -1
- package/dist/esm/lib/fetch/write-file.js.map +1 -1
- package/dist/esm/lib/filesystems/browser-filesystem.js +1 -11
- package/dist/esm/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/esm/lib/filesystems/read-array-buffer.js +0 -2
- package/dist/esm/lib/filesystems/read-array-buffer.js.map +1 -1
- package/dist/esm/lib/init.js +1 -4
- package/dist/esm/lib/init.js.map +1 -1
- package/dist/esm/lib/loader-utils/check-errors.js +1 -2
- package/dist/esm/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/esm/lib/loader-utils/get-data.js +0 -6
- package/dist/esm/lib/loader-utils/get-data.js.map +1 -1
- package/dist/esm/lib/loader-utils/get-fetch-function.js +18 -0
- package/dist/esm/lib/loader-utils/get-fetch-function.js.map +1 -0
- package/dist/esm/lib/loader-utils/loader-context.js +1 -5
- package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/esm/lib/loader-utils/loggers.js +0 -3
- package/dist/esm/lib/loader-utils/loggers.js.map +1 -1
- package/dist/esm/lib/loader-utils/normalize-loader.js +0 -3
- package/dist/esm/lib/loader-utils/normalize-loader.js.map +1 -1
- package/dist/esm/lib/loader-utils/option-defaults.js +0 -2
- package/dist/esm/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/esm/lib/loader-utils/option-utils.js +0 -32
- package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/esm/lib/progress/fetch-progress.js +2 -6
- package/dist/esm/lib/progress/fetch-progress.js.map +1 -1
- package/dist/esm/lib/utils/log.js +0 -1
- package/dist/esm/lib/utils/log.js.map +1 -1
- package/dist/esm/lib/utils/mime-type-utils.js +0 -4
- package/dist/esm/lib/utils/mime-type-utils.js.map +1 -1
- package/dist/esm/lib/utils/resource-utils.js +0 -4
- package/dist/esm/lib/utils/resource-utils.js.map +1 -1
- package/dist/esm/lib/utils/response-utils.js +1 -12
- package/dist/esm/lib/utils/response-utils.js.map +1 -1
- package/dist/esm/null-loader.js +1 -4
- package/dist/esm/null-loader.js.map +1 -1
- package/dist/iterators/make-stream/make-node-stream.d.ts +7 -2
- package/dist/iterators/make-stream/make-node-stream.d.ts.map +1 -1
- package/dist/iterators/make-stream/make-node-stream.js +28 -2
- package/dist/lib/api/encode.d.ts +5 -5
- package/dist/lib/api/encode.d.ts.map +1 -1
- package/dist/lib/api/encode.js +1 -0
- package/dist/lib/api/load-in-batches.js +2 -2
- package/dist/lib/api/load.d.ts.map +1 -1
- package/dist/lib/api/load.js +3 -2
- package/dist/lib/fetch/fetch-file.js +1 -1
- package/dist/lib/loader-utils/get-fetch-function.d.ts +9 -0
- package/dist/lib/loader-utils/get-fetch-function.d.ts.map +1 -0
- package/dist/lib/loader-utils/get-fetch-function.js +31 -0
- package/dist/lib/loader-utils/loader-context.js +2 -2
- package/dist/lib/loader-utils/option-utils.d.ts +5 -15
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +10 -31
- package/dist/lib/progress/fetch-progress.js +2 -2
- package/dist/null-worker.js +1 -1
- package/package.json +5 -5
- package/src/iterators/make-stream/make-node-stream.ts +8 -2
- package/src/lib/api/encode.ts +7 -6
- package/src/lib/api/load-in-batches.ts +1 -1
- package/src/lib/api/load.ts +3 -2
- package/src/lib/loader-utils/get-fetch-function.ts +38 -0
- package/src/lib/loader-utils/loader-context.ts +1 -1
- package/src/lib/loader-utils/option-utils.ts +17 -44
- package/src/lib/progress/fetch-progress.ts +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLoadersFromContext = exports.getLoaderContext = void 0;
|
|
4
|
-
const
|
|
4
|
+
const get_fetch_function_1 = require("./get-fetch-function");
|
|
5
5
|
/**
|
|
6
6
|
* "sub" loaders invoked by other loaders get a "context" injected on `this`
|
|
7
7
|
* The context will inject core methods like `parse` and contain information
|
|
@@ -18,7 +18,7 @@ function getLoaderContext(context, options, previousContext = null) {
|
|
|
18
18
|
return previousContext;
|
|
19
19
|
}
|
|
20
20
|
const resolvedContext = {
|
|
21
|
-
fetch: (0,
|
|
21
|
+
fetch: (0, get_fetch_function_1.getFetchFunction)(options, context),
|
|
22
22
|
...context
|
|
23
23
|
};
|
|
24
24
|
// Recursive loading does not use single loader
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { Loader,
|
|
1
|
+
import type { Loader, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
/**
|
|
3
3
|
* Global state for loaders.gl. Stored on `global.loaders._state`
|
|
4
4
|
*/
|
|
5
5
|
type GlobalLoaderState = {
|
|
6
6
|
loaderRegistry: Loader[];
|
|
7
|
-
globalOptions:
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
};
|
|
7
|
+
globalOptions: LoaderOptions;
|
|
10
8
|
};
|
|
11
9
|
/**
|
|
12
10
|
* Helper for safely accessing global loaders.gl variables
|
|
@@ -18,14 +16,12 @@ export declare function getGlobalLoaderState(): GlobalLoaderState;
|
|
|
18
16
|
* NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks
|
|
19
17
|
* @returns global loader options merged with default loader options
|
|
20
18
|
*/
|
|
21
|
-
export declare const getGlobalLoaderOptions: () =>
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
};
|
|
19
|
+
export declare const getGlobalLoaderOptions: () => LoaderOptions;
|
|
24
20
|
/**
|
|
25
21
|
* Set global loader options
|
|
26
22
|
* @param options
|
|
27
23
|
*/
|
|
28
|
-
export declare function setGlobalOptions(options:
|
|
24
|
+
export declare function setGlobalOptions(options: LoaderOptions): void;
|
|
29
25
|
/**
|
|
30
26
|
* Merges options with global opts and loader defaults, also injects baseUri
|
|
31
27
|
* @param options
|
|
@@ -33,12 +29,6 @@ export declare function setGlobalOptions(options: object): void;
|
|
|
33
29
|
* @param loaders
|
|
34
30
|
* @param url
|
|
35
31
|
*/
|
|
36
|
-
export declare function normalizeOptions(options:
|
|
37
|
-
/**
|
|
38
|
-
* Gets the current fetch function from options and context
|
|
39
|
-
* @param options
|
|
40
|
-
* @param context
|
|
41
|
-
*/
|
|
42
|
-
export declare function getFetchFunction(options?: LoaderOptions, context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>): any;
|
|
32
|
+
export declare function normalizeOptions(options: LoaderOptions, loader: Loader, loaders?: Loader[], url?: string): LoaderOptions;
|
|
43
33
|
export {};
|
|
44
34
|
//# sourceMappingURL=option-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/option-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"option-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/option-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAKpE;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CASxD;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAAO,aAKzC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAI7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,GAAG,CAAC,EAAE,MAAM,GACX,aAAa,CAMf"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// loaders.gl, MIT license
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
+
exports.normalizeOptions = exports.setGlobalOptions = exports.getGlobalLoaderOptions = exports.getGlobalLoaderState = void 0;
|
|
4
5
|
const is_type_1 = require("../../javascript-utils/is-type");
|
|
5
|
-
const fetch_file_1 = require("../fetch/fetch-file");
|
|
6
6
|
const loggers_1 = require("./loggers");
|
|
7
7
|
const option_defaults_1 = require("./option-defaults");
|
|
8
8
|
/**
|
|
@@ -55,30 +55,6 @@ function normalizeOptions(options, loader, loaders, url) {
|
|
|
55
55
|
return normalizeOptionsInternal(loader, options, url);
|
|
56
56
|
}
|
|
57
57
|
exports.normalizeOptions = normalizeOptions;
|
|
58
|
-
/**
|
|
59
|
-
* Gets the current fetch function from options and context
|
|
60
|
-
* @param options
|
|
61
|
-
* @param context
|
|
62
|
-
*/
|
|
63
|
-
function getFetchFunction(options, context) {
|
|
64
|
-
const globalOptions = (0, exports.getGlobalLoaderOptions)();
|
|
65
|
-
const fetchOptions = options || globalOptions;
|
|
66
|
-
// options.fetch can be a function
|
|
67
|
-
if (typeof fetchOptions.fetch === 'function') {
|
|
68
|
-
return fetchOptions.fetch;
|
|
69
|
-
}
|
|
70
|
-
// options.fetch can be an options object
|
|
71
|
-
if ((0, is_type_1.isObject)(fetchOptions.fetch)) {
|
|
72
|
-
return (url) => (0, fetch_file_1.fetchFile)(url, fetchOptions);
|
|
73
|
-
}
|
|
74
|
-
// else refer to context (from parent loader) if available
|
|
75
|
-
if (context?.fetch) {
|
|
76
|
-
return context?.fetch;
|
|
77
|
-
}
|
|
78
|
-
// else return the default fetch function
|
|
79
|
-
return fetch_file_1.fetchFile;
|
|
80
|
-
}
|
|
81
|
-
exports.getFetchFunction = getFetchFunction;
|
|
82
58
|
// VALIDATE OPTIONS
|
|
83
59
|
/**
|
|
84
60
|
* Warn for unsupported options
|
|
@@ -169,11 +145,14 @@ function mergeNestedFields(mergedOptions, options) {
|
|
|
169
145
|
// else: No need to merge nested opts, and the initial merge already copied over the nested options
|
|
170
146
|
}
|
|
171
147
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Harvest information from the url
|
|
150
|
+
* @deprecated This is mainly there to support a hack in the GLTFLoader
|
|
151
|
+
* TODO - baseUri should be a directory, i.e. remove file component from baseUri
|
|
152
|
+
* TODO - extract extension?
|
|
153
|
+
* TODO - extract query parameters?
|
|
154
|
+
* TODO - should these be injected on context instead of options?
|
|
155
|
+
*/
|
|
177
156
|
function addUrlOptions(options, url) {
|
|
178
157
|
if (url && !('baseUri' in options)) {
|
|
179
158
|
options.baseUri = url;
|
|
@@ -17,8 +17,8 @@ onDone = () => { }, onError = () => { }) {
|
|
|
17
17
|
return response;
|
|
18
18
|
}
|
|
19
19
|
const contentLength = response.headers.get('content-length') || 0;
|
|
20
|
-
const totalBytes = contentLength
|
|
21
|
-
if (!(
|
|
20
|
+
const totalBytes = contentLength ? parseInt(contentLength) : 0;
|
|
21
|
+
if (!(totalBytes > 0)) {
|
|
22
22
|
return response;
|
|
23
23
|
}
|
|
24
24
|
// Currently override only implemented in browser
|
package/dist/null-worker.js
CHANGED
|
@@ -184,7 +184,7 @@
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// src/null-loader.ts
|
|
187
|
-
var VERSION = true ? "3.4.0-alpha.
|
|
187
|
+
var VERSION = true ? "3.4.0-alpha.3" : "latest";
|
|
188
188
|
function parseSync(arrayBuffer, options, context) {
|
|
189
189
|
if (!options.null.echoParameters)
|
|
190
190
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/core",
|
|
3
|
-
"version": "3.4.0-alpha.
|
|
3
|
+
"version": "3.4.0-alpha.3",
|
|
4
4
|
"description": "The core API for working with loaders.gl loaders and writers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/runtime": "^7.3.1",
|
|
45
|
-
"@loaders.gl/loader-utils": "3.4.0-alpha.
|
|
46
|
-
"@loaders.gl/worker-utils": "3.4.0-alpha.
|
|
47
|
-
"@probe.gl/log": "^
|
|
45
|
+
"@loaders.gl/loader-utils": "3.4.0-alpha.3",
|
|
46
|
+
"@loaders.gl/worker-utils": "3.4.0-alpha.3",
|
|
47
|
+
"@probe.gl/log": "^4.0.1"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "a954528dd1d78a1f128d8f6b07e4baeb7a296924"
|
|
50
50
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {ReadableOptions} from 'stream';
|
|
2
|
+
import * as Stream from 'stream';
|
|
3
|
+
|
|
4
|
+
class _Readable {}
|
|
5
|
+
|
|
6
|
+
type ReadableType = Stream.Readable | _Readable;
|
|
7
|
+
const Readable = Stream.Readable || _Readable;
|
|
2
8
|
|
|
3
9
|
export type MakeStreamOptions = ReadableOptions;
|
|
4
10
|
|
|
@@ -6,7 +12,7 @@ export type MakeStreamOptions = ReadableOptions;
|
|
|
6
12
|
export function makeStream<ArrayBuffer>(
|
|
7
13
|
source: Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer>,
|
|
8
14
|
options?: ReadableOptions
|
|
9
|
-
):
|
|
15
|
+
): ReadableType {
|
|
10
16
|
const iterator = source[Symbol.asyncIterator]
|
|
11
17
|
? source[Symbol.asyncIterator]()
|
|
12
18
|
: source[Symbol.iterator]();
|
package/src/lib/api/encode.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Writer,
|
|
1
|
+
import {Writer, WriterOptions, canEncodeWithWorker} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {processOnWorker} from '@loaders.gl/worker-utils';
|
|
3
3
|
import {concatenateArrayBuffers, resolvePath} from '@loaders.gl/loader-utils';
|
|
4
4
|
import {isBrowser} from '@loaders.gl/loader-utils';
|
|
@@ -12,9 +12,10 @@ import {getLoaderOptions} from './loader-options';
|
|
|
12
12
|
export async function encode(
|
|
13
13
|
data: any,
|
|
14
14
|
writer: Writer,
|
|
15
|
-
options?:
|
|
15
|
+
options?: WriterOptions
|
|
16
16
|
): Promise<ArrayBuffer> {
|
|
17
|
-
const globalOptions = getLoaderOptions();
|
|
17
|
+
const globalOptions = getLoaderOptions() as WriterOptions;
|
|
18
|
+
// const globalOptions: WriterOptions = {}; // getWriterOptions();
|
|
18
19
|
options = {...globalOptions, ...options};
|
|
19
20
|
if (canEncodeWithWorker(writer, options)) {
|
|
20
21
|
return await processOnWorker(writer, data, options);
|
|
@@ -71,7 +72,7 @@ export async function encode(
|
|
|
71
72
|
/**
|
|
72
73
|
* Encode loaded data into a binary ArrayBuffer using the specified Writer.
|
|
73
74
|
*/
|
|
74
|
-
export function encodeSync(data: any, writer: Writer, options?:
|
|
75
|
+
export function encodeSync(data: any, writer: Writer, options?: WriterOptions): ArrayBuffer {
|
|
75
76
|
if (writer.encodeSync) {
|
|
76
77
|
return writer.encodeSync(data, options);
|
|
77
78
|
}
|
|
@@ -87,7 +88,7 @@ export function encodeSync(data: any, writer: Writer, options?: LoaderOptions):
|
|
|
87
88
|
export async function encodeText(
|
|
88
89
|
data: any,
|
|
89
90
|
writer: Writer,
|
|
90
|
-
options?:
|
|
91
|
+
options?: WriterOptions
|
|
91
92
|
): Promise<string> {
|
|
92
93
|
if (writer.text && writer.encodeText) {
|
|
93
94
|
return await writer.encodeText(data, options);
|
|
@@ -107,7 +108,7 @@ export async function encodeText(
|
|
|
107
108
|
export function encodeInBatches(
|
|
108
109
|
data: any,
|
|
109
110
|
writer: Writer,
|
|
110
|
-
options?:
|
|
111
|
+
options?: WriterOptions
|
|
111
112
|
): AsyncIterable<ArrayBuffer> {
|
|
112
113
|
if (writer.encodeInBatches) {
|
|
113
114
|
const dataIterator = getIterator(data);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {LoaderWithParser, LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {isLoaderObject} from '../loader-utils/normalize-loader';
|
|
3
|
-
import {getFetchFunction} from '../loader-utils/
|
|
3
|
+
import {getFetchFunction} from '../loader-utils/get-fetch-function';
|
|
4
4
|
|
|
5
5
|
import {parseInBatches} from './parse-in-batches';
|
|
6
6
|
|
package/src/lib/api/load.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {DataType, Loader, LoaderContext, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {isBlob} from '../../javascript-utils/is-type';
|
|
3
3
|
import {isLoaderObject} from '../loader-utils/normalize-loader';
|
|
4
|
-
import {getFetchFunction} from '../loader-utils/
|
|
4
|
+
import {getFetchFunction} from '../loader-utils/get-fetch-function';
|
|
5
5
|
|
|
6
6
|
import {parse} from './parse';
|
|
7
7
|
|
|
@@ -41,9 +41,10 @@ export async function load(
|
|
|
41
41
|
|
|
42
42
|
if (isBlob(url)) {
|
|
43
43
|
// The fetch response object will contain blob.name
|
|
44
|
+
// @ts-expect-error TODO - This may not work for overridden fetch functions
|
|
44
45
|
data = await fetch(url);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
// Data is loaded (at least we have a `Response` object) so time to hand over to `parse`
|
|
48
|
-
return await parse(data, loaders, options);
|
|
49
|
+
return await parse(data, loaders as Loader[], options);
|
|
49
50
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import type {LoaderContext, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
4
|
+
import {isObject} from '../../javascript-utils/is-type';
|
|
5
|
+
import {fetchFile} from '../fetch/fetch-file';
|
|
6
|
+
import {getGlobalLoaderOptions} from './option-utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets the current fetch function from options and context
|
|
10
|
+
* @param options
|
|
11
|
+
* @param context
|
|
12
|
+
*/
|
|
13
|
+
export function getFetchFunction(
|
|
14
|
+
options?: LoaderOptions,
|
|
15
|
+
context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>
|
|
16
|
+
) {
|
|
17
|
+
const globalOptions = getGlobalLoaderOptions();
|
|
18
|
+
|
|
19
|
+
const fetchOptions = options || globalOptions;
|
|
20
|
+
|
|
21
|
+
// options.fetch can be a function
|
|
22
|
+
if (typeof fetchOptions.fetch === 'function') {
|
|
23
|
+
return fetchOptions.fetch;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// options.fetch can be an options object
|
|
27
|
+
if (isObject(fetchOptions.fetch)) {
|
|
28
|
+
return (url) => fetchFile(url, fetchOptions as RequestInit);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// else refer to context (from parent loader) if available
|
|
32
|
+
if (context?.fetch) {
|
|
33
|
+
return context?.fetch;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// else return the default fetch function
|
|
37
|
+
return fetchFile;
|
|
38
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {Loader, LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
|
|
2
|
-
import {getFetchFunction} from './
|
|
2
|
+
import {getFetchFunction} from './get-fetch-function';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* "sub" loaders invoked by other loaders get a "context" injected on `this`
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
2
4
|
import {isPureObject, isObject} from '../../javascript-utils/is-type';
|
|
3
|
-
import {fetchFile} from '../fetch/fetch-file';
|
|
4
5
|
import {probeLog, NullLog} from './loggers';
|
|
5
6
|
import {DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS} from './option-defaults';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* Global state for loaders.gl. Stored on `global.loaders._state`
|
|
8
10
|
*/
|
|
9
11
|
type GlobalLoaderState = {
|
|
10
12
|
loaderRegistry: Loader[];
|
|
11
|
-
globalOptions:
|
|
13
|
+
globalOptions: LoaderOptions;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -31,7 +33,7 @@ export function getGlobalLoaderState(): GlobalLoaderState {
|
|
|
31
33
|
* NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks
|
|
32
34
|
* @returns global loader options merged with default loader options
|
|
33
35
|
*/
|
|
34
|
-
export const getGlobalLoaderOptions = () => {
|
|
36
|
+
export const getGlobalLoaderOptions = (): LoaderOptions => {
|
|
35
37
|
const state = getGlobalLoaderState();
|
|
36
38
|
// Ensure all default loader options from this library are mentioned
|
|
37
39
|
state.globalOptions = state.globalOptions || {...DEFAULT_LOADER_OPTIONS};
|
|
@@ -42,7 +44,7 @@ export const getGlobalLoaderOptions = () => {
|
|
|
42
44
|
* Set global loader options
|
|
43
45
|
* @param options
|
|
44
46
|
*/
|
|
45
|
-
export function setGlobalOptions(options:
|
|
47
|
+
export function setGlobalOptions(options: LoaderOptions): void {
|
|
46
48
|
const state = getGlobalLoaderState();
|
|
47
49
|
const globalOptions = getGlobalLoaderOptions();
|
|
48
50
|
state.globalOptions = normalizeOptionsInternal(globalOptions, options);
|
|
@@ -56,11 +58,11 @@ export function setGlobalOptions(options: object): void {
|
|
|
56
58
|
* @param url
|
|
57
59
|
*/
|
|
58
60
|
export function normalizeOptions(
|
|
59
|
-
options:
|
|
61
|
+
options: LoaderOptions,
|
|
60
62
|
loader: Loader,
|
|
61
63
|
loaders?: Loader[],
|
|
62
64
|
url?: string
|
|
63
|
-
):
|
|
65
|
+
): LoaderOptions {
|
|
64
66
|
loaders = loaders || [];
|
|
65
67
|
loaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
66
68
|
|
|
@@ -68,38 +70,6 @@ export function normalizeOptions(
|
|
|
68
70
|
return normalizeOptionsInternal(loader, options, url);
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
/**
|
|
72
|
-
* Gets the current fetch function from options and context
|
|
73
|
-
* @param options
|
|
74
|
-
* @param context
|
|
75
|
-
*/
|
|
76
|
-
export function getFetchFunction(
|
|
77
|
-
options?: LoaderOptions,
|
|
78
|
-
context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>
|
|
79
|
-
) {
|
|
80
|
-
const globalOptions = getGlobalLoaderOptions();
|
|
81
|
-
|
|
82
|
-
const fetchOptions = options || globalOptions;
|
|
83
|
-
|
|
84
|
-
// options.fetch can be a function
|
|
85
|
-
if (typeof fetchOptions.fetch === 'function') {
|
|
86
|
-
return fetchOptions.fetch;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// options.fetch can be an options object
|
|
90
|
-
if (isObject(fetchOptions.fetch)) {
|
|
91
|
-
return (url) => fetchFile(url, fetchOptions);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// else refer to context (from parent loader) if available
|
|
95
|
-
if (context?.fetch) {
|
|
96
|
-
return context?.fetch;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// else return the default fetch function
|
|
100
|
-
return fetchFile;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
73
|
// VALIDATE OPTIONS
|
|
104
74
|
|
|
105
75
|
/**
|
|
@@ -214,11 +184,14 @@ function mergeNestedFields(mergedOptions, options) {
|
|
|
214
184
|
}
|
|
215
185
|
}
|
|
216
186
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Harvest information from the url
|
|
189
|
+
* @deprecated This is mainly there to support a hack in the GLTFLoader
|
|
190
|
+
* TODO - baseUri should be a directory, i.e. remove file component from baseUri
|
|
191
|
+
* TODO - extract extension?
|
|
192
|
+
* TODO - extract query parameters?
|
|
193
|
+
* TODO - should these be injected on context instead of options?
|
|
194
|
+
*/
|
|
222
195
|
function addUrlOptions(options, url?: string) {
|
|
223
196
|
if (url && !('baseUri' in options)) {
|
|
224
197
|
options.baseUri = url;
|
|
@@ -20,8 +20,8 @@ export default async function fetchProgress(
|
|
|
20
20
|
return response;
|
|
21
21
|
}
|
|
22
22
|
const contentLength = response.headers.get('content-length') || 0;
|
|
23
|
-
const totalBytes = contentLength
|
|
24
|
-
if (!(
|
|
23
|
+
const totalBytes = contentLength ? parseInt(contentLength) : 0;
|
|
24
|
+
if (!(totalBytes > 0)) {
|
|
25
25
|
return response;
|
|
26
26
|
}
|
|
27
27
|
// Currently override only implemented in browser
|