@loaders.gl/loader-utils 3.1.0-alpha.2 → 3.1.0-beta.1

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 (199) hide show
  1. package/dist/es5/index.js +323 -0
  2. package/dist/es5/index.js.map +1 -0
  3. package/dist/es5/json-loader.js +29 -0
  4. package/dist/es5/json-loader.js.map +1 -0
  5. package/dist/es5/lib/binary-utils/array-buffer-utils.js +102 -0
  6. package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -0
  7. package/dist/es5/lib/binary-utils/binary-copy-utils.js +35 -0
  8. package/dist/es5/lib/binary-utils/binary-copy-utils.js.map +1 -0
  9. package/dist/es5/lib/binary-utils/buffer-utils.js +32 -0
  10. package/dist/es5/lib/binary-utils/buffer-utils.js.map +1 -0
  11. package/dist/es5/lib/binary-utils/encode-utils.js +42 -0
  12. package/dist/es5/lib/binary-utils/encode-utils.js.map +1 -0
  13. package/dist/es5/lib/binary-utils/get-first-characters.js +36 -0
  14. package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -0
  15. package/dist/es5/lib/binary-utils/memory-copy-utils.js +39 -0
  16. package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -0
  17. package/dist/es5/lib/env-utils/assert.js +13 -0
  18. package/dist/es5/lib/env-utils/assert.js.map +1 -0
  19. package/dist/es5/lib/env-utils/globals.js +28 -0
  20. package/dist/es5/lib/env-utils/globals.js.map +1 -0
  21. package/dist/es5/lib/filesystems/node-filesystem.js +74 -0
  22. package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -0
  23. package/dist/es5/lib/iterators/async-iteration.js +51 -0
  24. package/dist/es5/lib/iterators/async-iteration.js.map +1 -0
  25. package/dist/es5/lib/iterators/text-iterators.js +59 -0
  26. package/dist/es5/lib/iterators/text-iterators.js.map +1 -0
  27. package/dist/es5/lib/node/buffer.js +38 -0
  28. package/dist/es5/lib/node/buffer.js.map +1 -0
  29. package/dist/es5/lib/node/fs.js +52 -0
  30. package/dist/es5/lib/node/fs.js.map +1 -0
  31. package/dist/es5/lib/node/util.js +16 -0
  32. package/dist/es5/lib/node/util.js.map +1 -0
  33. package/dist/es5/lib/parser-utils/parse-json.js +17 -0
  34. package/dist/es5/lib/parser-utils/parse-json.js.map +1 -0
  35. package/dist/es5/lib/path-utils/file-aliases.js +39 -0
  36. package/dist/es5/lib/path-utils/file-aliases.js.map +1 -0
  37. package/dist/es5/lib/path-utils/path.js +35 -0
  38. package/dist/es5/lib/path-utils/path.js.map +1 -0
  39. package/dist/es5/lib/request-utils/request-scheduler.js +154 -0
  40. package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -0
  41. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +117 -0
  42. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
  43. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +76 -0
  44. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
  45. package/dist/es5/types.js +2 -0
  46. package/dist/{types.js.map → es5/types.js.map} +0 -0
  47. package/dist/es5/workers/json-worker.js +8 -0
  48. package/dist/es5/workers/json-worker.js.map +1 -0
  49. package/dist/esm/index.js +26 -0
  50. package/dist/esm/index.js.map +1 -0
  51. package/dist/esm/json-loader.js +21 -0
  52. package/dist/esm/json-loader.js.map +1 -0
  53. package/dist/esm/lib/binary-utils/array-buffer-utils.js +86 -0
  54. package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -0
  55. package/dist/esm/lib/binary-utils/binary-copy-utils.js +25 -0
  56. package/dist/esm/lib/binary-utils/binary-copy-utils.js.map +1 -0
  57. package/dist/esm/lib/binary-utils/buffer-utils.js +16 -0
  58. package/dist/esm/lib/binary-utils/buffer-utils.js.map +1 -0
  59. package/dist/esm/lib/binary-utils/encode-utils.js +31 -0
  60. package/dist/esm/lib/binary-utils/encode-utils.js.map +1 -0
  61. package/dist/esm/lib/binary-utils/get-first-characters.js +27 -0
  62. package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -0
  63. package/dist/esm/lib/binary-utils/memory-copy-utils.js +27 -0
  64. package/dist/esm/lib/binary-utils/memory-copy-utils.js.map +1 -0
  65. package/dist/esm/lib/env-utils/assert.js +6 -0
  66. package/dist/esm/lib/env-utils/assert.js.map +1 -0
  67. package/dist/esm/lib/env-utils/globals.js +16 -0
  68. package/dist/esm/lib/env-utils/globals.js.map +1 -0
  69. package/dist/esm/lib/filesystems/node-filesystem.js +60 -0
  70. package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -0
  71. package/dist/esm/lib/iterators/async-iteration.js +39 -0
  72. package/dist/esm/lib/iterators/async-iteration.js.map +1 -0
  73. package/dist/esm/lib/iterators/text-iterators.js +46 -0
  74. package/dist/esm/lib/iterators/text-iterators.js.map +1 -0
  75. package/dist/{lib/node/buffer-utils.node.js → esm/lib/node/buffer.js} +1 -1
  76. package/dist/esm/lib/node/buffer.js.map +1 -0
  77. package/dist/esm/lib/node/fs.js +27 -0
  78. package/dist/esm/lib/node/fs.js.map +1 -0
  79. package/dist/esm/lib/node/util.js +3 -0
  80. package/dist/esm/lib/node/util.js.map +1 -0
  81. package/dist/esm/lib/parser-utils/parse-json.js +9 -0
  82. package/dist/esm/lib/parser-utils/parse-json.js.map +1 -0
  83. package/dist/esm/lib/path-utils/file-aliases.js +26 -0
  84. package/dist/esm/lib/path-utils/file-aliases.js.map +1 -0
  85. package/dist/esm/lib/path-utils/path.js +24 -0
  86. package/dist/esm/lib/path-utils/path.js.map +1 -0
  87. package/dist/esm/lib/request-utils/request-scheduler.js +146 -0
  88. package/dist/esm/lib/request-utils/request-scheduler.js.map +1 -0
  89. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +102 -0
  90. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
  91. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +64 -0
  92. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
  93. package/dist/esm/types.js +2 -0
  94. package/dist/esm/types.js.map +1 -0
  95. package/dist/esm/workers/json-worker.js +4 -0
  96. package/dist/esm/workers/json-worker.js.map +1 -0
  97. package/dist/index.d.ts +27 -0
  98. package/dist/index.d.ts.map +1 -0
  99. package/dist/index.js +111 -22
  100. package/dist/json-loader.d.ts +22 -0
  101. package/dist/json-loader.d.ts.map +1 -0
  102. package/dist/json-loader.js +25 -18
  103. package/dist/lib/binary-utils/array-buffer-utils.d.ts +31 -0
  104. package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -0
  105. package/dist/lib/binary-utils/array-buffer-utils.js +108 -79
  106. package/dist/lib/binary-utils/binary-copy-utils.d.ts +24 -0
  107. package/dist/lib/binary-utils/binary-copy-utils.d.ts.map +1 -0
  108. package/dist/lib/binary-utils/binary-copy-utils.js +48 -22
  109. package/dist/lib/binary-utils/buffer-utils.d.ts +16 -0
  110. package/dist/lib/binary-utils/buffer-utils.d.ts.map +1 -0
  111. package/dist/lib/binary-utils/buffer-utils.js +47 -13
  112. package/dist/lib/binary-utils/encode-utils.d.ts +4 -0
  113. package/dist/lib/binary-utils/encode-utils.d.ts.map +1 -0
  114. package/dist/lib/binary-utils/encode-utils.js +30 -26
  115. package/dist/lib/binary-utils/get-first-characters.d.ts +3 -0
  116. package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -0
  117. package/dist/lib/binary-utils/get-first-characters.js +28 -25
  118. package/dist/lib/binary-utils/memory-copy-utils.d.ts +25 -0
  119. package/dist/lib/binary-utils/memory-copy-utils.d.ts.map +1 -0
  120. package/dist/lib/binary-utils/memory-copy-utils.js +58 -24
  121. package/dist/lib/env-utils/assert.d.ts +6 -0
  122. package/dist/lib/env-utils/assert.d.ts.map +1 -0
  123. package/dist/lib/env-utils/assert.js +12 -5
  124. package/dist/lib/env-utils/globals.d.ts +15 -0
  125. package/dist/lib/env-utils/globals.d.ts.map +1 -0
  126. package/dist/lib/env-utils/globals.js +23 -9
  127. package/dist/lib/filesystems/node-filesystem.d.ts +38 -0
  128. package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -0
  129. package/dist/lib/filesystems/node-filesystem.js +69 -0
  130. package/dist/lib/iterators/async-iteration.d.ts +20 -0
  131. package/dist/lib/iterators/async-iteration.d.ts.map +1 -0
  132. package/dist/lib/iterators/async-iteration.js +49 -35
  133. package/dist/lib/iterators/text-iterators.d.ts +19 -0
  134. package/dist/lib/iterators/text-iterators.d.ts.map +1 -0
  135. package/dist/lib/iterators/text-iterators.js +56 -41
  136. package/dist/lib/node/buffer.d.ts +10 -0
  137. package/dist/lib/node/buffer.d.ts.map +1 -0
  138. package/dist/lib/node/buffer.js +36 -0
  139. package/dist/lib/node/fs.d.ts +26 -0
  140. package/dist/lib/node/fs.d.ts.map +1 -0
  141. package/dist/lib/node/fs.js +40 -27
  142. package/dist/lib/node/util.d.ts +5 -0
  143. package/dist/lib/node/util.d.ts.map +1 -0
  144. package/dist/lib/node/util.js +25 -0
  145. package/dist/lib/parser-utils/parse-json.d.ts +5 -0
  146. package/dist/lib/parser-utils/parse-json.d.ts.map +1 -0
  147. package/dist/lib/parser-utils/parse-json.js +15 -8
  148. package/dist/lib/path-utils/file-aliases.d.ts +17 -0
  149. package/dist/lib/path-utils/file-aliases.d.ts.map +1 -0
  150. package/dist/lib/path-utils/file-aliases.js +40 -19
  151. package/dist/lib/path-utils/path.d.ts +16 -0
  152. package/dist/lib/path-utils/path.d.ts.map +1 -0
  153. package/dist/lib/path-utils/path.js +38 -18
  154. package/dist/lib/request-utils/request-scheduler.d.ts +62 -0
  155. package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -0
  156. package/dist/lib/request-utils/request-scheduler.js +127 -131
  157. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +7 -0
  158. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -0
  159. package/dist/lib/worker-loader-utils/create-loader-worker.js +91 -96
  160. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +15 -0
  161. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -0
  162. package/dist/lib/worker-loader-utils/parse-with-worker.js +69 -60
  163. package/dist/types.d.ts +207 -0
  164. package/dist/types.d.ts.map +1 -0
  165. package/dist/types.js +3 -2
  166. package/dist/workers/json-worker.d.ts +2 -0
  167. package/dist/workers/json-worker.d.ts.map +1 -0
  168. package/dist/workers/json-worker.js +5 -4
  169. package/package.json +15 -14
  170. package/src/index.ts +26 -8
  171. package/src/lib/binary-utils/buffer-utils.ts +1 -1
  172. package/src/lib/env-utils/globals.ts +1 -1
  173. package/src/lib/filesystems/node-filesystem.ts +79 -0
  174. package/src/lib/node/{buffer-utils.node.ts → buffer.ts} +0 -0
  175. package/src/lib/node/fs.ts +29 -13
  176. package/src/lib/node/util.ts +4 -0
  177. package/src/lib/path-utils/path.ts +9 -0
  178. package/src/lib/worker-loader-utils/parse-with-worker.ts +6 -5
  179. package/dist/index.js.map +0 -1
  180. package/dist/json-loader.js.map +0 -1
  181. package/dist/lib/binary-utils/array-buffer-utils.js.map +0 -1
  182. package/dist/lib/binary-utils/binary-copy-utils.js.map +0 -1
  183. package/dist/lib/binary-utils/buffer-utils.js.map +0 -1
  184. package/dist/lib/binary-utils/encode-utils.js.map +0 -1
  185. package/dist/lib/binary-utils/get-first-characters.js.map +0 -1
  186. package/dist/lib/binary-utils/memory-copy-utils.js.map +0 -1
  187. package/dist/lib/env-utils/assert.js.map +0 -1
  188. package/dist/lib/env-utils/globals.js.map +0 -1
  189. package/dist/lib/iterators/async-iteration.js.map +0 -1
  190. package/dist/lib/iterators/text-iterators.js.map +0 -1
  191. package/dist/lib/node/buffer-utils.node.js.map +0 -1
  192. package/dist/lib/node/fs.js.map +0 -1
  193. package/dist/lib/parser-utils/parse-json.js.map +0 -1
  194. package/dist/lib/path-utils/file-aliases.js.map +0 -1
  195. package/dist/lib/path-utils/path.js.map +0 -1
  196. package/dist/lib/request-utils/request-scheduler.js.map +0 -1
  197. package/dist/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
  198. package/dist/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
  199. package/dist/workers/json-worker.js.map +0 -1
@@ -0,0 +1,207 @@
1
+ /// <reference types="node" />
2
+ export declare type TypedIntArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Int32Array | Uint32Array;
3
+ export declare type TypedFloatArray = Uint16Array | Float32Array | Float64Array;
4
+ export declare type TypedArray = TypedIntArray | TypedFloatArray;
5
+ export declare type NumericArray = Array<number> | TypedIntArray | TypedFloatArray;
6
+ declare type FetchLike = (url: string, options?: RequestInit) => Promise<Response>;
7
+ export declare type LoaderOptions = {
8
+ /** fetch options or a custom fetch function */
9
+ fetch?: typeof fetch | FetchLike | RequestInit | null;
10
+ /** Do not throw on errors */
11
+ nothrow?: boolean;
12
+ /** loader selection, search first for supplied mimeType */
13
+ mimeType?: string;
14
+ /** loader selection, provide fallback mimeType is server does not provide */
15
+ fallbackMimeType?: string;
16
+ /** loader selection, avoid searching registered loaders */
17
+ ignoreRegisteredLoaders?: boolean;
18
+ /** Experimental: Supply a logger to the parser */
19
+ log?: any;
20
+ /** Size of each batch. `auto` matches batches to size of incoming chunks */
21
+ batchSize?: number | 'auto';
22
+ /** Minimal amount of time between batches */
23
+ batchDebounceMs?: number;
24
+ /** Stop loading after a given number of rows (compare SQL limit clause) */
25
+ limit?: 0;
26
+ /** Experimental: Stop loading after reaching */
27
+ _limitMB?: 0;
28
+ /** Generate metadata batches */
29
+ metadata?: boolean;
30
+ /** Transforms to run on incoming batches */
31
+ transforms?: TransformBatches[];
32
+ /** CDN load workers from */
33
+ CDN?: string;
34
+ /** Set to `false` to disable workers */
35
+ worker?: boolean;
36
+ /** Number of concurrent workers (per loader) on desktop browser */
37
+ maxConcurrency?: number;
38
+ /** Number of concurrent workers (per loader) on mobile browsers */
39
+ maxMobileConcurrency?: number;
40
+ /** Set to `false` to prevent reuse workers */
41
+ reuseWorkers?: boolean;
42
+ /** set to 'test' to run worker type */
43
+ _workerType?: string;
44
+ /** @deprecated `options.batchType` removed, Use `options.<loader>.type` instead */
45
+ batchType?: 'row' | 'columnar' | 'arrow';
46
+ /** @deprecated `options.throw removed`, Use `options.nothrow` instead */
47
+ throws?: boolean;
48
+ /** @deprecated `options.dataType` no longer used */
49
+ dataType?: any;
50
+ /** @deprecated `options.uri` no longer used */
51
+ uri?: any;
52
+ /** @deprecated `options.method` removed. Use `options.fetch.method` */
53
+ method?: any;
54
+ /** @deprecated `options.headers` removed. Use `options.fetch.headers` */
55
+ headers?: any;
56
+ /** @deprecated `options.body` removed. Use `options.fetch.body` */
57
+ body?: any;
58
+ /** @deprecated `options.mode` removed. Use `options.fetch.mode` */
59
+ mode?: any;
60
+ /** @deprecated `options.credentials` removed. Use `options.fetch.credentials` */
61
+ credentials?: any;
62
+ /** @deprecated `options.cache` removed. Use `options.fetch.cache` */
63
+ cache?: any;
64
+ /** @deprecated `options.redirect` removed. Use `options.fetch.redirect` */
65
+ redirect?: any;
66
+ /** @deprecated `options.referrer` removed. Use `options.fetch.referrer` */
67
+ referrer?: any;
68
+ /** @deprecated `options.referrerPolicy` removed. Use `options.fetch.referrerPolicy` */
69
+ referrerPolicy?: any;
70
+ /** @deprecated `options.integrity` removed. Use `options.fetch.integrity` */
71
+ integrity?: any;
72
+ /** @deprecated `options.keepalive` removed. Use `options.fetch.keepalive` */
73
+ keepalive?: any;
74
+ /** @deprecated `options.signal` removed. Use `options.fetch.signal` */
75
+ signal?: any;
76
+ [loaderId: string]: any;
77
+ };
78
+ declare type PreloadOptions = {
79
+ [key: string]: any;
80
+ };
81
+ /**
82
+ * A worker loader definition that can be used with `@loaders.gl/core` functions
83
+ */
84
+ export declare type Loader = {
85
+ name: string;
86
+ id: string;
87
+ module: string;
88
+ version: string;
89
+ worker?: string | boolean;
90
+ options: object;
91
+ deprecatedOptions?: object;
92
+ category?: string;
93
+ extensions: string[];
94
+ mimeTypes: string[];
95
+ binary?: boolean;
96
+ text?: boolean;
97
+ tests?: (((ArrayBuffer: any) => boolean) | ArrayBuffer | string)[];
98
+ supported?: boolean;
99
+ testText?: (string: any) => boolean;
100
+ };
101
+ /**
102
+ * A "bundled" loader definition that can be used with `@loaders.gl/core` functions
103
+ * If a worker loader is supported it will also be supported.
104
+ */
105
+ export declare type LoaderWithParser = Loader & {
106
+ testText?: (string: any) => boolean;
107
+ parse: Parse;
108
+ preload?: Preload;
109
+ parseSync?: ParseSync;
110
+ parseText?: ParseText;
111
+ parseTextSync?: ParseTextSync;
112
+ parseInBatches?: ParseInBatches;
113
+ parseFileInBatches?: ParseFileInBatches;
114
+ };
115
+ /** Options for writers */
116
+ export declare type WriterOptions = {};
117
+ /**
118
+ * A writer definition that can be used with `@loaders.gl/core` functions
119
+ */
120
+ export declare type Writer = {
121
+ name: string;
122
+ id: string;
123
+ module: string;
124
+ version: string;
125
+ options: object;
126
+ deprecatedOptions?: object;
127
+ binary?: boolean;
128
+ extensions?: string[];
129
+ mimeTypes?: string[];
130
+ text?: boolean;
131
+ encode?: Encode;
132
+ encodeSync?: EncodeSync;
133
+ encodeInBatches?: EncodeInBatches;
134
+ encodeURLtoURL?: EncodeURLtoURL;
135
+ encodeText?: EncodeText;
136
+ };
137
+ export declare type LoaderContext = {
138
+ loaders?: Loader[] | null;
139
+ url?: string;
140
+ fetch: typeof fetch;
141
+ parse: (arrayBuffer: ArrayBuffer, loaders?: any, options?: LoaderOptions, context?: LoaderContext) => Promise<any>;
142
+ parseSync?: (arrayBuffer: ArrayBuffer, loaders?: any, options?: LoaderOptions, context?: LoaderContext) => any;
143
+ parseInBatches?: (iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, loaders?: any, options?: LoaderOptions, context?: LoaderContext) => AsyncIterable<any> | Promise<AsyncIterable<any>>;
144
+ };
145
+ declare type Parse = (arrayBuffer: ArrayBuffer, options?: LoaderOptions, context?: LoaderContext) => Promise<any>;
146
+ declare type ParseSync = (arrayBuffer: ArrayBuffer, options?: LoaderOptions, context?: LoaderContext) => any;
147
+ declare type ParseText = (text: string, options?: LoaderOptions) => Promise<any>;
148
+ declare type ParseTextSync = (text: string, options?: LoaderOptions) => any;
149
+ declare type ParseInBatches = (iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options?: LoaderOptions, context?: LoaderContext) => AsyncIterable<any>;
150
+ declare type ParseFileInBatches = (file: Blob, options?: LoaderOptions, context?: LoaderContext) => AsyncIterable<any>;
151
+ declare type Encode = (data: any, options?: WriterOptions) => Promise<ArrayBuffer>;
152
+ declare type EncodeSync = (data: any, options?: WriterOptions) => ArrayBuffer;
153
+ declare type EncodeText = Function;
154
+ declare type EncodeInBatches = Function;
155
+ declare type EncodeURLtoURL = (inputUrl: string, outputUrl: string, options?: WriterOptions) => Promise<string>;
156
+ declare type Preload = (url: string, options?: PreloadOptions) => any;
157
+ export declare type TransformBatches = (asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>) => AsyncIterable<ArrayBuffer>;
158
+ /** Types that can be synchronously parsed */
159
+ export declare type SyncDataType = string | ArrayBuffer;
160
+ /** Types that can be parsed async */
161
+ export declare type DataType = string | ArrayBuffer | File | Blob | Response | ReadableStream | Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer>;
162
+ /** Types that can be parsed in batches */
163
+ export declare type BatchableDataType = DataType | Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer> | Promise<AsyncIterable<ArrayBuffer>>;
164
+ /**
165
+ * A FileSystem interface can encapsulate a FileList, a ZipFile, a GoogleDrive etc.
166
+ */
167
+ export interface IFileSystem {
168
+ /**
169
+ * Return a list of file names
170
+ * @param dirname directory name. file system root directory if omitted
171
+ */
172
+ readdir(dirname?: string, options?: {
173
+ recursive?: boolean;
174
+ }): Promise<string[]>;
175
+ /**
176
+ * Gets information from a local file from the filesystem
177
+ * @param filename file name to stat
178
+ * @param options currently unused
179
+ * @throws if filename is not in local filesystem
180
+ */
181
+ stat(filename: string, options?: object): Promise<{
182
+ size: number;
183
+ }>;
184
+ /**
185
+ * Fetches a local file from the filesystem (or a URL)
186
+ * @param filename
187
+ * @param options
188
+ */
189
+ fetch(filename: string, options?: object): Promise<Response>;
190
+ }
191
+ declare type ReadOptions = {
192
+ buffer?: ArrayBuffer;
193
+ offset?: number;
194
+ length?: number;
195
+ position?: number;
196
+ };
197
+ export interface IRandomAccessReadFileSystem extends IFileSystem {
198
+ open(path: string, flags: any, mode?: any): Promise<any>;
199
+ close(fd: any): Promise<void>;
200
+ fstat(fd: any): Promise<object>;
201
+ read(fd: any, options?: ReadOptions): Promise<{
202
+ bytesRead: number;
203
+ buffer: Buffer;
204
+ }>;
205
+ }
206
+ export {};
207
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAEA,oBAAY,aAAa,GACrB,SAAS,GACT,UAAU,GACV,iBAAiB,GACjB,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,CAAC;AAEhB,oBAAY,eAAe,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,CAAC;AAExE,oBAAY,UAAU,GAAG,aAAa,GAAG,eAAe,CAAC;AAEzD,oBAAY,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,aAAa,GAAG,eAAe,CAAC;AAE3E,aAAK,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAG3E,oBAAY,aAAa,GAAG;IAC1B,+CAA+C;IAC/C,KAAK,CAAC,EAAE,OAAO,KAAK,GAAG,SAAS,GAAG,WAAW,GAAG,IAAI,CAAC;IACtD,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,gB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,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE9E;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;IAElE;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC9D;AAED,aAAK,WAAW,GAAG;IAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AAC/F,MAAM,WAAW,2BAA4B,SAAQ,WAAW;IAC9D,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,KAAA,EAAE,IAAI,CAAC,KAAA,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/C,KAAK,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;CACpF"}
package/dist/types.js CHANGED
@@ -1,2 +1,3 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ "use strict";
2
+ // Typed arrays
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=json-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-worker.d.ts","sourceRoot":"","sources":["../../src/workers/json-worker.ts"],"names":[],"mappings":""}
@@ -1,4 +1,5 @@
1
- import { createLoaderWorker } from '../lib/worker-loader-utils/create-loader-worker';
2
- import { JSONLoader } from '../json-loader';
3
- createLoaderWorker(JSONLoader);
4
- //# sourceMappingURL=json-worker.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const create_loader_worker_1 = require("../lib/worker-loader-utils/create-loader-worker");
4
+ const json_loader_1 = require("../json-loader");
5
+ (0, create_loader_worker_1.createLoaderWorker)(json_loader_1.JSONLoader);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/loader-utils",
3
- "version": "3.1.0-alpha.2",
3
+ "version": "3.1.0-beta.1",
4
4
  "description": "Framework-independent loaders for 3D graphics formats",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -17,9 +17,9 @@
17
17
  "mesh",
18
18
  "point cloud"
19
19
  ],
20
- "types": "src/index.ts",
21
- "main": "dist/index.js",
22
- "module": "dist/index.js",
20
+ "types": "dist/index.d.ts",
21
+ "main": "dist/es5/index.js",
22
+ "module": "dist/esm/index.js",
23
23
  "sideEffects": false,
24
24
  "files": [
25
25
  "src",
@@ -27,25 +27,26 @@
27
27
  "README.md"
28
28
  ],
29
29
  "browser": {
30
- "./src/lib/node/buffer-utils.node.ts": false,
31
- "./src/lib/node/buffer-utils.node.js": false,
32
- "./dist/es5/lib/node/buffer-utils.node.js": false,
33
- "./dist/esm/lib/node/buffer-utils.node.js": false,
30
+ "./src/lib/node/buffer.ts": false,
31
+ "./src/lib/node/buffer.js": false,
32
+ "./dist/es5/lib/node/buffer.js": false,
33
+ "./dist/esm/lib/node/buffer.js": false,
34
34
  "./src/lib/node/fs.ts": false,
35
35
  "./src/lib/node/fs.js": false,
36
36
  "./dist/es5/lib/node/fs.js": false,
37
37
  "./dist/esm/lib/node/fs.js": false,
38
+ "./src/lib/node/util.ts": false,
39
+ "./src/lib/node/util.js": false,
40
+ "./dist/es5/lib/node/util.js": false,
41
+ "./dist/esm/lib/node/util.js": false,
38
42
  "fs": false,
39
43
  "util": false
40
44
  },
41
- "scripts": {
42
- "pre-build-disabled": "npm run build-bundle",
43
- "build-bundle": "webpack --config ../../scripts/webpack/bundle.js"
44
- },
45
+ "scripts": {},
45
46
  "dependencies": {
46
47
  "@babel/runtime": "^7.3.1",
47
- "@loaders.gl/worker-utils": "3.1.0-alpha.2",
48
+ "@loaders.gl/worker-utils": "3.1.0-beta.1",
48
49
  "@probe.gl/stats": "^3.4.0"
49
50
  },
50
- "gitHead": "ca83b8f05a6874db93051d446266d9ea360affb2"
51
+ "gitHead": "980cdefb4e8ec9ef9c951d20c78cf77777707f49"
51
52
  }
package/src/index.ts CHANGED
@@ -64,17 +64,35 @@ export {forEach, concatenateArrayBuffersAsync} from './lib/iterators/async-itera
64
64
  // REQUEST UTILS
65
65
  export {default as RequestScheduler} from './lib/request-utils/request-scheduler';
66
66
 
67
- // NODE `path`` REPLACEMENT
68
- import * as path from './lib/path-utils/path';
69
- export {path};
67
+ // PATH HELPERS
70
68
  export {setPathPrefix, getPathPrefix, resolvePath} from './lib/path-utils/file-aliases';
71
69
  export {addAliases as _addAliases} from './lib/path-utils/file-aliases';
72
70
 
73
- // NODE `fs` WRAPPERS
74
- import * as fs from './lib/node/fs';
75
- export {fs};
71
+ // MICRO LOADERS
72
+ export {JSONLoader} from './json-loader';
73
+
74
+ // NODE support
75
+
76
+ // Node.js emulation (can be used in browser)
77
+
78
+ // `path` replacement (avoids bundling big path polyfill)
79
+ import * as path from './lib/path-utils/path';
80
+ export {path};
76
81
 
77
- // NODE `buffer` WRAPPERS
82
+ // Avoid direct use of `Buffer` which pulls in 50KB polyfill
78
83
  export {isBuffer, toBuffer, bufferToArrayBuffer} from './lib/binary-utils/buffer-utils';
79
84
 
80
- export {JSONLoader} from './json-loader';
85
+ // Note.js wrappers (can be safely imported, but not used in browser)
86
+
87
+ // Use instead of importing 'util'
88
+ import * as util from './lib/node/util';
89
+ export {util};
90
+ // TODO - remove
91
+ export {promisify} from './lib/node/util';
92
+
93
+ // Use instead of importing 'fs';`
94
+ import * as fs from './lib/node/fs';
95
+ export {fs};
96
+
97
+ // EXPERIMENTAL
98
+ export {default as _NodeFileSystem} from './lib/filesystems/node-filesystem';
@@ -1,4 +1,4 @@
1
- import * as node from '../node/buffer-utils.node';
1
+ import * as node from '../node/buffer';
2
2
 
3
3
  /**
4
4
  * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
@@ -20,7 +20,7 @@ export {self_ as self, window_ as window, global_ as global, document_ as docume
20
20
  /** true if running in a browser */
21
21
  export const isBrowser: boolean =
22
22
  // @ts-ignore process does not exist on browser
23
- typeof process !== 'object' || String(process) !== '[object process]' || process.browser;
23
+ Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
24
24
 
25
25
  /** true if running in a worker thread */
26
26
  export const isWorker: boolean = typeof importScripts === 'function';
@@ -0,0 +1,79 @@
1
+ import * as fs from '../node/fs';
2
+ import {IFileSystem, IRandomAccessReadFileSystem} from '../../types';
3
+ // import {fetchFile} from "../fetch/fetch-file"
4
+ // import {selectLoader} from "../api/select-loader";
5
+
6
+ type Stat = {
7
+ size: number;
8
+ isDirectory: () => boolean;
9
+ info?: fs.Stats;
10
+ };
11
+
12
+ type ReadOptions = {
13
+ buffer?: Buffer;
14
+ offset?: number;
15
+ length?: number;
16
+ position?: number;
17
+ };
18
+
19
+ /**
20
+ * FileSystem pass-through for Node.js
21
+ * Compatible with BrowserFileSystem.
22
+ * @param options
23
+ */
24
+ export default class NodeFileSystem implements IFileSystem, IRandomAccessReadFileSystem {
25
+ // implements IFileSystem
26
+ constructor(options: {[key: string]: any}) {
27
+ this.fetch = options._fetch;
28
+ }
29
+
30
+ async readdir(dirname = '.', options?: {}): Promise<any[]> {
31
+ return await fs.readdir(dirname, options);
32
+ }
33
+
34
+ async stat(path: string, options?: {}): Promise<Stat> {
35
+ const info = await fs.stat(path, options);
36
+ return {size: Number(info.size), isDirectory: () => false, info};
37
+ }
38
+
39
+ async fetch(path: string, options: {[key: string]: any}) {
40
+ // Falls back to handle https:/http:/data: etc fetches
41
+ // eslint-disable-next-line
42
+ const fallbackFetch = options.fetch || this.fetch;
43
+ return fallbackFetch(path, options);
44
+ }
45
+
46
+ // implements IRandomAccessFileSystem
47
+ async open(path: string, flags: string | number, mode?: any): Promise<number> {
48
+ return await fs.open(path, flags);
49
+ }
50
+
51
+ async close(fd: number): Promise<void> {
52
+ return await fs.close(fd);
53
+ }
54
+
55
+ async fstat(fd: number): Promise<Stat> {
56
+ const info = await fs.fstat(fd);
57
+ return info;
58
+ }
59
+
60
+ async read(
61
+ fd: number,
62
+ // @ts-ignore Possibly null
63
+ {buffer = null, offset = 0, length = buffer.byteLength, position = null}: ReadOptions
64
+ ): Promise<{bytesRead: number; buffer: Buffer}> {
65
+ let totalBytesRead = 0;
66
+ // Read in loop until we get required number of bytes
67
+ while (totalBytesRead < length) {
68
+ const {bytesRead} = await fs.read(
69
+ fd,
70
+ buffer,
71
+ offset + totalBytesRead,
72
+ length - totalBytesRead,
73
+ position + totalBytesRead
74
+ );
75
+ totalBytesRead += bytesRead;
76
+ }
77
+ return {bytesRead: totalBytesRead, buffer};
78
+ }
79
+ }
File without changes
@@ -1,22 +1,38 @@
1
1
  // fs wrapper (promisified fs + avoids bundling fs in browsers)
2
2
  import fs from 'fs';
3
- import {toArrayBuffer} from './buffer-utils.node';
4
- import {promisify} from 'util';
3
+ import {toArrayBuffer} from './buffer';
4
+ import {promisify} from './util';
5
5
 
6
- const error = (fsFunction) => () => {
7
- throw new Error(`${fsFunction} not available in browser`);
8
- };
6
+ export type {Stats} from 'fs';
9
7
 
10
- export const isSupported = Boolean(fs);
8
+ // paths
9
+
10
+ /** Wrapper for Node.js fs method */
11
+ export const readdir = promisify(fs.readdir);
12
+ /** Wrapper for Node.js fs method */
13
+ export const stat = promisify(fs.stat);
14
+
15
+ /** Wrapper for Node.js fs method */
16
+ export const readFile = promisify(fs.readFile);
17
+ /** Wrapper for Node.js fs method */
18
+ export const readFileSync = fs.readFileSync;
19
+ /** Wrapper for Node.js fs method */
20
+ export const writeFile = promisify(fs.writeFile);
21
+ /** Wrapper for Node.js fs method */
22
+ export const writeFileSync = fs.writeFileSync;
11
23
 
12
- export const open = fs?.open ? promisify(fs.open) : error('fs.open');
13
- export const close = fs?.close ? promisify(fs.close) : error('fs.close');
14
- export const read = fs?.read ? promisify(fs.read) : error('fs.read');
24
+ // file descriptors
15
25
 
16
- export const readFile = fs?.readFile ? promisify(fs.readFile) : error('fs.readFile');
17
- export const readFileSync = fs?.readFileSync ? fs.readFileSync : error('fs.readFileSync');
18
- export const writeFile = fs?.writeFile ? promisify(fs.writeFile) : error('fs.writeFile');
19
- export const writeFileSync = fs?.writeFileSync ? fs.writeFileSync : error('fs.writeFileSync');
26
+ /** Wrapper for Node.js fs method */
27
+ export const open = promisify(fs.open);
28
+ /** Wrapper for Node.js fs method */
29
+ export const close = promisify(fs.close);
30
+ /** Wrapper for Node.js fs method */
31
+ export const read = promisify(fs.read);
32
+ /** Wrapper for Node.js fs method */
33
+ export const fstat = promisify(fs.fstat);
34
+
35
+ export const isSupported = Boolean(fs);
20
36
 
21
37
  export async function _readToArrayBuffer(fd: number, start: number, length: number) {
22
38
  const buffer = Buffer.alloc(length);
@@ -0,0 +1,4 @@
1
+ import * as util from 'util';
2
+
3
+ /** Wrapper for Node.js promisify */
4
+ export const promisify = util.promisify;
@@ -1,5 +1,14 @@
1
1
  // Beginning of a minimal implementation of the Node.js path API, that doesn't pull in big polyfills.
2
2
 
3
+ /**
4
+ * Replacement for Node.js path.filename
5
+ * @param url
6
+ */
7
+ export function filename(url: string): string {
8
+ const slashIndex = url && url.lastIndexOf('/');
9
+ return slashIndex >= 0 ? url.substr((slashIndex as number) + 1) : '';
10
+ }
11
+
3
12
  /**
4
13
  * Replacement for Node.js path.dirname
5
14
  * @param url
@@ -21,7 +21,7 @@ export function canParseWithWorker(loader: Loader, options?: LoaderOptions) {
21
21
  */
22
22
  export async function parseWithWorker(
23
23
  loader: Loader,
24
- data,
24
+ data: any,
25
25
  options?: LoaderOptions,
26
26
  context?: LoaderContext,
27
27
  parseOnMainThread?: (arrayBuffer: ArrayBuffer, options: {[key: string]: any}) => Promise<void>
@@ -38,8 +38,8 @@ export async function parseWithWorker(
38
38
 
39
39
  const job = await workerPool.startJob(
40
40
  'process-on-worker',
41
- // eslint-disable-next-line
42
- onMessage.bind(null, parseOnMainThread)
41
+ // @ts-expect-error
42
+ onMessage.bind(null, parseOnMainThread) // eslint-disable-line @typescript-eslint/no-misused-promises
43
43
  );
44
44
 
45
45
  job.postMessage('process', {
@@ -49,6 +49,7 @@ export async function parseWithWorker(
49
49
  });
50
50
 
51
51
  const result = await job.result;
52
+ // TODO - what is going on here?
52
53
  return await result.result;
53
54
  }
54
55
 
@@ -59,7 +60,7 @@ export async function parseWithWorker(
59
60
  * @param payload
60
61
  */
61
62
  async function onMessage(
62
- parseOnMainThread,
63
+ parseOnMainThread: (arrayBuffer: ArrayBuffer, options?: {[key: string]: any}) => Promise<void>,
63
64
  job: WorkerJob,
64
65
  type: WorkerMessageType,
65
66
  payload: WorkerMessagePayload
@@ -70,7 +71,7 @@ async function onMessage(
70
71
  break;
71
72
 
72
73
  case 'error':
73
- job.error(payload.error);
74
+ job.error(new Error(payload.error));
74
75
  break;
75
76
 
76
77
  case 'process':
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["assert","isBrowser","isWorker","nodeVersion","self","window","global","document","createLoaderWorker","parseWithWorker","canParseWithWorker","parseJSON","toArrayBuffer","sliceArrayBuffer","concatenateArrayBuffers","concatenateTypedArrays","compareArrayBuffers","padToNBytes","copyToArray","copyArrayBuffer","copyPaddedArrayBufferToDataView","copyPaddedStringToDataView","padStringToByteAlignment","copyStringToDataView","copyBinaryToDataView","getFirstCharacters","getMagicString","makeTextEncoderIterator","makeTextDecoderIterator","makeLineIterator","makeNumberedLineIterator","forEach","concatenateArrayBuffersAsync","default","RequestScheduler","path","setPathPrefix","getPathPrefix","resolvePath","addAliases","_addAliases","fs","isBuffer","toBuffer","bufferToArrayBuffer","JSONLoader"],"mappings":"AAgBA,SAAQA,MAAR,QAAqB,wBAArB;AACA,SACEC,SADF,EAEEC,QAFF,EAGEC,WAHF,EAIEC,IAJF,EAKEC,MALF,EAMEC,MANF,EAOEC,QAPF,QAQO,yBARP;AAWA,SAAQC,kBAAR,QAAiC,gDAAjC;AACA,SAAQC,eAAR,EAAyBC,kBAAzB,QAAkD,6CAAlD;AAGA,SAAQC,SAAR,QAAwB,+BAAxB;AAGA,SACEC,aADF,EAEEC,gBAFF,EAGEC,uBAHF,EAIEC,sBAJF,EAKEC,mBALF,QAMO,uCANP;AAOA,SAAQC,WAAR,EAAqBC,WAArB,EAAkCC,eAAlC,QAAwD,sCAAxD;AACA,SACEC,+BADF,EAEEC,0BAFF,QAGO,sCAHP;AAIA,SACEC,wBADF,EAEEC,oBAFF,EAGEC,oBAHF,QAIO,iCAJP;AAKA,SAAQC,kBAAR,EAA4BC,cAA5B,QAAiD,yCAAjD;AAGA,SACEC,uBADF,EAEEC,uBAFF,EAGEC,gBAHF,EAIEC,wBAJF,QAKO,gCALP;AAMA,SAAQC,OAAR,EAAiBC,4BAAjB,QAAoD,iCAApD;AAGA,SAAQC,OAAO,IAAIC,gBAAnB,QAA0C,uCAA1C;AAGA,OAAO,KAAKC,IAAZ,MAAsB,uBAAtB;AACA,SAAQA,IAAR;AACA,SAAQC,aAAR,EAAuBC,aAAvB,EAAsCC,WAAtC,QAAwD,+BAAxD;AACA,SAAQC,UAAU,IAAIC,WAAtB,QAAwC,+BAAxC;AAGA,OAAO,KAAKC,EAAZ,MAAoB,eAApB;AACA,SAAQA,EAAR;AAGA,SAAQC,QAAR,EAAkBC,QAAlB,EAA4BC,mBAA5B,QAAsD,iCAAtD;AAEA,SAAQC,UAAR,QAAyB,eAAzB","sourcesContent":["// TYPES\nexport type {\n Loader,\n LoaderWithParser,\n LoaderContext,\n LoaderOptions,\n Writer,\n WriterOptions,\n DataType,\n SyncDataType,\n BatchableDataType,\n IFileSystem,\n IRandomAccessReadFileSystem\n} from './types';\n\n// GENERAL UTILS\nexport {assert} from './lib/env-utils/assert';\nexport {\n isBrowser,\n isWorker,\n nodeVersion,\n self,\n window,\n global,\n document\n} from './lib/env-utils/globals';\n\n// LOADERS.GL-SPECIFIC WORKER UTILS\nexport {createLoaderWorker} from './lib/worker-loader-utils/create-loader-worker';\nexport {parseWithWorker, canParseWithWorker} from './lib/worker-loader-utils/parse-with-worker';\n\n// PARSER UTILS\nexport {parseJSON} from './lib/parser-utils/parse-json';\n\n// MEMORY COPY UTILS\nexport {\n toArrayBuffer,\n sliceArrayBuffer,\n concatenateArrayBuffers,\n concatenateTypedArrays,\n compareArrayBuffers\n} from './lib/binary-utils/array-buffer-utils';\nexport {padToNBytes, copyToArray, copyArrayBuffer} from './lib/binary-utils/memory-copy-utils';\nexport {\n copyPaddedArrayBufferToDataView,\n copyPaddedStringToDataView\n} from './lib/binary-utils/binary-copy-utils';\nexport {\n padStringToByteAlignment,\n copyStringToDataView,\n copyBinaryToDataView\n} from './lib/binary-utils/encode-utils';\nexport {getFirstCharacters, getMagicString} from './lib/binary-utils/get-first-characters';\n\n// ITERATOR UTILS\nexport {\n makeTextEncoderIterator,\n makeTextDecoderIterator,\n makeLineIterator,\n makeNumberedLineIterator\n} from './lib/iterators/text-iterators';\nexport {forEach, concatenateArrayBuffersAsync} from './lib/iterators/async-iteration';\n\n// REQUEST UTILS\nexport {default as RequestScheduler} from './lib/request-utils/request-scheduler';\n\n// NODE `path`` REPLACEMENT\nimport * as path from './lib/path-utils/path';\nexport {path};\nexport {setPathPrefix, getPathPrefix, resolvePath} from './lib/path-utils/file-aliases';\nexport {addAliases as _addAliases} from './lib/path-utils/file-aliases';\n\n// NODE `fs` WRAPPERS\nimport * as fs from './lib/node/fs';\nexport {fs};\n\n// NODE `buffer` WRAPPERS\nexport {isBuffer, toBuffer, bufferToArrayBuffer} from './lib/binary-utils/buffer-utils';\n\nexport {JSONLoader} from './json-loader';\n"],"file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/json-loader.ts"],"names":["VERSION","JSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parseTextSync","parse","arrayBuffer","TextDecoder","decode","options","JSON","_typecheckJSONLoader"],"mappings":"AAIA,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAMA,OAAO,MAAMC,UAAU,GAAG;AACxBC,EAAAA,IAAI,EAAE,MADkB;AAExBC,EAAAA,EAAE,EAAE,MAFoB;AAGxBC,EAAAA,MAAM,EAAE,MAHgB;AAIxBC,EAAAA,OAAO,EAAEL,OAJe;AAKxBM,EAAAA,UAAU,EAAE,CAAC,MAAD,EAAS,SAAT,CALY;AAMxBC,EAAAA,SAAS,EAAE,CAAC,kBAAD,CANa;AAOxBC,EAAAA,QAAQ,EAAE,MAPc;AAQxBC,EAAAA,IAAI,EAAE,IARkB;AASxBC,EAAAA,aATwB;AAUxBC,EAAAA,KAAK,EAAE,MAAOC,WAAP,IAAuBF,aAAa,CAAC,IAAIG,WAAJ,GAAkBC,MAAlB,CAAyBF,WAAzB,CAAD,CAVnB;AAWxBG,EAAAA,OAAO,EAAE;AAXe,CAAnB;;AAeP,SAASL,aAAT,CAAuBD,IAAvB,EAA6B;AAC3B,SAAOO,IAAI,CAACL,KAAL,CAAWF,IAAX,CAAP;AACD;;AAED,OAAO,MAAMQ,oBAAsC,GAAGhB,UAA/C","sourcesContent":["import type {LoaderWithParser} from './types';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * A JSON Micro loader (minimal bundle size)\n * Alternative to `@loaders.gl/json`\n */\nexport const JSONLoader = {\n name: 'JSON',\n id: 'json',\n module: 'json',\n version: VERSION,\n extensions: ['json', 'geojson'],\n mimeTypes: ['application/json'],\n category: 'json',\n text: true,\n parseTextSync,\n parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),\n options: {}\n};\n\n// TODO - deprecated\nfunction parseTextSync(text) {\n return JSON.parse(text);\n}\n\nexport const _typecheckJSONLoader: LoaderWithParser = JSONLoader;\n"],"file":"json-loader.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/binary-utils/array-buffer-utils.ts"],"names":["isBuffer","bufferToArrayBuffer","toArrayBuffer","data","ArrayBuffer","isView","byteOffset","byteLength","buffer","slice","text","uint8Array","TextEncoder","encode","_toArrayBuffer","Error","compareArrayBuffers","arrayBuffer1","arrayBuffer2","array1","Uint8Array","array2","i","length","concatenateArrayBuffers","sources","sourceArrays","map","source2","reduce","typedArray","result","offset","sourceArray","set","concatenateTypedArrays","typedArrays","arrays","TypedArrayConstructor","constructor","sumLength","acc","value","array","sliceArrayBuffer","arrayBuffer","subArray","undefined","subarray","arrayCopy"],"mappings":"AACA,SAAQA,QAAR,EAAkBC,mBAAlB,QAA4C,gBAA5C;AAKA,OAAO,SAASC,aAAT,CAAuBC,IAAvB,EAA+C;AAEpD,MAAIH,QAAQ,CAACG,IAAD,CAAZ,EAAoB;AAClB,WAAOF,mBAAmB,CAACE,IAAD,CAA1B;AACD;;AAED,MAAIA,IAAI,YAAYC,WAApB,EAAiC;AAC/B,WAAOD,IAAP;AACD;;AAGD,MAAIC,WAAW,CAACC,MAAZ,CAAmBF,IAAnB,CAAJ,EAA8B;AAC5B,QAAIA,IAAI,CAACG,UAAL,KAAoB,CAApB,IAAyBH,IAAI,CAACI,UAAL,KAAoBJ,IAAI,CAACK,MAAL,CAAYD,UAA7D,EAAyE;AACvE,aAAOJ,IAAI,CAACK,MAAZ;AACD;;AACD,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,MAAP;AACD;AAQD,OAAO,SAASa,gBAAT,CACLC,WADK,EAELvC,UAFK,EAGLC,UAHK,EAIQ;AACb,QAAMuC,QAAQ,GACZvC,UAAU,KAAKwC,SAAf,GACI,IAAI3B,UAAJ,CAAeyB,WAAf,EAA4BG,QAA5B,CAAqC1C,UAArC,EAAiDA,UAAU,GAAGC,UAA9D,CADJ,GAEI,IAAIa,UAAJ,CAAeyB,WAAf,EAA4BG,QAA5B,CAAqC1C,UAArC,CAHN;AAIA,QAAM2C,SAAS,GAAG,IAAI7B,UAAJ,CAAe0B,QAAf,CAAlB;AACA,SAAOG,SAAS,CAACzC,MAAjB;AACD","sourcesContent":["import {TypedArray} from '../../types';\nimport {isBuffer, bufferToArrayBuffer} from './buffer-utils';\n\n/**\n * Convert an object to an array buffer\n */\nexport function toArrayBuffer(data: any): ArrayBuffer {\n // Note: Should be called first, Buffers can trigger other detections below\n if (isBuffer(data)) {\n return bufferToArrayBuffer(data);\n }\n\n if (data instanceof ArrayBuffer) {\n return data;\n }\n\n // Careful - Node Buffers look like Uint8Arrays (keep after isBuffer)\n if (ArrayBuffer.isView(data)) {\n if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {\n return data.buffer;\n }\n return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);\n }\n\n if (typeof data === 'string') {\n const text = data;\n const uint8Array = new TextEncoder().encode(text);\n return uint8Array.buffer;\n }\n\n // HACK to support Blob polyfill\n if (data && typeof data === 'object' && data._toArrayBuffer) {\n return data._toArrayBuffer();\n }\n\n throw new Error('toArrayBuffer');\n}\n\n/**\n * compare two binary arrays for equality\n * @param {ArrayBuffer} a\n * @param {ArrayBuffer} b\n * @param {number} byteLength\n */\nexport function compareArrayBuffers(\n arrayBuffer1: ArrayBuffer,\n arrayBuffer2: ArrayBuffer,\n byteLength?: number\n): boolean {\n byteLength = byteLength || arrayBuffer1.byteLength;\n if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {\n return false;\n }\n const array1 = new Uint8Array(arrayBuffer1);\n const array2 = new Uint8Array(arrayBuffer2);\n for (let i = 0; i < array1.length; ++i) {\n if (array1[i] !== array2[i]) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Concatenate a sequence of ArrayBuffers\n * @return A concatenated ArrayBuffer\n */\nexport function concatenateArrayBuffers(...sources: (ArrayBuffer | Uint8Array)[]): ArrayBuffer {\n // Make sure all inputs are wrapped in typed arrays\n const sourceArrays = sources.map((source2) =>\n source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2\n );\n\n // Get length of all inputs\n const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);\n\n // Allocate array with space for all inputs\n const result = new Uint8Array(byteLength);\n\n // Copy the subarrays\n let offset = 0;\n for (const sourceArray of sourceArrays) {\n result.set(sourceArray, offset);\n offset += sourceArray.byteLength;\n }\n\n // We work with ArrayBuffers, discard the typed array wrapper\n return result.buffer;\n}\n\n/**\n * Concatenate arbitrary count of typed arrays\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays\n * @param {...*} arrays - list of arrays. All arrays should be the same type\n * @return A concatenated TypedArray\n */\nexport function concatenateTypedArrays<T>(...typedArrays: T[]): T {\n // @ts-ignore\n const arrays = typedArrays as TypedArray[];\n // @ts-ignore\n const TypedArrayConstructor = (arrays && arrays.length > 1 && arrays[0].constructor) || null;\n if (!TypedArrayConstructor) {\n throw new Error(\n '\"concatenateTypedArrays\" - incorrect quantity of arguments or arguments have incompatible data types'\n );\n }\n\n const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);\n // @ts-ignore typescript does not like dynamic constructors\n const result = new TypedArrayConstructor(sumLength);\n let offset = 0;\n for (const array of arrays) {\n result.set(array, offset);\n offset += array.length;\n }\n return result;\n}\n\n/**\n * Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0\n * @param arrayBuffer\n * @param byteOffset\n * @param byteLength\n */\nexport function sliceArrayBuffer(\n arrayBuffer: ArrayBuffer,\n byteOffset: number,\n byteLength?: number\n): ArrayBuffer {\n const subArray =\n byteLength !== undefined\n ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength)\n : new Uint8Array(arrayBuffer).subarray(byteOffset);\n const arrayCopy = new Uint8Array(subArray);\n return arrayCopy.buffer;\n}\n"],"file":"array-buffer-utils.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/binary-utils/binary-copy-utils.ts"],"names":["padToNBytes","copyPaddedArrayBufferToDataView","dataView","byteOffset","sourceBuffer","padding","paddedLength","byteLength","padLength","targetArray","Uint8Array","buffer","sourceArray","set","i","setUint8","copyPaddedStringToDataView","string","textEncoder","TextEncoder","stringBuffer","encode"],"mappings":"AACA,SAAQA,WAAR,QAA0B,qBAA1B;AAYA,OAAO,SAASC,+BAAT,CACLC,QADK,EAELC,UAFK,EAGLC,YAHK,EAILC,OAJK,EAKL;AACA,QAAMC,YAAY,GAAGN,WAAW,CAACI,YAAY,CAACG,UAAd,EAA0BF,OAA1B,CAAhC;AACA,QAAMG,SAAS,GAAGF,YAAY,GAAGF,YAAY,CAACG,UAA9C;;AAEA,MAAIL,QAAJ,EAAc;AAEZ,UAAMO,WAAW,GAAG,IAAIC,UAAJ,CAClBR,QAAQ,CAACS,MADS,EAElBT,QAAQ,CAACC,UAAT,GAAsBA,UAFJ,EAGlBC,YAAY,CAACG,UAHK,CAApB;AAKA,UAAMK,WAAW,GAAG,IAAIF,UAAJ,CAAeN,YAAf,CAApB;AACAK,IAAAA,WAAW,CAACI,GAAZ,CAAgBD,WAAhB;;AAGA,SAAK,IAAIE,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGN,SAApB,EAA+B,EAAEM,CAAjC,EAAoC;AAElCZ,MAAAA,QAAQ,CAACa,QAAT,CAAkBZ,UAAU,GAAGC,YAAY,CAACG,UAA1B,GAAuCO,CAAzD,EAA4D,IAA5D;AACD;AACF;;AACDX,EAAAA,UAAU,IAAIG,YAAd;AACA,SAAOH,UAAP;AACD;AAYD,OAAO,SAASa,0BAAT,CACLd,QADK,EAELC,UAFK,EAGLc,MAHK,EAILZ,OAJK,EAKG;AACR,QAAMa,WAAW,GAAG,IAAIC,WAAJ,EAApB;AAGA,QAAMC,YAAY,GAAGF,WAAW,CAACG,MAAZ,CAAmBJ,MAAnB,CAArB;AAEAd,EAAAA,UAAU,GAAGF,+BAA+B,CAACC,QAAD,EAAWC,UAAX,EAAuBiB,YAAvB,EAAqCf,OAArC,CAA5C;AAEA,SAAOF,UAAP;AACD","sourcesContent":["import {TypedArray} from '../../types';\nimport {padToNBytes} from './memory-copy-utils';\n\n/**\n * Copy sourceBuffer to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {Array | TypedArray} sourceBuffer - source data buffer\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedArrayBufferToDataView(\n dataView: DataView | null,\n byteOffset: number,\n sourceBuffer: TypedArray,\n padding: number\n) {\n const paddedLength = padToNBytes(sourceBuffer.byteLength, padding);\n const padLength = paddedLength - sourceBuffer.byteLength;\n\n if (dataView) {\n // Copy array\n const targetArray = new Uint8Array(\n dataView.buffer,\n dataView.byteOffset + byteOffset,\n sourceBuffer.byteLength\n );\n const sourceArray = new Uint8Array(sourceBuffer);\n targetArray.set(sourceArray);\n\n // Add PADDING\n for (let i = 0; i < padLength; ++i) {\n // json chunk is padded with spaces (ASCII 0x20)\n dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);\n }\n }\n byteOffset += paddedLength;\n return byteOffset;\n}\n\n/**\n * Copy string to dataView with some padding\n *\n * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated\n * @param {number} byteOffset - destination byte offset to copy to\n * @param {string} string - source string\n * @param {number} padding - pad the resulting array to multiple of \"padding\" bytes. Additional bytes are filled with 0x20 (ASCII space)\n *\n * @return new byteOffset of resulting dataView\n */\nexport function copyPaddedStringToDataView(\n dataView: DataView | null,\n byteOffset: number,\n string: string,\n padding: number\n): number {\n const textEncoder = new TextEncoder();\n // PERFORMANCE IDEA: We encode twice, once to get size and once to store\n // PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy\n const stringBuffer = textEncoder.encode(string);\n\n byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);\n\n return byteOffset;\n}\n"],"file":"binary-copy-utils.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/binary-utils/buffer-utils.ts"],"names":["node","isBuffer","value","toBuffer","data","bufferToArrayBuffer","buffer","typedArray","Uint8Array","byteOffset","length","slice"],"mappings":"AAAA,OAAO,KAAKA,IAAZ,MAAsB,2BAAtB;AAKA,OAAO,SAASC,QAAT,CAAkBC,KAAlB,EAAuC;AAC5C,SAAOA,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAA1B,IAAsCA,KAAK,CAACD,QAAnD;AACD;AAMD,OAAO,SAASE,QAAT,CAAkBC,IAAlB,EAAqC;AAC1C,SAAOJ,IAAI,CAACG,QAAL,GAAgBH,IAAI,CAACG,QAAL,CAAcC,IAAd,CAAhB,GAAsCA,IAA7C;AACD;AAMD,OAAO,SAASC,mBAAT,CAA6BC,MAA7B,EAAuD;AAC5D,MAAIL,QAAQ,CAACK,MAAD,CAAZ,EAAsB;AACpB,UAAMC,UAAU,GAAG,IAAIC,UAAJ,CAAeF,MAAM,CAACA,MAAtB,EAA8BA,MAAM,CAACG,UAArC,EAAiDH,MAAM,CAACI,MAAxD,CAAnB;AACA,WAAOH,UAAU,CAACI,KAAX,GAAmBL,MAA1B;AACD;;AACD,SAAOA,MAAP;AACD","sourcesContent":["import * as node from '../node/buffer-utils.node';\n\n/**\n * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n */\nexport function isBuffer(value: any): boolean {\n return value && typeof value === 'object' && value.isBuffer;\n}\n\n/**\n * Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n * @todo better data type\n */\nexport function toBuffer(data: any): Buffer {\n return node.toBuffer ? node.toBuffer(data) : data;\n}\n\n/**\n * Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)\n * @todo better data type\n */\nexport function bufferToArrayBuffer(buffer: any): ArrayBuffer {\n if (isBuffer(buffer)) {\n const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);\n return typedArray.slice().buffer;\n }\n return buffer;\n}\n"],"file":"buffer-utils.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/binary-utils/encode-utils.ts"],"names":["padStringToByteAlignment","string","byteAlignment","length","paddedLength","Math","ceil","padding","whitespace","i","copyStringToDataView","dataView","byteOffset","byteLength","setUint8","charCodeAt","copyBinaryToDataView","binary"],"mappings":"AAIA,OAAO,SAASA,wBAAT,CAAkCC,MAAlC,EAA0CC,aAA1C,EAAyD;AAC9D,QAAMC,MAAM,GAAGF,MAAM,CAACE,MAAtB;AACA,QAAMC,YAAY,GAAGC,IAAI,CAACC,IAAL,CAAUH,MAAM,GAAGD,aAAnB,IAAoCA,aAAzD;AACA,QAAMK,OAAO,GAAGH,YAAY,GAAGD,MAA/B;AACA,MAAIK,UAAU,GAAG,EAAjB;;AACA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,OAApB,EAA6B,EAAEE,CAA/B,EAAkC;AAChCD,IAAAA,UAAU,IAAI,GAAd;AACD;;AACD,SAAOP,MAAM,GAAGO,UAAhB;AACD;AAED,OAAO,SAASE,oBAAT,CAA8BC,QAA9B,EAAwCC,UAAxC,EAAoDX,MAApD,EAA4DY,UAA5D,EAAwE;AAC7E,MAAIF,QAAJ,EAAc;AACZ,SAAK,IAAIF,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGI,UAApB,EAAgCJ,CAAC,EAAjC,EAAqC;AACnCE,MAAAA,QAAQ,CAACG,QAAT,CAAkBF,UAAU,GAAGH,CAA/B,EAAkCR,MAAM,CAACc,UAAP,CAAkBN,CAAlB,CAAlC;AACD;AACF;;AACD,SAAOG,UAAU,GAAGC,UAApB;AACD;AAED,OAAO,SAASG,oBAAT,CAA8BL,QAA9B,EAAwCC,UAAxC,EAAoDK,MAApD,EAA4DJ,UAA5D,EAAwE;AAC7E,MAAIF,QAAJ,EAAc;AACZ,SAAK,IAAIF,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGI,UAApB,EAAgCJ,CAAC,EAAjC,EAAqC;AACnCE,MAAAA,QAAQ,CAACG,QAAT,CAAkBF,UAAU,GAAGH,CAA/B,EAAkCQ,MAAM,CAACR,CAAD,CAAxC;AACD;AACF;;AACD,SAAOG,UAAU,GAAGC,UAApB;AACD","sourcesContent":["// Note: These were broken out from gltf loader...\n// eslint-disable-next-line complexity\n\n// PERFORMANCE IDEA: No need to copy string twice...\nexport function padStringToByteAlignment(string, byteAlignment) {\n const length = string.length;\n const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment\n const padding = paddedLength - length;\n let whitespace = '';\n for (let i = 0; i < padding; ++i) {\n whitespace += ' ';\n }\n return string + whitespace;\n}\n\nexport function copyStringToDataView(dataView, byteOffset, string, byteLength) {\n if (dataView) {\n for (let i = 0; i < byteLength; i++) {\n dataView.setUint8(byteOffset + i, string.charCodeAt(i));\n }\n }\n return byteOffset + byteLength;\n}\n\nexport function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {\n if (dataView) {\n for (let i = 0; i < byteLength; i++) {\n dataView.setUint8(byteOffset + i, binary[i]);\n }\n }\n return byteOffset + byteLength;\n}\n"],"file":"encode-utils.js"}