@loaders.gl/core 3.1.0-alpha.5 → 3.1.0-beta.4

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.
Files changed (155) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +3380 -0
  4. package/dist/core-addons/write-file-browser.d.ts +1 -0
  5. package/dist/core-addons/write-file-browser.d.ts.map +1 -0
  6. package/dist/core-addons/write-file-browser.js +60 -0
  7. package/dist/es5/lib/api/register-loaders.js.map +1 -1
  8. package/dist/es5/lib/init.js +1 -1
  9. package/dist/es5/lib/init.js.map +1 -1
  10. package/dist/es5/null-loader.js +1 -1
  11. package/dist/es5/null-loader.js.map +1 -1
  12. package/dist/esm/lib/api/register-loaders.js.map +1 -1
  13. package/dist/esm/lib/init.js +1 -1
  14. package/dist/esm/lib/init.js.map +1 -1
  15. package/dist/esm/null-loader.js +1 -1
  16. package/dist/esm/null-loader.js.map +1 -1
  17. package/dist/index.d.ts +31 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +106 -0
  20. package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts +5 -0
  21. package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts.map +1 -0
  22. package/dist/iterators/batch-iterators/timed-batch-iterator.js +22 -0
  23. package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +9 -0
  24. package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -0
  25. package/dist/iterators/make-iterator/make-array-buffer-iterator.js +27 -0
  26. package/dist/iterators/make-iterator/make-blob-iterator.d.ts +9 -0
  27. package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -0
  28. package/dist/iterators/make-iterator/make-blob-iterator.js +21 -0
  29. package/dist/iterators/make-iterator/make-iterator.d.ts +19 -0
  30. package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -0
  31. package/dist/iterators/make-iterator/make-iterator.js +37 -0
  32. package/dist/iterators/make-iterator/make-stream-iterator.d.ts +11 -0
  33. package/dist/iterators/make-iterator/make-stream-iterator.d.ts.map +1 -0
  34. package/dist/iterators/make-iterator/make-stream-iterator.js +96 -0
  35. package/dist/iterators/make-iterator/make-string-iterator.d.ts +9 -0
  36. package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -0
  37. package/dist/iterators/make-iterator/make-string-iterator.js +24 -0
  38. package/dist/iterators/make-stream/make-dom-stream.d.ts +9 -0
  39. package/dist/iterators/make-stream/make-dom-stream.d.ts.map +1 -0
  40. package/dist/iterators/make-stream/make-dom-stream.js +41 -0
  41. package/dist/iterators/make-stream/make-node-stream.d.ts +7 -0
  42. package/dist/iterators/make-stream/make-node-stream.d.ts.map +1 -0
  43. package/dist/iterators/make-stream/make-node-stream.js +58 -0
  44. package/dist/iterators/make-stream/make-stream.d.ts +9 -0
  45. package/dist/iterators/make-stream/make-stream.d.ts.map +1 -0
  46. package/dist/iterators/make-stream/make-stream.js +16 -0
  47. package/dist/javascript-utils/is-type.d.ts +22 -0
  48. package/dist/javascript-utils/is-type.d.ts.map +1 -0
  49. package/dist/javascript-utils/is-type.js +41 -0
  50. package/dist/lib/api/encode.d.ts +26 -0
  51. package/dist/lib/api/encode.d.ts.map +1 -0
  52. package/dist/lib/api/encode.js +111 -0
  53. package/dist/lib/api/load-in-batches.d.ts +13 -0
  54. package/dist/lib/api/load-in-batches.d.ts.map +1 -0
  55. package/dist/lib/api/load-in-batches.js +33 -0
  56. package/dist/lib/api/load.d.ts +12 -0
  57. package/dist/lib/api/load.d.ts.map +1 -0
  58. package/dist/lib/api/load.js +41 -0
  59. package/dist/lib/api/parse-in-batches.d.ts +10 -0
  60. package/dist/lib/api/parse-in-batches.d.ts.map +1 -0
  61. package/dist/lib/api/parse-in-batches.js +120 -0
  62. package/dist/lib/api/parse-sync.d.ts +10 -0
  63. package/dist/lib/api/parse-sync.d.ts.map +1 -0
  64. package/dist/lib/api/parse-sync.js +59 -0
  65. package/dist/lib/api/parse.d.ts +10 -0
  66. package/dist/lib/api/parse.d.ts.map +1 -0
  67. package/dist/lib/api/parse.js +74 -0
  68. package/dist/lib/api/register-loaders.d.ts +7 -0
  69. package/dist/lib/api/register-loaders.d.ts.map +1 -0
  70. package/dist/lib/api/register-loaders.js +35 -0
  71. package/dist/lib/api/save.d.ts +4 -0
  72. package/dist/lib/api/save.d.ts.map +1 -0
  73. package/dist/lib/api/save.js +15 -0
  74. package/dist/lib/api/select-loader.d.ts +22 -0
  75. package/dist/lib/api/select-loader.d.ts.map +1 -0
  76. package/dist/lib/api/select-loader.js +239 -0
  77. package/dist/lib/api/set-loader-options.d.ts +6 -0
  78. package/dist/lib/api/set-loader-options.d.ts.map +1 -0
  79. package/dist/lib/api/set-loader-options.js +12 -0
  80. package/dist/lib/common.d.ts +2 -0
  81. package/dist/lib/common.d.ts.map +1 -0
  82. package/dist/lib/common.js +2 -0
  83. package/dist/lib/fetch/fetch-error-message.d.ts +3 -0
  84. package/dist/lib/fetch/fetch-error-message.d.ts.map +1 -0
  85. package/dist/lib/fetch/fetch-error-message.js +25 -0
  86. package/dist/lib/fetch/fetch-file.d.ts +13 -0
  87. package/dist/lib/fetch/fetch-file.d.ts.map +1 -0
  88. package/dist/lib/fetch/fetch-file.js +27 -0
  89. package/dist/lib/fetch/read-array-buffer.d.ts +17 -0
  90. package/dist/lib/fetch/read-array-buffer.d.ts.map +1 -0
  91. package/dist/lib/fetch/read-array-buffer.js +41 -0
  92. package/dist/lib/fetch/read-file.d.ts +5 -0
  93. package/dist/lib/fetch/read-file.d.ts.map +1 -0
  94. package/dist/lib/fetch/read-file.js +29 -0
  95. package/dist/lib/fetch/write-file.d.ts +3 -0
  96. package/dist/lib/fetch/write-file.d.ts.map +1 -0
  97. package/dist/lib/fetch/write-file.js +22 -0
  98. package/dist/lib/filesystems/browser-filesystem.d.ts +58 -0
  99. package/dist/lib/filesystems/browser-filesystem.d.ts.map +1 -0
  100. package/dist/lib/filesystems/browser-filesystem.js +126 -0
  101. package/dist/lib/filesystems/filesystem.d.ts +46 -0
  102. package/dist/lib/filesystems/filesystem.d.ts.map +1 -0
  103. package/dist/lib/filesystems/filesystem.js +2 -0
  104. package/dist/lib/filesystems/read-array-buffer.d.ts +19 -0
  105. package/dist/lib/filesystems/read-array-buffer.d.ts.map +1 -0
  106. package/dist/lib/filesystems/read-array-buffer.js +29 -0
  107. package/dist/lib/init.d.ts +3 -0
  108. package/dist/lib/init.d.ts.map +1 -0
  109. package/dist/lib/init.js +10 -0
  110. package/dist/lib/loader-utils/check-errors.d.ts +3 -0
  111. package/dist/lib/loader-utils/check-errors.d.ts.map +1 -0
  112. package/dist/lib/loader-utils/check-errors.js +30 -0
  113. package/dist/lib/loader-utils/get-data.d.ts +6 -0
  114. package/dist/lib/loader-utils/get-data.d.ts.map +1 -0
  115. package/dist/lib/loader-utils/get-data.js +129 -0
  116. package/dist/lib/loader-utils/loader-context.d.ts +13 -0
  117. package/dist/lib/loader-utils/loader-context.d.ts.map +1 -0
  118. package/dist/lib/loader-utils/loader-context.js +49 -0
  119. package/dist/lib/loader-utils/loggers.d.ts +16 -0
  120. package/dist/lib/loader-utils/loggers.d.ts.map +1 -0
  121. package/dist/lib/loader-utils/loggers.js +41 -0
  122. package/dist/lib/loader-utils/normalize-loader.d.ts +4 -0
  123. package/dist/lib/loader-utils/normalize-loader.d.ts.map +1 -0
  124. package/dist/lib/loader-utils/normalize-loader.js +52 -0
  125. package/dist/lib/loader-utils/option-defaults.d.ts +20 -0
  126. package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -0
  127. package/dist/lib/loader-utils/option-defaults.js +41 -0
  128. package/dist/lib/loader-utils/option-utils.d.ts +36 -0
  129. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -0
  130. package/dist/lib/loader-utils/option-utils.js +177 -0
  131. package/dist/lib/progress/fetch-progress.d.ts +6 -0
  132. package/dist/lib/progress/fetch-progress.d.ts.map +1 -0
  133. package/dist/lib/progress/fetch-progress.js +59 -0
  134. package/dist/lib/utils/mime-type-utils.d.ts +20 -0
  135. package/dist/lib/utils/mime-type-utils.d.ts.map +1 -0
  136. package/dist/lib/utils/mime-type-utils.js +42 -0
  137. package/dist/lib/utils/resource-utils.d.ts +21 -0
  138. package/dist/lib/utils/resource-utils.d.ts.map +1 -0
  139. package/dist/lib/utils/resource-utils.js +78 -0
  140. package/dist/lib/utils/response-utils.d.ts +18 -0
  141. package/dist/lib/utils/response-utils.d.ts.map +1 -0
  142. package/dist/lib/utils/response-utils.js +114 -0
  143. package/dist/null-loader.d.ts +10 -0
  144. package/dist/null-loader.d.ts.map +1 -0
  145. package/dist/null-loader.js +44 -0
  146. package/dist/null-worker.js +178 -2
  147. package/dist/workers/null-worker.d.ts +2 -0
  148. package/dist/workers/null-worker.d.ts.map +1 -0
  149. package/dist/workers/null-worker.js +5 -0
  150. package/package.json +7 -7
  151. package/src/lib/api/register-loaders.ts +2 -1
  152. package/src/lib/{init.js → init.ts} +0 -0
  153. package/dist/dist.min.js +0 -2
  154. package/dist/dist.min.js.map +0 -1
  155. package/dist/null-worker.js.map +0 -1
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getReadableStream = exports.getAsyncIterableFromData = exports.getArrayBufferOrStringFromData = exports.getArrayBufferOrStringFromDataSync = void 0;
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
+ const is_type_1 = require("../../javascript-utils/is-type");
6
+ const make_iterator_1 = require("../../iterators/make-iterator/make-iterator");
7
+ const response_utils_1 = require("../utils/response-utils");
8
+ const ERR_DATA = 'Cannot convert supplied data type';
9
+ // eslint-disable-next-line complexity
10
+ function getArrayBufferOrStringFromDataSync(data, loader, options) {
11
+ if (loader.text && typeof data === 'string') {
12
+ return data;
13
+ }
14
+ if ((0, is_type_1.isBuffer)(data)) {
15
+ // @ts-ignore
16
+ data = data.buffer;
17
+ }
18
+ if (data instanceof ArrayBuffer) {
19
+ const arrayBuffer = data;
20
+ if (loader.text && !loader.binary) {
21
+ const textDecoder = new TextDecoder('utf8');
22
+ return textDecoder.decode(arrayBuffer);
23
+ }
24
+ return arrayBuffer;
25
+ }
26
+ // We may need to handle offsets
27
+ if (ArrayBuffer.isView(data)) {
28
+ // TextDecoder is invoked on typed arrays and will handle offsets
29
+ if (loader.text && !loader.binary) {
30
+ const textDecoder = new TextDecoder('utf8');
31
+ return textDecoder.decode(data);
32
+ }
33
+ let arrayBuffer = data.buffer;
34
+ // Since we are returning the underlying arrayBuffer, we must create a new copy
35
+ // if this typed array / Buffer is a partial view into the ArryayBuffer
36
+ // TODO - this is a potentially unnecessary copy
37
+ const byteLength = data.byteLength || data.length;
38
+ if (data.byteOffset !== 0 || byteLength !== arrayBuffer.byteLength) {
39
+ // console.warn(`loaders.gl copying arraybuffer of length ${byteLength}`);
40
+ arrayBuffer = arrayBuffer.slice(data.byteOffset, data.byteOffset + byteLength);
41
+ }
42
+ return arrayBuffer;
43
+ }
44
+ throw new Error(ERR_DATA);
45
+ }
46
+ exports.getArrayBufferOrStringFromDataSync = getArrayBufferOrStringFromDataSync;
47
+ // Convert async iterator to a promise
48
+ async function getArrayBufferOrStringFromData(data, loader, options) {
49
+ const isArrayBuffer = data instanceof ArrayBuffer || ArrayBuffer.isView(data);
50
+ if (typeof data === 'string' || isArrayBuffer) {
51
+ return getArrayBufferOrStringFromDataSync(data, loader, options);
52
+ }
53
+ // Blobs and files are FileReader compatible
54
+ if ((0, is_type_1.isBlob)(data)) {
55
+ data = await (0, response_utils_1.makeResponse)(data);
56
+ }
57
+ if ((0, is_type_1.isResponse)(data)) {
58
+ const response = data;
59
+ await (0, response_utils_1.checkResponse)(response);
60
+ return loader.binary ? await response.arrayBuffer() : await response.text();
61
+ }
62
+ if ((0, is_type_1.isReadableStream)(data)) {
63
+ // @ts-expect-error TS2559 options type
64
+ data = (0, make_iterator_1.makeIterator)(data, options);
65
+ }
66
+ if ((0, is_type_1.isIterable)(data) || (0, is_type_1.isAsyncIterable)(data)) {
67
+ // Assume arrayBuffer iterator - attempt to concatenate
68
+ return (0, loader_utils_1.concatenateArrayBuffersAsync)(data);
69
+ }
70
+ throw new Error(ERR_DATA);
71
+ }
72
+ exports.getArrayBufferOrStringFromData = getArrayBufferOrStringFromData;
73
+ async function getAsyncIterableFromData(data, options) {
74
+ if ((0, is_type_1.isIterator)(data)) {
75
+ return data;
76
+ }
77
+ if ((0, is_type_1.isResponse)(data)) {
78
+ const response = data;
79
+ // Note Since this function is not async, we currently can't load error message, just status
80
+ await (0, response_utils_1.checkResponse)(response);
81
+ // TODO - bug in polyfill, body can be a Promise under Node.js
82
+ // eslint-disable-next-line @typescript-eslint/await-thenable
83
+ const body = await response.body;
84
+ // TODO - body can be null?
85
+ return (0, make_iterator_1.makeIterator)(body, options);
86
+ }
87
+ if ((0, is_type_1.isBlob)(data) || (0, is_type_1.isReadableStream)(data)) {
88
+ return (0, make_iterator_1.makeIterator)(data, options);
89
+ }
90
+ if ((0, is_type_1.isAsyncIterable)(data)) {
91
+ return data[Symbol.asyncIterator]();
92
+ }
93
+ return getIterableFromData(data);
94
+ }
95
+ exports.getAsyncIterableFromData = getAsyncIterableFromData;
96
+ async function getReadableStream(data) {
97
+ if ((0, is_type_1.isReadableStream)(data)) {
98
+ return data;
99
+ }
100
+ if ((0, is_type_1.isResponse)(data)) {
101
+ // @ts-ignore
102
+ return data.body;
103
+ }
104
+ const response = await (0, response_utils_1.makeResponse)(data);
105
+ // @ts-ignore
106
+ return response.body;
107
+ }
108
+ exports.getReadableStream = getReadableStream;
109
+ // HELPERS
110
+ function getIterableFromData(data) {
111
+ // generate an iterator that emits a single chunk
112
+ if (ArrayBuffer.isView(data)) {
113
+ return (function* oneChunk() {
114
+ yield data.buffer;
115
+ })();
116
+ }
117
+ if (data instanceof ArrayBuffer) {
118
+ return (function* oneChunk() {
119
+ yield data;
120
+ })();
121
+ }
122
+ if ((0, is_type_1.isIterator)(data)) {
123
+ return data;
124
+ }
125
+ if ((0, is_type_1.isIterable)(data)) {
126
+ return data[Symbol.iterator]();
127
+ }
128
+ throw new Error(ERR_DATA);
129
+ }
@@ -0,0 +1,13 @@
1
+ import type { Loader, LoaderOptions, LoaderContext } from '@loaders.gl/loader-utils';
2
+ /**
3
+ * "sub" loaders invoked by other loaders get a "context" injected on `this`
4
+ * The context will inject core methods like `parse` and contain information
5
+ * about loaders and options passed in to the top-level `parse` call.
6
+ *
7
+ * @param context
8
+ * @param options
9
+ * @param previousContext
10
+ */
11
+ export declare function getLoaderContext(context: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>, options?: LoaderOptions, previousContext?: LoaderContext | null): LoaderContext;
12
+ export declare function getLoadersFromContext(loaders: Loader[] | Loader | undefined, context?: LoaderContext): any;
13
+ //# sourceMappingURL=loader-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader-context.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/loader-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAGnF;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,EAC7E,OAAO,CAAC,EAAE,aAAa,EACvB,eAAe,GAAE,aAAa,GAAG,IAAW,GAC3C,aAAa,CAkBf;AAGD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,EACtC,OAAO,CAAC,EAAE,aAAa,OAkBxB"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLoadersFromContext = exports.getLoaderContext = void 0;
4
+ const option_utils_1 = require("./option-utils");
5
+ /**
6
+ * "sub" loaders invoked by other loaders get a "context" injected on `this`
7
+ * The context will inject core methods like `parse` and contain information
8
+ * about loaders and options passed in to the top-level `parse` call.
9
+ *
10
+ * @param context
11
+ * @param options
12
+ * @param previousContext
13
+ */
14
+ function getLoaderContext(context, options, previousContext = null) {
15
+ // For recursive calls, we already have a context
16
+ // TODO - add any additional loaders to context?
17
+ if (previousContext) {
18
+ return previousContext;
19
+ }
20
+ const resolvedContext = {
21
+ fetch: (0, option_utils_1.getFetchFunction)(options, context),
22
+ ...context
23
+ };
24
+ // Recursive loading does not use single loader
25
+ if (!Array.isArray(resolvedContext.loaders)) {
26
+ resolvedContext.loaders = null;
27
+ }
28
+ return resolvedContext;
29
+ }
30
+ exports.getLoaderContext = getLoaderContext;
31
+ // eslint-disable-next-line complexity
32
+ function getLoadersFromContext(loaders, context) {
33
+ // A single non-array loader is force selected, but only on top-level (context === null)
34
+ if (!context && loaders && !Array.isArray(loaders)) {
35
+ return loaders;
36
+ }
37
+ // Create a merged list
38
+ let candidateLoaders;
39
+ if (loaders) {
40
+ candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];
41
+ }
42
+ if (context && context.loaders) {
43
+ const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];
44
+ candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
45
+ }
46
+ // If no loaders, return null to look in globally registered loaders
47
+ return candidateLoaders && candidateLoaders.length ? candidateLoaders : null;
48
+ }
49
+ exports.getLoadersFromContext = getLoadersFromContext;
@@ -0,0 +1,16 @@
1
+ export declare const probeLog: any;
2
+ export declare class NullLog {
3
+ log(): () => void;
4
+ info(): () => void;
5
+ warn(): () => void;
6
+ error(): () => void;
7
+ }
8
+ export declare class ConsoleLog {
9
+ console: any;
10
+ constructor();
11
+ log(...args: any[]): any;
12
+ info(...args: any[]): any;
13
+ warn(...args: any[]): any;
14
+ error(...args: any[]): any;
15
+ }
16
+ //# sourceMappingURL=loggers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loggers.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/loggers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,KAA8B,CAAC;AAGpD,qBAAa,OAAO;IAClB,GAAG;IAGH,IAAI;IAGJ,IAAI;IAGJ,KAAK;CAGN;AAGD,qBAAa,UAAU;IACrB,OAAO,MAAC;;IAKR,GAAG,CAAC,GAAG,IAAI,OAAA;IAGX,IAAI,CAAC,GAAG,IAAI,OAAA;IAGZ,IAAI,CAAC,GAAG,IAAI,OAAA;IAGZ,KAAK,CAAC,GAAG,IAAI,OAAA;CAGd"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleLog = exports.NullLog = exports.probeLog = void 0;
4
+ // probe.gl Log compatible loggers
5
+ const probe_gl_1 = require("probe.gl");
6
+ exports.probeLog = new probe_gl_1.Log({ id: 'loaders.gl' });
7
+ // Logs nothing
8
+ class NullLog {
9
+ log() {
10
+ return () => { };
11
+ }
12
+ info() {
13
+ return () => { };
14
+ }
15
+ warn() {
16
+ return () => { };
17
+ }
18
+ error() {
19
+ return () => { };
20
+ }
21
+ }
22
+ exports.NullLog = NullLog;
23
+ // Logs to console
24
+ class ConsoleLog {
25
+ constructor() {
26
+ this.console = console; // eslint-disable-line
27
+ }
28
+ log(...args) {
29
+ return this.console.log.bind(this.console, ...args);
30
+ }
31
+ info(...args) {
32
+ return this.console.info.bind(this.console, ...args);
33
+ }
34
+ warn(...args) {
35
+ return this.console.warn.bind(this.console, ...args);
36
+ }
37
+ error(...args) {
38
+ return this.console.error.bind(this.console, ...args);
39
+ }
40
+ }
41
+ exports.ConsoleLog = ConsoleLog;
@@ -0,0 +1,4 @@
1
+ import type { Loader } from '@loaders.gl/loader-utils';
2
+ export declare function isLoaderObject(loader?: any): boolean;
3
+ export declare function normalizeLoader(loader: Loader): Loader;
4
+ //# sourceMappingURL=normalize-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/normalize-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAGrD,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAqBpD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAiCtD"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeLoader = exports.isLoaderObject = void 0;
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
+ function isLoaderObject(loader) {
6
+ if (!loader) {
7
+ return false;
8
+ }
9
+ if (Array.isArray(loader)) {
10
+ loader = loader[0];
11
+ }
12
+ const hasExtensions = Array.isArray(loader?.extensions);
13
+ /* Now handled by types and worker loaders do not have these
14
+ let hasParser =
15
+ loader.parseTextSync ||
16
+ loader.parseSync ||
17
+ loader.parse ||
18
+ loader.parseStream || // TODO Remove, Replace with parseInBatches
19
+ loader.parseInBatches;
20
+ */
21
+ return hasExtensions;
22
+ }
23
+ exports.isLoaderObject = isLoaderObject;
24
+ function normalizeLoader(loader) {
25
+ // This error is fairly easy to trigger by mixing up import statements etc
26
+ // So we make an exception and add a developer error message for this case
27
+ // To help new users from getting stuck here
28
+ (0, loader_utils_1.assert)(loader, 'null loader');
29
+ (0, loader_utils_1.assert)(isLoaderObject(loader), 'invalid loader');
30
+ // NORMALIZE [LOADER, OPTIONS] => LOADER
31
+ // If [loader, options], create a new loaders object with options merged in
32
+ let options;
33
+ if (Array.isArray(loader)) {
34
+ options = loader[1];
35
+ loader = loader[0];
36
+ loader = {
37
+ ...loader,
38
+ options: { ...loader.options, ...options }
39
+ };
40
+ }
41
+ // NORMALIZE text and binary flags
42
+ // Ensure at least one of text/binary flags are properly set
43
+ // @ts-expect-error
44
+ if (loader?.parseTextSync || loader?.parseText) {
45
+ loader.text = true;
46
+ }
47
+ if (!loader.text) {
48
+ loader.binary = true;
49
+ }
50
+ return loader;
51
+ }
52
+ exports.normalizeLoader = normalizeLoader;
@@ -0,0 +1,20 @@
1
+ import type { LoaderOptions } from '@loaders.gl/loader-utils';
2
+ export declare const DEFAULT_LOADER_OPTIONS: LoaderOptions;
3
+ export declare const REMOVED_LOADER_OPTIONS: {
4
+ throws: string;
5
+ dataType: string;
6
+ uri: string;
7
+ method: string;
8
+ headers: string;
9
+ body: string;
10
+ mode: string;
11
+ credentials: string;
12
+ cache: string;
13
+ redirect: string;
14
+ referrer: string;
15
+ referrerPolicy: string;
16
+ integrity: string;
17
+ keepalive: string;
18
+ signal: string;
19
+ };
20
+ //# sourceMappingURL=option-defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-defaults.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/option-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAG5D,eAAO,MAAM,sBAAsB,EAAE,aAoBpC,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;CAiBlC,CAAC"}
@@ -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"}