@elliemae/microfe-common 2.0.0-next.41 → 2.0.0-next.43
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/cjs/remoting.js +279 -317
- package/dist/cjs/scriptingObject.js +47 -73
- package/dist/cjs/scriptingObjectManager.js +173 -201
- package/dist/esm/remoting.js +279 -318
- package/dist/esm/scriptingObject.js +47 -74
- package/dist/esm/scriptingObjectManager.js +173 -202
- package/package.json +4 -4
|
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,38 +16,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
16
|
return to;
|
|
18
17
|
};
|
|
19
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
var __accessCheck = (obj, member, msg) => {
|
|
25
|
-
if (!member.has(obj))
|
|
26
|
-
throw TypeError("Cannot " + msg);
|
|
27
|
-
};
|
|
28
|
-
var __privateGet = (obj, member, getter) => {
|
|
29
|
-
__accessCheck(obj, member, "read from private field");
|
|
30
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
31
|
-
};
|
|
32
|
-
var __privateAdd = (obj, member, value) => {
|
|
33
|
-
if (member.has(obj))
|
|
34
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
35
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
36
|
-
};
|
|
37
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
38
|
-
__accessCheck(obj, member, "write to private field");
|
|
39
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
40
|
-
return value;
|
|
41
|
-
};
|
|
42
19
|
var scriptingObject_exports = {};
|
|
43
20
|
__export(scriptingObject_exports, {
|
|
44
21
|
ScriptingObject: () => ScriptingObject
|
|
45
22
|
});
|
|
46
23
|
module.exports = __toCommonJS(scriptingObject_exports);
|
|
47
24
|
var import_event = require("./event.js");
|
|
48
|
-
var _id, _objectType;
|
|
49
25
|
const FUNCTION = "function";
|
|
50
26
|
const isPublicFunction = (value, fnName) => typeof value === FUNCTION && !!fnName && !fnName.startsWith("_");
|
|
51
27
|
class ScriptingObject {
|
|
28
|
+
/**
|
|
29
|
+
* unique id of the scripting object
|
|
30
|
+
*/
|
|
31
|
+
#id;
|
|
32
|
+
/**
|
|
33
|
+
* type of the scripting object
|
|
34
|
+
*/
|
|
35
|
+
#objectType = "Object";
|
|
52
36
|
/**
|
|
53
37
|
* Creates an instance of ScriptingObject.
|
|
54
38
|
*
|
|
@@ -56,64 +40,54 @@ class ScriptingObject {
|
|
|
56
40
|
* @param objectType type of the scripting object
|
|
57
41
|
*/
|
|
58
42
|
constructor(objectId, objectType) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*/
|
|
62
|
-
__privateAdd(this, _id, void 0);
|
|
63
|
-
/**
|
|
64
|
-
* type of the scripting object
|
|
65
|
-
*/
|
|
66
|
-
__privateAdd(this, _objectType, "Object");
|
|
67
|
-
/**
|
|
68
|
-
* transform the scripting object to a format suitable for transmitting over window.postMessage
|
|
69
|
-
*
|
|
70
|
-
* @returns marshalled scripting object
|
|
71
|
-
*/
|
|
72
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
73
|
-
__publicField(this, "_toJSON", () => {
|
|
74
|
-
const functions = [];
|
|
75
|
-
const events = [];
|
|
76
|
-
Object.keys(this).forEach((property) => {
|
|
77
|
-
const value = this[property];
|
|
78
|
-
if ((0, import_event.isEvent)(value)) {
|
|
79
|
-
events.push(property);
|
|
80
|
-
} else if (isPublicFunction(value, property)) {
|
|
81
|
-
functions.push(property);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return {
|
|
85
|
-
objectId: __privateGet(this, _id),
|
|
86
|
-
objectType: __privateGet(this, _objectType),
|
|
87
|
-
functions,
|
|
88
|
-
events
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
/**
|
|
92
|
-
* dispose the scripting object
|
|
93
|
-
*/
|
|
94
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
95
|
-
__publicField(this, "_dispose", () => {
|
|
96
|
-
});
|
|
97
|
-
/**
|
|
98
|
-
* dispose the scripting object
|
|
99
|
-
*/
|
|
100
|
-
__publicField(this, "dispose", () => {
|
|
101
|
-
});
|
|
102
|
-
__privateSet(this, _id, objectId);
|
|
103
|
-
__privateSet(this, _objectType, objectType || __privateGet(this, _objectType));
|
|
43
|
+
this.#id = objectId;
|
|
44
|
+
this.#objectType = objectType || this.#objectType;
|
|
104
45
|
}
|
|
105
46
|
/**
|
|
106
47
|
* get unique id of the scripting object
|
|
107
48
|
*/
|
|
108
49
|
get id() {
|
|
109
|
-
return
|
|
50
|
+
return this.#id;
|
|
110
51
|
}
|
|
111
52
|
/**
|
|
112
53
|
* get type of the scripting object
|
|
113
54
|
*/
|
|
114
55
|
get objectType() {
|
|
115
|
-
return
|
|
56
|
+
return this.#objectType;
|
|
116
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* transform the scripting object to a format suitable for transmitting over window.postMessage
|
|
60
|
+
*
|
|
61
|
+
* @returns marshalled scripting object
|
|
62
|
+
*/
|
|
63
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
64
|
+
_toJSON = () => {
|
|
65
|
+
const functions = [];
|
|
66
|
+
const events = [];
|
|
67
|
+
Object.keys(this).forEach((property) => {
|
|
68
|
+
const value = this[property];
|
|
69
|
+
if ((0, import_event.isEvent)(value)) {
|
|
70
|
+
events.push(property);
|
|
71
|
+
} else if (isPublicFunction(value, property)) {
|
|
72
|
+
functions.push(property);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
objectId: this.#id,
|
|
77
|
+
objectType: this.#objectType,
|
|
78
|
+
functions,
|
|
79
|
+
events
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* dispose the scripting object
|
|
84
|
+
*/
|
|
85
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
86
|
+
_dispose = () => {
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* dispose the scripting object
|
|
90
|
+
*/
|
|
91
|
+
dispose = () => {
|
|
92
|
+
};
|
|
117
93
|
}
|
|
118
|
-
_id = new WeakMap();
|
|
119
|
-
_objectType = new WeakMap();
|
|
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,223 +16,196 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
16
|
return to;
|
|
18
17
|
};
|
|
19
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
var __accessCheck = (obj, member, msg) => {
|
|
25
|
-
if (!member.has(obj))
|
|
26
|
-
throw TypeError("Cannot " + msg);
|
|
27
|
-
};
|
|
28
|
-
var __privateGet = (obj, member, getter) => {
|
|
29
|
-
__accessCheck(obj, member, "read from private field");
|
|
30
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
31
|
-
};
|
|
32
|
-
var __privateAdd = (obj, member, value) => {
|
|
33
|
-
if (member.has(obj))
|
|
34
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
35
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
36
|
-
};
|
|
37
19
|
var scriptingObjectManager_exports = {};
|
|
38
20
|
__export(scriptingObjectManager_exports, {
|
|
39
21
|
ScriptingObjectManager: () => ScriptingObjectManager,
|
|
40
22
|
SecurityContext: () => SecurityContext
|
|
41
23
|
});
|
|
42
24
|
module.exports = __toCommonJS(scriptingObjectManager_exports);
|
|
43
|
-
var _scriptingObjects, _guestScriptingObjects, _addGuestScriptingObject, _disposeSO, _getGuestScriptingObject, _removeGuestScriptingObject, _attachCallContext;
|
|
44
25
|
var SecurityContext = /* @__PURE__ */ ((SecurityContext2) => {
|
|
45
26
|
SecurityContext2["USER"] = "USER";
|
|
46
27
|
SecurityContext2["PARTNER"] = "PARTNER";
|
|
47
28
|
return SecurityContext2;
|
|
48
29
|
})(SecurityContext || {});
|
|
49
30
|
class ScriptingObjectManager {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
sosInfo.forEach(__privateGet(this, _disposeSO));
|
|
97
|
-
}
|
|
98
|
-
__privateGet(this, _guestScriptingObjects).delete(guestId);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const moduleSOs = __privateGet(this, _guestScriptingObjects).get(guestId);
|
|
102
|
-
if (moduleSOs) {
|
|
103
|
-
const soInfo = moduleSOs.get(objectId);
|
|
104
|
-
if (soInfo)
|
|
105
|
-
__privateGet(this, _disposeSO).call(this, soInfo);
|
|
106
|
-
moduleSOs.delete(objectId);
|
|
107
|
-
}
|
|
108
|
-
} else if (objectId) {
|
|
109
|
-
__privateGet(this, _guestScriptingObjects).forEach((moduleSOs) => {
|
|
110
|
-
const soInfo = moduleSOs.get(objectId);
|
|
111
|
-
if (soInfo)
|
|
112
|
-
__privateGet(this, _disposeSO).call(this, soInfo);
|
|
113
|
-
moduleSOs.delete(objectId);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
/**
|
|
118
|
-
* attach guest context to the scripting object methods
|
|
119
|
-
*
|
|
120
|
-
* @param root0
|
|
121
|
-
* @param root0.so
|
|
122
|
-
* @param root0.guest
|
|
123
|
-
* @returns proxies scripting object that has call context set to the guest
|
|
124
|
-
*/
|
|
125
|
-
__privateAdd(this, _attachCallContext, ({
|
|
126
|
-
so,
|
|
127
|
-
guest
|
|
128
|
-
}) => new Proxy(so, {
|
|
129
|
-
get(target, prop, receiver) {
|
|
130
|
-
const value = target[prop];
|
|
131
|
-
if (value instanceof Function && prop !== "constructor") {
|
|
132
|
-
return function(...args) {
|
|
133
|
-
const proxyRef = this;
|
|
134
|
-
Object.defineProperty(value, "callContext", {
|
|
135
|
-
value: guest,
|
|
136
|
-
enumerable: false,
|
|
137
|
-
writable: true
|
|
138
|
-
});
|
|
139
|
-
return value.apply(proxyRef === receiver ? target : proxyRef, args);
|
|
140
|
-
};
|
|
31
|
+
/**
|
|
32
|
+
* collection of registered scripting objects
|
|
33
|
+
*/
|
|
34
|
+
#scriptingObjects = /* @__PURE__ */ new Map();
|
|
35
|
+
/**
|
|
36
|
+
* collection of proxied scripting objects for each guest
|
|
37
|
+
*/
|
|
38
|
+
#guestScriptingObjects = /* @__PURE__ */ new Map();
|
|
39
|
+
#addGuestScriptingObject = (params) => {
|
|
40
|
+
const { so, guestId } = params;
|
|
41
|
+
const objectId = so.id.toLowerCase();
|
|
42
|
+
const guestSOs = this.#guestScriptingObjects.get(guestId);
|
|
43
|
+
if (!guestSOs) {
|
|
44
|
+
this.#guestScriptingObjects.set(guestId, /* @__PURE__ */ new Map([[objectId, params]]));
|
|
45
|
+
} else {
|
|
46
|
+
if (guestSOs.has(objectId))
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Scripting Object ${so.id} already exists for guest ${guestId}`
|
|
49
|
+
);
|
|
50
|
+
guestSOs.set(objectId, params);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
#disposeSO = ({ so }) => {
|
|
54
|
+
if (so._dispose && typeof so._dispose === "function") {
|
|
55
|
+
so._dispose();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
#getGuestScriptingObject = ({
|
|
59
|
+
objectId,
|
|
60
|
+
guestId
|
|
61
|
+
}) => {
|
|
62
|
+
const moduleSOs = this.#guestScriptingObjects.get(guestId);
|
|
63
|
+
if (moduleSOs) {
|
|
64
|
+
return moduleSOs.get(objectId) ?? null;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
#removeGuestScriptingObject = ({
|
|
69
|
+
objectId,
|
|
70
|
+
guestId
|
|
71
|
+
} = {}) => {
|
|
72
|
+
if (guestId) {
|
|
73
|
+
if (!objectId) {
|
|
74
|
+
const sosInfo = this.#guestScriptingObjects.get(guestId);
|
|
75
|
+
if (sosInfo) {
|
|
76
|
+
sosInfo.forEach(this.#disposeSO);
|
|
141
77
|
}
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
}));
|
|
145
|
-
/**
|
|
146
|
-
* registers scripting object to the host
|
|
147
|
-
*
|
|
148
|
-
* @param so scripting object to register
|
|
149
|
-
* @param {AddScriptingObjectParams<ValueOf<AppObjects>>}
|
|
150
|
-
* @param params
|
|
151
|
-
*/
|
|
152
|
-
__publicField(this, "addScriptingObject", (so, params) => {
|
|
153
|
-
const { guestId } = params || {};
|
|
154
|
-
if (!so?.id || !so?._toJSON) {
|
|
155
|
-
throw new Error("Object is not derived from ScriptingObject");
|
|
156
|
-
}
|
|
157
|
-
const objectId = so.id.toLowerCase();
|
|
158
|
-
if (objectId === "module" && !guestId) {
|
|
159
|
-
throw new Error(`Guest id is required to add Module scripting object`);
|
|
160
|
-
}
|
|
161
|
-
if (guestId) {
|
|
162
|
-
__privateGet(this, _addGuestScriptingObject).call(this, { so, ...params, guestId });
|
|
78
|
+
this.#guestScriptingObjects.delete(guestId);
|
|
163
79
|
return;
|
|
164
80
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
});
|
|
169
|
-
/**
|
|
170
|
-
* Get reference to the scripting object proxy for a guest
|
|
171
|
-
*
|
|
172
|
-
* @param {string} objectId scripting object id
|
|
173
|
-
* @param {GuestContext} guest that is requesting the scripting object
|
|
174
|
-
* @returns proxied scripting object reference
|
|
175
|
-
*/
|
|
176
|
-
__publicField(this, "getObject", (objectId, guest) => {
|
|
177
|
-
const id = objectId.toLowerCase();
|
|
178
|
-
let soInfo = null;
|
|
179
|
-
if (guest?.id) {
|
|
180
|
-
soInfo = __privateGet(this, _getGuestScriptingObject).call(this, {
|
|
181
|
-
objectId: id,
|
|
182
|
-
guestId: guest.id
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
soInfo = soInfo ?? __privateGet(this, _scriptingObjects).get(id);
|
|
186
|
-
const { so } = soInfo || {};
|
|
187
|
-
if (!so)
|
|
188
|
-
return null;
|
|
189
|
-
if (!guest)
|
|
190
|
-
return so;
|
|
191
|
-
const guestSO = __privateGet(this, _attachCallContext).call(this, { so, guest });
|
|
192
|
-
Object.defineProperty(guestSO, "target", {
|
|
193
|
-
value: so,
|
|
194
|
-
enumerable: false,
|
|
195
|
-
configurable: false,
|
|
196
|
-
writable: true
|
|
197
|
-
});
|
|
198
|
-
return guestSO;
|
|
199
|
-
});
|
|
200
|
-
/**
|
|
201
|
-
* removes scripting object
|
|
202
|
-
*
|
|
203
|
-
* @param objectId unique id of the scripting object
|
|
204
|
-
* @param guestId unique id of the guest
|
|
205
|
-
*/
|
|
206
|
-
__publicField(this, "removeScriptingObject", (objectId, guestId) => {
|
|
207
|
-
const id = objectId.toLowerCase();
|
|
208
|
-
if (guestId) {
|
|
209
|
-
__privateGet(this, _removeGuestScriptingObject).call(this, { objectId: id, guestId });
|
|
210
|
-
} else {
|
|
211
|
-
__privateGet(this, _removeGuestScriptingObject).call(this, { objectId: id });
|
|
212
|
-
const soInfo = __privateGet(this, _scriptingObjects).get(id);
|
|
81
|
+
const moduleSOs = this.#guestScriptingObjects.get(guestId);
|
|
82
|
+
if (moduleSOs) {
|
|
83
|
+
const soInfo = moduleSOs.get(objectId);
|
|
213
84
|
if (soInfo)
|
|
214
|
-
|
|
215
|
-
|
|
85
|
+
this.#disposeSO(soInfo);
|
|
86
|
+
moduleSOs.delete(objectId);
|
|
216
87
|
}
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
88
|
+
} else if (objectId) {
|
|
89
|
+
this.#guestScriptingObjects.forEach((moduleSOs) => {
|
|
90
|
+
const soInfo = moduleSOs.get(objectId);
|
|
91
|
+
if (soInfo)
|
|
92
|
+
this.#disposeSO(soInfo);
|
|
93
|
+
moduleSOs.delete(objectId);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* attach guest context to the scripting object methods
|
|
99
|
+
*
|
|
100
|
+
* @param root0
|
|
101
|
+
* @param root0.so
|
|
102
|
+
* @param root0.guest
|
|
103
|
+
* @returns proxies scripting object that has call context set to the guest
|
|
104
|
+
*/
|
|
105
|
+
#attachCallContext = ({
|
|
106
|
+
so,
|
|
107
|
+
guest
|
|
108
|
+
}) => new Proxy(so, {
|
|
109
|
+
get(target, prop, receiver) {
|
|
110
|
+
const value = target[prop];
|
|
111
|
+
if (value instanceof Function && prop !== "constructor") {
|
|
112
|
+
return function(...args) {
|
|
113
|
+
const proxyRef = this;
|
|
114
|
+
Object.defineProperty(value, "callContext", {
|
|
115
|
+
value: guest,
|
|
116
|
+
enumerable: false,
|
|
117
|
+
writable: true
|
|
118
|
+
});
|
|
119
|
+
return value.apply(proxyRef === receiver ? target : proxyRef, args);
|
|
120
|
+
};
|
|
229
121
|
}
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
/**
|
|
126
|
+
* registers scripting object to the host
|
|
127
|
+
*
|
|
128
|
+
* @param so scripting object to register
|
|
129
|
+
* @param {AddScriptingObjectParams<ValueOf<AppObjects>>}
|
|
130
|
+
* @param params
|
|
131
|
+
*/
|
|
132
|
+
addScriptingObject = (so, params) => {
|
|
133
|
+
const { guestId } = params || {};
|
|
134
|
+
if (!so?.id || !so?._toJSON) {
|
|
135
|
+
throw new Error("Object is not derived from ScriptingObject");
|
|
136
|
+
}
|
|
137
|
+
const objectId = so.id.toLowerCase();
|
|
138
|
+
if (objectId === "module" && !guestId) {
|
|
139
|
+
throw new Error(`Guest id is required to add Module scripting object`);
|
|
140
|
+
}
|
|
141
|
+
if (guestId) {
|
|
142
|
+
this.#addGuestScriptingObject({ so, ...params, guestId });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (this.#scriptingObjects.has(objectId))
|
|
146
|
+
throw new Error(`Scripting Object ${so.id} already exists`);
|
|
147
|
+
this.#scriptingObjects.set(objectId, { so, ...params });
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Get reference to the scripting object proxy for a guest
|
|
151
|
+
*
|
|
152
|
+
* @param {string} objectId scripting object id
|
|
153
|
+
* @param {GuestContext} guest that is requesting the scripting object
|
|
154
|
+
* @returns proxied scripting object reference
|
|
155
|
+
*/
|
|
156
|
+
getObject = (objectId, guest) => {
|
|
157
|
+
const id = objectId.toLowerCase();
|
|
158
|
+
let soInfo = null;
|
|
159
|
+
if (guest?.id) {
|
|
160
|
+
soInfo = this.#getGuestScriptingObject({
|
|
161
|
+
objectId: id,
|
|
162
|
+
guestId: guest.id
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
soInfo = soInfo ?? this.#scriptingObjects.get(id);
|
|
166
|
+
const { so } = soInfo || {};
|
|
167
|
+
if (!so)
|
|
168
|
+
return null;
|
|
169
|
+
if (!guest)
|
|
170
|
+
return so;
|
|
171
|
+
const guestSO = this.#attachCallContext({ so, guest });
|
|
172
|
+
Object.defineProperty(guestSO, "target", {
|
|
173
|
+
value: so,
|
|
174
|
+
enumerable: false,
|
|
175
|
+
configurable: false,
|
|
176
|
+
writable: true
|
|
230
177
|
});
|
|
231
|
-
|
|
178
|
+
return guestSO;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* removes scripting object
|
|
182
|
+
*
|
|
183
|
+
* @param objectId unique id of the scripting object
|
|
184
|
+
* @param guestId unique id of the guest
|
|
185
|
+
*/
|
|
186
|
+
removeScriptingObject = (objectId, guestId) => {
|
|
187
|
+
const id = objectId.toLowerCase();
|
|
188
|
+
if (guestId) {
|
|
189
|
+
this.#removeGuestScriptingObject({ objectId: id, guestId });
|
|
190
|
+
} else {
|
|
191
|
+
this.#removeGuestScriptingObject({ objectId: id });
|
|
192
|
+
const soInfo = this.#scriptingObjects.get(id);
|
|
193
|
+
if (soInfo)
|
|
194
|
+
this.#disposeSO(soInfo);
|
|
195
|
+
this.#scriptingObjects.delete(id);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* removes all scripting objects
|
|
200
|
+
*
|
|
201
|
+
* @param guestId unique id of the guest
|
|
202
|
+
*/
|
|
203
|
+
removeAllScriptingObjects = (guestId) => {
|
|
204
|
+
if (!guestId) {
|
|
205
|
+
this.#scriptingObjects.forEach(this.#disposeSO);
|
|
206
|
+
this.#scriptingObjects.clear();
|
|
207
|
+
} else {
|
|
208
|
+
this.#removeGuestScriptingObject({ guestId });
|
|
209
|
+
}
|
|
210
|
+
};
|
|
232
211
|
}
|
|
233
|
-
_scriptingObjects = new WeakMap();
|
|
234
|
-
_guestScriptingObjects = new WeakMap();
|
|
235
|
-
_addGuestScriptingObject = new WeakMap();
|
|
236
|
-
_disposeSO = new WeakMap();
|
|
237
|
-
_getGuestScriptingObject = new WeakMap();
|
|
238
|
-
_removeGuestScriptingObject = new WeakMap();
|
|
239
|
-
_attachCallContext = new WeakMap();
|