@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,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const stats_1 = require("@probe.gl/stats");
4
+ const STAT_QUEUED_REQUESTS = 'Queued Requests';
5
+ const STAT_ACTIVE_REQUESTS = 'Active Requests';
6
+ const STAT_CANCELLED_REQUESTS = 'Cancelled Requests';
7
+ const STAT_QUEUED_REQUESTS_EVER = 'Queued Requests Ever';
8
+ const STAT_ACTIVE_REQUESTS_EVER = 'Active Requests Ever';
9
+ const DEFAULT_PROPS = {
10
+ id: 'request-scheduler',
11
+ // Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing
12
+ throttleRequests: true,
13
+ // The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit.
14
+ maxRequests: 6
15
+ };
16
+ /**
17
+ * Used to issue a request, without having them "deeply queued" by the browser.
18
+ * @todo - Track requests globally, across multiple servers
19
+ */
20
+ class RequestScheduler {
21
+ constructor(props = {}) {
22
+ this.activeRequestCount = 0;
23
+ /** Tracks the number of active requests and prioritizes/cancels queued requests. */
24
+ this.requestQueue = [];
25
+ this.requestMap = new Map();
26
+ this.deferredUpdate = null;
27
+ this.props = { ...DEFAULT_PROPS, ...props };
28
+ // Returns the statistics used by the request scheduler.
29
+ this.stats = new stats_1.Stats({ id: this.props.id });
30
+ this.stats.get(STAT_QUEUED_REQUESTS);
31
+ this.stats.get(STAT_ACTIVE_REQUESTS);
32
+ this.stats.get(STAT_CANCELLED_REQUESTS);
33
+ this.stats.get(STAT_QUEUED_REQUESTS_EVER);
34
+ this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
35
+ }
36
+ /**
37
+ * Called by an application that wants to issue a request, without having it deeply queued by the browser
38
+ *
39
+ * When the returned promise resolved, it is OK for the application to issue a request.
40
+ * The promise resolves to an object that contains a `done` method.
41
+ * When the application's request has completed (or failed), the application must call the `done` function
42
+ *
43
+ * @param handle
44
+ * @param getPriority will be called when request "slots" open up,
45
+ * allowing the caller to update priority or cancel the request
46
+ * Highest priority executes first, priority < 0 cancels the request
47
+ * @returns a promise
48
+ * - resolves to a object (with a `done` field) when the request can be issued without queueing,
49
+ * - resolves to `null` if the request has been cancelled (by the callback return < 0).
50
+ * In this case the application should not issue the request
51
+ */
52
+ scheduleRequest(handle, getPriority = () => 0) {
53
+ // Allows throttling to be disabled
54
+ if (!this.props.throttleRequests) {
55
+ return Promise.resolve({ done: () => { } });
56
+ }
57
+ // dedupe
58
+ if (this.requestMap.has(handle)) {
59
+ return this.requestMap.get(handle);
60
+ }
61
+ const request = { handle, priority: 0, getPriority };
62
+ const promise = new Promise((resolve) => {
63
+ // @ts-ignore
64
+ request.resolve = resolve;
65
+ return request;
66
+ });
67
+ this.requestQueue.push(request);
68
+ this.requestMap.set(handle, promise);
69
+ this._issueNewRequests();
70
+ return promise;
71
+ }
72
+ // PRIVATE
73
+ _issueRequest(request) {
74
+ const { handle, resolve } = request;
75
+ let isDone = false;
76
+ const done = () => {
77
+ // can only be called once
78
+ if (!isDone) {
79
+ isDone = true;
80
+ // Stop tracking a request - it has completed, failed, cancelled etc
81
+ this.requestMap.delete(handle);
82
+ this.activeRequestCount--;
83
+ // A slot just freed up, see if any queued requests are waiting
84
+ this._issueNewRequests();
85
+ }
86
+ };
87
+ // Track this request
88
+ this.activeRequestCount++;
89
+ return resolve ? resolve({ done }) : Promise.resolve({ done });
90
+ }
91
+ /** We check requests asynchronously, to prevent multiple updates */
92
+ _issueNewRequests() {
93
+ if (!this.deferredUpdate) {
94
+ this.deferredUpdate = setTimeout(() => this._issueNewRequestsAsync(), 0);
95
+ }
96
+ }
97
+ /** Refresh all requests */
98
+ _issueNewRequestsAsync() {
99
+ // TODO - shouldn't we clear the timeout?
100
+ this.deferredUpdate = null;
101
+ const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
102
+ if (freeSlots === 0) {
103
+ return;
104
+ }
105
+ this._updateAllRequests();
106
+ // Resolve pending promises for the top-priority requests
107
+ for (let i = 0; i < freeSlots; ++i) {
108
+ const request = this.requestQueue.shift();
109
+ if (request) {
110
+ this._issueRequest(request); // eslint-disable-line @typescript-eslint/no-floating-promises
111
+ }
112
+ }
113
+ // Uncomment to debug
114
+ // console.log(`${freeSlots} free slots, ${this.requestQueue.length} queued requests`);
115
+ }
116
+ /** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
117
+ _updateAllRequests() {
118
+ const requestQueue = this.requestQueue;
119
+ for (let i = 0; i < requestQueue.length; ++i) {
120
+ const request = requestQueue[i];
121
+ if (!this._updateRequest(request)) {
122
+ // Remove the element and make sure to adjust the counter to account for shortened array
123
+ requestQueue.splice(i, 1);
124
+ this.requestMap.delete(request.handle);
125
+ i--;
126
+ }
127
+ }
128
+ // Sort the remaining requests based on priority
129
+ requestQueue.sort((a, b) => a.priority - b.priority);
130
+ }
131
+ /** Update a single request by calling the callback */
132
+ _updateRequest(request) {
133
+ request.priority = request.getPriority(request.handle); // eslint-disable-line callback-return
134
+ // by returning a negative priority, the callback cancels the request
135
+ if (request.priority < 0) {
136
+ request.resolve(null);
137
+ return false;
138
+ }
139
+ return true;
140
+ }
141
+ }
142
+ exports.default = RequestScheduler;
@@ -0,0 +1,7 @@
1
+ import type { LoaderWithParser } from '../../types';
2
+ /**
3
+ * Set up a WebWorkerGlobalScope to talk with the main thread
4
+ * @param loader
5
+ */
6
+ export declare function createLoaderWorker(loader: LoaderWithParser): void;
7
+ //# sourceMappingURL=create-loader-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-loader-worker.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-loader-utils/create-loader-worker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAMlD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,QA+B1D"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLoaderWorker = void 0;
4
+ const worker_utils_1 = require("@loaders.gl/worker-utils");
5
+ // import {validateLoaderVersion} from './validate-loader-version';
6
+ let requestId = 0;
7
+ /**
8
+ * Set up a WebWorkerGlobalScope to talk with the main thread
9
+ * @param loader
10
+ */
11
+ function createLoaderWorker(loader) {
12
+ // Check that we are actually in a worker thread
13
+ if (typeof self === 'undefined') {
14
+ return;
15
+ }
16
+ worker_utils_1.WorkerBody.onmessage = async (type, payload) => {
17
+ switch (type) {
18
+ case 'process':
19
+ try {
20
+ // validateLoaderVersion(loader, data.source.split('@')[1]);
21
+ const { input, options = {} } = payload;
22
+ const result = await parseData({
23
+ loader,
24
+ arrayBuffer: input,
25
+ options,
26
+ context: {
27
+ parse: parseOnMainThread
28
+ }
29
+ });
30
+ worker_utils_1.WorkerBody.postMessage('done', { result });
31
+ }
32
+ catch (error) {
33
+ const message = error instanceof Error ? error.message : '';
34
+ worker_utils_1.WorkerBody.postMessage('error', { error: message });
35
+ }
36
+ break;
37
+ default:
38
+ }
39
+ };
40
+ }
41
+ exports.createLoaderWorker = createLoaderWorker;
42
+ function parseOnMainThread(arrayBuffer, options) {
43
+ return new Promise((resolve, reject) => {
44
+ const id = requestId++;
45
+ /**
46
+ */
47
+ const onMessage = (type, payload) => {
48
+ if (payload.id !== id) {
49
+ // not ours
50
+ return;
51
+ }
52
+ switch (type) {
53
+ case 'done':
54
+ worker_utils_1.WorkerBody.removeEventListener(onMessage);
55
+ resolve(payload.result);
56
+ break;
57
+ case 'error':
58
+ worker_utils_1.WorkerBody.removeEventListener(onMessage);
59
+ reject(payload.error);
60
+ break;
61
+ default:
62
+ // ignore
63
+ }
64
+ };
65
+ worker_utils_1.WorkerBody.addEventListener(onMessage);
66
+ // Ask the main thread to decode data
67
+ const payload = { id, input: arrayBuffer, options };
68
+ worker_utils_1.WorkerBody.postMessage('process', payload);
69
+ });
70
+ }
71
+ // TODO - Support byteOffset and byteLength (enabling parsing of embedded binaries without copies)
72
+ // TODO - Why not support async loader.parse* funcs here?
73
+ // TODO - Why not reuse a common function instead of reimplementing loader.parse* selection logic? Keeping loader small?
74
+ // TODO - Lack of appropriate parser functions can be detected when we create worker, no need to wait until parse
75
+ async function parseData({ loader, arrayBuffer, options, context }) {
76
+ let data;
77
+ let parser;
78
+ if (loader.parseSync || loader.parse) {
79
+ data = arrayBuffer;
80
+ parser = loader.parseSync || loader.parse;
81
+ }
82
+ else if (loader.parseTextSync) {
83
+ const textDecoder = new TextDecoder();
84
+ data = textDecoder.decode(arrayBuffer);
85
+ parser = loader.parseTextSync;
86
+ }
87
+ else {
88
+ throw new Error(`Could not load data with ${loader.name} loader`);
89
+ }
90
+ // TODO - proper merge in of loader options...
91
+ options = {
92
+ ...options,
93
+ modules: (loader && loader.options && loader.options.modules) || {},
94
+ worker: false
95
+ };
96
+ return await parser(data, { ...options }, context, loader);
97
+ }
@@ -0,0 +1,15 @@
1
+ import type { Loader, LoaderOptions, LoaderContext } from '../../types';
2
+ /**
3
+ * Determines if a loader can parse with worker
4
+ * @param loader
5
+ * @param options
6
+ */
7
+ export declare function canParseWithWorker(loader: Loader, options?: LoaderOptions): boolean | "" | undefined;
8
+ /**
9
+ * this function expects that the worker function sends certain messages,
10
+ * this can be automated if the worker is wrapper by a call to createLoaderWorker in @loaders.gl/loader-utils.
11
+ */
12
+ export declare function parseWithWorker(loader: Loader, data: any, options?: LoaderOptions, context?: LoaderContext, parseOnMainThread?: (arrayBuffer: ArrayBuffer, options: {
13
+ [key: string]: any;
14
+ }) => Promise<void>): Promise<any>;
15
+ //# sourceMappingURL=parse-with-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-with-worker.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-loader-utils/parse-with-worker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAGtE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,4BAMzE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EACT,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,EACvB,iBAAiB,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,gBA2B/F"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseWithWorker = exports.canParseWithWorker = void 0;
4
+ const worker_utils_1 = require("@loaders.gl/worker-utils");
5
+ /**
6
+ * Determines if a loader can parse with worker
7
+ * @param loader
8
+ * @param options
9
+ */
10
+ function canParseWithWorker(loader, options) {
11
+ if (!worker_utils_1.WorkerFarm.isSupported()) {
12
+ return false;
13
+ }
14
+ return loader.worker && options?.worker;
15
+ }
16
+ exports.canParseWithWorker = canParseWithWorker;
17
+ /**
18
+ * this function expects that the worker function sends certain messages,
19
+ * this can be automated if the worker is wrapper by a call to createLoaderWorker in @loaders.gl/loader-utils.
20
+ */
21
+ async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
22
+ const name = loader.id; // TODO
23
+ const url = (0, worker_utils_1.getWorkerURL)(loader, options);
24
+ const workerFarm = worker_utils_1.WorkerFarm.getWorkerFarm(options);
25
+ const workerPool = workerFarm.getWorkerPool({ name, url });
26
+ // options.log object contains functions which cannot be transferred
27
+ // TODO - decide how to handle logging on workers
28
+ options = JSON.parse(JSON.stringify(options));
29
+ const job = await workerPool.startJob('process-on-worker',
30
+ // @ts-expect-error
31
+ onMessage.bind(null, parseOnMainThread) // eslint-disable-line @typescript-eslint/no-misused-promises
32
+ );
33
+ job.postMessage('process', {
34
+ // @ts-ignore
35
+ input: data,
36
+ options
37
+ });
38
+ const result = await job.result;
39
+ // TODO - what is going on here?
40
+ return await result.result;
41
+ }
42
+ exports.parseWithWorker = parseWithWorker;
43
+ /**
44
+ * Handle worker's responses to the main thread
45
+ * @param job
46
+ * @param type
47
+ * @param payload
48
+ */
49
+ async function onMessage(parseOnMainThread, job, type, payload) {
50
+ switch (type) {
51
+ case 'done':
52
+ job.done(payload);
53
+ break;
54
+ case 'error':
55
+ job.error(new Error(payload.error));
56
+ break;
57
+ case 'process':
58
+ // Worker is asking for main thread to parseO
59
+ const { id, input, options } = payload;
60
+ try {
61
+ const result = await parseOnMainThread(input, options);
62
+ job.postMessage('done', { id, result });
63
+ }
64
+ catch (error) {
65
+ const message = error instanceof Error ? error.message : 'unknown error';
66
+ job.postMessage('error', { id, error: message });
67
+ }
68
+ break;
69
+ default:
70
+ // eslint-disable-next-line
71
+ console.warn(`parse-with-worker unknown message ${type}`);
72
+ }
73
+ }
@@ -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,G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I,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 ADDED
@@ -0,0 +1,3 @@
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":""}
@@ -0,0 +1,5 @@
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.4",
3
+ "version": "3.1.0-beta.3",
4
4
  "description": "Framework-independent loaders for 3D graphics formats",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -17,7 +17,7 @@
17
17
  "mesh",
18
18
  "point cloud"
19
19
  ],
20
- "types": "src/index.ts",
20
+ "types": "dist/index.d.ts",
21
21
  "main": "dist/es5/index.js",
22
22
  "module": "dist/esm/index.js",
23
23
  "sideEffects": false,
@@ -42,14 +42,11 @@
42
42
  "fs": false,
43
43
  "util": false
44
44
  },
45
- "scripts": {
46
- "pre-build-disabled": "npm run build-bundle",
47
- "build-bundle": "webpack --config ../../scripts/webpack/bundle.js"
48
- },
45
+ "scripts": {},
49
46
  "dependencies": {
50
47
  "@babel/runtime": "^7.3.1",
51
- "@loaders.gl/worker-utils": "3.1.0-alpha.4",
48
+ "@loaders.gl/worker-utils": "3.1.0-beta.3",
52
49
  "@probe.gl/stats": "^3.4.0"
53
50
  },
54
- "gitHead": "e309784af37ef9f3640c7733c7851124c72e1fa3"
51
+ "gitHead": "3537c382b3ea4e092b24b6f94c3edee72076039c"
55
52
  }
@@ -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':