@casual-simulation/aux-common 3.2.6 → 3.2.7-alpha.6227012901

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/Errors.d.ts +29 -0
  2. package/Errors.js +2 -0
  3. package/Errors.js.map +1 -0
  4. package/{aux-format-2 → bots}/AuxStateHelpers.d.ts +2 -33
  5. package/{aux-format-2 → bots}/AuxStateHelpers.js +1 -116
  6. package/bots/AuxStateHelpers.js.map +1 -0
  7. package/bots/Bot.d.ts +1 -1
  8. package/bots/BotCalculations.d.ts +4 -1
  9. package/bots/BotCalculations.js +62 -0
  10. package/bots/BotCalculations.js.map +1 -1
  11. package/bots/BotEvents.d.ts +859 -3401
  12. package/bots/BotEvents.js +133 -1529
  13. package/bots/BotEvents.js.map +1 -1
  14. package/bots/StateUpdatedEvent.d.ts +1 -1
  15. package/bots/StateUpdatedEvent.js +1 -1
  16. package/bots/StateUpdatedEvent.js.map +1 -1
  17. package/bots/index.d.ts +1 -0
  18. package/bots/index.js +1 -0
  19. package/bots/index.js.map +1 -1
  20. package/common/Action.d.ts +17 -0
  21. package/common/Action.js +2 -0
  22. package/common/Action.js.map +1 -0
  23. package/common/ConnectionIndicator.d.ts +29 -0
  24. package/common/ConnectionIndicator.js +23 -0
  25. package/common/ConnectionIndicator.js.map +1 -0
  26. package/common/ConnectionInfo.d.ts +30 -0
  27. package/common/ConnectionInfo.js +14 -0
  28. package/common/ConnectionInfo.js.map +1 -0
  29. package/common/ConnectionToken.d.ts +37 -0
  30. package/common/ConnectionToken.js +93 -0
  31. package/common/ConnectionToken.js.map +1 -0
  32. package/common/CurrentVersion.d.ts +26 -0
  33. package/common/CurrentVersion.js +2 -0
  34. package/common/CurrentVersion.js.map +1 -0
  35. package/common/Iterators.d.ts +19 -0
  36. package/common/Iterators.js +39 -0
  37. package/common/Iterators.js.map +1 -0
  38. package/common/LoadingProgress.d.ts +26 -0
  39. package/common/LoadingProgress.js +2 -0
  40. package/common/LoadingProgress.js.map +1 -0
  41. package/common/RemoteActions.d.ts +558 -0
  42. package/common/RemoteActions.js +128 -0
  43. package/common/RemoteActions.js.map +1 -0
  44. package/common/StatusUpdate.d.ts +108 -0
  45. package/common/StatusUpdate.js +2 -0
  46. package/common/StatusUpdate.js.map +1 -0
  47. package/common/StatusUpdateUtils.d.ts +3 -0
  48. package/common/StatusUpdateUtils.js +11 -0
  49. package/common/StatusUpdateUtils.js.map +1 -0
  50. package/common/index.d.ts +11 -0
  51. package/common/index.js +11 -0
  52. package/common/index.js.map +1 -0
  53. package/index.d.ts +4 -1
  54. package/index.js +4 -1
  55. package/index.js.map +1 -1
  56. package/package.json +3 -4
  57. package/partitions/AuxPartition.d.ts +1 -11
  58. package/partitions/AuxPartition.js.map +1 -1
  59. package/partitions/AuxPartitionConfig.d.ts +39 -123
  60. package/partitions/MemoryPartition.d.ts +2 -2
  61. package/partitions/MemoryPartition.js +2 -2
  62. package/partitions/MemoryPartition.js.map +1 -1
  63. package/partitions/OtherPlayersPartition.d.ts +6 -7
  64. package/partitions/OtherPlayersPartition.js +40 -54
  65. package/partitions/OtherPlayersPartition.js.map +1 -1
  66. package/partitions/PartitionUtils.d.ts +28 -1
  67. package/partitions/PartitionUtils.js +174 -1
  68. package/partitions/PartitionUtils.js.map +1 -1
  69. package/partitions/ProxyBridgePartition.d.ts +1 -3
  70. package/partitions/ProxyBridgePartition.js +0 -14
  71. package/partitions/ProxyBridgePartition.js.map +1 -1
  72. package/partitions/RemoteYjsPartition.d.ts +7 -6
  73. package/partitions/RemoteYjsPartition.js +55 -75
  74. package/partitions/RemoteYjsPartition.js.map +1 -1
  75. package/partitions/YjsPartition.d.ts +1 -2
  76. package/partitions/YjsPartition.js +3 -6
  77. package/partitions/YjsPartition.js.map +1 -1
  78. package/partitions/index.d.ts +1 -7
  79. package/partitions/index.js +1 -7
  80. package/partitions/index.js.map +1 -1
  81. package/test/FuzzingHelpers.d.ts +1 -1
  82. package/test/FuzzingHelpers.js +1 -1
  83. package/test/FuzzingHelpers.js.map +1 -1
  84. package/test/TestHelpers.d.ts +8 -0
  85. package/test/TestHelpers.js +23 -0
  86. package/test/TestHelpers.js.map +1 -1
  87. package/utils.d.ts +10 -5
  88. package/utils.js +19 -7
  89. package/utils.js.map +1 -1
  90. package/websockets/AuthenticatedConnectionClient.d.ts +26 -0
  91. package/websockets/AuthenticatedConnectionClient.js +61 -0
  92. package/websockets/AuthenticatedConnectionClient.js.map +1 -0
  93. package/websockets/ConnectionClient.d.ts +59 -0
  94. package/websockets/ConnectionClient.js +2 -0
  95. package/websockets/ConnectionClient.js.map +1 -0
  96. package/websockets/InstRecordsClient.d.ts +118 -0
  97. package/websockets/InstRecordsClient.js +387 -0
  98. package/websockets/InstRecordsClient.js.map +1 -0
  99. package/websockets/InstRecordsClientTimeSyncConnection.d.ts +13 -0
  100. package/websockets/InstRecordsClientTimeSyncConnection.js +16 -0
  101. package/websockets/InstRecordsClientTimeSyncConnection.js.map +1 -0
  102. package/websockets/MemoryConnectionClient.d.ts +19 -0
  103. package/websockets/MemoryConnectionClient.js +41 -0
  104. package/websockets/MemoryConnectionClient.js.map +1 -0
  105. package/websockets/WebsocketEvents.d.ts +2670 -0
  106. package/websockets/WebsocketEvents.js +189 -0
  107. package/websockets/WebsocketEvents.js.map +1 -0
  108. package/websockets/index.d.ts +7 -0
  109. package/websockets/index.js +7 -0
  110. package/websockets/index.js.map +1 -0
  111. package/yjs/YjsHelpers.d.ts +1 -1
  112. package/LoadingProgress.d.ts +0 -54
  113. package/LoadingProgress.js +0 -105
  114. package/LoadingProgress.js.map +0 -1
  115. package/aux-format-2/AuxCausalTree2.d.ts +0 -98
  116. package/aux-format-2/AuxCausalTree2.js +0 -616
  117. package/aux-format-2/AuxCausalTree2.js.map +0 -1
  118. package/aux-format-2/AuxOpTypes.d.ts +0 -268
  119. package/aux-format-2/AuxOpTypes.js +0 -240
  120. package/aux-format-2/AuxOpTypes.js.map +0 -1
  121. package/aux-format-2/AuxStateHelpers.js.map +0 -1
  122. package/aux-format-2/AuxWeaveHelpers.d.ts +0 -132
  123. package/aux-format-2/AuxWeaveHelpers.js +0 -335
  124. package/aux-format-2/AuxWeaveHelpers.js.map +0 -1
  125. package/aux-format-2/AuxWeaveReducer.d.ts +0 -37
  126. package/aux-format-2/AuxWeaveReducer.js +0 -980
  127. package/aux-format-2/AuxWeaveReducer.js.map +0 -1
  128. package/aux-format-2/index.d.ts +0 -7
  129. package/aux-format-2/index.js +0 -7
  130. package/aux-format-2/index.js.map +0 -1
  131. package/partitions/AuxPartitionRealtimeEditModeProvider.d.ts +0 -9
  132. package/partitions/AuxPartitionRealtimeEditModeProvider.js +0 -21
  133. package/partitions/AuxPartitionRealtimeEditModeProvider.js.map +0 -1
  134. package/partitions/BotClient.d.ts +0 -24
  135. package/partitions/BotClient.js +0 -2
  136. package/partitions/BotClient.js.map +0 -1
  137. package/partitions/BotPartition.d.ts +0 -45
  138. package/partitions/BotPartition.js +0 -186
  139. package/partitions/BotPartition.js.map +0 -1
  140. package/partitions/CausalRepoPartition.d.ts +0 -45
  141. package/partitions/CausalRepoPartition.js +0 -157
  142. package/partitions/CausalRepoPartition.js.map +0 -1
  143. package/partitions/MemoryBotClient.d.ts +0 -11
  144. package/partitions/MemoryBotClient.js +0 -41
  145. package/partitions/MemoryBotClient.js.map +0 -1
  146. package/partitions/RemoteCausalRepoHistoryPartition.d.ts +0 -53
  147. package/partitions/RemoteCausalRepoHistoryPartition.js +0 -206
  148. package/partitions/RemoteCausalRepoHistoryPartition.js.map +0 -1
  149. package/partitions/RemoteCausalRepoPartition.d.ts +0 -72
  150. package/partitions/RemoteCausalRepoPartition.js +0 -468
  151. package/partitions/RemoteCausalRepoPartition.js.map +0 -1
  152. package/runtime/AuxCompiler.d.ts +0 -258
  153. package/runtime/AuxCompiler.js +0 -722
  154. package/runtime/AuxCompiler.js.map +0 -1
  155. package/runtime/AuxDevice.d.ts +0 -28
  156. package/runtime/AuxDevice.js +0 -2
  157. package/runtime/AuxDevice.js.map +0 -1
  158. package/runtime/AuxGlobalContext.d.ts +0 -571
  159. package/runtime/AuxGlobalContext.js +0 -606
  160. package/runtime/AuxGlobalContext.js.map +0 -1
  161. package/runtime/AuxLibrary.d.ts +0 -2702
  162. package/runtime/AuxLibrary.js +0 -11046
  163. package/runtime/AuxLibrary.js.map +0 -1
  164. package/runtime/AuxLibraryDefinitions.def +0 -13139
  165. package/runtime/AuxRealtimeEditModeProvider.d.ts +0 -35
  166. package/runtime/AuxRealtimeEditModeProvider.js +0 -34
  167. package/runtime/AuxRealtimeEditModeProvider.js.map +0 -1
  168. package/runtime/AuxResults.d.ts +0 -77
  169. package/runtime/AuxResults.js +0 -6
  170. package/runtime/AuxResults.js.map +0 -1
  171. package/runtime/AuxRuntime.d.ts +0 -253
  172. package/runtime/AuxRuntime.js +0 -2700
  173. package/runtime/AuxRuntime.js.map +0 -1
  174. package/runtime/AuxRuntimeDynamicImports.d.ts +0 -14
  175. package/runtime/AuxRuntimeDynamicImports.js +0 -24
  176. package/runtime/AuxRuntimeDynamicImports.js.map +0 -1
  177. package/runtime/AuxVersion.d.ts +0 -39
  178. package/runtime/AuxVersion.js +0 -2
  179. package/runtime/AuxVersion.js.map +0 -1
  180. package/runtime/CasualOSError.d.ts +0 -37
  181. package/runtime/CasualOSError.js +0 -25
  182. package/runtime/CasualOSError.js.map +0 -1
  183. package/runtime/CompiledBot.d.ts +0 -106
  184. package/runtime/CompiledBot.js +0 -44
  185. package/runtime/CompiledBot.js.map +0 -1
  186. package/runtime/PerformanceNowPolyfill.d.ts +0 -1
  187. package/runtime/PerformanceNowPolyfill.js +0 -8
  188. package/runtime/PerformanceNowPolyfill.js.map +0 -1
  189. package/runtime/RuntimeBot.d.ts +0 -176
  190. package/runtime/RuntimeBot.js +0 -732
  191. package/runtime/RuntimeBot.js.map +0 -1
  192. package/runtime/RuntimeStateVersion.d.ts +0 -23
  193. package/runtime/RuntimeStateVersion.js +0 -22
  194. package/runtime/RuntimeStateVersion.js.map +0 -1
  195. package/runtime/Transpiler.d.ts +0 -174
  196. package/runtime/Transpiler.js +0 -611
  197. package/runtime/Transpiler.js.map +0 -1
  198. package/runtime/Utils.d.ts +0 -74
  199. package/runtime/Utils.js +0 -488
  200. package/runtime/Utils.js.map +0 -1
  201. package/runtime/index.d.ts +0 -9
  202. package/runtime/index.js +0 -9
  203. package/runtime/index.js.map +0 -1
  204. package/runtime/test/RuntimeTestHelpers.d.ts +0 -11
  205. package/runtime/test/RuntimeTestHelpers.js +0 -26
  206. package/runtime/test/RuntimeTestHelpers.js.map +0 -1
  207. package/runtime/test/TestScriptBotFactory.d.ts +0 -16
  208. package/runtime/test/TestScriptBotFactory.js +0 -107
  209. package/runtime/test/TestScriptBotFactory.js.map +0 -1
  210. /package/{runtime/BlobPolyfill.d.ts → BlobPolyfill.d.ts} +0 -0
  211. /package/{runtime/BlobPolyfill.js → BlobPolyfill.js} +0 -0
  212. /package/{runtime/BlobPolyfill.js.map → BlobPolyfill.js.map} +0 -0
@@ -1,732 +0,0 @@
1
- import { IS_PROXY_OBJECT, REGULAR_OBJECT, UNCOPIABLE, INTERPRETER_OBJECT, } from '@casual-simulation/js-interpreter/InterpreterUtils';
2
- import { applyTagEdit, isTagEdit, mergeEdits, remoteEdit, } from '../aux-format-2';
3
- import { BOT_SPACE_TAG, getBotSpace, getTagMaskSpaces, hasValue, DEFAULT_TAG_MASK_SPACE, TAG_MASK_SPACE_PRIORITIES_REVERSE, TAG_MASK_SPACE_PRIORITIES, CLEAR_CHANGES_SYMBOL, SET_TAG_MASK_SYMBOL, CLEAR_TAG_MASKS_SYMBOL, EDIT_TAG_SYMBOL, EDIT_TAG_MASK_SYMBOL, getOriginalObject, GET_TAG_MASKS_SYMBOL, } from '../bots';
4
- import { REPLACE_BOT_SYMBOL } from '../bots/Bot';
5
- import { createBotLink, isBot, isBotLink, ORIGINAL_OBJECT, } from '../bots/BotCalculations';
6
- import { INTERPRETABLE_FUNCTION } from './AuxCompiler';
7
- const KNOWN_SYMBOLS = new Set([
8
- REGULAR_OBJECT,
9
- INTERPRETER_OBJECT,
10
- INTERPRETABLE_FUNCTION,
11
- IS_PROXY_OBJECT,
12
- UNCOPIABLE,
13
- ]);
14
- /**
15
- * Adds any known symbols that the given target contains to the end of the given list of keys and returns a new list containing the combination of both.
16
- * @param target The target.
17
- * @param keys The keys that the symbols should be added to.
18
- */
19
- export function addKnownSymbolsToList(target, keys) {
20
- let result = keys;
21
- for (let symbol of KNOWN_SYMBOLS) {
22
- if (symbol in target) {
23
- if (result === keys) {
24
- result = [...keys];
25
- }
26
- result.push(symbol);
27
- }
28
- }
29
- return result;
30
- }
31
- /**
32
- * Flattens the given tag masks into a normal tags object.
33
- * Spaces are prioritized accoring to the TAG_MASK_SPACE_PRIORITIES_REVERSE list.
34
- * @param masks The masks to flatten.
35
- */
36
- export function flattenTagMasks(masks) {
37
- let result = {};
38
- if (masks) {
39
- for (let space of TAG_MASK_SPACE_PRIORITIES_REVERSE) {
40
- if (!!masks[space]) {
41
- Object.assign(result, masks[space]);
42
- }
43
- }
44
- }
45
- return result;
46
- }
47
- /**
48
- * Constructs a new script bot for the given bot.
49
- * Script bots provide special behaviors by implemlementing getters and setters for tag values as well
50
- * as handling extra compatibility concerns like serialization.
51
- *
52
- * @param bot The bot.
53
- * @param manager The service that is able to track updates on a bot.
54
- * @param context The global context.
55
- */
56
- export function createRuntimeBot(bot, manager) {
57
- if (!bot) {
58
- return null;
59
- }
60
- let replacement = null;
61
- const constantTags = {
62
- id: bot.id,
63
- space: getBotSpace(bot),
64
- };
65
- let changedRawTags = {};
66
- let rawTags = Object.assign({}, bot.tags);
67
- let rawMasks = flattenTagMasks(bot.masks || {});
68
- let rawLinks = {};
69
- let changedMasks = {};
70
- const arrayModifyMethods = new Set([
71
- 'push',
72
- 'shift',
73
- 'unshift',
74
- 'pop',
75
- 'splice',
76
- 'fill',
77
- 'sort',
78
- ]);
79
- // const arrayModifyProperties = new Set(['length']);
80
- const wrapValue = (tag, value) => {
81
- if (Array.isArray(value)) {
82
- const isTagValue = () => value === manager.getRawValue(bot, tag);
83
- const isMaskValue = () => value === manager.getTagMask(bot, tag);
84
- const proxy = new Proxy(value, {
85
- get(target, key, proxy) {
86
- if (arrayModifyMethods.has(key)) {
87
- const func = Reflect.get(target, key, proxy);
88
- return function () {
89
- const ret = func.apply(this, arguments);
90
- if (isMaskValue()) {
91
- updateTagMask(tag, value);
92
- }
93
- if (isTagValue()) {
94
- updateTag(tag, value);
95
- }
96
- return ret;
97
- };
98
- }
99
- return Reflect.get(target, key, proxy);
100
- },
101
- set(target, key, proxy) {
102
- const ret = Reflect.set(target, key, proxy);
103
- // if (arrayModifyProperties.has(key)) {
104
- if (isMaskValue()) {
105
- updateTagMask(tag, value);
106
- }
107
- if (isTagValue()) {
108
- updateTag(tag, value);
109
- }
110
- // }
111
- return ret;
112
- },
113
- });
114
- Object.defineProperty(proxy, ORIGINAL_OBJECT, {
115
- configurable: true,
116
- enumerable: false,
117
- writable: false,
118
- value: value,
119
- });
120
- return proxy;
121
- }
122
- return value;
123
- };
124
- const tagsProxy = new Proxy(rawTags, {
125
- get(target, key, proxy) {
126
- if (replacement) {
127
- return Reflect.get(replacement.tags, key, replacement.tags);
128
- }
129
- if (typeof key === 'symbol') {
130
- return Reflect.get(target, key, proxy);
131
- }
132
- if (key === 'toJSON') {
133
- return Reflect.get(target, key, proxy);
134
- }
135
- else if (key in constantTags) {
136
- return constantTags[key];
137
- }
138
- return wrapValue(key, manager.getValue(bot, key));
139
- },
140
- set(target, key, value, receiver) {
141
- if (replacement) {
142
- return Reflect.set(replacement.tags, key, value, replacement.tags);
143
- }
144
- if (typeof key === 'symbol' && KNOWN_SYMBOLS.has(key)) {
145
- return Reflect.set(target, key, value, receiver);
146
- }
147
- if (key in constantTags) {
148
- return true;
149
- }
150
- updateTag(key, getOriginalObject(value));
151
- return true;
152
- },
153
- deleteProperty(target, key) {
154
- if (replacement) {
155
- return Reflect.deleteProperty(replacement.tags, key);
156
- }
157
- if (typeof key === 'symbol' && KNOWN_SYMBOLS.has(key)) {
158
- return Reflect.deleteProperty(target, key);
159
- }
160
- if (key in constantTags) {
161
- return true;
162
- }
163
- const value = null;
164
- updateTag(key, value);
165
- return true;
166
- },
167
- ownKeys(target) {
168
- if (replacement) {
169
- return Reflect.ownKeys(replacement.tags);
170
- }
171
- const keys = Object.keys(bot.values);
172
- return addKnownSymbolsToList(target, keys);
173
- },
174
- getOwnPropertyDescriptor(target, property) {
175
- if (replacement) {
176
- return Reflect.getOwnPropertyDescriptor(replacement.tags, property);
177
- }
178
- if (typeof property === 'symbol') {
179
- return Reflect.getOwnPropertyDescriptor(target, property);
180
- }
181
- if (property === 'toJSON') {
182
- return Reflect.getOwnPropertyDescriptor(target, property);
183
- }
184
- return Reflect.getOwnPropertyDescriptor(bot.values, property);
185
- },
186
- });
187
- const rawProxy = new Proxy(rawTags, {
188
- get(target, key, proxy) {
189
- if (replacement) {
190
- return Reflect.get(replacement.raw, key, replacement.raw);
191
- }
192
- if (typeof key === 'symbol') {
193
- return Reflect.get(target, key, proxy);
194
- }
195
- if (key in constantTags) {
196
- return constantTags[key];
197
- }
198
- return manager.getRawValue(bot, key);
199
- },
200
- set(target, key, value, receiver) {
201
- if (replacement) {
202
- return Reflect.set(replacement.raw, key, value, replacement.raw);
203
- }
204
- if (typeof key === 'symbol' && KNOWN_SYMBOLS.has(key)) {
205
- return Reflect.set(target, key, value, receiver);
206
- }
207
- if (key in constantTags) {
208
- return true;
209
- }
210
- updateTag(key, getOriginalObject(value));
211
- return true;
212
- },
213
- deleteProperty(target, key) {
214
- if (replacement) {
215
- return Reflect.deleteProperty(replacement.raw, key);
216
- }
217
- if (typeof key === 'symbol' && KNOWN_SYMBOLS.has(key)) {
218
- return Reflect.deleteProperty(target, key);
219
- }
220
- if (key in constantTags) {
221
- return true;
222
- }
223
- const value = null;
224
- updateTag(key, value);
225
- return true;
226
- },
227
- ownKeys(target) {
228
- if (replacement) {
229
- return Reflect.ownKeys(replacement.raw);
230
- }
231
- const keys = Object.keys(bot.tags);
232
- return addKnownSymbolsToList(target, keys);
233
- },
234
- getOwnPropertyDescriptor(target, property) {
235
- if (replacement) {
236
- return Reflect.getOwnPropertyDescriptor(replacement.raw, property);
237
- }
238
- if (typeof property === 'symbol') {
239
- return Reflect.getOwnPropertyDescriptor(target, property);
240
- }
241
- if (property === 'toJSON') {
242
- return Reflect.getOwnPropertyDescriptor(target, property);
243
- }
244
- return Reflect.getOwnPropertyDescriptor(bot.tags, property);
245
- },
246
- });
247
- const listenersProxy = new Proxy(bot.listeners, {
248
- get(target, key, proxy) {
249
- if (replacement) {
250
- return Reflect.get(replacement.listeners, key, replacement.listeners);
251
- }
252
- if (typeof key === 'symbol') {
253
- return Reflect.get(target, key, proxy);
254
- }
255
- if (key in constantTags) {
256
- return null;
257
- }
258
- return manager.getListener(bot, key);
259
- },
260
- });
261
- const signatures = bot.signatures || {};
262
- const signaturesProxy = new Proxy(signatures, {
263
- get(target, key, proxy) {
264
- if (replacement) {
265
- return Reflect.get(replacement.signatures, key, replacement.signatures);
266
- }
267
- if (typeof key === 'symbol') {
268
- return Reflect.get(target, key, proxy);
269
- }
270
- if (key in constantTags) {
271
- return constantTags[key];
272
- }
273
- return manager.getSignature(bot, key);
274
- },
275
- set(target, key, proxy) {
276
- return true;
277
- },
278
- deleteProperty(target, key) {
279
- return true;
280
- },
281
- ownKeys(target) {
282
- if (replacement) {
283
- return Reflect.ownKeys(replacement.signatures);
284
- }
285
- return Reflect.ownKeys(target);
286
- },
287
- getOwnPropertyDescriptor(target, property) {
288
- if (replacement) {
289
- return Reflect.getOwnPropertyDescriptor(replacement.signatures, property);
290
- }
291
- return Reflect.getOwnPropertyDescriptor(target, property);
292
- },
293
- });
294
- const maskProxy = new Proxy(rawMasks, {
295
- get(target, key, proxy) {
296
- if (replacement) {
297
- return Reflect.get(replacement.masks, key, replacement.masks);
298
- }
299
- if (typeof key === 'symbol') {
300
- return Reflect.get(target, key, proxy);
301
- }
302
- return wrapValue(key, manager.getTagMask(bot, key));
303
- },
304
- set(target, key, value, proxy) {
305
- if (replacement) {
306
- return Reflect.set(replacement.masks, key, value, replacement.masks);
307
- }
308
- if (typeof key === 'symbol' && KNOWN_SYMBOLS.has(key)) {
309
- return Reflect.set(target, key, value, proxy);
310
- }
311
- if (key in constantTags) {
312
- return true;
313
- }
314
- updateTagMask(key, getOriginalObject(value));
315
- return true;
316
- },
317
- deleteProperty(target, key) {
318
- if (replacement) {
319
- return Reflect.deleteProperty(replacement.masks, key);
320
- }
321
- if (typeof key === 'symbol' && KNOWN_SYMBOLS.has(key)) {
322
- return Reflect.deleteProperty(target, key);
323
- }
324
- if (key in constantTags) {
325
- return true;
326
- }
327
- const spaces = getTagMaskSpaces(bot, key);
328
- const config = manager.updateTagMask(bot, key, spaces, null);
329
- if (config.mode === RealtimeEditMode.Immediate) {
330
- delete rawMasks[key];
331
- }
332
- changeTagMask(key, config.changedValue, spaces);
333
- return true;
334
- },
335
- ownKeys(target) {
336
- if (replacement) {
337
- return Reflect.ownKeys(replacement.masks);
338
- }
339
- const keys = Object.keys(flattenTagMasks(bot.masks));
340
- return addKnownSymbolsToList(target, keys);
341
- },
342
- getOwnPropertyDescriptor(target, property) {
343
- if (replacement) {
344
- return Reflect.getOwnPropertyDescriptor(replacement.masks, property);
345
- }
346
- if (typeof property === 'symbol') {
347
- return Reflect.getOwnPropertyDescriptor(target, property);
348
- }
349
- if (property === 'toJSON') {
350
- return Reflect.getOwnPropertyDescriptor(target, property);
351
- }
352
- const flat = flattenTagMasks(bot.masks);
353
- return Reflect.getOwnPropertyDescriptor(flat, property);
354
- },
355
- });
356
- const linkProxy = new Proxy(rawLinks, {
357
- set(target, key, value, proxy) {
358
- if (replacement) {
359
- return Reflect.set(replacement.links, key, value, replacement.links);
360
- }
361
- if (typeof key === 'symbol' && KNOWN_SYMBOLS.has(key)) {
362
- return Reflect.set(target, key, value, proxy);
363
- }
364
- if (key in constantTags) {
365
- return true;
366
- }
367
- if (isBot(value)) {
368
- updateTag(key, createBotLink([value.id]));
369
- }
370
- else if (Array.isArray(value)) {
371
- const tagValue = value.map((v) => (isBot(v) ? v.id : null));
372
- updateTag(key, createBotLink(tagValue));
373
- }
374
- else if (isBotLink(value)) {
375
- updateTag(key, value);
376
- }
377
- else if (typeof value === 'string') {
378
- updateTag(key, createBotLink([value]));
379
- }
380
- else if (!hasValue(value) &&
381
- isBotLink(manager.getValue(bot, key))) {
382
- updateTag(key, value);
383
- }
384
- return true;
385
- },
386
- get(target, key, proxy) {
387
- if (replacement) {
388
- return Reflect.get(replacement.links, key, replacement.links);
389
- }
390
- if (typeof key === 'symbol') {
391
- return Reflect.get(target, key, proxy);
392
- }
393
- if (key === 'toJSON') {
394
- return Reflect.get(target, key, proxy);
395
- }
396
- else if (key in constantTags) {
397
- return undefined;
398
- }
399
- return manager.getTagLink(bot, key);
400
- },
401
- ownKeys(target) {
402
- if (replacement) {
403
- return Reflect.ownKeys(replacement.links);
404
- }
405
- const keys = Object.keys(bot.values);
406
- return addKnownSymbolsToList(target, keys.filter((key) => {
407
- return isBotLink(manager.getValue(bot, key));
408
- }));
409
- },
410
- deleteProperty(target, key) {
411
- if (replacement) {
412
- return Reflect.deleteProperty(replacement.links, key);
413
- }
414
- if (typeof key === 'symbol' && KNOWN_SYMBOLS.has(key)) {
415
- return Reflect.deleteProperty(target, key);
416
- }
417
- if (key in constantTags) {
418
- return true;
419
- }
420
- if (isBotLink(manager.getValue(bot, key))) {
421
- const value = null;
422
- updateTag(key, value);
423
- }
424
- return true;
425
- },
426
- getOwnPropertyDescriptor(target, property) {
427
- if (replacement) {
428
- return Reflect.getOwnPropertyDescriptor(replacement.links, property);
429
- }
430
- if (typeof property === 'symbol') {
431
- return Reflect.getOwnPropertyDescriptor(target, property);
432
- }
433
- if (property === 'toJSON') {
434
- return Reflect.getOwnPropertyDescriptor(target, property);
435
- }
436
- if (isBotLink(manager.getValue(bot, property))) {
437
- return Reflect.getOwnPropertyDescriptor(bot.values, property);
438
- }
439
- return undefined;
440
- },
441
- });
442
- // Define a toJSON() function but
443
- // make it not enumerable so it is not included
444
- // in Object.keys() and for..in expressions.
445
- Object.defineProperty(tagsProxy, 'toJSON', {
446
- value: () => bot.tags,
447
- writable: false,
448
- enumerable: false,
449
- // This is so the function can be wrapped with another proxy
450
- // if needed. (Like for VM2Sandbox)
451
- configurable: true,
452
- });
453
- Object.defineProperty(linkProxy, 'toJSON', {
454
- value: () => {
455
- const linkKeys = Object.keys(linkProxy);
456
- let result = {};
457
- for (let key of linkKeys) {
458
- result[key] = manager.getValue(bot, key);
459
- }
460
- return result;
461
- },
462
- writable: false,
463
- enumerable: false,
464
- configurable: true,
465
- });
466
- let script = {
467
- id: bot.id,
468
- link: createBotLink([bot.id]),
469
- tags: tagsProxy,
470
- raw: rawProxy,
471
- masks: maskProxy,
472
- links: linkProxy,
473
- vars: {},
474
- changes: changedRawTags,
475
- maskChanges: changedMasks,
476
- listeners: listenersProxy,
477
- signatures: signaturesProxy,
478
- [CLEAR_CHANGES_SYMBOL]: null,
479
- [SET_TAG_MASK_SYMBOL]: null,
480
- [GET_TAG_MASKS_SYMBOL]: null,
481
- [CLEAR_TAG_MASKS_SYMBOL]: null,
482
- [EDIT_TAG_SYMBOL]: null,
483
- [EDIT_TAG_MASK_SYMBOL]: null,
484
- [REPLACE_BOT_SYMBOL]: null,
485
- };
486
- Object.defineProperty(script, CLEAR_CHANGES_SYMBOL, {
487
- value: () => {
488
- changedRawTags = {};
489
- changedMasks = {};
490
- script.changes = changedRawTags;
491
- script.maskChanges = changedMasks;
492
- },
493
- configurable: true,
494
- enumerable: false,
495
- writable: false,
496
- });
497
- Object.defineProperty(script, SET_TAG_MASK_SYMBOL, {
498
- value: (key, value, space) => {
499
- if (key in constantTags) {
500
- return true;
501
- }
502
- const spaces = !hasValue(space)
503
- ? hasValue(value)
504
- ? [DEFAULT_TAG_MASK_SPACE]
505
- : getTagMaskSpaces(bot, key)
506
- : [space];
507
- const valueToSet = getOriginalObject(value);
508
- const config = manager.updateTagMask(bot, key, spaces, valueToSet);
509
- if (config.mode === RealtimeEditMode.Immediate) {
510
- rawMasks[key] = valueToSet;
511
- }
512
- changeTagMask(key, config.changedValue, spaces);
513
- return value;
514
- },
515
- configurable: true,
516
- enumerable: false,
517
- writable: false,
518
- });
519
- Object.defineProperty(script, GET_TAG_MASKS_SYMBOL, {
520
- value: () => {
521
- let masks = {};
522
- if (bot.masks) {
523
- for (let space in bot.masks) {
524
- let spaceMasks = {};
525
- let hasSpaceMasks = false;
526
- const botMasks = bot.masks[space];
527
- for (let tag in botMasks) {
528
- const val = botMasks[tag];
529
- if (hasValue(val)) {
530
- hasSpaceMasks = true;
531
- spaceMasks[tag] = val;
532
- }
533
- }
534
- if (hasSpaceMasks) {
535
- masks[space] = spaceMasks;
536
- }
537
- }
538
- }
539
- return masks;
540
- },
541
- configurable: true,
542
- enumerable: false,
543
- writable: false,
544
- });
545
- Object.defineProperty(script, CLEAR_TAG_MASKS_SYMBOL, {
546
- value: (space) => {
547
- if (bot.masks) {
548
- let spaces = hasValue(space)
549
- ? [space]
550
- : TAG_MASK_SPACE_PRIORITIES;
551
- for (let space of spaces) {
552
- const tags = bot.masks[space];
553
- for (let tag in tags) {
554
- script[SET_TAG_MASK_SYMBOL](tag, null, space);
555
- }
556
- }
557
- }
558
- },
559
- configurable: true,
560
- enumerable: false,
561
- writable: false,
562
- });
563
- Object.defineProperty(script, EDIT_TAG_SYMBOL, {
564
- value: (tag, ops) => {
565
- if (tag in constantTags) {
566
- return;
567
- }
568
- const e = remoteEdit(manager.currentVersion.vector, ...ops);
569
- script.tags[tag] = e;
570
- },
571
- configurable: true,
572
- enumerable: false,
573
- writable: false,
574
- });
575
- Object.defineProperty(script, EDIT_TAG_MASK_SYMBOL, {
576
- value: (tag, ops, space) => {
577
- if (tag in constantTags) {
578
- return;
579
- }
580
- const e = remoteEdit(manager.currentVersion.vector, ...ops);
581
- if (!hasValue(space)) {
582
- const availableSpaces = getTagMaskSpaces(bot, tag);
583
- if (availableSpaces.length <= 0) {
584
- space = DEFAULT_TAG_MASK_SPACE;
585
- }
586
- else {
587
- for (let possibleSpace of TAG_MASK_SPACE_PRIORITIES) {
588
- if (availableSpaces.indexOf(possibleSpace) >= 0) {
589
- space = possibleSpace;
590
- break;
591
- }
592
- }
593
- }
594
- }
595
- script[SET_TAG_MASK_SYMBOL](tag, e, space);
596
- },
597
- configurable: true,
598
- enumerable: false,
599
- writable: false,
600
- });
601
- Object.defineProperty(script, REPLACE_BOT_SYMBOL, {
602
- value: (bot) => {
603
- if (bot === scriptProxy) {
604
- throw new Error('Cannot replace a bot with itself!');
605
- }
606
- if (!replacement) {
607
- replacement = bot;
608
- bot.vars = script.vars;
609
- }
610
- else {
611
- replacement[REPLACE_BOT_SYMBOL](bot);
612
- }
613
- },
614
- configurable: true,
615
- enumerable: false,
616
- writable: false,
617
- });
618
- Object.defineProperty(script, 'toJSON', {
619
- value: () => {
620
- if ('space' in bot) {
621
- return {
622
- id: bot.id,
623
- space: bot.space,
624
- tags: tagsProxy,
625
- };
626
- }
627
- else {
628
- return {
629
- id: bot.id,
630
- tags: tagsProxy,
631
- };
632
- }
633
- },
634
- writable: false,
635
- enumerable: false,
636
- // This is so the function can be wrapped with another proxy
637
- // if needed. (Like for VM2Sandbox)
638
- configurable: true,
639
- });
640
- if (BOT_SPACE_TAG in bot) {
641
- script.space = bot.space;
642
- }
643
- const scriptProxy = new Proxy(script, {
644
- get(target, prop, reciever) {
645
- if (replacement) {
646
- return Reflect.get(replacement, prop, replacement);
647
- }
648
- if (prop in target) {
649
- return Reflect.get(target, prop, reciever);
650
- }
651
- else if (typeof prop === 'string') {
652
- const listener = manager.getListener(bot, prop);
653
- if (listener) {
654
- return listener;
655
- }
656
- }
657
- return undefined;
658
- },
659
- });
660
- return scriptProxy;
661
- function updateTag(tag, value) {
662
- const { mode, changedValue } = manager.updateTag(bot, tag, value);
663
- if (mode === RealtimeEditMode.Immediate) {
664
- rawTags[tag] = value;
665
- changeTag(tag, changedValue);
666
- }
667
- else if (mode === RealtimeEditMode.Delayed) {
668
- changeTag(tag, changedValue);
669
- }
670
- }
671
- function updateTagMask(tag, value) {
672
- const spaces = hasValue(value)
673
- ? [DEFAULT_TAG_MASK_SPACE]
674
- : getTagMaskSpaces(bot, tag);
675
- const { mode, changedValue } = manager.updateTagMask(bot, tag, spaces, value);
676
- if (mode === RealtimeEditMode.Immediate) {
677
- rawMasks[tag] = value;
678
- }
679
- changeTagMask(tag, changedValue, spaces);
680
- }
681
- function changeTag(tag, value) {
682
- if (isTagEdit(value)) {
683
- const currentValue = changedRawTags[tag];
684
- if (isTagEdit(currentValue)) {
685
- value = mergeEdits(currentValue, value);
686
- }
687
- else if (hasValue(currentValue)) {
688
- value = applyTagEdit(currentValue, value);
689
- }
690
- }
691
- changedRawTags[tag] = value;
692
- }
693
- function changeTagMask(tag, value, spaces) {
694
- for (let space of spaces) {
695
- if (!changedMasks[space]) {
696
- changedMasks[space] = {};
697
- }
698
- if (isTagEdit(value)) {
699
- const currentValue = changedMasks[space][tag];
700
- if (isTagEdit(currentValue)) {
701
- value = mergeEdits(currentValue, value);
702
- }
703
- else if (hasValue(currentValue)) {
704
- value = applyTagEdit(currentValue, value);
705
- }
706
- }
707
- changedMasks[space][tag] = value;
708
- }
709
- }
710
- }
711
- /**
712
- * The list of possible realtime edit modes.
713
- */
714
- export var RealtimeEditMode;
715
- (function (RealtimeEditMode) {
716
- /**
717
- * Specifies that bots in this edit mode cannot be edited.
718
- */
719
- RealtimeEditMode[RealtimeEditMode["None"] = 0] = "None";
720
- /**
721
- * Specifies that all changes to the bot will be accepted.
722
- * This allows the changes to be immediately used.
723
- */
724
- RealtimeEditMode[RealtimeEditMode["Immediate"] = 1] = "Immediate";
725
- /**
726
- * Specifies that some changes to the bot may be rejected.
727
- * This requires that changes be delayed until the related
728
- * partition accepts/denies them.
729
- */
730
- RealtimeEditMode[RealtimeEditMode["Delayed"] = 2] = "Delayed";
731
- })(RealtimeEditMode || (RealtimeEditMode = {}));
732
- //# sourceMappingURL=RuntimeBot.js.map