@loaders.gl/loader-utils 3.1.0-alpha.4 → 3.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/es5/index.js +46 -48
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/json-loader.js +5 -33
  4. package/dist/es5/json-loader.js.map +1 -1
  5. package/dist/es5/lib/binary-utils/array-buffer-utils.js +23 -58
  6. package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -1
  7. package/dist/es5/lib/binary-utils/binary-copy-utils.js +7 -7
  8. package/dist/es5/lib/binary-utils/binary-copy-utils.js.map +1 -1
  9. package/dist/es5/lib/binary-utils/buffer-utils.js +4 -10
  10. package/dist/es5/lib/binary-utils/buffer-utils.js.map +1 -1
  11. package/dist/es5/lib/binary-utils/encode-utils.js +7 -7
  12. package/dist/es5/lib/binary-utils/encode-utils.js.map +1 -1
  13. package/dist/es5/lib/binary-utils/get-first-characters.js +5 -7
  14. package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -1
  15. package/dist/es5/lib/binary-utils/memory-copy-utils.js +6 -7
  16. package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -1
  17. package/dist/es5/lib/env-utils/globals.js +9 -14
  18. package/dist/es5/lib/env-utils/globals.js.map +1 -1
  19. package/dist/es5/lib/filesystems/node-filesystem.js +50 -243
  20. package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -1
  21. package/dist/es5/lib/iterators/async-iteration.js +27 -242
  22. package/dist/es5/lib/iterators/async-iteration.js.map +1 -1
  23. package/dist/es5/lib/iterators/text-iterators.js +35 -410
  24. package/dist/es5/lib/iterators/text-iterators.js.map +1 -1
  25. package/dist/es5/lib/node/buffer.js +4 -4
  26. package/dist/es5/lib/node/buffer.js.map +1 -1
  27. package/dist/es5/lib/node/fs.js +20 -51
  28. package/dist/es5/lib/node/fs.js.map +1 -1
  29. package/dist/es5/lib/node/util.js +3 -5
  30. package/dist/es5/lib/node/util.js.map +1 -1
  31. package/dist/es5/lib/path-utils/file-aliases.js +4 -4
  32. package/dist/es5/lib/path-utils/file-aliases.js.map +1 -1
  33. package/dist/es5/lib/path-utils/path.js +5 -9
  34. package/dist/es5/lib/path-utils/path.js.map +1 -1
  35. package/dist/es5/lib/request-utils/request-scheduler.js +96 -124
  36. package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -1
  37. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +63 -132
  38. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
  39. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +51 -111
  40. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
  41. package/dist/esm/json-loader.js +1 -1
  42. package/dist/esm/json-loader.js.map +1 -1
  43. package/dist/esm/lib/parser-utils/parse-json.js +1 -1
  44. package/dist/esm/lib/parser-utils/parse-json.js.map +1 -1
  45. package/dist/esm/lib/path-utils/file-aliases.js +1 -1
  46. package/dist/esm/lib/path-utils/file-aliases.js.map +1 -1
  47. package/dist/esm/lib/path-utils/path.js +2 -2
  48. package/dist/esm/lib/path-utils/path.js.map +1 -1
  49. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +1 -1
  50. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
  51. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +2 -2
  52. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
  53. package/dist/index.d.ts +27 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +111 -0
  56. package/dist/json-loader.d.ts +22 -0
  57. package/dist/json-loader.d.ts.map +1 -0
  58. package/dist/json-loader.js +28 -0
  59. package/dist/lib/binary-utils/array-buffer-utils.d.ts +31 -0
  60. package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -0
  61. package/dist/lib/binary-utils/array-buffer-utils.js +115 -0
  62. package/dist/lib/binary-utils/binary-copy-utils.d.ts +24 -0
  63. package/dist/lib/binary-utils/binary-copy-utils.d.ts.map +1 -0
  64. package/dist/lib/binary-utils/binary-copy-utils.js +51 -0
  65. package/dist/lib/binary-utils/buffer-utils.d.ts +16 -0
  66. package/dist/lib/binary-utils/buffer-utils.d.ts.map +1 -0
  67. package/dist/lib/binary-utils/buffer-utils.js +50 -0
  68. package/dist/lib/binary-utils/encode-utils.d.ts +4 -0
  69. package/dist/lib/binary-utils/encode-utils.d.ts.map +1 -0
  70. package/dist/lib/binary-utils/encode-utils.js +35 -0
  71. package/dist/lib/binary-utils/get-first-characters.d.ts +3 -0
  72. package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -0
  73. package/dist/lib/binary-utils/get-first-characters.js +30 -0
  74. package/dist/lib/binary-utils/memory-copy-utils.d.ts +25 -0
  75. package/dist/lib/binary-utils/memory-copy-utils.d.ts.map +1 -0
  76. package/dist/lib/binary-utils/memory-copy-utils.js +61 -0
  77. package/dist/lib/env-utils/assert.d.ts +6 -0
  78. package/dist/lib/env-utils/assert.d.ts.map +1 -0
  79. package/dist/lib/env-utils/assert.js +13 -0
  80. package/dist/lib/env-utils/globals.d.ts +15 -0
  81. package/dist/lib/env-utils/globals.d.ts.map +1 -0
  82. package/dist/lib/env-utils/globals.js +30 -0
  83. package/dist/lib/filesystems/node-filesystem.d.ts +38 -0
  84. package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -0
  85. package/dist/lib/filesystems/node-filesystem.js +69 -0
  86. package/dist/lib/iterators/async-iteration.d.ts +20 -0
  87. package/dist/lib/iterators/async-iteration.d.ts.map +1 -0
  88. package/dist/lib/iterators/async-iteration.js +53 -0
  89. package/dist/lib/iterators/text-iterators.d.ts +19 -0
  90. package/dist/lib/iterators/text-iterators.d.ts.map +1 -0
  91. package/dist/lib/iterators/text-iterators.js +61 -0
  92. package/dist/lib/node/buffer.d.ts +10 -0
  93. package/dist/lib/node/buffer.d.ts.map +1 -0
  94. package/dist/lib/node/buffer.js +36 -0
  95. package/dist/lib/node/fs.d.ts +26 -0
  96. package/dist/lib/node/fs.d.ts.map +1 -0
  97. package/dist/lib/node/fs.js +42 -0
  98. package/dist/lib/node/util.d.ts +5 -0
  99. package/dist/lib/node/util.d.ts.map +1 -0
  100. package/dist/lib/node/util.js +25 -0
  101. package/dist/lib/parser-utils/parse-json.d.ts +5 -0
  102. package/dist/lib/parser-utils/parse-json.d.ts.map +1 -0
  103. package/dist/lib/parser-utils/parse-json.js +16 -0
  104. package/dist/lib/path-utils/file-aliases.d.ts +17 -0
  105. package/dist/lib/path-utils/file-aliases.d.ts.map +1 -0
  106. package/dist/lib/path-utils/file-aliases.js +47 -0
  107. package/dist/lib/path-utils/path.d.ts +16 -0
  108. package/dist/lib/path-utils/path.d.ts.map +1 -0
  109. package/dist/lib/path-utils/path.js +40 -0
  110. package/dist/lib/request-utils/request-scheduler.d.ts +62 -0
  111. package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -0
  112. package/dist/lib/request-utils/request-scheduler.js +142 -0
  113. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +7 -0
  114. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -0
  115. package/dist/lib/worker-loader-utils/create-loader-worker.js +97 -0
  116. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +15 -0
  117. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -0
  118. package/dist/lib/worker-loader-utils/parse-with-worker.js +73 -0
  119. package/dist/types.d.ts +207 -0
  120. package/dist/types.d.ts.map +1 -0
  121. package/dist/types.js +3 -0
  122. package/dist/workers/json-worker.d.ts +2 -0
  123. package/dist/workers/json-worker.d.ts.map +1 -0
  124. package/dist/workers/json-worker.js +5 -0
  125. package/package.json +5 -8
  126. package/src/lib/worker-loader-utils/parse-with-worker.ts +6 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-filesystem.d.ts","sourceRoot":"","sources":["../../../src/lib/filesystems/node-filesystem.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,WAAW,EAAE,2BAA2B,EAAC,MAAM,aAAa,CAAC;AAIrE,aAAK,IAAI,GAAG;IACV,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC;CACjB,CAAC;AAEF,aAAK,WAAW,GAAG;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,WAAW,EAAE,2BAA2B;gBAEzE,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC;IAInC,OAAO,CAAC,OAAO,SAAM,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAIpD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC;IAQjD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAIvE,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKhC,IAAI,CACR,EAAE,EAAE,MAAM,EAEV,EAAC,MAAa,EAAE,MAAU,EAAE,MAA0B,EAAE,QAAe,EAAC,EAAE,WAAW,GACpF,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAC;CAehD"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const fs = __importStar(require("../node/fs"));
23
+ /**
24
+ * FileSystem pass-through for Node.js
25
+ * Compatible with BrowserFileSystem.
26
+ * @param options
27
+ */
28
+ class NodeFileSystem {
29
+ // implements IFileSystem
30
+ constructor(options) {
31
+ this.fetch = options._fetch;
32
+ }
33
+ async readdir(dirname = '.', options) {
34
+ return await fs.readdir(dirname, options);
35
+ }
36
+ async stat(path, options) {
37
+ const info = await fs.stat(path, options);
38
+ return { size: Number(info.size), isDirectory: () => false, info };
39
+ }
40
+ async fetch(path, options) {
41
+ // Falls back to handle https:/http:/data: etc fetches
42
+ // eslint-disable-next-line
43
+ const fallbackFetch = options.fetch || this.fetch;
44
+ return fallbackFetch(path, options);
45
+ }
46
+ // implements IRandomAccessFileSystem
47
+ async open(path, flags, mode) {
48
+ return await fs.open(path, flags);
49
+ }
50
+ async close(fd) {
51
+ return await fs.close(fd);
52
+ }
53
+ async fstat(fd) {
54
+ const info = await fs.fstat(fd);
55
+ return info;
56
+ }
57
+ async read(fd,
58
+ // @ts-ignore Possibly null
59
+ { buffer = null, offset = 0, length = buffer.byteLength, position = null }) {
60
+ let totalBytesRead = 0;
61
+ // Read in loop until we get required number of bytes
62
+ while (totalBytesRead < length) {
63
+ const { bytesRead } = await fs.read(fd, buffer, offset + totalBytesRead, length - totalBytesRead, position + totalBytesRead);
64
+ totalBytesRead += bytesRead;
65
+ }
66
+ return { bytesRead: totalBytesRead, buffer };
67
+ }
68
+ }
69
+ exports.default = NodeFileSystem;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Iterate over async iterator, without resetting iterator if end is not reached
3
+ * - forEach intentionally does not reset iterator if exiting loop prematurely
4
+ * so that iteration can continue in a second loop
5
+ * - It is recommended to use a standard for-await as last loop to ensure
6
+ * iterator gets properly reset
7
+ *
8
+ * TODO - optimize using sync iteration if argument is an Iterable?
9
+ *
10
+ * @param iterator
11
+ * @param visitor
12
+ */
13
+ export declare function forEach(iterator: any, visitor: any): Promise<void>;
14
+ /**
15
+ * Concatenates all data chunks yielded by an (async) iterator
16
+ * This function can e.g. be used to enable atomic parsers to work on (async) iterator inputs
17
+ */
18
+ export declare function concatenateArrayBuffersAsync(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>): Promise<ArrayBuffer>;
19
+ export declare function concatenateStringsAsync(asyncIterator: AsyncIterable<string> | Iterable<string>): Promise<string>;
20
+ //# sourceMappingURL=async-iteration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-iteration.d.ts","sourceRoot":"","sources":["../../../src/lib/iterators/async-iteration.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,wBAAsB,OAAO,CAAC,QAAQ,KAAA,EAAE,OAAO,KAAA,iBAa9C;AAID;;;GAGG;AAEH,wBAAsB,4BAA4B,CAChD,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,GAChE,OAAO,CAAC,WAAW,CAAC,CAMtB;AAED,wBAAsB,uBAAuB,CAC3C,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,GACtD,OAAO,CAAC,MAAM,CAAC,CAMjB"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.concatenateStringsAsync = exports.concatenateArrayBuffersAsync = exports.forEach = void 0;
4
+ const array_buffer_utils_1 = require("../binary-utils/array-buffer-utils");
5
+ // GENERAL UTILITIES
6
+ /**
7
+ * Iterate over async iterator, without resetting iterator if end is not reached
8
+ * - forEach intentionally does not reset iterator if exiting loop prematurely
9
+ * so that iteration can continue in a second loop
10
+ * - It is recommended to use a standard for-await as last loop to ensure
11
+ * iterator gets properly reset
12
+ *
13
+ * TODO - optimize using sync iteration if argument is an Iterable?
14
+ *
15
+ * @param iterator
16
+ * @param visitor
17
+ */
18
+ async function forEach(iterator, visitor) {
19
+ // eslint-disable-next-line
20
+ while (true) {
21
+ const { done, value } = await iterator.next();
22
+ if (done) {
23
+ iterator.return();
24
+ return;
25
+ }
26
+ const cancel = visitor(value);
27
+ if (cancel) {
28
+ return;
29
+ }
30
+ }
31
+ }
32
+ exports.forEach = forEach;
33
+ // Breaking big data into iterable chunks, concatenating iterable chunks into big data objects
34
+ /**
35
+ * Concatenates all data chunks yielded by an (async) iterator
36
+ * This function can e.g. be used to enable atomic parsers to work on (async) iterator inputs
37
+ */
38
+ async function concatenateArrayBuffersAsync(asyncIterator) {
39
+ const arrayBuffers = [];
40
+ for await (const chunk of asyncIterator) {
41
+ arrayBuffers.push(chunk);
42
+ }
43
+ return (0, array_buffer_utils_1.concatenateArrayBuffers)(...arrayBuffers);
44
+ }
45
+ exports.concatenateArrayBuffersAsync = concatenateArrayBuffersAsync;
46
+ async function concatenateStringsAsync(asyncIterator) {
47
+ const strings = [];
48
+ for await (const chunk of asyncIterator) {
49
+ strings.push(chunk);
50
+ }
51
+ return strings.join('');
52
+ }
53
+ exports.concatenateStringsAsync = concatenateStringsAsync;
@@ -0,0 +1,19 @@
1
+ export declare function makeTextDecoderIterator(arrayBufferIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options?: TextDecoderOptions): AsyncIterable<string>;
2
+ export declare function makeTextEncoderIterator(textIterator: AsyncIterable<string> | Iterable<ArrayBuffer>): AsyncIterable<ArrayBuffer>;
3
+ /**
4
+ * @param textIterator async iterable yielding strings
5
+ * @returns an async iterable over lines
6
+ * See http://2ality.com/2018/04/async-iter-nodejs.html
7
+ */
8
+ export declare function makeLineIterator(textIterator: AsyncIterable<string>): AsyncIterable<string>;
9
+ /**
10
+ * @param lineIterator async iterable yielding lines
11
+ * @returns async iterable yielding numbered lines
12
+ *
13
+ * See http://2ality.com/2018/04/async-iter-nodejs.html
14
+ */
15
+ export declare function makeNumberedLineIterator(lineIterator: AsyncIterable<string>): AsyncIterable<{
16
+ counter: number;
17
+ line: string;
18
+ }>;
19
+ //# sourceMappingURL=text-iterators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-iterators.d.ts","sourceRoot":"","sources":["../../../src/lib/iterators/text-iterators.ts"],"names":[],"mappings":"AAGA,wBAAuB,uBAAuB,CAC5C,mBAAmB,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACvE,OAAO,GAAE,kBAAuB,GAC/B,aAAa,CAAC,MAAM,CAAC,CAOvB;AAOD,wBAAuB,uBAAuB,CAC5C,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,GAC1D,aAAa,CAAC,WAAW,CAAC,CAK5B;AAED;;;;GAIG;AAEH,wBAAuB,gBAAgB,CACrC,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,GAClC,aAAa,CAAC,MAAM,CAAC,CAgBvB;AAED;;;;;GAKG;AACH,wBAAuB,wBAAwB,CAC7C,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,GAClC,aAAa,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,CAMhD"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ // TextDecoder iterators
3
+ // TextDecoder will keep any partial undecoded bytes between calls to `decode`
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.makeNumberedLineIterator = exports.makeLineIterator = exports.makeTextEncoderIterator = exports.makeTextDecoderIterator = void 0;
6
+ async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
7
+ const textDecoder = new TextDecoder(undefined, options);
8
+ for await (const arrayBuffer of arrayBufferIterator) {
9
+ yield typeof arrayBuffer === 'string'
10
+ ? arrayBuffer
11
+ : textDecoder.decode(arrayBuffer, { stream: true });
12
+ }
13
+ }
14
+ exports.makeTextDecoderIterator = makeTextDecoderIterator;
15
+ // TextEncoder iterator
16
+ // TODO - this is not useful unless min chunk size is given
17
+ // TextEncoder will keep any partial undecoded bytes between calls to `encode`
18
+ // If iterator does not yield strings, assume arrayBuffer and return unencoded
19
+ async function* makeTextEncoderIterator(textIterator) {
20
+ const textEncoder = new TextEncoder();
21
+ for await (const text of textIterator) {
22
+ yield typeof text === 'string' ? textEncoder.encode(text) : text;
23
+ }
24
+ }
25
+ exports.makeTextEncoderIterator = makeTextEncoderIterator;
26
+ /**
27
+ * @param textIterator async iterable yielding strings
28
+ * @returns an async iterable over lines
29
+ * See http://2ality.com/2018/04/async-iter-nodejs.html
30
+ */
31
+ async function* makeLineIterator(textIterator) {
32
+ let previous = '';
33
+ for await (const textChunk of textIterator) {
34
+ previous += textChunk;
35
+ let eolIndex;
36
+ while ((eolIndex = previous.indexOf('\n')) >= 0) {
37
+ // line includes the EOL
38
+ const line = previous.slice(0, eolIndex + 1);
39
+ previous = previous.slice(eolIndex + 1);
40
+ yield line;
41
+ }
42
+ }
43
+ if (previous.length > 0) {
44
+ yield previous;
45
+ }
46
+ }
47
+ exports.makeLineIterator = makeLineIterator;
48
+ /**
49
+ * @param lineIterator async iterable yielding lines
50
+ * @returns async iterable yielding numbered lines
51
+ *
52
+ * See http://2ality.com/2018/04/async-iter-nodejs.html
53
+ */
54
+ async function* makeNumberedLineIterator(lineIterator) {
55
+ let counter = 1;
56
+ for await (const line of lineIterator) {
57
+ yield { counter, line };
58
+ counter++;
59
+ }
60
+ }
61
+ exports.makeNumberedLineIterator = makeNumberedLineIterator;
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Convert Buffer to ArrayBuffer
4
+ */
5
+ export declare function toArrayBuffer(buffer: any): any;
6
+ /**
7
+ * Convert (copy) ArrayBuffer to Buffer
8
+ */
9
+ export declare function toBuffer(binaryData: any): void | Buffer;
10
+ //# sourceMappingURL=buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../../src/lib/node/buffer.ts"],"names":[],"mappings":";AAKA;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,KAAA,OAOnC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,UAAU,KAAA,iBAelC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ // Isolates Buffer references to ensure they are only bundled under Node.js (avoids big webpack polyfill)
3
+ // this file is not visible to webpack (it is excluded in the package.json "browser" field).
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.toBuffer = exports.toArrayBuffer = void 0;
6
+ const assert_1 = require("../env-utils/assert");
7
+ /**
8
+ * Convert Buffer to ArrayBuffer
9
+ */
10
+ function toArrayBuffer(buffer) {
11
+ // TODO - per docs we should just be able to call buffer.buffer, but there are issues
12
+ if (Buffer.isBuffer(buffer)) {
13
+ const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
14
+ return typedArray.slice().buffer;
15
+ }
16
+ return buffer;
17
+ }
18
+ exports.toArrayBuffer = toArrayBuffer;
19
+ /**
20
+ * Convert (copy) ArrayBuffer to Buffer
21
+ */
22
+ function toBuffer(binaryData) {
23
+ if (ArrayBuffer.isView(binaryData)) {
24
+ binaryData = binaryData.buffer;
25
+ }
26
+ if (typeof Buffer !== 'undefined' && binaryData instanceof ArrayBuffer) {
27
+ const buffer = new Buffer(binaryData.byteLength);
28
+ const view = new Uint8Array(binaryData);
29
+ for (let i = 0; i < buffer.length; ++i) {
30
+ buffer[i] = view[i];
31
+ }
32
+ return buffer;
33
+ }
34
+ return (0, assert_1.assert)(false);
35
+ }
36
+ exports.toBuffer = toBuffer;
@@ -0,0 +1,26 @@
1
+ /// <reference types="node" />
2
+ import fs from 'fs';
3
+ export type { Stats } from 'fs';
4
+ /** Wrapper for Node.js fs method */
5
+ export declare const readdir: typeof fs.readdir.__promisify__;
6
+ /** Wrapper for Node.js fs method */
7
+ export declare const stat: typeof fs.stat.__promisify__;
8
+ /** Wrapper for Node.js fs method */
9
+ export declare const readFile: typeof fs.readFile.__promisify__;
10
+ /** Wrapper for Node.js fs method */
11
+ export declare const readFileSync: typeof fs.readFileSync;
12
+ /** Wrapper for Node.js fs method */
13
+ export declare const writeFile: typeof fs.writeFile.__promisify__;
14
+ /** Wrapper for Node.js fs method */
15
+ export declare const writeFileSync: typeof fs.writeFileSync;
16
+ /** Wrapper for Node.js fs method */
17
+ export declare const open: typeof fs.open.__promisify__;
18
+ /** Wrapper for Node.js fs method */
19
+ export declare const close: typeof fs.close.__promisify__;
20
+ /** Wrapper for Node.js fs method */
21
+ export declare const read: typeof fs.read.__promisify__;
22
+ /** Wrapper for Node.js fs method */
23
+ export declare const fstat: typeof fs.fstat.__promisify__;
24
+ export declare const isSupported: boolean;
25
+ export declare function _readToArrayBuffer(fd: number, start: number, length: number): Promise<any>;
26
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../src/lib/node/fs.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,YAAY,EAAC,KAAK,EAAC,MAAM,IAAI,CAAC;AAI9B,oCAAoC;AACpC,eAAO,MAAM,OAAO,iCAAwB,CAAC;AAC7C,oCAAoC;AACpC,eAAO,MAAM,IAAI,8BAAqB,CAAC;AAEvC,oCAAoC;AACpC,eAAO,MAAM,QAAQ,kCAAyB,CAAC;AAC/C,oCAAoC;AACpC,eAAO,MAAM,YAAY,wBAAkB,CAAC;AAC5C,oCAAoC;AACpC,eAAO,MAAM,SAAS,mCAA0B,CAAC;AACjD,oCAAoC;AACpC,eAAO,MAAM,aAAa,yBAAmB,CAAC;AAI9C,oCAAoC;AACpC,eAAO,MAAM,IAAI,8BAAqB,CAAC;AACvC,oCAAoC;AACpC,eAAO,MAAM,KAAK,+BAAsB,CAAC;AACzC,oCAAoC;AACpC,eAAO,MAAM,IAAI,8BAAqB,CAAC;AACvC,oCAAoC;AACpC,eAAO,MAAM,KAAK,+BAAsB,CAAC;AAEzC,eAAO,MAAM,WAAW,SAAc,CAAC;AAEvC,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAOjF"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports._readToArrayBuffer = exports.isSupported = exports.fstat = exports.read = exports.close = exports.open = exports.writeFileSync = exports.writeFile = exports.readFileSync = exports.readFile = exports.stat = exports.readdir = void 0;
7
+ // fs wrapper (promisified fs + avoids bundling fs in browsers)
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const buffer_1 = require("./buffer");
10
+ const util_1 = require("./util");
11
+ // paths
12
+ /** Wrapper for Node.js fs method */
13
+ exports.readdir = (0, util_1.promisify)(fs_1.default.readdir);
14
+ /** Wrapper for Node.js fs method */
15
+ exports.stat = (0, util_1.promisify)(fs_1.default.stat);
16
+ /** Wrapper for Node.js fs method */
17
+ exports.readFile = (0, util_1.promisify)(fs_1.default.readFile);
18
+ /** Wrapper for Node.js fs method */
19
+ exports.readFileSync = fs_1.default.readFileSync;
20
+ /** Wrapper for Node.js fs method */
21
+ exports.writeFile = (0, util_1.promisify)(fs_1.default.writeFile);
22
+ /** Wrapper for Node.js fs method */
23
+ exports.writeFileSync = fs_1.default.writeFileSync;
24
+ // file descriptors
25
+ /** Wrapper for Node.js fs method */
26
+ exports.open = (0, util_1.promisify)(fs_1.default.open);
27
+ /** Wrapper for Node.js fs method */
28
+ exports.close = (0, util_1.promisify)(fs_1.default.close);
29
+ /** Wrapper for Node.js fs method */
30
+ exports.read = (0, util_1.promisify)(fs_1.default.read);
31
+ /** Wrapper for Node.js fs method */
32
+ exports.fstat = (0, util_1.promisify)(fs_1.default.fstat);
33
+ exports.isSupported = Boolean(fs_1.default);
34
+ async function _readToArrayBuffer(fd, start, length) {
35
+ const buffer = Buffer.alloc(length);
36
+ const { bytesRead } = await (0, exports.read)(fd, buffer, 0, length, start);
37
+ if (bytesRead !== length) {
38
+ throw new Error('fs.read failed');
39
+ }
40
+ return (0, buffer_1.toArrayBuffer)(buffer);
41
+ }
42
+ exports._readToArrayBuffer = _readToArrayBuffer;
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ import * as util from 'util';
3
+ /** Wrapper for Node.js promisify */
4
+ export declare const promisify: typeof util.promisify;
5
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/lib/node/util.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,oCAAoC;AACpC,eAAO,MAAM,SAAS,uBAAiB,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.promisify = void 0;
23
+ const util = __importStar(require("util"));
24
+ /** Wrapper for Node.js promisify */
25
+ exports.promisify = util.promisify;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Minimal JSON parser that throws more meaningful error messages
3
+ */
4
+ export declare function parseJSON(string: string): any;
5
+ //# sourceMappingURL=parse-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-json.d.ts","sourceRoot":"","sources":["../../../src/lib/parser-utils/parse-json.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAM7C"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseJSON = void 0;
4
+ const get_first_characters_1 = require("../binary-utils/get-first-characters");
5
+ /**
6
+ * Minimal JSON parser that throws more meaningful error messages
7
+ */
8
+ function parseJSON(string) {
9
+ try {
10
+ return JSON.parse(string);
11
+ }
12
+ catch (_) {
13
+ throw new Error(`Failed to parse JSON from data starting with "${(0, get_first_characters_1.getFirstCharacters)(string)}"`);
14
+ }
15
+ }
16
+ exports.parseJSON = parseJSON;
@@ -0,0 +1,17 @@
1
+ export declare function setPathPrefix(prefix: string): void;
2
+ export declare function getPathPrefix(): string;
3
+ /**
4
+ *
5
+ * @param aliases
6
+ *
7
+ * Note: addAliases are an experimental export, they are only for testing of loaders.gl loaders
8
+ * not intended as a generic aliasing mechanism
9
+ */
10
+ export declare function addAliases(aliases: {
11
+ [aliasPath: string]: string;
12
+ }): void;
13
+ /**
14
+ * Resolves aliases and adds path-prefix to paths
15
+ */
16
+ export declare function resolvePath(filename: string): string;
17
+ //# sourceMappingURL=file-aliases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-aliases.d.ts","sourceRoot":"","sources":["../../../src/lib/path-utils/file-aliases.ts"],"names":[],"mappings":"AAQA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAElD;AAKD,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE;IAAC,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GAAG,IAAI,CAEvE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAWpD"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ // Simple file alias mechanisms for tests.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.resolvePath = exports.addAliases = exports.getPathPrefix = exports.setPathPrefix = void 0;
5
+ let pathPrefix = '';
6
+ const fileAliases = {};
7
+ /*
8
+ * Set a relative path prefix
9
+ */
10
+ function setPathPrefix(prefix) {
11
+ pathPrefix = prefix;
12
+ }
13
+ exports.setPathPrefix = setPathPrefix;
14
+ /*
15
+ * Get the relative path prefix
16
+ */
17
+ function getPathPrefix() {
18
+ return pathPrefix;
19
+ }
20
+ exports.getPathPrefix = getPathPrefix;
21
+ /**
22
+ *
23
+ * @param aliases
24
+ *
25
+ * Note: addAliases are an experimental export, they are only for testing of loaders.gl loaders
26
+ * not intended as a generic aliasing mechanism
27
+ */
28
+ function addAliases(aliases) {
29
+ Object.assign(fileAliases, aliases);
30
+ }
31
+ exports.addAliases = addAliases;
32
+ /**
33
+ * Resolves aliases and adds path-prefix to paths
34
+ */
35
+ function resolvePath(filename) {
36
+ for (const alias in fileAliases) {
37
+ if (filename.startsWith(alias)) {
38
+ const replacement = fileAliases[alias];
39
+ filename = filename.replace(alias, replacement);
40
+ }
41
+ }
42
+ if (!filename.startsWith('http://') && !filename.startsWith('https://')) {
43
+ filename = `${pathPrefix}${filename}`;
44
+ }
45
+ return filename;
46
+ }
47
+ exports.resolvePath = resolvePath;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Replacement for Node.js path.filename
3
+ * @param url
4
+ */
5
+ export declare function filename(url: string): string;
6
+ /**
7
+ * Replacement for Node.js path.dirname
8
+ * @param url
9
+ */
10
+ export declare function dirname(url: string): string;
11
+ /**
12
+ * Replacement for Node.js path.join
13
+ * @param parts
14
+ */
15
+ export declare function join(...parts: string[]): string;
16
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/lib/path-utils/path.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG3C;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAY/C"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ // Beginning of a minimal implementation of the Node.js path API, that doesn't pull in big polyfills.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.join = exports.dirname = exports.filename = void 0;
5
+ /**
6
+ * Replacement for Node.js path.filename
7
+ * @param url
8
+ */
9
+ function filename(url) {
10
+ const slashIndex = url && url.lastIndexOf('/');
11
+ return slashIndex >= 0 ? url.substr(slashIndex + 1) : '';
12
+ }
13
+ exports.filename = filename;
14
+ /**
15
+ * Replacement for Node.js path.dirname
16
+ * @param url
17
+ */
18
+ function dirname(url) {
19
+ const slashIndex = url && url.lastIndexOf('/');
20
+ return slashIndex >= 0 ? url.substr(0, slashIndex) : '';
21
+ }
22
+ exports.dirname = dirname;
23
+ /**
24
+ * Replacement for Node.js path.join
25
+ * @param parts
26
+ */
27
+ function join(...parts) {
28
+ const separator = '/';
29
+ parts = parts.map((part, index) => {
30
+ if (index) {
31
+ part = part.replace(new RegExp(`^${separator}`), '');
32
+ }
33
+ if (index !== parts.length - 1) {
34
+ part = part.replace(new RegExp(`${separator}$`), '');
35
+ }
36
+ return part;
37
+ });
38
+ return parts.join(separator);
39
+ }
40
+ exports.join = join;
@@ -0,0 +1,62 @@
1
+ import { Stats } from '@probe.gl/stats';
2
+ declare type Handle = any;
3
+ declare type DoneFunction = () => any;
4
+ declare type GetPriorityFunction = () => number;
5
+ declare type RequestResult = {
6
+ done: DoneFunction;
7
+ } | null;
8
+ /** RequestScheduler Options */
9
+ export declare type RequestSchedulerProps = {
10
+ id?: string;
11
+ throttleRequests?: boolean;
12
+ maxRequests?: number;
13
+ };
14
+ /** Tracks one request */
15
+ declare type Request = {
16
+ handle: Handle;
17
+ priority: number;
18
+ getPriority: GetPriorityFunction;
19
+ resolve?: (value: any) => any;
20
+ };
21
+ /**
22
+ * Used to issue a request, without having them "deeply queued" by the browser.
23
+ * @todo - Track requests globally, across multiple servers
24
+ */
25
+ export default class RequestScheduler {
26
+ readonly props: Required<RequestSchedulerProps>;
27
+ readonly stats: Stats;
28
+ activeRequestCount: number;
29
+ /** Tracks the number of active requests and prioritizes/cancels queued requests. */
30
+ private requestQueue;
31
+ private requestMap;
32
+ private deferredUpdate;
33
+ constructor(props?: RequestSchedulerProps);
34
+ /**
35
+ * Called by an application that wants to issue a request, without having it deeply queued by the browser
36
+ *
37
+ * When the returned promise resolved, it is OK for the application to issue a request.
38
+ * The promise resolves to an object that contains a `done` method.
39
+ * When the application's request has completed (or failed), the application must call the `done` function
40
+ *
41
+ * @param handle
42
+ * @param getPriority will be called when request "slots" open up,
43
+ * allowing the caller to update priority or cancel the request
44
+ * Highest priority executes first, priority < 0 cancels the request
45
+ * @returns a promise
46
+ * - resolves to a object (with a `done` field) when the request can be issued without queueing,
47
+ * - resolves to `null` if the request has been cancelled (by the callback return < 0).
48
+ * In this case the application should not issue the request
49
+ */
50
+ scheduleRequest(handle: Handle, getPriority?: GetPriorityFunction): Promise<RequestResult>;
51
+ _issueRequest(request: Request): Promise<any>;
52
+ /** We check requests asynchronously, to prevent multiple updates */
53
+ _issueNewRequests(): void;
54
+ /** Refresh all requests */
55
+ _issueNewRequestsAsync(): void;
56
+ /** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
57
+ _updateAllRequests(): void;
58
+ /** Update a single request by calling the callback */
59
+ _updateRequest(request: any): boolean;
60
+ }
61
+ export {};
62
+ //# sourceMappingURL=request-scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-scheduler.d.ts","sourceRoot":"","sources":["../../../src/lib/request-utils/request-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAEtC,aAAK,MAAM,GAAG,GAAG,CAAC;AAClB,aAAK,YAAY,GAAG,MAAM,GAAG,CAAC;AAC9B,aAAK,mBAAmB,GAAG,MAAM,MAAM,CAAC;AACxC,aAAK,aAAa,GAAG;IACnB,IAAI,EAAE,YAAY,CAAC;CACpB,GAAG,IAAI,CAAC;AAET,+BAA+B;AAC/B,oBAAY,qBAAqB,GAAG;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAgBF,yBAAyB;AACzB,aAAK,OAAO,GAAG;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,mBAAmB,CAAC;IACjC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;CAC/B,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAChD,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAK;IAE/B,oFAAoF;IACpF,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,UAAU,CAAkD;IACpE,OAAO,CAAC,cAAc,CAAa;gBAEvB,KAAK,GAAE,qBAA0B;IAY7C;;;;;;;;;;;;;;;OAeG;IACH,eAAe,CACb,MAAM,EAAE,MAAM,EACd,WAAW,GAAE,mBAA6B,GACzC,OAAO,CAAC,aAAa,CAAC;IA0BzB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAuB7C,oEAAoE;IACpE,iBAAiB,IAAI,IAAI;IAMzB,4BAA4B;IAC5B,sBAAsB;IAwBtB,mGAAmG;IACnG,kBAAkB;IAgBlB,sDAAsD;IACtD,cAAc,CAAC,OAAO,KAAA;CAUvB"}