@loaders.gl/core 3.4.0-alpha.1 → 3.4.0-alpha.2
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 +281 -233
- package/dist/es5/iterators/make-stream/make-node-stream.js +13 -6
- package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/es5/lib/api/encode.js.map +1 -1
- package/dist/es5/lib/api/load-in-batches.js +2 -2
- package/dist/es5/lib/api/load-in-batches.js.map +1 -1
- package/dist/es5/lib/api/load.js +2 -2
- package/dist/es5/lib/api/load.js.map +1 -1
- package/dist/es5/lib/init.js +1 -1
- package/dist/es5/lib/loader-utils/get-fetch-function.js +31 -0
- package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -0
- package/dist/es5/lib/loader-utils/loader-context.js +2 -2
- package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-utils.js +20 -43
- package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/es5/null-loader.js +1 -1
- package/dist/esm/iterators/make-stream/make-node-stream.js +3 -1
- package/dist/esm/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/esm/lib/api/encode.js.map +1 -1
- package/dist/esm/lib/api/load-in-batches.js +1 -1
- package/dist/esm/lib/api/load-in-batches.js.map +1 -1
- package/dist/esm/lib/api/load.js +1 -1
- package/dist/esm/lib/api/load.js.map +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/lib/loader-utils/get-fetch-function.js +25 -0
- package/dist/esm/lib/loader-utils/get-fetch-function.js.map +1 -0
- package/dist/esm/lib/loader-utils/loader-context.js +1 -1
- package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/esm/lib/loader-utils/option-utils.js +2 -20
- package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/esm/null-loader.js +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/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/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/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;
|