@polarfront-lab/ionian 1.1.0 → 1.2.0
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/ionian.iife.js +1 -6
- package/dist/ionian.iife.js.map +1 -1
- package/dist/ionian.js +160 -2012
- package/dist/ionian.js.map +1 -1
- package/package.json +1 -3
package/dist/ionian.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import * as THREE from "three";
|
|
5
|
-
import { Mesh, OrthographicCamera, BufferGeometry, Float32BufferAttribute, NearestFilter, ShaderMaterial, WebGLRenderTarget, FloatType, RGBAFormat, DataTexture, ClampToEdgeWrapping } from "three";
|
|
5
|
+
import { Triangle, Vector3, Vector2, Mesh, OrthographicCamera, BufferGeometry, Float32BufferAttribute, NearestFilter, ShaderMaterial, WebGLRenderTarget, FloatType, RGBAFormat, DataTexture, ClampToEdgeWrapping } from "three";
|
|
6
6
|
import { GLTFLoader, DRACOLoader } from "three-stdlib";
|
|
7
7
|
const linear = (n) => n;
|
|
8
8
|
function mitt(n) {
|
|
@@ -44,2008 +44,6 @@ class DefaultEventEmitter {
|
|
|
44
44
|
this.emitter.all.clear();
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
48
|
-
* @license
|
|
49
|
-
* Copyright 2019 Google LLC
|
|
50
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
51
|
-
*/
|
|
52
|
-
const proxyMarker = Symbol("Comlink.proxy");
|
|
53
|
-
const createEndpoint = Symbol("Comlink.endpoint");
|
|
54
|
-
const releaseProxy = Symbol("Comlink.releaseProxy");
|
|
55
|
-
const finalizer = Symbol("Comlink.finalizer");
|
|
56
|
-
const throwMarker = Symbol("Comlink.thrown");
|
|
57
|
-
const isObject = (val) => typeof val === "object" && val !== null || typeof val === "function";
|
|
58
|
-
const proxyTransferHandler = {
|
|
59
|
-
canHandle: (val) => isObject(val) && val[proxyMarker],
|
|
60
|
-
serialize(obj) {
|
|
61
|
-
const { port1, port2 } = new MessageChannel();
|
|
62
|
-
expose(obj, port1);
|
|
63
|
-
return [port2, [port2]];
|
|
64
|
-
},
|
|
65
|
-
deserialize(port) {
|
|
66
|
-
port.start();
|
|
67
|
-
return wrap(port);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const throwTransferHandler = {
|
|
71
|
-
canHandle: (value) => isObject(value) && throwMarker in value,
|
|
72
|
-
serialize({ value }) {
|
|
73
|
-
let serialized;
|
|
74
|
-
if (value instanceof Error) {
|
|
75
|
-
serialized = {
|
|
76
|
-
isError: true,
|
|
77
|
-
value: {
|
|
78
|
-
message: value.message,
|
|
79
|
-
name: value.name,
|
|
80
|
-
stack: value.stack
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
} else {
|
|
84
|
-
serialized = { isError: false, value };
|
|
85
|
-
}
|
|
86
|
-
return [serialized, []];
|
|
87
|
-
},
|
|
88
|
-
deserialize(serialized) {
|
|
89
|
-
if (serialized.isError) {
|
|
90
|
-
throw Object.assign(new Error(serialized.value.message), serialized.value);
|
|
91
|
-
}
|
|
92
|
-
throw serialized.value;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const transferHandlers = /* @__PURE__ */ new Map([
|
|
96
|
-
["proxy", proxyTransferHandler],
|
|
97
|
-
["throw", throwTransferHandler]
|
|
98
|
-
]);
|
|
99
|
-
function isAllowedOrigin(allowedOrigins, origin) {
|
|
100
|
-
for (const allowedOrigin of allowedOrigins) {
|
|
101
|
-
if (origin === allowedOrigin || allowedOrigin === "*") {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
function expose(obj, ep = globalThis, allowedOrigins = ["*"]) {
|
|
111
|
-
ep.addEventListener("message", function callback(ev) {
|
|
112
|
-
if (!ev || !ev.data) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (!isAllowedOrigin(allowedOrigins, ev.origin)) {
|
|
116
|
-
console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const { id, type, path } = Object.assign({ path: [] }, ev.data);
|
|
120
|
-
const argumentList = (ev.data.argumentList || []).map(fromWireValue);
|
|
121
|
-
let returnValue;
|
|
122
|
-
try {
|
|
123
|
-
const parent = path.slice(0, -1).reduce((obj2, prop) => obj2[prop], obj);
|
|
124
|
-
const rawValue = path.reduce((obj2, prop) => obj2[prop], obj);
|
|
125
|
-
switch (type) {
|
|
126
|
-
case "GET":
|
|
127
|
-
{
|
|
128
|
-
returnValue = rawValue;
|
|
129
|
-
}
|
|
130
|
-
break;
|
|
131
|
-
case "SET":
|
|
132
|
-
{
|
|
133
|
-
parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);
|
|
134
|
-
returnValue = true;
|
|
135
|
-
}
|
|
136
|
-
break;
|
|
137
|
-
case "APPLY":
|
|
138
|
-
{
|
|
139
|
-
returnValue = rawValue.apply(parent, argumentList);
|
|
140
|
-
}
|
|
141
|
-
break;
|
|
142
|
-
case "CONSTRUCT":
|
|
143
|
-
{
|
|
144
|
-
const value = new rawValue(...argumentList);
|
|
145
|
-
returnValue = proxy(value);
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
case "ENDPOINT":
|
|
149
|
-
{
|
|
150
|
-
const { port1, port2 } = new MessageChannel();
|
|
151
|
-
expose(obj, port2);
|
|
152
|
-
returnValue = transfer(port1, [port1]);
|
|
153
|
-
}
|
|
154
|
-
break;
|
|
155
|
-
case "RELEASE":
|
|
156
|
-
{
|
|
157
|
-
returnValue = void 0;
|
|
158
|
-
}
|
|
159
|
-
break;
|
|
160
|
-
default:
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
} catch (value) {
|
|
164
|
-
returnValue = { value, [throwMarker]: 0 };
|
|
165
|
-
}
|
|
166
|
-
Promise.resolve(returnValue).catch((value) => {
|
|
167
|
-
return { value, [throwMarker]: 0 };
|
|
168
|
-
}).then((returnValue2) => {
|
|
169
|
-
const [wireValue, transferables] = toWireValue(returnValue2);
|
|
170
|
-
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
|
|
171
|
-
if (type === "RELEASE") {
|
|
172
|
-
ep.removeEventListener("message", callback);
|
|
173
|
-
closeEndPoint(ep);
|
|
174
|
-
if (finalizer in obj && typeof obj[finalizer] === "function") {
|
|
175
|
-
obj[finalizer]();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}).catch((error) => {
|
|
179
|
-
const [wireValue, transferables] = toWireValue({
|
|
180
|
-
value: new TypeError("Unserializable return value"),
|
|
181
|
-
[throwMarker]: 0
|
|
182
|
-
});
|
|
183
|
-
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
if (ep.start) {
|
|
187
|
-
ep.start();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
function isMessagePort(endpoint) {
|
|
191
|
-
return endpoint.constructor.name === "MessagePort";
|
|
192
|
-
}
|
|
193
|
-
function closeEndPoint(endpoint) {
|
|
194
|
-
if (isMessagePort(endpoint))
|
|
195
|
-
endpoint.close();
|
|
196
|
-
}
|
|
197
|
-
function wrap(ep, target) {
|
|
198
|
-
const pendingListeners = /* @__PURE__ */ new Map();
|
|
199
|
-
ep.addEventListener("message", function handleMessage(ev) {
|
|
200
|
-
const { data } = ev;
|
|
201
|
-
if (!data || !data.id) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const resolver = pendingListeners.get(data.id);
|
|
205
|
-
if (!resolver) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
try {
|
|
209
|
-
resolver(data);
|
|
210
|
-
} finally {
|
|
211
|
-
pendingListeners.delete(data.id);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
return createProxy(ep, pendingListeners, [], target);
|
|
215
|
-
}
|
|
216
|
-
function throwIfProxyReleased(isReleased) {
|
|
217
|
-
if (isReleased) {
|
|
218
|
-
throw new Error("Proxy has been released and is not useable");
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
function releaseEndpoint(ep) {
|
|
222
|
-
return requestResponseMessage(ep, /* @__PURE__ */ new Map(), {
|
|
223
|
-
type: "RELEASE"
|
|
224
|
-
}).then(() => {
|
|
225
|
-
closeEndPoint(ep);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
const proxyCounter = /* @__PURE__ */ new WeakMap();
|
|
229
|
-
const proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((ep) => {
|
|
230
|
-
const newCount = (proxyCounter.get(ep) || 0) - 1;
|
|
231
|
-
proxyCounter.set(ep, newCount);
|
|
232
|
-
if (newCount === 0) {
|
|
233
|
-
releaseEndpoint(ep);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
function registerProxy(proxy2, ep) {
|
|
237
|
-
const newCount = (proxyCounter.get(ep) || 0) + 1;
|
|
238
|
-
proxyCounter.set(ep, newCount);
|
|
239
|
-
if (proxyFinalizers) {
|
|
240
|
-
proxyFinalizers.register(proxy2, ep, proxy2);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
function unregisterProxy(proxy2) {
|
|
244
|
-
if (proxyFinalizers) {
|
|
245
|
-
proxyFinalizers.unregister(proxy2);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function createProxy(ep, pendingListeners, path = [], target = function() {
|
|
249
|
-
}) {
|
|
250
|
-
let isProxyReleased = false;
|
|
251
|
-
const proxy2 = new Proxy(target, {
|
|
252
|
-
get(_target, prop) {
|
|
253
|
-
throwIfProxyReleased(isProxyReleased);
|
|
254
|
-
if (prop === releaseProxy) {
|
|
255
|
-
return () => {
|
|
256
|
-
unregisterProxy(proxy2);
|
|
257
|
-
releaseEndpoint(ep);
|
|
258
|
-
pendingListeners.clear();
|
|
259
|
-
isProxyReleased = true;
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
if (prop === "then") {
|
|
263
|
-
if (path.length === 0) {
|
|
264
|
-
return { then: () => proxy2 };
|
|
265
|
-
}
|
|
266
|
-
const r = requestResponseMessage(ep, pendingListeners, {
|
|
267
|
-
type: "GET",
|
|
268
|
-
path: path.map((p) => p.toString())
|
|
269
|
-
}).then(fromWireValue);
|
|
270
|
-
return r.then.bind(r);
|
|
271
|
-
}
|
|
272
|
-
return createProxy(ep, pendingListeners, [...path, prop]);
|
|
273
|
-
},
|
|
274
|
-
set(_target, prop, rawValue) {
|
|
275
|
-
throwIfProxyReleased(isProxyReleased);
|
|
276
|
-
const [value, transferables] = toWireValue(rawValue);
|
|
277
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
278
|
-
type: "SET",
|
|
279
|
-
path: [...path, prop].map((p) => p.toString()),
|
|
280
|
-
value
|
|
281
|
-
}, transferables).then(fromWireValue);
|
|
282
|
-
},
|
|
283
|
-
apply(_target, _thisArg, rawArgumentList) {
|
|
284
|
-
throwIfProxyReleased(isProxyReleased);
|
|
285
|
-
const last = path[path.length - 1];
|
|
286
|
-
if (last === createEndpoint) {
|
|
287
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
288
|
-
type: "ENDPOINT"
|
|
289
|
-
}).then(fromWireValue);
|
|
290
|
-
}
|
|
291
|
-
if (last === "bind") {
|
|
292
|
-
return createProxy(ep, pendingListeners, path.slice(0, -1));
|
|
293
|
-
}
|
|
294
|
-
const [argumentList, transferables] = processArguments(rawArgumentList);
|
|
295
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
296
|
-
type: "APPLY",
|
|
297
|
-
path: path.map((p) => p.toString()),
|
|
298
|
-
argumentList
|
|
299
|
-
}, transferables).then(fromWireValue);
|
|
300
|
-
},
|
|
301
|
-
construct(_target, rawArgumentList) {
|
|
302
|
-
throwIfProxyReleased(isProxyReleased);
|
|
303
|
-
const [argumentList, transferables] = processArguments(rawArgumentList);
|
|
304
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
305
|
-
type: "CONSTRUCT",
|
|
306
|
-
path: path.map((p) => p.toString()),
|
|
307
|
-
argumentList
|
|
308
|
-
}, transferables).then(fromWireValue);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
registerProxy(proxy2, ep);
|
|
312
|
-
return proxy2;
|
|
313
|
-
}
|
|
314
|
-
function myFlat(arr) {
|
|
315
|
-
return Array.prototype.concat.apply([], arr);
|
|
316
|
-
}
|
|
317
|
-
function processArguments(argumentList) {
|
|
318
|
-
const processed = argumentList.map(toWireValue);
|
|
319
|
-
return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];
|
|
320
|
-
}
|
|
321
|
-
const transferCache = /* @__PURE__ */ new WeakMap();
|
|
322
|
-
function transfer(obj, transfers) {
|
|
323
|
-
transferCache.set(obj, transfers);
|
|
324
|
-
return obj;
|
|
325
|
-
}
|
|
326
|
-
function proxy(obj) {
|
|
327
|
-
return Object.assign(obj, { [proxyMarker]: true });
|
|
328
|
-
}
|
|
329
|
-
function toWireValue(value) {
|
|
330
|
-
for (const [name, handler] of transferHandlers) {
|
|
331
|
-
if (handler.canHandle(value)) {
|
|
332
|
-
const [serializedValue, transferables] = handler.serialize(value);
|
|
333
|
-
return [
|
|
334
|
-
{
|
|
335
|
-
type: "HANDLER",
|
|
336
|
-
name,
|
|
337
|
-
value: serializedValue
|
|
338
|
-
},
|
|
339
|
-
transferables
|
|
340
|
-
];
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return [
|
|
344
|
-
{
|
|
345
|
-
type: "RAW",
|
|
346
|
-
value
|
|
347
|
-
},
|
|
348
|
-
transferCache.get(value) || []
|
|
349
|
-
];
|
|
350
|
-
}
|
|
351
|
-
function fromWireValue(value) {
|
|
352
|
-
switch (value.type) {
|
|
353
|
-
case "HANDLER":
|
|
354
|
-
return transferHandlers.get(value.name).deserialize(value.value);
|
|
355
|
-
case "RAW":
|
|
356
|
-
return value.value;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
function requestResponseMessage(ep, pendingListeners, msg, transfers) {
|
|
360
|
-
return new Promise((resolve) => {
|
|
361
|
-
const id = generateUUID();
|
|
362
|
-
pendingListeners.set(id, resolve);
|
|
363
|
-
if (ep.start) {
|
|
364
|
-
ep.start();
|
|
365
|
-
}
|
|
366
|
-
ep.postMessage(Object.assign({ id }, msg), transfers);
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
function generateUUID() {
|
|
370
|
-
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
371
|
-
}
|
|
372
|
-
function getDefaultExportFromCjs(x) {
|
|
373
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
374
|
-
}
|
|
375
|
-
var events = { exports: {} };
|
|
376
|
-
var hasRequiredEvents;
|
|
377
|
-
function requireEvents() {
|
|
378
|
-
if (hasRequiredEvents) return events.exports;
|
|
379
|
-
hasRequiredEvents = 1;
|
|
380
|
-
var R = typeof Reflect === "object" ? Reflect : null;
|
|
381
|
-
var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) {
|
|
382
|
-
return Function.prototype.apply.call(target, receiver, args);
|
|
383
|
-
};
|
|
384
|
-
var ReflectOwnKeys;
|
|
385
|
-
if (R && typeof R.ownKeys === "function") {
|
|
386
|
-
ReflectOwnKeys = R.ownKeys;
|
|
387
|
-
} else if (Object.getOwnPropertySymbols) {
|
|
388
|
-
ReflectOwnKeys = function ReflectOwnKeys2(target) {
|
|
389
|
-
return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target));
|
|
390
|
-
};
|
|
391
|
-
} else {
|
|
392
|
-
ReflectOwnKeys = function ReflectOwnKeys2(target) {
|
|
393
|
-
return Object.getOwnPropertyNames(target);
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
function ProcessEmitWarning(warning) {
|
|
397
|
-
if (console && console.warn) console.warn(warning);
|
|
398
|
-
}
|
|
399
|
-
var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) {
|
|
400
|
-
return value !== value;
|
|
401
|
-
};
|
|
402
|
-
function EventEmitter() {
|
|
403
|
-
EventEmitter.init.call(this);
|
|
404
|
-
}
|
|
405
|
-
events.exports = EventEmitter;
|
|
406
|
-
events.exports.once = once;
|
|
407
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
408
|
-
EventEmitter.prototype._events = void 0;
|
|
409
|
-
EventEmitter.prototype._eventsCount = 0;
|
|
410
|
-
EventEmitter.prototype._maxListeners = void 0;
|
|
411
|
-
var defaultMaxListeners = 10;
|
|
412
|
-
function checkListener(listener) {
|
|
413
|
-
if (typeof listener !== "function") {
|
|
414
|
-
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
Object.defineProperty(EventEmitter, "defaultMaxListeners", {
|
|
418
|
-
enumerable: true,
|
|
419
|
-
get: function() {
|
|
420
|
-
return defaultMaxListeners;
|
|
421
|
-
},
|
|
422
|
-
set: function(arg) {
|
|
423
|
-
if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) {
|
|
424
|
-
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + ".");
|
|
425
|
-
}
|
|
426
|
-
defaultMaxListeners = arg;
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
EventEmitter.init = function() {
|
|
430
|
-
if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) {
|
|
431
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
432
|
-
this._eventsCount = 0;
|
|
433
|
-
}
|
|
434
|
-
this._maxListeners = this._maxListeners || void 0;
|
|
435
|
-
};
|
|
436
|
-
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
|
437
|
-
if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) {
|
|
438
|
-
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + ".");
|
|
439
|
-
}
|
|
440
|
-
this._maxListeners = n;
|
|
441
|
-
return this;
|
|
442
|
-
};
|
|
443
|
-
function _getMaxListeners(that) {
|
|
444
|
-
if (that._maxListeners === void 0)
|
|
445
|
-
return EventEmitter.defaultMaxListeners;
|
|
446
|
-
return that._maxListeners;
|
|
447
|
-
}
|
|
448
|
-
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
|
449
|
-
return _getMaxListeners(this);
|
|
450
|
-
};
|
|
451
|
-
EventEmitter.prototype.emit = function emit(type) {
|
|
452
|
-
var args = [];
|
|
453
|
-
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
|
454
|
-
var doError = type === "error";
|
|
455
|
-
var events2 = this._events;
|
|
456
|
-
if (events2 !== void 0)
|
|
457
|
-
doError = doError && events2.error === void 0;
|
|
458
|
-
else if (!doError)
|
|
459
|
-
return false;
|
|
460
|
-
if (doError) {
|
|
461
|
-
var er;
|
|
462
|
-
if (args.length > 0)
|
|
463
|
-
er = args[0];
|
|
464
|
-
if (er instanceof Error) {
|
|
465
|
-
throw er;
|
|
466
|
-
}
|
|
467
|
-
var err = new Error("Unhandled error." + (er ? " (" + er.message + ")" : ""));
|
|
468
|
-
err.context = er;
|
|
469
|
-
throw err;
|
|
470
|
-
}
|
|
471
|
-
var handler = events2[type];
|
|
472
|
-
if (handler === void 0)
|
|
473
|
-
return false;
|
|
474
|
-
if (typeof handler === "function") {
|
|
475
|
-
ReflectApply(handler, this, args);
|
|
476
|
-
} else {
|
|
477
|
-
var len = handler.length;
|
|
478
|
-
var listeners = arrayClone(handler, len);
|
|
479
|
-
for (var i = 0; i < len; ++i)
|
|
480
|
-
ReflectApply(listeners[i], this, args);
|
|
481
|
-
}
|
|
482
|
-
return true;
|
|
483
|
-
};
|
|
484
|
-
function _addListener(target, type, listener, prepend) {
|
|
485
|
-
var m;
|
|
486
|
-
var events2;
|
|
487
|
-
var existing;
|
|
488
|
-
checkListener(listener);
|
|
489
|
-
events2 = target._events;
|
|
490
|
-
if (events2 === void 0) {
|
|
491
|
-
events2 = target._events = /* @__PURE__ */ Object.create(null);
|
|
492
|
-
target._eventsCount = 0;
|
|
493
|
-
} else {
|
|
494
|
-
if (events2.newListener !== void 0) {
|
|
495
|
-
target.emit(
|
|
496
|
-
"newListener",
|
|
497
|
-
type,
|
|
498
|
-
listener.listener ? listener.listener : listener
|
|
499
|
-
);
|
|
500
|
-
events2 = target._events;
|
|
501
|
-
}
|
|
502
|
-
existing = events2[type];
|
|
503
|
-
}
|
|
504
|
-
if (existing === void 0) {
|
|
505
|
-
existing = events2[type] = listener;
|
|
506
|
-
++target._eventsCount;
|
|
507
|
-
} else {
|
|
508
|
-
if (typeof existing === "function") {
|
|
509
|
-
existing = events2[type] = prepend ? [listener, existing] : [existing, listener];
|
|
510
|
-
} else if (prepend) {
|
|
511
|
-
existing.unshift(listener);
|
|
512
|
-
} else {
|
|
513
|
-
existing.push(listener);
|
|
514
|
-
}
|
|
515
|
-
m = _getMaxListeners(target);
|
|
516
|
-
if (m > 0 && existing.length > m && !existing.warned) {
|
|
517
|
-
existing.warned = true;
|
|
518
|
-
var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit");
|
|
519
|
-
w.name = "MaxListenersExceededWarning";
|
|
520
|
-
w.emitter = target;
|
|
521
|
-
w.type = type;
|
|
522
|
-
w.count = existing.length;
|
|
523
|
-
ProcessEmitWarning(w);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
return target;
|
|
527
|
-
}
|
|
528
|
-
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
|
529
|
-
return _addListener(this, type, listener, false);
|
|
530
|
-
};
|
|
531
|
-
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
532
|
-
EventEmitter.prototype.prependListener = function prependListener(type, listener) {
|
|
533
|
-
return _addListener(this, type, listener, true);
|
|
534
|
-
};
|
|
535
|
-
function onceWrapper() {
|
|
536
|
-
if (!this.fired) {
|
|
537
|
-
this.target.removeListener(this.type, this.wrapFn);
|
|
538
|
-
this.fired = true;
|
|
539
|
-
if (arguments.length === 0)
|
|
540
|
-
return this.listener.call(this.target);
|
|
541
|
-
return this.listener.apply(this.target, arguments);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
function _onceWrap(target, type, listener) {
|
|
545
|
-
var state = { fired: false, wrapFn: void 0, target, type, listener };
|
|
546
|
-
var wrapped = onceWrapper.bind(state);
|
|
547
|
-
wrapped.listener = listener;
|
|
548
|
-
state.wrapFn = wrapped;
|
|
549
|
-
return wrapped;
|
|
550
|
-
}
|
|
551
|
-
EventEmitter.prototype.once = function once2(type, listener) {
|
|
552
|
-
checkListener(listener);
|
|
553
|
-
this.on(type, _onceWrap(this, type, listener));
|
|
554
|
-
return this;
|
|
555
|
-
};
|
|
556
|
-
EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
|
|
557
|
-
checkListener(listener);
|
|
558
|
-
this.prependListener(type, _onceWrap(this, type, listener));
|
|
559
|
-
return this;
|
|
560
|
-
};
|
|
561
|
-
EventEmitter.prototype.removeListener = function removeListener(type, listener) {
|
|
562
|
-
var list, events2, position, i, originalListener;
|
|
563
|
-
checkListener(listener);
|
|
564
|
-
events2 = this._events;
|
|
565
|
-
if (events2 === void 0)
|
|
566
|
-
return this;
|
|
567
|
-
list = events2[type];
|
|
568
|
-
if (list === void 0)
|
|
569
|
-
return this;
|
|
570
|
-
if (list === listener || list.listener === listener) {
|
|
571
|
-
if (--this._eventsCount === 0)
|
|
572
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
573
|
-
else {
|
|
574
|
-
delete events2[type];
|
|
575
|
-
if (events2.removeListener)
|
|
576
|
-
this.emit("removeListener", type, list.listener || listener);
|
|
577
|
-
}
|
|
578
|
-
} else if (typeof list !== "function") {
|
|
579
|
-
position = -1;
|
|
580
|
-
for (i = list.length - 1; i >= 0; i--) {
|
|
581
|
-
if (list[i] === listener || list[i].listener === listener) {
|
|
582
|
-
originalListener = list[i].listener;
|
|
583
|
-
position = i;
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
if (position < 0)
|
|
588
|
-
return this;
|
|
589
|
-
if (position === 0)
|
|
590
|
-
list.shift();
|
|
591
|
-
else {
|
|
592
|
-
spliceOne(list, position);
|
|
593
|
-
}
|
|
594
|
-
if (list.length === 1)
|
|
595
|
-
events2[type] = list[0];
|
|
596
|
-
if (events2.removeListener !== void 0)
|
|
597
|
-
this.emit("removeListener", type, originalListener || listener);
|
|
598
|
-
}
|
|
599
|
-
return this;
|
|
600
|
-
};
|
|
601
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
602
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) {
|
|
603
|
-
var listeners, events2, i;
|
|
604
|
-
events2 = this._events;
|
|
605
|
-
if (events2 === void 0)
|
|
606
|
-
return this;
|
|
607
|
-
if (events2.removeListener === void 0) {
|
|
608
|
-
if (arguments.length === 0) {
|
|
609
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
610
|
-
this._eventsCount = 0;
|
|
611
|
-
} else if (events2[type] !== void 0) {
|
|
612
|
-
if (--this._eventsCount === 0)
|
|
613
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
614
|
-
else
|
|
615
|
-
delete events2[type];
|
|
616
|
-
}
|
|
617
|
-
return this;
|
|
618
|
-
}
|
|
619
|
-
if (arguments.length === 0) {
|
|
620
|
-
var keys = Object.keys(events2);
|
|
621
|
-
var key;
|
|
622
|
-
for (i = 0; i < keys.length; ++i) {
|
|
623
|
-
key = keys[i];
|
|
624
|
-
if (key === "removeListener") continue;
|
|
625
|
-
this.removeAllListeners(key);
|
|
626
|
-
}
|
|
627
|
-
this.removeAllListeners("removeListener");
|
|
628
|
-
this._events = /* @__PURE__ */ Object.create(null);
|
|
629
|
-
this._eventsCount = 0;
|
|
630
|
-
return this;
|
|
631
|
-
}
|
|
632
|
-
listeners = events2[type];
|
|
633
|
-
if (typeof listeners === "function") {
|
|
634
|
-
this.removeListener(type, listeners);
|
|
635
|
-
} else if (listeners !== void 0) {
|
|
636
|
-
for (i = listeners.length - 1; i >= 0; i--) {
|
|
637
|
-
this.removeListener(type, listeners[i]);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
return this;
|
|
641
|
-
};
|
|
642
|
-
function _listeners(target, type, unwrap) {
|
|
643
|
-
var events2 = target._events;
|
|
644
|
-
if (events2 === void 0)
|
|
645
|
-
return [];
|
|
646
|
-
var evlistener = events2[type];
|
|
647
|
-
if (evlistener === void 0)
|
|
648
|
-
return [];
|
|
649
|
-
if (typeof evlistener === "function")
|
|
650
|
-
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
|
651
|
-
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
|
652
|
-
}
|
|
653
|
-
EventEmitter.prototype.listeners = function listeners(type) {
|
|
654
|
-
return _listeners(this, type, true);
|
|
655
|
-
};
|
|
656
|
-
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
|
657
|
-
return _listeners(this, type, false);
|
|
658
|
-
};
|
|
659
|
-
EventEmitter.listenerCount = function(emitter, type) {
|
|
660
|
-
if (typeof emitter.listenerCount === "function") {
|
|
661
|
-
return emitter.listenerCount(type);
|
|
662
|
-
} else {
|
|
663
|
-
return listenerCount.call(emitter, type);
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
EventEmitter.prototype.listenerCount = listenerCount;
|
|
667
|
-
function listenerCount(type) {
|
|
668
|
-
var events2 = this._events;
|
|
669
|
-
if (events2 !== void 0) {
|
|
670
|
-
var evlistener = events2[type];
|
|
671
|
-
if (typeof evlistener === "function") {
|
|
672
|
-
return 1;
|
|
673
|
-
} else if (evlistener !== void 0) {
|
|
674
|
-
return evlistener.length;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
return 0;
|
|
678
|
-
}
|
|
679
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
680
|
-
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
|
681
|
-
};
|
|
682
|
-
function arrayClone(arr, n) {
|
|
683
|
-
var copy = new Array(n);
|
|
684
|
-
for (var i = 0; i < n; ++i)
|
|
685
|
-
copy[i] = arr[i];
|
|
686
|
-
return copy;
|
|
687
|
-
}
|
|
688
|
-
function spliceOne(list, index) {
|
|
689
|
-
for (; index + 1 < list.length; index++)
|
|
690
|
-
list[index] = list[index + 1];
|
|
691
|
-
list.pop();
|
|
692
|
-
}
|
|
693
|
-
function unwrapListeners(arr) {
|
|
694
|
-
var ret = new Array(arr.length);
|
|
695
|
-
for (var i = 0; i < ret.length; ++i) {
|
|
696
|
-
ret[i] = arr[i].listener || arr[i];
|
|
697
|
-
}
|
|
698
|
-
return ret;
|
|
699
|
-
}
|
|
700
|
-
function once(emitter, name) {
|
|
701
|
-
return new Promise(function(resolve, reject) {
|
|
702
|
-
function errorListener(err) {
|
|
703
|
-
emitter.removeListener(name, resolver);
|
|
704
|
-
reject(err);
|
|
705
|
-
}
|
|
706
|
-
function resolver() {
|
|
707
|
-
if (typeof emitter.removeListener === "function") {
|
|
708
|
-
emitter.removeListener("error", errorListener);
|
|
709
|
-
}
|
|
710
|
-
resolve([].slice.call(arguments));
|
|
711
|
-
}
|
|
712
|
-
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
|
713
|
-
if (name !== "error") {
|
|
714
|
-
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
715
|
-
}
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
|
719
|
-
if (typeof emitter.on === "function") {
|
|
720
|
-
eventTargetAgnosticAddListener(emitter, "error", handler, flags);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
724
|
-
if (typeof emitter.on === "function") {
|
|
725
|
-
if (flags.once) {
|
|
726
|
-
emitter.once(name, listener);
|
|
727
|
-
} else {
|
|
728
|
-
emitter.on(name, listener);
|
|
729
|
-
}
|
|
730
|
-
} else if (typeof emitter.addEventListener === "function") {
|
|
731
|
-
emitter.addEventListener(name, function wrapListener(arg) {
|
|
732
|
-
if (flags.once) {
|
|
733
|
-
emitter.removeEventListener(name, wrapListener);
|
|
734
|
-
}
|
|
735
|
-
listener(arg);
|
|
736
|
-
});
|
|
737
|
-
} else {
|
|
738
|
-
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
return events.exports;
|
|
742
|
-
}
|
|
743
|
-
var factoryValidator;
|
|
744
|
-
var hasRequiredFactoryValidator;
|
|
745
|
-
function requireFactoryValidator() {
|
|
746
|
-
if (hasRequiredFactoryValidator) return factoryValidator;
|
|
747
|
-
hasRequiredFactoryValidator = 1;
|
|
748
|
-
factoryValidator = function(factory) {
|
|
749
|
-
if (typeof factory.create !== "function") {
|
|
750
|
-
throw new TypeError("factory.create must be a function");
|
|
751
|
-
}
|
|
752
|
-
if (typeof factory.destroy !== "function") {
|
|
753
|
-
throw new TypeError("factory.destroy must be a function");
|
|
754
|
-
}
|
|
755
|
-
if (typeof factory.validate !== "undefined" && typeof factory.validate !== "function") {
|
|
756
|
-
throw new TypeError("factory.validate must be a function");
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
return factoryValidator;
|
|
760
|
-
}
|
|
761
|
-
var PoolDefaults_1;
|
|
762
|
-
var hasRequiredPoolDefaults;
|
|
763
|
-
function requirePoolDefaults() {
|
|
764
|
-
if (hasRequiredPoolDefaults) return PoolDefaults_1;
|
|
765
|
-
hasRequiredPoolDefaults = 1;
|
|
766
|
-
class PoolDefaults {
|
|
767
|
-
constructor() {
|
|
768
|
-
this.fifo = true;
|
|
769
|
-
this.priorityRange = 1;
|
|
770
|
-
this.testOnBorrow = false;
|
|
771
|
-
this.testOnReturn = false;
|
|
772
|
-
this.autostart = true;
|
|
773
|
-
this.evictionRunIntervalMillis = 0;
|
|
774
|
-
this.numTestsPerEvictionRun = 3;
|
|
775
|
-
this.softIdleTimeoutMillis = -1;
|
|
776
|
-
this.idleTimeoutMillis = 3e4;
|
|
777
|
-
this.acquireTimeoutMillis = null;
|
|
778
|
-
this.destroyTimeoutMillis = null;
|
|
779
|
-
this.maxWaitingClients = null;
|
|
780
|
-
this.min = null;
|
|
781
|
-
this.max = null;
|
|
782
|
-
this.Promise = Promise;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
PoolDefaults_1 = PoolDefaults;
|
|
786
|
-
return PoolDefaults_1;
|
|
787
|
-
}
|
|
788
|
-
var PoolOptions_1;
|
|
789
|
-
var hasRequiredPoolOptions;
|
|
790
|
-
function requirePoolOptions() {
|
|
791
|
-
if (hasRequiredPoolOptions) return PoolOptions_1;
|
|
792
|
-
hasRequiredPoolOptions = 1;
|
|
793
|
-
const PoolDefaults = requirePoolDefaults();
|
|
794
|
-
class PoolOptions {
|
|
795
|
-
/**
|
|
796
|
-
* @param {Object} opts
|
|
797
|
-
* configuration for the pool
|
|
798
|
-
* @param {Number} [opts.max=null]
|
|
799
|
-
* Maximum number of items that can exist at the same time. Default: 1.
|
|
800
|
-
* Any further acquire requests will be pushed to the waiting list.
|
|
801
|
-
* @param {Number} [opts.min=null]
|
|
802
|
-
* Minimum number of items in pool (including in-use). Default: 0.
|
|
803
|
-
* When the pool is created, or a resource destroyed, this minimum will
|
|
804
|
-
* be checked. If the pool resource count is below the minimum, a new
|
|
805
|
-
* resource will be created and added to the pool.
|
|
806
|
-
* @param {Number} [opts.maxWaitingClients=null]
|
|
807
|
-
* maximum number of queued requests allowed after which acquire calls will be rejected
|
|
808
|
-
* @param {Boolean} [opts.testOnBorrow=false]
|
|
809
|
-
* should the pool validate resources before giving them to clients. Requires that
|
|
810
|
-
* `factory.validate` is specified.
|
|
811
|
-
* @param {Boolean} [opts.testOnReturn=false]
|
|
812
|
-
* should the pool validate resources before returning them to the pool.
|
|
813
|
-
* @param {Number} [opts.acquireTimeoutMillis=null]
|
|
814
|
-
* Delay in milliseconds after which the an `acquire` call will fail. optional.
|
|
815
|
-
* Default: undefined. Should be positive and non-zero
|
|
816
|
-
* @param {Number} [opts.destroyTimeoutMillis=null]
|
|
817
|
-
* Delay in milliseconds after which the an `destroy` call will fail, causing it to emit a factoryDestroyError event. optional.
|
|
818
|
-
* Default: undefined. Should be positive and non-zero
|
|
819
|
-
* @param {Number} [opts.priorityRange=1]
|
|
820
|
-
* The range from 1 to be treated as a valid priority
|
|
821
|
-
* @param {Boolean} [opts.fifo=true]
|
|
822
|
-
* Sets whether the pool has LIFO (last in, first out) behaviour with respect to idle objects.
|
|
823
|
-
* if false then pool has FIFO behaviour
|
|
824
|
-
* @param {Boolean} [opts.autostart=true]
|
|
825
|
-
* Should the pool start creating resources etc once the constructor is called
|
|
826
|
-
* @param {Number} [opts.evictionRunIntervalMillis=0]
|
|
827
|
-
* How often to run eviction checks. Default: 0 (does not run).
|
|
828
|
-
* @param {Number} [opts.numTestsPerEvictionRun=3]
|
|
829
|
-
* Number of resources to check each eviction run. Default: 3.
|
|
830
|
-
* @param {Number} [opts.softIdleTimeoutMillis=-1]
|
|
831
|
-
* amount of time an object may sit idle in the pool before it is eligible
|
|
832
|
-
* for eviction by the idle object evictor (if any), with the extra condition
|
|
833
|
-
* that at least "min idle" object instances remain in the pool. Default -1 (nothing can get evicted)
|
|
834
|
-
* @param {Number} [opts.idleTimeoutMillis=30000]
|
|
835
|
-
* the minimum amount of time that an object may sit idle in the pool before it is eligible for eviction
|
|
836
|
-
* due to idle time. Supercedes "softIdleTimeoutMillis" Default: 30000
|
|
837
|
-
* @param {typeof Promise} [opts.Promise=Promise]
|
|
838
|
-
* What promise implementation should the pool use, defaults to native promises.
|
|
839
|
-
*/
|
|
840
|
-
constructor(opts) {
|
|
841
|
-
const poolDefaults = new PoolDefaults();
|
|
842
|
-
opts = opts || {};
|
|
843
|
-
this.fifo = typeof opts.fifo === "boolean" ? opts.fifo : poolDefaults.fifo;
|
|
844
|
-
this.priorityRange = opts.priorityRange || poolDefaults.priorityRange;
|
|
845
|
-
this.testOnBorrow = typeof opts.testOnBorrow === "boolean" ? opts.testOnBorrow : poolDefaults.testOnBorrow;
|
|
846
|
-
this.testOnReturn = typeof opts.testOnReturn === "boolean" ? opts.testOnReturn : poolDefaults.testOnReturn;
|
|
847
|
-
this.autostart = typeof opts.autostart === "boolean" ? opts.autostart : poolDefaults.autostart;
|
|
848
|
-
if (opts.acquireTimeoutMillis) {
|
|
849
|
-
this.acquireTimeoutMillis = parseInt(opts.acquireTimeoutMillis, 10);
|
|
850
|
-
}
|
|
851
|
-
if (opts.destroyTimeoutMillis) {
|
|
852
|
-
this.destroyTimeoutMillis = parseInt(opts.destroyTimeoutMillis, 10);
|
|
853
|
-
}
|
|
854
|
-
if (opts.maxWaitingClients !== void 0) {
|
|
855
|
-
this.maxWaitingClients = parseInt(opts.maxWaitingClients, 10);
|
|
856
|
-
}
|
|
857
|
-
this.max = parseInt(opts.max, 10);
|
|
858
|
-
this.min = parseInt(opts.min, 10);
|
|
859
|
-
this.max = Math.max(isNaN(this.max) ? 1 : this.max, 1);
|
|
860
|
-
this.min = Math.min(isNaN(this.min) ? 0 : this.min, this.max);
|
|
861
|
-
this.evictionRunIntervalMillis = opts.evictionRunIntervalMillis || poolDefaults.evictionRunIntervalMillis;
|
|
862
|
-
this.numTestsPerEvictionRun = opts.numTestsPerEvictionRun || poolDefaults.numTestsPerEvictionRun;
|
|
863
|
-
this.softIdleTimeoutMillis = opts.softIdleTimeoutMillis || poolDefaults.softIdleTimeoutMillis;
|
|
864
|
-
this.idleTimeoutMillis = opts.idleTimeoutMillis || poolDefaults.idleTimeoutMillis;
|
|
865
|
-
this.Promise = opts.Promise != null ? opts.Promise : poolDefaults.Promise;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
PoolOptions_1 = PoolOptions;
|
|
869
|
-
return PoolOptions_1;
|
|
870
|
-
}
|
|
871
|
-
var Deferred_1;
|
|
872
|
-
var hasRequiredDeferred;
|
|
873
|
-
function requireDeferred() {
|
|
874
|
-
if (hasRequiredDeferred) return Deferred_1;
|
|
875
|
-
hasRequiredDeferred = 1;
|
|
876
|
-
class Deferred {
|
|
877
|
-
constructor(Promise2) {
|
|
878
|
-
this._state = Deferred.PENDING;
|
|
879
|
-
this._resolve = void 0;
|
|
880
|
-
this._reject = void 0;
|
|
881
|
-
this._promise = new Promise2((resolve, reject) => {
|
|
882
|
-
this._resolve = resolve;
|
|
883
|
-
this._reject = reject;
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
get state() {
|
|
887
|
-
return this._state;
|
|
888
|
-
}
|
|
889
|
-
get promise() {
|
|
890
|
-
return this._promise;
|
|
891
|
-
}
|
|
892
|
-
reject(reason) {
|
|
893
|
-
if (this._state !== Deferred.PENDING) {
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
this._state = Deferred.REJECTED;
|
|
897
|
-
this._reject(reason);
|
|
898
|
-
}
|
|
899
|
-
resolve(value) {
|
|
900
|
-
if (this._state !== Deferred.PENDING) {
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
this._state = Deferred.FULFILLED;
|
|
904
|
-
this._resolve(value);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
Deferred.PENDING = "PENDING";
|
|
908
|
-
Deferred.FULFILLED = "FULFILLED";
|
|
909
|
-
Deferred.REJECTED = "REJECTED";
|
|
910
|
-
Deferred_1 = Deferred;
|
|
911
|
-
return Deferred_1;
|
|
912
|
-
}
|
|
913
|
-
var errors;
|
|
914
|
-
var hasRequiredErrors;
|
|
915
|
-
function requireErrors() {
|
|
916
|
-
if (hasRequiredErrors) return errors;
|
|
917
|
-
hasRequiredErrors = 1;
|
|
918
|
-
class ExtendableError extends Error {
|
|
919
|
-
constructor(message) {
|
|
920
|
-
super(message);
|
|
921
|
-
this.name = this.constructor.name;
|
|
922
|
-
this.message = message;
|
|
923
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
924
|
-
Error.captureStackTrace(this, this.constructor);
|
|
925
|
-
} else {
|
|
926
|
-
this.stack = new Error(message).stack;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
class TimeoutError extends ExtendableError {
|
|
931
|
-
constructor(m) {
|
|
932
|
-
super(m);
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
errors = {
|
|
936
|
-
TimeoutError
|
|
937
|
-
};
|
|
938
|
-
return errors;
|
|
939
|
-
}
|
|
940
|
-
var ResourceRequest_1;
|
|
941
|
-
var hasRequiredResourceRequest;
|
|
942
|
-
function requireResourceRequest() {
|
|
943
|
-
if (hasRequiredResourceRequest) return ResourceRequest_1;
|
|
944
|
-
hasRequiredResourceRequest = 1;
|
|
945
|
-
const Deferred = requireDeferred();
|
|
946
|
-
const errors2 = requireErrors();
|
|
947
|
-
function fbind(fn, ctx) {
|
|
948
|
-
return function bound() {
|
|
949
|
-
return fn.apply(ctx, arguments);
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
class ResourceRequest extends Deferred {
|
|
953
|
-
/**
|
|
954
|
-
* [constructor description]
|
|
955
|
-
* @param {Number} ttl timeout
|
|
956
|
-
*/
|
|
957
|
-
constructor(ttl, Promise2) {
|
|
958
|
-
super(Promise2);
|
|
959
|
-
this._creationTimestamp = Date.now();
|
|
960
|
-
this._timeout = null;
|
|
961
|
-
if (ttl !== void 0) {
|
|
962
|
-
this.setTimeout(ttl);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
setTimeout(delay) {
|
|
966
|
-
if (this._state !== ResourceRequest.PENDING) {
|
|
967
|
-
return;
|
|
968
|
-
}
|
|
969
|
-
const ttl = parseInt(delay, 10);
|
|
970
|
-
if (isNaN(ttl) || ttl <= 0) {
|
|
971
|
-
throw new Error("delay must be a positive int");
|
|
972
|
-
}
|
|
973
|
-
const age = Date.now() - this._creationTimestamp;
|
|
974
|
-
if (this._timeout) {
|
|
975
|
-
this.removeTimeout();
|
|
976
|
-
}
|
|
977
|
-
this._timeout = setTimeout(
|
|
978
|
-
fbind(this._fireTimeout, this),
|
|
979
|
-
Math.max(ttl - age, 0)
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
removeTimeout() {
|
|
983
|
-
if (this._timeout) {
|
|
984
|
-
clearTimeout(this._timeout);
|
|
985
|
-
}
|
|
986
|
-
this._timeout = null;
|
|
987
|
-
}
|
|
988
|
-
_fireTimeout() {
|
|
989
|
-
this.reject(new errors2.TimeoutError("ResourceRequest timed out"));
|
|
990
|
-
}
|
|
991
|
-
reject(reason) {
|
|
992
|
-
this.removeTimeout();
|
|
993
|
-
super.reject(reason);
|
|
994
|
-
}
|
|
995
|
-
resolve(value) {
|
|
996
|
-
this.removeTimeout();
|
|
997
|
-
super.resolve(value);
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
ResourceRequest_1 = ResourceRequest;
|
|
1001
|
-
return ResourceRequest_1;
|
|
1002
|
-
}
|
|
1003
|
-
var ResourceLoan_1;
|
|
1004
|
-
var hasRequiredResourceLoan;
|
|
1005
|
-
function requireResourceLoan() {
|
|
1006
|
-
if (hasRequiredResourceLoan) return ResourceLoan_1;
|
|
1007
|
-
hasRequiredResourceLoan = 1;
|
|
1008
|
-
const Deferred = requireDeferred();
|
|
1009
|
-
class ResourceLoan extends Deferred {
|
|
1010
|
-
/**
|
|
1011
|
-
*
|
|
1012
|
-
* @param {any} pooledResource the PooledResource this loan belongs to
|
|
1013
|
-
* @return {any} [description]
|
|
1014
|
-
*/
|
|
1015
|
-
constructor(pooledResource, Promise2) {
|
|
1016
|
-
super(Promise2);
|
|
1017
|
-
this._creationTimestamp = Date.now();
|
|
1018
|
-
this.pooledResource = pooledResource;
|
|
1019
|
-
}
|
|
1020
|
-
reject() {
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
ResourceLoan_1 = ResourceLoan;
|
|
1024
|
-
return ResourceLoan_1;
|
|
1025
|
-
}
|
|
1026
|
-
var PooledResourceStateEnum_1;
|
|
1027
|
-
var hasRequiredPooledResourceStateEnum;
|
|
1028
|
-
function requirePooledResourceStateEnum() {
|
|
1029
|
-
if (hasRequiredPooledResourceStateEnum) return PooledResourceStateEnum_1;
|
|
1030
|
-
hasRequiredPooledResourceStateEnum = 1;
|
|
1031
|
-
const PooledResourceStateEnum = {
|
|
1032
|
-
ALLOCATED: "ALLOCATED",
|
|
1033
|
-
// In use
|
|
1034
|
-
IDLE: "IDLE",
|
|
1035
|
-
// In the queue, not in use.
|
|
1036
|
-
INVALID: "INVALID",
|
|
1037
|
-
// Failed validation
|
|
1038
|
-
RETURNING: "RETURNING",
|
|
1039
|
-
// Resource is in process of returning
|
|
1040
|
-
VALIDATION: "VALIDATION"
|
|
1041
|
-
// Currently being tested
|
|
1042
|
-
};
|
|
1043
|
-
PooledResourceStateEnum_1 = PooledResourceStateEnum;
|
|
1044
|
-
return PooledResourceStateEnum_1;
|
|
1045
|
-
}
|
|
1046
|
-
var PooledResource_1;
|
|
1047
|
-
var hasRequiredPooledResource;
|
|
1048
|
-
function requirePooledResource() {
|
|
1049
|
-
if (hasRequiredPooledResource) return PooledResource_1;
|
|
1050
|
-
hasRequiredPooledResource = 1;
|
|
1051
|
-
const PooledResourceStateEnum = requirePooledResourceStateEnum();
|
|
1052
|
-
class PooledResource {
|
|
1053
|
-
constructor(resource) {
|
|
1054
|
-
this.creationTime = Date.now();
|
|
1055
|
-
this.lastReturnTime = null;
|
|
1056
|
-
this.lastBorrowTime = null;
|
|
1057
|
-
this.lastIdleTime = null;
|
|
1058
|
-
this.obj = resource;
|
|
1059
|
-
this.state = PooledResourceStateEnum.IDLE;
|
|
1060
|
-
}
|
|
1061
|
-
// mark the resource as "allocated"
|
|
1062
|
-
allocate() {
|
|
1063
|
-
this.lastBorrowTime = Date.now();
|
|
1064
|
-
this.state = PooledResourceStateEnum.ALLOCATED;
|
|
1065
|
-
}
|
|
1066
|
-
// mark the resource as "deallocated"
|
|
1067
|
-
deallocate() {
|
|
1068
|
-
this.lastReturnTime = Date.now();
|
|
1069
|
-
this.state = PooledResourceStateEnum.IDLE;
|
|
1070
|
-
}
|
|
1071
|
-
invalidate() {
|
|
1072
|
-
this.state = PooledResourceStateEnum.INVALID;
|
|
1073
|
-
}
|
|
1074
|
-
test() {
|
|
1075
|
-
this.state = PooledResourceStateEnum.VALIDATION;
|
|
1076
|
-
}
|
|
1077
|
-
idle() {
|
|
1078
|
-
this.lastIdleTime = Date.now();
|
|
1079
|
-
this.state = PooledResourceStateEnum.IDLE;
|
|
1080
|
-
}
|
|
1081
|
-
returning() {
|
|
1082
|
-
this.state = PooledResourceStateEnum.RETURNING;
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
PooledResource_1 = PooledResource;
|
|
1086
|
-
return PooledResource_1;
|
|
1087
|
-
}
|
|
1088
|
-
var DefaultEvictor_1;
|
|
1089
|
-
var hasRequiredDefaultEvictor;
|
|
1090
|
-
function requireDefaultEvictor() {
|
|
1091
|
-
if (hasRequiredDefaultEvictor) return DefaultEvictor_1;
|
|
1092
|
-
hasRequiredDefaultEvictor = 1;
|
|
1093
|
-
class DefaultEvictor {
|
|
1094
|
-
evict(config, pooledResource, availableObjectsCount) {
|
|
1095
|
-
const idleTime = Date.now() - pooledResource.lastIdleTime;
|
|
1096
|
-
if (config.softIdleTimeoutMillis > 0 && config.softIdleTimeoutMillis < idleTime && config.min < availableObjectsCount) {
|
|
1097
|
-
return true;
|
|
1098
|
-
}
|
|
1099
|
-
if (config.idleTimeoutMillis < idleTime) {
|
|
1100
|
-
return true;
|
|
1101
|
-
}
|
|
1102
|
-
return false;
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
DefaultEvictor_1 = DefaultEvictor;
|
|
1106
|
-
return DefaultEvictor_1;
|
|
1107
|
-
}
|
|
1108
|
-
var DoublyLinkedList_1;
|
|
1109
|
-
var hasRequiredDoublyLinkedList;
|
|
1110
|
-
function requireDoublyLinkedList() {
|
|
1111
|
-
if (hasRequiredDoublyLinkedList) return DoublyLinkedList_1;
|
|
1112
|
-
hasRequiredDoublyLinkedList = 1;
|
|
1113
|
-
class DoublyLinkedList {
|
|
1114
|
-
constructor() {
|
|
1115
|
-
this.head = null;
|
|
1116
|
-
this.tail = null;
|
|
1117
|
-
this.length = 0;
|
|
1118
|
-
}
|
|
1119
|
-
insertBeginning(node) {
|
|
1120
|
-
if (this.head === null) {
|
|
1121
|
-
this.head = node;
|
|
1122
|
-
this.tail = node;
|
|
1123
|
-
node.prev = null;
|
|
1124
|
-
node.next = null;
|
|
1125
|
-
this.length++;
|
|
1126
|
-
} else {
|
|
1127
|
-
this.insertBefore(this.head, node);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
insertEnd(node) {
|
|
1131
|
-
if (this.tail === null) {
|
|
1132
|
-
this.insertBeginning(node);
|
|
1133
|
-
} else {
|
|
1134
|
-
this.insertAfter(this.tail, node);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
insertAfter(node, newNode) {
|
|
1138
|
-
newNode.prev = node;
|
|
1139
|
-
newNode.next = node.next;
|
|
1140
|
-
if (node.next === null) {
|
|
1141
|
-
this.tail = newNode;
|
|
1142
|
-
} else {
|
|
1143
|
-
node.next.prev = newNode;
|
|
1144
|
-
}
|
|
1145
|
-
node.next = newNode;
|
|
1146
|
-
this.length++;
|
|
1147
|
-
}
|
|
1148
|
-
insertBefore(node, newNode) {
|
|
1149
|
-
newNode.prev = node.prev;
|
|
1150
|
-
newNode.next = node;
|
|
1151
|
-
if (node.prev === null) {
|
|
1152
|
-
this.head = newNode;
|
|
1153
|
-
} else {
|
|
1154
|
-
node.prev.next = newNode;
|
|
1155
|
-
}
|
|
1156
|
-
node.prev = newNode;
|
|
1157
|
-
this.length++;
|
|
1158
|
-
}
|
|
1159
|
-
remove(node) {
|
|
1160
|
-
if (node.prev === null) {
|
|
1161
|
-
this.head = node.next;
|
|
1162
|
-
} else {
|
|
1163
|
-
node.prev.next = node.next;
|
|
1164
|
-
}
|
|
1165
|
-
if (node.next === null) {
|
|
1166
|
-
this.tail = node.prev;
|
|
1167
|
-
} else {
|
|
1168
|
-
node.next.prev = node.prev;
|
|
1169
|
-
}
|
|
1170
|
-
node.prev = null;
|
|
1171
|
-
node.next = null;
|
|
1172
|
-
this.length--;
|
|
1173
|
-
}
|
|
1174
|
-
// FIXME: this should not live here and has become a dumping ground...
|
|
1175
|
-
static createNode(data) {
|
|
1176
|
-
return {
|
|
1177
|
-
prev: null,
|
|
1178
|
-
next: null,
|
|
1179
|
-
data
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
DoublyLinkedList_1 = DoublyLinkedList;
|
|
1184
|
-
return DoublyLinkedList_1;
|
|
1185
|
-
}
|
|
1186
|
-
var DoublyLinkedListIterator_1;
|
|
1187
|
-
var hasRequiredDoublyLinkedListIterator;
|
|
1188
|
-
function requireDoublyLinkedListIterator() {
|
|
1189
|
-
if (hasRequiredDoublyLinkedListIterator) return DoublyLinkedListIterator_1;
|
|
1190
|
-
hasRequiredDoublyLinkedListIterator = 1;
|
|
1191
|
-
class DoublyLinkedListIterator {
|
|
1192
|
-
/**
|
|
1193
|
-
* @param {Object} doublyLinkedList a node that is part of a doublyLinkedList
|
|
1194
|
-
* @param {Boolean} [reverse=false] is this a reverse iterator? default: false
|
|
1195
|
-
*/
|
|
1196
|
-
constructor(doublyLinkedList, reverse) {
|
|
1197
|
-
this._list = doublyLinkedList;
|
|
1198
|
-
this._direction = reverse === true ? "prev" : "next";
|
|
1199
|
-
this._startPosition = reverse === true ? "tail" : "head";
|
|
1200
|
-
this._started = false;
|
|
1201
|
-
this._cursor = null;
|
|
1202
|
-
this._done = false;
|
|
1203
|
-
}
|
|
1204
|
-
_start() {
|
|
1205
|
-
this._cursor = this._list[this._startPosition];
|
|
1206
|
-
this._started = true;
|
|
1207
|
-
}
|
|
1208
|
-
_advanceCursor() {
|
|
1209
|
-
if (this._started === false) {
|
|
1210
|
-
this._started = true;
|
|
1211
|
-
this._cursor = this._list[this._startPosition];
|
|
1212
|
-
return;
|
|
1213
|
-
}
|
|
1214
|
-
this._cursor = this._cursor[this._direction];
|
|
1215
|
-
}
|
|
1216
|
-
reset() {
|
|
1217
|
-
this._done = false;
|
|
1218
|
-
this._started = false;
|
|
1219
|
-
this._cursor = null;
|
|
1220
|
-
}
|
|
1221
|
-
remove() {
|
|
1222
|
-
if (this._started === false || this._done === true || this._isCursorDetached()) {
|
|
1223
|
-
return false;
|
|
1224
|
-
}
|
|
1225
|
-
this._list.remove(this._cursor);
|
|
1226
|
-
}
|
|
1227
|
-
next() {
|
|
1228
|
-
if (this._done === true) {
|
|
1229
|
-
return { done: true };
|
|
1230
|
-
}
|
|
1231
|
-
this._advanceCursor();
|
|
1232
|
-
if (this._cursor === null || this._isCursorDetached()) {
|
|
1233
|
-
this._done = true;
|
|
1234
|
-
return { done: true };
|
|
1235
|
-
}
|
|
1236
|
-
return {
|
|
1237
|
-
value: this._cursor,
|
|
1238
|
-
done: false
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
/**
|
|
1242
|
-
* Is the node detached from a list?
|
|
1243
|
-
* NOTE: you can trick/bypass/confuse this check by removing a node from one DoublyLinkedList
|
|
1244
|
-
* and adding it to another.
|
|
1245
|
-
* TODO: We can make this smarter by checking the direction of travel and only checking
|
|
1246
|
-
* the required next/prev/head/tail rather than all of them
|
|
1247
|
-
* @return {Boolean} [description]
|
|
1248
|
-
*/
|
|
1249
|
-
_isCursorDetached() {
|
|
1250
|
-
return this._cursor.prev === null && this._cursor.next === null && this._list.tail !== this._cursor && this._list.head !== this._cursor;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
DoublyLinkedListIterator_1 = DoublyLinkedListIterator;
|
|
1254
|
-
return DoublyLinkedListIterator_1;
|
|
1255
|
-
}
|
|
1256
|
-
var DequeIterator_1;
|
|
1257
|
-
var hasRequiredDequeIterator;
|
|
1258
|
-
function requireDequeIterator() {
|
|
1259
|
-
if (hasRequiredDequeIterator) return DequeIterator_1;
|
|
1260
|
-
hasRequiredDequeIterator = 1;
|
|
1261
|
-
const DoublyLinkedListIterator = requireDoublyLinkedListIterator();
|
|
1262
|
-
class DequeIterator extends DoublyLinkedListIterator {
|
|
1263
|
-
next() {
|
|
1264
|
-
const result = super.next();
|
|
1265
|
-
if (result.value) {
|
|
1266
|
-
result.value = result.value.data;
|
|
1267
|
-
}
|
|
1268
|
-
return result;
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
DequeIterator_1 = DequeIterator;
|
|
1272
|
-
return DequeIterator_1;
|
|
1273
|
-
}
|
|
1274
|
-
var Deque_1;
|
|
1275
|
-
var hasRequiredDeque;
|
|
1276
|
-
function requireDeque() {
|
|
1277
|
-
if (hasRequiredDeque) return Deque_1;
|
|
1278
|
-
hasRequiredDeque = 1;
|
|
1279
|
-
const DoublyLinkedList = requireDoublyLinkedList();
|
|
1280
|
-
const DequeIterator = requireDequeIterator();
|
|
1281
|
-
class Deque {
|
|
1282
|
-
constructor() {
|
|
1283
|
-
this._list = new DoublyLinkedList();
|
|
1284
|
-
}
|
|
1285
|
-
/**
|
|
1286
|
-
* removes and returns the first element from the queue
|
|
1287
|
-
* @return {any} [description]
|
|
1288
|
-
*/
|
|
1289
|
-
shift() {
|
|
1290
|
-
if (this.length === 0) {
|
|
1291
|
-
return void 0;
|
|
1292
|
-
}
|
|
1293
|
-
const node = this._list.head;
|
|
1294
|
-
this._list.remove(node);
|
|
1295
|
-
return node.data;
|
|
1296
|
-
}
|
|
1297
|
-
/**
|
|
1298
|
-
* adds one elemts to the beginning of the queue
|
|
1299
|
-
* @param {any} element [description]
|
|
1300
|
-
* @return {any} [description]
|
|
1301
|
-
*/
|
|
1302
|
-
unshift(element) {
|
|
1303
|
-
const node = DoublyLinkedList.createNode(element);
|
|
1304
|
-
this._list.insertBeginning(node);
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* adds one to the end of the queue
|
|
1308
|
-
* @param {any} element [description]
|
|
1309
|
-
* @return {any} [description]
|
|
1310
|
-
*/
|
|
1311
|
-
push(element) {
|
|
1312
|
-
const node = DoublyLinkedList.createNode(element);
|
|
1313
|
-
this._list.insertEnd(node);
|
|
1314
|
-
}
|
|
1315
|
-
/**
|
|
1316
|
-
* removes and returns the last element from the queue
|
|
1317
|
-
*/
|
|
1318
|
-
pop() {
|
|
1319
|
-
if (this.length === 0) {
|
|
1320
|
-
return void 0;
|
|
1321
|
-
}
|
|
1322
|
-
const node = this._list.tail;
|
|
1323
|
-
this._list.remove(node);
|
|
1324
|
-
return node.data;
|
|
1325
|
-
}
|
|
1326
|
-
[Symbol.iterator]() {
|
|
1327
|
-
return new DequeIterator(this._list);
|
|
1328
|
-
}
|
|
1329
|
-
iterator() {
|
|
1330
|
-
return new DequeIterator(this._list);
|
|
1331
|
-
}
|
|
1332
|
-
reverseIterator() {
|
|
1333
|
-
return new DequeIterator(this._list, true);
|
|
1334
|
-
}
|
|
1335
|
-
/**
|
|
1336
|
-
* get a reference to the item at the head of the queue
|
|
1337
|
-
* @return {any} [description]
|
|
1338
|
-
*/
|
|
1339
|
-
get head() {
|
|
1340
|
-
if (this.length === 0) {
|
|
1341
|
-
return void 0;
|
|
1342
|
-
}
|
|
1343
|
-
const node = this._list.head;
|
|
1344
|
-
return node.data;
|
|
1345
|
-
}
|
|
1346
|
-
/**
|
|
1347
|
-
* get a reference to the item at the tail of the queue
|
|
1348
|
-
* @return {any} [description]
|
|
1349
|
-
*/
|
|
1350
|
-
get tail() {
|
|
1351
|
-
if (this.length === 0) {
|
|
1352
|
-
return void 0;
|
|
1353
|
-
}
|
|
1354
|
-
const node = this._list.tail;
|
|
1355
|
-
return node.data;
|
|
1356
|
-
}
|
|
1357
|
-
get length() {
|
|
1358
|
-
return this._list.length;
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
Deque_1 = Deque;
|
|
1362
|
-
return Deque_1;
|
|
1363
|
-
}
|
|
1364
|
-
var Queue_1;
|
|
1365
|
-
var hasRequiredQueue;
|
|
1366
|
-
function requireQueue() {
|
|
1367
|
-
if (hasRequiredQueue) return Queue_1;
|
|
1368
|
-
hasRequiredQueue = 1;
|
|
1369
|
-
const DoublyLinkedList = requireDoublyLinkedList();
|
|
1370
|
-
const Deque = requireDeque();
|
|
1371
|
-
class Queue extends Deque {
|
|
1372
|
-
/**
|
|
1373
|
-
* Adds the obj to the end of the list for this slot
|
|
1374
|
-
* we completely override the parent method because we need access to the
|
|
1375
|
-
* node for our rejection handler
|
|
1376
|
-
* @param {any} resourceRequest [description]
|
|
1377
|
-
*/
|
|
1378
|
-
push(resourceRequest) {
|
|
1379
|
-
const node = DoublyLinkedList.createNode(resourceRequest);
|
|
1380
|
-
resourceRequest.promise.catch(this._createTimeoutRejectionHandler(node));
|
|
1381
|
-
this._list.insertEnd(node);
|
|
1382
|
-
}
|
|
1383
|
-
_createTimeoutRejectionHandler(node) {
|
|
1384
|
-
return (reason) => {
|
|
1385
|
-
if (reason.name === "TimeoutError") {
|
|
1386
|
-
this._list.remove(node);
|
|
1387
|
-
}
|
|
1388
|
-
};
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
Queue_1 = Queue;
|
|
1392
|
-
return Queue_1;
|
|
1393
|
-
}
|
|
1394
|
-
var PriorityQueue_1;
|
|
1395
|
-
var hasRequiredPriorityQueue;
|
|
1396
|
-
function requirePriorityQueue() {
|
|
1397
|
-
if (hasRequiredPriorityQueue) return PriorityQueue_1;
|
|
1398
|
-
hasRequiredPriorityQueue = 1;
|
|
1399
|
-
const Queue = requireQueue();
|
|
1400
|
-
class PriorityQueue {
|
|
1401
|
-
constructor(size) {
|
|
1402
|
-
this._size = Math.max(+size | 0, 1);
|
|
1403
|
-
this._slots = [];
|
|
1404
|
-
for (let i = 0; i < this._size; i++) {
|
|
1405
|
-
this._slots.push(new Queue());
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
get length() {
|
|
1409
|
-
let _length = 0;
|
|
1410
|
-
for (let i = 0, slots = this._slots.length; i < slots; i++) {
|
|
1411
|
-
_length += this._slots[i].length;
|
|
1412
|
-
}
|
|
1413
|
-
return _length;
|
|
1414
|
-
}
|
|
1415
|
-
enqueue(obj, priority) {
|
|
1416
|
-
priority = priority && +priority | 0 || 0;
|
|
1417
|
-
if (priority) {
|
|
1418
|
-
if (priority < 0 || priority >= this._size) {
|
|
1419
|
-
priority = this._size - 1;
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
this._slots[priority].push(obj);
|
|
1423
|
-
}
|
|
1424
|
-
dequeue() {
|
|
1425
|
-
for (let i = 0, sl = this._slots.length; i < sl; i += 1) {
|
|
1426
|
-
if (this._slots[i].length) {
|
|
1427
|
-
return this._slots[i].shift();
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
return;
|
|
1431
|
-
}
|
|
1432
|
-
get head() {
|
|
1433
|
-
for (let i = 0, sl = this._slots.length; i < sl; i += 1) {
|
|
1434
|
-
if (this._slots[i].length > 0) {
|
|
1435
|
-
return this._slots[i].head;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
get tail() {
|
|
1441
|
-
for (let i = this._slots.length - 1; i >= 0; i--) {
|
|
1442
|
-
if (this._slots[i].length > 0) {
|
|
1443
|
-
return this._slots[i].tail;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
return;
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
PriorityQueue_1 = PriorityQueue;
|
|
1450
|
-
return PriorityQueue_1;
|
|
1451
|
-
}
|
|
1452
|
-
var utils = {};
|
|
1453
|
-
var hasRequiredUtils;
|
|
1454
|
-
function requireUtils() {
|
|
1455
|
-
if (hasRequiredUtils) return utils;
|
|
1456
|
-
hasRequiredUtils = 1;
|
|
1457
|
-
function noop() {
|
|
1458
|
-
}
|
|
1459
|
-
utils.reflector = function(promise) {
|
|
1460
|
-
return promise.then(noop, noop);
|
|
1461
|
-
};
|
|
1462
|
-
return utils;
|
|
1463
|
-
}
|
|
1464
|
-
var Pool_1;
|
|
1465
|
-
var hasRequiredPool;
|
|
1466
|
-
function requirePool() {
|
|
1467
|
-
if (hasRequiredPool) return Pool_1;
|
|
1468
|
-
hasRequiredPool = 1;
|
|
1469
|
-
const EventEmitter = requireEvents().EventEmitter;
|
|
1470
|
-
const factoryValidator2 = requireFactoryValidator();
|
|
1471
|
-
const PoolOptions = requirePoolOptions();
|
|
1472
|
-
const ResourceRequest = requireResourceRequest();
|
|
1473
|
-
const ResourceLoan = requireResourceLoan();
|
|
1474
|
-
const PooledResource = requirePooledResource();
|
|
1475
|
-
requireDefaultEvictor();
|
|
1476
|
-
requireDeque();
|
|
1477
|
-
const Deferred = requireDeferred();
|
|
1478
|
-
requirePriorityQueue();
|
|
1479
|
-
requireDequeIterator();
|
|
1480
|
-
const reflector = requireUtils().reflector;
|
|
1481
|
-
const FACTORY_CREATE_ERROR = "factoryCreateError";
|
|
1482
|
-
const FACTORY_DESTROY_ERROR = "factoryDestroyError";
|
|
1483
|
-
class Pool extends EventEmitter {
|
|
1484
|
-
/**
|
|
1485
|
-
* Generate an Object pool with a specified `factory` and `config`.
|
|
1486
|
-
*
|
|
1487
|
-
* @param {typeof DefaultEvictor} Evictor
|
|
1488
|
-
* @param {typeof Deque} Deque
|
|
1489
|
-
* @param {typeof PriorityQueue} PriorityQueue
|
|
1490
|
-
* @param {Object} factory
|
|
1491
|
-
* Factory to be used for generating and destroying the items.
|
|
1492
|
-
* @param {Function} factory.create
|
|
1493
|
-
* Should create the item to be acquired,
|
|
1494
|
-
* and call it's first callback argument with the generated item as it's argument.
|
|
1495
|
-
* @param {Function} factory.destroy
|
|
1496
|
-
* Should gently close any resources that the item is using.
|
|
1497
|
-
* Called before the items is destroyed.
|
|
1498
|
-
* @param {Function} factory.validate
|
|
1499
|
-
* Test if a resource is still valid .Should return a promise that resolves to a boolean, true if resource is still valid and false
|
|
1500
|
-
* If it should be removed from pool.
|
|
1501
|
-
* @param {Object} options
|
|
1502
|
-
*/
|
|
1503
|
-
constructor(Evictor, Deque, PriorityQueue, factory, options) {
|
|
1504
|
-
super();
|
|
1505
|
-
factoryValidator2(factory);
|
|
1506
|
-
this._config = new PoolOptions(options);
|
|
1507
|
-
this._Promise = this._config.Promise;
|
|
1508
|
-
this._factory = factory;
|
|
1509
|
-
this._draining = false;
|
|
1510
|
-
this._started = false;
|
|
1511
|
-
this._waitingClientsQueue = new PriorityQueue(this._config.priorityRange);
|
|
1512
|
-
this._factoryCreateOperations = /* @__PURE__ */ new Set();
|
|
1513
|
-
this._factoryDestroyOperations = /* @__PURE__ */ new Set();
|
|
1514
|
-
this._availableObjects = new Deque();
|
|
1515
|
-
this._testOnBorrowResources = /* @__PURE__ */ new Set();
|
|
1516
|
-
this._testOnReturnResources = /* @__PURE__ */ new Set();
|
|
1517
|
-
this._validationOperations = /* @__PURE__ */ new Set();
|
|
1518
|
-
this._allObjects = /* @__PURE__ */ new Set();
|
|
1519
|
-
this._resourceLoans = /* @__PURE__ */ new Map();
|
|
1520
|
-
this._evictionIterator = this._availableObjects.iterator();
|
|
1521
|
-
this._evictor = new Evictor();
|
|
1522
|
-
this._scheduledEviction = null;
|
|
1523
|
-
if (this._config.autostart === true) {
|
|
1524
|
-
this.start();
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
_destroy(pooledResource) {
|
|
1528
|
-
pooledResource.invalidate();
|
|
1529
|
-
this._allObjects.delete(pooledResource);
|
|
1530
|
-
const destroyPromise = this._factory.destroy(pooledResource.obj);
|
|
1531
|
-
const wrappedDestroyPromise = this._config.destroyTimeoutMillis ? this._Promise.resolve(this._applyDestroyTimeout(destroyPromise)) : this._Promise.resolve(destroyPromise);
|
|
1532
|
-
this._trackOperation(
|
|
1533
|
-
wrappedDestroyPromise,
|
|
1534
|
-
this._factoryDestroyOperations
|
|
1535
|
-
).catch((reason) => {
|
|
1536
|
-
this.emit(FACTORY_DESTROY_ERROR, reason);
|
|
1537
|
-
});
|
|
1538
|
-
this._ensureMinimum();
|
|
1539
|
-
}
|
|
1540
|
-
_applyDestroyTimeout(promise) {
|
|
1541
|
-
const timeoutPromise = new this._Promise((resolve, reject) => {
|
|
1542
|
-
setTimeout(() => {
|
|
1543
|
-
reject(new Error("destroy timed out"));
|
|
1544
|
-
}, this._config.destroyTimeoutMillis).unref();
|
|
1545
|
-
});
|
|
1546
|
-
return this._Promise.race([timeoutPromise, promise]);
|
|
1547
|
-
}
|
|
1548
|
-
/**
|
|
1549
|
-
* Attempt to move an available resource into test and then onto a waiting client
|
|
1550
|
-
* @return {Boolean} could we move an available resource into test
|
|
1551
|
-
*/
|
|
1552
|
-
_testOnBorrow() {
|
|
1553
|
-
if (this._availableObjects.length < 1) {
|
|
1554
|
-
return false;
|
|
1555
|
-
}
|
|
1556
|
-
const pooledResource = this._availableObjects.shift();
|
|
1557
|
-
pooledResource.test();
|
|
1558
|
-
this._testOnBorrowResources.add(pooledResource);
|
|
1559
|
-
const validationPromise = this._factory.validate(pooledResource.obj);
|
|
1560
|
-
const wrappedValidationPromise = this._Promise.resolve(validationPromise);
|
|
1561
|
-
this._trackOperation(
|
|
1562
|
-
wrappedValidationPromise,
|
|
1563
|
-
this._validationOperations
|
|
1564
|
-
).then((isValid) => {
|
|
1565
|
-
this._testOnBorrowResources.delete(pooledResource);
|
|
1566
|
-
if (isValid === false) {
|
|
1567
|
-
pooledResource.invalidate();
|
|
1568
|
-
this._destroy(pooledResource);
|
|
1569
|
-
this._dispense();
|
|
1570
|
-
return;
|
|
1571
|
-
}
|
|
1572
|
-
this._dispatchPooledResourceToNextWaitingClient(pooledResource);
|
|
1573
|
-
});
|
|
1574
|
-
return true;
|
|
1575
|
-
}
|
|
1576
|
-
/**
|
|
1577
|
-
* Attempt to move an available resource to a waiting client
|
|
1578
|
-
* @return {Boolean} [description]
|
|
1579
|
-
*/
|
|
1580
|
-
_dispatchResource() {
|
|
1581
|
-
if (this._availableObjects.length < 1) {
|
|
1582
|
-
return false;
|
|
1583
|
-
}
|
|
1584
|
-
const pooledResource = this._availableObjects.shift();
|
|
1585
|
-
this._dispatchPooledResourceToNextWaitingClient(pooledResource);
|
|
1586
|
-
return false;
|
|
1587
|
-
}
|
|
1588
|
-
/**
|
|
1589
|
-
* Attempt to resolve an outstanding resource request using an available resource from
|
|
1590
|
-
* the pool, or creating new ones
|
|
1591
|
-
*
|
|
1592
|
-
* @private
|
|
1593
|
-
*/
|
|
1594
|
-
_dispense() {
|
|
1595
|
-
const numWaitingClients = this._waitingClientsQueue.length;
|
|
1596
|
-
if (numWaitingClients < 1) {
|
|
1597
|
-
return;
|
|
1598
|
-
}
|
|
1599
|
-
const resourceShortfall = numWaitingClients - this._potentiallyAllocableResourceCount;
|
|
1600
|
-
const actualNumberOfResourcesToCreate = Math.min(
|
|
1601
|
-
this.spareResourceCapacity,
|
|
1602
|
-
resourceShortfall
|
|
1603
|
-
);
|
|
1604
|
-
for (let i = 0; actualNumberOfResourcesToCreate > i; i++) {
|
|
1605
|
-
this._createResource();
|
|
1606
|
-
}
|
|
1607
|
-
if (this._config.testOnBorrow === true) {
|
|
1608
|
-
const desiredNumberOfResourcesToMoveIntoTest = numWaitingClients - this._testOnBorrowResources.size;
|
|
1609
|
-
const actualNumberOfResourcesToMoveIntoTest = Math.min(
|
|
1610
|
-
this._availableObjects.length,
|
|
1611
|
-
desiredNumberOfResourcesToMoveIntoTest
|
|
1612
|
-
);
|
|
1613
|
-
for (let i = 0; actualNumberOfResourcesToMoveIntoTest > i; i++) {
|
|
1614
|
-
this._testOnBorrow();
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
if (this._config.testOnBorrow === false) {
|
|
1618
|
-
const actualNumberOfResourcesToDispatch = Math.min(
|
|
1619
|
-
this._availableObjects.length,
|
|
1620
|
-
numWaitingClients
|
|
1621
|
-
);
|
|
1622
|
-
for (let i = 0; actualNumberOfResourcesToDispatch > i; i++) {
|
|
1623
|
-
this._dispatchResource();
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
/**
|
|
1628
|
-
* Dispatches a pooledResource to the next waiting client (if any) else
|
|
1629
|
-
* puts the PooledResource back on the available list
|
|
1630
|
-
* @param {PooledResource} pooledResource [description]
|
|
1631
|
-
* @return {Boolean} [description]
|
|
1632
|
-
*/
|
|
1633
|
-
_dispatchPooledResourceToNextWaitingClient(pooledResource) {
|
|
1634
|
-
const clientResourceRequest = this._waitingClientsQueue.dequeue();
|
|
1635
|
-
if (clientResourceRequest === void 0 || clientResourceRequest.state !== Deferred.PENDING) {
|
|
1636
|
-
this._addPooledResourceToAvailableObjects(pooledResource);
|
|
1637
|
-
return false;
|
|
1638
|
-
}
|
|
1639
|
-
const loan = new ResourceLoan(pooledResource, this._Promise);
|
|
1640
|
-
this._resourceLoans.set(pooledResource.obj, loan);
|
|
1641
|
-
pooledResource.allocate();
|
|
1642
|
-
clientResourceRequest.resolve(pooledResource.obj);
|
|
1643
|
-
return true;
|
|
1644
|
-
}
|
|
1645
|
-
/**
|
|
1646
|
-
* tracks on operation using given set
|
|
1647
|
-
* handles adding/removing from the set and resolve/rejects the value/reason
|
|
1648
|
-
* @param {Promise} operation
|
|
1649
|
-
* @param {Set} set Set holding operations
|
|
1650
|
-
* @return {Promise} Promise that resolves once operation has been removed from set
|
|
1651
|
-
*/
|
|
1652
|
-
_trackOperation(operation, set) {
|
|
1653
|
-
set.add(operation);
|
|
1654
|
-
return operation.then(
|
|
1655
|
-
(v) => {
|
|
1656
|
-
set.delete(operation);
|
|
1657
|
-
return this._Promise.resolve(v);
|
|
1658
|
-
},
|
|
1659
|
-
(e) => {
|
|
1660
|
-
set.delete(operation);
|
|
1661
|
-
return this._Promise.reject(e);
|
|
1662
|
-
}
|
|
1663
|
-
);
|
|
1664
|
-
}
|
|
1665
|
-
/**
|
|
1666
|
-
* @private
|
|
1667
|
-
*/
|
|
1668
|
-
_createResource() {
|
|
1669
|
-
const factoryPromise = this._factory.create();
|
|
1670
|
-
const wrappedFactoryPromise = this._Promise.resolve(factoryPromise).then((resource) => {
|
|
1671
|
-
const pooledResource = new PooledResource(resource);
|
|
1672
|
-
this._allObjects.add(pooledResource);
|
|
1673
|
-
this._addPooledResourceToAvailableObjects(pooledResource);
|
|
1674
|
-
});
|
|
1675
|
-
this._trackOperation(wrappedFactoryPromise, this._factoryCreateOperations).then(() => {
|
|
1676
|
-
this._dispense();
|
|
1677
|
-
return null;
|
|
1678
|
-
}).catch((reason) => {
|
|
1679
|
-
this.emit(FACTORY_CREATE_ERROR, reason);
|
|
1680
|
-
this._dispense();
|
|
1681
|
-
});
|
|
1682
|
-
}
|
|
1683
|
-
/**
|
|
1684
|
-
* @private
|
|
1685
|
-
*/
|
|
1686
|
-
_ensureMinimum() {
|
|
1687
|
-
if (this._draining === true) {
|
|
1688
|
-
return;
|
|
1689
|
-
}
|
|
1690
|
-
const minShortfall = this._config.min - this._count;
|
|
1691
|
-
for (let i = 0; i < minShortfall; i++) {
|
|
1692
|
-
this._createResource();
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
_evict() {
|
|
1696
|
-
const testsToRun = Math.min(
|
|
1697
|
-
this._config.numTestsPerEvictionRun,
|
|
1698
|
-
this._availableObjects.length
|
|
1699
|
-
);
|
|
1700
|
-
const evictionConfig = {
|
|
1701
|
-
softIdleTimeoutMillis: this._config.softIdleTimeoutMillis,
|
|
1702
|
-
idleTimeoutMillis: this._config.idleTimeoutMillis,
|
|
1703
|
-
min: this._config.min
|
|
1704
|
-
};
|
|
1705
|
-
for (let testsHaveRun = 0; testsHaveRun < testsToRun; ) {
|
|
1706
|
-
const iterationResult = this._evictionIterator.next();
|
|
1707
|
-
if (iterationResult.done === true && this._availableObjects.length < 1) {
|
|
1708
|
-
this._evictionIterator.reset();
|
|
1709
|
-
return;
|
|
1710
|
-
}
|
|
1711
|
-
if (iterationResult.done === true && this._availableObjects.length > 0) {
|
|
1712
|
-
this._evictionIterator.reset();
|
|
1713
|
-
continue;
|
|
1714
|
-
}
|
|
1715
|
-
const resource = iterationResult.value;
|
|
1716
|
-
const shouldEvict = this._evictor.evict(
|
|
1717
|
-
evictionConfig,
|
|
1718
|
-
resource,
|
|
1719
|
-
this._availableObjects.length
|
|
1720
|
-
);
|
|
1721
|
-
testsHaveRun++;
|
|
1722
|
-
if (shouldEvict === true) {
|
|
1723
|
-
this._evictionIterator.remove();
|
|
1724
|
-
this._destroy(resource);
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
_scheduleEvictorRun() {
|
|
1729
|
-
if (this._config.evictionRunIntervalMillis > 0) {
|
|
1730
|
-
this._scheduledEviction = setTimeout(() => {
|
|
1731
|
-
this._evict();
|
|
1732
|
-
this._scheduleEvictorRun();
|
|
1733
|
-
}, this._config.evictionRunIntervalMillis).unref();
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
_descheduleEvictorRun() {
|
|
1737
|
-
if (this._scheduledEviction) {
|
|
1738
|
-
clearTimeout(this._scheduledEviction);
|
|
1739
|
-
}
|
|
1740
|
-
this._scheduledEviction = null;
|
|
1741
|
-
}
|
|
1742
|
-
start() {
|
|
1743
|
-
if (this._draining === true) {
|
|
1744
|
-
return;
|
|
1745
|
-
}
|
|
1746
|
-
if (this._started === true) {
|
|
1747
|
-
return;
|
|
1748
|
-
}
|
|
1749
|
-
this._started = true;
|
|
1750
|
-
this._scheduleEvictorRun();
|
|
1751
|
-
this._ensureMinimum();
|
|
1752
|
-
}
|
|
1753
|
-
/**
|
|
1754
|
-
* Request a new resource. The callback will be called,
|
|
1755
|
-
* when a new resource is available, passing the resource to the callback.
|
|
1756
|
-
* TODO: should we add a seperate "acquireWithPriority" function
|
|
1757
|
-
*
|
|
1758
|
-
* @param {Number} [priority=0]
|
|
1759
|
-
* Optional. Integer between 0 and (priorityRange - 1). Specifies the priority
|
|
1760
|
-
* of the caller if there are no available resources. Lower numbers mean higher
|
|
1761
|
-
* priority.
|
|
1762
|
-
*
|
|
1763
|
-
* @returns {Promise}
|
|
1764
|
-
*/
|
|
1765
|
-
acquire(priority) {
|
|
1766
|
-
if (this._started === false && this._config.autostart === false) {
|
|
1767
|
-
this.start();
|
|
1768
|
-
}
|
|
1769
|
-
if (this._draining) {
|
|
1770
|
-
return this._Promise.reject(
|
|
1771
|
-
new Error("pool is draining and cannot accept work")
|
|
1772
|
-
);
|
|
1773
|
-
}
|
|
1774
|
-
if (this.spareResourceCapacity < 1 && this._availableObjects.length < 1 && this._config.maxWaitingClients !== void 0 && this._waitingClientsQueue.length >= this._config.maxWaitingClients) {
|
|
1775
|
-
return this._Promise.reject(
|
|
1776
|
-
new Error("max waitingClients count exceeded")
|
|
1777
|
-
);
|
|
1778
|
-
}
|
|
1779
|
-
const resourceRequest = new ResourceRequest(
|
|
1780
|
-
this._config.acquireTimeoutMillis,
|
|
1781
|
-
this._Promise
|
|
1782
|
-
);
|
|
1783
|
-
this._waitingClientsQueue.enqueue(resourceRequest, priority);
|
|
1784
|
-
this._dispense();
|
|
1785
|
-
return resourceRequest.promise;
|
|
1786
|
-
}
|
|
1787
|
-
/**
|
|
1788
|
-
* [use method, aquires a resource, passes the resource to a user supplied function and releases it]
|
|
1789
|
-
* @param {Function} fn [a function that accepts a resource and returns a promise that resolves/rejects once it has finished using the resource]
|
|
1790
|
-
* @return {Promise} [resolves once the resource is released to the pool]
|
|
1791
|
-
*/
|
|
1792
|
-
use(fn, priority) {
|
|
1793
|
-
return this.acquire(priority).then((resource) => {
|
|
1794
|
-
return fn(resource).then(
|
|
1795
|
-
(result) => {
|
|
1796
|
-
this.release(resource);
|
|
1797
|
-
return result;
|
|
1798
|
-
},
|
|
1799
|
-
(err) => {
|
|
1800
|
-
this.destroy(resource);
|
|
1801
|
-
throw err;
|
|
1802
|
-
}
|
|
1803
|
-
);
|
|
1804
|
-
});
|
|
1805
|
-
}
|
|
1806
|
-
/**
|
|
1807
|
-
* Check if resource is currently on loan from the pool
|
|
1808
|
-
*
|
|
1809
|
-
* @param {Function} resource
|
|
1810
|
-
* Resource for checking.
|
|
1811
|
-
*
|
|
1812
|
-
* @returns {Boolean}
|
|
1813
|
-
* True if resource belongs to this pool and false otherwise
|
|
1814
|
-
*/
|
|
1815
|
-
isBorrowedResource(resource) {
|
|
1816
|
-
return this._resourceLoans.has(resource);
|
|
1817
|
-
}
|
|
1818
|
-
/**
|
|
1819
|
-
* Return the resource to the pool when it is no longer required.
|
|
1820
|
-
*
|
|
1821
|
-
* @param {Object} resource
|
|
1822
|
-
* The acquired object to be put back to the pool.
|
|
1823
|
-
*/
|
|
1824
|
-
release(resource) {
|
|
1825
|
-
const loan = this._resourceLoans.get(resource);
|
|
1826
|
-
if (loan === void 0) {
|
|
1827
|
-
return this._Promise.reject(
|
|
1828
|
-
new Error("Resource not currently part of this pool")
|
|
1829
|
-
);
|
|
1830
|
-
}
|
|
1831
|
-
this._resourceLoans.delete(resource);
|
|
1832
|
-
loan.resolve();
|
|
1833
|
-
const pooledResource = loan.pooledResource;
|
|
1834
|
-
pooledResource.deallocate();
|
|
1835
|
-
this._addPooledResourceToAvailableObjects(pooledResource);
|
|
1836
|
-
this._dispense();
|
|
1837
|
-
return this._Promise.resolve();
|
|
1838
|
-
}
|
|
1839
|
-
/**
|
|
1840
|
-
* Request the resource to be destroyed. The factory's destroy handler
|
|
1841
|
-
* will also be called.
|
|
1842
|
-
*
|
|
1843
|
-
* This should be called within an acquire() block as an alternative to release().
|
|
1844
|
-
*
|
|
1845
|
-
* @param {Object} resource
|
|
1846
|
-
* The acquired resource to be destoyed.
|
|
1847
|
-
*/
|
|
1848
|
-
destroy(resource) {
|
|
1849
|
-
const loan = this._resourceLoans.get(resource);
|
|
1850
|
-
if (loan === void 0) {
|
|
1851
|
-
return this._Promise.reject(
|
|
1852
|
-
new Error("Resource not currently part of this pool")
|
|
1853
|
-
);
|
|
1854
|
-
}
|
|
1855
|
-
this._resourceLoans.delete(resource);
|
|
1856
|
-
loan.resolve();
|
|
1857
|
-
const pooledResource = loan.pooledResource;
|
|
1858
|
-
pooledResource.deallocate();
|
|
1859
|
-
this._destroy(pooledResource);
|
|
1860
|
-
this._dispense();
|
|
1861
|
-
return this._Promise.resolve();
|
|
1862
|
-
}
|
|
1863
|
-
_addPooledResourceToAvailableObjects(pooledResource) {
|
|
1864
|
-
pooledResource.idle();
|
|
1865
|
-
if (this._config.fifo === true) {
|
|
1866
|
-
this._availableObjects.push(pooledResource);
|
|
1867
|
-
} else {
|
|
1868
|
-
this._availableObjects.unshift(pooledResource);
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
/**
|
|
1872
|
-
* Disallow any new acquire calls and let the request backlog dissapate.
|
|
1873
|
-
* The Pool will no longer attempt to maintain a "min" number of resources
|
|
1874
|
-
* and will only make new resources on demand.
|
|
1875
|
-
* Resolves once all resource requests are fulfilled and all resources are returned to pool and available...
|
|
1876
|
-
* Should probably be called "drain work"
|
|
1877
|
-
* @returns {Promise}
|
|
1878
|
-
*/
|
|
1879
|
-
drain() {
|
|
1880
|
-
this._draining = true;
|
|
1881
|
-
return this.__allResourceRequestsSettled().then(() => {
|
|
1882
|
-
return this.__allResourcesReturned();
|
|
1883
|
-
}).then(() => {
|
|
1884
|
-
this._descheduleEvictorRun();
|
|
1885
|
-
});
|
|
1886
|
-
}
|
|
1887
|
-
__allResourceRequestsSettled() {
|
|
1888
|
-
if (this._waitingClientsQueue.length > 0) {
|
|
1889
|
-
return reflector(this._waitingClientsQueue.tail.promise);
|
|
1890
|
-
}
|
|
1891
|
-
return this._Promise.resolve();
|
|
1892
|
-
}
|
|
1893
|
-
// FIXME: this is a horrific mess
|
|
1894
|
-
__allResourcesReturned() {
|
|
1895
|
-
const ps = Array.from(this._resourceLoans.values()).map((loan) => loan.promise).map(reflector);
|
|
1896
|
-
return this._Promise.all(ps);
|
|
1897
|
-
}
|
|
1898
|
-
/**
|
|
1899
|
-
* Forcibly destroys all available resources regardless of timeout. Intended to be
|
|
1900
|
-
* invoked as part of a drain. Does not prevent the creation of new
|
|
1901
|
-
* resources as a result of subsequent calls to acquire.
|
|
1902
|
-
*
|
|
1903
|
-
* Note that if factory.min > 0 and the pool isn't "draining", the pool will destroy all idle resources
|
|
1904
|
-
* in the pool, but replace them with newly created resources up to the
|
|
1905
|
-
* specified factory.min value. If this is not desired, set factory.min
|
|
1906
|
-
* to zero before calling clear()
|
|
1907
|
-
*
|
|
1908
|
-
*/
|
|
1909
|
-
clear() {
|
|
1910
|
-
const reflectedCreatePromises = Array.from(
|
|
1911
|
-
this._factoryCreateOperations
|
|
1912
|
-
).map(reflector);
|
|
1913
|
-
return this._Promise.all(reflectedCreatePromises).then(() => {
|
|
1914
|
-
for (const resource of this._availableObjects) {
|
|
1915
|
-
this._destroy(resource);
|
|
1916
|
-
}
|
|
1917
|
-
const reflectedDestroyPromises = Array.from(
|
|
1918
|
-
this._factoryDestroyOperations
|
|
1919
|
-
).map(reflector);
|
|
1920
|
-
return reflector(this._Promise.all(reflectedDestroyPromises));
|
|
1921
|
-
});
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Waits until the pool is ready.
|
|
1925
|
-
* We define ready by checking if the current resource number is at least
|
|
1926
|
-
* the minimum number defined.
|
|
1927
|
-
* @returns {Promise} that resolves when the minimum number is ready.
|
|
1928
|
-
*/
|
|
1929
|
-
ready() {
|
|
1930
|
-
return new this._Promise((resolve) => {
|
|
1931
|
-
const isReady = () => {
|
|
1932
|
-
if (this.available >= this.min) {
|
|
1933
|
-
resolve();
|
|
1934
|
-
} else {
|
|
1935
|
-
setTimeout(isReady, 100);
|
|
1936
|
-
}
|
|
1937
|
-
};
|
|
1938
|
-
isReady();
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* How many resources are available to allocated
|
|
1943
|
-
* (includes resources that have not been tested and may faul validation)
|
|
1944
|
-
* NOTE: internal for now as the name is awful and might not be useful to anyone
|
|
1945
|
-
* @return {Number} number of resources the pool has to allocate
|
|
1946
|
-
*/
|
|
1947
|
-
get _potentiallyAllocableResourceCount() {
|
|
1948
|
-
return this._availableObjects.length + this._testOnBorrowResources.size + this._testOnReturnResources.size + this._factoryCreateOperations.size;
|
|
1949
|
-
}
|
|
1950
|
-
/**
|
|
1951
|
-
* The combined count of the currently created objects and those in the
|
|
1952
|
-
* process of being created
|
|
1953
|
-
* Does NOT include resources in the process of being destroyed
|
|
1954
|
-
* sort of legacy...
|
|
1955
|
-
* @return {Number}
|
|
1956
|
-
*/
|
|
1957
|
-
get _count() {
|
|
1958
|
-
return this._allObjects.size + this._factoryCreateOperations.size;
|
|
1959
|
-
}
|
|
1960
|
-
/**
|
|
1961
|
-
* How many more resources does the pool have room for
|
|
1962
|
-
* @return {Number} number of resources the pool could create before hitting any limits
|
|
1963
|
-
*/
|
|
1964
|
-
get spareResourceCapacity() {
|
|
1965
|
-
return this._config.max - (this._allObjects.size + this._factoryCreateOperations.size);
|
|
1966
|
-
}
|
|
1967
|
-
/**
|
|
1968
|
-
* see _count above
|
|
1969
|
-
* @return {Number} [description]
|
|
1970
|
-
*/
|
|
1971
|
-
get size() {
|
|
1972
|
-
return this._count;
|
|
1973
|
-
}
|
|
1974
|
-
/**
|
|
1975
|
-
* number of available resources
|
|
1976
|
-
* @return {Number} [description]
|
|
1977
|
-
*/
|
|
1978
|
-
get available() {
|
|
1979
|
-
return this._availableObjects.length;
|
|
1980
|
-
}
|
|
1981
|
-
/**
|
|
1982
|
-
* number of resources that are currently acquired
|
|
1983
|
-
* @return {Number} [description]
|
|
1984
|
-
*/
|
|
1985
|
-
get borrowed() {
|
|
1986
|
-
return this._resourceLoans.size;
|
|
1987
|
-
}
|
|
1988
|
-
/**
|
|
1989
|
-
* number of waiting acquire calls
|
|
1990
|
-
* @return {Number} [description]
|
|
1991
|
-
*/
|
|
1992
|
-
get pending() {
|
|
1993
|
-
return this._waitingClientsQueue.length;
|
|
1994
|
-
}
|
|
1995
|
-
/**
|
|
1996
|
-
* maximum size of the pool
|
|
1997
|
-
* @return {Number} [description]
|
|
1998
|
-
*/
|
|
1999
|
-
get max() {
|
|
2000
|
-
return this._config.max;
|
|
2001
|
-
}
|
|
2002
|
-
/**
|
|
2003
|
-
* minimum size of the pool
|
|
2004
|
-
* @return {Number} [description]
|
|
2005
|
-
*/
|
|
2006
|
-
get min() {
|
|
2007
|
-
return this._config.min;
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
Pool_1 = Pool;
|
|
2011
|
-
return Pool_1;
|
|
2012
|
-
}
|
|
2013
|
-
var genericPool$1;
|
|
2014
|
-
var hasRequiredGenericPool;
|
|
2015
|
-
function requireGenericPool() {
|
|
2016
|
-
if (hasRequiredGenericPool) return genericPool$1;
|
|
2017
|
-
hasRequiredGenericPool = 1;
|
|
2018
|
-
const Pool = requirePool();
|
|
2019
|
-
const Deque = requireDeque();
|
|
2020
|
-
const PriorityQueue = requirePriorityQueue();
|
|
2021
|
-
const DefaultEvictor = requireDefaultEvictor();
|
|
2022
|
-
genericPool$1 = {
|
|
2023
|
-
Pool,
|
|
2024
|
-
Deque,
|
|
2025
|
-
PriorityQueue,
|
|
2026
|
-
DefaultEvictor,
|
|
2027
|
-
createPool: function(factory, config) {
|
|
2028
|
-
return new Pool(DefaultEvictor, Deque, PriorityQueue, factory, config);
|
|
2029
|
-
}
|
|
2030
|
-
};
|
|
2031
|
-
return genericPool$1;
|
|
2032
|
-
}
|
|
2033
|
-
var genericPoolExports = requireGenericPool();
|
|
2034
|
-
const genericPool = /* @__PURE__ */ getDefaultExportFromCjs(genericPoolExports);
|
|
2035
|
-
const workerFactory = {
|
|
2036
|
-
create: async () => {
|
|
2037
|
-
const workerPath = new URL("data:video/mp2t;base64,aW1wb3J0IHsgTWVzaERhdGEgfSBmcm9tICdAL2xpYi90eXBlcyc7CmltcG9ydCAqIGFzIENvbWxpbmsgZnJvbSAnY29tbGluayc7CmltcG9ydCAqIGFzIFRIUkVFIGZyb20gJ3RocmVlJzsKaW1wb3J0IHsgTWVzaFN1cmZhY2VTYW1wbGVyIH0gZnJvbSAndGhyZWUvZXhhbXBsZXMvanNtL21hdGgvTWVzaFN1cmZhY2VTYW1wbGVyLmpzJzsKCmV4cG9ydCBpbnRlcmZhY2UgTWVzaFNhbXBsZXJBUEkgewogIHNhbXBsZU1lc2g6IChtZXNoRGF0YTogTWVzaERhdGEsIHNpemU6IG51bWJlcikgPT4gUHJvbWlzZTxGbG9hdDMyQXJyYXk+Owp9Cgpjb25zdCBhcGkgPSB7CiAgc2FtcGxlTWVzaDogKG1lc2hEYXRhOiBNZXNoRGF0YSwgc2l6ZTogbnVtYmVyKTogRmxvYXQzMkFycmF5ID0+IHsKICAgIGNvbnN0IGdlb21ldHJ5ID0gbmV3IFRIUkVFLkJ1ZmZlckdlb21ldHJ5KCk7CiAgICBnZW9tZXRyeS5zZXRBdHRyaWJ1dGUoJ3Bvc2l0aW9uJywgbmV3IFRIUkVFLkJ1ZmZlckF0dHJpYnV0ZShuZXcgRmxvYXQzMkFycmF5KG1lc2hEYXRhLnBvc2l0aW9uKSwgMykpOwogICAgaWYgKG1lc2hEYXRhLm5vcm1hbCkgewogICAgICBnZW9tZXRyeS5zZXRBdHRyaWJ1dGUoJ25vcm1hbCcsIG5ldyBUSFJFRS5CdWZmZXJBdHRyaWJ1dGUobmV3IEZsb2F0MzJBcnJheShtZXNoRGF0YS5ub3JtYWwpLCAzKSk7CiAgICB9CiAgICBjb25zdCBtYXRlcmlhbCA9IG5ldyBUSFJFRS5NZXNoQmFzaWNNYXRlcmlhbCgpOwogICAgY29uc3QgbWVzaCA9IG5ldyBUSFJFRS5NZXNoKGdlb21ldHJ5LCBtYXRlcmlhbCk7CiAgICBtZXNoLnNjYWxlLnNldChtZXNoRGF0YS5zY2FsZS54LCBtZXNoRGF0YS5zY2FsZS55LCBtZXNoRGF0YS5zY2FsZS56KTsKCiAgICBjb25zdCBzYW1wbGVyID0gbmV3IE1lc2hTdXJmYWNlU2FtcGxlcihtZXNoKS5idWlsZCgpOwogICAgY29uc3QgZGF0YSA9IG5ldyBGbG9hdDMyQXJyYXkoc2l6ZSAqIHNpemUgKiA0KTsKICAgIGNvbnN0IHBvc2l0aW9uID0gbmV3IFRIUkVFLlZlY3RvcjMoKTsKCiAgICBmb3IgKGxldCBpID0gMDsgaSA8IHNpemU7IGkrKykgewogICAgICBmb3IgKGxldCBqID0gMDsgaiA8IHNpemU7IGorKykgewogICAgICAgIGNvbnN0IGluZGV4ID0gaSAqIHNpemUgKyBqOwogICAgICAgIHNhbXBsZXIuc2FtcGxlKHBvc2l0aW9uKTsKICAgICAgICBkYXRhWzQgKiBpbmRleF0gPSBwb3NpdGlvbi54ICogbWVzaERhdGEuc2NhbGUueDsKICAgICAgICBkYXRhWzQgKiBpbmRleCArIDFdID0gcG9zaXRpb24ueSAqIG1lc2hEYXRhLnNjYWxlLnk7CiAgICAgICAgZGF0YVs0ICogaW5kZXggKyAyXSA9IHBvc2l0aW9uLnogKiBtZXNoRGF0YS5zY2FsZS56OwogICAgICAgIGRhdGFbNCAqIGluZGV4ICsgM10gPSAoTWF0aC5yYW5kb20oKSAtIDAuNSkgKiAwLjAxOwogICAgICB9CiAgICB9CgogICAgcmV0dXJuIGRhdGE7CiAgfSwKfTsKCkNvbWxpbmsuZXhwb3NlKGFwaSk7Cg==", import.meta.url);
|
|
2038
|
-
const worker = new Worker(workerPath, { type: "module" });
|
|
2039
|
-
return wrap(worker);
|
|
2040
|
-
},
|
|
2041
|
-
destroy: async (worker) => {
|
|
2042
|
-
return worker[releaseProxy]();
|
|
2043
|
-
}
|
|
2044
|
-
};
|
|
2045
|
-
const pool = genericPool.createPool(workerFactory, {
|
|
2046
|
-
max: navigator.hardwareConcurrency || 4,
|
|
2047
|
-
min: 2
|
|
2048
|
-
});
|
|
2049
47
|
function createDataTexture(data, size) {
|
|
2050
48
|
const texture = new THREE.DataTexture(data, size, size, THREE.RGBAFormat, THREE.FloatType);
|
|
2051
49
|
texture.needsUpdate = true;
|
|
@@ -2085,6 +83,137 @@ function clamp(value, min, max) {
|
|
|
2085
83
|
value = Math.max(value, min);
|
|
2086
84
|
return value;
|
|
2087
85
|
}
|
|
86
|
+
const _face = new Triangle();
|
|
87
|
+
const _color = new Vector3();
|
|
88
|
+
const _uva = new Vector2(), _uvb = new Vector2(), _uvc = new Vector2();
|
|
89
|
+
class MeshSurfaceSampler {
|
|
90
|
+
constructor(mesh) {
|
|
91
|
+
this.geometry = mesh.geometry;
|
|
92
|
+
this.randomFunction = Math.random;
|
|
93
|
+
this.indexAttribute = this.geometry.index;
|
|
94
|
+
this.positionAttribute = this.geometry.getAttribute("position");
|
|
95
|
+
this.normalAttribute = this.geometry.getAttribute("normal");
|
|
96
|
+
this.colorAttribute = this.geometry.getAttribute("color");
|
|
97
|
+
this.uvAttribute = this.geometry.getAttribute("uv");
|
|
98
|
+
this.weightAttribute = null;
|
|
99
|
+
this.distribution = null;
|
|
100
|
+
}
|
|
101
|
+
setWeightAttribute(name) {
|
|
102
|
+
this.weightAttribute = name ? this.geometry.getAttribute(name) : null;
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
build() {
|
|
106
|
+
const indexAttribute = this.indexAttribute;
|
|
107
|
+
const positionAttribute = this.positionAttribute;
|
|
108
|
+
const weightAttribute = this.weightAttribute;
|
|
109
|
+
const totalFaces = indexAttribute ? indexAttribute.count / 3 : positionAttribute.count / 3;
|
|
110
|
+
const faceWeights = new Float32Array(totalFaces);
|
|
111
|
+
for (let i = 0; i < totalFaces; i++) {
|
|
112
|
+
let faceWeight = 1;
|
|
113
|
+
let i0 = 3 * i;
|
|
114
|
+
let i1 = 3 * i + 1;
|
|
115
|
+
let i2 = 3 * i + 2;
|
|
116
|
+
if (indexAttribute) {
|
|
117
|
+
i0 = indexAttribute.getX(i0);
|
|
118
|
+
i1 = indexAttribute.getX(i1);
|
|
119
|
+
i2 = indexAttribute.getX(i2);
|
|
120
|
+
}
|
|
121
|
+
if (weightAttribute) {
|
|
122
|
+
faceWeight = weightAttribute.getX(i0) + weightAttribute.getX(i1) + weightAttribute.getX(i2);
|
|
123
|
+
}
|
|
124
|
+
_face.a.fromBufferAttribute(positionAttribute, i0);
|
|
125
|
+
_face.b.fromBufferAttribute(positionAttribute, i1);
|
|
126
|
+
_face.c.fromBufferAttribute(positionAttribute, i2);
|
|
127
|
+
faceWeight *= _face.getArea();
|
|
128
|
+
faceWeights[i] = faceWeight;
|
|
129
|
+
}
|
|
130
|
+
const distribution = new Float32Array(totalFaces);
|
|
131
|
+
let cumulativeTotal = 0;
|
|
132
|
+
for (let i = 0; i < totalFaces; i++) {
|
|
133
|
+
cumulativeTotal += faceWeights[i];
|
|
134
|
+
distribution[i] = cumulativeTotal;
|
|
135
|
+
}
|
|
136
|
+
this.distribution = distribution;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
setRandomGenerator(randomFunction) {
|
|
140
|
+
this.randomFunction = randomFunction;
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
sample(targetPosition, targetNormal, targetColor, targetUV) {
|
|
144
|
+
const faceIndex = this.sampleFaceIndex();
|
|
145
|
+
return this.sampleFace(faceIndex, targetPosition, targetNormal, targetColor, targetUV);
|
|
146
|
+
}
|
|
147
|
+
sampleFaceIndex() {
|
|
148
|
+
const cumulativeTotal = this.distribution[this.distribution.length - 1];
|
|
149
|
+
return this.binarySearch(this.randomFunction() * cumulativeTotal);
|
|
150
|
+
}
|
|
151
|
+
binarySearch(x) {
|
|
152
|
+
const dist = this.distribution;
|
|
153
|
+
let start = 0;
|
|
154
|
+
let end = dist.length - 1;
|
|
155
|
+
let index = -1;
|
|
156
|
+
while (start <= end) {
|
|
157
|
+
const mid = Math.ceil((start + end) / 2);
|
|
158
|
+
if (mid === 0 || dist[mid - 1] <= x && dist[mid] > x) {
|
|
159
|
+
index = mid;
|
|
160
|
+
break;
|
|
161
|
+
} else if (x < dist[mid]) {
|
|
162
|
+
end = mid - 1;
|
|
163
|
+
} else {
|
|
164
|
+
start = mid + 1;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return index;
|
|
168
|
+
}
|
|
169
|
+
sampleFace(faceIndex, targetPosition, targetNormal, targetColor, targetUV) {
|
|
170
|
+
let u = this.randomFunction();
|
|
171
|
+
let v = this.randomFunction();
|
|
172
|
+
if (u + v > 1) {
|
|
173
|
+
u = 1 - u;
|
|
174
|
+
v = 1 - v;
|
|
175
|
+
}
|
|
176
|
+
const indexAttribute = this.indexAttribute;
|
|
177
|
+
let i0 = faceIndex * 3;
|
|
178
|
+
let i1 = faceIndex * 3 + 1;
|
|
179
|
+
let i2 = faceIndex * 3 + 2;
|
|
180
|
+
if (indexAttribute) {
|
|
181
|
+
i0 = indexAttribute.getX(i0);
|
|
182
|
+
i1 = indexAttribute.getX(i1);
|
|
183
|
+
i2 = indexAttribute.getX(i2);
|
|
184
|
+
}
|
|
185
|
+
_face.a.fromBufferAttribute(this.positionAttribute, i0);
|
|
186
|
+
_face.b.fromBufferAttribute(this.positionAttribute, i1);
|
|
187
|
+
_face.c.fromBufferAttribute(this.positionAttribute, i2);
|
|
188
|
+
targetPosition.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v));
|
|
189
|
+
if (targetNormal !== void 0) {
|
|
190
|
+
if (this.normalAttribute !== void 0) {
|
|
191
|
+
_face.a.fromBufferAttribute(this.normalAttribute, i0);
|
|
192
|
+
_face.b.fromBufferAttribute(this.normalAttribute, i1);
|
|
193
|
+
_face.c.fromBufferAttribute(this.normalAttribute, i2);
|
|
194
|
+
targetNormal.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v)).normalize();
|
|
195
|
+
} else {
|
|
196
|
+
_face.getNormal(targetNormal);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (targetColor !== void 0 && this.colorAttribute !== void 0) {
|
|
200
|
+
_face.a.fromBufferAttribute(this.colorAttribute, i0);
|
|
201
|
+
_face.b.fromBufferAttribute(this.colorAttribute, i1);
|
|
202
|
+
_face.c.fromBufferAttribute(this.colorAttribute, i2);
|
|
203
|
+
_color.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v));
|
|
204
|
+
targetColor.r = _color.x;
|
|
205
|
+
targetColor.g = _color.y;
|
|
206
|
+
targetColor.b = _color.z;
|
|
207
|
+
}
|
|
208
|
+
if (targetUV !== void 0 && this.uvAttribute !== void 0) {
|
|
209
|
+
_uva.fromBufferAttribute(this.uvAttribute, i0);
|
|
210
|
+
_uvb.fromBufferAttribute(this.uvAttribute, i1);
|
|
211
|
+
_uvc.fromBufferAttribute(this.uvAttribute, i2);
|
|
212
|
+
targetUV.set(0, 0).addScaledVector(_uva, u).addScaledVector(_uvb, v).addScaledVector(_uvc, 1 - (u + v));
|
|
213
|
+
}
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
2088
217
|
class DataTextureService {
|
|
2089
218
|
/**
|
|
2090
219
|
* Creates a new DataTextureManager instance.
|
|
@@ -2117,15 +246,10 @@ class DataTextureService {
|
|
|
2117
246
|
return texture;
|
|
2118
247
|
}
|
|
2119
248
|
const meshData = parseMeshData(asset);
|
|
2120
|
-
const
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
dataTexture.name = asset.name;
|
|
2125
|
-
return dataTexture;
|
|
2126
|
-
} finally {
|
|
2127
|
-
await pool.release(worker);
|
|
2128
|
-
}
|
|
249
|
+
const array = sampleMesh(meshData, this.textureSize);
|
|
250
|
+
const dataTexture = createDataTexture(array, this.textureSize);
|
|
251
|
+
dataTexture.name = asset.name;
|
|
252
|
+
return dataTexture;
|
|
2129
253
|
}
|
|
2130
254
|
async dispose() {
|
|
2131
255
|
this.dataTextures.clear();
|
|
@@ -2143,6 +267,30 @@ function parseMeshData(mesh) {
|
|
|
2143
267
|
scale: { x: mesh.scale.x, y: mesh.scale.y, z: mesh.scale.z }
|
|
2144
268
|
};
|
|
2145
269
|
}
|
|
270
|
+
function sampleMesh(meshData, size) {
|
|
271
|
+
const geometry = new THREE.BufferGeometry();
|
|
272
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array(meshData.position), 3));
|
|
273
|
+
if (meshData.normal) {
|
|
274
|
+
geometry.setAttribute("normal", new THREE.BufferAttribute(new Float32Array(meshData.normal), 3));
|
|
275
|
+
}
|
|
276
|
+
const material = new THREE.MeshBasicMaterial();
|
|
277
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
278
|
+
mesh.scale.set(meshData.scale.x, meshData.scale.y, meshData.scale.z);
|
|
279
|
+
const sampler = new MeshSurfaceSampler(mesh).build();
|
|
280
|
+
const data = new Float32Array(size * size * 4);
|
|
281
|
+
const position = new THREE.Vector3();
|
|
282
|
+
for (let i = 0; i < size; i++) {
|
|
283
|
+
for (let j = 0; j < size; j++) {
|
|
284
|
+
const index = i * size + j;
|
|
285
|
+
sampler.sample(position);
|
|
286
|
+
data[4 * index] = position.x * meshData.scale.x;
|
|
287
|
+
data[4 * index + 1] = position.y * meshData.scale.y;
|
|
288
|
+
data[4 * index + 2] = position.z * meshData.scale.z;
|
|
289
|
+
data[4 * index + 3] = (Math.random() - 0.5) * 0.01;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return data;
|
|
293
|
+
}
|
|
2146
294
|
const instanceFragmentShader = `
|
|
2147
295
|
varying vec2 vUv;
|
|
2148
296
|
uniform sampler2D uTexture;
|