@dronedeploy/rocos-js-sdk 3.0.1-alpha.8 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (378) hide show
  1. package/README.md +59 -29
  2. package/cjs/IRocosSDK.d.ts +4 -3
  3. package/cjs/RocosSDK.d.ts +19 -7
  4. package/cjs/RocosSDK.js +31 -10
  5. package/cjs/api/streams/caller/CallerStream.js +5 -2
  6. package/cjs/api/streams/caller/CallerStreamNode.js +2 -1
  7. package/cjs/api/streams/command/CommandStream.js +5 -2
  8. package/cjs/api/streams/command/CommandStreamNode.js +2 -1
  9. package/cjs/api/streams/control/ControlStream.js +5 -2
  10. package/cjs/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  11. package/cjs/api/streams/control/ControlStreamNode.js +2 -1
  12. package/cjs/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  13. package/cjs/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  14. package/cjs/api/streams/search/SearchStream.js +5 -2
  15. package/cjs/api/streams/search/SearchStreamNode.js +2 -1
  16. package/cjs/api/streams/telemetry/TelemetryStream.js +4 -1
  17. package/cjs/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  18. package/cjs/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  19. package/cjs/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  20. package/cjs/constants/api.d.ts +31 -15
  21. package/cjs/constants/api.js +35 -18
  22. package/cjs/helpers/cleanObject.js +4 -1
  23. package/cjs/helpers/getUniqueConfigKey.d.ts +6 -2
  24. package/cjs/helpers/getUniqueConfigKey.js +7 -2
  25. package/cjs/helpers/index.d.ts +1 -0
  26. package/cjs/helpers/index.js +1 -0
  27. package/cjs/helpers/kscript/Context.d.ts +34 -0
  28. package/cjs/helpers/kscript/Context.js +52 -0
  29. package/cjs/helpers/kscript/index.d.ts +1 -0
  30. package/cjs/helpers/kscript/index.js +27 -0
  31. package/cjs/helpers/kscript/kscript.d.ts +6 -0
  32. package/cjs/helpers/kscript/kscript.js +115 -0
  33. package/cjs/helpers/kscript/nodes/Identifier.d.ts +12 -0
  34. package/cjs/helpers/kscript/nodes/Identifier.js +20 -0
  35. package/cjs/helpers/kscript/nodes/Literal.d.ts +11 -0
  36. package/cjs/helpers/kscript/nodes/Literal.js +22 -0
  37. package/cjs/helpers/kscript/nodes/Node.d.ts +9 -0
  38. package/cjs/helpers/kscript/nodes/Node.js +15 -0
  39. package/cjs/helpers/kscript/nodes/Program.d.ts +11 -0
  40. package/cjs/helpers/kscript/nodes/Program.js +24 -0
  41. package/cjs/helpers/kscript/nodes/TemplateLiteral.d.ts +23 -0
  42. package/cjs/helpers/kscript/nodes/TemplateLiteral.js +35 -0
  43. package/cjs/helpers/kscript/nodes/expressions/ArrayExpression.d.ts +7 -0
  44. package/cjs/helpers/kscript/nodes/expressions/ArrayExpression.js +31 -0
  45. package/cjs/helpers/kscript/nodes/expressions/ArrowFunctionExpression.d.ts +14 -0
  46. package/cjs/helpers/kscript/nodes/expressions/ArrowFunctionExpression.js +40 -0
  47. package/cjs/helpers/kscript/nodes/expressions/BinaryExpression.d.ts +16 -0
  48. package/cjs/helpers/kscript/nodes/expressions/BinaryExpression.js +104 -0
  49. package/cjs/helpers/kscript/nodes/expressions/CallExpression.d.ts +8 -0
  50. package/cjs/helpers/kscript/nodes/expressions/CallExpression.js +38 -0
  51. package/cjs/helpers/kscript/nodes/expressions/ChainExpression.d.ts +16 -0
  52. package/cjs/helpers/kscript/nodes/expressions/ChainExpression.js +25 -0
  53. package/cjs/helpers/kscript/nodes/expressions/ConditionalExpression.d.ts +14 -0
  54. package/cjs/helpers/kscript/nodes/expressions/ConditionalExpression.js +30 -0
  55. package/cjs/helpers/kscript/nodes/expressions/ExpressionStatement.d.ts +7 -0
  56. package/cjs/helpers/kscript/nodes/expressions/ExpressionStatement.js +18 -0
  57. package/cjs/helpers/kscript/nodes/expressions/LogicalExpression.d.ts +10 -0
  58. package/cjs/helpers/kscript/nodes/expressions/LogicalExpression.js +47 -0
  59. package/cjs/helpers/kscript/nodes/expressions/MemberExpression.d.ts +44 -0
  60. package/cjs/helpers/kscript/nodes/expressions/MemberExpression.js +98 -0
  61. package/cjs/helpers/kscript/nodes/expressions/ObjectExpression.d.ts +11 -0
  62. package/cjs/helpers/kscript/nodes/expressions/ObjectExpression.js +59 -0
  63. package/cjs/helpers/kscript/nodes/expressions/UnaryExpression.d.ts +12 -0
  64. package/cjs/helpers/kscript/nodes/expressions/UnaryExpression.js +44 -0
  65. package/cjs/helpers/kscript/nodes/expressions/index.d.ts +11 -0
  66. package/cjs/helpers/kscript/nodes/expressions/index.js +28 -0
  67. package/cjs/helpers/kscript/nodes/index.d.ts +4 -0
  68. package/cjs/helpers/kscript/nodes/index.js +10 -0
  69. package/cjs/helpers/kscript/nodes/nodeTypes.d.ts +33 -0
  70. package/cjs/helpers/kscript/nodes/nodeTypes.js +29 -0
  71. package/cjs/helpers/kscript/utils.d.ts +4 -0
  72. package/cjs/helpers/kscript/utils.js +15 -0
  73. package/cjs/helpers/websandbox/connection.d.ts +2 -1
  74. package/cjs/helpers/websandbox/connection.js +6 -5
  75. package/cjs/helpers/websandbox/frame/frame.js +4 -1
  76. package/cjs/helpers/websandbox/frame/frame.source.js +1 -1
  77. package/cjs/helpers/websandbox/frame/worker/manager.d.ts +8 -4
  78. package/cjs/helpers/websandbox/frame/worker/manager.js +32 -14
  79. package/cjs/helpers/websandbox/frame/worker/worker.source.js +1 -1
  80. package/cjs/helpers/websandbox/sandbox.d.ts +1 -1
  81. package/cjs/helpers/websandbox/sandbox.js +7 -7
  82. package/cjs/models/IConnectedCallsign.d.ts +10 -0
  83. package/cjs/models/IConnectedCallsign.js +8 -0
  84. package/cjs/models/RocosError.d.ts +3 -0
  85. package/cjs/models/RocosError.js +3 -0
  86. package/cjs/models/ServiceEnum.d.ts +20 -17
  87. package/cjs/models/ServiceEnum.js +20 -17
  88. package/cjs/models/TelemetryStatus.d.ts +12 -0
  89. package/cjs/models/TelemetryStatus.js +17 -0
  90. package/cjs/models/Token.d.ts +2 -2
  91. package/cjs/models/Token.js +5 -5
  92. package/cjs/models/asset-storage/{AssetModelItem.d.ts → AssetItem.d.ts} +2 -0
  93. package/cjs/models/asset-storage/SyncIntegrations.d.ts +1 -1
  94. package/cjs/models/device-credentials/DeviceCredentials.d.ts +61 -0
  95. package/cjs/models/device-credentials/DeviceCredentials.js +2 -0
  96. package/cjs/models/graph/Position.d.ts +6 -0
  97. package/cjs/models/graph/Position.js +2 -0
  98. package/cjs/models/graph/Quaternion.d.ts +6 -0
  99. package/cjs/models/graph/Quaternion.js +2 -0
  100. package/cjs/models/graph/Vector3.d.ts +5 -0
  101. package/cjs/models/graph/Vector3.js +2 -0
  102. package/cjs/models/graph/index.d.ts +3 -0
  103. package/cjs/models/graph/index.js +19 -0
  104. package/cjs/models/index.d.ts +9 -2
  105. package/cjs/models/index.js +9 -2
  106. package/cjs/models/integrations/Location.d.ts +24 -0
  107. package/cjs/models/integrations/Location.js +2 -0
  108. package/cjs/models/integrations/PaginatedResults.d.ts +4 -0
  109. package/cjs/models/integrations/PaginatedResults.js +2 -0
  110. package/cjs/models/maps/Panorama.d.ts +12 -21
  111. package/cjs/models/projects/ExternalProject.d.ts +10 -0
  112. package/cjs/models/projects/ExternalProject.js +2 -0
  113. package/cjs/models/projects/NewProjectRequest.d.ts +8 -0
  114. package/cjs/models/projects/NewProjectRequest.js +2 -0
  115. package/cjs/models/target/Target.d.ts +30 -0
  116. package/cjs/models/target/Target.js +15 -0
  117. package/cjs/node/RocosSDKNode.d.ts +1 -5
  118. package/cjs/node/RocosSDKNode.js +9 -9
  119. package/cjs/services/AssetStorageService.d.ts +19 -19
  120. package/cjs/services/AssetStorageService.js +20 -9
  121. package/cjs/services/AuthService.d.ts +12 -1
  122. package/cjs/services/AuthService.js +25 -1
  123. package/cjs/services/BaseServiceAbstract.d.ts +1 -1
  124. package/cjs/services/BaseServiceAbstract.js +2 -2
  125. package/cjs/services/DeviceCredentialsService.d.ts +15 -0
  126. package/cjs/services/DeviceCredentialsService.js +56 -0
  127. package/cjs/services/EnvironmentService.d.ts +28 -0
  128. package/cjs/services/EnvironmentService.js +48 -0
  129. package/cjs/services/EvaluatorService.js +1 -1
  130. package/cjs/services/IntegrationService.d.ts +7 -1
  131. package/cjs/services/IntegrationService.js +8 -0
  132. package/cjs/services/MapService.d.ts +18 -8
  133. package/cjs/services/MapService.js +37 -19
  134. package/cjs/services/ProfileService.d.ts +24 -0
  135. package/cjs/services/ProfileService.js +34 -0
  136. package/cjs/services/ProjectService.d.ts +7 -2
  137. package/cjs/services/ProjectService.js +7 -3
  138. package/cjs/services/RTPWebRTCService.d.ts +6 -1
  139. package/cjs/services/RTPWebRTCService.js +10 -2
  140. package/cjs/services/RobotService.d.ts +3 -1
  141. package/cjs/services/RobotService.js +6 -0
  142. package/cjs/services/SpotProvisioningService.d.ts +1 -1
  143. package/cjs/services/SpotProvisioningServiceNode.d.ts +1 -1
  144. package/cjs/services/TargetService.d.ts +16 -0
  145. package/cjs/services/TargetService.js +58 -0
  146. package/cjs/services/TelemetryService.d.ts +10 -1
  147. package/cjs/services/TelemetryService.js +27 -5
  148. package/cjs/services/WorkflowService.d.ts +18 -8
  149. package/cjs/services/WorkflowService.js +37 -11
  150. package/cjs/services/index.d.ts +11 -9
  151. package/cjs/services/index.js +11 -9
  152. package/cjs/store/RocosStore.d.ts +1 -2
  153. package/esm/IRocosSDK.d.ts +4 -3
  154. package/esm/RocosSDK.d.ts +19 -7
  155. package/esm/RocosSDK.js +32 -11
  156. package/esm/api/streams/caller/CallerStream.js +5 -2
  157. package/esm/api/streams/caller/CallerStreamNode.js +2 -1
  158. package/esm/api/streams/command/CommandStream.js +5 -2
  159. package/esm/api/streams/command/CommandStreamNode.js +2 -1
  160. package/esm/api/streams/control/ControlStream.js +5 -2
  161. package/esm/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  162. package/esm/api/streams/control/ControlStreamNode.js +2 -1
  163. package/esm/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  164. package/esm/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  165. package/esm/api/streams/search/SearchStream.js +5 -2
  166. package/esm/api/streams/search/SearchStreamNode.js +2 -1
  167. package/esm/api/streams/telemetry/TelemetryStream.js +4 -1
  168. package/esm/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  169. package/esm/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  170. package/esm/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  171. package/esm/constants/api.d.ts +31 -15
  172. package/esm/constants/api.js +31 -15
  173. package/esm/helpers/cleanObject.js +4 -1
  174. package/esm/helpers/getUniqueConfigKey.d.ts +6 -2
  175. package/esm/helpers/getUniqueConfigKey.js +7 -2
  176. package/esm/helpers/index.d.ts +1 -0
  177. package/esm/helpers/index.js +1 -0
  178. package/esm/helpers/kscript/Context.d.ts +34 -0
  179. package/esm/helpers/kscript/Context.js +49 -0
  180. package/esm/helpers/kscript/index.d.ts +1 -0
  181. package/esm/helpers/kscript/index.js +1 -0
  182. package/esm/helpers/kscript/kscript.d.ts +6 -0
  183. package/esm/helpers/kscript/kscript.js +107 -0
  184. package/esm/helpers/kscript/nodes/Identifier.d.ts +12 -0
  185. package/esm/helpers/kscript/nodes/Identifier.js +14 -0
  186. package/esm/helpers/kscript/nodes/Literal.d.ts +11 -0
  187. package/esm/helpers/kscript/nodes/Literal.js +16 -0
  188. package/esm/helpers/kscript/nodes/Node.d.ts +9 -0
  189. package/esm/helpers/kscript/nodes/Node.js +12 -0
  190. package/esm/helpers/kscript/nodes/Program.d.ts +11 -0
  191. package/esm/helpers/kscript/nodes/Program.js +18 -0
  192. package/esm/helpers/kscript/nodes/TemplateLiteral.d.ts +23 -0
  193. package/esm/helpers/kscript/nodes/TemplateLiteral.js +29 -0
  194. package/esm/helpers/kscript/nodes/expressions/ArrayExpression.d.ts +7 -0
  195. package/esm/helpers/kscript/nodes/expressions/ArrayExpression.js +25 -0
  196. package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.d.ts +14 -0
  197. package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.js +34 -0
  198. package/esm/helpers/kscript/nodes/expressions/BinaryExpression.d.ts +16 -0
  199. package/esm/helpers/kscript/nodes/expressions/BinaryExpression.js +98 -0
  200. package/esm/helpers/kscript/nodes/expressions/CallExpression.d.ts +8 -0
  201. package/esm/helpers/kscript/nodes/expressions/CallExpression.js +32 -0
  202. package/esm/helpers/kscript/nodes/expressions/ChainExpression.d.ts +16 -0
  203. package/esm/helpers/kscript/nodes/expressions/ChainExpression.js +19 -0
  204. package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.d.ts +14 -0
  205. package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.js +24 -0
  206. package/esm/helpers/kscript/nodes/expressions/ExpressionStatement.d.ts +7 -0
  207. package/esm/helpers/kscript/nodes/expressions/ExpressionStatement.js +12 -0
  208. package/esm/helpers/kscript/nodes/expressions/LogicalExpression.d.ts +10 -0
  209. package/esm/helpers/kscript/nodes/expressions/LogicalExpression.js +41 -0
  210. package/esm/helpers/kscript/nodes/expressions/MemberExpression.d.ts +44 -0
  211. package/esm/helpers/kscript/nodes/expressions/MemberExpression.js +92 -0
  212. package/esm/helpers/kscript/nodes/expressions/ObjectExpression.d.ts +11 -0
  213. package/esm/helpers/kscript/nodes/expressions/ObjectExpression.js +53 -0
  214. package/esm/helpers/kscript/nodes/expressions/UnaryExpression.d.ts +12 -0
  215. package/esm/helpers/kscript/nodes/expressions/UnaryExpression.js +38 -0
  216. package/esm/helpers/kscript/nodes/expressions/index.d.ts +11 -0
  217. package/esm/helpers/kscript/nodes/expressions/index.js +11 -0
  218. package/esm/helpers/kscript/nodes/index.d.ts +4 -0
  219. package/esm/helpers/kscript/nodes/index.js +3 -0
  220. package/esm/helpers/kscript/nodes/nodeTypes.d.ts +33 -0
  221. package/esm/helpers/kscript/nodes/nodeTypes.js +24 -0
  222. package/esm/helpers/kscript/utils.d.ts +4 -0
  223. package/esm/helpers/kscript/utils.js +11 -0
  224. package/esm/helpers/websandbox/connection.d.ts +2 -1
  225. package/esm/helpers/websandbox/connection.js +6 -5
  226. package/esm/helpers/websandbox/frame/frame.js +4 -1
  227. package/esm/helpers/websandbox/frame/frame.source.js +1 -1
  228. package/esm/helpers/websandbox/frame/worker/manager.d.ts +8 -4
  229. package/esm/helpers/websandbox/frame/worker/manager.js +32 -14
  230. package/esm/helpers/websandbox/frame/worker/worker.source.js +1 -1
  231. package/esm/helpers/websandbox/sandbox.d.ts +1 -1
  232. package/esm/helpers/websandbox/sandbox.js +7 -7
  233. package/esm/models/IConnectedCallsign.d.ts +10 -0
  234. package/esm/models/IConnectedCallsign.js +5 -0
  235. package/esm/models/RocosError.d.ts +3 -0
  236. package/esm/models/RocosError.js +3 -0
  237. package/esm/models/ServiceEnum.d.ts +20 -17
  238. package/esm/models/ServiceEnum.js +20 -17
  239. package/esm/models/TelemetryStatus.d.ts +12 -0
  240. package/esm/models/TelemetryStatus.js +14 -0
  241. package/esm/models/Token.d.ts +2 -2
  242. package/esm/models/Token.js +5 -5
  243. package/esm/models/asset-storage/{AssetModelItem.d.ts → AssetItem.d.ts} +2 -0
  244. package/esm/models/asset-storage/SyncIntegrations.d.ts +1 -1
  245. package/esm/models/device-credentials/DeviceCredentials.d.ts +61 -0
  246. package/esm/models/graph/Position.d.ts +6 -0
  247. package/esm/models/graph/Quaternion.d.ts +6 -0
  248. package/esm/models/graph/Vector3.d.ts +5 -0
  249. package/esm/models/graph/index.d.ts +3 -0
  250. package/esm/models/graph/index.js +3 -0
  251. package/esm/models/index.d.ts +9 -2
  252. package/esm/models/index.js +9 -2
  253. package/esm/models/integrations/Location.d.ts +24 -0
  254. package/esm/models/integrations/PaginatedResults.d.ts +4 -0
  255. package/esm/models/maps/Panorama.d.ts +12 -21
  256. package/esm/models/projects/ExternalProject.d.ts +10 -0
  257. package/esm/models/projects/NewProjectRequest.d.ts +8 -0
  258. package/esm/models/target/Target.d.ts +30 -0
  259. package/esm/models/target/Target.js +9 -0
  260. package/esm/node/RocosSDKNode.d.ts +1 -5
  261. package/esm/node/RocosSDKNode.js +10 -10
  262. package/esm/services/AssetStorageService.d.ts +19 -19
  263. package/esm/services/AssetStorageService.js +20 -9
  264. package/esm/services/AuthService.d.ts +12 -1
  265. package/esm/services/AuthService.js +25 -1
  266. package/esm/services/BaseServiceAbstract.d.ts +1 -1
  267. package/esm/services/BaseServiceAbstract.js +3 -3
  268. package/esm/services/DeviceCredentialsService.d.ts +15 -0
  269. package/esm/services/DeviceCredentialsService.js +52 -0
  270. package/esm/services/EnvironmentService.d.ts +28 -0
  271. package/esm/services/EnvironmentService.js +44 -0
  272. package/esm/services/EvaluatorService.js +1 -1
  273. package/esm/services/IntegrationService.d.ts +7 -1
  274. package/esm/services/IntegrationService.js +10 -2
  275. package/esm/services/MapService.d.ts +18 -8
  276. package/esm/services/MapService.js +38 -20
  277. package/esm/services/ProfileService.d.ts +24 -0
  278. package/esm/services/ProfileService.js +35 -1
  279. package/esm/services/ProjectService.d.ts +7 -2
  280. package/esm/services/ProjectService.js +9 -5
  281. package/esm/services/RTPWebRTCService.d.ts +6 -1
  282. package/esm/services/RTPWebRTCService.js +10 -2
  283. package/esm/services/RobotService.d.ts +3 -1
  284. package/esm/services/RobotService.js +8 -2
  285. package/esm/services/SpotProvisioningService.d.ts +1 -1
  286. package/esm/services/SpotProvisioningServiceNode.d.ts +1 -1
  287. package/esm/services/TargetService.d.ts +16 -0
  288. package/esm/services/TargetService.js +54 -0
  289. package/esm/services/TelemetryService.d.ts +10 -1
  290. package/esm/services/TelemetryService.js +28 -6
  291. package/esm/services/WorkflowService.d.ts +18 -8
  292. package/esm/services/WorkflowService.js +38 -12
  293. package/esm/services/index.d.ts +11 -9
  294. package/esm/services/index.js +11 -9
  295. package/esm/store/RocosStore.d.ts +1 -2
  296. package/package.json +2 -2
  297. package/cjs/helpers/cleanObject.spec.js +0 -55
  298. package/cjs/helpers/flattenObject.spec.js +0 -31
  299. package/cjs/helpers/flattenOneOf.spec.js +0 -159
  300. package/cjs/helpers/formatServiceUrl.spec.js +0 -18
  301. package/cjs/helpers/getSha256Hex.spec.js +0 -19
  302. package/cjs/helpers/getSha256HexNode.spec.js +0 -10
  303. package/cjs/helpers/getURLSearchParams.spec.js +0 -21
  304. package/cjs/helpers/nanosecondToMillisecond.spec.js +0 -22
  305. package/cjs/helpers/splitRobotTopic.spec.js +0 -53
  306. package/cjs/helpers/standardDeviation.spec.d.ts +0 -1
  307. package/cjs/helpers/standardDeviation.spec.js +0 -13
  308. package/cjs/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  309. package/cjs/helpers/websandbox/frame/worker/manager.spec.js +0 -132
  310. package/cjs/models/CallsignStatus.d.ts +0 -6
  311. package/cjs/models/CallsignStatus.js +0 -10
  312. package/cjs/models/ExternalProject.d.ts +0 -6
  313. package/cjs/models/ExternalProject.js +0 -6
  314. package/cjs/models/Token.spec.d.ts +0 -1
  315. package/cjs/models/Token.spec.js +0 -110
  316. package/cjs/services/AuthService.spec.d.ts +0 -1
  317. package/cjs/services/AuthService.spec.js +0 -165
  318. package/cjs/services/CallerService.spec.d.ts +0 -1
  319. package/cjs/services/CallerService.spec.js +0 -229
  320. package/cjs/services/FunctionService.d.ts +0 -68
  321. package/cjs/services/FunctionService.js +0 -103
  322. package/cjs/services/PlatformTimeService.spec.d.ts +0 -1
  323. package/cjs/services/PlatformTimeService.spec.js +0 -182
  324. package/cjs/services/RTPWebRTCService.spec.d.ts +0 -4
  325. package/cjs/services/RTPWebRTCService.spec.js +0 -171
  326. package/cjs/services/TelemetryService.spec.d.ts +0 -1
  327. package/cjs/services/TelemetryService.spec.js +0 -39
  328. package/esm/helpers/cleanObject.spec.d.ts +0 -1
  329. package/esm/helpers/cleanObject.spec.js +0 -53
  330. package/esm/helpers/flattenObject.spec.d.ts +0 -1
  331. package/esm/helpers/flattenObject.spec.js +0 -29
  332. package/esm/helpers/flattenOneOf.spec.d.ts +0 -1
  333. package/esm/helpers/flattenOneOf.spec.js +0 -157
  334. package/esm/helpers/formatServiceUrl.spec.d.ts +0 -1
  335. package/esm/helpers/formatServiceUrl.spec.js +0 -16
  336. package/esm/helpers/getSha256Hex.spec.d.ts +0 -1
  337. package/esm/helpers/getSha256Hex.spec.js +0 -14
  338. package/esm/helpers/getSha256HexNode.spec.d.ts +0 -1
  339. package/esm/helpers/getSha256HexNode.spec.js +0 -8
  340. package/esm/helpers/getURLSearchParams.spec.d.ts +0 -1
  341. package/esm/helpers/getURLSearchParams.spec.js +0 -19
  342. package/esm/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
  343. package/esm/helpers/nanosecondToMillisecond.spec.js +0 -20
  344. package/esm/helpers/splitRobotTopic.spec.d.ts +0 -1
  345. package/esm/helpers/splitRobotTopic.spec.js +0 -51
  346. package/esm/helpers/standardDeviation.spec.d.ts +0 -1
  347. package/esm/helpers/standardDeviation.spec.js +0 -11
  348. package/esm/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  349. package/esm/helpers/websandbox/frame/worker/manager.spec.js +0 -127
  350. package/esm/models/CallsignStatus.d.ts +0 -6
  351. package/esm/models/CallsignStatus.js +0 -7
  352. package/esm/models/ExternalProject.d.ts +0 -6
  353. package/esm/models/ExternalProject.js +0 -2
  354. package/esm/models/Token.spec.d.ts +0 -1
  355. package/esm/models/Token.spec.js +0 -108
  356. package/esm/models/asset-storage/AssetModelItem.js +0 -1
  357. package/esm/services/AuthService.spec.d.ts +0 -1
  358. package/esm/services/AuthService.spec.js +0 -163
  359. package/esm/services/CallerService.spec.d.ts +0 -1
  360. package/esm/services/CallerService.spec.js +0 -227
  361. package/esm/services/FunctionService.d.ts +0 -68
  362. package/esm/services/FunctionService.js +0 -99
  363. package/esm/services/PlatformTimeService.spec.d.ts +0 -1
  364. package/esm/services/PlatformTimeService.spec.js +0 -180
  365. package/esm/services/RTPWebRTCService.spec.d.ts +0 -4
  366. package/esm/services/RTPWebRTCService.spec.js +0 -169
  367. package/esm/services/TelemetryService.spec.d.ts +0 -1
  368. package/esm/services/TelemetryService.spec.js +0 -37
  369. /package/cjs/models/asset-storage/{AssetModelItem.js → AssetItem.js} +0 -0
  370. /package/{cjs/helpers/cleanObject.spec.d.ts → esm/models/asset-storage/AssetItem.js} +0 -0
  371. /package/{cjs/helpers/flattenObject.spec.d.ts → esm/models/device-credentials/DeviceCredentials.js} +0 -0
  372. /package/{cjs/helpers/flattenOneOf.spec.d.ts → esm/models/graph/Position.js} +0 -0
  373. /package/{cjs/helpers/formatServiceUrl.spec.d.ts → esm/models/graph/Quaternion.js} +0 -0
  374. /package/{cjs/helpers/getSha256Hex.spec.d.ts → esm/models/graph/Vector3.js} +0 -0
  375. /package/{cjs/helpers/getSha256HexNode.spec.d.ts → esm/models/integrations/Location.js} +0 -0
  376. /package/{cjs/helpers/getURLSearchParams.spec.d.ts → esm/models/integrations/PaginatedResults.js} +0 -0
  377. /package/{cjs/helpers/nanosecondToMillisecond.spec.d.ts → esm/models/projects/ExternalProject.js} +0 -0
  378. /package/{cjs/helpers/splitRobotTopic.spec.d.ts → esm/models/projects/NewProjectRequest.js} +0 -0
@@ -0,0 +1,14 @@
1
+ import { AnyNode, ConditionalExpression, IfStatement } from 'acorn';
2
+ import type Context from '../../Context';
3
+ import Node from '../Node';
4
+ /** Represents a ternary conditional expression (a ? b : c) or an if statement (if (a) b else c).
5
+ *
6
+ * If a (test) is truthy, b (consequent) is returned. Otherwise, c (alternate) is returned.
7
+ *
8
+ * Since the if statement and the conditional expression are so similar, they are both handled by this node,
9
+ * even though they are separate in the AST.
10
+ */
11
+ export default class ConditionalExpressionNode extends Node<IfStatement | ConditionalExpression> {
12
+ constructor(node: AnyNode, context: Context);
13
+ run(): unknown;
14
+ }
@@ -0,0 +1,24 @@
1
+ import Node from '../Node';
2
+ import { construct } from '../../utils';
3
+ /** Represents a ternary conditional expression (a ? b : c) or an if statement (if (a) b else c).
4
+ *
5
+ * If a (test) is truthy, b (consequent) is returned. Otherwise, c (alternate) is returned.
6
+ *
7
+ * Since the if statement and the conditional expression are so similar, they are both handled by this node,
8
+ * even though they are separate in the AST.
9
+ */
10
+ export default class ConditionalExpressionNode extends Node {
11
+ constructor(node, context) {
12
+ super(node, context, ['ConditionalExpression', 'IfStatement']);
13
+ }
14
+ run() {
15
+ const test = construct(this.node.test, this.context).run();
16
+ if (test) {
17
+ return construct(this.node.consequent, this.context).run();
18
+ }
19
+ if (this.node.alternate === null || this.node.alternate === undefined) {
20
+ return undefined;
21
+ }
22
+ return construct(this.node.alternate, this.context).run();
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ import { AnyNode, ExpressionStatement } from 'acorn';
2
+ import Context from '../../Context';
3
+ import Node from '../Node';
4
+ export default class ExpressionStatementNode extends Node<ExpressionStatement> {
5
+ constructor(node: AnyNode, context: Context);
6
+ run(): unknown;
7
+ }
@@ -0,0 +1,12 @@
1
+ import Node from '../Node';
2
+ import { construct } from '../../utils';
3
+ export default class ExpressionStatementNode extends Node {
4
+ constructor(node, context) {
5
+ super(node, context, 'ExpressionStatement');
6
+ }
7
+ run() {
8
+ if (this.node.directive)
9
+ throw new Error('Directives are not supported');
10
+ return construct(this.node.expression, this.context).run();
11
+ }
12
+ }
@@ -0,0 +1,10 @@
1
+ import { AnyNode, LogicalExpression } from 'acorn';
2
+ import Context from '../../Context';
3
+ import Node from '../Node';
4
+ export default class BinaryExpressionNode extends Node<LogicalExpression> {
5
+ constructor(node: AnyNode, context: Context);
6
+ run(): unknown;
7
+ /** Try and skip evaluating the right operand */
8
+ private shortCircuit;
9
+ private operate;
10
+ }
@@ -0,0 +1,41 @@
1
+ import Node from '../Node';
2
+ import { construct } from '../../utils';
3
+ export default class BinaryExpressionNode extends Node {
4
+ constructor(node, context) {
5
+ super(node, context, 'LogicalExpression');
6
+ }
7
+ run() {
8
+ const left = construct(this.node.left, this.context).run();
9
+ const shortCircuit = this.shortCircuit(left);
10
+ if (shortCircuit !== null) {
11
+ return shortCircuit;
12
+ }
13
+ const right = construct(this.node.right, this.context).run();
14
+ return this.operate(left, right);
15
+ }
16
+ /** Try and skip evaluating the right operand */
17
+ shortCircuit(left) {
18
+ if (this.node.operator === '&&' && !left) {
19
+ return false;
20
+ }
21
+ if (this.node.operator === '||' && left) {
22
+ return true;
23
+ }
24
+ if (this.node.operator === '??' && left !== null && left !== undefined) {
25
+ return left;
26
+ }
27
+ return null;
28
+ }
29
+ operate(left, right) {
30
+ switch (this.node.operator) {
31
+ case '||':
32
+ return left || right;
33
+ case '&&':
34
+ return left && right;
35
+ case '??':
36
+ return left ?? right;
37
+ default:
38
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,44 @@
1
+ import { AnyNode, MemberExpression } from 'acorn';
2
+ import Context from '../../Context';
3
+ import Node from '../Node';
4
+ /**
5
+ * A member expression is an expression that accesses a property of an object.
6
+ *
7
+ * Examples of member expressions are:
8
+ * - `a.b`
9
+ * - `a['b']`
10
+ * - `a[0]`
11
+ * - `a?.b`
12
+ * - `a?.['b']`
13
+ * - `a?.[0]`
14
+ *
15
+ * A member access in the sandbox is considered secure if the following conditions are met:
16
+ * - The property is not named 'constructor'
17
+ * - Either:
18
+ * * The property is owned by the object and is *not* on the whitelist.
19
+ * * The prototype is whitelisted and the property list is null or contains the property.
20
+ *
21
+ * @see Context.isPrototypeAllowed
22
+ */
23
+ export default class MemberExpressionNode extends Node<MemberExpression> {
24
+ constructor(node: AnyNode, context: Context);
25
+ run(): unknown;
26
+ /** Returns the name of the property being accessed.
27
+ *
28
+ * Handles both computed and non-computed properties.
29
+ */
30
+ private getPropertyIdentifier;
31
+ /** Checks if the property can be accessed on the object.
32
+ *
33
+ * @throws {Error} If the property is not allowed to be accessed.
34
+ */
35
+ private checkPropertyAccess;
36
+ /** Searches the prototype chain of the object for the prototype that defines the property. */
37
+ private getPropertyPrototype;
38
+ /**
39
+ * Returns true if the property exists on the object.
40
+ *
41
+ * i.e. the property is defined somewhere on the prototype chain.
42
+ */
43
+ private propertyExists;
44
+ }
@@ -0,0 +1,92 @@
1
+ import Node from '../Node';
2
+ import { construct } from '../../utils';
3
+ /**
4
+ * A member expression is an expression that accesses a property of an object.
5
+ *
6
+ * Examples of member expressions are:
7
+ * - `a.b`
8
+ * - `a['b']`
9
+ * - `a[0]`
10
+ * - `a?.b`
11
+ * - `a?.['b']`
12
+ * - `a?.[0]`
13
+ *
14
+ * A member access in the sandbox is considered secure if the following conditions are met:
15
+ * - The property is not named 'constructor'
16
+ * - Either:
17
+ * * The property is owned by the object and is *not* on the whitelist.
18
+ * * The prototype is whitelisted and the property list is null or contains the property.
19
+ *
20
+ * @see Context.isPrototypeAllowed
21
+ */
22
+ export default class MemberExpressionNode extends Node {
23
+ constructor(node, context) {
24
+ super(node, context, 'MemberExpression');
25
+ }
26
+ run() {
27
+ const object = construct(this.node.object, this.context).run();
28
+ if (object === null || object === undefined) {
29
+ if (this.node.optional)
30
+ return undefined;
31
+ throw new Error(`Cannot read property of ${object}`);
32
+ }
33
+ const propertyIdentifier = this.getPropertyIdentifier();
34
+ if (!this.propertyExists(object, propertyIdentifier)) {
35
+ return undefined;
36
+ }
37
+ this.checkPropertyAccess(object, propertyIdentifier);
38
+ return object[propertyIdentifier];
39
+ }
40
+ /** Returns the name of the property being accessed.
41
+ *
42
+ * Handles both computed and non-computed properties.
43
+ */
44
+ getPropertyIdentifier() {
45
+ if (this.node.computed) {
46
+ const name = construct(this.node.property, this.context).run();
47
+ if (typeof name !== 'string' && typeof name !== 'number') {
48
+ throw new Error('Only string or number computed properties are supported');
49
+ }
50
+ return name;
51
+ }
52
+ if (this.node.property.type !== 'Identifier') {
53
+ throw new Error('Only identifiers are supported for non-computed member expression properties');
54
+ }
55
+ return this.node.property.name;
56
+ }
57
+ /** Checks if the property can be accessed on the object.
58
+ *
59
+ * @throws {Error} If the property is not allowed to be accessed.
60
+ */
61
+ checkPropertyAccess(object, propertyIdentifier) {
62
+ if (typeof propertyIdentifier === 'number')
63
+ return;
64
+ if (propertyIdentifier === 'constructor') {
65
+ throw new Error('Cannot access constructor property');
66
+ }
67
+ const definingProto = this.getPropertyPrototype(object, propertyIdentifier);
68
+ const ownProperty = Object.prototype.hasOwnProperty.call(object, propertyIdentifier);
69
+ if (!this.context.isPrototypeAllowed(definingProto, propertyIdentifier, ownProperty)) {
70
+ throw new Error(`SecurityError: Access to property '${propertyIdentifier}' is not allowed`);
71
+ }
72
+ }
73
+ /** Searches the prototype chain of the object for the prototype that defines the property. */
74
+ getPropertyPrototype(object, propertyIdentifier) {
75
+ let proto = object;
76
+ while (proto !== null) {
77
+ if (Object.prototype.hasOwnProperty.call(proto, propertyIdentifier)) {
78
+ return proto;
79
+ }
80
+ proto = Object.getPrototypeOf(proto);
81
+ }
82
+ return null;
83
+ }
84
+ /**
85
+ * Returns true if the property exists on the object.
86
+ *
87
+ * i.e. the property is defined somewhere on the prototype chain.
88
+ */
89
+ propertyExists(object, propertyIdentifier) {
90
+ return this.getPropertyPrototype(object, propertyIdentifier) !== null;
91
+ }
92
+ }
@@ -0,0 +1,11 @@
1
+ import { AnyNode, ObjectExpression } from 'acorn';
2
+ import type Context from '../../Context';
3
+ import Node from '../Node';
4
+ export default class ObjectExpressionNode extends Node<ObjectExpression> {
5
+ constructor(node: AnyNode, context: Context);
6
+ run(): unknown;
7
+ private addProperty;
8
+ private spreadProperty;
9
+ private getKey;
10
+ private getStaticKey;
11
+ }
@@ -0,0 +1,53 @@
1
+ import Node from '../Node';
2
+ import { construct } from '../../utils';
3
+ export default class ObjectExpressionNode extends Node {
4
+ constructor(node, context) {
5
+ super(node, context, 'ObjectExpression');
6
+ }
7
+ run() {
8
+ const object = {};
9
+ for (const property of this.node.properties) {
10
+ if (property.type === 'SpreadElement') {
11
+ this.spreadProperty(property, object);
12
+ continue;
13
+ }
14
+ this.addProperty(property, object);
15
+ }
16
+ return object;
17
+ }
18
+ addProperty(property, object) {
19
+ if (property.kind !== 'init')
20
+ throw new Error('Only init properties are supported');
21
+ const key = this.getKey(property);
22
+ object[key] = construct(property.value, this.context).run();
23
+ }
24
+ spreadProperty(property, object) {
25
+ const value = construct(property.argument, this.context).run();
26
+ if (!(typeof value === 'object' && value !== null)) {
27
+ throw new Error('Spread argument must be an object');
28
+ }
29
+ Object.assign(object, value);
30
+ }
31
+ getKey(property) {
32
+ let key;
33
+ if (property.computed) {
34
+ key = construct(property.key, this.context).run();
35
+ }
36
+ else {
37
+ key = this.getStaticKey(property.key);
38
+ }
39
+ if (key === null || key === undefined)
40
+ throw new Error('Key cannot be null or undefined');
41
+ if (typeof key !== 'string' && typeof key !== 'number' && typeof key !== 'symbol') {
42
+ throw new Error(`Unsupported key type: ${typeof key}`);
43
+ }
44
+ return key;
45
+ }
46
+ getStaticKey(key) {
47
+ if (key.type === 'Identifier')
48
+ return key.name;
49
+ if (key.type === 'Literal')
50
+ return key.value;
51
+ throw new Error('Only identifier and literal keys are supported');
52
+ }
53
+ }
@@ -0,0 +1,12 @@
1
+ import { AnyNode, UnaryExpression } from 'acorn';
2
+ import Context from '../../Context';
3
+ import Node from '../Node';
4
+ /** A unary expression is an expression that consists of a single operand and an operator
5
+ *
6
+ * e.g. `+1`, `-2`, `!true`, `typeof x`
7
+ */
8
+ export default class UnaryExpressionNode extends Node<UnaryExpression> {
9
+ constructor(node: AnyNode, context: Context);
10
+ run(): unknown;
11
+ private arithmetic;
12
+ }
@@ -0,0 +1,38 @@
1
+ import Node from '../Node';
2
+ import { construct } from '../../utils';
3
+ /** A unary expression is an expression that consists of a single operand and an operator
4
+ *
5
+ * e.g. `+1`, `-2`, `!true`, `typeof x`
6
+ */
7
+ export default class UnaryExpressionNode extends Node {
8
+ constructor(node, context) {
9
+ super(node, context, 'UnaryExpression');
10
+ }
11
+ run() {
12
+ const argument = construct(this.node.argument, this.context).run();
13
+ switch (this.node.operator) {
14
+ case '+':
15
+ case '-':
16
+ return this.arithmetic(this.node.operator, argument);
17
+ case '!':
18
+ return !argument;
19
+ case 'typeof':
20
+ return typeof argument;
21
+ default:
22
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
23
+ }
24
+ }
25
+ arithmetic(operator, argument) {
26
+ if (typeof argument !== 'number') {
27
+ throw new Error('Unary arithmetic operators are only supported for numbers');
28
+ }
29
+ switch (operator) {
30
+ case '+':
31
+ return +argument;
32
+ case '-':
33
+ return -argument;
34
+ default:
35
+ throw new Error(`Unsupported operator: ${operator}`);
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,11 @@
1
+ export { default as ExpressionStatement } from './ExpressionStatement';
2
+ export { default as ArrayExpression } from './ArrayExpression';
3
+ export { default as ObjectExpression } from './ObjectExpression';
4
+ export { default as BinaryExpression } from './BinaryExpression';
5
+ export { default as UnaryExpression } from './UnaryExpression';
6
+ export { default as LogicalExpression } from './LogicalExpression';
7
+ export { default as ConditionalExpression } from './ConditionalExpression';
8
+ export { default as CallExpression } from './CallExpression';
9
+ export { default as ArrowFunctionExpression } from './ArrowFunctionExpression';
10
+ export { default as MemberExpression } from './MemberExpression';
11
+ export { default as ChainExpression } from './ChainExpression';
@@ -0,0 +1,11 @@
1
+ export { default as ExpressionStatement } from './ExpressionStatement';
2
+ export { default as ArrayExpression } from './ArrayExpression';
3
+ export { default as ObjectExpression } from './ObjectExpression';
4
+ export { default as BinaryExpression } from './BinaryExpression';
5
+ export { default as UnaryExpression } from './UnaryExpression';
6
+ export { default as LogicalExpression } from './LogicalExpression';
7
+ export { default as ConditionalExpression } from './ConditionalExpression';
8
+ export { default as CallExpression } from './CallExpression';
9
+ export { default as ArrowFunctionExpression } from './ArrowFunctionExpression';
10
+ export { default as MemberExpression } from './MemberExpression';
11
+ export { default as ChainExpression } from './ChainExpression';
@@ -0,0 +1,4 @@
1
+ import { NodeType, default as nodes } from './nodeTypes';
2
+ import Context from '../Context';
3
+ import Node from './Node';
4
+ export { type Node, type NodeType, nodes, Context };
@@ -0,0 +1,3 @@
1
+ import { default as nodes } from './nodeTypes';
2
+ import Context from '../Context';
3
+ export { nodes, Context };
@@ -0,0 +1,33 @@
1
+ import { ArrayExpression, ArrowFunctionExpression, BinaryExpression, CallExpression, ChainExpression, ConditionalExpression, ExpressionStatement, LogicalExpression, MemberExpression, ObjectExpression, UnaryExpression } from './expressions';
2
+ import { AnyNode } from 'acorn';
3
+ import type Context from '../Context';
4
+ import Identifier from './Identifier';
5
+ import Literal from './Literal';
6
+ import Node from './Node';
7
+ import Program from './Program';
8
+ import TemplateLiteral from './TemplateLiteral';
9
+ type NodeConstructor = {
10
+ new (node: AnyNode, scope: Context): Node<AnyNode>;
11
+ };
12
+ export type NodeMap = Map<AnyNode['type'], NodeConstructor>;
13
+ declare const nodes: {
14
+ readonly Program: typeof Program;
15
+ readonly Literal: typeof Literal;
16
+ readonly ExpressionStatement: typeof ExpressionStatement;
17
+ readonly ArrayExpression: typeof ArrayExpression;
18
+ readonly ObjectExpression: typeof ObjectExpression;
19
+ readonly Identifier: typeof Identifier;
20
+ readonly BinaryExpression: typeof BinaryExpression;
21
+ readonly UnaryExpression: typeof UnaryExpression;
22
+ readonly LogicalExpression: typeof LogicalExpression;
23
+ readonly ConditionalExpression: typeof ConditionalExpression;
24
+ readonly IfStatement: typeof ConditionalExpression;
25
+ readonly TemplateLiteral: typeof TemplateLiteral;
26
+ readonly ArrowFunctionExpression: typeof ArrowFunctionExpression;
27
+ readonly CallExpression: typeof CallExpression;
28
+ readonly MemberExpression: typeof MemberExpression;
29
+ readonly ChainExpression: typeof ChainExpression;
30
+ };
31
+ export type NodeType = keyof typeof nodes;
32
+ declare const _default: NodeMap;
33
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { ArrayExpression, ArrowFunctionExpression, BinaryExpression, CallExpression, ChainExpression, ConditionalExpression, ExpressionStatement, LogicalExpression, MemberExpression, ObjectExpression, UnaryExpression, } from './expressions';
2
+ import Identifier from './Identifier';
3
+ import Literal from './Literal';
4
+ import Program from './Program';
5
+ import TemplateLiteral from './TemplateLiteral';
6
+ const nodes = {
7
+ Program,
8
+ Literal,
9
+ ExpressionStatement,
10
+ ArrayExpression,
11
+ ObjectExpression,
12
+ Identifier,
13
+ BinaryExpression,
14
+ UnaryExpression,
15
+ LogicalExpression,
16
+ ConditionalExpression,
17
+ IfStatement: ConditionalExpression,
18
+ TemplateLiteral,
19
+ ArrowFunctionExpression,
20
+ CallExpression,
21
+ MemberExpression,
22
+ ChainExpression,
23
+ };
24
+ export default new Map(Object.entries(nodes));
@@ -0,0 +1,4 @@
1
+ import { Node } from './nodes';
2
+ import { AnyNode } from 'acorn';
3
+ import Context from './Context';
4
+ export declare function construct(node: AnyNode, context: Context): Node<AnyNode>;
@@ -0,0 +1,11 @@
1
+ import { nodes } from './nodes';
2
+ export function construct(node, context) {
3
+ if (!context.isNodeAllowed(node.type)) {
4
+ throw new Error(`Blacklisted Operation: ${node.type}`);
5
+ }
6
+ const nodeClass = nodes.get(node.type);
7
+ if (!nodeClass) {
8
+ throw new Error(`Unknown node type: ${node.type}`);
9
+ }
10
+ return Reflect.construct(nodeClass, [node, context]);
11
+ }
@@ -39,6 +39,8 @@ export default class Connection<Local extends APIDeclaration<Local>, Remote exte
39
39
  * @param args - arguments to pass to remote method
40
40
  */
41
41
  callRemoteMethod<Method extends keyof Remote>(name: Method, ...args: Parameters<Remote[Method]>): Promise<ReturnType<Remote[Method]>>;
42
+ /** Log a message if debug mode is enabled */
43
+ log(...args: unknown[]): void;
42
44
  private onMessageListener;
43
45
  private callLocalMethod;
44
46
  /** Respond to remote call
@@ -62,6 +64,5 @@ export default class Connection<Local extends APIDeclaration<Local>, Remote exte
62
64
  */
63
65
  private popCallback;
64
66
  private postMessage;
65
- private log;
66
67
  }
67
68
  export {};
@@ -43,6 +43,12 @@ export default class Connection {
43
43
  });
44
44
  });
45
45
  }
46
+ /** Log a message if debug mode is enabled */
47
+ log(...args) {
48
+ if (this.options.debugMode) {
49
+ console.debug(`[${this.name}]`, ...args);
50
+ }
51
+ }
46
52
  onMessageListener(e) {
47
53
  this.log('Received message', e);
48
54
  const { data } = e;
@@ -125,9 +131,4 @@ export default class Connection {
125
131
  this.log('sending message', { data, targetOrigin });
126
132
  this.postMessageInternal(data, targetOrigin);
127
133
  }
128
- log(...args) {
129
- if (this.options.debugMode) {
130
- console.debug(`[${this.name}]`, ...args);
131
- }
132
- }
133
134
  }
@@ -12,7 +12,10 @@ class Frame {
12
12
  debugMode: isDebugMode,
13
13
  });
14
14
  void this.connection.callRemoteMethod('iframeInitialised');
15
- this.workerManager = new WorkerManager();
15
+ // use roughly half the number of logical cores available clamped between 1 and 6
16
+ const workers = Math.min(Math.max(Math.ceil(navigator.hardwareConcurrency / 2), 1), 6);
17
+ this.connection.log(`Creating ${workers} workers`);
18
+ this.workerManager = new WorkerManager(workers);
16
19
  }
17
20
  async runCode(task) {
18
21
  return this.workerManager.execute(task);
@@ -1,5 +1,5 @@
1
1
  // Auto-generated file
2
2
  /* eslint-disable */
3
3
  import __WORKER_SOURCE__ from './worker/worker.source';
4
- const source = `(()=>{"use strict";var e={880:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),function(e){e.RESPONSE="response",e.MESSAGE="message"}(s||(s={}));const r={allowedSenderOrigin:void 0,debugMode:!1};t.default=class{constructor(e,t,s,i,o={}){this.callbacks=new Map,this.serviceMethods=new Map,this.name=e,this.options={...r,...o},this.log("Created connection w/ allowedOrigin:",this.options.allowedSenderOrigin),this.serviceMethods=new Map(Object.entries(s));const[n]=crypto.getRandomValues(new Uint32Array(1));this.incrementalID=n,this.postMessageInternal=t,i((e=>this.onMessageListener(e)))}callRemoteMethod(e,...t){return this.log("Calling Remote Method",{name:e,args:t}),new Promise(((r,i)=>{const o=this.registerCallback(r,i);this.postMessage({callId:o,type:s.MESSAGE,methodName:e,arguments:t})}))}onMessageListener(e){this.log("Received message",e);const{data:t}=e,{allowedSenderOrigin:r}=this.options;switch(r&&e.origin!==r&&console.warn(\`Received message from invalid origin: \${e.origin}\`),t.type){case s.RESPONSE:return void this.popCallback(t.callId,t.success,t.result);case s.MESSAGE:this.callLocalMethod(t.methodName,t.arguments).then((e=>this.responseOtherSide(t.callId,e))).catch((e=>this.responseOtherSide(t.callId,e,!1)))}}async callLocalMethod(e,t){this.log("calling local method",e,t);const s=this.serviceMethods.get(e);if(!s)throw new Error(\`service method \${e} not found\`);return s(...t)}responseOtherSide(e,t,r=!0){this.log("responding to remote call",{id:e,result:t,success:r});const i=t=>{this.postMessage({callId:e,type:s.RESPONSE,success:r,result:t})};try{i(t)}catch(e){e instanceof DOMException&&i(JSON.parse(JSON.stringify(t)))}}registerCallback(e,t){const s=(++this.incrementalID).toString();return this.log("registering callback for id",s),this.callbacks.set(s,{success:e,failure:t}),s}popCallback(e,t,s){this.log("calling callback for id",e,{success:t,result:s});const r=this.callbacks.get(e);t?r?.success(s):r?.failure(s),this.callbacks.delete(e)}postMessage(e,t="*"){this.log("sending message",{data:e,targetOrigin:t}),this.postMessageInternal(e,t)}log(...e){this.options.debugMode&&console.debug(\`[\${this.name}]\`,...e)}}},306:function(e,t,s){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(s(880)),o=r(s(54)),n=new class{constructor(){const e=!!window?.debugMode;this.connection=new i.default("FRAME",window.parent.postMessage.bind(window.parent),{startTask:this.runCode.bind(this)},(e=>{window.addEventListener("message",e)}),{debugMode:e}),this.connection.callRemoteMethod("iframeInitialised"),this.workerManager=new o.default}async runCode(e){return this.workerManager.execute(e)}};t.default=n},54:function(e,t,s){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(s(420));t.default=i.default},420:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(){this.messageListeners=new Map,this.worker=this.createWorker()}async execute(e){const t={...e,contextVariable:e.contextVariable??"ctx"},s=this.runTask(t),r=new Promise(((t,s)=>{const r=AbortSignal.timeout(e.timeout);r.addEventListener("abort",(()=>{s(r.reason)}))}));return Promise.race([s,r]).catch((e=>{throw"TimeoutError"===e.name&&this.terminate(),e})).finally((()=>{this.removeMessageListener(e.id)}))}terminate(){for(const e of this.messageListeners.values())this.worker.removeEventListener("message",e);this.worker.terminate(),this.worker=this.createWorker()}runTask(e){return new Promise(((t,s)=>{const r=r=>{const{data:i}=r;i.id===e.id&&(i.success?t(i.result):s(i.result))};this.messageListeners.set(e.id,r),this.worker.addEventListener("message",r),this.worker.postMessage(e)}))}createWorker(){const e=URL.createObjectURL(new Blob(["${__WORKER_SOURCE__.replace(/(['`"$])/g, '\\$1')}"],{type:"application/javascript"}));return new Worker(e)}removeMessageListener(e){const t=this.messageListeners.get(e);t&&this.worker.removeEventListener("message",t)}}}},t={};!function s(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,s),o.exports}(306)})();`;
4
+ const source = `(()=>{"use strict";var e;!function(e){e.RESPONSE="response",e.MESSAGE="message"}(e||(e={}));const s={allowedSenderOrigin:void 0,debugMode:!1};class t{constructor(e,t,r,n,o={}){this.callbacks=new Map,this.serviceMethods=new Map,this.name=e,this.options={...s,...o},this.log("Created connection w/ allowedOrigin:",this.options.allowedSenderOrigin),this.serviceMethods=new Map(Object.entries(r));const[i]=crypto.getRandomValues(new Uint32Array(1));this.incrementalID=i,this.postMessageInternal=t,n((e=>this.onMessageListener(e)))}callRemoteMethod(s,...t){return this.log("Calling Remote Method",{name:s,args:t}),new Promise(((r,n)=>{const o=this.registerCallback(r,n);this.postMessage({callId:o,type:e.MESSAGE,methodName:s,arguments:t})}))}log(...e){this.options.debugMode&&console.debug(\`[\${this.name}]\`,...e)}onMessageListener(s){this.log("Received message",s);const{data:t}=s,{allowedSenderOrigin:r}=this.options;switch(r&&s.origin!==r&&console.warn(\`Received message from invalid origin: \${s.origin}\`),t.type){case e.RESPONSE:return void this.popCallback(t.callId,t.success,t.result);case e.MESSAGE:this.callLocalMethod(t.methodName,t.arguments).then((e=>this.responseOtherSide(t.callId,e))).catch((e=>this.responseOtherSide(t.callId,e,!1)))}}async callLocalMethod(e,s){this.log("calling local method",e,s);const t=this.serviceMethods.get(e);if(!t)throw new Error(\`service method \${e} not found\`);return t(...s)}responseOtherSide(s,t,r=!0){this.log("responding to remote call",{id:s,result:t,success:r});const n=t=>{this.postMessage({callId:s,type:e.RESPONSE,success:r,result:t})};try{n(t)}catch(e){e instanceof DOMException&&n(JSON.parse(JSON.stringify(t)))}}registerCallback(e,s){const t=(++this.incrementalID).toString();return this.log("registering callback for id",t),this.callbacks.set(t,{success:e,failure:s}),t}popCallback(e,s,t){this.log("calling callback for id",e,{success:s,result:t});const r=this.callbacks.get(e);s?r?.success(t):r?.failure(t),this.callbacks.delete(e)}postMessage(e,s="*"){this.log("sending message",{data:e,targetOrigin:s}),this.postMessageInternal(e,s)}}new class{constructor(){const e=!!window?.debugMode;this.connection=new t("FRAME",window.parent.postMessage.bind(window.parent),{startTask:this.runCode.bind(this)},(e=>{window.addEventListener("message",e)}),{debugMode:e}),this.connection.callRemoteMethod("iframeInitialised");const s=Math.max(Math.ceil(navigator.hardwareConcurrency/2),1);this.connection.log(\`Creating \${s} workers\`),this.workerManager=new class{constructor(e=1){this.messageListeners=new Map,this.requestedWorkers=e,this.workers=Array.from({length:e},(()=>this.createWorker())),this.nextWorkerGenerator=this.nextWorker()}async execute(e){const s=this.nextWorkerGenerator.next().value,t={...e,contextVariable:e.contextVariable??"ctx"},r=this.runTask(s,t),n=new Promise(((s,t)=>{const r=AbortSignal.timeout(e.timeout);r.addEventListener("abort",(()=>{t(r.reason)}))}));return Promise.race([r,n]).catch((e=>{if("TimeoutError"===e.name)throw this.terminate(s),new DOMException("soft timeout reached","TimeoutError");throw e})).finally((()=>{this.removeMessageListener(e.id)}))}terminate(e){for(const s of this.messageListeners.values())e.removeEventListener("message",s);e.terminate(),this.rebuildWorkers()}runTask(e,s){return new Promise(((t,r)=>{const n=e=>{const{data:n}=e;n.id===s.id&&(n.success?t(n.result):r(n.result))};this.messageListeners.set(s.id,n),e.addEventListener("message",n),e.postMessage(s)}))}createWorker(){const e=URL.createObjectURL(new Blob(["${__WORKER_SOURCE__.replace(/(['`"$])/g, '\\$1')}"],{type:"application/javascript"}));return new Worker(e)}rebuildWorkers(){const e=this.requestedWorkers-this.workers.length;if(e<0)throw new Error("Cannot have less than 0 workers");if(e<=0)return;const s=Array.from({length:e},(()=>this.createWorker()));this.workers.push(...s)}*nextWorker(){let e=0;for(;;)e=(e+1)%this.workers.length,yield this.workers[e]}removeMessageListener(e){const s=this.messageListeners.get(e);s&&(this.workers.forEach((e=>e.removeEventListener("message",s))),this.messageListeners.delete(e))}}(s)}async runCode(e){return this.workerManager.execute(e)}}})();`;
5
5
  export default source;
@@ -1,11 +1,15 @@
1
1
  import { Task } from '../../types';
2
2
  export default class Manager {
3
- private worker;
4
- private messageListeners;
5
- constructor();
3
+ private readonly requestedWorkers;
4
+ private readonly workers;
5
+ private nextWorkerIndex;
6
+ private readonly messageListeners;
7
+ constructor(workers?: number);
6
8
  execute(task: Task): Promise<unknown>;
7
- terminate(): void;
9
+ private terminate;
8
10
  private runTask;
9
11
  private createWorker;
12
+ private rebuildWorkers;
13
+ private getWorker;
10
14
  private removeMessageListener;
11
15
  }