@spearwolf/shadow-objects 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/CHANGELOG.md +350 -61
  2. package/README.md +66 -13
  3. package/bundle.js +6 -53
  4. package/package.json +15 -3
  5. package/src/ChangeTrailRefusedError.d.ts +27 -0
  6. package/src/ChangeTrailRefusedError.d.ts.map +1 -0
  7. package/src/ChangeTrailRefusedError.js +12 -0
  8. package/src/ChangeTrailRefusedError.js.map +7 -0
  9. package/src/EntityUuidInUseError.d.ts +19 -0
  10. package/src/EntityUuidInUseError.d.ts.map +1 -0
  11. package/src/EntityUuidInUseError.js +11 -0
  12. package/src/EntityUuidInUseError.js.map +7 -0
  13. package/src/WorkerTimeoutError.d.ts +26 -0
  14. package/src/WorkerTimeoutError.d.ts.map +1 -0
  15. package/src/WorkerTimeoutError.js +12 -0
  16. package/src/WorkerTimeoutError.js.map +7 -0
  17. package/src/bundle.d.ts +1 -1
  18. package/src/bundle.d.ts.map +1 -1
  19. package/src/bundle.js +1 -1
  20. package/src/bundle.js.map +2 -2
  21. package/src/constants.d.ts +13 -2
  22. package/src/constants.d.ts.map +1 -1
  23. package/src/constants.js +7 -1
  24. package/src/constants.js.map +2 -2
  25. package/src/create-worker.bundle.d.ts +1 -1
  26. package/src/create-worker.bundle.d.ts.map +1 -1
  27. package/src/create-worker.bundle.js.map +1 -1
  28. package/src/create-worker.d.ts +1 -1
  29. package/src/create-worker.d.ts.map +1 -1
  30. package/src/create-worker.js.map +1 -1
  31. package/src/elements/ShaeElement.d.ts +70 -2
  32. package/src/elements/ShaeElement.d.ts.map +1 -1
  33. package/src/elements/ShaeElement.js +129 -25
  34. package/src/elements/ShaeElement.js.map +3 -3
  35. package/src/elements/ShaeEntElement.d.ts +39 -1
  36. package/src/elements/ShaeEntElement.d.ts.map +1 -1
  37. package/src/elements/ShaeEntElement.js +397 -167
  38. package/src/elements/ShaeEntElement.js.map +2 -2
  39. package/src/elements/ShaeLifecycleElement.d.ts +71 -0
  40. package/src/elements/ShaeLifecycleElement.d.ts.map +1 -0
  41. package/src/elements/ShaeLifecycleElement.js +83 -0
  42. package/src/elements/ShaeLifecycleElement.js.map +7 -0
  43. package/src/elements/ShaePropElement.d.ts +61 -2
  44. package/src/elements/ShaePropElement.d.ts.map +1 -1
  45. package/src/elements/ShaePropElement.js +264 -219
  46. package/src/elements/ShaePropElement.js.map +2 -2
  47. package/src/elements/ShaeWorkerElement.d.ts +59 -5
  48. package/src/elements/ShaeWorkerElement.d.ts.map +1 -1
  49. package/src/elements/ShaeWorkerElement.js +271 -73
  50. package/src/elements/ShaeWorkerElement.js.map +2 -2
  51. package/src/elements/constants.d.ts +9 -0
  52. package/src/elements/constants.d.ts.map +1 -1
  53. package/src/elements/constants.js +18 -0
  54. package/src/elements/constants.js.map +2 -2
  55. package/src/elements/deferredTeardown.d.ts +24 -0
  56. package/src/elements/deferredTeardown.d.ts.map +1 -0
  57. package/src/elements/deferredTeardown.js +30 -0
  58. package/src/elements/deferredTeardown.js.map +7 -0
  59. package/src/elements/displayContentsRule.d.ts +25 -0
  60. package/src/elements/displayContentsRule.d.ts.map +1 -0
  61. package/src/elements/displayContentsRule.js +37 -0
  62. package/src/elements/displayContentsRule.js.map +7 -0
  63. package/src/elements/events.d.ts +10 -7
  64. package/src/elements/events.d.ts.map +1 -1
  65. package/src/elements/forwardCustomEvents.d.ts +19 -0
  66. package/src/elements/forwardCustomEvents.d.ts.map +1 -0
  67. package/src/elements/forwardCustomEvents.js +47 -0
  68. package/src/elements/forwardCustomEvents.js.map +7 -0
  69. package/src/elements/hostedSlots.d.ts +36 -0
  70. package/src/elements/hostedSlots.d.ts.map +1 -0
  71. package/src/elements/hostedSlots.js +118 -0
  72. package/src/elements/hostedSlots.js.map +7 -0
  73. package/src/elements/parentRemoval.d.ts +18 -0
  74. package/src/elements/parentRemoval.d.ts.map +1 -0
  75. package/src/elements/parentRemoval.js +60 -0
  76. package/src/elements/parentRemoval.js.map +7 -0
  77. package/src/elements/propValueConverters.d.ts +3 -0
  78. package/src/elements/propValueConverters.d.ts.map +1 -0
  79. package/src/elements/propValueConverters.js +54 -0
  80. package/src/elements/propValueConverters.js.map +7 -0
  81. package/src/elements/requestEntAncestor.d.ts +32 -0
  82. package/src/elements/requestEntAncestor.d.ts.map +1 -0
  83. package/src/elements/requestEntAncestor.js +16 -0
  84. package/src/elements/requestEntAncestor.js.map +7 -0
  85. package/src/elements.js.map +1 -1
  86. package/src/in-the-dark/Entity.d.ts +143 -3
  87. package/src/in-the-dark/Entity.d.ts.map +1 -1
  88. package/src/in-the-dark/Entity.js +330 -63
  89. package/src/in-the-dark/Entity.js.map +3 -3
  90. package/src/in-the-dark/Kernel.d.ts +98 -16
  91. package/src/in-the-dark/Kernel.d.ts.map +1 -1
  92. package/src/in-the-dark/Kernel.js +466 -379
  93. package/src/in-the-dark/Kernel.js.map +3 -3
  94. package/src/in-the-dark/Registry.d.ts +7 -1
  95. package/src/in-the-dark/Registry.d.ts.map +1 -1
  96. package/src/in-the-dark/Registry.js +112 -14
  97. package/src/in-the-dark/Registry.js.map +2 -2
  98. package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
  99. package/src/in-the-dark/ShadowObject.js +1 -0
  100. package/src/in-the-dark/ShadowObject.js.map +2 -2
  101. package/src/in-the-dark/ShadowObjectCreationScope.d.ts +133 -0
  102. package/src/in-the-dark/ShadowObjectCreationScope.d.ts.map +1 -0
  103. package/src/in-the-dark/ShadowObjectCreationScope.js +603 -0
  104. package/src/in-the-dark/ShadowObjectCreationScope.js.map +7 -0
  105. package/src/in-the-dark/SignalsPath.d.ts +2 -0
  106. package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
  107. package/src/in-the-dark/SignalsPath.js +6 -2
  108. package/src/in-the-dark/SignalsPath.js.map +2 -2
  109. package/src/in-the-dark/displayName.d.ts +4 -0
  110. package/src/in-the-dark/displayName.d.ts.map +1 -0
  111. package/src/in-the-dark/displayName.js +5 -0
  112. package/src/in-the-dark/displayName.js.map +7 -0
  113. package/src/in-the-dark/events.js.map +1 -1
  114. package/src/in-the-dark/importModule.d.ts +7 -0
  115. package/src/in-the-dark/importModule.d.ts.map +1 -1
  116. package/src/in-the-dark/importModule.js +5 -2
  117. package/src/in-the-dark/importModule.js.map +2 -2
  118. package/src/index.d.ts +9 -1
  119. package/src/index.d.ts.map +1 -1
  120. package/src/index.js +9 -1
  121. package/src/index.js.map +2 -2
  122. package/src/inspect/createKernelSnapshot.d.ts +17 -0
  123. package/src/inspect/createKernelSnapshot.d.ts.map +1 -0
  124. package/src/inspect/createKernelSnapshot.js +247 -0
  125. package/src/inspect/createKernelSnapshot.js.map +7 -0
  126. package/src/inspect/createViewSnapshot.d.ts +10 -0
  127. package/src/inspect/createViewSnapshot.d.ts.map +1 -0
  128. package/src/inspect/createViewSnapshot.js +143 -0
  129. package/src/inspect/createViewSnapshot.js.map +7 -0
  130. package/src/inspect/normalizeInspectRequest.d.ts +32 -0
  131. package/src/inspect/normalizeInspectRequest.d.ts.map +1 -0
  132. package/src/inspect/normalizeInspectRequest.js +55 -0
  133. package/src/inspect/normalizeInspectRequest.js.map +7 -0
  134. package/src/inspect/serializeValue.d.ts +13 -0
  135. package/src/inspect/serializeValue.d.ts.map +1 -0
  136. package/src/inspect/serializeValue.js +149 -0
  137. package/src/inspect/serializeValue.js.map +7 -0
  138. package/src/inspect/types.d.ts +260 -0
  139. package/src/inspect/types.d.ts.map +1 -0
  140. package/src/inspect/types.js +1 -0
  141. package/src/inspect/types.js.map +7 -0
  142. package/src/model-context/ModelContextLike.d.ts +59 -0
  143. package/src/model-context/ModelContextLike.d.ts.map +1 -0
  144. package/src/model-context/ModelContextLike.js +15 -0
  145. package/src/model-context/ModelContextLike.js.map +7 -0
  146. package/src/model-context/exposeShadowEnvsToModelContext.d.ts +48 -0
  147. package/src/model-context/exposeShadowEnvsToModelContext.d.ts.map +1 -0
  148. package/src/model-context/exposeShadowEnvsToModelContext.js +39 -0
  149. package/src/model-context/exposeShadowEnvsToModelContext.js.map +7 -0
  150. package/src/model-context/redactProps.d.ts +14 -0
  151. package/src/model-context/redactProps.d.ts.map +1 -0
  152. package/src/model-context/redactProps.js +22 -0
  153. package/src/model-context/redactProps.js.map +7 -0
  154. package/src/model-context/sharedExposure.d.ts +32 -0
  155. package/src/model-context/sharedExposure.d.ts.map +1 -0
  156. package/src/model-context/sharedExposure.js +108 -0
  157. package/src/model-context/sharedExposure.js.map +7 -0
  158. package/src/model-context/toolSupport.d.ts +72 -0
  159. package/src/model-context/toolSupport.d.ts.map +1 -0
  160. package/src/model-context/toolSupport.js +145 -0
  161. package/src/model-context/toolSupport.js.map +7 -0
  162. package/src/model-context/tools/findEntities.d.ts +15 -0
  163. package/src/model-context/tools/findEntities.d.ts.map +1 -0
  164. package/src/model-context/tools/findEntities.js +71 -0
  165. package/src/model-context/tools/findEntities.js.map +7 -0
  166. package/src/model-context/tools/getEntity.d.ts +16 -0
  167. package/src/model-context/tools/getEntity.d.ts.map +1 -0
  168. package/src/model-context/tools/getEntity.js +65 -0
  169. package/src/model-context/tools/getEntity.js.map +7 -0
  170. package/src/model-context/tools/getEntityTree.d.ts +4 -0
  171. package/src/model-context/tools/getEntityTree.d.ts.map +1 -0
  172. package/src/model-context/tools/getEntityTree.js +58 -0
  173. package/src/model-context/tools/getEntityTree.js.map +7 -0
  174. package/src/model-context/tools/getRegistry.d.ts +14 -0
  175. package/src/model-context/tools/getRegistry.d.ts.map +1 -0
  176. package/src/model-context/tools/getRegistry.js +39 -0
  177. package/src/model-context/tools/getRegistry.js.map +7 -0
  178. package/src/model-context/tools/index.d.ts +9 -0
  179. package/src/model-context/tools/index.d.ts.map +1 -0
  180. package/src/model-context/tools/index.js +16 -0
  181. package/src/model-context/tools/index.js.map +7 -0
  182. package/src/model-context/tools/listEnvs.d.ts +33 -0
  183. package/src/model-context/tools/listEnvs.d.ts.map +1 -0
  184. package/src/model-context/tools/listEnvs.js +37 -0
  185. package/src/model-context/tools/listEnvs.js.map +7 -0
  186. package/src/model-context.d.ts +13 -0
  187. package/src/model-context.d.ts.map +1 -0
  188. package/src/model-context.js +15 -0
  189. package/src/model-context.js.map +7 -0
  190. package/src/shadow-objects.d.ts +4 -0
  191. package/src/shadow-objects.d.ts.map +1 -1
  192. package/src/shadow-objects.js +6 -0
  193. package/src/shadow-objects.js.map +2 -2
  194. package/src/shadow-objects.worker.js +0 -1
  195. package/src/shadow-objects.worker.js.map +2 -2
  196. package/src/shae-ent.js.map +1 -1
  197. package/src/shae-prop.js +2 -2
  198. package/src/shae-prop.js.map +2 -2
  199. package/src/shae-worker.js.map +1 -1
  200. package/src/testing/TestEntity.d.ts +79 -0
  201. package/src/testing/TestEntity.d.ts.map +1 -0
  202. package/src/testing/TestEntity.js +135 -0
  203. package/src/testing/TestEntity.js.map +7 -0
  204. package/src/testing/createTestKernel.d.ts +11 -0
  205. package/src/testing/createTestKernel.d.ts.map +1 -0
  206. package/src/testing/createTestKernel.js +132 -0
  207. package/src/testing/createTestKernel.js.map +7 -0
  208. package/src/testing/mountShadowObject.d.ts +21 -0
  209. package/src/testing/mountShadowObject.d.ts.map +1 -0
  210. package/src/testing/mountShadowObject.js +72 -0
  211. package/src/testing/mountShadowObject.js.map +7 -0
  212. package/src/testing/recordKernelErrors.d.ts +21 -0
  213. package/src/testing/recordKernelErrors.d.ts.map +1 -0
  214. package/src/testing/recordKernelErrors.js +39 -0
  215. package/src/testing/recordKernelErrors.js.map +7 -0
  216. package/src/testing/settle.d.ts +15 -0
  217. package/src/testing/settle.d.ts.map +1 -0
  218. package/src/testing/settle.js +19 -0
  219. package/src/testing/settle.js.map +7 -0
  220. package/src/testing/types.d.ts +119 -0
  221. package/src/testing/types.d.ts.map +1 -0
  222. package/src/testing/types.js +1 -0
  223. package/src/testing/types.js.map +7 -0
  224. package/src/testing.d.ts +14 -0
  225. package/src/testing.d.ts.map +1 -0
  226. package/src/testing.js +11 -0
  227. package/src/testing.js.map +7 -0
  228. package/src/types.d.ts +185 -14
  229. package/src/types.d.ts.map +1 -1
  230. package/src/utils/ConsoleLogger.d.ts +45 -10
  231. package/src/utils/ConsoleLogger.d.ts.map +1 -1
  232. package/src/utils/ConsoleLogger.js +51 -26
  233. package/src/utils/ConsoleLogger.js.map +2 -2
  234. package/src/utils/FrameLoop.d.ts +42 -3
  235. package/src/utils/FrameLoop.d.ts.map +1 -1
  236. package/src/utils/FrameLoop.js +71 -10
  237. package/src/utils/FrameLoop.js.map +2 -2
  238. package/src/utils/MicrotaskCollector.d.ts +45 -0
  239. package/src/utils/MicrotaskCollector.d.ts.map +1 -0
  240. package/src/utils/MicrotaskCollector.js +33 -0
  241. package/src/utils/MicrotaskCollector.js.map +7 -0
  242. package/src/utils/MicrotaskGate.d.ts +17 -0
  243. package/src/utils/MicrotaskGate.d.ts.map +1 -0
  244. package/src/utils/MicrotaskGate.js +20 -0
  245. package/src/utils/MicrotaskGate.js.map +7 -0
  246. package/src/utils/array-utils.js.map +1 -1
  247. package/src/utils/attr-utils.d.ts +11 -0
  248. package/src/utils/attr-utils.d.ts.map +1 -1
  249. package/src/utils/attr-utils.js +5 -1
  250. package/src/utils/attr-utils.js.map +2 -2
  251. package/src/utils/constants.js.map +1 -1
  252. package/src/utils/generateUUID.d.ts +11 -0
  253. package/src/utils/generateUUID.d.ts.map +1 -1
  254. package/src/utils/generateUUID.js +31 -266
  255. package/src/utils/generateUUID.js.map +2 -2
  256. package/src/utils/props-utils.d.ts +3 -2
  257. package/src/utils/props-utils.d.ts.map +1 -1
  258. package/src/utils/props-utils.js +13 -24
  259. package/src/utils/props-utils.js.map +2 -2
  260. package/src/utils/runGuarded.d.ts +27 -0
  261. package/src/utils/runGuarded.d.ts.map +1 -0
  262. package/src/utils/runGuarded.js +11 -0
  263. package/src/utils/runGuarded.js.map +7 -0
  264. package/src/utils/toMaybe.d.ts.map +1 -1
  265. package/src/utils/toMaybe.js.map +1 -1
  266. package/src/utils/toNamespace.d.ts.map +1 -1
  267. package/src/utils/toNamespace.js.map +1 -1
  268. package/src/utils/toUrlString.d.ts +12 -0
  269. package/src/utils/toUrlString.d.ts.map +1 -1
  270. package/src/utils/toUrlString.js.map +2 -2
  271. package/src/utils/waitForMessageOfType.d.ts +12 -1
  272. package/src/utils/waitForMessageOfType.d.ts.map +1 -1
  273. package/src/utils/waitForMessageOfType.js +16 -1
  274. package/src/utils/waitForMessageOfType.js.map +2 -2
  275. package/src/view/ComponentChanges.d.ts +88 -1
  276. package/src/view/ComponentChanges.d.ts.map +1 -1
  277. package/src/view/ComponentChanges.js +243 -73
  278. package/src/view/ComponentChanges.js.map +2 -2
  279. package/src/view/ComponentContext.d.ts +206 -16
  280. package/src/view/ComponentContext.d.ts.map +1 -1
  281. package/src/view/ComponentContext.js +548 -91
  282. package/src/view/ComponentContext.js.map +2 -2
  283. package/src/view/ComponentMemory.d.ts +3 -3
  284. package/src/view/ComponentMemory.d.ts.map +1 -1
  285. package/src/view/ComponentMemory.js.map +1 -1
  286. package/src/view/IShadowObjectEnvProxy.d.ts +38 -3
  287. package/src/view/IShadowObjectEnvProxy.d.ts.map +1 -1
  288. package/src/view/LocalShadowObjectEnv.d.ts +8 -1
  289. package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
  290. package/src/view/LocalShadowObjectEnv.js +23 -7
  291. package/src/view/LocalShadowObjectEnv.js.map +2 -2
  292. package/src/view/RemoteWorkerEnv.d.ts +108 -5
  293. package/src/view/RemoteWorkerEnv.d.ts.map +1 -1
  294. package/src/view/RemoteWorkerEnv.js +244 -77
  295. package/src/view/RemoteWorkerEnv.js.map +2 -2
  296. package/src/view/ShadowEnv.d.ts +79 -2
  297. package/src/view/ShadowEnv.d.ts.map +1 -1
  298. package/src/view/ShadowEnv.js +323 -59
  299. package/src/view/ShadowEnv.js.map +3 -3
  300. package/src/view/ViewComponent.d.ts +78 -14
  301. package/src/view/ViewComponent.d.ts.map +1 -1
  302. package/src/view/ViewComponent.js +90 -14
  303. package/src/view/ViewComponent.js.map +2 -2
  304. package/src/view/cloneChangeTrail.js.map +2 -2
  305. package/src/worker/MessageRouter.d.ts +14 -0
  306. package/src/worker/MessageRouter.d.ts.map +1 -1
  307. package/src/worker/MessageRouter.js +98 -15
  308. package/src/worker/MessageRouter.js.map +2 -2
  309. package/src/worker/WorkerRuntime.d.ts +22 -1
  310. package/src/worker/WorkerRuntime.d.ts.map +1 -1
  311. package/src/worker/WorkerRuntime.js +60 -8
  312. package/src/worker/WorkerRuntime.js.map +2 -2
@@ -46,18 +46,54 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
46
46
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
47
47
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
48
48
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
49
- var _proxyReady_dec, _viewReady_dec, _comCtx, _shaObjEnvProxy, _syncScheduled, _syncAfterContextCreated, _syncWaitForConfirmation, _afterNextSync, _init, _viewReady, _proxyReady, _isDestroyed, _whenDestroyed, _rejectWhenDestroyed, _ShadowEnv_instances, destroyedSignal_fn, _syncIfScheduled, syncNow_fn, onMessageToView_fn, onProxyFailed_fn;
50
- import { emit, off, on, onceAsync, Priority, retain, retainClear } from "@spearwolf/eventize";
51
- import { createEffect, createSignal, destroyObjectSignals, findObjectSignalByName } from "@spearwolf/signalize";
49
+ var __privateWrapper = (obj, member, setter, getter) => ({
50
+ set _(value) {
51
+ __privateSet(obj, member, value, setter);
52
+ },
53
+ get _() {
54
+ return __privateGet(obj, member, getter);
55
+ }
56
+ });
57
+ var _proxyReady_dec, _viewReady_dec, _comCtx, _shaObjEnvProxy, _syncScheduled, _syncAfterContextCreated, _syncWaitForConfirmation, _nextSyncCycle, _logger, _init, _viewReady, _proxyReady, _isDestroyed, _contextEffect, _ShadowEnv_instances, ensureContextEffect_fn, releaseNamespace_fn, _proxyGeneration, _whenDestroyed, _rejectWhenDestroyed, destroyedSignal_fn, openSyncCycle_fn, _syncIfScheduled, syncNow_fn, commitSyncCycle_fn, announceContext_fn, endSyncCycle_fn, onMessageToView_fn, onProxyFailed_fn;
58
+ import { emitStrict, off, on, onceAsync, Priority, retain, retainClear } from "@spearwolf/eventize";
59
+ import {
60
+ createEffect,
61
+ createSignal,
62
+ destroyObjectSignals,
63
+ findObjectSignalByName,
64
+ hibernate
65
+ } from "@spearwolf/signalize";
52
66
  import { signal } from "@spearwolf/signalize/decorators";
67
+ import { ChangeTrailRefusedError } from "../ChangeTrailRefusedError.js";
68
+ import { GlobalNS } from "../constants.js";
69
+ import { createViewSnapshot } from "../inspect/createViewSnapshot.js";
53
70
  import { ConsoleLogger } from "../utils/ConsoleLogger.js";
54
71
  import { ComponentContext } from "./ComponentContext.js";
72
+ import { RemoteWorkerEnv } from "./RemoteWorkerEnv.js";
55
73
  class ShadowEnvDestroyedError extends Error {
56
74
  constructor(message = "the shadow environment has been destroyed") {
57
75
  super(message);
58
76
  this.name = "ShadowEnvDestroyedError";
59
77
  }
60
78
  }
79
+ const namespaceAsString = (ns) => typeof ns === "symbol" ? ns.description ?? String(ns) : ns ?? "";
80
+ const errorInfo = (error) => error instanceof Error ? { name: error.name, message: error.message } : { name: "Error", message: String(error) };
81
+ const abortRace = (signal2) => {
82
+ let onAbort;
83
+ const promise = new Promise((_, reject) => {
84
+ onAbort = () => reject(signal2.reason);
85
+ signal2.addEventListener("abort", onAbort, { once: true });
86
+ });
87
+ promise.catch(() => {
88
+ });
89
+ return { promise, dispose: () => signal2.removeEventListener("abort", onAbort) };
90
+ };
91
+ const proxyKind = (proxy) => {
92
+ if (proxy === void 0) return "none";
93
+ if (proxy.isLocalEnv === true) return "local";
94
+ if (proxy instanceof RemoteWorkerEnv) return "worker";
95
+ return "custom";
96
+ };
61
97
  _viewReady_dec = [signal()], _proxyReady_dec = [signal()];
62
98
  const _ShadowEnv = class _ShadowEnv {
63
99
  constructor() {
@@ -67,12 +103,22 @@ const _ShadowEnv = class _ShadowEnv {
67
103
  __privateAdd(this, _syncScheduled, false);
68
104
  __privateAdd(this, _syncAfterContextCreated, false);
69
105
  __privateAdd(this, _syncWaitForConfirmation, false);
70
- __privateAdd(this, _afterNextSync);
71
- this.logger = new ConsoleLogger("ShadowEnv");
106
+ __privateAdd(this, _nextSyncCycle);
107
+ __privateAdd(this, _logger, new ConsoleLogger("ShadowEnv"));
108
+ /**
109
+ * The namespace of the {@link ComponentContext} this environment observes, and `undefined`
110
+ * while it observes none. The `view` setter writes it, so it carries the name
111
+ * {@link ShadowEnv.get} finds this environment under, unless another environment has since
112
+ * taken that namespace over; a `destroy()` leaves it on `undefined`.
113
+ */
72
114
  this.ns$ = createSignal();
73
115
  __privateAdd(this, _viewReady, __runInitializers(_init, 8, this, false)), __runInitializers(_init, 11, this);
74
116
  __privateAdd(this, _proxyReady, __runInitializers(_init, 12, this, false)), __runInitializers(_init, 15, this);
75
117
  __privateAdd(this, _isDestroyed, false);
118
+ __privateAdd(this, _contextEffect);
119
+ // Each assignment to `envProxy` opens a generation. A start that finishes outside the generation
120
+ // it belongs to speaks for a proxy this environment has already let go, and is discarded.
121
+ __privateAdd(this, _proxyGeneration, 0);
76
122
  __privateAdd(this, _whenDestroyed);
77
123
  __privateAdd(this, _rejectWhenDestroyed);
78
124
  /**
@@ -92,27 +138,45 @@ const _ShadowEnv = class _ShadowEnv {
92
138
  });
93
139
  const self = this;
94
140
  retain(self, _ShadowEnv.ContextCreated);
95
- on(self, _ShadowEnv.ContextLost, Priority.AAA, () => {
141
+ on(self, _ShadowEnv.ContextLost, Priority.Critical, () => {
96
142
  retainClear(self, _ShadowEnv.ContextCreated);
97
143
  });
98
- createEffect(() => {
99
- if (this.viewReady && this.proxyReady) {
100
- this.view.reCreateChanges();
101
- emit(self, _ShadowEnv.ContextCreated, self);
102
- if (__privateGet(this, _syncAfterContextCreated)) {
103
- __privateSet(this, _syncAfterContextCreated, false);
104
- __privateMethod(this, _ShadowEnv_instances, syncNow_fn).call(this);
105
- }
106
- return () => {
107
- emit(self, _ShadowEnv.ContextLost, self);
108
- };
109
- }
110
- }, [findObjectSignalByName(this, "viewReady"), findObjectSignalByName(this, "proxyReady")]);
111
144
  }
112
145
  static get(ns) {
113
146
  if (ns == null) return void 0;
114
147
  return globalThis.__shadowEnvs?.get(ns);
115
148
  }
149
+ /**
150
+ * Every environment that holds a namespace, in registration order, each described by
151
+ * {@link ShadowEnv.inspect}. One environment that cannot answer costs its own entry and not the
152
+ * list: the per-environment failures are reported under `error`, and an environment destroyed
153
+ * while it answers drops out of the list. Rejects only for the caller's reasons -- an aborted
154
+ * signal.
155
+ *
156
+ * `only` narrows the list before anything is asked: it is called with the namespace an
157
+ * environment is registered under, and an environment it refuses is neither inspected nor
158
+ * listed. That is what lets a caller keep an environment out of a picture without touching it.
159
+ */
160
+ static async inspectAll(request = {}, signal2, only) {
161
+ const envs = [];
162
+ for (const [ns, env] of globalThis.__shadowEnvs?.entries() ?? []) {
163
+ if (only === void 0 || only(ns)) envs.push(env);
164
+ }
165
+ const settled = await Promise.all(
166
+ envs.map(
167
+ (env) => env.inspect(request, signal2).catch((error) => {
168
+ if (signal2?.aborted) throw signal2.reason;
169
+ if (error instanceof ShadowEnvDestroyedError) return void 0;
170
+ throw error;
171
+ })
172
+ )
173
+ );
174
+ return settled.filter((snapshot) => snapshot !== void 0);
175
+ }
176
+ /** The logger this environment reports through. */
177
+ get logger() {
178
+ return __privateGet(this, _logger);
179
+ }
116
180
  get isDestroyed() {
117
181
  return __privateGet(this, _isDestroyed);
118
182
  }
@@ -121,23 +185,17 @@ const _ShadowEnv = class _ShadowEnv {
121
185
  }
122
186
  set view(ctx) {
123
187
  if (ctx !== __privateGet(this, _comCtx)) {
124
- if (__privateGet(this, _comCtx)?.ns && globalThis.__shadowEnvs) {
125
- globalThis.__shadowEnvs.delete(__privateGet(this, _comCtx).ns);
126
- }
188
+ if (ctx) __privateMethod(this, _ShadowEnv_instances, ensureContextEffect_fn).call(this);
189
+ __privateMethod(this, _ShadowEnv_instances, releaseNamespace_fn).call(this, __privateGet(this, _comCtx)?.ns);
127
190
  __privateSet(this, _comCtx, ctx ?? void 0);
128
191
  if (__privateGet(this, _comCtx)?.ns) {
129
192
  globalThis.__shadowEnvs ??= /* @__PURE__ */ new Map();
130
193
  if (globalThis.__shadowEnvs.has(__privateGet(this, _comCtx).ns) && globalThis.__shadowEnvs.get(__privateGet(this, _comCtx).ns) !== this) {
131
- if (this.logger.isWarn) {
132
- this.logger.warn(
133
- "overwrite a namespace already in use",
134
- __privateGet(this, _comCtx).ns,
135
- globalThis.__shadowEnvs.get(__privateGet(this, _comCtx).ns)
136
- );
137
- }
194
+ this.logger.warn("overwrite a namespace already in use", __privateGet(this, _comCtx).ns, globalThis.__shadowEnvs.get(__privateGet(this, _comCtx).ns));
138
195
  }
139
196
  globalThis.__shadowEnvs.set(__privateGet(this, _comCtx).ns, this);
140
197
  }
198
+ this.ns$.set(__privateGet(this, _comCtx)?.ns);
141
199
  this.viewReady = Boolean(ctx);
142
200
  }
143
201
  }
@@ -146,19 +204,27 @@ const _ShadowEnv = class _ShadowEnv {
146
204
  }
147
205
  set envProxy(proxy) {
148
206
  if (proxy !== __privateGet(this, _shaObjEnvProxy)) {
207
+ if (proxy) __privateMethod(this, _ShadowEnv_instances, ensureContextEffect_fn).call(this);
149
208
  const prevProxy = __privateGet(this, _shaObjEnvProxy);
150
209
  __privateSet(this, _shaObjEnvProxy, proxy ?? void 0);
210
+ const generation = ++__privateWrapper(this, _proxyGeneration)._;
151
211
  if (__privateGet(this, _shaObjEnvProxy)) {
152
212
  __privateGet(this, _shaObjEnvProxy).onMessageToView = __privateMethod(this, _ShadowEnv_instances, onMessageToView_fn).bind(this);
153
213
  __privateGet(this, _shaObjEnvProxy).onProxyFailed = __privateMethod(this, _ShadowEnv_instances, onProxyFailed_fn).bind(this);
154
214
  }
155
215
  if (prevProxy) {
156
216
  prevProxy.destroy();
217
+ prevProxy.onProxyFailed = void 0;
218
+ queueMicrotask(() => {
219
+ prevProxy.onMessageToView = void 0;
220
+ });
157
221
  }
158
222
  this.proxyReady = false;
159
223
  proxy?.start().then(() => {
224
+ if (generation !== __privateGet(this, _proxyGeneration)) return;
160
225
  this.proxyReady = true;
161
226
  }).catch((error) => {
227
+ if (generation !== __privateGet(this, _proxyGeneration)) return;
162
228
  this.logger.error("failed to start envProxy", error);
163
229
  this.proxyReady = false;
164
230
  });
@@ -167,6 +233,21 @@ const _ShadowEnv = class _ShadowEnv {
167
233
  get isReady() {
168
234
  return Boolean(__privateGet(this, _comCtx) && __privateGet(this, _shaObjEnvProxy) && this.proxyReady && !this.isDestroyed);
169
235
  }
236
+ /**
237
+ * Send the change trail without asking the Shadow Environment to confirm it --
238
+ * {@link ShadowEnv.syncWait} is the call that asks.
239
+ *
240
+ * What becomes of a refusal is then the proxy's decision, and the two shipped ones differ.
241
+ * `LocalShadowObjectEnv` runs the Kernel synchronously, inside the call the environment makes to
242
+ * the proxy -- one microtask after `sync()` returned, not inside the call to `sync()` itself --
243
+ * and rejects with what it threw, so a refusal reaches {@link ShadowEnv.SyncFailed} here as well,
244
+ * carrying its number.
245
+ * `RemoteWorkerEnv` sends no serial without a confirmation and gets no answer back, so a
246
+ * refusal stays in the worker: it is written to the console there, `SyncFailed` stays silent, and
247
+ * the whole trail is booked as applied.
248
+ *
249
+ * {@link ShadowEnv.syncWait} is the way both proxies answer on.
250
+ */
170
251
  sync() {
171
252
  if (__privateGet(this, _isDestroyed)) return;
172
253
  if (!this.isReady) {
@@ -180,27 +261,91 @@ const _ShadowEnv = class _ShadowEnv {
180
261
  /**
181
262
  * Like {@link ShadowEnv.sync}, but resolves with the change trail once the cycle completed.
182
263
  *
183
- * @throws {ShadowEnvDestroyedError} if the environment is destroyed before that happens
264
+ * A cycle whose change trail the Shadow Environment could not apply rejects instead, with the
265
+ * reason the proxy gave. Where the Kernel itself refused the trail that reason is a
266
+ * {@link ChangeTrailRefusedError}: it names how many entries the Kernel applied, this side folds
267
+ * exactly those into its bookkeeping, and everything behind that line stays pending and goes out
268
+ * again with the next cycle. A trail whose cause of refusal stays put is refused every time, which
269
+ * is what {@link ShadowEnv.SyncFailed} is the place to act on.
270
+ *
271
+ * A reason that says nothing about how far the Kernel got -- a confirmation window that ran out,
272
+ * a proxy whose environment is gone -- counts the whole trail as applied, because a Shadow
273
+ * Environment that fell silent may well hold all of it. Then the trail is gone, and only a
274
+ * re-creation from the Component Memory brings it back. That re-creation belongs to a fresh
275
+ * proxy: an environment that still holds the entities refuses a creation for a uuid it already
276
+ * has. Handing {@link ShadowEnv.envProxy} a new proxy is therefore the way back -- the Shadow
277
+ * Environment calls {@link ComponentContext.reCreateChanges} itself once the new proxy is ready.
278
+ * Making that call is the consumer's decision, the same way recovering from a
279
+ * {@link ShadowEnv.ProxyFailed} is.
280
+ *
281
+ * Which cycle a caller gets is decided when the change trail is built. Everyone who arrives
282
+ * before that point waits on the same promise -- they all ride the same trail. From the build
283
+ * on the trail is fixed, and a call after it belongs to the next cycle, the one that carries
284
+ * the changes made since. That holds inside a listener of {@link ShadowEnv.AfterSync} or
285
+ * {@link ShadowEnv.SyncFailed} as well: the cycle it was told about is over, so the call opens
286
+ * the one behind it.
287
+ *
288
+ * @throws {ShadowEnvDestroyedError} if the environment is destroyed before the cycle completes
184
289
  */
185
290
  syncWait() {
186
291
  if (__privateGet(this, _isDestroyed)) return Promise.reject(new ShadowEnvDestroyedError());
187
292
  __privateSet(this, _syncWaitForConfirmation, true);
188
293
  this.sync();
189
- if (__privateGet(this, _afterNextSync)) return __privateGet(this, _afterNextSync);
190
- __privateSet(this, _afterNextSync, Promise.race([
191
- onceAsync(this, _ShadowEnv.AfterSync),
192
- __privateMethod(this, _ShadowEnv_instances, destroyedSignal_fn).call(this)
193
- ]).then(
194
- (changeTrail) => {
195
- __privateSet(this, _afterNextSync, void 0);
196
- return changeTrail;
197
- },
198
- (error) => {
199
- __privateSet(this, _afterNextSync, void 0);
200
- throw error;
294
+ __privateGet(this, _nextSyncCycle) ?? __privateSet(this, _nextSyncCycle, __privateMethod(this, _ShadowEnv_instances, openSyncCycle_fn).call(this));
295
+ return __privateGet(this, _nextSyncCycle).promise;
296
+ }
297
+ /**
298
+ * Describe this environment: the View's component tree and, where the proxy is ready and
299
+ * implements `inspect`, the Kernel's Entity Tree behind it.
300
+ *
301
+ * Never rejects for a reason inside the environment -- a proxy that cannot answer, a Kernel that
302
+ * threw, a View snapshot that threw -- and reports those under `error`, with the half that failed
303
+ * absent. Where both halves fail, `error` carries the View's reason. A proxy that is not ready yet
304
+ * is not an error either: `state.proxyReady` says so, and `kernel` is simply absent. It rejects
305
+ * only for a reason of the caller's: an aborted signal, or an environment that is destroyed
306
+ * before or while the proxy answers. The signal is raced here as well, so an abort settles the
307
+ * call whether or not the proxy honours the signal it was handed.
308
+ *
309
+ * A caller that wants the View and the Kernel to agree after its own change awaits
310
+ * {@link ShadowEnv.syncWait} first; the View snapshot reads the committed Component Memory,
311
+ * not the pending changes.
312
+ */
313
+ async inspect(request = {}, signal2) {
314
+ if (__privateGet(this, _isDestroyed)) throw new ShadowEnvDestroyedError();
315
+ if (signal2?.aborted) throw signal2.reason;
316
+ const ns = __privateGet(this, _comCtx)?.ns;
317
+ const proxy = __privateGet(this, _shaObjEnvProxy);
318
+ const snapshot = {
319
+ namespace: namespaceAsString(ns),
320
+ isGlobalNamespace: ns === GlobalNS,
321
+ kind: proxyKind(proxy),
322
+ state: { viewReady: this.viewReady, proxyReady: this.proxyReady, isReady: this.isReady, isDestroyed: __privateGet(this, _isDestroyed) }
323
+ };
324
+ if (__privateGet(this, _comCtx)) {
325
+ try {
326
+ snapshot.view = createViewSnapshot(__privateGet(this, _comCtx), request);
327
+ } catch (error) {
328
+ snapshot.error = errorInfo(error);
201
329
  }
202
- ));
203
- return __privateGet(this, _afterNextSync);
330
+ }
331
+ if (proxy === void 0 || !this.proxyReady) return snapshot;
332
+ if (typeof proxy.inspect !== "function") {
333
+ snapshot.error = { name: "NotInspectable", message: "the environment proxy does not implement inspect()" };
334
+ return snapshot;
335
+ }
336
+ const aborted = signal2 === void 0 ? void 0 : abortRace(signal2);
337
+ const contenders = [proxy.inspect(request, signal2), __privateMethod(this, _ShadowEnv_instances, destroyedSignal_fn).call(this)];
338
+ if (aborted !== void 0) contenders.push(aborted.promise);
339
+ try {
340
+ snapshot.kernel = await Promise.race(contenders);
341
+ } catch (error) {
342
+ if (__privateGet(this, _isDestroyed)) throw new ShadowEnvDestroyedError();
343
+ if (signal2?.aborted) throw signal2.reason;
344
+ if (snapshot.error === void 0) snapshot.error = errorInfo(error);
345
+ } finally {
346
+ aborted?.dispose();
347
+ }
348
+ return snapshot;
204
349
  }
205
350
  /**
206
351
  * Tear the environment down: the proxy is destroyed, the namespace is released, all signals
@@ -215,15 +360,12 @@ const _ShadowEnv = class _ShadowEnv {
215
360
  __privateSet(this, _syncScheduled, false);
216
361
  __privateSet(this, _syncAfterContextCreated, false);
217
362
  __privateSet(this, _syncWaitForConfirmation, false);
218
- const ns = __privateGet(this, _comCtx)?.ns;
219
363
  this.envProxy = void 0;
220
364
  this.view = void 0;
221
- const shadowEnvs = globalThis.__shadowEnvs;
222
- if (ns && shadowEnvs?.get(ns) === this) {
223
- shadowEnvs.delete(ns);
224
- }
225
365
  (_a = __privateGet(this, _rejectWhenDestroyed)) == null ? void 0 : _a.call(this, new ShadowEnvDestroyedError());
226
- __privateSet(this, _afterNextSync, void 0);
366
+ __privateSet(this, _nextSyncCycle, void 0);
367
+ __privateGet(this, _contextEffect)?.destroy();
368
+ __privateSet(this, _contextEffect, void 0);
227
369
  destroyObjectSignals(this);
228
370
  off(this);
229
371
  Object.freeze(this);
@@ -235,13 +377,52 @@ _shaObjEnvProxy = new WeakMap();
235
377
  _syncScheduled = new WeakMap();
236
378
  _syncAfterContextCreated = new WeakMap();
237
379
  _syncWaitForConfirmation = new WeakMap();
238
- _afterNextSync = new WeakMap();
380
+ _nextSyncCycle = new WeakMap();
381
+ _logger = new WeakMap();
239
382
  _viewReady = new WeakMap();
240
383
  _proxyReady = new WeakMap();
241
384
  _isDestroyed = new WeakMap();
385
+ _contextEffect = new WeakMap();
386
+ _ShadowEnv_instances = new WeakSet();
387
+ /**
388
+ * Builds the effect that reports {@link ShadowEnv.ContextCreated} and {@link ShadowEnv.ContextLost}
389
+ * once, on the first half of the environment that arrives.
390
+ */
391
+ ensureContextEffect_fn = function() {
392
+ if (__privateGet(this, _isDestroyed) || __privateGet(this, _contextEffect) != null) return;
393
+ const self = this;
394
+ hibernate(() => {
395
+ __privateSet(this, _contextEffect, createEffect(() => {
396
+ if (this.viewReady && this.proxyReady) {
397
+ this.view.reCreateChanges();
398
+ __privateMethod(this, _ShadowEnv_instances, announceContext_fn).call(this, _ShadowEnv.ContextCreated, self);
399
+ if (__privateGet(this, _syncAfterContextCreated)) {
400
+ __privateSet(this, _syncAfterContextCreated, false);
401
+ __privateMethod(this, _ShadowEnv_instances, syncNow_fn).call(this);
402
+ }
403
+ return () => {
404
+ __privateMethod(this, _ShadowEnv_instances, announceContext_fn).call(this, _ShadowEnv.ContextLost, self);
405
+ };
406
+ }
407
+ }, [findObjectSignalByName(this, "viewReady"), findObjectSignalByName(this, "proxyReady")]));
408
+ });
409
+ };
410
+ /**
411
+ * Releases the namespace registration, but only while this environment holds it. A namespace
412
+ * carries one environment at a time, and an assignment that displaces another one leaves that
413
+ * other environment registered under nothing -- taking its entry along on the way out would
414
+ * make `ShadowEnv.get()` answer `undefined` for an environment that is very much alive.
415
+ */
416
+ releaseNamespace_fn = function(ns) {
417
+ if (!ns) return;
418
+ const shadowEnvs = globalThis.__shadowEnvs;
419
+ if (shadowEnvs?.get(ns) === this) {
420
+ shadowEnvs.delete(ns);
421
+ }
422
+ };
423
+ _proxyGeneration = new WeakMap();
242
424
  _whenDestroyed = new WeakMap();
243
425
  _rejectWhenDestroyed = new WeakMap();
244
- _ShadowEnv_instances = new WeakSet();
245
426
  /**
246
427
  * A promise that rejects the moment this environment is destroyed.
247
428
  *
@@ -259,6 +440,23 @@ destroyedSignal_fn = function() {
259
440
  }
260
441
  return __privateGet(this, _whenDestroyed);
261
442
  };
443
+ /**
444
+ * The cycle settles this promise by hand rather than through `AfterSync` / `SyncFailed`. A
445
+ * subscription made here would stand in line behind the listeners the application registered
446
+ * during setup, and an eventize emit stops at the first listener that throws -- everything
447
+ * behind it, this promise included, would be left waiting forever. Settling by hand also
448
+ * spares the bookkeeping a subscription per call would need: a cycle produces one of the two
449
+ * events, and the subscriber of the other one would stay behind and pile up.
450
+ */
451
+ openSyncCycle_fn = function() {
452
+ let resolve;
453
+ let reject;
454
+ const outcome = new Promise((res, rej) => {
455
+ resolve = res;
456
+ reject = rej;
457
+ });
458
+ return { promise: Promise.race([outcome, __privateMethod(this, _ShadowEnv_instances, destroyedSignal_fn).call(this)]), resolve, reject };
459
+ };
262
460
  _syncIfScheduled = new WeakMap();
263
461
  syncNow_fn = async function() {
264
462
  __privateSet(this, _syncScheduled, false);
@@ -267,7 +465,9 @@ syncNow_fn = async function() {
267
465
  __privateSet(this, _syncAfterContextCreated, true);
268
466
  return;
269
467
  }
270
- const data = this.view.buildChangeTrails();
468
+ const data = this.view.buildChangeTrails(false);
469
+ const cycle = __privateGet(this, _nextSyncCycle);
470
+ __privateSet(this, _nextSyncCycle, void 0);
271
471
  const waitForConfirmation = __privateGet(this, _syncWaitForConfirmation);
272
472
  __privateSet(this, _syncWaitForConfirmation, false);
273
473
  try {
@@ -275,22 +475,85 @@ syncNow_fn = async function() {
275
475
  await this.envProxy.applyChangeTrail(data, waitForConfirmation);
276
476
  }
277
477
  } catch (error) {
478
+ if (__privateGet(this, _isDestroyed)) return;
278
479
  this.logger.error("failed to apply change trail", error);
279
- } finally {
280
- emit(this, _ShadowEnv.AfterSync, data);
480
+ __privateMethod(this, _ShadowEnv_instances, commitSyncCycle_fn).call(this, data, error);
481
+ __privateMethod(this, _ShadowEnv_instances, endSyncCycle_fn).call(this, data, cycle, { reason: error });
482
+ return;
281
483
  }
484
+ if (__privateGet(this, _isDestroyed)) return;
485
+ __privateMethod(this, _ShadowEnv_instances, commitSyncCycle_fn).call(this, data);
486
+ __privateMethod(this, _ShadowEnv_instances, endSyncCycle_fn).call(this, data, cycle);
282
487
  };
283
- onMessageToView_fn = function(event) {
284
- if (this.logger.isDebug) {
285
- this.logger.debug("onMessageToView", event.type, event.data);
488
+ /**
489
+ * Draws the line between what the Shadow Environment applied and what it still owes, and hands
490
+ * it to the view. Runs ahead of {@link ShadowEnv.#endSyncCycle} so that a `SyncFailed` listener
491
+ * and a waiting {@link ShadowEnv.syncWait} caller find bookkeeping that already holds.
492
+ *
493
+ * An empty change trail is settled as well: the build may have retired components even without
494
+ * writing an entry for any of them.
495
+ */
496
+ commitSyncCycle_fn = function(changeTrail, reason) {
497
+ const appliedCount = reason instanceof ChangeTrailRefusedError ? reason.appliedCount : changeTrail.length;
498
+ this.view?.commitChangeTrail(appliedCount, changeTrail);
499
+ };
500
+ /**
501
+ * Sends one of the two context events and keeps a listener that throws to itself.
502
+ *
503
+ * Both go out from inside the effect that watches `viewReady` and `proxyReady` -- `ContextLost`
504
+ * from its cleanup -- so a throw would leave through whatever signal write set that effect
505
+ * going, and reach code that has nothing to do with either event. `emitStrict()` serves every
506
+ * listener whatever the one before it did, and what they threw is reported here and travels no
507
+ * further.
508
+ */
509
+ announceContext_fn = function(eventName, self) {
510
+ try {
511
+ emitStrict(self, eventName, self);
512
+ } catch (error) {
513
+ this.logger.error(`a ${eventName} listener threw`, error);
286
514
  }
515
+ };
516
+ /**
517
+ * Ends a synchronization cycle in exactly one of its two outcomes. A cycle the Shadow
518
+ * Environment applied resolves {@link ShadowEnv.syncWait} and emits {@link ShadowEnv.AfterSync};
519
+ * a cycle whose change trail it refused rejects and emits {@link ShadowEnv.SyncFailed}. Only a
520
+ * listener that can tell the two apart can react to either, so no cycle ever sends both.
521
+ *
522
+ * The waiting caller is settled before the event goes out, and the emit is the last thing that
523
+ * happens: a settlement that travelled as a listener of its own would sit behind whatever the
524
+ * application registered during setup, and this method is the wrong place to make a promise
525
+ * depend on the order consumers subscribe in. The dispatch is `emitStrict()`, so every listener
526
+ * hears about the cycle whatever the one before it did, and what they threw arrives here
527
+ * afterwards -- one of them unchanged, several as an `AggregateError` in dispatch order. It ends
528
+ * here as well: `#syncNow()` runs unawaited, and an error escaping it becomes an unhandled
529
+ * rejection rather than a report anybody reads.
530
+ *
531
+ * Which cycle is being ended arrives as an argument: the caller carries it from the moment its
532
+ * change trail was built, so a cycle that is still in flight cannot be settled by the one behind it.
533
+ */
534
+ endSyncCycle_fn = function(changeTrail, cycle, failure) {
535
+ try {
536
+ if (failure) {
537
+ cycle?.reject(failure.reason);
538
+ emitStrict(this, _ShadowEnv.SyncFailed, failure.reason, changeTrail, this);
539
+ } else {
540
+ cycle?.resolve(changeTrail);
541
+ emitStrict(this, _ShadowEnv.AfterSync, changeTrail);
542
+ }
543
+ } catch (error) {
544
+ this.logger.error("a sync cycle listener threw", error);
545
+ }
546
+ };
547
+ onMessageToView_fn = function(event) {
548
+ this.logger.debug("onMessageToView", event.type, event.data);
287
549
  this.view?.dispatchMessage(event.uuid, event.type, event.data, event.traverseChildren);
288
550
  };
289
551
  onProxyFailed_fn = function(reason) {
290
552
  if (__privateGet(this, _isDestroyed)) return;
291
553
  this.logger.error("the environment proxy failed", reason);
554
+ ++__privateWrapper(this, _proxyGeneration)._;
292
555
  try {
293
- emit(this, _ShadowEnv.ProxyFailed, reason, this);
556
+ emitStrict(this, _ShadowEnv.ProxyFailed, reason, this);
294
557
  } finally {
295
558
  this.proxyReady = false;
296
559
  }
@@ -299,6 +562,7 @@ __decorateElement(_init, 4, "viewReady", _viewReady_dec, _ShadowEnv, _viewReady)
299
562
  __decorateElement(_init, 4, "proxyReady", _proxyReady_dec, _ShadowEnv, _proxyReady);
300
563
  __decoratorMetadata(_init, _ShadowEnv);
301
564
  _ShadowEnv.AfterSync = "afterSync";
565
+ _ShadowEnv.SyncFailed = "syncFailed";
302
566
  _ShadowEnv.ContextLost = "contextLost";
303
567
  _ShadowEnv.ContextCreated = "contextCreated";
304
568
  _ShadowEnv.ProxyFailed = "proxyFailed";