1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.proxyWrap = exports.makeCallable = void 0;
|
4 | function makeCallable(func, object) {
|
5 | Object.assign(func, object);
|
6 | return func;
|
7 | }
|
8 | exports.makeCallable = makeCallable;
|
9 | function intercept(wrapper) {
|
10 | return (target, property) => {
|
11 | if (target[property]) {
|
12 | if (wrapper[property]) {
|
13 | const propertyType = typeof wrapper[property];
|
14 | if (propertyType === 'function') {
|
15 | wrapper[property](...arguments);
|
16 | }
|
17 | }
|
18 | return target[property];
|
19 | }
|
20 | else {
|
21 | if (wrapper[property]) {
|
22 | return wrapper[property];
|
23 | }
|
24 | throw new Error('Tried to access an unititialized property.');
|
25 | }
|
26 | };
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function proxyWrap(target, wrapper) {
|
41 | const proxy = new Proxy(target, {
|
42 | get: intercept(wrapper || {}),
|
43 | set() {
|
44 | throw new Error('Tried to update a readonly object.');
|
45 | },
|
46 | });
|
47 | return [target, proxy];
|
48 | }
|
49 | exports.proxyWrap = proxyWrap;
|