@loaders.gl/loader-utils 4.0.0-alpha.1 → 4.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es5/index.js +328 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/json-loader.js +44 -0
- package/dist/es5/json-loader.js.map +1 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js +80 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/dataview-copy-utils.js +58 -0
- package/dist/es5/lib/binary-utils/dataview-copy-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js +31 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/es5/lib/binary-utils/memory-conversion-utils.js +44 -0
- package/dist/es5/lib/binary-utils/memory-conversion-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js +34 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -0
- package/dist/es5/lib/env-utils/assert.js +12 -0
- package/dist/es5/lib/env-utils/assert.js.map +1 -0
- package/dist/es5/lib/env-utils/globals.js +30 -0
- package/dist/es5/lib/env-utils/globals.js.map +1 -0
- package/dist/es5/lib/filesystems/node-filesystem.js +210 -0
- package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/es5/lib/filesystems/readable-file.js +91 -0
- package/dist/es5/lib/filesystems/readable-file.js.map +1 -0
- package/dist/es5/lib/filesystems/writable-file.js +82 -0
- package/dist/es5/lib/filesystems/writable-file.js.map +1 -0
- package/dist/es5/lib/iterators/async-iteration.js +190 -0
- package/dist/es5/lib/iterators/async-iteration.js.map +1 -0
- package/dist/es5/lib/iterators/text-iterators.js +305 -0
- package/dist/es5/lib/iterators/text-iterators.js.map +1 -0
- package/dist/es5/lib/node/buffer.browser.js +14 -0
- package/dist/es5/lib/node/buffer.browser.js.map +1 -0
- package/dist/es5/lib/node/buffer.js +27 -0
- package/dist/es5/lib/node/buffer.js.map +1 -0
- package/dist/es5/lib/node/fs.js +88 -0
- package/dist/es5/lib/node/fs.js.map +1 -0
- package/dist/es5/lib/node/promisify.js +36 -0
- package/dist/es5/lib/node/promisify.js.map +1 -0
- package/dist/es5/lib/node/stream.js +16 -0
- package/dist/es5/lib/node/stream.js.map +1 -0
- package/dist/es5/lib/option-utils/merge-loader-options.js +30 -0
- package/dist/es5/lib/option-utils/merge-loader-options.js.map +1 -0
- package/dist/es5/lib/parser-utils/parse-json.js +15 -0
- package/dist/es5/lib/parser-utils/parse-json.js.map +1 -0
- package/dist/es5/lib/path-utils/file-aliases.js +33 -0
- package/dist/es5/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/es5/lib/path-utils/get-cwd.js +15 -0
- package/dist/es5/lib/path-utils/get-cwd.js.map +1 -0
- package/dist/es5/lib/path-utils/path.js +136 -0
- package/dist/es5/lib/path-utils/path.js.map +1 -0
- package/dist/es5/lib/request-utils/request-scheduler.js +150 -0
- package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +142 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/encode-with-worker.js +18 -0
- package/dist/es5/lib/worker-loader-utils/encode-with-worker.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +115 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/workers/json-worker.js +6 -0
- package/dist/es5/workers/json-worker.js.map +1 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-loader.js +18 -0
- package/dist/esm/json-loader.js.map +1 -0
- package/dist/esm/lib/binary-utils/array-buffer-utils.js +52 -0
- package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/{lib/binary-utils/binary-copy-utils.js → esm/lib/binary-utils/dataview-copy-utils.js} +27 -4
- package/dist/esm/lib/binary-utils/dataview-copy-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js +24 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/esm/lib/binary-utils/memory-conversion-utils.js +31 -0
- package/dist/esm/lib/binary-utils/memory-conversion-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/memory-copy-utils.js +26 -0
- package/dist/esm/lib/binary-utils/memory-copy-utils.js.map +1 -0
- package/dist/esm/lib/env-utils/assert.js +6 -0
- package/dist/esm/lib/env-utils/assert.js.map +1 -0
- package/dist/esm/lib/env-utils/globals.js +16 -0
- package/dist/esm/lib/env-utils/globals.js.map +1 -0
- package/dist/esm/lib/filesystems/node-filesystem.js +53 -0
- package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/esm/lib/filesystems/readable-file.js +20 -0
- package/dist/esm/lib/filesystems/readable-file.js.map +1 -0
- package/dist/esm/lib/filesystems/writable-file.js +20 -0
- package/dist/esm/lib/filesystems/writable-file.js.map +1 -0
- package/dist/esm/lib/iterators/async-iteration.js +32 -0
- package/dist/esm/lib/iterators/async-iteration.js.map +1 -0
- package/dist/esm/lib/iterators/text-iterators.js +47 -0
- package/dist/esm/lib/iterators/text-iterators.js.map +1 -0
- package/dist/esm/lib/node/buffer.browser.js +7 -0
- package/dist/esm/lib/node/buffer.browser.js.map +1 -0
- package/dist/esm/lib/node/buffer.js +20 -0
- package/dist/esm/lib/node/buffer.js.map +1 -0
- package/dist/esm/lib/node/fs.js +40 -0
- package/dist/esm/lib/node/fs.js.map +1 -0
- package/dist/esm/lib/node/promisify.js +10 -0
- package/dist/esm/lib/node/promisify.js.map +1 -0
- package/dist/esm/lib/node/stream.js +7 -0
- package/dist/esm/lib/node/stream.js.map +1 -0
- package/dist/esm/lib/option-utils/merge-loader-options.js +17 -0
- package/dist/esm/lib/option-utils/merge-loader-options.js.map +1 -0
- package/dist/esm/lib/parser-utils/parse-json.js +9 -0
- package/dist/esm/lib/parser-utils/parse-json.js.map +1 -0
- package/dist/esm/lib/path-utils/file-aliases.js +24 -0
- package/dist/esm/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/esm/lib/path-utils/get-cwd.js +9 -0
- package/dist/esm/lib/path-utils/get-cwd.js.map +1 -0
- package/dist/esm/lib/path-utils/path.js +127 -0
- package/dist/esm/lib/path-utils/path.js.map +1 -0
- package/dist/esm/lib/request-utils/request-scheduler.js +120 -0
- package/dist/esm/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +95 -0
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/encode-with-worker.js +12 -0
- package/dist/esm/lib/worker-loader-utils/encode-with-worker.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +63 -0
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/workers/json-worker.js +4 -0
- package/dist/esm/workers/json-worker.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -26
- package/dist/json-loader.d.ts +9 -0
- package/dist/json-loader.d.ts.map +1 -0
- package/dist/json-loader.js +24 -18
- package/dist/lib/binary-utils/array-buffer-utils.d.ts +27 -0
- package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/array-buffer-utils.js +78 -80
- package/dist/lib/binary-utils/dataview-copy-utils.d.ts +43 -0
- package/dist/lib/binary-utils/dataview-copy-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/dataview-copy-utils.js +97 -0
- package/dist/lib/binary-utils/get-first-characters.d.ts +17 -0
- package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -0
- package/dist/lib/binary-utils/get-first-characters.js +43 -25
- package/dist/lib/binary-utils/memory-conversion-utils.d.ts +15 -0
- package/dist/lib/binary-utils/memory-conversion-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/memory-conversion-utils.js +73 -0
- package/dist/lib/binary-utils/memory-copy-utils.d.ts +25 -0
- package/dist/lib/binary-utils/memory-copy-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/memory-copy-utils.js +58 -24
- package/dist/lib/env-utils/assert.d.ts +6 -0
- package/dist/lib/env-utils/assert.d.ts.map +1 -0
- package/dist/lib/env-utils/assert.js +12 -5
- package/dist/lib/env-utils/globals.d.ts +15 -0
- package/dist/lib/env-utils/globals.d.ts.map +1 -0
- package/dist/lib/env-utils/globals.js +23 -9
- package/dist/lib/filesystems/node-filesystem.d.ts +39 -0
- package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/node-filesystem.js +72 -59
- package/dist/lib/filesystems/readable-file.d.ts +10 -0
- package/dist/lib/filesystems/readable-file.d.ts.map +1 -0
- package/dist/lib/filesystems/readable-file.js +25 -0
- package/dist/lib/filesystems/writable-file.d.ts +18 -0
- package/dist/lib/filesystems/writable-file.d.ts.map +1 -0
- package/dist/lib/filesystems/writable-file.js +48 -0
- package/dist/lib/iterators/async-iteration.d.ts +20 -0
- package/dist/lib/iterators/async-iteration.d.ts.map +1 -0
- package/dist/lib/iterators/async-iteration.js +49 -35
- package/dist/lib/iterators/text-iterators.d.ts +19 -0
- package/dist/lib/iterators/text-iterators.d.ts.map +1 -0
- package/dist/lib/iterators/text-iterators.js +56 -41
- package/dist/lib/node/buffer.browser.d.ts +12 -0
- package/dist/lib/node/buffer.browser.d.ts.map +1 -0
- package/dist/lib/node/buffer.browser.js +22 -0
- package/dist/lib/node/buffer.d.ts +12 -0
- package/dist/lib/node/buffer.d.ts.map +1 -0
- package/dist/lib/node/buffer.js +33 -25
- package/dist/lib/node/fs.d.ts +25 -0
- package/dist/lib/node/fs.d.ts.map +1 -0
- package/dist/lib/node/fs.js +48 -26
- package/dist/lib/node/promisify.d.ts +13 -0
- package/dist/lib/node/promisify.d.ts.map +1 -0
- package/dist/lib/node/promisify.js +22 -0
- package/dist/lib/node/stream.d.ts +4 -0
- package/dist/lib/node/stream.d.ts.map +1 -0
- package/dist/lib/node/stream.js +17 -0
- package/dist/lib/option-utils/merge-loader-options.d.ts +9 -0
- package/dist/lib/option-utils/merge-loader-options.d.ts.map +1 -0
- package/dist/lib/option-utils/merge-loader-options.js +27 -0
- package/dist/lib/parser-utils/parse-json.d.ts +5 -0
- package/dist/lib/parser-utils/parse-json.d.ts.map +1 -0
- package/dist/lib/parser-utils/parse-json.js +15 -8
- package/dist/lib/path-utils/file-aliases.d.ts +17 -0
- package/dist/lib/path-utils/file-aliases.d.ts.map +1 -0
- package/dist/lib/path-utils/file-aliases.js +40 -19
- package/dist/lib/path-utils/get-cwd.d.ts +2 -0
- package/dist/lib/path-utils/get-cwd.d.ts.map +1 -0
- package/dist/lib/path-utils/get-cwd.js +12 -0
- package/dist/lib/path-utils/path.d.ts +24 -0
- package/dist/lib/path-utils/path.d.ts.map +1 -0
- package/dist/lib/path-utils/path.js +173 -19
- package/dist/lib/request-utils/request-scheduler.d.ts +62 -0
- package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -0
- package/dist/lib/request-utils/request-scheduler.js +127 -131
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +7 -0
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/create-loader-worker.js +92 -96
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts +8 -0
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/encode-with-worker.js +21 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +15 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.js +77 -60
- package/dist/types.d.ts +257 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -2
- package/dist/workers/json-worker.d.ts +2 -0
- package/dist/workers/json-worker.d.ts.map +1 -0
- package/dist/workers/json-worker.js +5 -4
- package/package.json +14 -24
- package/src/index.ts +40 -19
- package/src/json-loader.ts +5 -4
- package/src/lib/binary-utils/array-buffer-utils.ts +4 -40
- package/src/lib/binary-utils/{binary-copy-utils.ts → dataview-copy-utils.ts} +57 -5
- package/src/lib/binary-utils/get-first-characters.ts +17 -1
- package/src/lib/binary-utils/memory-conversion-utils.ts +53 -0
- package/src/lib/filesystems/readable-file.ts +30 -0
- package/src/lib/filesystems/writable-file.ts +44 -0
- package/src/lib/node/buffer.browser.ts +20 -0
- package/src/lib/node/buffer.ts +12 -11
- package/src/lib/node/fs.ts +51 -16
- package/src/lib/node/promisify.ts +70 -0
- package/src/lib/node/stream.ts +18 -0
- package/src/lib/option-utils/merge-loader-options.ts +35 -0
- package/src/lib/path-utils/get-cwd.ts +9 -0
- package/src/lib/path-utils/path.ts +138 -4
- package/src/lib/worker-loader-utils/create-loader-worker.ts +3 -2
- package/src/lib/worker-loader-utils/encode-with-worker.ts +21 -0
- package/src/lib/worker-loader-utils/parse-with-worker.ts +16 -3
- package/src/types.ts +211 -93
- package/dist/index.js.map +0 -1
- package/dist/json-loader.js.map +0 -1
- package/dist/lib/binary-utils/array-buffer-utils.js.map +0 -1
- package/dist/lib/binary-utils/binary-copy-utils.js.map +0 -1
- package/dist/lib/binary-utils/buffer-utils.js +0 -16
- package/dist/lib/binary-utils/buffer-utils.js.map +0 -1
- package/dist/lib/binary-utils/encode-utils.js +0 -31
- package/dist/lib/binary-utils/encode-utils.js.map +0 -1
- package/dist/lib/binary-utils/get-first-characters.js.map +0 -1
- package/dist/lib/binary-utils/memory-copy-utils.js.map +0 -1
- package/dist/lib/env-utils/assert.js.map +0 -1
- package/dist/lib/env-utils/globals.js.map +0 -1
- package/dist/lib/filesystems/node-filesystem.js.map +0 -1
- package/dist/lib/iterators/async-iteration.js.map +0 -1
- package/dist/lib/iterators/text-iterators.js.map +0 -1
- package/dist/lib/node/buffer.js.map +0 -1
- package/dist/lib/node/fs.js.map +0 -1
- package/dist/lib/node/util.js +0 -3
- package/dist/lib/node/util.js.map +0 -1
- package/dist/lib/parser-utils/parse-json.js.map +0 -1
- package/dist/lib/path-utils/file-aliases.js.map +0 -1
- package/dist/lib/path-utils/path.js.map +0 -1
- package/dist/lib/request-utils/request-scheduler.js.map +0 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
- package/dist/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/workers/json-worker.js.map +0 -1
- package/src/lib/binary-utils/buffer-utils.ts +0 -28
- package/src/lib/binary-utils/encode-utils.ts +0 -32
- package/src/lib/node/util.ts +0 -4
|
@@ -1,12 +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
|
+
import {getCWD} from './get-cwd';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Replacement for Node.js path.filename
|
|
5
7
|
* @param url
|
|
6
8
|
*/
|
|
7
9
|
export function filename(url: string): string {
|
|
8
|
-
const slashIndex = url
|
|
9
|
-
return slashIndex >= 0 ? url.substr(
|
|
10
|
+
const slashIndex = url ? url.lastIndexOf('/') : -1;
|
|
11
|
+
return slashIndex >= 0 ? url.substr(slashIndex + 1) : '';
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -14,8 +16,8 @@ export function filename(url: string): string {
|
|
|
14
16
|
* @param url
|
|
15
17
|
*/
|
|
16
18
|
export function dirname(url: string): string {
|
|
17
|
-
const slashIndex = url
|
|
18
|
-
return slashIndex >= 0 ? url.substr(0, slashIndex
|
|
19
|
+
const slashIndex = url ? url.lastIndexOf('/') : -1;
|
|
20
|
+
return slashIndex >= 0 ? url.substr(0, slashIndex) : '';
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/**
|
|
@@ -35,3 +37,135 @@ export function join(...parts: string[]): string {
|
|
|
35
37
|
});
|
|
36
38
|
return parts.join(separator);
|
|
37
39
|
}
|
|
40
|
+
|
|
41
|
+
/* eslint-disable no-continue */
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* https://nodejs.org/api/path.html#path_path_resolve_paths
|
|
45
|
+
* @param paths A sequence of paths or path segments.
|
|
46
|
+
* @return resolved path
|
|
47
|
+
* Forked from BTOdell/path-resolve under MIT license
|
|
48
|
+
* @see https://github.com/BTOdell/path-resolve/blob/master/LICENSE
|
|
49
|
+
*/
|
|
50
|
+
export function resolve(...components: string[]): string {
|
|
51
|
+
const paths: string[] = [];
|
|
52
|
+
for (let _i = 0; _i < components.length; _i++) {
|
|
53
|
+
paths[_i] = components[_i];
|
|
54
|
+
}
|
|
55
|
+
let resolvedPath = '';
|
|
56
|
+
let resolvedAbsolute = false;
|
|
57
|
+
let cwd: string | undefined;
|
|
58
|
+
for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
59
|
+
let path: string | undefined;
|
|
60
|
+
if (i >= 0) {
|
|
61
|
+
path = paths[i];
|
|
62
|
+
} else {
|
|
63
|
+
if (cwd === undefined) {
|
|
64
|
+
cwd = getCWD();
|
|
65
|
+
}
|
|
66
|
+
path = cwd;
|
|
67
|
+
}
|
|
68
|
+
// Skip empty entries
|
|
69
|
+
if (path.length === 0) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
73
|
+
resolvedAbsolute = path.charCodeAt(0) === SLASH;
|
|
74
|
+
}
|
|
75
|
+
// At this point the path should be resolved to a full absolute path, but
|
|
76
|
+
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
77
|
+
// Normalize the path (removes leading slash)
|
|
78
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
79
|
+
if (resolvedAbsolute) {
|
|
80
|
+
return `/${resolvedPath}`;
|
|
81
|
+
} else if (resolvedPath.length > 0) {
|
|
82
|
+
return resolvedPath;
|
|
83
|
+
}
|
|
84
|
+
return '.';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const SLASH = 47;
|
|
88
|
+
const DOT = 46;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Resolves . and .. elements in a path with directory names
|
|
92
|
+
* Forked from BTOdell/path-resolve under MIT license
|
|
93
|
+
* @see https://github.com/BTOdell/path-resolve/blob/master/LICENSE
|
|
94
|
+
*/
|
|
95
|
+
/* eslint-disable max-depth */
|
|
96
|
+
// eslint-disable-next-line complexity, max-statements
|
|
97
|
+
function normalizeStringPosix(path: string, allowAboveRoot: boolean): string {
|
|
98
|
+
let res = '';
|
|
99
|
+
let lastSlash = -1;
|
|
100
|
+
let dots = 0;
|
|
101
|
+
let code: number | undefined;
|
|
102
|
+
let isAboveRoot = false;
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i <= path.length; ++i) {
|
|
105
|
+
if (i < path.length) {
|
|
106
|
+
code = path.charCodeAt(i);
|
|
107
|
+
} else if (code === SLASH) {
|
|
108
|
+
break;
|
|
109
|
+
} else {
|
|
110
|
+
code = SLASH;
|
|
111
|
+
}
|
|
112
|
+
if (code === SLASH) {
|
|
113
|
+
if (lastSlash === i - 1 || dots === 1) {
|
|
114
|
+
// NOOP
|
|
115
|
+
} else if (lastSlash !== i - 1 && dots === 2) {
|
|
116
|
+
if (
|
|
117
|
+
res.length < 2 ||
|
|
118
|
+
!isAboveRoot ||
|
|
119
|
+
res.charCodeAt(res.length - 1) !== DOT ||
|
|
120
|
+
res.charCodeAt(res.length - 2) !== DOT
|
|
121
|
+
) {
|
|
122
|
+
if (res.length > 2) {
|
|
123
|
+
const start = res.length - 1;
|
|
124
|
+
let j = start;
|
|
125
|
+
for (; j >= 0; --j) {
|
|
126
|
+
if (res.charCodeAt(j) === SLASH) {
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (j !== start) {
|
|
131
|
+
res = j === -1 ? '' : res.slice(0, j);
|
|
132
|
+
lastSlash = i;
|
|
133
|
+
dots = 0;
|
|
134
|
+
isAboveRoot = false;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
138
|
+
res = '';
|
|
139
|
+
lastSlash = i;
|
|
140
|
+
dots = 0;
|
|
141
|
+
isAboveRoot = false;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (allowAboveRoot) {
|
|
146
|
+
if (res.length > 0) {
|
|
147
|
+
res += '/..';
|
|
148
|
+
} else {
|
|
149
|
+
res = '..';
|
|
150
|
+
}
|
|
151
|
+
isAboveRoot = true;
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
const slice = path.slice(lastSlash + 1, i);
|
|
155
|
+
if (res.length > 0) {
|
|
156
|
+
res += `/${slice}`;
|
|
157
|
+
} else {
|
|
158
|
+
res = slice;
|
|
159
|
+
}
|
|
160
|
+
isAboveRoot = false;
|
|
161
|
+
}
|
|
162
|
+
lastSlash = i;
|
|
163
|
+
dots = 0;
|
|
164
|
+
} else if (code === DOT && dots !== -1) {
|
|
165
|
+
++dots;
|
|
166
|
+
} else {
|
|
167
|
+
dots = -1;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return res;
|
|
171
|
+
}
|
|
@@ -11,7 +11,7 @@ let requestId = 0;
|
|
|
11
11
|
*/
|
|
12
12
|
export function createLoaderWorker(loader: LoaderWithParser) {
|
|
13
13
|
// Check that we are actually in a worker thread
|
|
14
|
-
if (
|
|
14
|
+
if (!WorkerBody.inWorkerThread()) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -21,13 +21,14 @@ export function createLoaderWorker(loader: LoaderWithParser) {
|
|
|
21
21
|
try {
|
|
22
22
|
// validateLoaderVersion(loader, data.source.split('@')[1]);
|
|
23
23
|
|
|
24
|
-
const {input, options = {}} = payload;
|
|
24
|
+
const {input, options = {}, context = {}} = payload;
|
|
25
25
|
|
|
26
26
|
const result = await parseData({
|
|
27
27
|
loader,
|
|
28
28
|
arrayBuffer: input,
|
|
29
29
|
options,
|
|
30
30
|
context: {
|
|
31
|
+
...context,
|
|
31
32
|
parse: parseOnMainThread
|
|
32
33
|
}
|
|
33
34
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {WorkerFarm} from '@loaders.gl/worker-utils';
|
|
2
|
+
import {Writer, WriterOptions} from '../../types';
|
|
3
|
+
import {isBrowser} from '../env-utils/globals';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Determines if a loader can parse with worker
|
|
7
|
+
* @param loader
|
|
8
|
+
* @param options
|
|
9
|
+
*/
|
|
10
|
+
export function canEncodeWithWorker(writer: Writer, options?: WriterOptions) {
|
|
11
|
+
if (!WorkerFarm.isSupported()) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Node workers are still experimental
|
|
16
|
+
if (!isBrowser && !options?._nodeWorkers) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return writer.worker && options?.worker;
|
|
21
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
WorkerJob,
|
|
3
|
+
WorkerMessageType,
|
|
4
|
+
WorkerMessagePayload,
|
|
5
|
+
isBrowser
|
|
6
|
+
} from '@loaders.gl/worker-utils';
|
|
2
7
|
import type {Loader, LoaderOptions, LoaderContext} from '../../types';
|
|
3
8
|
import {WorkerFarm, getWorkerURL} from '@loaders.gl/worker-utils';
|
|
4
9
|
|
|
@@ -12,6 +17,11 @@ export function canParseWithWorker(loader: Loader, options?: LoaderOptions) {
|
|
|
12
17
|
return false;
|
|
13
18
|
}
|
|
14
19
|
|
|
20
|
+
// Node workers are still experimental
|
|
21
|
+
if (!isBrowser && !options?._nodeWorkers) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
return loader.worker && options?.worker;
|
|
16
26
|
}
|
|
17
27
|
|
|
@@ -33,19 +43,22 @@ export async function parseWithWorker(
|
|
|
33
43
|
const workerPool = workerFarm.getWorkerPool({name, url});
|
|
34
44
|
|
|
35
45
|
// options.log object contains functions which cannot be transferred
|
|
46
|
+
// context.fetch & context.parse functions cannot be transferred
|
|
36
47
|
// TODO - decide how to handle logging on workers
|
|
37
48
|
options = JSON.parse(JSON.stringify(options));
|
|
49
|
+
context = JSON.parse(JSON.stringify(context || {}));
|
|
38
50
|
|
|
39
51
|
const job = await workerPool.startJob(
|
|
40
52
|
'process-on-worker',
|
|
41
53
|
// @ts-expect-error
|
|
42
|
-
onMessage.bind(null, parseOnMainThread) // eslint-disable-
|
|
54
|
+
onMessage.bind(null, parseOnMainThread) // eslint-disable-line @typescript-eslint/no-misused-promises
|
|
43
55
|
);
|
|
44
56
|
|
|
45
57
|
job.postMessage('process', {
|
|
46
58
|
// @ts-ignore
|
|
47
59
|
input: data,
|
|
48
|
-
options
|
|
60
|
+
options,
|
|
61
|
+
context
|
|
49
62
|
});
|
|
50
63
|
|
|
51
64
|
const result = await job.result;
|
package/src/types.ts
CHANGED
|
@@ -15,11 +15,37 @@ export type TypedFloatArray = Uint16Array | Float32Array | Float64Array;
|
|
|
15
15
|
|
|
16
16
|
export type TypedArray = TypedIntArray | TypedFloatArray;
|
|
17
17
|
|
|
18
|
-
export type
|
|
18
|
+
export type BigTypedArray = TypedArray | BigInt64Array | BigUint64Array;
|
|
19
|
+
|
|
20
|
+
export type TypedArrayConstructor =
|
|
21
|
+
| Int8ArrayConstructor
|
|
22
|
+
| Uint8ArrayConstructor
|
|
23
|
+
| Int16ArrayConstructor
|
|
24
|
+
| Uint16ArrayConstructor
|
|
25
|
+
| Int32ArrayConstructor
|
|
26
|
+
| Uint32ArrayConstructor
|
|
27
|
+
| Int32ArrayConstructor
|
|
28
|
+
| Uint32ArrayConstructor
|
|
29
|
+
| Float32ArrayConstructor
|
|
30
|
+
| Float64ArrayConstructor;
|
|
31
|
+
|
|
32
|
+
export type BigTypedArrayConstructor =
|
|
33
|
+
| TypedArrayConstructor
|
|
34
|
+
| BigInt64ArrayConstructor
|
|
35
|
+
| BigUint64ArrayConstructor;
|
|
36
|
+
|
|
37
|
+
/** Any numeric array: typed array or `number[]` */
|
|
38
|
+
export type NumberArray = number[] | TypedArray;
|
|
39
|
+
|
|
40
|
+
export type NumericArray = number[] | TypedArray;
|
|
19
41
|
|
|
20
42
|
type FetchLike = (url: string, options?: RequestInit) => Promise<Response>;
|
|
21
43
|
|
|
22
|
-
//
|
|
44
|
+
// LOADERS
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Core Loader Options
|
|
48
|
+
*/
|
|
23
49
|
export type LoaderOptions = {
|
|
24
50
|
/** fetch options or a custom fetch function */
|
|
25
51
|
fetch?: typeof fetch | FetchLike | RequestInit | null;
|
|
@@ -55,7 +81,7 @@ export type LoaderOptions = {
|
|
|
55
81
|
// workers
|
|
56
82
|
|
|
57
83
|
/** CDN load workers from */
|
|
58
|
-
CDN?: string;
|
|
84
|
+
CDN?: string | null;
|
|
59
85
|
/** Set to `false` to disable workers */
|
|
60
86
|
worker?: boolean;
|
|
61
87
|
/** Number of concurrent workers (per loader) on desktop browser */
|
|
@@ -64,7 +90,9 @@ export type LoaderOptions = {
|
|
|
64
90
|
maxMobileConcurrency?: number;
|
|
65
91
|
/** Set to `false` to prevent reuse workers */
|
|
66
92
|
reuseWorkers?: boolean;
|
|
67
|
-
/**
|
|
93
|
+
/** Whether to use workers under Node.js (experimental) */
|
|
94
|
+
_nodeWorkers?: boolean;
|
|
95
|
+
/** set to 'test' to run local worker */
|
|
68
96
|
_workerType?: string;
|
|
69
97
|
|
|
70
98
|
/** @deprecated `options.batchType` removed, Use `options.<loader>.type` instead */
|
|
@@ -72,175 +100,265 @@ export type LoaderOptions = {
|
|
|
72
100
|
/** @deprecated `options.throw removed`, Use `options.nothrow` instead */
|
|
73
101
|
throws?: boolean;
|
|
74
102
|
/** @deprecated `options.dataType` no longer used */
|
|
75
|
-
dataType?:
|
|
103
|
+
dataType?: never;
|
|
76
104
|
/** @deprecated `options.uri` no longer used */
|
|
77
|
-
uri?:
|
|
105
|
+
uri?: never;
|
|
78
106
|
/** @deprecated `options.method` removed. Use `options.fetch.method` */
|
|
79
|
-
method?:
|
|
107
|
+
method?: never;
|
|
80
108
|
/** @deprecated `options.headers` removed. Use `options.fetch.headers` */
|
|
81
|
-
headers?:
|
|
109
|
+
headers?: never;
|
|
82
110
|
/** @deprecated `options.body` removed. Use `options.fetch.body` */
|
|
83
|
-
body?:
|
|
111
|
+
body?: never;
|
|
84
112
|
/** @deprecated `options.mode` removed. Use `options.fetch.mode` */
|
|
85
|
-
mode?:
|
|
113
|
+
mode?: never;
|
|
86
114
|
/** @deprecated `options.credentials` removed. Use `options.fetch.credentials` */
|
|
87
|
-
credentials?:
|
|
115
|
+
credentials?: never;
|
|
88
116
|
/** @deprecated `options.cache` removed. Use `options.fetch.cache` */
|
|
89
|
-
cache?:
|
|
117
|
+
cache?: never;
|
|
90
118
|
/** @deprecated `options.redirect` removed. Use `options.fetch.redirect` */
|
|
91
|
-
redirect?:
|
|
119
|
+
redirect?: never;
|
|
92
120
|
/** @deprecated `options.referrer` removed. Use `options.fetch.referrer` */
|
|
93
|
-
referrer?:
|
|
121
|
+
referrer?: never;
|
|
94
122
|
/** @deprecated `options.referrerPolicy` removed. Use `options.fetch.referrerPolicy` */
|
|
95
|
-
referrerPolicy?:
|
|
123
|
+
referrerPolicy?: never;
|
|
96
124
|
/** @deprecated `options.integrity` removed. Use `options.fetch.integrity` */
|
|
97
|
-
integrity?:
|
|
125
|
+
integrity?: never;
|
|
98
126
|
/** @deprecated `options.keepalive` removed. Use `options.fetch.keepalive` */
|
|
99
|
-
keepalive?:
|
|
127
|
+
keepalive?: never;
|
|
100
128
|
/** @deprecated `options.signal` removed. Use `options.fetch.signal` */
|
|
101
|
-
signal?:
|
|
129
|
+
signal?: never;
|
|
102
130
|
|
|
103
131
|
// Accept other keys (loader options objects, e.g. `options.csv`, `options.json` ...)
|
|
104
|
-
[loaderId: string]:
|
|
132
|
+
[loaderId: string]: unknown;
|
|
105
133
|
};
|
|
106
134
|
|
|
107
135
|
type PreloadOptions = {
|
|
108
|
-
[key: string]:
|
|
136
|
+
[key: string]: unknown;
|
|
109
137
|
};
|
|
110
138
|
|
|
111
139
|
/**
|
|
112
140
|
* A worker loader definition that can be used with `@loaders.gl/core` functions
|
|
113
141
|
*/
|
|
114
|
-
export type Loader = {
|
|
142
|
+
export type Loader<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = {
|
|
143
|
+
// Types
|
|
144
|
+
dataType?: DataT;
|
|
145
|
+
batchType?: BatchT;
|
|
146
|
+
|
|
147
|
+
/** Default Options */
|
|
148
|
+
options: LoaderOptionsT;
|
|
149
|
+
/** Deprecated Options */
|
|
150
|
+
deprecatedOptions?: Record<string, string | Record<string, string>>;
|
|
151
|
+
|
|
115
152
|
// Worker
|
|
116
153
|
name: string;
|
|
154
|
+
/** id should be the same as the field used in LoaderOptions */
|
|
117
155
|
id: string;
|
|
156
|
+
/** module is used to generate worker threads, need to be the module directory name */
|
|
118
157
|
module: string;
|
|
158
|
+
/** Version should be injected by build tools */
|
|
119
159
|
version: string;
|
|
160
|
+
/** A boolean, or a URL */
|
|
120
161
|
worker?: string | boolean;
|
|
121
|
-
options: object;
|
|
122
|
-
deprecatedOptions?: object;
|
|
123
162
|
// end Worker
|
|
124
163
|
|
|
164
|
+
/** Which category does this loader belong to */
|
|
125
165
|
category?: string;
|
|
166
|
+
/** What extensions does this loader generate */
|
|
126
167
|
extensions: string[];
|
|
127
168
|
mimeTypes: string[];
|
|
128
169
|
|
|
129
170
|
binary?: boolean;
|
|
130
171
|
text?: boolean;
|
|
131
172
|
|
|
132
|
-
tests?: (((ArrayBuffer) => boolean) | ArrayBuffer | string)[];
|
|
173
|
+
tests?: (((ArrayBuffer: ArrayBuffer) => boolean) | ArrayBuffer | string)[];
|
|
133
174
|
|
|
134
175
|
// TODO - deprecated
|
|
135
176
|
supported?: boolean;
|
|
136
|
-
testText?: (string) => boolean;
|
|
177
|
+
testText?: (string: string) => boolean;
|
|
137
178
|
};
|
|
138
179
|
|
|
139
180
|
/**
|
|
140
181
|
* A "bundled" loader definition that can be used with `@loaders.gl/core` functions
|
|
141
182
|
* If a worker loader is supported it will also be supported.
|
|
142
183
|
*/
|
|
143
|
-
export type LoaderWithParser =
|
|
184
|
+
export type LoaderWithParser<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = Loader<
|
|
185
|
+
DataT,
|
|
186
|
+
BatchT,
|
|
187
|
+
LoaderOptionsT
|
|
188
|
+
> & {
|
|
144
189
|
// TODO - deprecated
|
|
145
|
-
testText?: (string) => boolean;
|
|
190
|
+
testText?: (string: string) => boolean;
|
|
146
191
|
|
|
147
|
-
parse:
|
|
192
|
+
parse: (
|
|
193
|
+
arrayBuffer: ArrayBuffer,
|
|
194
|
+
options?: LoaderOptionsT,
|
|
195
|
+
context?: LoaderContext
|
|
196
|
+
) => Promise<DataT>;
|
|
148
197
|
preload?: Preload;
|
|
149
|
-
parseSync?:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
198
|
+
parseSync?: (
|
|
199
|
+
arrayBuffer: ArrayBuffer,
|
|
200
|
+
options?: LoaderOptionsT,
|
|
201
|
+
context?: LoaderContext
|
|
202
|
+
) => DataT;
|
|
203
|
+
parseText?: (text: string, options?: LoaderOptionsT) => Promise<DataT>;
|
|
204
|
+
parseTextSync?: (text: string, options?: LoaderOptionsT) => DataT;
|
|
205
|
+
parseInBatches?: (
|
|
206
|
+
iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
207
|
+
options?: LoaderOptionsT,
|
|
208
|
+
context?: LoaderContext
|
|
209
|
+
) => AsyncIterable<BatchT>;
|
|
210
|
+
parseFileInBatches?: (
|
|
211
|
+
file: Blob,
|
|
212
|
+
options?: LoaderOptionsT,
|
|
213
|
+
context?: LoaderContext
|
|
214
|
+
) => AsyncIterable<BatchT>;
|
|
154
215
|
};
|
|
155
216
|
|
|
156
|
-
/** Options for writers */
|
|
157
|
-
export type WriterOptions = {};
|
|
158
|
-
|
|
159
217
|
/**
|
|
160
|
-
* A
|
|
218
|
+
* A Loader context is provided as a third parameters to a loader object's
|
|
219
|
+
* parse functions when that loader is called by other loaders rather then
|
|
220
|
+
* directly by the application.
|
|
221
|
+
*
|
|
222
|
+
* - The context object allows the subloaders to be aware of the parameters and
|
|
223
|
+
* options that the application provided in the top level call.
|
|
224
|
+
* - The context also providedsaccess to parse functions so that the subloader
|
|
225
|
+
* does not need to include the core module.
|
|
226
|
+
* - In addition, the context's parse functions may also redirect loads from worker
|
|
227
|
+
* threads back to main thread.
|
|
161
228
|
*/
|
|
162
|
-
export type Writer = {
|
|
163
|
-
name: string;
|
|
164
|
-
|
|
165
|
-
id: string;
|
|
166
|
-
module: string;
|
|
167
|
-
version: string;
|
|
168
|
-
|
|
169
|
-
options: object;
|
|
170
|
-
deprecatedOptions?: object;
|
|
171
|
-
|
|
172
|
-
// TODO - are these are needed?
|
|
173
|
-
binary?: boolean;
|
|
174
|
-
extensions?: string[];
|
|
175
|
-
mimeTypes?: string[];
|
|
176
|
-
text?: boolean;
|
|
177
|
-
|
|
178
|
-
encode?: Encode;
|
|
179
|
-
encodeSync?: EncodeSync;
|
|
180
|
-
encodeInBatches?: EncodeInBatches;
|
|
181
|
-
encodeURLtoURL?: EncodeURLtoURL;
|
|
182
|
-
encodeText?: EncodeText;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
229
|
export type LoaderContext = {
|
|
186
230
|
loaders?: Loader[] | null;
|
|
231
|
+
/** If URL is available. */
|
|
187
232
|
url?: string;
|
|
188
|
-
|
|
189
|
-
|
|
233
|
+
/** the file name component of the URL (leading path and query string removed) */
|
|
234
|
+
filename?: string;
|
|
235
|
+
/** the directory name component of the URL (leading path excluding file name and query string) */
|
|
236
|
+
baseUrl?: string;
|
|
237
|
+
/** Query string (characters after `?`) */
|
|
238
|
+
queryString?: string;
|
|
239
|
+
|
|
240
|
+
/** Provides access to any application overrides of fetch() */
|
|
241
|
+
fetch: typeof fetch | FetchLike;
|
|
242
|
+
/** TBD */
|
|
243
|
+
response?: Response;
|
|
244
|
+
/** Parse function. Use instead of importing `core`. In workers, may redirect to main thread */
|
|
190
245
|
parse: (
|
|
191
246
|
arrayBuffer: ArrayBuffer,
|
|
192
|
-
loaders
|
|
247
|
+
loaders?: Loader | Loader[] | LoaderOptions,
|
|
193
248
|
options?: LoaderOptions,
|
|
194
249
|
context?: LoaderContext
|
|
195
250
|
) => Promise<any>;
|
|
251
|
+
/** ParseSync function. Use instead of importing `core`. In workers, may redirect to main thread */
|
|
196
252
|
parseSync?: (
|
|
197
253
|
arrayBuffer: ArrayBuffer,
|
|
198
|
-
loaders
|
|
254
|
+
loaders?: Loader | Loader[] | LoaderOptions,
|
|
199
255
|
options?: LoaderOptions,
|
|
200
256
|
context?: LoaderContext
|
|
201
257
|
) => any;
|
|
258
|
+
/** ParseInBatches function. Use instead of importing `core`. */
|
|
202
259
|
parseInBatches?: (
|
|
203
260
|
iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
204
|
-
loaders
|
|
261
|
+
loaders?: Loader | Loader[] | LoaderOptions,
|
|
205
262
|
options?: LoaderOptions,
|
|
206
263
|
context?: LoaderContext
|
|
207
264
|
) => AsyncIterable<any> | Promise<AsyncIterable<any>>;
|
|
208
265
|
};
|
|
209
266
|
|
|
210
|
-
type Parse = (
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
) => Promise<any>;
|
|
215
|
-
type ParseSync = (
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
) => any;
|
|
220
|
-
type ParseText = (text: string, options?: LoaderOptions) => Promise<any>;
|
|
221
|
-
type ParseTextSync = (text: string, options?: LoaderOptions) => any;
|
|
222
|
-
type ParseInBatches = (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
) => AsyncIterable<any>;
|
|
227
|
-
type ParseFileInBatches = (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
) => AsyncIterable<any>;
|
|
232
|
-
|
|
233
|
-
type
|
|
267
|
+
// type Parse = (
|
|
268
|
+
// arrayBuffer: ArrayBuffer,
|
|
269
|
+
// options?: LoaderOptions,
|
|
270
|
+
// context?: LoaderContext
|
|
271
|
+
// ) => Promise<any>;
|
|
272
|
+
// type ParseSync = (
|
|
273
|
+
// arrayBuffer: ArrayBuffer,
|
|
274
|
+
// options?: LoaderOptions,
|
|
275
|
+
// context?: LoaderContext
|
|
276
|
+
// ) => any;
|
|
277
|
+
// type ParseText = (text: string, options?: LoaderOptions) => Promise<any>;
|
|
278
|
+
// type ParseTextSync = (text: string, options?: LoaderOptions) => any;
|
|
279
|
+
// type ParseInBatches = (
|
|
280
|
+
// iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
281
|
+
// options?: LoaderOptions,
|
|
282
|
+
// context?: LoaderContext
|
|
283
|
+
// ) => AsyncIterable<any>;
|
|
284
|
+
// type ParseFileInBatches = (
|
|
285
|
+
// file: Blob,
|
|
286
|
+
// options?: LoaderOptions,
|
|
287
|
+
// context?: LoaderContext
|
|
288
|
+
// ) => AsyncIterable<any>;
|
|
289
|
+
|
|
290
|
+
type Preload = (url: string, options?: PreloadOptions) => any;
|
|
291
|
+
|
|
292
|
+
/** Typescript helper to extract options type from a generic loader type */
|
|
293
|
+
export type LoaderOptionsType<T = Loader> = T extends Loader<any, any, infer Options>
|
|
294
|
+
? Options
|
|
295
|
+
: never;
|
|
296
|
+
/** Typescript helper to extract data type from a generic loader type */
|
|
297
|
+
export type LoaderReturnType<T = Loader> = T extends Loader<infer Return, any, any>
|
|
298
|
+
? Return
|
|
299
|
+
: never;
|
|
300
|
+
/** Typescript helper to extract batch type from a generic loader type */
|
|
301
|
+
export type LoaderBatchType<T = Loader> = T extends Loader<any, infer Batch, any> ? Batch : never;
|
|
302
|
+
|
|
303
|
+
// WRITERS
|
|
304
|
+
|
|
305
|
+
/** Options for writers */
|
|
306
|
+
export type WriterOptions = {
|
|
307
|
+
/** worker source. If is set will be used instead of loading worker from the Internet */
|
|
308
|
+
souce?: string | null;
|
|
309
|
+
/** writer-specific options */
|
|
310
|
+
[writerId: string]: any;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* A writer definition that can be used with `@loaders.gl/core` functions
|
|
315
|
+
*/
|
|
316
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
317
|
+
export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOptions> = {
|
|
318
|
+
name: string;
|
|
319
|
+
|
|
320
|
+
id: string;
|
|
321
|
+
module: string;
|
|
322
|
+
version: string;
|
|
323
|
+
worker?: string | boolean;
|
|
324
|
+
|
|
325
|
+
// TODO - are these are needed?
|
|
326
|
+
extensions?: string[];
|
|
327
|
+
mimeTypes?: string[];
|
|
328
|
+
binary?: boolean;
|
|
329
|
+
text?: boolean;
|
|
330
|
+
|
|
331
|
+
options: WriterOptionsT;
|
|
332
|
+
deprecatedOptions?: Record<string, string>;
|
|
333
|
+
|
|
334
|
+
// encodeText?: EncodeText;
|
|
335
|
+
// encode?: Encode;
|
|
336
|
+
encodeSync?: EncodeSync;
|
|
337
|
+
// encodeInBatches?: EncodeInBatches;
|
|
338
|
+
encodeURLtoURL?: EncodeURLtoURL;
|
|
339
|
+
|
|
340
|
+
encode?(data: DataT, options?: WriterOptionsT): Promise<ArrayBuffer>;
|
|
341
|
+
encodeText?(table: DataT, options?: WriterOptionsT): Promise<string> | string;
|
|
342
|
+
encodeInBatches?(data: AsyncIterable<any>, options?: WriterOptionsT): AsyncIterable<ArrayBuffer>;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// type Encode = (data: any, options?: WriterOptions) => Promise<ArrayBuffer>;
|
|
234
346
|
type EncodeSync = (data: any, options?: WriterOptions) => ArrayBuffer;
|
|
235
347
|
// TODO
|
|
236
|
-
type EncodeText = Function;
|
|
237
|
-
type EncodeInBatches = Function;
|
|
348
|
+
// type EncodeText = Function;
|
|
349
|
+
// type EncodeInBatches = Function;
|
|
238
350
|
type EncodeURLtoURL = (
|
|
239
351
|
inputUrl: string,
|
|
240
352
|
outputUrl: string,
|
|
241
353
|
options?: WriterOptions
|
|
242
354
|
) => Promise<string>;
|
|
243
|
-
|
|
355
|
+
|
|
356
|
+
/** Typescript helper to extract the writer options type from a generic writer type */
|
|
357
|
+
export type WriterOptionsType<T = Writer> = T extends Writer<unknown, unknown, infer Options>
|
|
358
|
+
? Options
|
|
359
|
+
: never;
|
|
360
|
+
|
|
361
|
+
// MISC TYPES
|
|
244
362
|
|
|
245
363
|
export type TransformBatches = (
|
|
246
364
|
asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>
|
|
@@ -295,7 +413,7 @@ export interface IFileSystem {
|
|
|
295
413
|
|
|
296
414
|
type ReadOptions = {buffer?: ArrayBuffer; offset?: number; length?: number; position?: number};
|
|
297
415
|
export interface IRandomAccessReadFileSystem extends IFileSystem {
|
|
298
|
-
open(path: string, flags, mode
|
|
416
|
+
open(path: string, flags: string | number, mode?: any): Promise<any>;
|
|
299
417
|
close(fd: any): Promise<void>;
|
|
300
418
|
fstat(fd: any): Promise<object>;
|
|
301
419
|
read(fd: any, options?: ReadOptions): Promise<{bytesRead: number; buffer: Buffer}>;
|