@mountaya/elements 0.0.0-stage → 0.2.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.
- package/CHANGELOG.md +273 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +1510 -2
- package/THIRD-PARTY-NOTICES.txt +103 -0
- package/dist/agent/index.cjs +1211 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +1966 -0
- package/dist/agent/index.d.ts +1966 -0
- package/dist/agent/index.js +1181 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/camera/index.cjs +2512 -0
- package/dist/camera/index.cjs.map +1 -0
- package/dist/camera/index.d.cts +1723 -0
- package/dist/camera/index.d.ts +1723 -0
- package/dist/camera/index.js +2443 -0
- package/dist/camera/index.js.map +1 -0
- package/dist/chunk-5pTPpv4v.d.cts +897 -0
- package/dist/chunk-5pTPpv4v.d.ts +897 -0
- package/dist/chunk-6JzFMFHh.d.ts +119 -0
- package/dist/chunk-6qyuJVvt.d.ts +513 -0
- package/dist/chunk-9fp0lDic.cjs +583 -0
- package/dist/chunk-9fp0lDic.cjs.map +1 -0
- package/dist/chunk-A48H1rDg.d.cts +73 -0
- package/dist/chunk-A48H1rDg.d.ts +73 -0
- package/dist/chunk-B-m1AchR.cjs +57 -0
- package/dist/chunk-B-m1AchR.cjs.map +1 -0
- package/dist/chunk-B-qFTf04.d.ts +216 -0
- package/dist/chunk-B0YROiZh.d.cts +1475 -0
- package/dist/chunk-B14wgOvH.d.cts +68 -0
- package/dist/chunk-B19l3j9r.cjs +150 -0
- package/dist/chunk-B19l3j9r.cjs.map +1 -0
- package/dist/chunk-B2PtjVKg.cjs +86 -0
- package/dist/chunk-B2PtjVKg.cjs.map +1 -0
- package/dist/chunk-B56Oyb7W.cjs +70 -0
- package/dist/chunk-B56Oyb7W.cjs.map +1 -0
- package/dist/chunk-B5WGMQwK.cjs +113 -0
- package/dist/chunk-B5WGMQwK.cjs.map +1 -0
- package/dist/chunk-B98mKrdu.d.cts +302 -0
- package/dist/chunk-BB0PmqIM.d.cts +44 -0
- package/dist/chunk-BBikve0Z.cjs +269 -0
- package/dist/chunk-BBikve0Z.cjs.map +1 -0
- package/dist/chunk-BHeXmM0X.js +37 -0
- package/dist/chunk-BHeXmM0X.js.map +1 -0
- package/dist/chunk-BI8WZLpU.cjs +281 -0
- package/dist/chunk-BI8WZLpU.cjs.map +1 -0
- package/dist/chunk-BIEc_SkR.cjs +29 -0
- package/dist/chunk-BIEc_SkR.cjs.map +1 -0
- package/dist/chunk-BJ6L6_W9.cjs +553 -0
- package/dist/chunk-BJ6L6_W9.cjs.map +1 -0
- package/dist/chunk-BJ91UCbB.js +11 -0
- package/dist/chunk-BJ91UCbB.js.map +1 -0
- package/dist/chunk-BJEZWTKj.cjs +166 -0
- package/dist/chunk-BJEZWTKj.cjs.map +1 -0
- package/dist/chunk-BJz54mfg.cjs +10 -0
- package/dist/chunk-BJz54mfg.cjs.map +1 -0
- package/dist/chunk-BNX5LAfN.d.cts +912 -0
- package/dist/chunk-BP6KgA86.js +35 -0
- package/dist/chunk-BP6KgA86.js.map +1 -0
- package/dist/chunk-BRnjQq6K.d.cts +157 -0
- package/dist/chunk-BSiMEwPS.js +46 -0
- package/dist/chunk-BSiMEwPS.js.map +1 -0
- package/dist/chunk-BTPjDw_y.cjs +16 -0
- package/dist/chunk-BTPjDw_y.cjs.map +1 -0
- package/dist/chunk-BTUUABGI.js +17 -0
- package/dist/chunk-BTUUABGI.js.map +1 -0
- package/dist/chunk-BUeL9y7s.cjs +45 -0
- package/dist/chunk-BUeL9y7s.cjs.map +1 -0
- package/dist/chunk-BWMuCNc9.cjs +172 -0
- package/dist/chunk-BWMuCNc9.cjs.map +1 -0
- package/dist/chunk-BWjRfhpF.js +126 -0
- package/dist/chunk-BWjRfhpF.js.map +1 -0
- package/dist/chunk-BZ5KyZXI.d.ts +302 -0
- package/dist/chunk-B_4SVmvh.js +94 -0
- package/dist/chunk-B_4SVmvh.js.map +1 -0
- package/dist/chunk-BcTUuZQ3.js +95 -0
- package/dist/chunk-BcTUuZQ3.js.map +1 -0
- package/dist/chunk-BdkqSsJe.cjs +140 -0
- package/dist/chunk-BdkqSsJe.cjs.map +1 -0
- package/dist/chunk-BfktMVmI.js +70 -0
- package/dist/chunk-BfktMVmI.js.map +1 -0
- package/dist/chunk-BfzQb0EK.cjs +6 -0
- package/dist/chunk-BhWfT-22.d.cts +808 -0
- package/dist/chunk-BjJcqX5J.cjs +60 -0
- package/dist/chunk-BjJcqX5J.cjs.map +1 -0
- package/dist/chunk-Bk0L8g5J.d.cts +77 -0
- package/dist/chunk-Bk0L8g5J.d.ts +77 -0
- package/dist/chunk-Bl4_uVa6.cjs +11 -0
- package/dist/chunk-Bl4_uVa6.cjs.map +1 -0
- package/dist/chunk-BlKF4lrp.js +43 -0
- package/dist/chunk-BlKF4lrp.js.map +1 -0
- package/dist/chunk-Bm1FieGR.js +4 -0
- package/dist/chunk-Bm1FieGR.js.map +1 -0
- package/dist/chunk-Bn6ZbxkS.cjs +27 -0
- package/dist/chunk-BpN3hr6a.cjs +541 -0
- package/dist/chunk-BpN3hr6a.cjs.map +1 -0
- package/dist/chunk-Bq_WHTfd.d.cts +119 -0
- package/dist/chunk-Bqt4LBBz.cjs +648 -0
- package/dist/chunk-Bqt4LBBz.cjs.map +1 -0
- package/dist/chunk-Bqt97zwf.d.cts +54 -0
- package/dist/chunk-Bqt97zwf.d.ts +54 -0
- package/dist/chunk-BsBiN4w6.d.cts +245 -0
- package/dist/chunk-BvTpOUoC.cjs +207 -0
- package/dist/chunk-BvTpOUoC.cjs.map +1 -0
- package/dist/chunk-BwK6Hl3q.cjs +446 -0
- package/dist/chunk-BwK6Hl3q.cjs.map +1 -0
- package/dist/chunk-BxDQZDXR.d.cts +76 -0
- package/dist/chunk-BxDQZDXR.d.ts +76 -0
- package/dist/chunk-BxUio8kX.js +20 -0
- package/dist/chunk-BxUio8kX.js.map +1 -0
- package/dist/chunk-BxaocpFi.d.cts +1 -0
- package/dist/chunk-Bywi0K1N.js +36 -0
- package/dist/chunk-Bywi0K1N.js.map +1 -0
- package/dist/chunk-C-IlmkDl.js +59 -0
- package/dist/chunk-C-IlmkDl.js.map +1 -0
- package/dist/chunk-C5PtVewq.d.ts +389 -0
- package/dist/chunk-C5dpC7mQ.js +19 -0
- package/dist/chunk-C5dpC7mQ.js.map +1 -0
- package/dist/chunk-C5q1sgSa.js +46 -0
- package/dist/chunk-C5q1sgSa.js.map +1 -0
- package/dist/chunk-C6fU9G5I.cjs +221 -0
- package/dist/chunk-C6fU9G5I.cjs.map +1 -0
- package/dist/chunk-C71dpWUK.js +5 -0
- package/dist/chunk-C71dpWUK.js.map +1 -0
- package/dist/chunk-C82N1gQX.d.ts +1831 -0
- package/dist/chunk-C8HdaHpu.js +118 -0
- package/dist/chunk-C8HdaHpu.js.map +1 -0
- package/dist/chunk-C8ZGryck.js +236 -0
- package/dist/chunk-C8ZGryck.js.map +1 -0
- package/dist/chunk-C95NG0oD.cjs +43 -0
- package/dist/chunk-C95NG0oD.cjs.map +1 -0
- package/dist/chunk-C9aR8DXb.js +9 -0
- package/dist/chunk-C9aR8DXb.js.map +1 -0
- package/dist/chunk-CAUZnoCs.d.ts +525 -0
- package/dist/chunk-CBXWWuM9.cjs +82 -0
- package/dist/chunk-CBXWWuM9.cjs.map +1 -0
- package/dist/chunk-CC_Kquu7.d.cts +125 -0
- package/dist/chunk-CC_Kquu7.d.ts +125 -0
- package/dist/chunk-CCp85vXg.cjs +60 -0
- package/dist/chunk-CCp85vXg.cjs.map +1 -0
- package/dist/chunk-CEcB1_uK.js +39 -0
- package/dist/chunk-CEcB1_uK.js.map +1 -0
- package/dist/chunk-CFIo021l.d.cts +216 -0
- package/dist/chunk-CH_IZoJE.js +33 -0
- package/dist/chunk-CH_IZoJE.js.map +1 -0
- package/dist/chunk-CHrasH_g.cjs +25 -0
- package/dist/chunk-CHrasH_g.cjs.map +1 -0
- package/dist/chunk-CJVoSaAE.cjs +3 -0
- package/dist/chunk-CJp8nGcb.js +96 -0
- package/dist/chunk-CJp8nGcb.js.map +1 -0
- package/dist/chunk-CJwUtkOt.js +112 -0
- package/dist/chunk-CJwUtkOt.js.map +1 -0
- package/dist/chunk-CKhCOVIf.d.cts +751 -0
- package/dist/chunk-CKiVSRYg.js +50 -0
- package/dist/chunk-CKiVSRYg.js.map +1 -0
- package/dist/chunk-CKtd19eD.cjs +59 -0
- package/dist/chunk-CKtd19eD.cjs.map +1 -0
- package/dist/chunk-CL92KE3j.d.ts +3188 -0
- package/dist/chunk-CLqUlkAe.js +54 -0
- package/dist/chunk-CLqUlkAe.js.map +1 -0
- package/dist/chunk-CMG5OV0q.cjs +4741 -0
- package/dist/chunk-CMG5OV0q.cjs.map +1 -0
- package/dist/chunk-CN_TKSgm.js +10 -0
- package/dist/chunk-CN_TKSgm.js.map +1 -0
- package/dist/chunk-CNe6MtqV.cjs +29 -0
- package/dist/chunk-CNe6MtqV.cjs.map +1 -0
- package/dist/chunk-COQkDTC5.js +83 -0
- package/dist/chunk-COQkDTC5.js.map +1 -0
- package/dist/chunk-CPBl6K4M.cjs +168 -0
- package/dist/chunk-CPBl6K4M.cjs.map +1 -0
- package/dist/chunk-CPx0ZYFB.d.ts +3 -0
- package/dist/chunk-CQQhcP_C.d.ts +197 -0
- package/dist/chunk-CTNoajFh.d.cts +389 -0
- package/dist/chunk-CTd-qgJc.cjs +384 -0
- package/dist/chunk-CTd-qgJc.cjs.map +1 -0
- package/dist/chunk-CW80YYtU.cjs +1056 -0
- package/dist/chunk-CW80YYtU.cjs.map +1 -0
- package/dist/chunk-CWpqBgkF.d.cts +24 -0
- package/dist/chunk-CWpqBgkF.d.ts +24 -0
- package/dist/chunk-CXjRArgy.d.ts +3 -0
- package/dist/chunk-CXonfH3-.cjs +14 -0
- package/dist/chunk-CXonfH3-.cjs.map +1 -0
- package/dist/chunk-CYcouGXN.d.ts +825 -0
- package/dist/chunk-CZDAzEBw.cjs +1621 -0
- package/dist/chunk-CZDAzEBw.cjs.map +1 -0
- package/dist/chunk-C_fQFr70.d.cts +159 -0
- package/dist/chunk-C_fQFr70.d.ts +159 -0
- package/dist/chunk-CbOtHnnB.cjs +359 -0
- package/dist/chunk-CbOtHnnB.cjs.map +1 -0
- package/dist/chunk-CdA6ZMGk.d.cts +825 -0
- package/dist/chunk-Ce1_thm7.js +146 -0
- package/dist/chunk-Ce1_thm7.js.map +1 -0
- package/dist/chunk-CeD8Hw0j.d.cts +3188 -0
- package/dist/chunk-CeiTuMyt.d.cts +525 -0
- package/dist/chunk-Ch1OLzLi.js +1 -0
- package/dist/chunk-Cizu_j1N.cjs +87 -0
- package/dist/chunk-Cizu_j1N.cjs.map +1 -0
- package/dist/chunk-CjDe9z6A.d.cts +427 -0
- package/dist/chunk-Cl1etdlu.js +63 -0
- package/dist/chunk-Cl1etdlu.js.map +1 -0
- package/dist/chunk-CmoVJDoz.js +4 -0
- package/dist/chunk-CmoVJDoz.js.map +1 -0
- package/dist/chunk-CnLucxjG.cjs +197 -0
- package/dist/chunk-CnLucxjG.cjs.map +1 -0
- package/dist/chunk-CsWjBmdi.cjs +56 -0
- package/dist/chunk-CsWjBmdi.cjs.map +1 -0
- package/dist/chunk-CuseO5MZ.d.cts +3 -0
- package/dist/chunk-CvMHibbA.d.ts +427 -0
- package/dist/chunk-CwDeiN5U.js +870 -0
- package/dist/chunk-CwDeiN5U.js.map +1 -0
- package/dist/chunk-Cwdmx4tG.js +1 -0
- package/dist/chunk-D-4MxHTt.d.cts +105 -0
- package/dist/chunk-D-4MxHTt.d.ts +105 -0
- package/dist/chunk-D0LF-99V.js +1093 -0
- package/dist/chunk-D0LF-99V.js.map +1 -0
- package/dist/chunk-D1fe-0c_.js +367 -0
- package/dist/chunk-D1fe-0c_.js.map +1 -0
- package/dist/chunk-D21fEI6A.d.ts +1926 -0
- package/dist/chunk-D39gAxya.cjs +89 -0
- package/dist/chunk-D39gAxya.cjs.map +1 -0
- package/dist/chunk-D6KdIW5e.cjs +228 -0
- package/dist/chunk-D6KdIW5e.cjs.map +1 -0
- package/dist/chunk-D6qHYbgW.d.cts +36 -0
- package/dist/chunk-D89E-w70.d.ts +44 -0
- package/dist/chunk-D8bdTysL.js +552 -0
- package/dist/chunk-D8bdTysL.js.map +1 -0
- package/dist/chunk-D96QJT24.cjs +109 -0
- package/dist/chunk-D96QJT24.cjs.map +1 -0
- package/dist/chunk-DAmkQl-i.js +119 -0
- package/dist/chunk-DAmkQl-i.js.map +1 -0
- package/dist/chunk-DEfsb2lc.cjs +10 -0
- package/dist/chunk-DEfsb2lc.cjs.map +1 -0
- package/dist/chunk-DIFjT5-V.d.cts +66 -0
- package/dist/chunk-DJpUw8TN.d.ts +912 -0
- package/dist/chunk-DK6lm2IZ.cjs +11 -0
- package/dist/chunk-DK6lm2IZ.cjs.map +1 -0
- package/dist/chunk-DKqgr31j.cjs +61 -0
- package/dist/chunk-DKqgr31j.cjs.map +1 -0
- package/dist/chunk-DLZ0QYm9.js +37 -0
- package/dist/chunk-DLZ0QYm9.js.map +1 -0
- package/dist/chunk-DLjS0uaC.js +4 -0
- package/dist/chunk-DLjS0uaC.js.map +1 -0
- package/dist/chunk-DMokwmOV.cjs +49 -0
- package/dist/chunk-DMokwmOV.cjs.map +1 -0
- package/dist/chunk-DMvWgBZL.d.cts +1831 -0
- package/dist/chunk-DNfGfIF3.js +31 -0
- package/dist/chunk-DNfGfIF3.js.map +1 -0
- package/dist/chunk-DQbSRe8D.d.ts +245 -0
- package/dist/chunk-DSGkP8_y.js +45 -0
- package/dist/chunk-DSGkP8_y.js.map +1 -0
- package/dist/chunk-DTctvfSd.d.cts +197 -0
- package/dist/chunk-DWe7igyw.cjs +206 -0
- package/dist/chunk-DWe7igyw.cjs.map +1 -0
- package/dist/chunk-DWsMP5JR.d.ts +68 -0
- package/dist/chunk-DWsm3HIW.d.cts +120 -0
- package/dist/chunk-DWsm3HIW.d.ts +120 -0
- package/dist/chunk-DXABHjLa.cjs +3 -0
- package/dist/chunk-D_BeqSbc.cjs +42 -0
- package/dist/chunk-D_BeqSbc.cjs.map +1 -0
- package/dist/chunk-D_svQNdW.d.ts +66 -0
- package/dist/chunk-Dav4xWrp.js +330 -0
- package/dist/chunk-Dav4xWrp.js.map +1 -0
- package/dist/chunk-DbCPhepL.js +293 -0
- package/dist/chunk-DbCPhepL.js.map +1 -0
- package/dist/chunk-DcrTy-y2.cjs +43 -0
- package/dist/chunk-DcrTy-y2.cjs.map +1 -0
- package/dist/chunk-Ddv484ld.js +487 -0
- package/dist/chunk-Ddv484ld.js.map +1 -0
- package/dist/chunk-De0bjnhY.cjs +88 -0
- package/dist/chunk-De0bjnhY.cjs.map +1 -0
- package/dist/chunk-De2FmNPu.cjs +32 -0
- package/dist/chunk-De2FmNPu.cjs.map +1 -0
- package/dist/chunk-DeSjQXiI.d.ts +157 -0
- package/dist/chunk-Den0Ta6C.js +132 -0
- package/dist/chunk-Den0Ta6C.js.map +1 -0
- package/dist/chunk-DiDKEeEa.js +8 -0
- package/dist/chunk-DiDKEeEa.js.map +1 -0
- package/dist/chunk-Dj60k5PU.js +197 -0
- package/dist/chunk-Dj60k5PU.js.map +1 -0
- package/dist/chunk-DjnYQBCN.js +4705 -0
- package/dist/chunk-DjnYQBCN.js.map +1 -0
- package/dist/chunk-Dk9VKvyq.d.ts +1 -0
- package/dist/chunk-Dor1ERI9.cjs +85 -0
- package/dist/chunk-Dor1ERI9.cjs.map +1 -0
- package/dist/chunk-DpMouOoH.js +451 -0
- package/dist/chunk-DpMouOoH.js.map +1 -0
- package/dist/chunk-DposgdNL.cjs +52 -0
- package/dist/chunk-DposgdNL.cjs.map +1 -0
- package/dist/chunk-DqLTG_5Q.d.cts +3 -0
- package/dist/chunk-Dr5MCIpS.d.cts +63 -0
- package/dist/chunk-Dr5MCIpS.d.ts +63 -0
- package/dist/chunk-DrudttCC.cjs +4 -0
- package/dist/chunk-DsDYVJQC.js +173 -0
- package/dist/chunk-DsDYVJQC.js.map +1 -0
- package/dist/chunk-Dw8ur6FJ.js +27 -0
- package/dist/chunk-Dw8ur6FJ.js.map +1 -0
- package/dist/chunk-DwG6M_0v.js +64 -0
- package/dist/chunk-DwG6M_0v.js.map +1 -0
- package/dist/chunk-Dy9a5ibO.js +284 -0
- package/dist/chunk-Dy9a5ibO.js.map +1 -0
- package/dist/chunk-DyayZlQJ.js +157 -0
- package/dist/chunk-DyayZlQJ.js.map +1 -0
- package/dist/chunk-DyhJZC2i.js +126 -0
- package/dist/chunk-DyhJZC2i.js.map +1 -0
- package/dist/chunk-F9zBzmmG.cjs +45 -0
- package/dist/chunk-F9zBzmmG.cjs.map +1 -0
- package/dist/chunk-FyCYofv2.js +116 -0
- package/dist/chunk-FyCYofv2.js.map +1 -0
- package/dist/chunk-GHJRjAk2.js +1 -0
- package/dist/chunk-H14isiSf.d.ts +751 -0
- package/dist/chunk-HIJzXoN4.js +7 -0
- package/dist/chunk-HIJzXoN4.js.map +1 -0
- package/dist/chunk-Id_8kRtu.d.ts +36 -0
- package/dist/chunk-KN60yxBQ.js +5 -0
- package/dist/chunk-KN60yxBQ.js.map +1 -0
- package/dist/chunk-NM5yg6bh.cjs +82 -0
- package/dist/chunk-NM5yg6bh.cjs.map +1 -0
- package/dist/chunk-OXr3zJfM.cjs +119 -0
- package/dist/chunk-OXr3zJfM.cjs.map +1 -0
- package/dist/chunk-QGqgNC4z.d.ts +928 -0
- package/dist/chunk-QJBtJrZ0.js +36 -0
- package/dist/chunk-QJBtJrZ0.js.map +1 -0
- package/dist/chunk-QKWhxfPv.d.cts +361 -0
- package/dist/chunk-QKWhxfPv.d.ts +361 -0
- package/dist/chunk-QXW7b4Ev.d.cts +410 -0
- package/dist/chunk-RHZrxUrM.cjs +39 -0
- package/dist/chunk-RHZrxUrM.cjs.map +1 -0
- package/dist/chunk-RTxe2i66.js +91 -0
- package/dist/chunk-RTxe2i66.js.map +1 -0
- package/dist/chunk-RrKkJb6P.js +16 -0
- package/dist/chunk-RrKkJb6P.js.map +1 -0
- package/dist/chunk-VOJqpcnM.cjs +181 -0
- package/dist/chunk-VOJqpcnM.cjs.map +1 -0
- package/dist/chunk-VljGTrid.js +1 -0
- package/dist/chunk-X3UVwUEK.d.cts +513 -0
- package/dist/chunk-X9K2WChn.cjs +28 -0
- package/dist/chunk-X9K2WChn.cjs.map +1 -0
- package/dist/chunk-YrtOx6oy.js +251 -0
- package/dist/chunk-YrtOx6oy.js.map +1 -0
- package/dist/chunk-bY7ySujI.d.cts +928 -0
- package/dist/chunk-bYf1sBz5.d.cts +11 -0
- package/dist/chunk-bYf1sBz5.d.ts +11 -0
- package/dist/chunk-blfknWoM.d.cts +1926 -0
- package/dist/chunk-blqsohAb.js +113 -0
- package/dist/chunk-blqsohAb.js.map +1 -0
- package/dist/chunk-cDMCjodI.cjs +58 -0
- package/dist/chunk-cDMCjodI.cjs.map +1 -0
- package/dist/chunk-cWjE3qd6.cjs +10 -0
- package/dist/chunk-cWjE3qd6.cjs.map +1 -0
- package/dist/chunk-dfOgV3fu.js +26 -0
- package/dist/chunk-dfOgV3fu.js.map +1 -0
- package/dist/chunk-f9cTwUX1.cjs +125 -0
- package/dist/chunk-f9cTwUX1.cjs.map +1 -0
- package/dist/chunk-fHVYEZs4.cjs +28 -0
- package/dist/chunk-fHVYEZs4.cjs.map +1 -0
- package/dist/chunk-fWRUMgRI.js +22 -0
- package/dist/chunk-fWRUMgRI.js.map +1 -0
- package/dist/chunk-fozLXfHY.d.cts +55 -0
- package/dist/chunk-fozLXfHY.d.ts +55 -0
- package/dist/chunk-gWmB1l3A.cjs +3122 -0
- package/dist/chunk-gWmB1l3A.cjs.map +1 -0
- package/dist/chunk-gbj2R-_w.js +58 -0
- package/dist/chunk-gbj2R-_w.js.map +1 -0
- package/dist/chunk-iIWxsAXd.js +59 -0
- package/dist/chunk-iIWxsAXd.js.map +1 -0
- package/dist/chunk-lItIuOIS.cjs +137 -0
- package/dist/chunk-lItIuOIS.cjs.map +1 -0
- package/dist/chunk-m6Rh4PCe.cjs +798 -0
- package/dist/chunk-m6Rh4PCe.cjs.map +1 -0
- package/dist/chunk-o3IRANDf.cjs +99 -0
- package/dist/chunk-o3IRANDf.cjs.map +1 -0
- package/dist/chunk-obUcg3Sk.d.ts +808 -0
- package/dist/chunk-ohsf-6Rn.js +600 -0
- package/dist/chunk-ohsf-6Rn.js.map +1 -0
- package/dist/chunk-pBleU6Nv.js +3061 -0
- package/dist/chunk-pBleU6Nv.js.map +1 -0
- package/dist/chunk-px4e99cy.js +71 -0
- package/dist/chunk-px4e99cy.js.map +1 -0
- package/dist/chunk-qwYDLeXc.cjs +99 -0
- package/dist/chunk-qwYDLeXc.cjs.map +1 -0
- package/dist/chunk-rF_859Qk.cjs +101 -0
- package/dist/chunk-rF_859Qk.cjs.map +1 -0
- package/dist/chunk-rLJkqJ5j.d.ts +1475 -0
- package/dist/chunk-twQItIRg.cjs +338 -0
- package/dist/chunk-twQItIRg.cjs.map +1 -0
- package/dist/chunk-vnPrMVjY.js +10 -0
- package/dist/chunk-vnPrMVjY.js.map +1 -0
- package/dist/chunk-ws3bVwaS.d.ts +410 -0
- package/dist/chunk-xh3UkuVs.cjs +246 -0
- package/dist/chunk-xh3UkuVs.cjs.map +1 -0
- package/dist/chunk-yMzRr26E.js +153 -0
- package/dist/chunk-yMzRr26E.js.map +1 -0
- package/dist/collab/index.cjs +831 -0
- package/dist/collab/index.cjs.map +1 -0
- package/dist/collab/index.d.cts +824 -0
- package/dist/collab/index.d.ts +824 -0
- package/dist/collab/index.js +819 -0
- package/dist/collab/index.js.map +1 -0
- package/dist/data/index.cjs +39 -0
- package/dist/data/index.d.cts +6 -0
- package/dist/data/index.d.ts +6 -0
- package/dist/data/index.js +7 -0
- package/dist/editor/index.cjs +2713 -0
- package/dist/editor/index.cjs.map +1 -0
- package/dist/editor/index.d.cts +10 -0
- package/dist/editor/index.d.ts +10 -0
- package/dist/editor/index.js +2702 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/errors/index.cjs +11 -0
- package/dist/errors/index.d.cts +2 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +1 -0
- package/dist/geo/index.cjs +68 -0
- package/dist/geo/index.d.cts +6 -0
- package/dist/geo/index.d.ts +6 -0
- package/dist/geo/index.js +11 -0
- package/dist/i18n/fr/index.cjs +333 -0
- package/dist/i18n/fr/index.cjs.map +1 -0
- package/dist/i18n/fr/index.d.cts +18 -0
- package/dist/i18n/fr/index.d.ts +18 -0
- package/dist/i18n/fr/index.js +328 -0
- package/dist/i18n/fr/index.js.map +1 -0
- package/dist/i18n/index.cjs +451 -0
- package/dist/i18n/index.cjs.map +1 -0
- package/dist/i18n/index.d.cts +268 -0
- package/dist/i18n/index.d.ts +268 -0
- package/dist/i18n/index.js +430 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/icons/index.cjs +37 -0
- package/dist/icons/index.d.cts +4 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +8 -0
- package/dist/index.cjs +517 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +174 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/layers/index.cjs +83 -0
- package/dist/layers/index.d.cts +3 -0
- package/dist/layers/index.d.ts +3 -0
- package/dist/layers/index.js +5 -0
- package/dist/map-client/index.cjs +5 -0
- package/dist/map-client/index.d.cts +6 -0
- package/dist/map-client/index.d.ts +6 -0
- package/dist/map-client/index.js +0 -0
- package/dist/maplibre-worker.mjs +12 -0
- package/dist/navigation/index.cjs +612 -0
- package/dist/navigation/index.cjs.map +1 -0
- package/dist/navigation/index.d.cts +551 -0
- package/dist/navigation/index.d.ts +551 -0
- package/dist/navigation/index.js +599 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/profile/index.cjs +177 -0
- package/dist/profile/index.d.cts +8 -0
- package/dist/profile/index.d.ts +8 -0
- package/dist/profile/index.js +10 -0
- package/dist/seams/index.cjs +15 -0
- package/dist/seams/index.d.cts +4 -0
- package/dist/seams/index.d.ts +4 -0
- package/dist/seams/index.js +4 -0
- package/dist/search/index.cjs +39 -0
- package/dist/search/index.d.cts +6 -0
- package/dist/search/index.d.ts +6 -0
- package/dist/search/index.js +3 -0
- package/dist/style/index.cjs +34 -0
- package/dist/style/index.d.cts +5 -0
- package/dist/style/index.d.ts +5 -0
- package/dist/style/index.js +5 -0
- package/dist/styles.css +11 -0
- package/dist/testing/index.cjs +444 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +217 -0
- package/dist/testing/index.d.ts +217 -0
- package/dist/testing/index.js +435 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/timezone/index.cjs +1953 -0
- package/dist/timezone/index.cjs.map +1 -0
- package/dist/timezone/index.d.cts +28 -0
- package/dist/timezone/index.d.ts +28 -0
- package/dist/timezone/index.js +1948 -0
- package/dist/timezone/index.js.map +1 -0
- package/dist/units/index.cjs +29 -0
- package/dist/units/index.d.cts +3 -0
- package/dist/units/index.d.ts +3 -0
- package/dist/units/index.js +3 -0
- package/dist/video/index.cjs +1713 -0
- package/dist/video/index.cjs.map +1 -0
- package/dist/video/index.d.cts +846 -0
- package/dist/video/index.d.ts +846 -0
- package/dist/video/index.js +1689 -0
- package/dist/video/index.js.map +1 -0
- package/dist/view/index.cjs +7 -0
- package/dist/view/index.d.cts +3 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +1 -0
- package/package.json +433 -4
- package/src/agent/engines/session.ts +2255 -0
- package/src/agent/index.ts +109 -0
- package/src/agent/rules/agentError.ts +128 -0
- package/src/agent/rules/boundedInputJson.ts +53 -0
- package/src/agent/rules/conversation.ts +629 -0
- package/src/agent/rules/conversationFaults.ts +349 -0
- package/src/agent/rules/conversationHost.ts +390 -0
- package/src/agent/rules/dispatcher.ts +102 -0
- package/src/agent/rules/errorCodes.ts +78 -0
- package/src/agent/rules/errorStatus.ts +65 -0
- package/src/agent/rules/scriptedTransport.ts +390 -0
- package/src/agent/rules/stickToBottom.ts +38 -0
- package/src/agent/rules/toolResultPayload.ts +197 -0
- package/src/auth/rules/clientHeader.ts +22 -0
- package/src/auth/rules/sentCredential.ts +76 -0
- package/src/auth/rules/transformRequest.ts +803 -0
- package/src/camera/engines/videoFlight.ts +1758 -0
- package/src/camera/index.ts +157 -0
- package/src/camera/rules/clearance.ts +1099 -0
- package/src/camera/rules/fit.ts +132 -0
- package/src/camera/rules/modes.ts +1019 -0
- package/src/camera/rules/plan.ts +478 -0
- package/src/camera/rules/planner.ts +129 -0
- package/src/camera/rules/poseRanges.ts +38 -0
- package/src/camera/rules/presets.ts +185 -0
- package/src/camera/rules/profileSamples.ts +243 -0
- package/src/camera/rules/route.ts +596 -0
- package/src/camera/rules/routeContent.ts +105 -0
- package/src/camera/rules/spline.ts +765 -0
- package/src/camera/rules/sweptViewports.ts +39 -0
- package/src/camera/rules/track.ts +1412 -0
- package/src/camera/rules/vocabulary.ts +130 -0
- package/src/camera/rules/zoom.ts +216 -0
- package/src/collab/engines/session.ts +1902 -0
- package/src/collab/engines/trailingThrottle.ts +151 -0
- package/src/collab/index.ts +52 -0
- package/src/collab/rules/dispatch.ts +143 -0
- package/src/collab/rules/peerNames.ts +51 -0
- package/src/collab/rules/scriptedTransport.ts +244 -0
- package/src/compose/engines/baseMapSwitch.ts +1136 -0
- package/src/compose/engines/events.ts +962 -0
- package/src/compose/engines/mountayaMap.ts +5648 -0
- package/src/compose/engines/sentCredentials.ts +146 -0
- package/src/compose/engines/slotRequests.ts +413 -0
- package/src/compose/rules/accessRefusal.ts +109 -0
- package/src/compose/rules/accessStanding.ts +75 -0
- package/src/compose/rules/analysisKinds.ts +331 -0
- package/src/compose/rules/analysisLayers.ts +176 -0
- package/src/compose/rules/cameraMoves.ts +38 -0
- package/src/compose/rules/carriedLayers.ts +87 -0
- package/src/compose/rules/developmentWarnings.ts +167 -0
- package/src/compose/rules/fitBox.ts +67 -0
- package/src/compose/rules/fitCamera.ts +54 -0
- package/src/compose/rules/geoJsonSlot.ts +61 -0
- package/src/compose/rules/geometrySlots.ts +155 -0
- package/src/compose/rules/glyphNode.ts +62 -0
- package/src/compose/rules/layerKeys.ts +92 -0
- package/src/compose/rules/layerOrder.ts +85 -0
- package/src/compose/rules/layersManifest.ts +26 -0
- package/src/compose/rules/mapOptions.ts +300 -0
- package/src/compose/rules/maplibreWorkerVersion.gen.ts +8 -0
- package/src/compose/rules/markerPin.ts +122 -0
- package/src/compose/rules/markerRegistry.ts +85 -0
- package/src/compose/rules/markerSprite.ts +382 -0
- package/src/compose/rules/maxBounds.ts +120 -0
- package/src/compose/rules/overlayLookup.ts +49 -0
- package/src/compose/rules/paintDiff.ts +38 -0
- package/src/compose/rules/panLock.ts +77 -0
- package/src/compose/rules/patch.ts +124 -0
- package/src/compose/rules/queriedFeature.ts +55 -0
- package/src/compose/rules/queryLayers.ts +46 -0
- package/src/compose/rules/searchHighlight.ts +313 -0
- package/src/compose/rules/slotNames.ts +19 -0
- package/src/compose/rules/stripeImage.ts +253 -0
- package/src/compose/rules/swapMarker.ts +66 -0
- package/src/compose/rules/terrainVariant.ts +88 -0
- package/src/compose/rules/types.ts +559 -0
- package/src/compose/rules/urlHash.ts +19 -0
- package/src/compose/rules/viewOptions.ts +451 -0
- package/src/compose/rules/workerUrl.ts +131 -0
- package/src/data/engines/itineraryResource.ts +643 -0
- package/src/data/index.ts +78 -0
- package/src/data/rules/adapt.ts +473 -0
- package/src/data/rules/editModes.ts +51 -0
- package/src/data/rules/itinerary.ts +168 -0
- package/src/data/rules/nullable.ts +63 -0
- package/src/data/rules/roadAccess.ts +169 -0
- package/src/data/rules/segmentGroups.ts +309 -0
- package/src/data/rules/selectors.ts +95 -0
- package/src/data/rules/zones.ts +79 -0
- package/src/draw/engines/boundaryEngine.ts +1003 -0
- package/src/draw/engines/framedAdapter.ts +198 -0
- package/src/draw/engines/pointerCursor.ts +205 -0
- package/src/draw/engines/segmentEngine.ts +1405 -0
- package/src/draw/engines/snapIndex.ts +254 -0
- package/src/draw/engines/waypointEngine.ts +574 -0
- package/src/draw/engines/zoneEngine.ts +1137 -0
- package/src/draw/rules/drawFrame.ts +123 -0
- package/src/draw/rules/insertVertex.ts +226 -0
- package/src/draw/rules/screenSpace.ts +62 -0
- package/src/draw/rules/seeds.ts +185 -0
- package/src/draw/rules/snap.ts +115 -0
- package/src/draw/rules/snapCameraKey.ts +50 -0
- package/src/draw/rules/terraDrawShared.ts +214 -0
- package/src/draw/rules/zoneOutline.ts +213 -0
- package/src/editing/engines/cursor.ts +505 -0
- package/src/editing/engines/draftMarker.ts +149 -0
- package/src/editing/rules/accent.ts +11 -0
- package/src/editing/rules/engine.ts +288 -0
- package/src/editing/rules/placement.ts +22 -0
- package/src/editing/rules/positions.ts +89 -0
- package/src/editing/rules/sources.ts +9 -0
- package/src/editing/rules/types.ts +457 -0
- package/src/editing/rules/vocabulary.ts +10 -0
- package/src/editing/rules/waypointCursor.ts +228 -0
- package/src/editor/engines/directionArrows.ts +459 -0
- package/src/editor/engines/directions.ts +1383 -0
- package/src/editor/engines/editorClient.ts +134 -0
- package/src/editor/engines/eventScope.ts +59 -0
- package/src/editor/engines/frameLoop.ts +159 -0
- package/src/editor/engines/itineraryPreview.ts +272 -0
- package/src/editor/engines/mapLockGuard.ts +66 -0
- package/src/editor/engines/overlayRenderer.ts +2696 -0
- package/src/editor/engines/peerDraft.ts +760 -0
- package/src/editor/engines/poiPick.ts +305 -0
- package/src/editor/engines/pointPick.ts +84 -0
- package/src/editor/engines/roadAccessLine.ts +140 -0
- package/src/editor/engines/searchHighlight.ts +183 -0
- package/src/editor/engines/viewClient.ts +4091 -0
- package/src/editor/engines/zoneBadges.ts +503 -0
- package/src/editor/index.ts +97 -0
- package/src/editor/rules/accentColor.ts +116 -0
- package/src/editor/rules/camera.ts +121 -0
- package/src/editor/rules/contract.ts +120 -0
- package/src/editor/rules/icons.ts +825 -0
- package/src/editor/rules/markerElements.ts +244 -0
- package/src/editor/rules/style.ts +51 -0
- package/src/editor/rules/terrain.ts +98 -0
- package/src/editor/rules/tileWarm.ts +191 -0
- package/src/editor/rules/tilesReload.ts +158 -0
- package/src/editor/rules/zoneBadgePlacement.ts +1832 -0
- package/src/editor/rules/zoneTimeStyling.ts +119 -0
- package/src/errors/index.ts +25 -0
- package/src/errors/rules/errors.ts +158 -0
- package/src/errors/rules/print.ts +129 -0
- package/src/geo/index.ts +89 -0
- package/src/geo/rules/boundaries.ts +105 -0
- package/src/geo/rules/camera.ts +496 -0
- package/src/geo/rules/corridor.ts +242 -0
- package/src/geo/rules/elevationTiles.ts +269 -0
- package/src/geo/rules/formatLngLat.ts +63 -0
- package/src/geo/rules/geodesy.ts +125 -0
- package/src/geo/rules/geometry.ts +362 -0
- package/src/geo/rules/lineWalk.ts +77 -0
- package/src/geo/rules/longitude.ts +99 -0
- package/src/geo/rules/searchLimits.ts +22 -0
- package/src/geo/rules/segmentGeometry.ts +80 -0
- package/src/geo/rules/terrain.ts +107 -0
- package/src/geo/rules/tuples.ts +124 -0
- package/src/geo/rules/types.ts +54 -0
- package/src/geo/rules/webMercator.ts +57 -0
- package/src/i18n/fr/index.ts +17 -0
- package/src/i18n/fr/rules/fr.ts +85 -0
- package/src/i18n/fr/rules/words.gen.ts +277 -0
- package/src/i18n/index.ts +82 -0
- package/src/i18n/rules/bundle.ts +378 -0
- package/src/i18n/rules/config.ts +71 -0
- package/src/i18n/rules/dates.ts +165 -0
- package/src/i18n/rules/endonyms.gen.ts +19 -0
- package/src/i18n/rules/language.ts +92 -0
- package/src/i18n/rules/localizedName.ts +33 -0
- package/src/i18n/rules/merge.ts +106 -0
- package/src/i18n/rules/scope.ts +127 -0
- package/src/i18n/rules/strings.ts +632 -0
- package/src/i18n/rules/videoOverlay.ts +121 -0
- package/src/i18n/rules/wordForms.ts +95 -0
- package/src/i18n/rules/words.gen.ts +277 -0
- package/src/icons/index.ts +54 -0
- package/src/icons/rules/activities.ts +40 -0
- package/src/icons/rules/amenities.ts +250 -0
- package/src/icons/rules/artwork.gen.ts +83 -0
- package/src/icons/rules/artwork.ts +47 -0
- package/src/icons/rules/fallback.ts +21 -0
- package/src/icons/rules/lucideMarkers.gen.ts +112 -0
- package/src/icons/rules/lucideUi.gen.ts +197 -0
- package/src/icons/rules/paint.ts +107 -0
- package/src/icons/rules/parse.ts +475 -0
- package/src/icons/rules/provider.ts +373 -0
- package/src/icons/rules/sprites.ts +54 -0
- package/src/icons/rules/ui.ts +348 -0
- package/src/icons/rules/waypoints.ts +215 -0
- package/src/index.ts +993 -0
- package/src/layers/engines/layersSelection.ts +515 -0
- package/src/layers/engines/readoutEngine.ts +131 -0
- package/src/layers/index.ts +151 -0
- package/src/layers/rules/analysis.ts +135 -0
- package/src/layers/rules/enrichment.ts +30 -0
- package/src/layers/rules/geoJson.ts +270 -0
- package/src/layers/rules/hover.ts +67 -0
- package/src/layers/rules/itineraries.ts +182 -0
- package/src/layers/rules/layersPanel.ts +237 -0
- package/src/layers/rules/order.ts +194 -0
- package/src/layers/rules/overlayInstant.ts +49 -0
- package/src/layers/rules/overlays.ts +52 -0
- package/src/layers/rules/poiPanel.ts +119 -0
- package/src/layers/rules/pois.ts +114 -0
- package/src/layers/rules/readout.ts +340 -0
- package/src/layers/rules/streetView.ts +16 -0
- package/src/layers/rules/tileTimestamp.ts +146 -0
- package/src/layers/rules/timeSlider.ts +192 -0
- package/src/layers/rules/timeWindow.ts +123 -0
- package/src/layers/rules/zones.ts +43 -0
- package/src/layers/rules/zoom.ts +77 -0
- package/src/map-client/index.ts +71 -0
- package/src/map-client/rules/mapClient.ts +1945 -0
- package/src/navigation/engines/navigation.ts +493 -0
- package/src/navigation/index.ts +51 -0
- package/src/navigation/rules/followedRoute.ts +78 -0
- package/src/navigation/rules/instructions.ts +89 -0
- package/src/navigation/rules/itineraryRoute.ts +232 -0
- package/src/navigation/rules/offRoute.ts +41 -0
- package/src/navigation/rules/progress.ts +230 -0
- package/src/navigation/rules/prompts.ts +217 -0
- package/src/navigation/rules/routeRequest.ts +98 -0
- package/src/navigation/rules/status.ts +142 -0
- package/src/navigation/rules/steps.ts +234 -0
- package/src/navigation/rules/types.ts +83 -0
- package/src/profile/index.ts +307 -0
- package/src/profile/rules/amenityBadge.ts +35 -0
- package/src/profile/rules/amenityFilter.ts +74 -0
- package/src/profile/rules/amenityStacks.ts +66 -0
- package/src/profile/rules/axis.ts +89 -0
- package/src/profile/rules/axisCulling.ts +83 -0
- package/src/profile/rules/axisLookup.ts +180 -0
- package/src/profile/rules/climbs.ts +292 -0
- package/src/profile/rules/cursorMarker.ts +122 -0
- package/src/profile/rules/cursorReadout.ts +104 -0
- package/src/profile/rules/curvePlacement.ts +216 -0
- package/src/profile/rules/dock.ts +293 -0
- package/src/profile/rules/elevation.ts +1263 -0
- package/src/profile/rules/instant.ts +89 -0
- package/src/profile/rules/intl.ts +237 -0
- package/src/profile/rules/legEmphasis.ts +53 -0
- package/src/profile/rules/profileColors.ts +66 -0
- package/src/profile/rules/profileLayout.ts +59 -0
- package/src/profile/rules/profileSlices.ts +55 -0
- package/src/profile/rules/routeProfile.ts +475 -0
- package/src/profile/rules/rowMatch.ts +50 -0
- package/src/profile/rules/scale.ts +646 -0
- package/src/profile/rules/scaleFrame.ts +171 -0
- package/src/profile/rules/sectionChips.ts +83 -0
- package/src/profile/rules/sections.ts +923 -0
- package/src/profile/rules/slopeRamp.ts +160 -0
- package/src/profile/rules/statStrip.ts +103 -0
- package/src/profile/rules/steepness.ts +51 -0
- package/src/profile/rules/tableCells.ts +269 -0
- package/src/profile/rules/tableCursor.ts +87 -0
- package/src/profile/rules/unitPatterns.ts +335 -0
- package/src/profile/rules/units.ts +1025 -0
- package/src/profile/rules/waypointCard.ts +590 -0
- package/src/profile/rules/webAddress.ts +130 -0
- package/src/profile/rules/windowSpans.ts +65 -0
- package/src/rules/asciiFold.ts +17 -0
- package/src/rules/inDevelopment.ts +54 -0
- package/src/rules/listeners.ts +62 -0
- package/src/rules/timers.ts +9 -0
- package/src/rules/types.ts +22 -0
- package/src/rules/uuid.ts +87 -0
- package/src/seams/engines/geolocateControl.ts +286 -0
- package/src/seams/index.ts +50 -0
- package/src/seams/rules/clock.ts +169 -0
- package/src/seams/rules/geolocation.ts +165 -0
- package/src/seams/rules/segmentRoute.ts +187 -0
- package/src/search/engines/search.ts +1093 -0
- package/src/search/index.ts +99 -0
- package/src/search/rules/describe.ts +383 -0
- package/src/search/rules/filters.ts +195 -0
- package/src/search/rules/highlight.ts +270 -0
- package/src/search/rules/pick.ts +90 -0
- package/src/search/rules/rows.ts +258 -0
- package/src/search/rules/searchFocus.ts +27 -0
- package/src/search/rules/searchViewport.ts +44 -0
- package/src/search/rules/shown.ts +77 -0
- package/src/search/rules/types.ts +340 -0
- package/src/stream/rules/reconnectSchedule.ts +83 -0
- package/src/style/engines/organizationRead.ts +80 -0
- package/src/style/index.ts +63 -0
- package/src/style/rules/apply.ts +268 -0
- package/src/style/rules/attribution.ts +119 -0
- package/src/style/rules/itineraryLine.ts +142 -0
- package/src/style/rules/language.ts +668 -0
- package/src/style/rules/layout.gen.ts +27 -0
- package/src/style/rules/organization.ts +96 -0
- package/src/style/rules/paint.ts +143 -0
- package/src/style/rules/panelLayout.ts +51 -0
- package/src/style/rules/roadAccessColors.ts +29 -0
- package/src/style/rules/roadAccessLine.ts +267 -0
- package/src/style/rules/segmentColors.ts +207 -0
- package/src/testing/catalogs.ts +103 -0
- package/src/testing/index.ts +30 -0
- package/src/testing/mapClient.ts +241 -0
- package/src/testing/mountayaMap.ts +741 -0
- package/src/timezone/index.ts +14 -0
- package/src/timezone/rules/viewport.ts +875 -0
- package/src/units/index.ts +55 -0
- package/src/units/rules/conversions.ts +620 -0
- package/src/units/rules/preferenceChoices.ts +124 -0
- package/src/units/rules/preferences.ts +77 -0
- package/src/units/rules/rounding.ts +69 -0
- package/src/video/engines/videoRun.ts +654 -0
- package/src/video/engines/viewClient.ts +6 -0
- package/src/video/index.ts +83 -0
- package/src/video/profileOverlay/rules/contract.ts +210 -0
- package/src/video/profileOverlay/rules/curve.ts +216 -0
- package/src/video/profileOverlay/rules/draw.ts +410 -0
- package/src/video/profileOverlay/rules/fonts.ts +54 -0
- package/src/video/profileOverlay/rules/graphDesign.ts +690 -0
- package/src/video/profileOverlay/rules/minimalDesign.ts +144 -0
- package/src/video/profileOverlay/rules/registry.ts +23 -0
- package/src/video/profileOverlay/rules/staticLayer.ts +582 -0
- package/src/video/profileOverlay/rules/stripDesign.ts +327 -0
- package/src/video/profileOverlay/rules/types.ts +78 -0
- package/src/video/rules/videoConstants.ts +250 -0
- package/src/video/rules/videoEncoder.ts +277 -0
- package/src/video/rules/videoFrames.ts +99 -0
- package/src/video/rules/videoPreview.ts +185 -0
- package/src/video/rules/videoRecorder.ts +746 -0
- package/src/video/rules/videoWatermark.ts +155 -0
- package/src/video/rules/watermarkMark.ts +40 -0
- package/src/view/engines/viewClient.ts +6 -0
- package/src/view/index.ts +20 -0
|
@@ -0,0 +1,1902 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Following one resource's collaboration stream for as long as a surface is open.
|
|
3
|
+
*
|
|
4
|
+
* The engine subscribes to an itinerary's or a zone's frames, applies each one by dispatching a
|
|
5
|
+
* LOCAL tool through the caller's own bus (so peers, locks and drafts reach a store through
|
|
6
|
+
* the same single mutation surface a human uses), resumes after a drop, and drops the echoes of
|
|
7
|
+
* the local user's own signals.
|
|
8
|
+
*
|
|
9
|
+
* **It is not the agent session wearing a different name, and the two are deliberately not one
|
|
10
|
+
* engine.** The shared halves already are shared: `@mountaya/client/events` publishes the
|
|
11
|
+
* reader, the frame decoding and the event types, and both draw the wait before a reopen through
|
|
12
|
+
* `reconnectDelayMs` (`stream/rules/reconnectSchedule.ts`). What is left is policy, and the
|
|
13
|
+
* policies disagree because one has a person waiting on it and the other does not: see the
|
|
14
|
+
* paragraph in `agent/engines/session.ts`, which states both sides. In short: this one's ceiling
|
|
15
|
+
* doubles to 15 seconds with no attempt limit and it reconnects a productive stream immediately,
|
|
16
|
+
* because a collaboration feed is background; that one's doubles to 8 seconds and it stops after
|
|
17
|
+
* six tries, or two minutes of opens answered 503, because a run nobody can revive must not keep
|
|
18
|
+
* re-opening a stream.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { CollabChangeKind, CollabEntity, CollabSelectionRef } from "@mountaya/client";
|
|
22
|
+
import type {
|
|
23
|
+
CollabDurableChange,
|
|
24
|
+
CollabEvent,
|
|
25
|
+
CollabSignal,
|
|
26
|
+
CollabSignalResult,
|
|
27
|
+
CollabStreamHandlers,
|
|
28
|
+
CollabSubscribeOptions,
|
|
29
|
+
CollabTransport,
|
|
30
|
+
} from "@mountaya/client/events";
|
|
31
|
+
|
|
32
|
+
import { retryAfterMsOf, statusOf } from "../../agent/rules/errorStatus.js";
|
|
33
|
+
import { MountayaElementsForbiddenError } from "../../errors/rules/errors.js";
|
|
34
|
+
import { surfaceFault } from "../../rules/listeners.js";
|
|
35
|
+
import {
|
|
36
|
+
type ReconnectSchedule,
|
|
37
|
+
reconnectDelayMs,
|
|
38
|
+
retryAfterDelayMs,
|
|
39
|
+
} from "../../stream/rules/reconnectSchedule.js";
|
|
40
|
+
import type {
|
|
41
|
+
CollabApplyInput,
|
|
42
|
+
CollabContext,
|
|
43
|
+
CollabDispatch,
|
|
44
|
+
CollabListTools,
|
|
45
|
+
CollabResourceRef,
|
|
46
|
+
CollabTools,
|
|
47
|
+
} from "../rules/dispatch.js";
|
|
48
|
+
import { TrailingThrottle } from "./trailingThrottle.js";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* CHANGE_COALESCE_MS is the window a burst of durable changes to the same entity
|
|
52
|
+
* is collapsed over: rapid `*.changed` frames (a drag that commits many revisions,
|
|
53
|
+
* a neighbour cascade) settle into one reconciling apply carrying the latest
|
|
54
|
+
* frame's bust token, so the UI refetches once rather than per intermediate
|
|
55
|
+
* change.
|
|
56
|
+
*/
|
|
57
|
+
const CHANGE_COALESCE_MS = 200;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* SELECTION_THROTTLE_MS is the trailing cadence a peer's own selection changes are
|
|
61
|
+
* announced at: slow enough to not flood the signal endpoint, fast enough that a
|
|
62
|
+
* peer's highlight tracks the local user closely.
|
|
63
|
+
*/
|
|
64
|
+
const SELECTION_THROTTLE_MS = 150;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* LIVE_SEGMENT_THROTTLE_MS is the trailing cadence in-progress segment geometry is
|
|
68
|
+
* broadcast at while the local user drags an edit, so a peer's live preview advances at
|
|
69
|
+
* the same smoothness the local editor renders it.
|
|
70
|
+
*
|
|
71
|
+
* It is exported because it has a consumer: `SegmentDraftEngine` in `@mountaya/studio/engines`
|
|
72
|
+
* paces a segment edit's live-segment writes at it by default, and the two are one decision seen
|
|
73
|
+
* from either end of the wire. The engine IMPORTS this constant, and `@mountaya/studio-react/map`
|
|
74
|
+
* republishes it beside `useStudioSegmentEditing`, rather than either declaring a second 60: this
|
|
75
|
+
* entry is renderer-free, so both packages can reach it, which is what makes the cadence one
|
|
76
|
+
* number instead of a parity test over two.
|
|
77
|
+
*/
|
|
78
|
+
export const LIVE_SEGMENT_THROTTLE_MS = 60;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* COLLAB_RECONNECT_BASE_MS is the ceiling of the collaboration feed's wait after the first attempt
|
|
82
|
+
* that made no progress: one that failed to connect, or connected and delivered nothing beyond
|
|
83
|
+
* the frames an open begins with (the {@link OPENING_SNAPSHOTS}, then the member's own arrival
|
|
84
|
+
* where the stream is their first). A stream that made progress reconnects with no wait, so a
|
|
85
|
+
* healthy feed that the API or a proxy cycles resumes promptly.
|
|
86
|
+
*/
|
|
87
|
+
const COLLAB_RECONNECT_BASE_MS = 500;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* RECONNECT_MAX_MS caps the doubling ceiling, so a persistently-unreachable endpoint is retried
|
|
91
|
+
* at a steady cadence rather than an ever-growing one.
|
|
92
|
+
*/
|
|
93
|
+
const RECONNECT_MAX_MS = 15_000;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* reconnectSchedule is the feed's numbers for {@link reconnectDelayMs}: a wait drawn from zero to
|
|
97
|
+
* a ceiling that starts at {@link COLLAB_RECONNECT_BASE_MS} and doubles to
|
|
98
|
+
* {@link RECONNECT_MAX_MS}.
|
|
99
|
+
*/
|
|
100
|
+
const reconnectSchedule: ReconnectSchedule = {
|
|
101
|
+
baseMs: COLLAB_RECONNECT_BASE_MS,
|
|
102
|
+
maxMs: RECONNECT_MAX_MS,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* releaseRetrySchedule is the wait before a lock release that failed is asked again: a draw from
|
|
107
|
+
* zero to a ceiling that starts at one second and doubles to thirty. The editor stream keeps a
|
|
108
|
+
* lock its member holds alive for as long as it stays open, so a release that is not asked again
|
|
109
|
+
* leaves the lock held, refusing every peer's write and every publish, until the member closes
|
|
110
|
+
* the page.
|
|
111
|
+
*/
|
|
112
|
+
const releaseRetrySchedule: ReconnectSchedule = { baseMs: 1_000, maxMs: 30_000 };
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* unsettledFailure reports whether a lock signal that failed left its outcome open: it found no
|
|
116
|
+
* answer (a dropped socket, a timeout) or met a fault of the server's (a 5xx, a 408, a 429). A
|
|
117
|
+
* release that failed so may not have let the lock go, and is worth asking again. An acquire that
|
|
118
|
+
* failed so may have taken it: the API can take a lock and fail to answer, and the client repeats
|
|
119
|
+
* a signal whose answer was lost. Any other refusal settled the signal: a release refused so says
|
|
120
|
+
* the lock is no longer the member's to give back (a 403 for a member who lost the write role,
|
|
121
|
+
* whose locks the API released with it, among them), and an acquire refused so took nothing.
|
|
122
|
+
*/
|
|
123
|
+
const unsettledFailure = (error: unknown): boolean => {
|
|
124
|
+
const status = statusOf(error);
|
|
125
|
+
|
|
126
|
+
return status === undefined || status >= 500 || status === 408 || status === 429;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/** lockKey names a lock by the entity it holds, as a snapshot and a release both name it. */
|
|
130
|
+
const lockKey = (entity: Pick<CollabEntity, "id" | "kind">): string =>
|
|
131
|
+
`${entity.kind}:${entity.id}`;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* ReleasedLock is a lock a {@link CollabEngine} gave back, kept until a lock snapshot settles it:
|
|
135
|
+
* the entity it names, and the watch its latest release left under.
|
|
136
|
+
*
|
|
137
|
+
* The watch is what lets a snapshot that still lists the lock be read. A snapshot names the
|
|
138
|
+
* member and not the connection, and the one frame that says another of the member's connections
|
|
139
|
+
* took the lock since is that connection's `lock.acquired`, which the stream carries and never
|
|
140
|
+
* replays: a reopen delivers none of those sent while no read was open. The session mints a watch
|
|
141
|
+
* at the first lock snapshot of each open and keeps it until the next open begins. A release that
|
|
142
|
+
* left under the watch the session still keeps has had every such frame read since, so a
|
|
143
|
+
* snapshot that lists its lock shows a re-stamp that crossed the release, and the release is asked
|
|
144
|
+
* again. One that left under no watch, or under one an open since ended, may have missed the
|
|
145
|
+
* frame, so the snapshot cannot tell the re-stamp from another tab's edit, and the lock is
|
|
146
|
+
* forgotten rather than taken from that tab.
|
|
147
|
+
*/
|
|
148
|
+
interface ReleasedLock {
|
|
149
|
+
readonly entity: CollabEntity;
|
|
150
|
+
/** The watch the latest release of the lock left under, or null where it left under none. */
|
|
151
|
+
watch: number | null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* OwedEcho counts the `lock.acquired` frames a {@link CollabEngine}'s own acquires of one entity
|
|
156
|
+
* are still owed.
|
|
157
|
+
*
|
|
158
|
+
* The API stamps every lock it grants onto the stream as a `lock.acquired` naming the member, and
|
|
159
|
+
* publishes it before it answers the acquire. The frame and the answer travel different paths
|
|
160
|
+
* that nothing orders, so the frame can arrive after the lock has been given back, and read as
|
|
161
|
+
* another tab's acquire it would stop the release of a lock the stream keeps re-stamping. So an
|
|
162
|
+
* acquire owes a frame from the moment it is sent, and a frame that arrives for the entity while
|
|
163
|
+
* one is owed is taken as the session's own.
|
|
164
|
+
*
|
|
165
|
+
* A frame that never comes would leave a debt that reads the next tab's acquire as the session's
|
|
166
|
+
* own. So an acquire refused pays its debt as it is answered. A new open pays every debt but those
|
|
167
|
+
* of the acquires still on the wire, since a frame sent while no read was open is never delivered.
|
|
168
|
+
* And a debt goes once {@link OWED_ECHO_SNAPSHOTS} lock snapshots have been read while the session
|
|
169
|
+
* neither holds nor asks for the lock.
|
|
170
|
+
*/
|
|
171
|
+
interface OwedEcho {
|
|
172
|
+
/** The acquires of the entity still on the wire, each of which may yet be stamped. */
|
|
173
|
+
asking: number;
|
|
174
|
+
/** The frames owed. */
|
|
175
|
+
frames: number;
|
|
176
|
+
/** The lock snapshots seen since the session last held or asked for the lock. */
|
|
177
|
+
snapshots: number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* OWED_ECHO_SNAPSHOTS is the lock snapshot an owed `lock.acquired` is forgotten at, counted from
|
|
182
|
+
* the first that is read with its lock given back. The second rather than the first: the stream
|
|
183
|
+
* writes its snapshots on a clock of its own, which nothing orders against the frame, so one
|
|
184
|
+
* snapshot can overtake a frame that is still coming, and two are a whole snapshot interval apart.
|
|
185
|
+
*/
|
|
186
|
+
const OWED_ECHO_SNAPSHOTS = 2;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* OPENING_SNAPSHOTS are the frames the editor stream writes to a connection as it opens: one
|
|
190
|
+
* roster and one lock snapshot.
|
|
191
|
+
*
|
|
192
|
+
* Every open delivers them, so they show that a stream opened and nothing about whether it stays
|
|
193
|
+
* up. Counted as progress, they would have a stream that sends the pair and drops, on every open,
|
|
194
|
+
* reopen with no wait for as long as whatever drops it keeps doing so. The contract re-writes both
|
|
195
|
+
* down the same connection every few seconds, so a second one of a kind is progress, as every
|
|
196
|
+
* other frame is.
|
|
197
|
+
*/
|
|
198
|
+
const OPENING_SNAPSHOTS: readonly CollabEvent["type"][] = ["presence.snapshot", "lock.snapshot"];
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* CollabEngineConfig wires an editor collaboration session to the tool bus and its
|
|
202
|
+
* execution context, the injectable transport, and the resource (an itinerary or a
|
|
203
|
+
* zone) whose stream it follows. Every received frame is applied by dispatching a
|
|
204
|
+
* LOCAL tool through the bus, named by the caller's own dispatch table (the same single
|
|
205
|
+
* mutation surface humans and the agent use), so the session touches no store, map, or
|
|
206
|
+
* query cache directly. `ctx.viewer.getUserId()` supplies the local user id the session
|
|
207
|
+
* drops the echoes of the user's own signals by; it is read live at each frame, so a
|
|
208
|
+
* session built before the viewer hydrates still self-filters correctly once it does. The
|
|
209
|
+
* member whose own `presence.join` shows no progress of the stream is the user the session token
|
|
210
|
+
* the stream was opened with names, and the viewer's only where the client is not told that user.
|
|
211
|
+
*/
|
|
212
|
+
export interface CollabEngineConfig<TContext extends CollabContext = CollabContext> {
|
|
213
|
+
/**
|
|
214
|
+
* The dispatch surface every inbound frame is applied through.
|
|
215
|
+
*
|
|
216
|
+
* The narrow slice rather than the whole bus, because that is all a session uses: it
|
|
217
|
+
* dispatches the tools named in {@link CollabEngineConfig.tools} and reads nothing else. A
|
|
218
|
+
* concrete bus satisfies it, and so does a host handing down the dispatch half alone, which
|
|
219
|
+
* is what the studio's own provider carries.
|
|
220
|
+
*/
|
|
221
|
+
bus: CollabDispatch<TContext>;
|
|
222
|
+
/**
|
|
223
|
+
* Whether the local user may send signals into the resource's session: a member holding a write
|
|
224
|
+
* role (owner, admin or contributor) in the organization that owns it, as the API grants it.
|
|
225
|
+
* The API refuses every signal of a member who only watches with a 403, a selection and a draft
|
|
226
|
+
* as much as a lock, so while this answers false the session sends none: a selection or a draft
|
|
227
|
+
* announced, a draft cleared and a lock given back are dropped, and a lock asked for rejects
|
|
228
|
+
* without asking, with a `MountayaElementsForbiddenError` that stands in for the API's 403. The
|
|
229
|
+
* stream is read either way.
|
|
230
|
+
*
|
|
231
|
+
* Read before every send and never kept, so a role that changes while the resource is open
|
|
232
|
+
* takes effect at the next signal. A signal already on its way when the role is lost is refused
|
|
233
|
+
* by the API and dropped as any failed signal is, and a refused edit signal still reaches
|
|
234
|
+
* {@link CollabEngineConfig.onEditRefused}. A throw from it is read as false, and reaches the
|
|
235
|
+
* program as an uncaught error on a microtask.
|
|
236
|
+
*
|
|
237
|
+
* Omitted, every signal is sent, and the API's refusal of one is dropped.
|
|
238
|
+
*/
|
|
239
|
+
canEdit?: (() => boolean) | undefined;
|
|
240
|
+
ctx: TContext;
|
|
241
|
+
/**
|
|
242
|
+
* Called once with the failure that stopped the session, when the stream failed in a way a
|
|
243
|
+
* reconnect cannot change.
|
|
244
|
+
*
|
|
245
|
+
* A terminal failure stops the loop rather than reconnecting into the same answer forever:
|
|
246
|
+
* a 400, 401, 402, 403 or 404 on the open, a credential the client refuses before it, a
|
|
247
|
+
* producer that never ends a frame. Stopping silently would leave a surface that looks live
|
|
248
|
+
* and never updates, with nothing to say why; this is where a host learns it and decides
|
|
249
|
+
* what to show. A transient drop never reaches it: the session recovers from those alone.
|
|
250
|
+
*
|
|
251
|
+
* The API re-checks an open stream's access as it runs, and ends the stream of a member who
|
|
252
|
+
* lost it: one removed from the resource's organization, or whose organization's agreement
|
|
253
|
+
* stopped including the product. A stream the API ends is closed like any other, so the
|
|
254
|
+
* session reconnects, and it is the reopen, answered 402, 403 or 404, that reaches this
|
|
255
|
+
* callback. The session's stream has stopped by then and is not reopened: following the
|
|
256
|
+
* resource again, once the member's access returns, is a new session.
|
|
257
|
+
*
|
|
258
|
+
* A stream also ends with the credential it was opened with: when the session token it
|
|
259
|
+
* carried expires, or the key is revoked. The session reopens it at once, with the token the
|
|
260
|
+
* client holds then and from the last change it read, so the feed goes on with nothing
|
|
261
|
+
* missed. A reopen answered 401 means the credential is gone, and it is that 401 which reaches
|
|
262
|
+
* this callback. A stream the API cannot keep delivering (`interrupted`: the reader fell behind,
|
|
263
|
+
* or the subscription was lost) is reopened at once in the same way, with the token already
|
|
264
|
+
* held, and reaches nothing here either.
|
|
265
|
+
*
|
|
266
|
+
* A throw from it reaches the program as an uncaught error on a microtask.
|
|
267
|
+
*/
|
|
268
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* Called when the API refuses one of the local user's edit signals with a 403: a lock taken or
|
|
271
|
+
* given back, or a draft announced or cleared, with the failure and the entity the signal
|
|
272
|
+
* named. It says the user holds no write role on the resource any more.
|
|
273
|
+
*
|
|
274
|
+
* The stream is not stopped. A member who loses the write role keeps watching, and the API
|
|
275
|
+
* releases their locks and clears their drafts for the peers, as `lock.released` and
|
|
276
|
+
* `draft.clear` frames this session drops as the local user's own. So this is where a host
|
|
277
|
+
* learns that the edit in progress cannot be saved: it closes it, says why, and reads the
|
|
278
|
+
* member's roles again.
|
|
279
|
+
*
|
|
280
|
+
* Told once for a run of refusals, and again only after an edit signal of this session is
|
|
281
|
+
* accepted in between, so a draft announced on every frame of a drag reports one loss rather
|
|
282
|
+
* than one per frame. A lock taken still rejects to its own caller, which is told the refusal
|
|
283
|
+
* either way. A refusal with any other status, a contention included, never reaches it.
|
|
284
|
+
*
|
|
285
|
+
* A throw from it reaches the program as an uncaught error on a microtask.
|
|
286
|
+
*/
|
|
287
|
+
onEditRefused?: ((error: unknown, entity: CollabEntity) => void) | undefined;
|
|
288
|
+
resource: CollabResourceRef;
|
|
289
|
+
/**
|
|
290
|
+
* The local tool each received frame is applied through.
|
|
291
|
+
*
|
|
292
|
+
* Required, because the alternative is a default spelled in this package's source, and a
|
|
293
|
+
* default naming one product's tools would put `studio.collab.*` literals in a websocket
|
|
294
|
+
* reader. `@mountaya/studio` publishes `studioCollabTools` for a host driving the
|
|
295
|
+
* studio's own bus.
|
|
296
|
+
*/
|
|
297
|
+
tools: CollabTools;
|
|
298
|
+
/**
|
|
299
|
+
* The reader of the resource's stream: usually `createCollabTransport` from
|
|
300
|
+
* `@mountaya/client/events`, which gives up an open that never answers and a stream gone silent
|
|
301
|
+
* as connection errors. A transport of your own bounds both waits the same way: the session
|
|
302
|
+
* waits as long as `subscribe` says nothing.
|
|
303
|
+
*/
|
|
304
|
+
transport: CollabTransport;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* CollabListEngineConfig wires the org-list collaboration session. It names the
|
|
309
|
+
* TARGET organization explicitly, so the API authorizes the caller's membership in
|
|
310
|
+
* the named organization rather than inferring one, and exposes no upstream helpers:
|
|
311
|
+
* the list surface has no selection, lock, or draft to announce.
|
|
312
|
+
*/
|
|
313
|
+
export interface CollabListEngineConfig<TContext extends CollabContext = CollabContext> {
|
|
314
|
+
/** The dispatch surface, as {@link CollabEngineConfig.bus}. */
|
|
315
|
+
bus: CollabDispatch<TContext>;
|
|
316
|
+
ctx: TContext;
|
|
317
|
+
/** The failure that stopped the session, as {@link CollabEngineConfig.onError}. */
|
|
318
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
319
|
+
organizationId: string;
|
|
320
|
+
/** The two tools a list stream reaches, as {@link CollabEngineConfig.tools}. */
|
|
321
|
+
tools: CollabListTools;
|
|
322
|
+
/** The reader of the organization's list stream, as {@link CollabEngineConfig.transport}. */
|
|
323
|
+
transport: CollabTransport;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* itineraryLessKinds are the change kinds that hang off an organization rather than
|
|
328
|
+
* off an itinerary: a zone and a collection. The API sends the nil uuid in
|
|
329
|
+
* `itinerary_id` for both, so the translation below drops it to null rather than
|
|
330
|
+
* forwarding a zero id the tool would scope a refetch to.
|
|
331
|
+
*/
|
|
332
|
+
const itineraryLessKinds: ReadonlySet<CollabChangeKind> = new Set<CollabChangeKind>([
|
|
333
|
+
"collection",
|
|
334
|
+
"zone",
|
|
335
|
+
]);
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* changeApplyInput translates a durable `*.changed` wire frame into the change-apply
|
|
339
|
+
* tool's camelCase input. A zone and a collection are organization-scoped rather than
|
|
340
|
+
* itinerary-scoped, so their itinerary id is dropped to null; every other kind
|
|
341
|
+
* carries the owning itinerary through for the tool's grouped invalidation. The
|
|
342
|
+
* frame's stream id rides along as the tile bust token (durable frames always
|
|
343
|
+
* carry one; the parameter stays optional so a decode quirk degrades to a
|
|
344
|
+
* wall-clock bust rather than a dropped reconcile).
|
|
345
|
+
*/
|
|
346
|
+
const changeApplyInput = (event: CollabDurableChange, bustToken?: string): CollabApplyInput => ({
|
|
347
|
+
action: event.action,
|
|
348
|
+
bustToken,
|
|
349
|
+
id: event.id,
|
|
350
|
+
itineraryId: itineraryLessKinds.has(event.kind) ? null : event.itinerary_id,
|
|
351
|
+
kind: event.kind,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* foldChange answers the one apply that stands for two changes to an entity inside a coalescing
|
|
356
|
+
* window: the later one, which carries the newest bust token (durable frames arrive in ascending
|
|
357
|
+
* revision order), under its own action, except that a creation followed by an update stays a
|
|
358
|
+
* creation. A host reconciling by action then hears that the entity is new, where the later
|
|
359
|
+
* frame alone would ask it to update an id it has never held.
|
|
360
|
+
*/
|
|
361
|
+
const foldChange = (pending: CollabApplyInput, next: CollabApplyInput): CollabApplyInput =>
|
|
362
|
+
pending.action === "created" && next.action === "updated" ? { ...next, action: "created" } : next;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* dispatchContained runs one local tool through the host's dispatcher, without waiting, and
|
|
366
|
+
* contains whatever the dispatcher does with it.
|
|
367
|
+
*
|
|
368
|
+
* The seam answers `unknown`: the studio's bus answers a structured result and never rejects,
|
|
369
|
+
* and a host reconciling into a store of its own may throw, or answer a promise that rejects.
|
|
370
|
+
* Either loses that one frame, and the fault is handed to {@link surfaceFault}: it is a defect of
|
|
371
|
+
* the host's own dispatcher, and it reaches the program as one while the session reads on. There
|
|
372
|
+
* is no result to post back the way an agent tool call has one, and a durable change leaves from
|
|
373
|
+
* the coalescer's timer, where a throw would unwind the timer and a rejection go unhandled.
|
|
374
|
+
*/
|
|
375
|
+
const dispatchContained = <TContext extends CollabContext>(
|
|
376
|
+
bus: CollabDispatch<TContext>,
|
|
377
|
+
ctx: TContext,
|
|
378
|
+
name: string,
|
|
379
|
+
input: unknown,
|
|
380
|
+
): void => {
|
|
381
|
+
try {
|
|
382
|
+
void Promise.resolve(bus.dispatchUnsafe(ctx, name, input)).catch(surfaceFault);
|
|
383
|
+
} catch (fault) {
|
|
384
|
+
// A dispatcher that throws where it would answer is the same fault a turn sooner.
|
|
385
|
+
surfaceFault(fault);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* CollabDraftPayload is the open JSON object a draft signal carries, taken off the contract's
|
|
391
|
+
* own draft-update member rather than restated.
|
|
392
|
+
*/
|
|
393
|
+
type CollabDraftPayload = Extract<CollabSignal, { type: "draft.update" }>["draft"];
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* CollabEditSignal is a signal that names an entity being edited: a lock taken or given back, a
|
|
397
|
+
* draft announced or cleared. The API refuses every signal of a member who holds no write role
|
|
398
|
+
* with a 403, a selection or a cursor as much as these, and these are the ones whose refusal says
|
|
399
|
+
* an edit in progress cannot be saved, so a host hears of it.
|
|
400
|
+
*/
|
|
401
|
+
type CollabEditSignal = Extract<
|
|
402
|
+
CollabSignal,
|
|
403
|
+
{ type: "draft.clear" | "draft.update" | "lock.acquire" | "lock.release" }
|
|
404
|
+
>;
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* toEpochMs converts a presence frame's `connected_at` into the epoch-milliseconds number the
|
|
408
|
+
* presence tools expect.
|
|
409
|
+
*
|
|
410
|
+
* It takes a `Date` because the frame decoder decodes one: the contract declares `connected_at`
|
|
411
|
+
* an instant on the presence events, and the decoder decodes each event's declared instants.
|
|
412
|
+
* An absent or invalid timestamp falls back to the current time, so a peer is recorded as
|
|
413
|
+
* connected rather than dropped over a timestamp quirk: the frame is required to carry one, and
|
|
414
|
+
* the fallback is what keeps a producer's quirk from costing a member their roster entry.
|
|
415
|
+
*/
|
|
416
|
+
const toEpochMs = (connectedAt: Date | undefined): number => {
|
|
417
|
+
const parsed = connectedAt?.getTime();
|
|
418
|
+
|
|
419
|
+
return parsed !== undefined && !Number.isNaN(parsed) ? parsed : Date.now();
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
/** CollabSnapshotEvent is a frame that states a whole set at once: the roster, or the held locks. */
|
|
423
|
+
type CollabSnapshotEvent = Extract<CollabEvent, { type: "lock.snapshot" | "presence.snapshot" }>;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* CollabReconnectEvent is the frame the API ends a stream with when the credential it was opened
|
|
427
|
+
* with ends, or when it cannot keep delivering the stream (`interrupted`). It names no member and
|
|
428
|
+
* changes nothing: the read it ends is what it says, and the client's transport closes that read
|
|
429
|
+
* as `reconnect` rather than handing the frame on.
|
|
430
|
+
*/
|
|
431
|
+
type CollabReconnectEvent = Extract<CollabEvent, { type: "reconnect" }>;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* CollabPeerEvent is a frame carrying one member's transient state: every frame that is neither
|
|
435
|
+
* a durable change, a snapshot nor the end of the stream's credential. Stated by exclusion, so a
|
|
436
|
+
* kind the contract gains is one of these until it is given a family of its own.
|
|
437
|
+
*/
|
|
438
|
+
type CollabPeerEvent = Exclude<
|
|
439
|
+
CollabEvent,
|
|
440
|
+
CollabDurableChange | CollabReconnectEvent | CollabSnapshotEvent
|
|
441
|
+
>;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* isDurableChange reports whether a frame is a durable `*.changed` event (as opposed
|
|
445
|
+
* to an ephemeral presence, selection, cursor, lock or draft frame). The durable frames are
|
|
446
|
+
* the only ones the change coalescer handles and the only ones that advance the resume
|
|
447
|
+
* cursor.
|
|
448
|
+
*/
|
|
449
|
+
const isDurableChange = (event: CollabEvent): event is CollabDurableChange =>
|
|
450
|
+
event.type === "itinerary.changed" ||
|
|
451
|
+
event.type === "segment.changed" ||
|
|
452
|
+
event.type === "waypoint.changed" ||
|
|
453
|
+
event.type === "zone.changed" ||
|
|
454
|
+
event.type === "collection.changed";
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* sleep resolves after `ms`, or immediately once `signal` aborts, so a backoff wait
|
|
458
|
+
* never outlives the session's disposal: the pending timer is cleared on abort
|
|
459
|
+
* rather than firing into a torn-down session.
|
|
460
|
+
*/
|
|
461
|
+
const sleep = (ms: number, signal: AbortSignal): Promise<void> =>
|
|
462
|
+
new Promise<void>((resolve) => {
|
|
463
|
+
if (signal.aborted) {
|
|
464
|
+
resolve();
|
|
465
|
+
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const onAbort = (): void => {
|
|
470
|
+
clearTimeout(timer);
|
|
471
|
+
resolve();
|
|
472
|
+
};
|
|
473
|
+
const timer = setTimeout(() => {
|
|
474
|
+
signal.removeEventListener("abort", onAbort);
|
|
475
|
+
resolve();
|
|
476
|
+
}, ms);
|
|
477
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Coalescer collapses a burst of updates keyed by an entity into a single trailing
|
|
482
|
+
* dispatch per key. Each push folds into the key's pending value and arms a timer that
|
|
483
|
+
* flushes it after the window. It is the mechanism that turns many rapid `*.changed` frames
|
|
484
|
+
* for one entity into one reconciling apply.
|
|
485
|
+
*
|
|
486
|
+
* `fold` answers the value a key holds once `next` joins the `pending` one. Without one the
|
|
487
|
+
* last push stands alone, which is right for a value that carries nothing (the list engine's
|
|
488
|
+
* invalidation).
|
|
489
|
+
*/
|
|
490
|
+
class Coalescer<T> {
|
|
491
|
+
private readonly pending = new Map<string, T>();
|
|
492
|
+
private readonly timers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
493
|
+
|
|
494
|
+
constructor(
|
|
495
|
+
private readonly delayMs: number,
|
|
496
|
+
private readonly flush: (value: T) => void,
|
|
497
|
+
private readonly fold: (pending: T, next: T) => T = (_pending, next) => next,
|
|
498
|
+
) {}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* push folds the value into the key's pending one and arms a single flush timer for it,
|
|
502
|
+
* so a continuing burst keeps folding into the value without resetting the window.
|
|
503
|
+
*/
|
|
504
|
+
push(key: string, value: T): void {
|
|
505
|
+
const pending = this.pending.get(key);
|
|
506
|
+
this.pending.set(key, pending === undefined ? value : this.fold(pending, value));
|
|
507
|
+
if (!this.timers.has(key)) {
|
|
508
|
+
this.timers.set(
|
|
509
|
+
key,
|
|
510
|
+
setTimeout(() => this.fire(key), this.delayMs),
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* cancel drops every armed timer and pending value, so a disposed session leaves
|
|
517
|
+
* no coalesced dispatch to fire after teardown.
|
|
518
|
+
*/
|
|
519
|
+
cancel(): void {
|
|
520
|
+
for (const timer of this.timers.values()) {
|
|
521
|
+
clearTimeout(timer);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
this.timers.clear();
|
|
525
|
+
this.pending.clear();
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
private fire(key: string): void {
|
|
529
|
+
this.timers.delete(key);
|
|
530
|
+
const value = this.pending.get(key);
|
|
531
|
+
this.pending.delete(key);
|
|
532
|
+
if (value !== undefined) {
|
|
533
|
+
this.flush(value);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* StreamLoopConfig wires a StreamLoop to one collaboration stream: how to open it
|
|
540
|
+
* (subscribe, taking the resume/abort options) and what to do with each decoded
|
|
541
|
+
* frame. Both the editor and org-list sessions build one, differing only in which
|
|
542
|
+
* transport subscribe they bind and how they route a frame.
|
|
543
|
+
*/
|
|
544
|
+
interface StreamLoopConfig {
|
|
545
|
+
/**
|
|
546
|
+
* Whether a frame is the arrival of the session's own member: the `presence.join` the editor
|
|
547
|
+
* stream broadcasts as a member's first stream opens, which reaches that stream as it reaches
|
|
548
|
+
* every other. It follows the {@link OPENING_SNAPSHOTS} on such an open and shows what they
|
|
549
|
+
* show, that the stream opened, so the loop reads no progress in it. Omitted, no frame is one:
|
|
550
|
+
* on the list stream every `presence.join` is progress.
|
|
551
|
+
*
|
|
552
|
+
* `member` is the user the stream is read as, the one the session token the open was made with
|
|
553
|
+
* names, as the transport tells it as the open is answered, and undefined where the client is
|
|
554
|
+
* not told that user.
|
|
555
|
+
*/
|
|
556
|
+
isOwnArrival?: ((event: CollabEvent, member: string | undefined) => boolean) | undefined;
|
|
557
|
+
/** Told once, with the failure, when a terminal fault stops the loop. */
|
|
558
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
559
|
+
onFrame: (event: CollabEvent, frameId?: string) => void;
|
|
560
|
+
/**
|
|
561
|
+
* Told as each attempt opens, before its subscribe: whatever the stream carried before it, the
|
|
562
|
+
* frames no read was there to deliver included, is behind the session by then.
|
|
563
|
+
*/
|
|
564
|
+
onOpen?: (() => void) | undefined;
|
|
565
|
+
subscribe: (handlers: CollabStreamHandlers, options: CollabSubscribeOptions) => () => void;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* StreamAttempt is the outcome of one open of a collaboration stream: whether it
|
|
570
|
+
* made progress, delivering a frame beyond the {@link OPENING_SNAPSHOTS} and the member's own
|
|
571
|
+
* arrival (so the loop chooses a prompt reconnect over a backoff), whether it ended with the
|
|
572
|
+
* credential it was opened with (`reconnect`, which the loop follows at once whatever the attempt
|
|
573
|
+
* delivered), and whether it failed terminally (a fault a reconnect cannot recover, so the loop
|
|
574
|
+
* stops instead of reconnecting). The transport decides which faults are terminal and which
|
|
575
|
+
* closes end with the credential, and a terminal attempt carries the failure so the loop can
|
|
576
|
+
* surface it.
|
|
577
|
+
*/
|
|
578
|
+
type StreamAttempt =
|
|
579
|
+
| { progressed: boolean; reconnect: boolean; terminal: false; waitMs?: number | undefined }
|
|
580
|
+
| { error: unknown; progressed: boolean; terminal: true };
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* StreamLoop keeps one collaboration stream open for the life of a session, reconnecting when it
|
|
584
|
+
* drops. A collaboration stream has no terminal event, so a close or a TRANSIENT fault is a
|
|
585
|
+
* candidate for a resume: the loop reconnects from the last durable frame's id, promptly after an
|
|
586
|
+
* attempt that made progress, and otherwise after the jittered wait {@link reconnectDelayMs} draws
|
|
587
|
+
* on the feed's {@link reconnectSchedule}, so a dead endpoint is not hammered. A 500 on the open is
|
|
588
|
+
* transient like any 5xx, and is bounded by that wait, and so is a stream the client's own reader
|
|
589
|
+
* gives up as gone silent. A stream that ended with the credential it was opened with, or that
|
|
590
|
+
* the API could not keep delivering (the transport closes either as `reconnect`: the API said
|
|
591
|
+
* so, or the session token it carried has expired), is no drop: the loop reopens it at once, with
|
|
592
|
+
* the token the client holds then and the last event id, and the count of opens without progress
|
|
593
|
+
* starts again, as it does after progress. A 401 on that reopen is terminal like any 4xx but a 429. A 429 names its wait in
|
|
594
|
+
* `Retry-After`, and the next open waits it out in place of the schedule's draw, with up to a
|
|
595
|
+
* second drawn above it ({@link retryAfterDelayMs}): the bound on the streams one member or one
|
|
596
|
+
* address holds open answers the same until one of them ends, and answers every reader it refused
|
|
597
|
+
* in one window the same seconds. A 503 that names its wait is waited out the same way: the API
|
|
598
|
+
* answers one, naming a second, while a stream's events cannot be reached for a moment, and the
|
|
599
|
+
* reopen resumes from the last event id with nothing missed. A TERMINAL fault (one a reconnect
|
|
600
|
+
* cannot recover, as the transport classifies it) is the exception: the loop disposes itself
|
|
601
|
+
* rather than retry forever. Every attempt's stream is released as the attempt ends, before
|
|
602
|
+
* anything reopens. dispose() trips the abort that both closes the open stream and wakes any
|
|
603
|
+
* pending backoff wait.
|
|
604
|
+
*/
|
|
605
|
+
class StreamLoop {
|
|
606
|
+
private disposed = false;
|
|
607
|
+
// The last position the stream named, sent back as Last-Event-ID so a reconnect resumes
|
|
608
|
+
// after it rather than replaying the whole durable history. A frame advances it only as a
|
|
609
|
+
// durable change (consume gates on isDurableChange), so a spuriously-numbered ephemeral frame
|
|
610
|
+
// never moves it; a record that names a position and carries no frame moves it too, and an
|
|
611
|
+
// empty `id:` clears it.
|
|
612
|
+
private lastEventId: string | undefined;
|
|
613
|
+
// Aborts a pending backoff wait on dispose so a torn-down loop never wakes to
|
|
614
|
+
// reconnect. Tripped once, by dispose().
|
|
615
|
+
private readonly lifecycle = new AbortController();
|
|
616
|
+
// Aborts the currently-open stream. Replaced each reconnect, tripped by dispose().
|
|
617
|
+
private streamAbort: AbortController | null = null;
|
|
618
|
+
// Unsubscribes from the open stream. The abort tears a live fetch down; this stops
|
|
619
|
+
// the callback delivery (and the scripted drain, which has no fetch). A settle
|
|
620
|
+
// inside consume clears it; dispose() calls it explicitly.
|
|
621
|
+
private unsubscribe: (() => void) | null = null;
|
|
622
|
+
// Set by the first start(): the loop holds one stream's handles, so it runs once.
|
|
623
|
+
private started = false;
|
|
624
|
+
|
|
625
|
+
constructor(private readonly config: StreamLoopConfig) {}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* start opens the stream and runs the reconnect loop until dispose(). The
|
|
629
|
+
* returned work is fire-and-forget: the loop reacts to frames through the
|
|
630
|
+
* configured onFrame and never resolves to the caller.
|
|
631
|
+
*
|
|
632
|
+
* A second call is a no-op, and so is one after dispose(). A second loop would overwrite the
|
|
633
|
+
* handles of the first, and dispose() would then release the second stream alone.
|
|
634
|
+
*/
|
|
635
|
+
start(): void {
|
|
636
|
+
if (this.started || this.disposed) {
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
this.started = true;
|
|
641
|
+
void this.run();
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* dispose stops the loop and tears the open stream down: it aborts the lifecycle
|
|
646
|
+
* (waking any backoff wait), then aborts the open stream and unsubscribes so a
|
|
647
|
+
* parked read is released. Idempotent.
|
|
648
|
+
*/
|
|
649
|
+
dispose(): void {
|
|
650
|
+
if (this.disposed) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
this.disposed = true;
|
|
655
|
+
this.lifecycle.abort();
|
|
656
|
+
this.teardownStream();
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* teardownStream releases the open stream from both sides: it captures the
|
|
661
|
+
* unsubscribe BEFORE aborting (the abort's settle nulls the field, so capturing
|
|
662
|
+
* first keeps the scripted drain's teardown reachable), aborts the live fetch,
|
|
663
|
+
* then unsubscribes. The release runs once whichever path reaches it first, the
|
|
664
|
+
* settle or this call. Idempotent.
|
|
665
|
+
*/
|
|
666
|
+
private teardownStream(): void {
|
|
667
|
+
const unsubscribe = this.unsubscribe;
|
|
668
|
+
this.unsubscribe = null;
|
|
669
|
+
this.streamAbort?.abort();
|
|
670
|
+
unsubscribe?.();
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
private async run(): Promise<void> {
|
|
674
|
+
// The consecutive attempts that made no progress, which sets the ceiling of the next wait.
|
|
675
|
+
// An attempt that made progress resets it.
|
|
676
|
+
let failures = 0;
|
|
677
|
+
// The wait the last refusal named (the `Retry-After` of a 429 or a 503), which the next open
|
|
678
|
+
// waits out in place of the schedule's draw: a reopen sooner meets the same answer, a 429's
|
|
679
|
+
// counted against the same bound, and one later waits for nothing. Undefined where it named
|
|
680
|
+
// none; a wait of zero seconds is named, and the draw above it is then the whole wait.
|
|
681
|
+
let named: number | undefined;
|
|
682
|
+
while (!this.disposed) {
|
|
683
|
+
if (failures > 0 || named !== undefined) {
|
|
684
|
+
const wait =
|
|
685
|
+
named === undefined
|
|
686
|
+
? reconnectDelayMs(failures, reconnectSchedule)
|
|
687
|
+
: retryAfterDelayMs(named);
|
|
688
|
+
await sleep(wait, this.lifecycle.signal);
|
|
689
|
+
if (this.disposed) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const abort = new AbortController();
|
|
695
|
+
this.streamAbort = abort;
|
|
696
|
+
|
|
697
|
+
const attempt = await this.consume(abort.signal);
|
|
698
|
+
if (this.disposed || abort.signal.aborted) {
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// A terminal failure will keep failing the same way, so stop the loop rather
|
|
703
|
+
// than reconnect forever: dispose tears the open stream down and no further
|
|
704
|
+
// reconnect runs. And say why, once: a loop that stopped silently leaves a surface
|
|
705
|
+
// that looks live and never updates.
|
|
706
|
+
if (attempt.terminal) {
|
|
707
|
+
this.dispose();
|
|
708
|
+
// The host's sink is called from a loop nothing awaits, so its own fault is surfaced
|
|
709
|
+
// rather than left to reject that loop unhandled.
|
|
710
|
+
try {
|
|
711
|
+
this.config.onError?.(attempt.error);
|
|
712
|
+
} catch (fault) {
|
|
713
|
+
surfaceFault(fault);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// A stream that made progress reconnects with no wait (a healthy feed the API or a
|
|
720
|
+
// proxy cycles), and so does one that ended with its credential, whatever it delivered:
|
|
721
|
+
// the reopen carries the token the client holds now, and the count starts again. One that
|
|
722
|
+
// failed, or delivered only the frames an open begins with, waits a jittered draw below a
|
|
723
|
+
// ceiling that doubles, so a dead endpoint is retried at a cadence.
|
|
724
|
+
failures = attempt.progressed || attempt.reconnect ? 0 : failures + 1;
|
|
725
|
+
named = attempt.waitMs;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* consume opens one read of the stream and resolves a {@link StreamAttempt}:
|
|
731
|
+
* whether it made progress (so run() chooses a prompt reconnect over a backoff)
|
|
732
|
+
* and whether it failed terminally (so run() stops the loop). It bridges the
|
|
733
|
+
* transport's callbacks to a single promise: onFrame records each DURABLE frame's
|
|
734
|
+
* id as the resume position and routes it; onClose and a transient onError settle
|
|
735
|
+
* the attempt for a reconnect, a close as `reconnect` marking it as the end of the stream's
|
|
736
|
+
* credential, a terminal onError settles it to stop the loop, and so does a
|
|
737
|
+
* subscribe that throws; a dispose abort settles it on its own since the transport fires no
|
|
738
|
+
* callback on a deliberate abort.
|
|
739
|
+
*
|
|
740
|
+
* However the attempt settles, its stream is released as it does, and its listener
|
|
741
|
+
* comes off the attempt's signal. A transport reports a failure through onError with
|
|
742
|
+
* nothing obliging it to have let its connection go first, and each attempt left
|
|
743
|
+
* holding one is a socket: on HTTP/1.1 six of them hold the whole per-origin pool,
|
|
744
|
+
* and every request beside them stalls.
|
|
745
|
+
*/
|
|
746
|
+
private consume(signal: AbortSignal): Promise<StreamAttempt> {
|
|
747
|
+
return new Promise<StreamAttempt>((resolve) => {
|
|
748
|
+
let progressed = false;
|
|
749
|
+
// The handlers and the abort can fire after a settle (a body close racing an
|
|
750
|
+
// abort); this guard makes the first outcome win and drops the rest, so the
|
|
751
|
+
// promise settles exactly once.
|
|
752
|
+
let settled = false;
|
|
753
|
+
// The snapshots this open has yet to deliver; see OPENING_SNAPSHOTS.
|
|
754
|
+
const opening = new Set(OPENING_SNAPSHOTS);
|
|
755
|
+
// The user this open reads the stream as, as the transport tells it once the open is
|
|
756
|
+
// answered; see StreamLoopConfig.isOwnArrival.
|
|
757
|
+
let member: string | undefined;
|
|
758
|
+
// What the transport's subscribe returned for this attempt, until it is called.
|
|
759
|
+
let handle: (() => void) | undefined;
|
|
760
|
+
|
|
761
|
+
// Releases this attempt's stream once, however many paths reach for it: the settle, a
|
|
762
|
+
// dispose, or both.
|
|
763
|
+
const release = (): void => {
|
|
764
|
+
const pending = handle;
|
|
765
|
+
handle = undefined;
|
|
766
|
+
pending?.();
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
// `failure` is present exactly when the attempt failed terminally, carrying what failed;
|
|
770
|
+
// `reconnect` says the stream ended with the credential it was opened with; `waitMs` is the
|
|
771
|
+
// wait a refusal named, the `Retry-After` of a 429 or a 503, which the next open waits out.
|
|
772
|
+
const finish = (
|
|
773
|
+
failure?: { readonly error: unknown },
|
|
774
|
+
reconnect = false,
|
|
775
|
+
waitMs?: number,
|
|
776
|
+
): void => {
|
|
777
|
+
if (settled) {
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
settled = true;
|
|
782
|
+
signal.removeEventListener("abort", onAbort);
|
|
783
|
+
if (this.unsubscribe === release) {
|
|
784
|
+
this.unsubscribe = null;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
release();
|
|
788
|
+
resolve(
|
|
789
|
+
failure === undefined
|
|
790
|
+
? { progressed, reconnect, terminal: false, waitMs }
|
|
791
|
+
: { error: failure.error, progressed, terminal: true },
|
|
792
|
+
);
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
// A deliberate abort (dispose) fires no transport callback, so settle here.
|
|
796
|
+
// run() reads abort.signal.aborted and returns, so progress is moot.
|
|
797
|
+
const onAbort = (): void => finish();
|
|
798
|
+
|
|
799
|
+
if (signal.aborted) {
|
|
800
|
+
finish();
|
|
801
|
+
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
806
|
+
|
|
807
|
+
const handlers: CollabStreamHandlers = {
|
|
808
|
+
onClose: (reason) => finish(undefined, reason === "reconnect"),
|
|
809
|
+
// A transient error settles the attempt like a close: run() reopens at once after an
|
|
810
|
+
// attempt that made progress and after a wait otherwise. A terminal error settles it
|
|
811
|
+
// carrying the failure, so run() stops the loop and surfaces it. A transient stream
|
|
812
|
+
// drop is background noise the session recovers from silently.
|
|
813
|
+
onError: (error, options) =>
|
|
814
|
+
options?.terminal === true
|
|
815
|
+
? finish({ error })
|
|
816
|
+
: finish(undefined, false, retryAfterMsOf(error)),
|
|
817
|
+
onFrame: (frame) => {
|
|
818
|
+
if (settled) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// The first of each opening snapshot says nothing about the stream staying up, and
|
|
823
|
+
// neither does the member's own arrival; any other frame, a second snapshot of a kind
|
|
824
|
+
// included, does.
|
|
825
|
+
if (!opening.delete(frame.event.type) && !this.isOwnArrival(frame.event, member)) {
|
|
826
|
+
progressed = true;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// Only a durable change advances the resume cursor. Gating on the decoded
|
|
830
|
+
// event (not merely on the presence of a frame id) is defense-in-depth:
|
|
831
|
+
// the API is expected never to number an ephemeral frame, but a
|
|
832
|
+
// spuriously-numbered one must not move the cursor past unread durable
|
|
833
|
+
// history. The frame is still routed below; it just does not resume from.
|
|
834
|
+
if (frame.id && isDurableChange(frame.event)) {
|
|
835
|
+
this.lastEventId = frame.id;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
try {
|
|
839
|
+
this.config.onFrame(frame.event, frame.id === "" ? undefined : frame.id);
|
|
840
|
+
} catch {
|
|
841
|
+
// A frame the session cannot apply (a snapshot with no roster in it, a lock frame
|
|
842
|
+
// naming no entity) is dropped, and the stream reads on, as the bus drops a change
|
|
843
|
+
// its tool refuses. Thrown on, it would end the read: the transport reports the
|
|
844
|
+
// throw as the read failing, and the reopen replays the snapshot that opens every
|
|
845
|
+
// read, so one frame a producer keeps sending would cost every frame behind it.
|
|
846
|
+
}
|
|
847
|
+
},
|
|
848
|
+
// A record that names a position and carries no event moves the cursor too. No frame
|
|
849
|
+
// carries that position, so there is no event for the gate above to read, and none that
|
|
850
|
+
// could be an ephemeral one. A settled attempt's report is stale, like its frames.
|
|
851
|
+
onLastEventId: (lastEventId) => {
|
|
852
|
+
if (!settled) {
|
|
853
|
+
this.lastEventId = lastEventId;
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
onOpen: (open) => {
|
|
857
|
+
if (!settled) {
|
|
858
|
+
member = open.userId;
|
|
859
|
+
}
|
|
860
|
+
},
|
|
861
|
+
// A frame the transport skips, a kind this build does not know or data it cannot read, is
|
|
862
|
+
// none of those every open begins with, so the stream delivered something past them.
|
|
863
|
+
onSkippedFrame: () => {
|
|
864
|
+
if (!settled) {
|
|
865
|
+
progressed = true;
|
|
866
|
+
}
|
|
867
|
+
},
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
this.config.onOpen?.();
|
|
871
|
+
try {
|
|
872
|
+
handle = this.config.subscribe(handlers, {
|
|
873
|
+
lastEventId: this.lastEventId,
|
|
874
|
+
signal,
|
|
875
|
+
});
|
|
876
|
+
} catch (error) {
|
|
877
|
+
// A subscribe that throws opened nothing and would throw the same way on every
|
|
878
|
+
// reopen, so the attempt settles as a terminal failure. Thrown on, it would reject
|
|
879
|
+
// run()'s own promise, which nothing awaits, and the loop would stop with no word.
|
|
880
|
+
finish({ error });
|
|
881
|
+
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// An attempt the transport settled from inside subscribe itself (a credential it refused
|
|
886
|
+
// before the open) settled before its release existed, so it is released here.
|
|
887
|
+
if (settled) {
|
|
888
|
+
release();
|
|
889
|
+
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
this.unsubscribe = release;
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* isOwnArrival asks the session whether a frame is its own member's arrival
|
|
899
|
+
* ({@link StreamLoopConfig.isOwnArrival}), and reads an answer that throws as yes: a frame the
|
|
900
|
+
* session cannot attribute is no evidence that the stream stays up. Thrown on, the fault would
|
|
901
|
+
* reach the transport as the subscriber's own, which ends the stream for good, where the same
|
|
902
|
+
* fault met as the frame is applied loses that frame alone.
|
|
903
|
+
*/
|
|
904
|
+
private isOwnArrival(event: CollabEvent, member: string | undefined): boolean {
|
|
905
|
+
try {
|
|
906
|
+
return this.config.isOwnArrival?.(event, member) === true;
|
|
907
|
+
} catch {
|
|
908
|
+
return true;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* CollabEngine is the editor collaboration session for one resource (an itinerary
|
|
915
|
+
* or a zone). start() opens the resource's event stream and keeps it open
|
|
916
|
+
* (reconnecting on drop), applying every received frame by dispatching a LOCAL
|
|
917
|
+
* tool through the bus, named by the caller's own {@link CollabTools} table: a durable change is
|
|
918
|
+
* coalesced then reconciled through `changeApply`; a peer's
|
|
919
|
+
* presence, selection, lock or draft is
|
|
920
|
+
* reflected through the matching peer tool (an echo of the local user's own signal
|
|
921
|
+
* is dropped), and a peer's cursor is read and applied through no tool. The upstream helpers
|
|
922
|
+
* announce the local user's own transient state, paced so a high-frequency source (a dragged
|
|
923
|
+
* geometry) never floods the signal endpoint. The bus is the sole mutation surface: the session itself touches no
|
|
924
|
+
* store, map, or cache.
|
|
925
|
+
*
|
|
926
|
+
* A studio host passes `studioCollabTools` from `@mountaya/studio` as `tools` and its bus as
|
|
927
|
+
* `bus`; a host reconciling into a store of its own names its own tools.
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* ```ts
|
|
931
|
+
* import type { Mountaya } from "@mountaya/client";
|
|
932
|
+
* import { createCollabTransport } from "@mountaya/client/events";
|
|
933
|
+
* import { CollabEngine, type CollabDispatch, type CollabTools } from "@mountaya/elements/collab";
|
|
934
|
+
*
|
|
935
|
+
* declare const mountaya: Mountaya;
|
|
936
|
+
* declare const tools: CollabTools;
|
|
937
|
+
* declare const apply: (name: string, input: unknown) => void;
|
|
938
|
+
*
|
|
939
|
+
* const bus: CollabDispatch<{ viewer: { getUserId(): string | null } }> = {
|
|
940
|
+
* dispatchUnsafe: (_context, name, input) => apply(name, input),
|
|
941
|
+
* };
|
|
942
|
+
*
|
|
943
|
+
* const session = new CollabEngine({
|
|
944
|
+
* bus,
|
|
945
|
+
* ctx: { viewer: { getUserId: () => "user_123" } },
|
|
946
|
+
* onError: (error) => console.error("The collaboration stream stopped.", error),
|
|
947
|
+
* resource: { id: "itinerary_123", kind: "itineraries" },
|
|
948
|
+
* tools,
|
|
949
|
+
* transport: createCollabTransport(mountaya.transport),
|
|
950
|
+
* });
|
|
951
|
+
*
|
|
952
|
+
* session.start();
|
|
953
|
+
* // On the way out:
|
|
954
|
+
* session.dispose();
|
|
955
|
+
* ```
|
|
956
|
+
*/
|
|
957
|
+
export class CollabEngine {
|
|
958
|
+
private readonly changeCoalescer: Coalescer<CollabApplyInput>;
|
|
959
|
+
private readonly draftThrottle: TrailingThrottle<{ draft: unknown; entity: CollabEntity }>;
|
|
960
|
+
private readonly loop: StreamLoop;
|
|
961
|
+
private readonly selectionThrottle: TrailingThrottle<CollabSelectionRef | null>;
|
|
962
|
+
// The draft updates sent and not yet answered. A clear leaves only once each has been, since
|
|
963
|
+
// two requests in flight at once are answered in whatever order the network delivers them.
|
|
964
|
+
private readonly draftUpdatesInFlight = new Set<Promise<void>>();
|
|
965
|
+
// The last clear asked for, until it is answered, whether it is still waiting to leave or on
|
|
966
|
+
// the wire: a draft update sent after it waits for it in turn.
|
|
967
|
+
private draftClearInFlight: Promise<void> | null = null;
|
|
968
|
+
// Set by dispose(): a sender called after it is a no-op, and no draft update leaves after it,
|
|
969
|
+
// whenever it was sent.
|
|
970
|
+
private disposed = false;
|
|
971
|
+
// Whether the latest edit signal to settle was refused for want of the write role, so a burst
|
|
972
|
+
// of refusals reports one loss: an accepted edit signal clears it.
|
|
973
|
+
private editRefused = false;
|
|
974
|
+
// The locks this session holds, or has asked for and not yet been answered on, by lockKey.
|
|
975
|
+
private readonly heldLocks = new Set<string>();
|
|
976
|
+
// The locks this session gave back that no lock snapshot has yet settled, answered or not, by
|
|
977
|
+
// lockKey: a stream that re-stamps a lock after its release keeps it held, and a snapshot is
|
|
978
|
+
// where that shows. releaseLock says what settles one.
|
|
979
|
+
private readonly releasedLocks = new Map<string, ReleasedLock>();
|
|
980
|
+
// The locks a release is on the wire for, asked by releaseLock or by a retry, by lockKey.
|
|
981
|
+
private readonly releasesInFlight = new Set<string>();
|
|
982
|
+
// The locks a retry loop runs for, one loop per lock.
|
|
983
|
+
private readonly releaseRetries = new Set<string>();
|
|
984
|
+
// The `lock.acquired` frames this session's own acquires are still owed, by lockKey.
|
|
985
|
+
private readonly owedEchoes = new Map<string, OwedEcho>();
|
|
986
|
+
// The watch over the stream's `lock.acquired` frames (ReleasedLock): minted at the first lock
|
|
987
|
+
// snapshot of each open, and null from the moment an open begins until that snapshot.
|
|
988
|
+
private lockWatch: number | null = null;
|
|
989
|
+
// The last watch minted, so each is new.
|
|
990
|
+
private lockWatches = 0;
|
|
991
|
+
// Aborted by dispose(), which wakes every release retry's wait so none outlives the session.
|
|
992
|
+
private readonly lifecycle = new AbortController();
|
|
993
|
+
|
|
994
|
+
constructor(private readonly config: CollabEngineConfig) {
|
|
995
|
+
this.changeCoalescer = new Coalescer(
|
|
996
|
+
CHANGE_COALESCE_MS,
|
|
997
|
+
(input) => this.dispatch(this.config.tools.changeApply, input),
|
|
998
|
+
foldChange,
|
|
999
|
+
);
|
|
1000
|
+
this.selectionThrottle = new TrailingThrottle(SELECTION_THROTTLE_MS, (selection) => {
|
|
1001
|
+
void this.postSignal({ selection, type: "selection" });
|
|
1002
|
+
});
|
|
1003
|
+
this.draftThrottle = new TrailingThrottle(LIVE_SEGMENT_THROTTLE_MS, ({ draft, entity }) =>
|
|
1004
|
+
// A draft is whatever the editing surface is holding mid-gesture (a GeoJSON geometry,
|
|
1005
|
+
// a live segment), and the server relays it verbatim, so the contract spells it as an
|
|
1006
|
+
// open JSON object. The assertion is where those two meet: every value passed here is
|
|
1007
|
+
// one, and TypeScript refuses the assignment only because an interface carries no
|
|
1008
|
+
// implicit index signature. Validating it would mean this package deciding what a draft
|
|
1009
|
+
// may be, which is the one thing neither end of the relay knows.
|
|
1010
|
+
this.postDraftUpdate({ draft: draft as CollabDraftPayload, entity, type: "draft.update" }),
|
|
1011
|
+
);
|
|
1012
|
+
this.loop = new StreamLoop({
|
|
1013
|
+
// The member the stream is read as is the user its session token names, and the viewer's
|
|
1014
|
+
// only where the client is not told that user: the API sends the join of the member the
|
|
1015
|
+
// token names, whoever the viewer says is signed in.
|
|
1016
|
+
isOwnArrival: (event, member) =>
|
|
1017
|
+
event.type === "presence.join" &&
|
|
1018
|
+
event.user_id === (member ?? this.config.ctx.viewer.getUserId()),
|
|
1019
|
+
onError: (error) => this.config.onError?.(error),
|
|
1020
|
+
onFrame: (event, frameId) => this.applyFrame(event, frameId),
|
|
1021
|
+
onOpen: () => this.beginOpen(),
|
|
1022
|
+
subscribe: (handlers, options) =>
|
|
1023
|
+
this.config.transport.subscribeEditor(this.config.resource, handlers, options),
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* start opens the editor stream and keeps it open until dispose(). One engine follows one
|
|
1029
|
+
* stream: a second call, or one after dispose(), is a no-op.
|
|
1030
|
+
*/
|
|
1031
|
+
start(): void {
|
|
1032
|
+
this.loop.start();
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* dispose tears the stream down and drops every pending coalesced or throttled send, so
|
|
1037
|
+
* leaving the resource leaks no connection. No draft update leaves after it, one still waiting
|
|
1038
|
+
* on a clear included.
|
|
1039
|
+
*
|
|
1040
|
+
* A clear asked for before dispose still leaves, once the draft updates sent before it are
|
|
1041
|
+
* answered: a clear only removes a draft at peers, and dropping it would leave them the phantom
|
|
1042
|
+
* draft {@link clearDraft} exists to prevent.
|
|
1043
|
+
*
|
|
1044
|
+
* {@link sendSelection}, {@link sendDraft} and {@link clearDraft} called
|
|
1045
|
+
* after it send nothing and arm no timer: a signal sent then would announce a member who left.
|
|
1046
|
+
*/
|
|
1047
|
+
dispose(): void {
|
|
1048
|
+
this.disposed = true;
|
|
1049
|
+
this.lifecycle.abort();
|
|
1050
|
+
this.loop.dispose();
|
|
1051
|
+
this.changeCoalescer.cancel();
|
|
1052
|
+
this.selectionThrottle.cancel();
|
|
1053
|
+
this.draftThrottle.cancel();
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* sendSelection announces the local user's selection (or its clearing, with
|
|
1058
|
+
* null), trailing-throttled so a rapid re-selection sends only the settled target. Nothing is
|
|
1059
|
+
* sent while {@link CollabEngineConfig.canEdit} answers false when the selection is due.
|
|
1060
|
+
*/
|
|
1061
|
+
sendSelection(selection: CollabSelectionRef | null): void {
|
|
1062
|
+
if (this.disposed) {
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
this.selectionThrottle.push(selection);
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* sendDraft announces the local user's in-progress (uncommitted) geometry for an
|
|
1071
|
+
* entity, trailing-throttled at the live-segment cadence so a peer's preview
|
|
1072
|
+
* advances smoothly without flooding the endpoint. The throttle is single-slot: a
|
|
1073
|
+
* second entity's draft pushed within the window would replace the first. That is
|
|
1074
|
+
* correct only because the local user edits one entity at a time (the tool layer's
|
|
1075
|
+
* `guardEditBegin` enforces the one-edit-at-a-time invariant), so a refactor that
|
|
1076
|
+
* relaxed that mutual exclusion would have to key this throttle per entity.
|
|
1077
|
+
*/
|
|
1078
|
+
sendDraft(entity: CollabEntity, draft: unknown): void {
|
|
1079
|
+
if (this.disposed) {
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
this.draftThrottle.push({ draft, entity });
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* clearDraft announces that the local user's live draft for an entity is gone (an
|
|
1088
|
+
* edit committed or cancelled). It drops any draft update still parked in the
|
|
1089
|
+
* throttle first, and leaves only once every draft update already sent has been
|
|
1090
|
+
* answered, so a stale update can never land after the clear and resurrect a
|
|
1091
|
+
* phantom draft for peers: one no later signal removes while its author stays
|
|
1092
|
+
* connected. With nothing unanswered before it, it leaves at once.
|
|
1093
|
+
*
|
|
1094
|
+
* A draft update sent after the clear leaves only once the clear has been answered, whether
|
|
1095
|
+
* the clear left at once or is still waiting, so the clear never wipes the draft of the edit
|
|
1096
|
+
* after it. Best-effort, like the other transient senders: a draft signal that failed holds
|
|
1097
|
+
* nothing back.
|
|
1098
|
+
*/
|
|
1099
|
+
clearDraft(entity: CollabEntity): void {
|
|
1100
|
+
if (this.disposed) {
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
this.draftThrottle.cancel();
|
|
1105
|
+
|
|
1106
|
+
const signal: CollabSignal = { entity, type: "draft.clear" };
|
|
1107
|
+
const earlier = [...this.draftUpdatesInFlight];
|
|
1108
|
+
if (this.draftClearInFlight !== null) {
|
|
1109
|
+
earlier.push(this.draftClearInFlight);
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
const cleared =
|
|
1113
|
+
earlier.length === 0
|
|
1114
|
+
? this.postSignal(signal)
|
|
1115
|
+
: Promise.all(earlier).then(() => this.postSignal(signal));
|
|
1116
|
+
this.draftClearInFlight = cleared;
|
|
1117
|
+
void cleared.then(() => {
|
|
1118
|
+
if (this.draftClearInFlight === cleared) {
|
|
1119
|
+
this.draftClearInFlight = null;
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* acquireLock asks the API to grant the local user the entity's soft-lock. It
|
|
1126
|
+
* resolves acquired when the lock is the local user's to take, and not-acquired
|
|
1127
|
+
* (carrying the id of the peer holding it, when the 409 named one) on a genuine
|
|
1128
|
+
* contention.
|
|
1129
|
+
*
|
|
1130
|
+
* It REJECTS on anything else, and that is the whole point. Swallowing the throw
|
|
1131
|
+
* into `{ acquired: false }` would collapse unrelated outcomes onto one answer: a
|
|
1132
|
+
* 400 on a malformed or unauthenticated write, a 403, a 404, a 500, a 504, and a
|
|
1133
|
+
* dropped socket would all arrive as "not acquired, no holder", which the caller can
|
|
1134
|
+
* only report as contention: a lone editor told that somebody else is editing their
|
|
1135
|
+
* itinerary, and on the add-segment path (where the lock is taken on a uuid minted a
|
|
1136
|
+
* microsecond earlier) a sentence that can never be true.
|
|
1137
|
+
* A failure that names itself is a failure somebody can fix; a failure disguised as
|
|
1138
|
+
* a peer is one nobody can even look for.
|
|
1139
|
+
*
|
|
1140
|
+
* A rejection that settles nothing (no answer came, or the server failed: a 5xx, a 408, a 429)
|
|
1141
|
+
* may still have left the lock taken, since the API can take a lock and lose its answer. Nobody
|
|
1142
|
+
* edits under it, so the session gives it back in the background as it gives back a lock whose
|
|
1143
|
+
* release failed ({@link releaseLock}), and the caller hears the rejection all the same.
|
|
1144
|
+
*
|
|
1145
|
+
* @throws {MountayaElementsForbiddenError} Before anything is sent, while
|
|
1146
|
+
* {@link CollabEngineConfig.canEdit} answers false: the API refuses every signal of a member
|
|
1147
|
+
* who only watches with a 403, which this stands in for.
|
|
1148
|
+
*/
|
|
1149
|
+
async acquireLock(
|
|
1150
|
+
entity: CollabEntity,
|
|
1151
|
+
): Promise<{ acquired: boolean; holderId?: string | undefined }> {
|
|
1152
|
+
// Asked of a member who only watches, it is refused here rather than sent: the API refuses
|
|
1153
|
+
// every signal of such a member, and a lock asked for answers a caller who waits on it, so
|
|
1154
|
+
// the refusal names itself rather than reading as a contention. Its class is the one a caller
|
|
1155
|
+
// reads as a refused permission, as it reads the API's 403 for the same lock.
|
|
1156
|
+
if (!this.maySignal()) {
|
|
1157
|
+
throw new MountayaElementsForbiddenError(
|
|
1158
|
+
`CollabEngine.acquireLock: the local user holds no write role on ${this.config.resource.kind} ` +
|
|
1159
|
+
`${this.config.resource.id}, as canEdit answers, so no lock on ${entity.kind} ${entity.id} ` +
|
|
1160
|
+
"is asked for: the API refuses every signal of a member who only watches. Begin an edit " +
|
|
1161
|
+
"only where canEdit answers true, and read the member's roles again where it should.",
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// Armed again: a release of the same lock still waiting to be asked again stops, since the
|
|
1166
|
+
// lock is wanted. It is put back where the API does not answer, as the lock may still be held.
|
|
1167
|
+
const key = lockKey(entity);
|
|
1168
|
+
const givenBack = this.releasedLocks.get(key);
|
|
1169
|
+
this.heldLocks.add(key);
|
|
1170
|
+
this.releasedLocks.delete(key);
|
|
1171
|
+
// Owed from the send rather than the answer: the frame is published first, and usually
|
|
1172
|
+
// arrives first.
|
|
1173
|
+
this.oweEcho(key);
|
|
1174
|
+
|
|
1175
|
+
let result: CollabSignalResult;
|
|
1176
|
+
try {
|
|
1177
|
+
result = await this.sendEditSignal({ entity, type: "lock.acquire" });
|
|
1178
|
+
} catch (error) {
|
|
1179
|
+
this.heldLocks.delete(key);
|
|
1180
|
+
// A failure that settles nothing may have left the lock taken, and the frame its grant
|
|
1181
|
+
// stamps owed; it is given back as a failed release is. Any other took nothing, and leaves
|
|
1182
|
+
// a lock that was being given back to the release it was under.
|
|
1183
|
+
const unsettled = unsettledFailure(error);
|
|
1184
|
+
this.answerEcho(key, unsettled);
|
|
1185
|
+
const record: ReleasedLock | undefined =
|
|
1186
|
+
givenBack ?? (unsettled ? { entity, watch: null } : undefined);
|
|
1187
|
+
if (record !== undefined && !this.releasedLocks.has(key)) {
|
|
1188
|
+
this.releasedLocks.set(key, record);
|
|
1189
|
+
this.retryRelease(key, entity, false, retryAfterMsOf(error));
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
throw error;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
this.answerEcho(key, result.ok);
|
|
1196
|
+
if (result.ok) {
|
|
1197
|
+
return { acquired: true };
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
this.heldLocks.delete(key);
|
|
1201
|
+
|
|
1202
|
+
return result.holderId === undefined
|
|
1203
|
+
? { acquired: false }
|
|
1204
|
+
: { acquired: false, holderId: result.holderId };
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* releaseLock relinquishes the local user's soft-lock on an entity. Unlike the
|
|
1209
|
+
* best-effort transient senders it surfaces a failure (it rejects), so a caller can react. While
|
|
1210
|
+
* {@link CollabEngineConfig.canEdit} answers false it sends nothing and resolves: a member who
|
|
1211
|
+
* only watches holds no lock to give back.
|
|
1212
|
+
*
|
|
1213
|
+
* No TTL frees a lock whose release failed: the editor stream keeps every lock its member holds
|
|
1214
|
+
* alive for as long as it stays open. So a release that finds no answer or meets a fault of the
|
|
1215
|
+
* server's (a 5xx, a 408, a 429, a dropped socket) is asked again in the background, after a wait
|
|
1216
|
+
* that doubles from one second to thirty, or after the wait a 429 or a 503 named, for as long as
|
|
1217
|
+
* the session lives and the entity is not armed again by {@link acquireLock}. A caller that
|
|
1218
|
+
* repeats a release that rejected asks for it twice: the session is already asking. A refusal no
|
|
1219
|
+
* repeat changes (a 403, a 404) forgets it at once. A 409 never rejects: the client's transport
|
|
1220
|
+
* answers it as a result, so the release resolves and the lock is kept until a snapshot settles
|
|
1221
|
+
* it.
|
|
1222
|
+
*
|
|
1223
|
+
* Each `lock.snapshot` reconciles the locks this session gave back. One it does not list is
|
|
1224
|
+
* forgotten, and a retry still waiting for it stops. One it still lists while a retry waits is
|
|
1225
|
+
* left to that retry, which the snapshot wakes no sooner. One it still lists after its release
|
|
1226
|
+
* was answered is asked for again at once, where the stream has been read without a break since
|
|
1227
|
+
* that release left: the stream re-stamps a lock its member holds on a clock of its own, and a
|
|
1228
|
+
* re-stamp that crossed the release is what the snapshot shows.
|
|
1229
|
+
*
|
|
1230
|
+
* A snapshot names the member and not the connection, so a lock the member holds from another
|
|
1231
|
+
* tab is told apart only by that tab's `lock.acquired`, which the stream carries and never
|
|
1232
|
+
* replays. A lock this session never took is left alone. One it gave back and another tab took
|
|
1233
|
+
* since is forgotten on that frame, and nothing more is asked for it. Where the stream broke
|
|
1234
|
+
* between the release and the snapshot (a credential's end, a drop), the frame may have come
|
|
1235
|
+
* while no read was open: a lock whose release was answered is then forgotten at the snapshot,
|
|
1236
|
+
* whatever it lists, which leaves a re-stamp that crossed that release held. A release that
|
|
1237
|
+
* failed is asked for across a break all the same, so a tab that took the lock during it loses
|
|
1238
|
+
* it: its acquire refreshed a lock the release never let go of, and no answer the API gives can
|
|
1239
|
+
* tell the two tabs apart.
|
|
1240
|
+
*/
|
|
1241
|
+
async releaseLock(entity: CollabEntity): Promise<void> {
|
|
1242
|
+
const key = lockKey(entity);
|
|
1243
|
+
this.heldLocks.delete(key);
|
|
1244
|
+
|
|
1245
|
+
// A member who only watches holds no lock: the API released any they held when their write
|
|
1246
|
+
// role went, so there is nothing to give back and nothing is sent.
|
|
1247
|
+
if (!this.maySignal()) {
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
const record: ReleasedLock = { entity, watch: this.lockWatch };
|
|
1252
|
+
this.releasedLocks.set(key, record);
|
|
1253
|
+
this.releasesInFlight.add(key);
|
|
1254
|
+
try {
|
|
1255
|
+
await this.sendEditSignal({ entity, type: "lock.release" });
|
|
1256
|
+
} catch (error) {
|
|
1257
|
+
if (unsettledFailure(error)) {
|
|
1258
|
+
this.retryRelease(key, entity, false, retryAfterMsOf(error));
|
|
1259
|
+
} else if (this.releasedLocks.get(key) === record) {
|
|
1260
|
+
this.releasedLocks.delete(key);
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
throw error;
|
|
1264
|
+
} finally {
|
|
1265
|
+
this.releasesInFlight.delete(key);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* stillToRelease reports whether a lock this session gave back may still be asked for: the
|
|
1271
|
+
* session lives, no snapshot has settled it, the entity was not armed again, and the member may
|
|
1272
|
+
* still signal.
|
|
1273
|
+
*/
|
|
1274
|
+
private stillToRelease(key: string): boolean {
|
|
1275
|
+
return (
|
|
1276
|
+
!this.disposed && this.releasedLocks.has(key) && !this.heldLocks.has(key) && this.maySignal()
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
/**
|
|
1281
|
+
* retryRelease asks again, in the background, for the release of a lock this session gave back,
|
|
1282
|
+
* one loop per lock: at once where `immediate` (a snapshot that still lists it), after the wait
|
|
1283
|
+
* a 429 or a 503 named where `namedMs` carries one, and after the release schedule's wait
|
|
1284
|
+
* otherwise. The loop ends on an answer, which leaves the lock remembered for the next snapshot
|
|
1285
|
+
* to settle, on a refusal no repeat can change, which forgets it, and as soon as
|
|
1286
|
+
* {@link stillToRelease} answers false.
|
|
1287
|
+
*/
|
|
1288
|
+
private retryRelease(
|
|
1289
|
+
key: string,
|
|
1290
|
+
entity: CollabEntity,
|
|
1291
|
+
immediate = false,
|
|
1292
|
+
namedMs?: number,
|
|
1293
|
+
): void {
|
|
1294
|
+
if (this.releaseRetries.has(key) || !this.stillToRelease(key)) {
|
|
1295
|
+
return;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
this.releaseRetries.add(key);
|
|
1299
|
+
void this.runReleaseRetries(key, entity, immediate ? 0 : 1, namedMs).finally(() => {
|
|
1300
|
+
this.releaseRetries.delete(key);
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
private async runReleaseRetries(
|
|
1305
|
+
key: string,
|
|
1306
|
+
entity: CollabEntity,
|
|
1307
|
+
failed: number,
|
|
1308
|
+
namedMs: number | undefined,
|
|
1309
|
+
): Promise<void> {
|
|
1310
|
+
let failures = failed;
|
|
1311
|
+
let named = namedMs;
|
|
1312
|
+
while (this.stillToRelease(key)) {
|
|
1313
|
+
if (failures > 0) {
|
|
1314
|
+
// The wait a 429 or a 503 named replaces the schedule, as it does before a stream reopens.
|
|
1315
|
+
const wait =
|
|
1316
|
+
named === undefined
|
|
1317
|
+
? reconnectDelayMs(failures, releaseRetrySchedule)
|
|
1318
|
+
: retryAfterDelayMs(named);
|
|
1319
|
+
await sleep(wait, this.lifecycle.signal);
|
|
1320
|
+
if (!this.stillToRelease(key)) {
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
const record = this.releasedLocks.get(key);
|
|
1326
|
+
if (record !== undefined) {
|
|
1327
|
+
record.watch = this.lockWatch;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
this.releasesInFlight.add(key);
|
|
1331
|
+
try {
|
|
1332
|
+
await this.sendEditSignal({ entity, type: "lock.release" });
|
|
1333
|
+
} catch (error) {
|
|
1334
|
+
if (!unsettledFailure(error)) {
|
|
1335
|
+
if (this.releasedLocks.get(key) === record) {
|
|
1336
|
+
this.releasedLocks.delete(key);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
failures += 1;
|
|
1343
|
+
named = retryAfterMsOf(error);
|
|
1344
|
+
continue;
|
|
1345
|
+
} finally {
|
|
1346
|
+
this.releasesInFlight.delete(key);
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* reconcileReleasedLocks reads a lock snapshot against the locks this session gave back, as
|
|
1355
|
+
* {@link releaseLock} states: a release on the wire is left to its answer, which the snapshot may
|
|
1356
|
+
* predate; a lock it does not list is forgotten; a lock it lists is left to a retry still
|
|
1357
|
+
* waiting for it, asked for again at once where its answered release left under the watch the
|
|
1358
|
+
* session still keeps, and forgotten where it did not.
|
|
1359
|
+
*/
|
|
1360
|
+
private reconcileReleasedLocks(
|
|
1361
|
+
locks: Extract<CollabEvent, { type: "lock.snapshot" }>["locks"],
|
|
1362
|
+
): void {
|
|
1363
|
+
if (this.releasedLocks.size === 0) {
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
const listed = new Set(
|
|
1368
|
+
locks.filter((lock) => this.isSelf(lock.user_id)).map((lock) => lockKey(lock.entity)),
|
|
1369
|
+
);
|
|
1370
|
+
for (const [key, record] of [...this.releasedLocks]) {
|
|
1371
|
+
if (this.releasesInFlight.has(key)) {
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
if (!listed.has(key)) {
|
|
1376
|
+
this.releasedLocks.delete(key);
|
|
1377
|
+
|
|
1378
|
+
continue;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
if (this.releaseRetries.has(key)) {
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
if (record.watch !== null && record.watch === this.lockWatch) {
|
|
1386
|
+
this.retryRelease(key, record.entity, true);
|
|
1387
|
+
} else {
|
|
1388
|
+
this.releasedLocks.delete(key);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* readOwnLockAcquired reads a `lock.acquired` the stream stamps with the local member. While one
|
|
1395
|
+
* of this session's own acquires of the entity is owed a frame ({@link OwedEcho}), the frame is
|
|
1396
|
+
* that acquire's and pays the debt. Otherwise it is another of the member's connections taking
|
|
1397
|
+
* the lock (a second tab). A lock this session gave back and that connection took is that
|
|
1398
|
+
* connection's edit now, and the API releases a lock by member and never by connection, so it is
|
|
1399
|
+
* forgotten: no snapshot that lists it and no retry still waiting asks for its release again,
|
|
1400
|
+
* which would end that tab's edit. A release already on the wire is left to settle, and nothing
|
|
1401
|
+
* follows it.
|
|
1402
|
+
*/
|
|
1403
|
+
private readOwnLockAcquired(entity: Pick<CollabEntity, "id" | "kind">): void {
|
|
1404
|
+
const key = lockKey(entity);
|
|
1405
|
+
const owed = this.owedEchoes.get(key);
|
|
1406
|
+
if (owed !== undefined && owed.frames > 0) {
|
|
1407
|
+
owed.frames -= 1;
|
|
1408
|
+
this.dropPaidEcho(key, owed);
|
|
1409
|
+
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
this.releasedLocks.delete(key);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* oweEcho records that an acquire of the entity is on its way, and owes the frame its grant
|
|
1418
|
+
* would stamp ({@link OwedEcho}).
|
|
1419
|
+
*/
|
|
1420
|
+
private oweEcho(key: string): void {
|
|
1421
|
+
const owed = this.owedEchoes.get(key) ?? { asking: 0, frames: 0, snapshots: 0 };
|
|
1422
|
+
owed.asking += 1;
|
|
1423
|
+
owed.frames += 1;
|
|
1424
|
+
owed.snapshots = 0;
|
|
1425
|
+
this.owedEchoes.set(key, owed);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* answerEcho records that an acquire of the entity was answered, and pays the frame it owed
|
|
1430
|
+
* unless the API may have granted it (`granted`: an acceptance, or a failure that settled
|
|
1431
|
+
* nothing).
|
|
1432
|
+
*/
|
|
1433
|
+
private answerEcho(key: string, granted: boolean): void {
|
|
1434
|
+
const owed = this.owedEchoes.get(key);
|
|
1435
|
+
if (owed === undefined) {
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
owed.asking = Math.max(0, owed.asking - 1);
|
|
1440
|
+
if (!granted) {
|
|
1441
|
+
owed.frames = Math.max(0, owed.frames - 1);
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
this.dropPaidEcho(key, owed);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
/** dropPaidEcho forgets a debt that owes no frame and waits on no acquire. */
|
|
1448
|
+
private dropPaidEcho(key: string, owed: OwedEcho): void {
|
|
1449
|
+
if (owed.frames === 0 && owed.asking === 0) {
|
|
1450
|
+
this.owedEchoes.delete(key);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* ageOwedEchoes counts one lock snapshot against every debt whose lock the session neither holds
|
|
1456
|
+
* nor asks for, and forgets each once its count reaches {@link OWED_ECHO_SNAPSHOTS}. A lock held
|
|
1457
|
+
* or asked for starts its count again.
|
|
1458
|
+
*/
|
|
1459
|
+
private ageOwedEchoes(): void {
|
|
1460
|
+
for (const [key, owed] of [...this.owedEchoes]) {
|
|
1461
|
+
if (this.heldLocks.has(key) || owed.asking > 0) {
|
|
1462
|
+
owed.snapshots = 0;
|
|
1463
|
+
|
|
1464
|
+
continue;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
owed.snapshots += 1;
|
|
1468
|
+
if (owed.snapshots >= OWED_ECHO_SNAPSHOTS) {
|
|
1469
|
+
this.owedEchoes.delete(key);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
/**
|
|
1475
|
+
* beginOpen runs as each open of the stream begins: the watch over the member's `lock.acquired`
|
|
1476
|
+
* frames ends, since the frames sent until the new read opens are never delivered, and every
|
|
1477
|
+
* debt goes but those of the acquires still on the wire, whose frames may yet come to it.
|
|
1478
|
+
*/
|
|
1479
|
+
private beginOpen(): void {
|
|
1480
|
+
this.lockWatch = null;
|
|
1481
|
+
for (const [key, owed] of [...this.owedEchoes]) {
|
|
1482
|
+
owed.frames = Math.min(owed.frames, owed.asking);
|
|
1483
|
+
owed.snapshots = 0;
|
|
1484
|
+
this.dropPaidEcho(key, owed);
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
/**
|
|
1489
|
+
* maySignal reports whether the local user may send a signal now, as the host's
|
|
1490
|
+
* {@link CollabEngineConfig.canEdit} answers it: every signal where the host states no answer,
|
|
1491
|
+
* and none where its answer throws, whose fault reaches the program on a microtask.
|
|
1492
|
+
*/
|
|
1493
|
+
private maySignal(): boolean {
|
|
1494
|
+
const canEdit = this.config.canEdit;
|
|
1495
|
+
if (canEdit === undefined) {
|
|
1496
|
+
return true;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
try {
|
|
1500
|
+
return canEdit() === true;
|
|
1501
|
+
} catch (fault) {
|
|
1502
|
+
surfaceFault(fault);
|
|
1503
|
+
|
|
1504
|
+
return false;
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* sendEditSignal sends one of the local user's edit signals (a lock or a draft) and reads its
|
|
1510
|
+
* outcome for the write role: an answer clears the refusal latch, a contention included, since
|
|
1511
|
+
* the API judges a contention only for a member it lets edit, and a 403 is reported through
|
|
1512
|
+
* {@link CollabEngineConfig.onEditRefused}. The outcome is handed back as it came, a rejection
|
|
1513
|
+
* included.
|
|
1514
|
+
*/
|
|
1515
|
+
private async sendEditSignal(signal: CollabEditSignal): Promise<CollabSignalResult> {
|
|
1516
|
+
try {
|
|
1517
|
+
const result = await this.config.transport.sendSignal(this.config.resource, signal);
|
|
1518
|
+
this.editRefused = false;
|
|
1519
|
+
|
|
1520
|
+
return result;
|
|
1521
|
+
} catch (error) {
|
|
1522
|
+
if (statusOf(error) === 403) {
|
|
1523
|
+
this.reportEditRefused(error, signal.entity);
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
throw error;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/**
|
|
1531
|
+
* reportEditRefused tells the host that an edit signal was refused for want of the write role,
|
|
1532
|
+
* once for a run of refusals. A session the host disposed reports nothing: the edit it would
|
|
1533
|
+
* close is gone with it.
|
|
1534
|
+
*/
|
|
1535
|
+
private reportEditRefused(error: unknown, entity: CollabEntity): void {
|
|
1536
|
+
if (this.editRefused || this.disposed) {
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
this.editRefused = true;
|
|
1541
|
+
try {
|
|
1542
|
+
this.config.onEditRefused?.(error, entity);
|
|
1543
|
+
} catch (fault) {
|
|
1544
|
+
surfaceFault(fault);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
/**
|
|
1549
|
+
* applyFrame routes one received editor frame to a LOCAL tool dispatch. A durable
|
|
1550
|
+
* change is coalesced per entity and reconciled through change.apply (never
|
|
1551
|
+
* actor-filtered: a second tab of the SAME user must reconcile too). An ephemeral
|
|
1552
|
+
* frame is dropped when it echoes the local user's own signal, and otherwise
|
|
1553
|
+
* reflects a peer's transient state through the matching peer tool. An unknown
|
|
1554
|
+
* frame type never reaches here: the transport drops it at decode.
|
|
1555
|
+
*
|
|
1556
|
+
* Each family has its own method: a durable change here, a snapshot in
|
|
1557
|
+
* {@link applySnapshot}, and every other frame in {@link applyPeerFrame}, whose parameter is
|
|
1558
|
+
* stated by exclusion so that a kind the contract gains has to be given an arm there.
|
|
1559
|
+
*/
|
|
1560
|
+
private applyFrame(event: CollabEvent, frameId?: string): void {
|
|
1561
|
+
if (isDurableChange(event)) {
|
|
1562
|
+
this.changeCoalescer.push(`${event.kind}:${event.id}`, changeApplyInput(event, frameId));
|
|
1563
|
+
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
if (event.type === "presence.snapshot" || event.type === "lock.snapshot") {
|
|
1568
|
+
this.applySnapshot(event);
|
|
1569
|
+
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
// The end of the stream's credential, or of the API's delivery of it, is the read's to act
|
|
1574
|
+
// on, and the loop reopens on the close that follows it. A transport of the host's own that
|
|
1575
|
+
// hands the frame on as well has it dropped here: it carries nothing to apply.
|
|
1576
|
+
if (event.type === "reconnect") {
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
this.applyPeerFrame(event);
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
/**
|
|
1584
|
+
* applySnapshot applies a frame that states a whole set at once, the roster or the held locks,
|
|
1585
|
+
* with the local user's own entries left out. The frame is applied whoever is in it: it
|
|
1586
|
+
* replaces what the local side holds.
|
|
1587
|
+
*/
|
|
1588
|
+
private applySnapshot(event: CollabSnapshotEvent): void {
|
|
1589
|
+
if (event.type === "presence.snapshot") {
|
|
1590
|
+
// Self is filtered out of the roster, not dropped: the snapshot still seeds
|
|
1591
|
+
// the peer set for everyone else connected. Each wire timestamp is converted
|
|
1592
|
+
// to the epoch-ms number the presence tool holds.
|
|
1593
|
+
const peers = event.members
|
|
1594
|
+
.filter((member) => !this.isSelf(member.user_id))
|
|
1595
|
+
.map((member) => ({
|
|
1596
|
+
connectedAt: toEpochMs(member.connected_at),
|
|
1597
|
+
userId: member.user_id,
|
|
1598
|
+
}));
|
|
1599
|
+
this.dispatch(this.config.tools.presenceSnapshot, {
|
|
1600
|
+
peers,
|
|
1601
|
+
resource: this.config.resource,
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
// Snapshot semantics, not echo: the frame is the authoritative held-lock
|
|
1608
|
+
// set, so the local user's OWN entries are filtered OUT (their locks are
|
|
1609
|
+
// reflected by their own edit flow) but the rest of the frame is APPLIED:
|
|
1610
|
+
// the lock-snapshot tool replaces the local lock map with every peer lock.
|
|
1611
|
+
// That wholesale replace is what clears a stale "locked by …" badge when its
|
|
1612
|
+
// holder departs uncleanly. Each wire entity and holder is translated to the
|
|
1613
|
+
// camelCase the tool holds.
|
|
1614
|
+
this.reconcileReleasedLocks(event.locks);
|
|
1615
|
+
this.ageOwedEchoes();
|
|
1616
|
+
// The first lock snapshot of an open starts the watch, after it was read against the locks
|
|
1617
|
+
// given back: a release that left before it may have missed a frame no read was open for.
|
|
1618
|
+
if (this.lockWatch === null) {
|
|
1619
|
+
this.lockWatches += 1;
|
|
1620
|
+
this.lockWatch = this.lockWatches;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
const locks = event.locks
|
|
1624
|
+
.filter((lock) => !this.isSelf(lock.user_id))
|
|
1625
|
+
.map((lock) => ({
|
|
1626
|
+
id: lock.entity.id,
|
|
1627
|
+
kind: lock.entity.kind,
|
|
1628
|
+
userId: lock.user_id,
|
|
1629
|
+
}));
|
|
1630
|
+
this.dispatch(this.config.tools.lockSnapshot, { locks, resource: this.config.resource });
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
/**
|
|
1634
|
+
* applyPeerFrame reflects one member's transient state through the matching peer tool, and
|
|
1635
|
+
* drops the frame when it echoes the local user's own signal. A `lock.acquired` of the local
|
|
1636
|
+
* member is read before it is dropped, by {@link readOwnLockAcquired}.
|
|
1637
|
+
*/
|
|
1638
|
+
private applyPeerFrame(event: CollabPeerEvent): void {
|
|
1639
|
+
if (this.isSelf(event.user_id)) {
|
|
1640
|
+
if (event.type === "lock.acquired") {
|
|
1641
|
+
this.readOwnLockAcquired(event.entity);
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
switch (event.type) {
|
|
1648
|
+
case "presence.join":
|
|
1649
|
+
this.dispatch(this.config.tools.presenceSet, {
|
|
1650
|
+
connectedAt: toEpochMs(event.connected_at),
|
|
1651
|
+
resource: this.config.resource,
|
|
1652
|
+
userId: event.user_id,
|
|
1653
|
+
});
|
|
1654
|
+
|
|
1655
|
+
return;
|
|
1656
|
+
|
|
1657
|
+
case "presence.leave":
|
|
1658
|
+
this.dispatch(this.config.tools.presenceClear, {
|
|
1659
|
+
resource: this.config.resource,
|
|
1660
|
+
userId: event.user_id,
|
|
1661
|
+
});
|
|
1662
|
+
|
|
1663
|
+
return;
|
|
1664
|
+
|
|
1665
|
+
case "selection":
|
|
1666
|
+
this.dispatch(this.config.tools.peerSelectionSet, {
|
|
1667
|
+
resource: this.config.resource,
|
|
1668
|
+
selection: event.selection,
|
|
1669
|
+
userId: event.user_id,
|
|
1670
|
+
});
|
|
1671
|
+
|
|
1672
|
+
return;
|
|
1673
|
+
|
|
1674
|
+
case "cursor":
|
|
1675
|
+
// The wire carries a peer's cursor, and no tool reflects it: the studio draws no peer
|
|
1676
|
+
// cursor until a cursor feature is designed.
|
|
1677
|
+
return;
|
|
1678
|
+
|
|
1679
|
+
case "lock.acquired":
|
|
1680
|
+
this.dispatch(this.config.tools.lockSet, {
|
|
1681
|
+
id: event.entity.id,
|
|
1682
|
+
kind: event.entity.kind,
|
|
1683
|
+
resource: this.config.resource,
|
|
1684
|
+
userId: event.user_id,
|
|
1685
|
+
});
|
|
1686
|
+
|
|
1687
|
+
return;
|
|
1688
|
+
|
|
1689
|
+
case "lock.released":
|
|
1690
|
+
this.dispatch(this.config.tools.lockClear, {
|
|
1691
|
+
id: event.entity.id,
|
|
1692
|
+
kind: event.entity.kind,
|
|
1693
|
+
resource: this.config.resource,
|
|
1694
|
+
});
|
|
1695
|
+
|
|
1696
|
+
return;
|
|
1697
|
+
|
|
1698
|
+
case "draft.update":
|
|
1699
|
+
// A zone draft relays the drawn Polygon|LineString the peer is reshaping; a
|
|
1700
|
+
// segment draft relays the live ItinerarySegment projection. The peerDraft.set
|
|
1701
|
+
// tool discriminates on `kind`, so a zone frame carries its geometry under
|
|
1702
|
+
// `zone` while the segment frame keeps its `segment` shape byte-for-byte.
|
|
1703
|
+
this.dispatch(
|
|
1704
|
+
this.config.tools.peerDraftSet,
|
|
1705
|
+
event.entity.kind === "zone"
|
|
1706
|
+
? {
|
|
1707
|
+
id: event.entity.id,
|
|
1708
|
+
kind: "zone",
|
|
1709
|
+
resource: this.config.resource,
|
|
1710
|
+
userId: event.user_id,
|
|
1711
|
+
zone: event.draft,
|
|
1712
|
+
}
|
|
1713
|
+
: {
|
|
1714
|
+
id: event.entity.id,
|
|
1715
|
+
kind: "segment",
|
|
1716
|
+
resource: this.config.resource,
|
|
1717
|
+
segment: event.draft,
|
|
1718
|
+
userId: event.user_id,
|
|
1719
|
+
},
|
|
1720
|
+
);
|
|
1721
|
+
|
|
1722
|
+
return;
|
|
1723
|
+
|
|
1724
|
+
case "draft.clear":
|
|
1725
|
+
this.dispatch(this.config.tools.peerDraftClear, {
|
|
1726
|
+
id: event.entity.id,
|
|
1727
|
+
kind: event.entity.kind,
|
|
1728
|
+
resource: this.config.resource,
|
|
1729
|
+
});
|
|
1730
|
+
|
|
1731
|
+
return;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
// Every arm above returns, so `event` narrows to `never` here, and that is the gate that
|
|
1735
|
+
// carries the frame kinds. The switch has no `default` and the method returns void, so a
|
|
1736
|
+
// member the contract gains would fall straight through and be dropped in silence: no
|
|
1737
|
+
// error, no log, a whole class of frame quietly not applied. It fails `tsc` on this line
|
|
1738
|
+
// instead, naming the member that has no arm.
|
|
1739
|
+
event satisfies never;
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
/**
|
|
1743
|
+
* isSelf reports whether a frame's user id is the local user's, read live off the
|
|
1744
|
+
* viewer seam so a session built before the viewer hydrates self-filters correctly
|
|
1745
|
+
* once it does.
|
|
1746
|
+
*/
|
|
1747
|
+
private isSelf(userId: string): boolean {
|
|
1748
|
+
return userId === this.config.ctx.viewer.getUserId();
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
/**
|
|
1752
|
+
* dispatch applies a received frame by running a LOCAL tool through the bus, without waiting
|
|
1753
|
+
* and whatever the dispatcher does with it ({@link dispatchContained}).
|
|
1754
|
+
*/
|
|
1755
|
+
private dispatch(name: string, input: unknown): void {
|
|
1756
|
+
dispatchContained(this.config.bus, this.config.ctx, name, input);
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
/**
|
|
1760
|
+
* postSignal sends one upstream signal, best-effort: a failed send is swallowed
|
|
1761
|
+
* rather than surfaced, because presence, selection and draft self-heal on the next
|
|
1762
|
+
* movement and a dropped frame is not worth interrupting the user for. It resolves
|
|
1763
|
+
* once the signal has been answered, either way, and never rejects or throws: a
|
|
1764
|
+
* draft signal chained behind it must leave whatever became of this one.
|
|
1765
|
+
*
|
|
1766
|
+
* Nothing is sent while {@link CollabEngineConfig.canEdit} answers false, since the API refuses
|
|
1767
|
+
* every signal of a member who only watches. The swallow stays for the role that changes
|
|
1768
|
+
* between that answer and the API's: a signal on its way when the write role went is refused
|
|
1769
|
+
* and dropped. A draft signal is an edit signal, so a 403 refusing one still reaches the host
|
|
1770
|
+
* through {@link CollabEngineConfig.onEditRefused}: the user lost the write role, which no next
|
|
1771
|
+
* movement heals.
|
|
1772
|
+
*/
|
|
1773
|
+
private postSignal(signal: CollabSignal): Promise<void> {
|
|
1774
|
+
// Read at the send, never at the push: a selection or a draft the throttle held while the
|
|
1775
|
+
// member lost the write role is not sent once it is due.
|
|
1776
|
+
if (!this.maySignal()) {
|
|
1777
|
+
return Promise.resolve();
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
try {
|
|
1781
|
+
const sent =
|
|
1782
|
+
signal.type === "draft.update" || signal.type === "draft.clear"
|
|
1783
|
+
? this.sendEditSignal(signal)
|
|
1784
|
+
: this.config.transport.sendSignal(this.config.resource, signal);
|
|
1785
|
+
|
|
1786
|
+
return sent.then(
|
|
1787
|
+
() => undefined,
|
|
1788
|
+
() => undefined,
|
|
1789
|
+
);
|
|
1790
|
+
} catch {
|
|
1791
|
+
// A transport that throws rather than rejecting has failed the send all the same.
|
|
1792
|
+
return Promise.resolve();
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
/**
|
|
1797
|
+
* postDraftUpdate sends one draft update, once the last clear has been answered when one has
|
|
1798
|
+
* not been ({@link clearDraft}), and records it as on the wire until it is answered. An update
|
|
1799
|
+
* whose turn comes after dispose() is dropped.
|
|
1800
|
+
*/
|
|
1801
|
+
private postDraftUpdate(signal: CollabSignal): void {
|
|
1802
|
+
const send = (): Promise<void> => (this.disposed ? Promise.resolve() : this.postSignal(signal));
|
|
1803
|
+
const pendingClear = this.draftClearInFlight;
|
|
1804
|
+
const sent = pendingClear === null ? send() : pendingClear.then(send);
|
|
1805
|
+
this.draftUpdatesInFlight.add(sent);
|
|
1806
|
+
void sent.then(() => {
|
|
1807
|
+
this.draftUpdatesInFlight.delete(sent);
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* CollabListEngine is the org-list collaboration session: it keeps the org's
|
|
1814
|
+
* itinerary-list event stream open (reconnecting on drop) and reconciles the
|
|
1815
|
+
* grouped listing. An itinerary change invalidates the whole listing through
|
|
1816
|
+
* the caller's `listApply` tool; any other durable change on this stream (a zone, a
|
|
1817
|
+
* collection) reconciles through `changeApply` exactly as the editor
|
|
1818
|
+
* session does. It is deliberately lightweight: the list surface announces nothing
|
|
1819
|
+
* upstream, so it carries no signal helpers.
|
|
1820
|
+
*
|
|
1821
|
+
* @example
|
|
1822
|
+
* ```ts
|
|
1823
|
+
* import type { Mountaya } from "@mountaya/client";
|
|
1824
|
+
* import { createCollabTransport } from "@mountaya/client/events";
|
|
1825
|
+
* import { CollabListEngine, type CollabDispatch } from "@mountaya/elements/collab";
|
|
1826
|
+
*
|
|
1827
|
+
* declare const mountaya: Mountaya;
|
|
1828
|
+
* declare const bus: CollabDispatch<{ viewer: { getUserId(): string | null } }>;
|
|
1829
|
+
*
|
|
1830
|
+
* const listing = new CollabListEngine({
|
|
1831
|
+
* bus,
|
|
1832
|
+
* ctx: { viewer: { getUserId: () => "user_123" } },
|
|
1833
|
+
* organizationId: "org_123",
|
|
1834
|
+
* tools: { changeApply: "acme.change.apply", listApply: "acme.list.refetch" },
|
|
1835
|
+
* transport: createCollabTransport(mountaya.transport),
|
|
1836
|
+
* });
|
|
1837
|
+
*
|
|
1838
|
+
* listing.start();
|
|
1839
|
+
* ```
|
|
1840
|
+
*/
|
|
1841
|
+
export class CollabListEngine {
|
|
1842
|
+
private readonly changeCoalescer: Coalescer<CollabApplyInput>;
|
|
1843
|
+
private readonly listCoalescer: Coalescer<Record<string, never>>;
|
|
1844
|
+
private readonly loop: StreamLoop;
|
|
1845
|
+
|
|
1846
|
+
constructor(private readonly config: CollabListEngineConfig) {
|
|
1847
|
+
this.changeCoalescer = new Coalescer(
|
|
1848
|
+
CHANGE_COALESCE_MS,
|
|
1849
|
+
(input) => this.dispatch(this.config.tools.changeApply, input),
|
|
1850
|
+
foldChange,
|
|
1851
|
+
);
|
|
1852
|
+
this.listCoalescer = new Coalescer(CHANGE_COALESCE_MS, () =>
|
|
1853
|
+
this.dispatch(this.config.tools.listApply, {}),
|
|
1854
|
+
);
|
|
1855
|
+
this.loop = new StreamLoop({
|
|
1856
|
+
onError: (error) => this.config.onError?.(error),
|
|
1857
|
+
onFrame: (event, frameId) => this.applyFrame(event, frameId),
|
|
1858
|
+
subscribe: (handlers, options) =>
|
|
1859
|
+
this.config.transport.subscribeList(this.config.organizationId, handlers, options),
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* start opens the org list stream and keeps it open until dispose(). One engine follows one
|
|
1865
|
+
* stream: a second call, or one after dispose(), is a no-op.
|
|
1866
|
+
*/
|
|
1867
|
+
start(): void {
|
|
1868
|
+
this.loop.start();
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
/** dispose tears the stream down and drops every pending coalesced dispatch. */
|
|
1872
|
+
dispose(): void {
|
|
1873
|
+
this.loop.dispose();
|
|
1874
|
+
this.changeCoalescer.cancel();
|
|
1875
|
+
this.listCoalescer.cancel();
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
/**
|
|
1879
|
+
* applyFrame routes one received list frame. Only durable changes ride this stream
|
|
1880
|
+
* (it carries no ephemeral peer state), so a non-durable frame is ignored. An
|
|
1881
|
+
* itinerary change coalesces into one grouped-listing invalidation; any other
|
|
1882
|
+
* durable change (a zone, a collection) reconciles through change.apply.
|
|
1883
|
+
*/
|
|
1884
|
+
private applyFrame(event: CollabEvent, frameId?: string): void {
|
|
1885
|
+
if (!isDurableChange(event)) {
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
if (event.kind === "itinerary") {
|
|
1890
|
+
this.listCoalescer.push("list", {});
|
|
1891
|
+
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
this.changeCoalescer.push(`${event.kind}:${event.id}`, changeApplyInput(event, frameId));
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
/** dispatch runs one local tool through the bus, as {@link CollabEngine} does. */
|
|
1899
|
+
private dispatch(name: string, input: unknown): void {
|
|
1900
|
+
dispatchContained(this.config.bus, this.config.ctx, name, input);
|
|
1901
|
+
}
|
|
1902
|
+
}
|