@laceio/sdk 0.1.1 → 0.1.2-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{TransactionBuilder-DrB3NVTi.cjs → TransactionBuilder-X1H9Gze6.cjs} +64 -14
- package/dist/{TransactionBuilder-V6aLx4SV.js → TransactionBuilder-bp2aMDhg.js} +23 -15
- package/dist/{_polyfill-buffer-patch-BnPVerlG.cjs → _polyfill-buffer-patch-CM8X7JiY.cjs} +21 -2
- package/dist/_polyfill-buffer-patch-yNxN4d5E.js +1467 -0
- package/dist/_web-crypto-random-bytes-Bo-GTcRS.js +197 -0
- package/dist/acc-module-4iIUv6My.cjs +27654 -0
- package/dist/acc-module-Cmj8EsIb.js +27624 -0
- package/dist/account-BOQruszJ.js +6 -0
- package/dist/account-BUOj4pYJ.cjs +11 -0
- package/dist/account-call-7wnopBq0.cjs +5 -0
- package/dist/account-call-B9d_2Xwi.js +4 -0
- package/dist/account-call-Bd4Rpbvt.cjs +323 -0
- package/dist/account-call-C3CkDqEC.js +276 -0
- package/dist/account-guards-BtjTGxDZ.cjs +42 -0
- package/dist/account-guards-D9Lu5T3W.js +36 -0
- package/dist/account-tokens-DvkOFVON.js +16 -0
- package/dist/account-tokens-nwcvwLu4.cjs +21 -0
- package/dist/{activity-type.stable-BJEfeLxL.cjs → activity-type-Ch6ljxBy.cjs} +2 -1
- package/dist/{activity-type.stable-C76_hWd7.js → activity-type-GsJGWs-3.js} +2 -1
- package/dist/address-B9ntKL8K.js +13761 -0
- package/dist/address-BXp-mY8H.cjs +11270 -0
- package/dist/{address-book-address-validator-DIUolI-s.js → address-book-address-validator-0J9XAADH.js} +2 -2
- package/dist/address-book-address-validator-DK0dnsRS.cjs +41 -0
- package/dist/address-book-address-validator-Di_ywo8M.js +39 -0
- package/dist/{address-book-address-validator-DNwQGlOB.cjs → address-book-address-validator-Dte_YQ2L.cjs} +2 -2
- package/dist/artefact-loader-BWWYAD7E.cjs +183 -0
- package/dist/artefact-loader-Dik4HIfv.js +160 -0
- package/dist/auto-dismiss-failure-on-success-C-qoJuid.cjs +37 -0
- package/dist/auto-dismiss-failure-on-success-s8MGDEIu.js +31 -0
- package/dist/bip32-D6wd_QMn.cjs +3851 -0
- package/dist/bitcoin-data-provider-BYPSmuZS.js +21 -0
- package/dist/bitcoin-data-provider-w1oEDSU3.cjs +26 -0
- package/dist/bitcoin.cjs +45 -0
- package/dist/bitcoin.d.ts +29906 -1
- package/dist/bitcoin.js +20 -0
- package/dist/{blockfrost-tx-submit-provider-DPTrapz-.js → blockfrost-tx-submit-provider-CBWQ0wK9.js} +5 -157
- package/dist/{blockfrost-tx-submit-provider-BAIzV5o3.cjs → blockfrost-tx-submit-provider-CLNQ5ycR.cjs} +3 -167
- package/dist/bn-d3nSOIf7.cjs +2553 -0
- package/dist/browser-B1eMbDwh.js +7468 -0
- package/dist/bytes.vo-BB7_4JK6.js +23 -0
- package/dist/bytes.vo-BNRquqaO.cjs +34 -0
- package/dist/cardano-DfPwhwm-.js +3 -0
- package/dist/{cardano-network-id.vo-DSxrFk9S.cjs → cardano-network-id.vo-BEDPn6Li.cjs} +1 -1
- package/dist/{cardano-network-id.vo-CK1tNQDg.js → cardano-network-id.vo-Cfpvbod9.js} +1 -1
- package/dist/cardano.cjs +22 -18
- package/dist/cardano.d.ts +16962 -1716
- package/dist/cardano.js +16 -11
- package/dist/client-DXBLHk7K.cjs +808 -0
- package/dist/codecs-Cswkg7Tm.cjs +4051 -0
- package/dist/codecs-Dc1Krpbt.js +3903 -0
- package/dist/{const-C84qHkjp.js → const-BJfIK_G-.js} +4 -4
- package/dist/const-BhYOdznB.cjs +42 -0
- package/dist/const-BsnjG2_Q.cjs +32071 -0
- package/dist/const-CUnCl5U0.js +13 -0
- package/dist/{const-DXk2tFyv.js → const-CjmfjBP3.js} +1 -1
- package/dist/{const-BDEg2Trq.cjs → const-D-eZIS4n.cjs} +4 -4
- package/dist/const-D0CbQlo4.js +154 -0
- package/dist/{const-BY8B3_0_.cjs → const-iwzZEE_w.cjs} +1 -1
- package/dist/contract-1R86jhSw.js +171 -0
- package/dist/contract-MKLzYVkW.cjs +189 -0
- package/dist/create-add-accounts-Brqk84vF.js +102 -0
- package/dist/create-add-accounts-DzXIh7Ot.cjs +114 -0
- package/dist/{delegation-tx-builder-CRpLP6jH.cjs → delegation-tx-builder-Dof_0N_d.cjs} +6 -6
- package/dist/{delegation-tx-builder-CGVqlaFE.js → delegation-tx-builder-Dy3-2Auz.js} +5 -5
- package/dist/{deregistration-tx-builder-DZGwB4cz.cjs → deregistration-tx-builder-CcLwyFpj.cjs} +6 -6
- package/dist/{deregistration-tx-builder-B-CrUyX6.js → deregistration-tx-builder-QkWW_gWl.js} +5 -5
- package/dist/device-commitment-hex.vo-5wFtQvDS.js +26 -0
- package/dist/device-commitment-hex.vo-CT3RmAug.cjs +31 -0
- package/dist/device-readers-CUHYoYOH.js +145 -0
- package/dist/device-readers-CdxS2btd.cjs +168 -0
- package/dist/device-readers-D_JZeNL2.cjs +8 -0
- package/dist/device-readers-DwSNCGPP.js +4 -0
- package/dist/dist-BMi5ZjEq.cjs +43175 -0
- package/dist/dist-BtIq4XFn.cjs +535 -0
- package/dist/dist-C3SHC_Ho.cjs +1394 -0
- package/dist/dist-CykEjYEX.cjs +3814 -0
- package/dist/dist-Dcsxh3be.cjs +3452 -0
- package/dist/dist-DqJfSlTd.cjs +4413 -0
- package/dist/dist-nTZ70qj7.cjs +1306 -0
- package/dist/{earn-rewards-tx-builder-D5sUT5v8.cjs → earn-rewards-tx-builder-BP5JMIKS.cjs} +6 -6
- package/dist/{earn-rewards-tx-builder-BDbTDZmD.js → earn-rewards-tx-builder-Cku4BmNU.js} +5 -5
- package/dist/enc-key-circuits-B7BjgUL9.js +13 -0
- package/dist/enc-key-circuits-BLrZrBVI.cjs +24 -0
- package/dist/english-Byb9M0E_.cjs +2057 -0
- package/dist/envelopes-BGoO_v8m.js +1621 -0
- package/dist/envelopes-CH25R-DN.cjs +1722 -0
- package/dist/errors-BIftM8ZN.cjs +688 -0
- package/dist/errors-DSq5wUwt.js +466 -0
- package/dist/esm-HBSUQw3w.js +384 -0
- package/dist/esm-LZuaZjMf.cjs +389 -0
- package/dist/experimental.cjs +7349 -0
- package/dist/experimental.d.ts +86279 -0
- package/dist/experimental.js +7184 -0
- package/dist/gated-call-CDCVZIK-.cjs +5 -0
- package/dist/gated-call-D-tT7P_t.js +722 -0
- package/dist/gated-call-D_VT2quk.js +4 -0
- package/dist/gated-call-DgJm1Mi_.cjs +787 -0
- package/dist/grant-circuits-DswmW3nI.cjs +71 -0
- package/dist/grant-circuits-Jxb5y1HW.js +42 -0
- package/dist/grant-rules-By07_eDi.js +6824 -0
- package/dist/grant-rules-BzVTWXS7.cjs +7099 -0
- package/dist/grant-spend-B3Md9L0n.js +215 -0
- package/dist/grant-spend-oWmzRsjH.cjs +217 -0
- package/dist/grant-status-B2y49iIu.js +2688 -0
- package/dist/grant-status-DOr3t_u8.cjs +2820 -0
- package/dist/grants-2BZ-qEVQ.js +5 -0
- package/dist/grants-BPoLSiMt.cjs +18 -0
- package/dist/grants-BoI5uwSF.cjs +272 -0
- package/dist/grants-CtofFu-e.js +213 -0
- package/dist/{group-cardano-addresses-by-account-B533oVXR.cjs → group-cardano-addresses-by-account-Bp0g4wEY.cjs} +3 -39
- package/dist/{group-cardano-addresses-by-account-RHKoEskR.js → group-cardano-addresses-by-account-SR8MMrZf.js} +5 -35
- package/dist/{guarded-transaction-signer-Bxl6_XNd.cjs → guarded-transaction-signer-MFpPg98D.cjs} +17 -18
- package/dist/{guarded-transaction-signer-CpKLj8Kp.js → guarded-transaction-signer-P6Rp1faj.js} +8 -15
- package/dist/hex-D9ITYbwt.cjs +263 -0
- package/dist/hex-mkXcV3pN.js +191 -0
- package/dist/http-client-B3N-TMxu.cjs +167 -0
- package/dist/http-client-TRlhDZGh.js +155 -0
- package/dist/identity-BMLuufva.cjs +263 -0
- package/dist/identity-DII6f-h7.js +233 -0
- package/dist/in-memory-wallet-integration-B2xzxORj.cjs +20741 -0
- package/dist/in-memory-wallet-integration-CBRiPjLO.js +130 -0
- package/dist/in-memory-wallet-integration-CULUB5Tf.cjs +240 -0
- package/dist/{in-memory-wallet-integration-D-qn65Kx.js → in-memory-wallet-integration-ChIOirMW.js} +5 -2
- package/dist/{in-memory-wallet-integration-Croiuopx.js → in-memory-wallet-integration-CljprQQV.js} +7 -104
- package/dist/{in-memory-wallet-integration-DVh9sRXa.cjs → in-memory-wallet-integration-Cm6P8sk6.cjs} +3 -2
- package/dist/in-memory-wallet-integration-TM9bBphA.js +20738 -0
- package/dist/{in-memory-wallet-integration-CnLYeX4-.cjs → in-memory-wallet-integration-t9I00R_V.cjs} +17 -108
- package/dist/index.cjs +84 -47
- package/dist/index.d.ts +37505 -10036
- package/dist/index.js +52 -24
- package/dist/{init-CLHuAMB-.js → init-0zzs9aqU.js} +4 -4
- package/dist/{init-U8c9yHYx.cjs → init-5KcGcBb5.cjs} +1 -1
- package/dist/{init-CigestoM.js → init-B3-1ghyx.js} +2 -2
- package/dist/init-B8U3ABhS.cjs +107 -0
- package/dist/init-BJn-8_hf.js +141 -0
- package/dist/init-BPU3j8sT.cjs +6 -0
- package/dist/init-BRzH6xu-2.cjs +2797 -0
- package/dist/init-BmzfDaKL.js +1142 -0
- package/dist/{init-C-jErzp5.cjs → init-BopV9ed4.cjs} +2 -2
- package/dist/init-BpHTq2R5.js +105 -0
- package/dist/init-BpSITBfF.js +39 -0
- package/dist/{init-DX4WyB0R.cjs → init-BrdVzxei.cjs} +3 -3
- package/dist/{init-LfyMo-sS.cjs → init-BwkU0ruo.cjs} +2 -2
- package/dist/{init-CB__aLD7.cjs → init-C-G32J12.cjs} +2 -2
- package/dist/init-C00gw1zi.js +422 -0
- package/dist/{init-TkPq_Ny_.js → init-C2RgrfZe.js} +1 -1
- package/dist/init-C5mYyFTv.js +3584 -0
- package/dist/{init-DcYY6zMD.js → init-C8URA2OX.js} +1 -1
- package/dist/init-CDkRynJa.js +2796 -0
- package/dist/{init-Cg9XdAru.js → init-CNM5m7M2.js} +4 -4
- package/dist/init-CR7BfztQ.cjs +18 -0
- package/dist/{init-CSHwHnfg.cjs → init-CSDpdu0Q.cjs} +2 -2
- package/dist/{init-aJHl-7AO.js → init-CX0AMQUn.js} +2 -2
- package/dist/{init-FMGDET-9.js → init-CfTbSEKy.js} +259 -60
- package/dist/{init-CR6tpw1B.js → init-Cigr_tKx.js} +47 -43
- package/dist/init-Clu8pxwQ.cjs +1181 -0
- package/dist/{init-CFYsq82V.js → init-CyAY4Lzl.js} +1 -1
- package/dist/{init-BKhH6mVR.cjs → init-D6BxBs7e.cjs} +1 -1
- package/dist/init-D8OeObDF.cjs +1141 -0
- package/dist/init-D9g1HXYf.cjs +40 -0
- package/dist/{init-CNLGJJRx.js → init-DA7zmptx.js} +1 -1
- package/dist/{init-DkIc5nqF.cjs → init-DFMiP2ZH.cjs} +1 -1
- package/dist/{init-zSzCjoor.js → init-DFjT8YvT.js} +4 -4
- package/dist/init-DGjXwWs2.cjs +143 -0
- package/dist/init-DHrCbpkW.cjs +121 -0
- package/dist/init-DRzJR02G.cjs +3585 -0
- package/dist/{init-B64zCLxG.cjs → init-DUF4ar8P.cjs} +4 -4
- package/dist/init-DlqJuHhl.js +119 -0
- package/dist/{init-y2Ra0vZP.js → init-Dnsv155v.js} +3 -3
- package/dist/init-DuYENxci.js +17 -0
- package/dist/{init-D6DBUsD3.cjs → init-Dv3zKj0r.cjs} +4 -4
- package/dist/{init-BtzMZ7Pk.cjs → init-Dy-05ktr.cjs} +1 -1
- package/dist/{init-BsCBAGWf.cjs → init-EP0CUWNK.cjs} +2 -2
- package/dist/{init-BJVU54pI.cjs → init-EhzD7a8i.cjs} +1 -1
- package/dist/{init-w9GEs73W.js → init-Fw89ZmrR.js} +2 -2
- package/dist/init-GsT2AEa4.cjs +424 -0
- package/dist/{init-Rxohwpmu.js → init-NCjgwCZy.js} +2 -2
- package/dist/{init-DxUHsN53.cjs → init-NdhG_VrF.cjs} +6 -6
- package/dist/{init-DDdhguVC.js → init-SZ01tARX2.js} +2 -2
- package/dist/{init-BAJJzBza.js → init-Y3mkB4XS.js} +2 -2
- package/dist/init-c4l6r-o-.js +5 -0
- package/dist/{init-Dku4b2lG.js → init-kEfUTuG2.js} +1 -1
- package/dist/{init-C7IeJwQR.cjs → init-lzHt4Cli.cjs} +256 -59
- package/dist/init-qSEd_Spq.js +1182 -0
- package/dist/{init-anYu6XB7.cjs → init-rmt7-fQE.cjs} +2 -2
- package/dist/{init-C4Bkib9u.cjs → init-zU-_9Gsp.cjs} +67 -65
- package/dist/{is-retriable-error-BU0e3hVI.js → is-retriable-error-BUiVJDwH.js} +1 -1
- package/dist/{is-retriable-error-CeeuHqDa.cjs → is-retriable-error-Dpt860if.cjs} +1 -1
- package/dist/jubjub-authoriser-D7zDXu3V.js +86 -0
- package/dist/jubjub-authoriser-Dgu6o3Sv.cjs +87 -0
- package/dist/key-source-5oUBFiC7.cjs +583 -0
- package/dist/key-source-B08HukZg.js +2550 -0
- package/dist/keyDerivation-D3k9XyHg.js +4077 -0
- package/dist/keyDerivation-u0nBA93T.cjs +274 -0
- package/dist/{lace-context-CZcNHr4M.js → lace-context-BZciB9c7.js} +4 -4
- package/dist/{lace-context-fJTDghdp.cjs → lace-context-DgR6vLli.cjs} +4 -4
- package/dist/lib--iqvW4O_.js +2354 -0
- package/dist/lib-Yk6Upl5D.cjs +2359 -0
- package/dist/{libsodium-wrappers-UH0LaOUE.js → libsodium-wrappers-BhbOA8dQ.js} +3 -1647
- package/dist/midnight-account-id.vo-0x9X-r3l.cjs +10 -0
- package/dist/midnight-account-id.vo-DjCAGcqc.js +5 -0
- package/dist/midnight-engine-DpemplKO.js +5 -0
- package/dist/midnight-engine-xU1wotne.cjs +6 -0
- package/dist/midnight-wallet-DIsAlSn6.js +18 -0
- package/dist/midnight-wallet-XTZc2li7.cjs +24 -0
- package/dist/midnight.cjs +1408 -0
- package/dist/midnight.d.ts +28934 -0
- package/dist/midnight.js +1352 -0
- package/dist/modules-cardano-D9Gs2j60.cjs +1108 -0
- package/dist/modules-cardano-VIM8fKu-.js +995 -0
- package/dist/node-relay-DWe1U0w2.cjs +49 -0
- package/dist/node-relay-h4i5IlAQ.js +48 -0
- package/dist/outputs-Bd2yZVjx.js +720 -0
- package/dist/outputs-CJoQBIA2.cjs +990 -0
- package/dist/pbkdf2-CIW-oWrm.cjs +1337 -0
- package/dist/pending-operation-B0_P78Jo.cjs +26 -0
- package/dist/pending-operation-BIS6mpjB.js +21 -0
- package/dist/providers-FjhM47BH.cjs +388 -0
- package/dist/providers-WtiSuxFu.js +365 -0
- package/dist/redacted-BmE2aXqr.js +81 -0
- package/dist/redacted-CRZJLS3w.cjs +86 -0
- package/dist/{retry-config-DC5IMaH7.cjs → retry-config-BaCfVC1H.cjs} +1 -1
- package/dist/{retry-config-BcUmMS--.js → retry-config-Dmgt28wM.js} +1 -1
- package/dist/safe-buffer-B_vMqJWU.js +43 -0
- package/dist/safe-buffer-DYOwEfHB.cjs +48 -0
- package/dist/sdk-Cb-gZnS9.js +1241 -0
- package/dist/sdk-DffwmX8b.cjs +1439 -0
- package/dist/sdk-init-Bln9rFtn.js +4138 -0
- package/dist/sdk-init-CYViTJY_.cjs +3841 -0
- package/dist/{seam-cardano-CATqBEyK.js → seam-cardano-B_etH4F4.js} +1 -1
- package/dist/{bytes.vo-TgiwogWF.js → secret-box-DUR0ACYz.js} +3 -25
- package/dist/{bytes.vo-Ck5u40RA.cjs → secret-box-DrjLZuS1.cjs} +1 -35
- package/dist/send-proof-progress-C-ljq1x5.js +30 -0
- package/dist/send-proof-progress-vmsaSfbz.cjs +47 -0
- package/dist/side-effects-BnqYz7Nl.js +768 -0
- package/dist/side-effects-CngaeXi0.cjs +804 -0
- package/dist/sign-bitcoin-transaction-with-seed-D4z62-jV.js +147 -0
- package/dist/sign-bitcoin-transaction-with-seed-DsLYXnCY.cjs +158 -0
- package/dist/signer-3fk8lZtE.cjs +7 -0
- package/dist/signer-CsL28DrK.cjs +121 -0
- package/dist/signer-DGluibtn.js +92 -0
- package/dist/signer-RqB5pu3K.js +2 -0
- package/dist/signer-factory-BA7WFJVZ.js +282 -0
- package/dist/signer-factory-Cwd6o-lG.cjs +281 -0
- package/dist/{signer-factory-9URFliA5.js → signer-factory-DObB55D4.js} +6 -3
- package/dist/signer-factory-DhZiE03y.cjs +149 -0
- package/dist/{signer-factory-BWGUmnvm.cjs → signer-factory-Ds6G2AZk.cjs} +4 -3
- package/dist/signer-factory-hzSRaIw2.js +148 -0
- package/dist/{slice-CuHUaPZx.cjs → slice-7G2xxYKJ.cjs} +3 -3
- package/dist/{slice-DZmQJNV8.cjs → slice-B4CdYoPu.cjs} +2 -2
- package/dist/slice-BPNuHKfw.js +9091 -0
- package/dist/{slice-DGcNrbPR.cjs → slice-Bg6HEr3K.cjs} +4 -4
- package/dist/{slice-DtaO72qY.cjs → slice-Bs2aMERu.cjs} +3 -3
- package/dist/{slice-HeHCv3bl.cjs → slice-C34iOOUH.cjs} +7 -7
- package/dist/{slice-Do2R2CYW.cjs → slice-C9TT5KhY.cjs} +6 -6
- package/dist/{slice-eIwcwKHI.js → slice-CK07EBCo.js} +4 -4
- package/dist/{slice-CnyWevM9.js → slice-CU80pbiu.js} +3 -3
- package/dist/{slice-CobanYgn.js → slice-CwyYrh1H.js} +2 -2
- package/dist/slice-Czfp6t84.cjs +436 -0
- package/dist/{slice-d0p6-xj5.js → slice-D-9aPKG-.js} +6 -6
- package/dist/{slice-maaskdUn.js → slice-DBpJ2QGf.js} +6 -6
- package/dist/{slice-mxLQ_FeY.cjs → slice-DTZTiJle.cjs} +352 -39
- package/dist/{slice-zJ9XVYjZ.js → slice-Da426sf9.js} +1 -1
- package/dist/{slice-D11m2EKl.cjs → slice-DayJvMRD.cjs} +1 -1
- package/dist/slice-DnBWfA-k.cjs +9109 -0
- package/dist/{slice-oqm_r1cS.cjs → slice-DnG-yvpI.cjs} +2 -2
- package/dist/{slice-BNu73oBa.js → slice-DyNs7oWp.js} +2 -2
- package/dist/{slice-CB4SnzMm.js → slice-GwiiJRoq.js} +3 -3
- package/dist/slice-oWnc7YVD.js +412 -0
- package/dist/{slice-B2PhoWAg.js → slice-qt0uBExh.js} +325 -37
- package/dist/slice-t8Gzj55G2.cjs +106 -0
- package/dist/slice-t8Q1cHm-.js +88 -0
- package/dist/src-BDzYIksE.cjs +20637 -0
- package/dist/src-BFoefPv_.js +20755 -0
- package/dist/store-B1Lq3cEf.cjs +66 -0
- package/dist/store-DuBG8qh5.js +37 -0
- package/dist/submit-Bs77dPn_.cjs +413 -0
- package/dist/submit-DOv8Z0Vf.js +336 -0
- package/dist/submit-bitcoin-tx-D6oYgH5S.js +983 -0
- package/dist/submit-bitcoin-tx-goFuRL7K.cjs +1049 -0
- package/dist/{sync-operation-utils-BYXLO80m.js → sync-operation-utils-31iFLExW.js} +2 -38
- package/dist/{sync-operation-utils-SdPbwFoD.cjs → sync-operation-utils-COIZ66-I.cjs} +1 -67
- package/dist/token-id-mapper-Bnds3xKH.cjs +18 -0
- package/dist/{token-id-mapper-DsPAL6Nh.cjs → token-id-mapper-CVyQJUKY.cjs} +2 -2
- package/dist/token-id-mapper-CnKHQ8DV.js +16 -0
- package/dist/{token-id-mapper-B2ivlLv3.js → token-id-mapper-D29Ggv8h.js} +2 -2
- package/dist/tokens-Cevp7rdU.cjs +62 -0
- package/dist/tokens-Diw4MLRM.js +44 -0
- package/dist/types-B8uiJn-X.js +12 -0
- package/dist/types-BHC12eSa.js +33 -0
- package/dist/types-CJT6XF2c.js +10 -0
- package/dist/types-CLRUYpfe.cjs +23 -0
- package/dist/types-Cc3mC8u0.cjs +50 -0
- package/dist/types-DWbVZpnF.cjs +15 -0
- package/dist/unwrap-provider-result-BZSiwabU.js +32 -0
- package/dist/unwrap-provider-result-ZqfBsTkk.cjs +39 -0
- package/dist/{util-CGzqQ8IV.cjs → util-Bu4W5lF4.cjs} +1 -1
- package/dist/{util-BaLzwa32.js → util-Cp5cZkfK.js} +1 -1
- package/dist/{utils-o8aMjfln.js → utils-BfBEUvWA.js} +2 -2
- package/dist/utils-DFwzEvbv.js +65 -0
- package/dist/{utils-5JvjbqH3.cjs → utils-DsElZgCI.cjs} +7 -1
- package/dist/utils-IXxR-Djh.cjs +112 -0
- package/dist/v8Signatures-CO_Uloy7.cjs +71 -0
- package/dist/{vote-delegation-tx-builder-CmKv6GoG.js → vote-delegation-tx-builder-BsBSDmcX.js} +5 -5
- package/dist/{vote-delegation-tx-builder-BpEMSti4.cjs → vote-delegation-tx-builder-DSs8nybk.cjs} +6 -6
- package/dist/watch-CUEvcP-V.js +21997 -0
- package/dist/watch-DMF2s-II.cjs +52281 -0
- package/package.json +96 -4
- package/dist/account-guards.stable-B1DSSh9D.cjs +0 -10
- package/dist/account-guards.stable-JRQ5qx2V.js +0 -5
- package/dist/codecs-B7X9pAsK.cjs +0 -1945
- package/dist/codecs-CC1Xjntz.js +0 -1882
- package/dist/init-Bv53hpLM.js +0 -19
- package/dist/init-CRbjI7p1.js +0 -3494
- package/dist/init-DAna1KCg.cjs +0 -3495
- package/dist/init-DGe47B22.cjs +0 -364
- package/dist/init-DMtyvYfC.cjs +0 -21
- package/dist/init-TkPDD750.js +0 -363
- package/dist/modules-cardano-BDvuL4Xx.js +0 -5248
- package/dist/modules-cardano-D2G3De2P.cjs +0 -5432
- package/dist/slice-CGVHXHDt.cjs +0 -125
- package/dist/slice-DhvF7L6X.js +0 -107
- /package/dist/{account-id.vo-LvCBVn5r.cjs → account-id.vo-DwqFjK5u.cjs} +0 -0
- /package/dist/{account-id.vo-MYSI7YFm.js → account-id.vo-OPz2v-JZ.js} +0 -0
- /package/dist/{actions-DdGbj7c7.cjs → actions-B2BJ4RTy.cjs} +0 -0
- /package/dist/{actions-9QSQR-GB.js → actions-iLXdgL5Y.js} +0 -0
- /package/dist/{apply-vkey-witnesses-ClZbpk5w.js → apply-vkey-witnesses-BKx3lcs0.js} +0 -0
- /package/dist/{apply-vkey-witnesses-CLzVSWxl.cjs → apply-vkey-witnesses-ZnFS0jnJ.cjs} +0 -0
- /package/dist/{asyncoption-Cw07zPH7.js → asyncoption-CruEYOBI.js} +0 -0
- /package/dist/{asyncoption-DYoGuQfP.cjs → asyncoption-i0VbqVTq.cjs} +0 -0
- /package/dist/{bignum.vo-B0rK_PQ1.js → bignum.vo-CEXOIew0.js} +0 -0
- /package/dist/{bignum.vo-DsG3kNiZ.cjs → bignum.vo-hx2kuqlA.cjs} +0 -0
- /package/dist/{bip32ed25519-1ApqeAZk.cjs → bip32ed25519-B7Yat217.cjs} +0 -0
- /package/dist/{bip32ed25519-DetAdGwD.js → bip32ed25519-FQ8qvdcq.js} +0 -0
- /package/dist/{blake2b-DOEVc57D.js → blake2b-BiQTw3GC.js} +0 -0
- /package/dist/{blake2b-B9tftbvG.cjs → blake2b-DEeVUdKR.cjs} +0 -0
- /package/dist/{blockchain-network-id.vo-BXpZhvvQ.cjs → blockchain-network-id.vo-BAKEwGjG.cjs} +0 -0
- /package/dist/{blockchain-network-id.vo-DNRkuT5B.js → blockchain-network-id.vo-CiVykuqG.js} +0 -0
- /package/dist/{blockingWithLatestFrom-C5wp_uA-.js → blockingWithLatestFrom-Cd8c8EPG.js} +0 -0
- /package/dist/{blockingWithLatestFrom-DY8OPg0w.cjs → blockingWithLatestFrom-D8kBPBMX.cjs} +0 -0
- /package/dist/{cardano-network-id-to-network-type-CrZfUcyP.js → cardano-network-id-to-network-type-BWwzeEtM.js} +0 -0
- /package/dist/{cardano-network-id-to-network-type-BDTF-HmK.cjs → cardano-network-id-to-network-type-C0ufJOyE.cjs} +0 -0
- /package/dist/{cardano-tx-id.vo-BPhV-AmZ.cjs → cardano-tx-id.vo-TLjJZHCI.cjs} +0 -0
- /package/dist/{cardano-tx-id.vo-DF9NzZXk.js → cardano-tx-id.vo-eVnKuzlm.js} +0 -0
- /package/dist/{composite-signer-factory-_46QsNBz.js → composite-signer-factory-CR8YHA1y.js} +0 -0
- /package/dist/{composite-signer-factory-BpF1mIYA.cjs → composite-signer-factory-m5cVs9h_.cjs} +0 -0
- /package/dist/{error-CNIquqT5.cjs → error-Cb3EnD0u.cjs} +0 -0
- /package/dist/{error-BCp9NkPi.js → error-DIZOY2Lw.js} +0 -0
- /package/dist/{esm-browser-C93Q-EOI.js → esm-browser-MG97cre9.js} +0 -0
- /package/dist/{esm-browser-DTc9IK3D.cjs → esm-browser-bweqfBlL.cjs} +0 -0
- /package/dist/{feature-flag-key.vo-ofrB6ZVQ.js → feature-flag-key.vo-DN_-4-sG.js} +0 -0
- /package/dist/{feature-flag-key.vo-BPz-ZAp6.cjs → feature-flag-key.vo-RlfHL3hq.cjs} +0 -0
- /package/dist/{first-state-of-status-OROkXcRv.cjs → first-state-of-status-CbT7hPa4.cjs} +0 -0
- /package/dist/{first-state-of-status-DQnMT3ya.js → first-state-of-status-unPynOuM.js} +0 -0
- /package/dist/{init-Es3wHW7D.js → init-829HRYcz.js} +0 -0
- /package/dist/{init-CKipPE_c.js → init-A-VyGSNW2.js} +0 -0
- /package/dist/{init-DFQQ9dTW.cjs → init-Atisw4x2.cjs} +0 -0
- /package/dist/{init-C5CEZ1m0.cjs → init-BFcvPHL-.cjs} +0 -0
- /package/dist/{init-IAk_CkGa.cjs → init-BgNobbNq.cjs} +0 -0
- /package/dist/{init-cqN3uX2j.js → init-atCFur0v.js} +0 -0
- /package/dist/{is-redux-persist-state-CTn3WZVh.cjs → is-redux-persist-state-BCFnSm36.cjs} +0 -0
- /package/dist/{is-redux-persist-state-Cxcd0_bM.js → is-redux-persist-state-yBfq0h_E.js} +0 -0
- /package/dist/{key-value-store-8cMzeNyG.js → key-value-store--W3SrMaw.js} +0 -0
- /package/dist/{key-value-store-DUAepXQf.cjs → key-value-store-C2Xt5Emp.cjs} +0 -0
- /package/dist/{repo-slice-WxetRhMY.cjs → repo-slice-7X4AYYVm.cjs} +0 -0
- /package/dist/{repo-slice-DwyMhCR1.js → repo-slice-RxFm0zDZ.js} +0 -0
- /package/dist/{reselect-CRDqmQY9.cjs → reselect-Bd94u0K-.cjs} +0 -0
- /package/dist/{reselect-C06X06oX.js → reselect-CGoLzEPv.js} +0 -0
- /package/dist/{serializable-B8GahgE1.js → serializable-BHdKIgk3.js} +0 -0
- /package/dist/{serializable-CRdnFaLZ.cjs → serializable-BxHkoPdk.cjs} +0 -0
- /package/dist/{slice-D11FHQuQ.cjs → slice-BiRsDKOK.cjs} +0 -0
- /package/dist/{slice-Be7hj4Iy.js → slice-Bk0Sv05J.js} +0 -0
- /package/dist/{slice-FioKeHtA.cjs → slice-Dqw1ecum.cjs} +0 -0
- /package/dist/{slice-B87b52iM.js → slice-obCSLm1x.js} +0 -0
- /package/dist/{src-vq1wS9sZ.js → src-BlxEp6Mm.js} +0 -0
- /package/dist/{src-BTPIvlDI.cjs → src-Cqp0B2M_.cjs} +0 -0
- /package/dist/{time.vo-CQ8pSXz2.cjs → time.vo-D3wWRw9L.cjs} +0 -0
- /package/dist/{time.vo-DkYYGYp6.js → time.vo-tNheinXm.js} +0 -0
- /package/dist/{toEmpty-CgAl3097.js → toEmpty-8Zax1MPd.js} +0 -0
- /package/dist/{toEmpty-DAMmNB5r.cjs → toEmpty-CYAbupM4.cjs} +0 -0
- /package/dist/{token-id.vo-ClsroxHO.js → token-id.vo-Bvwhr3ZE.js} +0 -0
- /package/dist/{token-id.vo-BxG9TG0O.cjs → token-id.vo-DXv5uS9n.cjs} +0 -0
- /package/dist/{util-DxzlYNS5.js → util-C8a4fA9p.js} +0 -0
- /package/dist/{util-CmdAhheh.cjs → util-CzeB3hfa.cjs} +0 -0
- /package/dist/{util-selector-CcK-GAdE.js → util-selector-BSTsxgne.js} +0 -0
- /package/dist/{util-selector-BcAncU4L.cjs → util-selector-BWPH68_l.cjs} +0 -0
- /package/dist/{while-active-BpppWuCs.js → while-active-B0lWy_6l.js} +0 -0
- /package/dist/{while-active-Dhc2LwOm.cjs → while-active-Dsowp0Fi.cjs} +0 -0
|
@@ -0,0 +1,4138 @@
|
|
|
1
|
+
import "./_web-crypto-random-bytes-Bo-GTcRS.js";
|
|
2
|
+
import "./_polyfill-buffer-patch-yNxN4d5E.js";
|
|
3
|
+
import "./libsodium-wrappers-BhbOA8dQ.js";
|
|
4
|
+
import "./codecs-Dc1Krpbt.js";
|
|
5
|
+
import { n as HexBytes } from "./bytes.vo-BB7_4JK6.js";
|
|
6
|
+
import { r as Milliseconds, s as Timestamp } from "./time.vo-tNheinXm.js";
|
|
7
|
+
import { t as BigNumber } from "./bignum.vo-CEXOIew0.js";
|
|
8
|
+
import { t as autoDismissFailureOnSuccess } from "./auto-dismiss-failure-on-success-s8MGDEIu.js";
|
|
9
|
+
import "./retry-config-Dmgt28wM.js";
|
|
10
|
+
import { t as ActivityType } from "./activity-type-GsJGWs-3.js";
|
|
11
|
+
import { t as TokenId } from "./token-id.vo-Bvwhr3ZE.js";
|
|
12
|
+
import { t as AuthenticationCancelledError } from "./types-CJT6XF2c.js";
|
|
13
|
+
import { g as MidnightNetworkId, l as MidnightSDKTestNetworkId, x as getProofServerEndpoint, y as assertProofServerRouting } from "./const-D0CbQlo4.js";
|
|
14
|
+
import { n as midnightContextActions } from "./slice-oWnc7YVD.js";
|
|
15
|
+
import { c as toUnshieldedTokenType, o as hasMidnightAccount, s as isInMemoryMidnightAccount, t as convertHttpUrlToWebsocket } from "./utils-DFwzEvbv.js";
|
|
16
|
+
import { t as midnightWalletsForRuntime } from "./midnight-wallet-DIsAlSn6.js";
|
|
17
|
+
import { $ as makeSemaphore, $c as appendAll, $l as match$10, $o as all$2, Aa as interruptAs$1, Ac as void_$4, Al as unsafeGet$2, Au as FEATURE_FLAG_MIDNIGHT_SHIELDED_ACTIVITY_ROWS, B as flatten$6, Ba as fork, Bc as set$2, Cl as splitAt$1, Ct as runSync$1, D as dieMessage$2, Da as _await$1, Du as identity$2, Ec as sync$7, Es as catchAll$6, Eu as dual, Fa as Scope, Ga as die$7, Gc as size$8, Gl as splitAt, Go as capacity$8, Gs as deferredMake, Gt as zipRight$8, Ht as withFiberRuntime$1, Ia as addFinalizer$1, Io as update$1, Is as currentSchedulingPriority$1, J as ignoreLogged, Jl as getOrElse, Jo as offer$5, Js as deferredUnsafeMake, K as gen, Ka as fail$8, Ko as isEmpty$9, Ks as deferredSucceed, Kt as zipWith$7, L as fiberIdWith, La as addFinalizerExit, Lc as combineAll, M as exit, Mc as withFiberRuntime, Ml as unsafeLast, Mt as sync$8, N as fail$10, Nc as zipRight$6, No as make$18, Nt as tap$7, Oa as inheritAll, Oc as uninterruptible, Os as currentContext$1, Ot as scopedWith$3, Ou as pipe, P as failCause$8, Pc as SingleShotGen, Po as modify$1, Pt as tapErrorCause$4, Q as isEffect, Qa as isInterrupted, Qc as append, Qo as unbounded$8, Ra as close, Rc as get$4, Ro as Class, Rt as uninterruptible$1, S as catchAllCause$5, Sc as onInterrupt, St as runPromise$1, Tc as suspend$8, To as sequential$1, Ts as asVoid$1, Tt as scope$2, Tu as constVoid, U as forkDaemon, Ua as NoSuchElementException, Ul as fromIterable$2, Uo as EmptyMutableQueue, Us as deferredAwait, Ut as zip$4, V as forEach$2, Va as make$19, Vl as empty$4, Vt as when$2, W as forkIn, Wo as bounded$8, Ws as deferredInterruptWith, Wt as zipLeft$4, X as interruptible, Xa as interruptors, Xl as isNone, Xo as poll$4, Y as interrupt$4, Ya as interrupt$3, Yo as offerAll$4, Z as intoDeferred, Za as isDieType, Zl as isSome, Zo as pollUpTo, Zs as fiberId, _c as flatMap$7, _o as forEachParUnbounded, _s as isDone$1, _u as YieldWrap, as as isFailure, at as matchCause$2, au as right, b as cached$1, bs as succeed$11, bt as repeat$3, c as createProofServerAccess, cu as OP_COMMIT, d as EffectTypeId, ds as void_$5, du as symbol$1, el as drop$2, es as die$6, eu as none, f as _void, fl as isEmpty$8, fs as zip$5, fu as cached, g as as$5, gl as map$13, go as forEachConcurrentDiscard, gs as failCause$9, gt as race$3, gu as symbol, h as all$3, hu as random, i as MidnightSyncFailureId, it as match$11, iu as match$8, j as ensuring$5, ja as join, jc as whenEffect$2, jo as get$5, jt as suspend$9, ka as interrupt$2, kt as succeed$10, ll as fromIterable$3, ls as match$9, lu as pipeArguments, m as acquireUseRelease$1, ms as _await, mt as provideService$6, mu as hash, n as watchMidnightAccount, nl as empty$5, ns as failCause$7, nu as some$2, o as createAttestedProofServerAccess, ol as findFirst, os as isSuccess$1, ot as matchCauseEffect, ou as StreamTypeId$2, pl as isNonEmpty, ps as zipRight$7, pt as provide$2, pu as combine$2, q as ignore, qa as failureOrCause, qo as length, qs as deferredUnsafeDone, r as watchMidnightAccounts, rl as filter$3, rs as interrupt$5, rt as mapError$5, ru as left, s as createHttpProofServerTransport, ss as map$11, su as effectVariance, to as map$12, ts as fail$9, tt as map$10, u as createScopedProofServerAccess, us as succeed$9, uu as equals, v as asVoid$2, vc as interrupt$1, vl as of$2, vs as make$17, vt as raceWith$1, vu as internalCall, wc as succeed$8, wo as currentScheduler$1, wt as runtime, x as catchAll$7, xc as map$9, xl as reduce$2, y as async, yl as prepend$2, yu as hasProperty, z as flatMap$8, za as extend, zc as make$16, zl as unsafeGet$3, zt as uninterruptibleMask } from "./watch-CUEvcP-V.js";
|
|
18
|
+
import { n as teeAttestationProgress$ } from "./send-proof-progress-C-ljq1x5.js";
|
|
19
|
+
import { Percent, deepEquals } from "@laceio/cardano/util";
|
|
20
|
+
import { EMPTY, Observable, catchError, combineLatest, concat, defaultIfEmpty, defer, distinctUntilChanged, exhaustMap, filter, firstValueFrom, forkJoin, from, groupBy, ignoreElements, map, merge, mergeMap, of, scan, shareReplay, switchMap, take, takeUntil, tap, throttleTime, throwError, throwIfEmpty, withLatestFrom, zip } from "rxjs";
|
|
21
|
+
import isEqual from "lodash/isEqual.js";
|
|
22
|
+
import { SerializedTransaction } from "@midnightntwrk/wallet-sdk-abstractions";
|
|
23
|
+
import { DustAddress, ShieldedAddress, UnshieldedAddress } from "@midnightntwrk/wallet-sdk-address-format";
|
|
24
|
+
import * as ledger from "@midnight-ntwrk/ledger-v8";
|
|
25
|
+
import { PublicKey, UnshieldedWallet } from "@midnightntwrk/wallet-sdk/unshielded";
|
|
26
|
+
import { SubmissionError } from "@midnightntwrk/wallet-sdk/capabilities/submission";
|
|
27
|
+
import { NodeClientError, PolkadotNodeClient } from "@midnightntwrk/wallet-sdk/node-client/effect";
|
|
28
|
+
import { InMemoryTransactionHistoryStorage, WalletEntrySchema, mergeWalletEntries } from "@midnightntwrk/wallet-sdk";
|
|
29
|
+
import { DustWallet } from "@midnightntwrk/wallet-sdk/dust";
|
|
30
|
+
import { WalletFacade } from "@midnightntwrk/wallet-sdk/facade";
|
|
31
|
+
import { ShieldedWallet } from "@midnightntwrk/wallet-sdk/shielded";
|
|
32
|
+
//#region ../../packages/contract/midnight-context/src/value-objects/midnight-address.vo.ts
|
|
33
|
+
const MidnightShieldedAddress = (address) => address;
|
|
34
|
+
const MidnightUnshieldedAddress = (address) => address;
|
|
35
|
+
const MidnightDustAddress = (address) => address;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region ../../packages/contract/midnight-context/src/value-objects/serialised-wallet-state.vo.ts
|
|
38
|
+
/**
|
|
39
|
+
* Either encoding. Production only ever constructs this from the SDK's
|
|
40
|
+
* verbatim JSON; the hex form comes back from storage on older profiles.
|
|
41
|
+
*/
|
|
42
|
+
const SerialisedWalletState = (value) => value;
|
|
43
|
+
/**
|
|
44
|
+
* A heuristic over the values we actually persist, not a parse: hex and JSON
|
|
45
|
+
* overlap (`12345678` is both), so nothing can separate them in general. Every
|
|
46
|
+
* blob written here opens with `{`; `[` is headroom for a serialiser that
|
|
47
|
+
* returns a top-level array. Anything else reads as hex, and a wrong guess
|
|
48
|
+
* costs a rebuild from seed, which the restore path already handles.
|
|
49
|
+
*
|
|
50
|
+
* First character only: matching hex across the whole payload cost ~2500ms
|
|
51
|
+
* against 10k documents of 100k characters, against ~8ms here, and was
|
|
52
|
+
* case-sensitive so it missed uppercase hex besides.
|
|
53
|
+
*/
|
|
54
|
+
const isVerbatimJson = (value) => value.startsWith("{") || value.startsWith("[");
|
|
55
|
+
SerialisedWalletState.toJSON = (value) => isVerbatimJson(value) ? value : HexBytes.toUTF8(value);
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region ../../packages/contract/midnight-context/src/midnight-accounts.ts
|
|
58
|
+
/** Two account lists are the same run of accounts when their ids line up in
|
|
59
|
+
* order — the identity the account stream re-emits on. */
|
|
60
|
+
const sameAccounts = (accounts1, accounts2) => {
|
|
61
|
+
if (accounts1.length !== accounts2.length) return false;
|
|
62
|
+
for (let index = 0; index < accounts1.length; index++) if (accounts1[index].accountId !== accounts2[index].accountId) return false;
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The in-memory Midnight accounts on the active Midnight network, as a stream
|
|
67
|
+
* that only re-emits when the run of account ids actually changes. Emits an
|
|
68
|
+
* empty list while the wallet repo is migrating, so a consumer never acts on a
|
|
69
|
+
* half-migrated repo. Nothing is emitted until a Midnight network is registered.
|
|
70
|
+
*/
|
|
71
|
+
const midnightAccounts$ = (state) => combineLatest([
|
|
72
|
+
state.wallets.selectActiveNetworkAccounts$,
|
|
73
|
+
state.midnightContext.selectMidnightBlockchainNetworkId$.pipe(filter(Boolean)),
|
|
74
|
+
state.wallets.selectIsWalletRepoMigrating$
|
|
75
|
+
]).pipe(map(([accounts, activeNetwork, isWalletRepoMigrating]) => isWalletRepoMigrating ? [] : accounts.filter(isInMemoryMidnightAccount).filter((account) => account.blockchainNetworkId === activeNetwork)), distinctUntilChanged(sameAccounts));
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region ../../packages/contract/midnight-context/src/register-midnight-blockchain-networks.ts
|
|
78
|
+
/**
|
|
79
|
+
* Registers the Midnight networks with the global network store once, the
|
|
80
|
+
* first time it reports Midnight absent. Every loadout with Midnight accounts
|
|
81
|
+
* needs this: `wallets.selectActiveNetworkAccounts` drops the accounts of an
|
|
82
|
+
* unregistered blockchain. The registration lands a tick after this decides,
|
|
83
|
+
* so it sets the networks only while Midnight still has none: a network the
|
|
84
|
+
* consumer selected in between keeps precedence.
|
|
85
|
+
*
|
|
86
|
+
* An existing Midnight account pins the testnet selection to its own network,
|
|
87
|
+
* so a profile created before the network store existed keeps syncing where
|
|
88
|
+
* its account lives; otherwise the default testnet is selected.
|
|
89
|
+
*/
|
|
90
|
+
const registerMidnightBlockchainNetworks = (_, { network: { selectBlockchainNetworks$ }, midnightContext: { selectDefaultTestNetNetworkId$ }, wallets: { selectAll$ } }, { actions }) => selectBlockchainNetworks$.pipe(filter((blockchainNetworks) => !blockchainNetworks?.Midnight), withLatestFrom(selectDefaultTestNetNetworkId$, selectAll$.pipe(map((allWallets) => allWallets.flatMap((wallet) => wallet.accounts)))), map(([, defaultTestNetNetworkId, accounts]) => {
|
|
91
|
+
const existingMidnightAccount = accounts.find((account) => account.blockchainName === "Midnight");
|
|
92
|
+
const testnetNetworkId = existingMidnightAccount ? existingMidnightAccount.blockchainSpecific.networkId : defaultTestNetNetworkId;
|
|
93
|
+
return actions.network.registerBlockchainNetworks({
|
|
94
|
+
blockchain: "Midnight",
|
|
95
|
+
mainnet: MidnightNetworkId("mainnet"),
|
|
96
|
+
testnet: MidnightNetworkId(testnetNetworkId)
|
|
97
|
+
});
|
|
98
|
+
}));
|
|
99
|
+
/**
|
|
100
|
+
* @since 2.0.0
|
|
101
|
+
* @category fiberRefs
|
|
102
|
+
*/
|
|
103
|
+
const currentContext = currentContext$1;
|
|
104
|
+
/**
|
|
105
|
+
* @since 2.0.0
|
|
106
|
+
* @category fiberRefs
|
|
107
|
+
*/
|
|
108
|
+
const currentSchedulingPriority = currentSchedulingPriority$1;
|
|
109
|
+
/**
|
|
110
|
+
* @since 2.0.0
|
|
111
|
+
* @category fiberRefs
|
|
112
|
+
*/
|
|
113
|
+
const currentScheduler = currentScheduler$1;
|
|
114
|
+
/** @internal */
|
|
115
|
+
const EnqueueTypeId$1 = /* @__PURE__ */ Symbol.for("effect/QueueEnqueue");
|
|
116
|
+
/** @internal */
|
|
117
|
+
const DequeueTypeId$1 = /* @__PURE__ */ Symbol.for("effect/QueueDequeue");
|
|
118
|
+
/** @internal */
|
|
119
|
+
const QueueStrategyTypeId$1 = /* @__PURE__ */ Symbol.for("effect/QueueStrategy");
|
|
120
|
+
/** @internal */
|
|
121
|
+
const BackingQueueTypeId$1 = /* @__PURE__ */ Symbol.for("effect/BackingQueue");
|
|
122
|
+
const queueStrategyVariance = { _A: (_) => _ };
|
|
123
|
+
const backingQueueVariance = { _A: (_) => _ };
|
|
124
|
+
/** @internal */
|
|
125
|
+
const enqueueVariance = { _In: (_) => _ };
|
|
126
|
+
/** @internal */
|
|
127
|
+
const dequeueVariance = { _Out: (_) => _ };
|
|
128
|
+
/** @internal */
|
|
129
|
+
var QueueImpl = class extends Class {
|
|
130
|
+
queue;
|
|
131
|
+
takers;
|
|
132
|
+
shutdownHook;
|
|
133
|
+
shutdownFlag;
|
|
134
|
+
strategy;
|
|
135
|
+
[EnqueueTypeId$1] = enqueueVariance;
|
|
136
|
+
[DequeueTypeId$1] = dequeueVariance;
|
|
137
|
+
constructor(queue, takers, shutdownHook, shutdownFlag, strategy) {
|
|
138
|
+
super();
|
|
139
|
+
this.queue = queue;
|
|
140
|
+
this.takers = takers;
|
|
141
|
+
this.shutdownHook = shutdownHook;
|
|
142
|
+
this.shutdownFlag = shutdownFlag;
|
|
143
|
+
this.strategy = strategy;
|
|
144
|
+
}
|
|
145
|
+
pipe() {
|
|
146
|
+
return pipeArguments(this, arguments);
|
|
147
|
+
}
|
|
148
|
+
commit() {
|
|
149
|
+
return this.take;
|
|
150
|
+
}
|
|
151
|
+
capacity() {
|
|
152
|
+
return this.queue.capacity();
|
|
153
|
+
}
|
|
154
|
+
get size() {
|
|
155
|
+
return suspend$8(() => catchAll$6(this.unsafeSize(), () => interrupt$1));
|
|
156
|
+
}
|
|
157
|
+
unsafeSize() {
|
|
158
|
+
if (get$4(this.shutdownFlag)) return none();
|
|
159
|
+
return some$2(this.queue.length() - length(this.takers) + this.strategy.surplusSize());
|
|
160
|
+
}
|
|
161
|
+
get isEmpty() {
|
|
162
|
+
return map$9(this.size, (size) => size <= 0);
|
|
163
|
+
}
|
|
164
|
+
get isFull() {
|
|
165
|
+
return map$9(this.size, (size) => size >= this.capacity());
|
|
166
|
+
}
|
|
167
|
+
get shutdown() {
|
|
168
|
+
return uninterruptible(withFiberRuntime((state) => {
|
|
169
|
+
pipe(this.shutdownFlag, set$2(true));
|
|
170
|
+
return pipe(forEachConcurrentDiscard(unsafePollAll(this.takers), (d) => deferredInterruptWith(d, state.id()), false, false), zipRight$6(this.strategy.shutdown), whenEffect$2(deferredSucceed(this.shutdownHook, void 0)), asVoid$1);
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
get isShutdown() {
|
|
174
|
+
return sync$7(() => get$4(this.shutdownFlag));
|
|
175
|
+
}
|
|
176
|
+
get awaitShutdown() {
|
|
177
|
+
return deferredAwait(this.shutdownHook);
|
|
178
|
+
}
|
|
179
|
+
isActive() {
|
|
180
|
+
return !get$4(this.shutdownFlag);
|
|
181
|
+
}
|
|
182
|
+
unsafeOffer(value) {
|
|
183
|
+
if (get$4(this.shutdownFlag)) return false;
|
|
184
|
+
let noRemaining;
|
|
185
|
+
if (this.queue.length() === 0) {
|
|
186
|
+
const taker = pipe(this.takers, poll$4(EmptyMutableQueue));
|
|
187
|
+
if (taker !== EmptyMutableQueue) {
|
|
188
|
+
unsafeCompleteDeferred$1(taker, value);
|
|
189
|
+
noRemaining = true;
|
|
190
|
+
} else noRemaining = false;
|
|
191
|
+
} else noRemaining = false;
|
|
192
|
+
if (noRemaining) return true;
|
|
193
|
+
const succeeded = this.queue.offer(value);
|
|
194
|
+
unsafeCompleteTakers(this.strategy, this.queue, this.takers);
|
|
195
|
+
return succeeded;
|
|
196
|
+
}
|
|
197
|
+
offer(value) {
|
|
198
|
+
return suspend$8(() => {
|
|
199
|
+
if (get$4(this.shutdownFlag)) return interrupt$1;
|
|
200
|
+
let noRemaining;
|
|
201
|
+
if (this.queue.length() === 0) {
|
|
202
|
+
const taker = pipe(this.takers, poll$4(EmptyMutableQueue));
|
|
203
|
+
if (taker !== EmptyMutableQueue) {
|
|
204
|
+
unsafeCompleteDeferred$1(taker, value);
|
|
205
|
+
noRemaining = true;
|
|
206
|
+
} else noRemaining = false;
|
|
207
|
+
} else noRemaining = false;
|
|
208
|
+
if (noRemaining) return succeed$8(true);
|
|
209
|
+
const succeeded = this.queue.offer(value);
|
|
210
|
+
unsafeCompleteTakers(this.strategy, this.queue, this.takers);
|
|
211
|
+
return succeeded ? succeed$8(true) : this.strategy.handleSurplus([value], this.queue, this.takers, this.shutdownFlag);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
offerAll(iterable) {
|
|
215
|
+
return suspend$8(() => {
|
|
216
|
+
if (get$4(this.shutdownFlag)) return interrupt$1;
|
|
217
|
+
const values = fromIterable$2(iterable);
|
|
218
|
+
const pTakers = this.queue.length() === 0 ? fromIterable$2(unsafePollN$1(this.takers, values.length)) : empty$4;
|
|
219
|
+
const [forTakers, remaining] = pipe(values, splitAt(pTakers.length));
|
|
220
|
+
for (let i = 0; i < pTakers.length; i++) {
|
|
221
|
+
const taker = pTakers[i];
|
|
222
|
+
const item = forTakers[i];
|
|
223
|
+
unsafeCompleteDeferred$1(taker, item);
|
|
224
|
+
}
|
|
225
|
+
if (remaining.length === 0) return succeed$8(true);
|
|
226
|
+
const surplus = this.queue.offerAll(remaining);
|
|
227
|
+
unsafeCompleteTakers(this.strategy, this.queue, this.takers);
|
|
228
|
+
return isEmpty$8(surplus) ? succeed$8(true) : this.strategy.handleSurplus(surplus, this.queue, this.takers, this.shutdownFlag);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
get take() {
|
|
232
|
+
return withFiberRuntime((state) => {
|
|
233
|
+
if (get$4(this.shutdownFlag)) return interrupt$1;
|
|
234
|
+
const item = this.queue.poll(EmptyMutableQueue);
|
|
235
|
+
if (item !== EmptyMutableQueue) {
|
|
236
|
+
this.strategy.unsafeOnQueueEmptySpace(this.queue, this.takers);
|
|
237
|
+
return succeed$8(item);
|
|
238
|
+
} else {
|
|
239
|
+
const deferred = deferredUnsafeMake(state.id());
|
|
240
|
+
return pipe(suspend$8(() => {
|
|
241
|
+
pipe(this.takers, offer$5(deferred));
|
|
242
|
+
unsafeCompleteTakers(this.strategy, this.queue, this.takers);
|
|
243
|
+
return get$4(this.shutdownFlag) ? interrupt$1 : deferredAwait(deferred);
|
|
244
|
+
}), onInterrupt(() => {
|
|
245
|
+
return sync$7(() => unsafeRemove$1(this.takers, deferred));
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
get takeAll() {
|
|
251
|
+
return suspend$8(() => {
|
|
252
|
+
return get$4(this.shutdownFlag) ? interrupt$1 : sync$7(() => {
|
|
253
|
+
const values = this.queue.pollUpTo(Number.POSITIVE_INFINITY);
|
|
254
|
+
this.strategy.unsafeOnQueueEmptySpace(this.queue, this.takers);
|
|
255
|
+
return fromIterable$3(values);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
takeUpTo(max) {
|
|
260
|
+
return suspend$8(() => get$4(this.shutdownFlag) ? interrupt$1 : sync$7(() => {
|
|
261
|
+
const values = this.queue.pollUpTo(max);
|
|
262
|
+
this.strategy.unsafeOnQueueEmptySpace(this.queue, this.takers);
|
|
263
|
+
return fromIterable$3(values);
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
takeBetween(min, max) {
|
|
267
|
+
return suspend$8(() => takeRemainderLoop$1(this, min, max, empty$5()));
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
/** @internal */
|
|
271
|
+
const takeRemainderLoop$1 = (self, min, max, acc) => {
|
|
272
|
+
if (max < min) return succeed$8(acc);
|
|
273
|
+
return pipe(takeUpTo$3(self, max), flatMap$7((bs) => {
|
|
274
|
+
const remaining = min - bs.length;
|
|
275
|
+
if (remaining === 1) return pipe(take$7(self), map$9((b) => pipe(acc, appendAll(bs), append(b))));
|
|
276
|
+
if (remaining > 1) return pipe(take$7(self), flatMap$7((b) => takeRemainderLoop$1(self, remaining - 1, max - bs.length - 1, pipe(acc, appendAll(bs), append(b)))));
|
|
277
|
+
return succeed$8(pipe(acc, appendAll(bs)));
|
|
278
|
+
}));
|
|
279
|
+
};
|
|
280
|
+
/** @internal */
|
|
281
|
+
const bounded$7 = (requestedCapacity) => pipe(sync$7(() => bounded$8(requestedCapacity)), flatMap$7((queue) => make$13(backingQueueFromMutableQueue(queue), backPressureStrategy$1())));
|
|
282
|
+
/** @internal */
|
|
283
|
+
const unbounded$7 = () => pipe(sync$7(() => unbounded$8()), flatMap$7((queue) => make$13(backingQueueFromMutableQueue(queue), droppingStrategy$1())));
|
|
284
|
+
/** @internal */
|
|
285
|
+
const unsafeMake = (queue, takers, shutdownHook, shutdownFlag, strategy) => {
|
|
286
|
+
return new QueueImpl(queue, takers, shutdownHook, shutdownFlag, strategy);
|
|
287
|
+
};
|
|
288
|
+
/** @internal */
|
|
289
|
+
const make$13 = (queue, strategy) => pipe(deferredMake(), map$9((deferred) => unsafeMake(queue, unbounded$8(), deferred, make$16(false), strategy)));
|
|
290
|
+
/** @internal */
|
|
291
|
+
var BackingQueueFromMutableQueue = class {
|
|
292
|
+
mutable;
|
|
293
|
+
[BackingQueueTypeId$1] = backingQueueVariance;
|
|
294
|
+
constructor(mutable) {
|
|
295
|
+
this.mutable = mutable;
|
|
296
|
+
}
|
|
297
|
+
poll(def) {
|
|
298
|
+
return poll$4(this.mutable, def);
|
|
299
|
+
}
|
|
300
|
+
pollUpTo(limit) {
|
|
301
|
+
return pollUpTo(this.mutable, limit);
|
|
302
|
+
}
|
|
303
|
+
offerAll(elements) {
|
|
304
|
+
return offerAll$4(this.mutable, elements);
|
|
305
|
+
}
|
|
306
|
+
offer(element) {
|
|
307
|
+
return offer$5(this.mutable, element);
|
|
308
|
+
}
|
|
309
|
+
capacity() {
|
|
310
|
+
return capacity$8(this.mutable);
|
|
311
|
+
}
|
|
312
|
+
length() {
|
|
313
|
+
return length(this.mutable);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
/** @internal */
|
|
317
|
+
const backingQueueFromMutableQueue = (mutable) => new BackingQueueFromMutableQueue(mutable);
|
|
318
|
+
/** @internal */
|
|
319
|
+
const size$7 = (self) => self.size;
|
|
320
|
+
/** @internal */
|
|
321
|
+
const shutdown$7 = (self) => self.shutdown;
|
|
322
|
+
/** @internal */
|
|
323
|
+
const offer$4 = /* @__PURE__ */ dual(2, (self, value) => self.offer(value));
|
|
324
|
+
/** @internal */
|
|
325
|
+
const take$7 = (self) => self.take;
|
|
326
|
+
/** @internal */
|
|
327
|
+
const takeUpTo$3 = /* @__PURE__ */ dual(2, (self, max) => self.takeUpTo(max));
|
|
328
|
+
/** @internal */
|
|
329
|
+
const backPressureStrategy$1 = () => new BackPressureStrategy$1();
|
|
330
|
+
/** @internal */
|
|
331
|
+
const droppingStrategy$1 = () => new DroppingStrategy$1();
|
|
332
|
+
/** @internal */
|
|
333
|
+
var BackPressureStrategy$1 = class {
|
|
334
|
+
[QueueStrategyTypeId$1] = queueStrategyVariance;
|
|
335
|
+
putters = /* @__PURE__ */ unbounded$8();
|
|
336
|
+
surplusSize() {
|
|
337
|
+
return length(this.putters);
|
|
338
|
+
}
|
|
339
|
+
onCompleteTakersWithEmptyQueue(takers) {
|
|
340
|
+
while (!isEmpty$9(this.putters) && !isEmpty$9(takers)) {
|
|
341
|
+
const taker = poll$4(takers, void 0);
|
|
342
|
+
const putter = poll$4(this.putters, void 0);
|
|
343
|
+
if (putter[2]) unsafeCompleteDeferred$1(putter[1], true);
|
|
344
|
+
unsafeCompleteDeferred$1(taker, putter[0]);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
get shutdown() {
|
|
348
|
+
return pipe(fiberId, flatMap$7((fiberId) => pipe(sync$7(() => unsafePollAll(this.putters)), flatMap$7((putters) => forEachConcurrentDiscard(putters, ([_, deferred, isLastItem]) => isLastItem ? pipe(deferredInterruptWith(deferred, fiberId), asVoid$1) : void_$4, false, false)))));
|
|
349
|
+
}
|
|
350
|
+
handleSurplus(iterable, queue, takers, isShutdown) {
|
|
351
|
+
return withFiberRuntime((state) => {
|
|
352
|
+
const deferred = deferredUnsafeMake(state.id());
|
|
353
|
+
return pipe(suspend$8(() => {
|
|
354
|
+
this.unsafeOffer(iterable, deferred);
|
|
355
|
+
this.unsafeOnQueueEmptySpace(queue, takers);
|
|
356
|
+
unsafeCompleteTakers(this, queue, takers);
|
|
357
|
+
return get$4(isShutdown) ? interrupt$1 : deferredAwait(deferred);
|
|
358
|
+
}), onInterrupt(() => sync$7(() => this.unsafeRemove(deferred))));
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
unsafeOnQueueEmptySpace(queue, takers) {
|
|
362
|
+
let keepPolling = true;
|
|
363
|
+
while (keepPolling && (queue.capacity() === Number.POSITIVE_INFINITY || queue.length() < queue.capacity())) {
|
|
364
|
+
const putter = pipe(this.putters, poll$4(EmptyMutableQueue));
|
|
365
|
+
if (putter === EmptyMutableQueue) keepPolling = false;
|
|
366
|
+
else {
|
|
367
|
+
const offered = queue.offer(putter[0]);
|
|
368
|
+
if (offered && putter[2]) unsafeCompleteDeferred$1(putter[1], true);
|
|
369
|
+
else if (!offered) unsafeOfferAll$1(this.putters, pipe(unsafePollAll(this.putters), prepend$2(putter)));
|
|
370
|
+
unsafeCompleteTakers(this, queue, takers);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
unsafeOffer(iterable, deferred) {
|
|
375
|
+
const stuff = fromIterable$2(iterable);
|
|
376
|
+
for (let i = 0; i < stuff.length; i++) {
|
|
377
|
+
const value = stuff[i];
|
|
378
|
+
if (i === stuff.length - 1) pipe(this.putters, offer$5([
|
|
379
|
+
value,
|
|
380
|
+
deferred,
|
|
381
|
+
true
|
|
382
|
+
]));
|
|
383
|
+
else pipe(this.putters, offer$5([
|
|
384
|
+
value,
|
|
385
|
+
deferred,
|
|
386
|
+
false
|
|
387
|
+
]));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
unsafeRemove(deferred) {
|
|
391
|
+
unsafeOfferAll$1(this.putters, pipe(unsafePollAll(this.putters), filter$3(([, _]) => _ !== deferred)));
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
/** @internal */
|
|
395
|
+
var DroppingStrategy$1 = class {
|
|
396
|
+
[QueueStrategyTypeId$1] = queueStrategyVariance;
|
|
397
|
+
surplusSize() {
|
|
398
|
+
return 0;
|
|
399
|
+
}
|
|
400
|
+
get shutdown() {
|
|
401
|
+
return void_$4;
|
|
402
|
+
}
|
|
403
|
+
onCompleteTakersWithEmptyQueue() {}
|
|
404
|
+
handleSurplus(_iterable, _queue, _takers, _isShutdown) {
|
|
405
|
+
return succeed$8(false);
|
|
406
|
+
}
|
|
407
|
+
unsafeOnQueueEmptySpace(_queue, _takers) {}
|
|
408
|
+
};
|
|
409
|
+
/** @internal */
|
|
410
|
+
const unsafeCompleteDeferred$1 = (deferred, a) => {
|
|
411
|
+
return deferredUnsafeDone(deferred, succeed$8(a));
|
|
412
|
+
};
|
|
413
|
+
/** @internal */
|
|
414
|
+
const unsafeOfferAll$1 = (queue, as) => {
|
|
415
|
+
return pipe(queue, offerAll$4(as));
|
|
416
|
+
};
|
|
417
|
+
/** @internal */
|
|
418
|
+
const unsafePollAll = (queue) => {
|
|
419
|
+
return pipe(queue, pollUpTo(Number.POSITIVE_INFINITY));
|
|
420
|
+
};
|
|
421
|
+
/** @internal */
|
|
422
|
+
const unsafePollN$1 = (queue, max) => {
|
|
423
|
+
return pipe(queue, pollUpTo(max));
|
|
424
|
+
};
|
|
425
|
+
/** @internal */
|
|
426
|
+
const unsafeRemove$1 = (queue, a) => {
|
|
427
|
+
unsafeOfferAll$1(queue, pipe(unsafePollAll(queue), filter$3((b) => a !== b)));
|
|
428
|
+
};
|
|
429
|
+
/** @internal */
|
|
430
|
+
const unsafeCompleteTakers = (strategy, queue, takers) => {
|
|
431
|
+
let keepPolling = true;
|
|
432
|
+
while (keepPolling && queue.length() !== 0) {
|
|
433
|
+
const taker = pipe(takers, poll$4(EmptyMutableQueue));
|
|
434
|
+
if (taker !== EmptyMutableQueue) {
|
|
435
|
+
const element = queue.poll(EmptyMutableQueue);
|
|
436
|
+
if (element !== EmptyMutableQueue) {
|
|
437
|
+
unsafeCompleteDeferred$1(taker, element);
|
|
438
|
+
strategy.unsafeOnQueueEmptySpace(queue, takers);
|
|
439
|
+
} else unsafeOfferAll$1(takers, pipe(unsafePollAll(takers), prepend$2(taker)));
|
|
440
|
+
keepPolling = true;
|
|
441
|
+
} else keepPolling = false;
|
|
442
|
+
}
|
|
443
|
+
if (keepPolling && queue.length() === 0 && !isEmpty$9(takers)) strategy.onCompleteTakersWithEmptyQueue(takers);
|
|
444
|
+
};
|
|
445
|
+
const addSubscribers = (subscription, pollers) => (subscribers) => {
|
|
446
|
+
if (!subscribers.has(subscription)) subscribers.set(subscription, /* @__PURE__ */ new Set());
|
|
447
|
+
subscribers.get(subscription).add(pollers);
|
|
448
|
+
};
|
|
449
|
+
/** @internal */
|
|
450
|
+
var SubscriptionImpl = class extends Class {
|
|
451
|
+
pubsub;
|
|
452
|
+
subscribers;
|
|
453
|
+
subscription;
|
|
454
|
+
pollers;
|
|
455
|
+
shutdownHook;
|
|
456
|
+
shutdownFlag;
|
|
457
|
+
strategy;
|
|
458
|
+
replayWindow;
|
|
459
|
+
[DequeueTypeId$1] = dequeueVariance;
|
|
460
|
+
constructor(pubsub, subscribers, subscription, pollers, shutdownHook, shutdownFlag, strategy, replayWindow) {
|
|
461
|
+
super();
|
|
462
|
+
this.pubsub = pubsub;
|
|
463
|
+
this.subscribers = subscribers;
|
|
464
|
+
this.subscription = subscription;
|
|
465
|
+
this.pollers = pollers;
|
|
466
|
+
this.shutdownHook = shutdownHook;
|
|
467
|
+
this.shutdownFlag = shutdownFlag;
|
|
468
|
+
this.strategy = strategy;
|
|
469
|
+
this.replayWindow = replayWindow;
|
|
470
|
+
}
|
|
471
|
+
commit() {
|
|
472
|
+
return this.take;
|
|
473
|
+
}
|
|
474
|
+
pipe() {
|
|
475
|
+
return pipeArguments(this, arguments);
|
|
476
|
+
}
|
|
477
|
+
capacity() {
|
|
478
|
+
return this.pubsub.capacity;
|
|
479
|
+
}
|
|
480
|
+
isActive() {
|
|
481
|
+
return !get$4(this.shutdownFlag);
|
|
482
|
+
}
|
|
483
|
+
get size() {
|
|
484
|
+
return suspend$8(() => get$4(this.shutdownFlag) ? interrupt$1 : succeed$8(this.subscription.size() + this.replayWindow.remaining));
|
|
485
|
+
}
|
|
486
|
+
unsafeSize() {
|
|
487
|
+
if (get$4(this.shutdownFlag)) return none();
|
|
488
|
+
return some$2(this.subscription.size() + this.replayWindow.remaining);
|
|
489
|
+
}
|
|
490
|
+
get isFull() {
|
|
491
|
+
return suspend$8(() => get$4(this.shutdownFlag) ? interrupt$1 : succeed$8(this.subscription.size() === this.capacity()));
|
|
492
|
+
}
|
|
493
|
+
get isEmpty() {
|
|
494
|
+
return map$9(this.size, (size) => size === 0);
|
|
495
|
+
}
|
|
496
|
+
get shutdown() {
|
|
497
|
+
return uninterruptible(withFiberRuntime((state) => {
|
|
498
|
+
set$2(this.shutdownFlag, true);
|
|
499
|
+
return pipe(forEachParUnbounded(unsafePollAllQueue(this.pollers), (d) => deferredInterruptWith(d, state.id()), false), zipRight$6(sync$7(() => {
|
|
500
|
+
this.subscribers.delete(this.subscription);
|
|
501
|
+
this.subscription.unsubscribe();
|
|
502
|
+
this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers);
|
|
503
|
+
})), whenEffect$2(deferredSucceed(this.shutdownHook, void 0)), asVoid$1);
|
|
504
|
+
}));
|
|
505
|
+
}
|
|
506
|
+
get isShutdown() {
|
|
507
|
+
return sync$7(() => get$4(this.shutdownFlag));
|
|
508
|
+
}
|
|
509
|
+
get awaitShutdown() {
|
|
510
|
+
return deferredAwait(this.shutdownHook);
|
|
511
|
+
}
|
|
512
|
+
get take() {
|
|
513
|
+
return withFiberRuntime((state) => {
|
|
514
|
+
if (get$4(this.shutdownFlag)) return interrupt$1;
|
|
515
|
+
if (this.replayWindow.remaining > 0) return succeed$8(this.replayWindow.take());
|
|
516
|
+
const message = isEmpty$9(this.pollers) ? this.subscription.poll(EmptyMutableQueue) : EmptyMutableQueue;
|
|
517
|
+
if (message === EmptyMutableQueue) {
|
|
518
|
+
const deferred = deferredUnsafeMake(state.id());
|
|
519
|
+
return pipe(suspend$8(() => {
|
|
520
|
+
pipe(this.pollers, offer$5(deferred));
|
|
521
|
+
pipe(this.subscribers, addSubscribers(this.subscription, this.pollers));
|
|
522
|
+
this.strategy.unsafeCompletePollers(this.pubsub, this.subscribers, this.subscription, this.pollers);
|
|
523
|
+
return get$4(this.shutdownFlag) ? interrupt$1 : deferredAwait(deferred);
|
|
524
|
+
}), onInterrupt(() => sync$7(() => unsafeRemove(this.pollers, deferred))));
|
|
525
|
+
} else {
|
|
526
|
+
this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers);
|
|
527
|
+
return succeed$8(message);
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
get takeAll() {
|
|
532
|
+
return suspend$8(() => {
|
|
533
|
+
if (get$4(this.shutdownFlag)) return interrupt$1;
|
|
534
|
+
const as = isEmpty$9(this.pollers) ? unsafePollAllSubscription(this.subscription) : empty$5();
|
|
535
|
+
this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers);
|
|
536
|
+
if (this.replayWindow.remaining > 0) return succeed$8(appendAll(this.replayWindow.takeAll(), as));
|
|
537
|
+
return succeed$8(as);
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
takeUpTo(max) {
|
|
541
|
+
return suspend$8(() => {
|
|
542
|
+
if (get$4(this.shutdownFlag)) return interrupt$1;
|
|
543
|
+
let replay = void 0;
|
|
544
|
+
if (this.replayWindow.remaining >= max) return succeed$8(this.replayWindow.takeN(max));
|
|
545
|
+
else if (this.replayWindow.remaining > 0) {
|
|
546
|
+
replay = this.replayWindow.takeAll();
|
|
547
|
+
max = max - replay.length;
|
|
548
|
+
}
|
|
549
|
+
const as = isEmpty$9(this.pollers) ? unsafePollN(this.subscription, max) : empty$5();
|
|
550
|
+
this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers);
|
|
551
|
+
return replay ? succeed$8(appendAll(replay, as)) : succeed$8(as);
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
takeBetween(min, max) {
|
|
555
|
+
return suspend$8(() => takeRemainderLoop(this, min, max, empty$5()));
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
/** @internal */
|
|
559
|
+
const takeRemainderLoop = (self, min, max, acc) => {
|
|
560
|
+
if (max < min) return succeed$8(acc);
|
|
561
|
+
return pipe(self.takeUpTo(max), flatMap$7((bs) => {
|
|
562
|
+
const remaining = min - bs.length;
|
|
563
|
+
if (remaining === 1) return pipe(self.take, map$9((b) => pipe(acc, appendAll(bs), append(b))));
|
|
564
|
+
if (remaining > 1) return pipe(self.take, flatMap$7((b) => takeRemainderLoop(self, remaining - 1, max - bs.length - 1, pipe(acc, appendAll(bs), append(b)))));
|
|
565
|
+
return succeed$8(pipe(acc, appendAll(bs)));
|
|
566
|
+
}));
|
|
567
|
+
};
|
|
568
|
+
/** @internal */
|
|
569
|
+
const unsafeOfferAll = (queue, as) => {
|
|
570
|
+
return pipe(queue, offerAll$4(as));
|
|
571
|
+
};
|
|
572
|
+
/** @internal */
|
|
573
|
+
const unsafePollAllQueue = (queue) => {
|
|
574
|
+
return pipe(queue, pollUpTo(Number.POSITIVE_INFINITY));
|
|
575
|
+
};
|
|
576
|
+
/** @internal */
|
|
577
|
+
const unsafePollAllSubscription = (subscription) => {
|
|
578
|
+
return subscription.pollUpTo(Number.POSITIVE_INFINITY);
|
|
579
|
+
};
|
|
580
|
+
/** @internal */
|
|
581
|
+
const unsafePollN = (subscription, max) => {
|
|
582
|
+
return subscription.pollUpTo(max);
|
|
583
|
+
};
|
|
584
|
+
/** @internal */
|
|
585
|
+
const unsafeRemove = (queue, value) => {
|
|
586
|
+
unsafeOfferAll(queue, pipe(unsafePollAllQueue(queue), filter$3((elem) => elem !== value)));
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* Makes a new bounded `Queue`. When the capacity of the queue is reached, any
|
|
590
|
+
* additional calls to `offer` will be suspended until there is more room in
|
|
591
|
+
* the queue.
|
|
592
|
+
*
|
|
593
|
+
* **Note**: When possible use only power of 2 capacities; this will provide
|
|
594
|
+
* better performance by utilising an optimised version of the underlying
|
|
595
|
+
* `RingBuffer`.
|
|
596
|
+
*
|
|
597
|
+
* @since 2.0.0
|
|
598
|
+
* @category constructors
|
|
599
|
+
*/
|
|
600
|
+
const bounded$4 = bounded$7;
|
|
601
|
+
/**
|
|
602
|
+
* Creates a new unbounded `Queue`.
|
|
603
|
+
*
|
|
604
|
+
* @since 2.0.0
|
|
605
|
+
* @category constructors
|
|
606
|
+
*/
|
|
607
|
+
const unbounded$4 = unbounded$7;
|
|
608
|
+
/**
|
|
609
|
+
* Retrieves the size of the queue, which is equal to the number of elements
|
|
610
|
+
* in the queue. This may be negative if fibers are suspended waiting for
|
|
611
|
+
* elements to be added to the queue.
|
|
612
|
+
*
|
|
613
|
+
* @since 2.0.0
|
|
614
|
+
* @category getters
|
|
615
|
+
*/
|
|
616
|
+
const size$4 = size$7;
|
|
617
|
+
/**
|
|
618
|
+
* Interrupts any fibers that are suspended on `offer` or `take`. Future calls
|
|
619
|
+
* to `offer*` and `take*` will be interrupted immediately.
|
|
620
|
+
*
|
|
621
|
+
* @since 2.0.0
|
|
622
|
+
* @category utils
|
|
623
|
+
*/
|
|
624
|
+
const shutdown$4 = shutdown$7;
|
|
625
|
+
/**
|
|
626
|
+
* Places one value in the queue.
|
|
627
|
+
*
|
|
628
|
+
* @since 2.0.0
|
|
629
|
+
* @category utils
|
|
630
|
+
*/
|
|
631
|
+
const offer$3 = offer$4;
|
|
632
|
+
/**
|
|
633
|
+
* Takes the oldest value in the queue. If the queue is empty, this will return
|
|
634
|
+
* a computation that resumes when an item has been added to the queue.
|
|
635
|
+
*
|
|
636
|
+
* @since 2.0.0
|
|
637
|
+
* @category utils
|
|
638
|
+
*/
|
|
639
|
+
const take$6 = take$7;
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/channelChildExecutorDecision.js
|
|
642
|
+
/** @internal */
|
|
643
|
+
const OP_CONTINUE = "Continue";
|
|
644
|
+
/** @internal */
|
|
645
|
+
const OP_CLOSE = "Close";
|
|
646
|
+
/** @internal */
|
|
647
|
+
const OP_YIELD = "Yield";
|
|
648
|
+
/** @internal */
|
|
649
|
+
const ChildExecutorDecisionTypeId = /* @__PURE__ */ Symbol.for("effect/ChannelChildExecutorDecision");
|
|
650
|
+
/** @internal */
|
|
651
|
+
const proto$7 = { [ChildExecutorDecisionTypeId]: ChildExecutorDecisionTypeId };
|
|
652
|
+
/** @internal */
|
|
653
|
+
const Continue = (_) => {
|
|
654
|
+
const op = Object.create(proto$7);
|
|
655
|
+
op._tag = OP_CONTINUE;
|
|
656
|
+
return op;
|
|
657
|
+
};
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/continuation.js
|
|
660
|
+
/** @internal */
|
|
661
|
+
const OP_CONTINUATION_K = "ContinuationK";
|
|
662
|
+
/** @internal */
|
|
663
|
+
const OP_CONTINUATION_FINALIZER = "ContinuationFinalizer";
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region ../../node_modules/effect/dist/esm/internal/channel/continuation.js
|
|
666
|
+
/** @internal */
|
|
667
|
+
const ContinuationTypeId = /* @__PURE__ */ Symbol.for("effect/ChannelContinuation");
|
|
668
|
+
const continuationVariance = {
|
|
669
|
+
_Env: (_) => _,
|
|
670
|
+
_InErr: (_) => _,
|
|
671
|
+
_InElem: (_) => _,
|
|
672
|
+
_InDone: (_) => _,
|
|
673
|
+
_OutErr: (_) => _,
|
|
674
|
+
_OutDone: (_) => _,
|
|
675
|
+
_OutErr2: (_) => _,
|
|
676
|
+
_OutElem: (_) => _,
|
|
677
|
+
_OutDone2: (_) => _
|
|
678
|
+
};
|
|
679
|
+
/** @internal */
|
|
680
|
+
var ContinuationKImpl = class {
|
|
681
|
+
onSuccess;
|
|
682
|
+
onHalt;
|
|
683
|
+
_tag = OP_CONTINUATION_K;
|
|
684
|
+
[ContinuationTypeId] = continuationVariance;
|
|
685
|
+
constructor(onSuccess, onHalt) {
|
|
686
|
+
this.onSuccess = onSuccess;
|
|
687
|
+
this.onHalt = onHalt;
|
|
688
|
+
}
|
|
689
|
+
onExit(exit) {
|
|
690
|
+
return isFailure(exit) ? this.onHalt(exit.cause) : this.onSuccess(exit.value);
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
/** @internal */
|
|
694
|
+
var ContinuationFinalizerImpl = class {
|
|
695
|
+
finalizer;
|
|
696
|
+
_tag = OP_CONTINUATION_FINALIZER;
|
|
697
|
+
[ContinuationTypeId] = continuationVariance;
|
|
698
|
+
constructor(finalizer) {
|
|
699
|
+
this.finalizer = finalizer;
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
//#endregion
|
|
703
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/channelUpstreamPullStrategy.js
|
|
704
|
+
/** @internal */
|
|
705
|
+
const OP_PULL_AFTER_NEXT = "PullAfterNext";
|
|
706
|
+
/** @internal */
|
|
707
|
+
const OP_PULL_AFTER_ALL_ENQUEUED = "PullAfterAllEnqueued";
|
|
708
|
+
/** @internal */
|
|
709
|
+
const UpstreamPullStrategyTypeId = /* @__PURE__ */ Symbol.for("effect/ChannelUpstreamPullStrategy");
|
|
710
|
+
const upstreamPullStrategyVariance = { _A: (_) => _ };
|
|
711
|
+
/** @internal */
|
|
712
|
+
const proto$6 = { [UpstreamPullStrategyTypeId]: upstreamPullStrategyVariance };
|
|
713
|
+
/** @internal */
|
|
714
|
+
const PullAfterNext = (emitSeparator) => {
|
|
715
|
+
const op = Object.create(proto$6);
|
|
716
|
+
op._tag = OP_PULL_AFTER_NEXT;
|
|
717
|
+
op.emitSeparator = emitSeparator;
|
|
718
|
+
return op;
|
|
719
|
+
};
|
|
720
|
+
//#endregion
|
|
721
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/channel.js
|
|
722
|
+
/** @internal */
|
|
723
|
+
const OP_BRACKET_OUT = "BracketOut";
|
|
724
|
+
/** @internal */
|
|
725
|
+
const OP_BRIDGE = "Bridge";
|
|
726
|
+
/** @internal */
|
|
727
|
+
const OP_CONCAT_ALL = "ConcatAll";
|
|
728
|
+
/** @internal */
|
|
729
|
+
const OP_EMIT$3 = "Emit";
|
|
730
|
+
/** @internal */
|
|
731
|
+
const OP_ENSURING = "Ensuring";
|
|
732
|
+
/** @internal */
|
|
733
|
+
const OP_FAIL$2 = "Fail";
|
|
734
|
+
/** @internal */
|
|
735
|
+
const OP_FOLD = "Fold";
|
|
736
|
+
/** @internal */
|
|
737
|
+
const OP_FROM_EFFECT$1 = "FromEffect";
|
|
738
|
+
/** @internal */
|
|
739
|
+
const OP_PIPE_TO = "PipeTo";
|
|
740
|
+
/** @internal */
|
|
741
|
+
const OP_PROVIDE$1 = "Provide";
|
|
742
|
+
/** @internal */
|
|
743
|
+
const OP_READ$1 = "Read";
|
|
744
|
+
/** @internal */
|
|
745
|
+
const OP_SUCCEED$2 = "Succeed";
|
|
746
|
+
/** @internal */
|
|
747
|
+
const OP_SUCCEED_NOW = "SucceedNow";
|
|
748
|
+
/** @internal */
|
|
749
|
+
const OP_SUSPEND$1 = "Suspend";
|
|
750
|
+
/** @internal */
|
|
751
|
+
const ChannelTypeId = /* @__PURE__ */ Symbol.for("effect/Channel");
|
|
752
|
+
const channelVariance = {
|
|
753
|
+
_Env: (_) => _,
|
|
754
|
+
_InErr: (_) => _,
|
|
755
|
+
_InElem: (_) => _,
|
|
756
|
+
_InDone: (_) => _,
|
|
757
|
+
_OutErr: (_) => _,
|
|
758
|
+
_OutElem: (_) => _,
|
|
759
|
+
_OutDone: (_) => _
|
|
760
|
+
};
|
|
761
|
+
/** @internal */
|
|
762
|
+
const proto$5 = {
|
|
763
|
+
[ChannelTypeId]: channelVariance,
|
|
764
|
+
pipe() {
|
|
765
|
+
return pipeArguments(this, arguments);
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
/** @internal */
|
|
769
|
+
const isChannel = (u) => hasProperty(u, ChannelTypeId) || isEffect(u);
|
|
770
|
+
/** @internal */
|
|
771
|
+
const acquireReleaseOut = /* @__PURE__ */ dual(2, (self, release) => {
|
|
772
|
+
const op = Object.create(proto$5);
|
|
773
|
+
op._tag = OP_BRACKET_OUT;
|
|
774
|
+
op.acquire = () => self;
|
|
775
|
+
op.finalizer = release;
|
|
776
|
+
return op;
|
|
777
|
+
});
|
|
778
|
+
/** @internal */
|
|
779
|
+
const catchAllCause$2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
780
|
+
const op = Object.create(proto$5);
|
|
781
|
+
op._tag = OP_FOLD;
|
|
782
|
+
op.channel = self;
|
|
783
|
+
op.k = new ContinuationKImpl(succeed$5, f);
|
|
784
|
+
return op;
|
|
785
|
+
});
|
|
786
|
+
/** @internal */
|
|
787
|
+
const collectElementsReader = (builder) => readWith({
|
|
788
|
+
onInput: (outElem) => flatMap$4(sync$4(() => {
|
|
789
|
+
builder.push(outElem);
|
|
790
|
+
}), () => collectElementsReader(builder)),
|
|
791
|
+
onFailure: fail$5,
|
|
792
|
+
onDone: succeedNow
|
|
793
|
+
});
|
|
794
|
+
/** @internal */
|
|
795
|
+
const concatAllWith = (channels, f, g) => {
|
|
796
|
+
const op = Object.create(proto$5);
|
|
797
|
+
op._tag = OP_CONCAT_ALL;
|
|
798
|
+
op.combineInners = f;
|
|
799
|
+
op.combineAll = g;
|
|
800
|
+
op.onPull = () => PullAfterNext(none());
|
|
801
|
+
op.onEmit = () => Continue;
|
|
802
|
+
op.value = () => channels;
|
|
803
|
+
op.k = identity$2;
|
|
804
|
+
return op;
|
|
805
|
+
};
|
|
806
|
+
/** @internal */
|
|
807
|
+
const concatMapWith = /* @__PURE__ */ dual(4, (self, f, g, h) => {
|
|
808
|
+
const op = Object.create(proto$5);
|
|
809
|
+
op._tag = OP_CONCAT_ALL;
|
|
810
|
+
op.combineInners = g;
|
|
811
|
+
op.combineAll = h;
|
|
812
|
+
op.onPull = () => PullAfterNext(none());
|
|
813
|
+
op.onEmit = () => Continue;
|
|
814
|
+
op.value = () => self;
|
|
815
|
+
op.k = f;
|
|
816
|
+
return op;
|
|
817
|
+
});
|
|
818
|
+
/** @internal */
|
|
819
|
+
const embedInput = /* @__PURE__ */ dual(2, (self, input) => {
|
|
820
|
+
const op = Object.create(proto$5);
|
|
821
|
+
op._tag = OP_BRIDGE;
|
|
822
|
+
op.input = input;
|
|
823
|
+
op.channel = self;
|
|
824
|
+
return op;
|
|
825
|
+
});
|
|
826
|
+
/** @internal */
|
|
827
|
+
const ensuringWith$2 = /* @__PURE__ */ dual(2, (self, finalizer) => {
|
|
828
|
+
const op = Object.create(proto$5);
|
|
829
|
+
op._tag = OP_ENSURING;
|
|
830
|
+
op.channel = self;
|
|
831
|
+
op.finalizer = finalizer;
|
|
832
|
+
return op;
|
|
833
|
+
});
|
|
834
|
+
/** @internal */
|
|
835
|
+
const fail$5 = (error) => failCause$4(fail$8(error));
|
|
836
|
+
/** @internal */
|
|
837
|
+
const failCause$4 = (cause) => failCauseSync$2(() => cause);
|
|
838
|
+
/** @internal */
|
|
839
|
+
const failCauseSync$2 = (evaluate) => {
|
|
840
|
+
const op = Object.create(proto$5);
|
|
841
|
+
op._tag = OP_FAIL$2;
|
|
842
|
+
op.error = evaluate;
|
|
843
|
+
return op;
|
|
844
|
+
};
|
|
845
|
+
/** @internal */
|
|
846
|
+
const flatMap$4 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
847
|
+
const op = Object.create(proto$5);
|
|
848
|
+
op._tag = OP_FOLD;
|
|
849
|
+
op.channel = self;
|
|
850
|
+
op.k = new ContinuationKImpl(f, failCause$4);
|
|
851
|
+
return op;
|
|
852
|
+
});
|
|
853
|
+
/** @internal */
|
|
854
|
+
const fromEffect$4 = (effect) => {
|
|
855
|
+
const op = Object.create(proto$5);
|
|
856
|
+
op._tag = OP_FROM_EFFECT$1;
|
|
857
|
+
op.effect = () => effect;
|
|
858
|
+
return op;
|
|
859
|
+
};
|
|
860
|
+
/** @internal */
|
|
861
|
+
const pipeTo = /* @__PURE__ */ dual(2, (self, that) => {
|
|
862
|
+
const op = Object.create(proto$5);
|
|
863
|
+
op._tag = OP_PIPE_TO;
|
|
864
|
+
op.left = () => self;
|
|
865
|
+
op.right = () => that;
|
|
866
|
+
return op;
|
|
867
|
+
});
|
|
868
|
+
/** @internal */
|
|
869
|
+
const readWith = (options) => readWithCause({
|
|
870
|
+
onInput: options.onInput,
|
|
871
|
+
onFailure: (cause) => match$8(failureOrCause(cause), {
|
|
872
|
+
onLeft: options.onFailure,
|
|
873
|
+
onRight: failCause$4
|
|
874
|
+
}),
|
|
875
|
+
onDone: options.onDone
|
|
876
|
+
});
|
|
877
|
+
/** @internal */
|
|
878
|
+
const readWithCause = (options) => {
|
|
879
|
+
const op = Object.create(proto$5);
|
|
880
|
+
op._tag = OP_READ$1;
|
|
881
|
+
op.more = options.onInput;
|
|
882
|
+
op.done = new ContinuationKImpl(options.onDone, options.onFailure);
|
|
883
|
+
return op;
|
|
884
|
+
};
|
|
885
|
+
/** @internal */
|
|
886
|
+
const succeed$5 = (value) => sync$4(() => value);
|
|
887
|
+
/** @internal */
|
|
888
|
+
const succeedNow = (result) => {
|
|
889
|
+
const op = Object.create(proto$5);
|
|
890
|
+
op._tag = OP_SUCCEED_NOW;
|
|
891
|
+
op.terminal = result;
|
|
892
|
+
return op;
|
|
893
|
+
};
|
|
894
|
+
/** @internal */
|
|
895
|
+
const suspend$5 = (evaluate) => {
|
|
896
|
+
const op = Object.create(proto$5);
|
|
897
|
+
op._tag = OP_SUSPEND$1;
|
|
898
|
+
op.channel = evaluate;
|
|
899
|
+
return op;
|
|
900
|
+
};
|
|
901
|
+
const sync$4 = (evaluate) => {
|
|
902
|
+
const op = Object.create(proto$5);
|
|
903
|
+
op._tag = OP_SUCCEED$2;
|
|
904
|
+
op.evaluate = evaluate;
|
|
905
|
+
return op;
|
|
906
|
+
};
|
|
907
|
+
const void_$3 = /* @__PURE__ */ succeedNow(void 0);
|
|
908
|
+
/** @internal */
|
|
909
|
+
const write = (out) => {
|
|
910
|
+
const op = Object.create(proto$5);
|
|
911
|
+
op._tag = OP_EMIT$3;
|
|
912
|
+
op.out = out;
|
|
913
|
+
return op;
|
|
914
|
+
};
|
|
915
|
+
//#endregion
|
|
916
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/channelState.js
|
|
917
|
+
/** @internal */
|
|
918
|
+
const OP_DONE$3 = "Done";
|
|
919
|
+
/** @internal */
|
|
920
|
+
const OP_EMIT$2 = "Emit";
|
|
921
|
+
/** @internal */
|
|
922
|
+
const OP_FROM_EFFECT = "FromEffect";
|
|
923
|
+
/** @internal */
|
|
924
|
+
const OP_READ = "Read";
|
|
925
|
+
//#endregion
|
|
926
|
+
//#region ../../node_modules/effect/dist/esm/internal/channel/channelState.js
|
|
927
|
+
/** @internal */
|
|
928
|
+
const ChannelStateTypeId = /* @__PURE__ */ Symbol.for("effect/ChannelState");
|
|
929
|
+
const channelStateVariance = {
|
|
930
|
+
_E: (_) => _,
|
|
931
|
+
_R: (_) => _
|
|
932
|
+
};
|
|
933
|
+
/** @internal */
|
|
934
|
+
const proto$4 = { [ChannelStateTypeId]: channelStateVariance };
|
|
935
|
+
/** @internal */
|
|
936
|
+
const Done$2 = () => {
|
|
937
|
+
const op = Object.create(proto$4);
|
|
938
|
+
op._tag = OP_DONE$3;
|
|
939
|
+
return op;
|
|
940
|
+
};
|
|
941
|
+
/** @internal */
|
|
942
|
+
const Emit$1 = () => {
|
|
943
|
+
const op = Object.create(proto$4);
|
|
944
|
+
op._tag = OP_EMIT$2;
|
|
945
|
+
return op;
|
|
946
|
+
};
|
|
947
|
+
/** @internal */
|
|
948
|
+
const fromEffect$3 = (effect) => {
|
|
949
|
+
const op = Object.create(proto$4);
|
|
950
|
+
op._tag = OP_FROM_EFFECT;
|
|
951
|
+
op.effect = effect;
|
|
952
|
+
return op;
|
|
953
|
+
};
|
|
954
|
+
/** @internal */
|
|
955
|
+
const Read = (upstream, onEffect, onEmit, onDone) => {
|
|
956
|
+
const op = Object.create(proto$4);
|
|
957
|
+
op._tag = OP_READ;
|
|
958
|
+
op.upstream = upstream;
|
|
959
|
+
op.onEffect = onEffect;
|
|
960
|
+
op.onEmit = onEmit;
|
|
961
|
+
op.onDone = onDone;
|
|
962
|
+
return op;
|
|
963
|
+
};
|
|
964
|
+
/** @internal */
|
|
965
|
+
const isFromEffect = (self) => self._tag === OP_FROM_EFFECT;
|
|
966
|
+
/** @internal */
|
|
967
|
+
const effect$1 = (self) => isFromEffect(self) ? self.effect : _void;
|
|
968
|
+
/** @internal */
|
|
969
|
+
const effectOrUndefinedIgnored = (self) => isFromEffect(self) ? ignore(self.effect) : void 0;
|
|
970
|
+
//#endregion
|
|
971
|
+
//#region ../../node_modules/effect/dist/esm/internal/channel/subexecutor.js
|
|
972
|
+
/** @internal */
|
|
973
|
+
const OP_PULL_FROM_CHILD = "PullFromChild";
|
|
974
|
+
/** @internal */
|
|
975
|
+
const OP_PULL_FROM_UPSTREAM = "PullFromUpstream";
|
|
976
|
+
/** @internal */
|
|
977
|
+
const OP_DRAIN_CHILD_EXECUTORS = "DrainChildExecutors";
|
|
978
|
+
/** @internal */
|
|
979
|
+
const OP_EMIT$1 = "Emit";
|
|
980
|
+
/**
|
|
981
|
+
* Execute the `childExecutor` and on each emitted value, decide what to do by
|
|
982
|
+
* `onEmit`.
|
|
983
|
+
*
|
|
984
|
+
* @internal
|
|
985
|
+
*/
|
|
986
|
+
var PullFromChild = class {
|
|
987
|
+
childExecutor;
|
|
988
|
+
parentSubexecutor;
|
|
989
|
+
onEmit;
|
|
990
|
+
_tag = OP_PULL_FROM_CHILD;
|
|
991
|
+
constructor(childExecutor, parentSubexecutor, onEmit) {
|
|
992
|
+
this.childExecutor = childExecutor;
|
|
993
|
+
this.parentSubexecutor = parentSubexecutor;
|
|
994
|
+
this.onEmit = onEmit;
|
|
995
|
+
}
|
|
996
|
+
close(exit$4) {
|
|
997
|
+
const fin1 = this.childExecutor.close(exit$4);
|
|
998
|
+
const fin2 = this.parentSubexecutor.close(exit$4);
|
|
999
|
+
if (fin1 !== void 0 && fin2 !== void 0) return zipWith$7(exit(fin1), exit(fin2), (exit1, exit2) => pipe(exit1, zipRight$7(exit2)));
|
|
1000
|
+
else if (fin1 !== void 0) return fin1;
|
|
1001
|
+
else if (fin2 !== void 0) return fin2;
|
|
1002
|
+
else return;
|
|
1003
|
+
}
|
|
1004
|
+
enqueuePullFromChild(_child) {
|
|
1005
|
+
return this;
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
/**
|
|
1009
|
+
* Execute `upstreamExecutor` and for each emitted element, spawn a child
|
|
1010
|
+
* channel and continue with processing it by `PullFromChild`.
|
|
1011
|
+
*
|
|
1012
|
+
* @internal
|
|
1013
|
+
*/
|
|
1014
|
+
var PullFromUpstream = class PullFromUpstream {
|
|
1015
|
+
upstreamExecutor;
|
|
1016
|
+
createChild;
|
|
1017
|
+
lastDone;
|
|
1018
|
+
activeChildExecutors;
|
|
1019
|
+
combineChildResults;
|
|
1020
|
+
combineWithChildResult;
|
|
1021
|
+
onPull;
|
|
1022
|
+
onEmit;
|
|
1023
|
+
_tag = OP_PULL_FROM_UPSTREAM;
|
|
1024
|
+
constructor(upstreamExecutor, createChild, lastDone, activeChildExecutors, combineChildResults, combineWithChildResult, onPull, onEmit) {
|
|
1025
|
+
this.upstreamExecutor = upstreamExecutor;
|
|
1026
|
+
this.createChild = createChild;
|
|
1027
|
+
this.lastDone = lastDone;
|
|
1028
|
+
this.activeChildExecutors = activeChildExecutors;
|
|
1029
|
+
this.combineChildResults = combineChildResults;
|
|
1030
|
+
this.combineWithChildResult = combineWithChildResult;
|
|
1031
|
+
this.onPull = onPull;
|
|
1032
|
+
this.onEmit = onEmit;
|
|
1033
|
+
}
|
|
1034
|
+
close(exit$5) {
|
|
1035
|
+
const fin1 = this.upstreamExecutor.close(exit$5);
|
|
1036
|
+
const result = [...this.activeChildExecutors.map((child) => child !== void 0 ? child.childExecutor.close(exit$5) : void 0), fin1].reduce((acc, next) => {
|
|
1037
|
+
if (acc !== void 0 && next !== void 0) return zipWith$7(acc, exit(next), (exit1, exit2) => zipRight$7(exit1, exit2));
|
|
1038
|
+
else if (acc !== void 0) return acc;
|
|
1039
|
+
else if (next !== void 0) return exit(next);
|
|
1040
|
+
else return;
|
|
1041
|
+
}, void 0);
|
|
1042
|
+
return result === void 0 ? result : result;
|
|
1043
|
+
}
|
|
1044
|
+
enqueuePullFromChild(child) {
|
|
1045
|
+
return new PullFromUpstream(this.upstreamExecutor, this.createChild, this.lastDone, [...this.activeChildExecutors, child], this.combineChildResults, this.combineWithChildResult, this.onPull, this.onEmit);
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
/**
|
|
1049
|
+
* Transformed from `PullFromUpstream` when upstream has finished but there
|
|
1050
|
+
* are still active child executors.
|
|
1051
|
+
*
|
|
1052
|
+
* @internal
|
|
1053
|
+
*/
|
|
1054
|
+
var DrainChildExecutors = class DrainChildExecutors {
|
|
1055
|
+
upstreamExecutor;
|
|
1056
|
+
lastDone;
|
|
1057
|
+
activeChildExecutors;
|
|
1058
|
+
upstreamDone;
|
|
1059
|
+
combineChildResults;
|
|
1060
|
+
combineWithChildResult;
|
|
1061
|
+
onPull;
|
|
1062
|
+
_tag = OP_DRAIN_CHILD_EXECUTORS;
|
|
1063
|
+
constructor(upstreamExecutor, lastDone, activeChildExecutors, upstreamDone, combineChildResults, combineWithChildResult, onPull) {
|
|
1064
|
+
this.upstreamExecutor = upstreamExecutor;
|
|
1065
|
+
this.lastDone = lastDone;
|
|
1066
|
+
this.activeChildExecutors = activeChildExecutors;
|
|
1067
|
+
this.upstreamDone = upstreamDone;
|
|
1068
|
+
this.combineChildResults = combineChildResults;
|
|
1069
|
+
this.combineWithChildResult = combineWithChildResult;
|
|
1070
|
+
this.onPull = onPull;
|
|
1071
|
+
}
|
|
1072
|
+
close(exit$3) {
|
|
1073
|
+
const fin1 = this.upstreamExecutor.close(exit$3);
|
|
1074
|
+
const result = [...this.activeChildExecutors.map((child) => child !== void 0 ? child.childExecutor.close(exit$3) : void 0), fin1].reduce((acc, next) => {
|
|
1075
|
+
if (acc !== void 0 && next !== void 0) return zipWith$7(acc, exit(next), (exit1, exit2) => zipRight$7(exit1, exit2));
|
|
1076
|
+
else if (acc !== void 0) return acc;
|
|
1077
|
+
else if (next !== void 0) return exit(next);
|
|
1078
|
+
else return;
|
|
1079
|
+
}, void 0);
|
|
1080
|
+
return result === void 0 ? result : result;
|
|
1081
|
+
}
|
|
1082
|
+
enqueuePullFromChild(child) {
|
|
1083
|
+
return new DrainChildExecutors(this.upstreamExecutor, this.lastDone, [...this.activeChildExecutors, child], this.upstreamDone, this.combineChildResults, this.combineWithChildResult, this.onPull);
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
/** @internal */
|
|
1087
|
+
var Emit = class {
|
|
1088
|
+
value;
|
|
1089
|
+
next;
|
|
1090
|
+
_tag = OP_EMIT$1;
|
|
1091
|
+
constructor(value, next) {
|
|
1092
|
+
this.value = value;
|
|
1093
|
+
this.next = next;
|
|
1094
|
+
}
|
|
1095
|
+
close(exit) {
|
|
1096
|
+
const result = this.next.close(exit);
|
|
1097
|
+
return result === void 0 ? result : result;
|
|
1098
|
+
}
|
|
1099
|
+
enqueuePullFromChild(_child) {
|
|
1100
|
+
return this;
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
//#endregion
|
|
1104
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/channelUpstreamPullRequest.js
|
|
1105
|
+
/** @internal */
|
|
1106
|
+
const OP_PULLED = "Pulled";
|
|
1107
|
+
/** @internal */
|
|
1108
|
+
const OP_NO_UPSTREAM = "NoUpstream";
|
|
1109
|
+
/** @internal */
|
|
1110
|
+
const UpstreamPullRequestTypeId = /* @__PURE__ */ Symbol.for("effect/ChannelUpstreamPullRequest");
|
|
1111
|
+
const upstreamPullRequestVariance = { _A: (_) => _ };
|
|
1112
|
+
/** @internal */
|
|
1113
|
+
const proto$3 = { [UpstreamPullRequestTypeId]: upstreamPullRequestVariance };
|
|
1114
|
+
/** @internal */
|
|
1115
|
+
const Pulled = (value) => {
|
|
1116
|
+
const op = Object.create(proto$3);
|
|
1117
|
+
op._tag = OP_PULLED;
|
|
1118
|
+
op.value = value;
|
|
1119
|
+
return op;
|
|
1120
|
+
};
|
|
1121
|
+
/** @internal */
|
|
1122
|
+
const NoUpstream = (activeDownstreamCount) => {
|
|
1123
|
+
const op = Object.create(proto$3);
|
|
1124
|
+
op._tag = OP_NO_UPSTREAM;
|
|
1125
|
+
op.activeDownstreamCount = activeDownstreamCount;
|
|
1126
|
+
return op;
|
|
1127
|
+
};
|
|
1128
|
+
//#endregion
|
|
1129
|
+
//#region ../../node_modules/effect/dist/esm/internal/channel/channelExecutor.js
|
|
1130
|
+
/** @internal */
|
|
1131
|
+
var ChannelExecutor = class ChannelExecutor {
|
|
1132
|
+
_activeSubexecutor = void 0;
|
|
1133
|
+
_cancelled = void 0;
|
|
1134
|
+
_closeLastSubstream = void 0;
|
|
1135
|
+
_currentChannel;
|
|
1136
|
+
_done = void 0;
|
|
1137
|
+
_doneStack = [];
|
|
1138
|
+
_emitted = void 0;
|
|
1139
|
+
_executeCloseLastSubstream;
|
|
1140
|
+
_input = void 0;
|
|
1141
|
+
_inProgressFinalizer = void 0;
|
|
1142
|
+
_providedEnv;
|
|
1143
|
+
constructor(initialChannel, providedEnv, executeCloseLastSubstream) {
|
|
1144
|
+
this._currentChannel = initialChannel;
|
|
1145
|
+
this._executeCloseLastSubstream = executeCloseLastSubstream;
|
|
1146
|
+
this._providedEnv = providedEnv;
|
|
1147
|
+
}
|
|
1148
|
+
run() {
|
|
1149
|
+
let result = void 0;
|
|
1150
|
+
while (result === void 0) if (this._cancelled !== void 0) result = this.processCancellation();
|
|
1151
|
+
else if (this._activeSubexecutor !== void 0) result = this.runSubexecutor();
|
|
1152
|
+
else try {
|
|
1153
|
+
if (this._currentChannel === void 0) result = Done$2();
|
|
1154
|
+
else {
|
|
1155
|
+
if (isEffect(this._currentChannel)) this._currentChannel = fromEffect$4(this._currentChannel);
|
|
1156
|
+
switch (this._currentChannel._tag) {
|
|
1157
|
+
case OP_BRACKET_OUT:
|
|
1158
|
+
result = this.runBracketOut(this._currentChannel);
|
|
1159
|
+
break;
|
|
1160
|
+
case OP_BRIDGE: {
|
|
1161
|
+
const bridgeInput = this._currentChannel.input;
|
|
1162
|
+
this._currentChannel = this._currentChannel.channel;
|
|
1163
|
+
if (this._input !== void 0) {
|
|
1164
|
+
const inputExecutor = this._input;
|
|
1165
|
+
this._input = void 0;
|
|
1166
|
+
const drainer = () => flatMap$8(bridgeInput.awaitRead(), () => suspend$9(() => {
|
|
1167
|
+
const state = inputExecutor.run();
|
|
1168
|
+
switch (state._tag) {
|
|
1169
|
+
case OP_DONE$3: return match$9(inputExecutor.getDone(), {
|
|
1170
|
+
onFailure: (cause) => bridgeInput.error(cause),
|
|
1171
|
+
onSuccess: (value) => bridgeInput.done(value)
|
|
1172
|
+
});
|
|
1173
|
+
case OP_EMIT$2: return flatMap$8(bridgeInput.emit(inputExecutor.getEmit()), () => drainer());
|
|
1174
|
+
case OP_FROM_EFFECT: return matchCauseEffect(state.effect, {
|
|
1175
|
+
onFailure: (cause) => bridgeInput.error(cause),
|
|
1176
|
+
onSuccess: () => drainer()
|
|
1177
|
+
});
|
|
1178
|
+
case OP_READ: return readUpstream(state, () => drainer(), (cause) => bridgeInput.error(cause));
|
|
1179
|
+
}
|
|
1180
|
+
}));
|
|
1181
|
+
result = fromEffect$3(flatMap$8(forkDaemon(interruptible(drainer())), (fiber) => sync$8(() => this.addFinalizer((exit) => flatMap$8(interrupt$2(fiber), () => suspend$9(() => {
|
|
1182
|
+
const effect = this.restorePipe(exit, inputExecutor);
|
|
1183
|
+
return effect !== void 0 ? effect : _void;
|
|
1184
|
+
}))))));
|
|
1185
|
+
}
|
|
1186
|
+
break;
|
|
1187
|
+
}
|
|
1188
|
+
case OP_CONCAT_ALL: {
|
|
1189
|
+
const executor = new ChannelExecutor(this._currentChannel.value(), this._providedEnv, (effect) => sync$8(() => {
|
|
1190
|
+
this._closeLastSubstream = pipe(this._closeLastSubstream === void 0 ? _void : this._closeLastSubstream, zipRight$8(effect));
|
|
1191
|
+
}));
|
|
1192
|
+
executor._input = this._input;
|
|
1193
|
+
const channel = this._currentChannel;
|
|
1194
|
+
this._activeSubexecutor = new PullFromUpstream(executor, (value) => channel.k(value), void 0, [], (x, y) => channel.combineInners(x, y), (x, y) => channel.combineAll(x, y), (request) => channel.onPull(request), (value) => channel.onEmit(value));
|
|
1195
|
+
this._closeLastSubstream = void 0;
|
|
1196
|
+
this._currentChannel = void 0;
|
|
1197
|
+
break;
|
|
1198
|
+
}
|
|
1199
|
+
case OP_EMIT$3:
|
|
1200
|
+
this._emitted = this._currentChannel.out;
|
|
1201
|
+
this._currentChannel = this._activeSubexecutor !== void 0 ? void 0 : void_$3;
|
|
1202
|
+
result = Emit$1();
|
|
1203
|
+
break;
|
|
1204
|
+
case OP_ENSURING:
|
|
1205
|
+
this.runEnsuring(this._currentChannel);
|
|
1206
|
+
break;
|
|
1207
|
+
case OP_FAIL$2:
|
|
1208
|
+
result = this.doneHalt(this._currentChannel.error());
|
|
1209
|
+
break;
|
|
1210
|
+
case OP_FOLD:
|
|
1211
|
+
this._doneStack.push(this._currentChannel.k);
|
|
1212
|
+
this._currentChannel = this._currentChannel.channel;
|
|
1213
|
+
break;
|
|
1214
|
+
case OP_FROM_EFFECT$1:
|
|
1215
|
+
result = fromEffect$3(matchCauseEffect(this._providedEnv === void 0 ? this._currentChannel.effect() : pipe(this._currentChannel.effect(), provide$2(this._providedEnv)), {
|
|
1216
|
+
onFailure: (cause) => {
|
|
1217
|
+
const state = this.doneHalt(cause);
|
|
1218
|
+
return state !== void 0 && isFromEffect(state) ? state.effect : _void;
|
|
1219
|
+
},
|
|
1220
|
+
onSuccess: (value) => {
|
|
1221
|
+
const state = this.doneSucceed(value);
|
|
1222
|
+
return state !== void 0 && isFromEffect(state) ? state.effect : _void;
|
|
1223
|
+
}
|
|
1224
|
+
}));
|
|
1225
|
+
break;
|
|
1226
|
+
case OP_PIPE_TO: {
|
|
1227
|
+
const previousInput = this._input;
|
|
1228
|
+
const leftExec = new ChannelExecutor(this._currentChannel.left(), this._providedEnv, (effect) => this._executeCloseLastSubstream(effect));
|
|
1229
|
+
leftExec._input = previousInput;
|
|
1230
|
+
this._input = leftExec;
|
|
1231
|
+
this.addFinalizer((exit) => {
|
|
1232
|
+
const effect = this.restorePipe(exit, previousInput);
|
|
1233
|
+
return effect !== void 0 ? effect : _void;
|
|
1234
|
+
});
|
|
1235
|
+
this._currentChannel = this._currentChannel.right();
|
|
1236
|
+
break;
|
|
1237
|
+
}
|
|
1238
|
+
case OP_PROVIDE$1: {
|
|
1239
|
+
const previousEnv = this._providedEnv;
|
|
1240
|
+
this._providedEnv = this._currentChannel.context();
|
|
1241
|
+
this._currentChannel = this._currentChannel.inner;
|
|
1242
|
+
this.addFinalizer(() => sync$8(() => {
|
|
1243
|
+
this._providedEnv = previousEnv;
|
|
1244
|
+
}));
|
|
1245
|
+
break;
|
|
1246
|
+
}
|
|
1247
|
+
case OP_READ$1: {
|
|
1248
|
+
const read = this._currentChannel;
|
|
1249
|
+
result = Read(this._input, identity$2, (emitted) => {
|
|
1250
|
+
try {
|
|
1251
|
+
this._currentChannel = read.more(emitted);
|
|
1252
|
+
} catch (error) {
|
|
1253
|
+
this._currentChannel = read.done.onExit(die$6(error));
|
|
1254
|
+
}
|
|
1255
|
+
}, (exit) => {
|
|
1256
|
+
const onExit = (exit) => {
|
|
1257
|
+
return read.done.onExit(exit);
|
|
1258
|
+
};
|
|
1259
|
+
this._currentChannel = onExit(exit);
|
|
1260
|
+
});
|
|
1261
|
+
break;
|
|
1262
|
+
}
|
|
1263
|
+
case OP_SUCCEED$2:
|
|
1264
|
+
result = this.doneSucceed(this._currentChannel.evaluate());
|
|
1265
|
+
break;
|
|
1266
|
+
case OP_SUCCEED_NOW:
|
|
1267
|
+
result = this.doneSucceed(this._currentChannel.terminal);
|
|
1268
|
+
break;
|
|
1269
|
+
case OP_SUSPEND$1:
|
|
1270
|
+
this._currentChannel = this._currentChannel.channel();
|
|
1271
|
+
break;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
} catch (error) {
|
|
1275
|
+
this._currentChannel = failCause$4(die$7(error));
|
|
1276
|
+
}
|
|
1277
|
+
return result;
|
|
1278
|
+
}
|
|
1279
|
+
getDone() {
|
|
1280
|
+
return this._done;
|
|
1281
|
+
}
|
|
1282
|
+
getEmit() {
|
|
1283
|
+
return this._emitted;
|
|
1284
|
+
}
|
|
1285
|
+
cancelWith(exit) {
|
|
1286
|
+
this._cancelled = exit;
|
|
1287
|
+
}
|
|
1288
|
+
clearInProgressFinalizer() {
|
|
1289
|
+
this._inProgressFinalizer = void 0;
|
|
1290
|
+
}
|
|
1291
|
+
storeInProgressFinalizer(finalizer) {
|
|
1292
|
+
this._inProgressFinalizer = finalizer;
|
|
1293
|
+
}
|
|
1294
|
+
popAllFinalizers(exit) {
|
|
1295
|
+
const finalizers = [];
|
|
1296
|
+
let next = this._doneStack.pop();
|
|
1297
|
+
while (next) {
|
|
1298
|
+
if (next._tag === "ContinuationFinalizer") finalizers.push(next.finalizer);
|
|
1299
|
+
next = this._doneStack.pop();
|
|
1300
|
+
}
|
|
1301
|
+
const effect = finalizers.length === 0 ? _void : runFinalizers(finalizers, exit);
|
|
1302
|
+
this.storeInProgressFinalizer(effect);
|
|
1303
|
+
return effect;
|
|
1304
|
+
}
|
|
1305
|
+
popNextFinalizers() {
|
|
1306
|
+
const builder = [];
|
|
1307
|
+
while (this._doneStack.length !== 0) {
|
|
1308
|
+
const cont = this._doneStack[this._doneStack.length - 1];
|
|
1309
|
+
if (cont._tag === "ContinuationK") return builder;
|
|
1310
|
+
builder.push(cont);
|
|
1311
|
+
this._doneStack.pop();
|
|
1312
|
+
}
|
|
1313
|
+
return builder;
|
|
1314
|
+
}
|
|
1315
|
+
restorePipe(exit, prev) {
|
|
1316
|
+
const currInput = this._input;
|
|
1317
|
+
this._input = prev;
|
|
1318
|
+
if (currInput !== void 0) return currInput.close(exit);
|
|
1319
|
+
return _void;
|
|
1320
|
+
}
|
|
1321
|
+
close(exit$1) {
|
|
1322
|
+
let runInProgressFinalizers = void 0;
|
|
1323
|
+
const finalizer = this._inProgressFinalizer;
|
|
1324
|
+
if (finalizer !== void 0) runInProgressFinalizers = pipe(finalizer, ensuring$5(sync$8(() => this.clearInProgressFinalizer())));
|
|
1325
|
+
let closeSelf = void 0;
|
|
1326
|
+
const selfFinalizers = this.popAllFinalizers(exit$1);
|
|
1327
|
+
if (selfFinalizers !== void 0) closeSelf = pipe(selfFinalizers, ensuring$5(sync$8(() => this.clearInProgressFinalizer())));
|
|
1328
|
+
const closeSubexecutors = this._activeSubexecutor === void 0 ? void 0 : this._activeSubexecutor.close(exit$1);
|
|
1329
|
+
if (closeSubexecutors === void 0 && runInProgressFinalizers === void 0 && closeSelf === void 0) return;
|
|
1330
|
+
return pipe(exit(ifNotNull(closeSubexecutors)), zip$4(exit(ifNotNull(runInProgressFinalizers))), zip$4(exit(ifNotNull(closeSelf))), map$10(([[exit1, exit2], exit3]) => pipe(exit1, zipRight$7(exit2), zipRight$7(exit3))), uninterruptible$1, flatMap$8((exit) => suspend$9(() => exit)));
|
|
1331
|
+
}
|
|
1332
|
+
doneSucceed(value) {
|
|
1333
|
+
if (this._doneStack.length === 0) {
|
|
1334
|
+
this._done = succeed$9(value);
|
|
1335
|
+
this._currentChannel = void 0;
|
|
1336
|
+
return Done$2();
|
|
1337
|
+
}
|
|
1338
|
+
const head = this._doneStack[this._doneStack.length - 1];
|
|
1339
|
+
if (head._tag === "ContinuationK") {
|
|
1340
|
+
this._doneStack.pop();
|
|
1341
|
+
this._currentChannel = head.onSuccess(value);
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
const finalizers = this.popNextFinalizers();
|
|
1345
|
+
if (this._doneStack.length === 0) {
|
|
1346
|
+
this._doneStack = finalizers.reverse();
|
|
1347
|
+
this._done = succeed$9(value);
|
|
1348
|
+
this._currentChannel = void 0;
|
|
1349
|
+
return Done$2();
|
|
1350
|
+
}
|
|
1351
|
+
const finalizerEffect = runFinalizers(finalizers.map((f) => f.finalizer), succeed$9(value));
|
|
1352
|
+
this.storeInProgressFinalizer(finalizerEffect);
|
|
1353
|
+
return fromEffect$3(pipe(finalizerEffect, ensuring$5(sync$8(() => this.clearInProgressFinalizer())), uninterruptible$1, flatMap$8(() => sync$8(() => this.doneSucceed(value)))));
|
|
1354
|
+
}
|
|
1355
|
+
doneHalt(cause) {
|
|
1356
|
+
if (this._doneStack.length === 0) {
|
|
1357
|
+
this._done = failCause$7(cause);
|
|
1358
|
+
this._currentChannel = void 0;
|
|
1359
|
+
return Done$2();
|
|
1360
|
+
}
|
|
1361
|
+
const head = this._doneStack[this._doneStack.length - 1];
|
|
1362
|
+
if (head._tag === "ContinuationK") {
|
|
1363
|
+
this._doneStack.pop();
|
|
1364
|
+
try {
|
|
1365
|
+
this._currentChannel = head.onHalt(cause);
|
|
1366
|
+
} catch (error) {
|
|
1367
|
+
this._currentChannel = failCause$4(die$7(error));
|
|
1368
|
+
}
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
const finalizers = this.popNextFinalizers();
|
|
1372
|
+
if (this._doneStack.length === 0) {
|
|
1373
|
+
this._doneStack = finalizers.reverse();
|
|
1374
|
+
this._done = failCause$7(cause);
|
|
1375
|
+
this._currentChannel = void 0;
|
|
1376
|
+
return Done$2();
|
|
1377
|
+
}
|
|
1378
|
+
const finalizerEffect = runFinalizers(finalizers.map((f) => f.finalizer), failCause$7(cause));
|
|
1379
|
+
this.storeInProgressFinalizer(finalizerEffect);
|
|
1380
|
+
return fromEffect$3(pipe(finalizerEffect, ensuring$5(sync$8(() => this.clearInProgressFinalizer())), uninterruptible$1, flatMap$8(() => sync$8(() => this.doneHalt(cause)))));
|
|
1381
|
+
}
|
|
1382
|
+
processCancellation() {
|
|
1383
|
+
this._currentChannel = void 0;
|
|
1384
|
+
this._done = this._cancelled;
|
|
1385
|
+
this._cancelled = void 0;
|
|
1386
|
+
return Done$2();
|
|
1387
|
+
}
|
|
1388
|
+
runBracketOut(bracketOut) {
|
|
1389
|
+
return fromEffect$3(uninterruptible$1(matchCauseEffect(this.provide(bracketOut.acquire()), {
|
|
1390
|
+
onFailure: (cause) => sync$8(() => {
|
|
1391
|
+
this._currentChannel = failCause$4(cause);
|
|
1392
|
+
}),
|
|
1393
|
+
onSuccess: (out) => sync$8(() => {
|
|
1394
|
+
this.addFinalizer((exit) => this.provide(bracketOut.finalizer(out, exit)));
|
|
1395
|
+
this._currentChannel = write(out);
|
|
1396
|
+
})
|
|
1397
|
+
})));
|
|
1398
|
+
}
|
|
1399
|
+
provide(effect) {
|
|
1400
|
+
if (this._providedEnv === void 0) return effect;
|
|
1401
|
+
return pipe(effect, provide$2(this._providedEnv));
|
|
1402
|
+
}
|
|
1403
|
+
runEnsuring(ensuring) {
|
|
1404
|
+
this.addFinalizer(ensuring.finalizer);
|
|
1405
|
+
this._currentChannel = ensuring.channel;
|
|
1406
|
+
}
|
|
1407
|
+
addFinalizer(f) {
|
|
1408
|
+
this._doneStack.push(new ContinuationFinalizerImpl(f));
|
|
1409
|
+
}
|
|
1410
|
+
runSubexecutor() {
|
|
1411
|
+
const subexecutor = this._activeSubexecutor;
|
|
1412
|
+
switch (subexecutor._tag) {
|
|
1413
|
+
case OP_PULL_FROM_CHILD: return this.pullFromChild(subexecutor.childExecutor, subexecutor.parentSubexecutor, subexecutor.onEmit, subexecutor);
|
|
1414
|
+
case OP_PULL_FROM_UPSTREAM: return this.pullFromUpstream(subexecutor);
|
|
1415
|
+
case OP_DRAIN_CHILD_EXECUTORS: return this.drainChildExecutors(subexecutor);
|
|
1416
|
+
case OP_EMIT$1:
|
|
1417
|
+
this._emitted = subexecutor.value;
|
|
1418
|
+
this._activeSubexecutor = subexecutor.next;
|
|
1419
|
+
return Emit$1();
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
replaceSubexecutor(nextSubExec) {
|
|
1423
|
+
this._currentChannel = void 0;
|
|
1424
|
+
this._activeSubexecutor = nextSubExec;
|
|
1425
|
+
}
|
|
1426
|
+
finishWithExit(exit) {
|
|
1427
|
+
const state = match$9(exit, {
|
|
1428
|
+
onFailure: (cause) => this.doneHalt(cause),
|
|
1429
|
+
onSuccess: (value) => this.doneSucceed(value)
|
|
1430
|
+
});
|
|
1431
|
+
this._activeSubexecutor = void 0;
|
|
1432
|
+
return state === void 0 ? _void : effect$1(state);
|
|
1433
|
+
}
|
|
1434
|
+
finishSubexecutorWithCloseEffect(subexecutorDone, ...closeFuncs) {
|
|
1435
|
+
this.addFinalizer(() => pipe(closeFuncs, forEach$2((closeFunc) => pipe(sync$8(() => closeFunc(subexecutorDone)), flatMap$8((closeEffect) => closeEffect !== void 0 ? closeEffect : _void)), { discard: true })));
|
|
1436
|
+
const state = pipe(subexecutorDone, match$9({
|
|
1437
|
+
onFailure: (cause) => this.doneHalt(cause),
|
|
1438
|
+
onSuccess: (value) => this.doneSucceed(value)
|
|
1439
|
+
}));
|
|
1440
|
+
this._activeSubexecutor = void 0;
|
|
1441
|
+
return state;
|
|
1442
|
+
}
|
|
1443
|
+
applyUpstreamPullStrategy(upstreamFinished, queue, strategy) {
|
|
1444
|
+
switch (strategy._tag) {
|
|
1445
|
+
case OP_PULL_AFTER_NEXT: {
|
|
1446
|
+
const shouldPrepend = !upstreamFinished || queue.some((subexecutor) => subexecutor !== void 0);
|
|
1447
|
+
return [strategy.emitSeparator, shouldPrepend ? [void 0, ...queue] : queue];
|
|
1448
|
+
}
|
|
1449
|
+
case OP_PULL_AFTER_ALL_ENQUEUED: {
|
|
1450
|
+
const shouldEnqueue = !upstreamFinished || queue.some((subexecutor) => subexecutor !== void 0);
|
|
1451
|
+
return [strategy.emitSeparator, shouldEnqueue ? [...queue, void 0] : queue];
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
pullFromChild(childExecutor, parentSubexecutor, onEmitted, subexecutor) {
|
|
1456
|
+
return Read(childExecutor, identity$2, (emitted) => {
|
|
1457
|
+
const childExecutorDecision = onEmitted(emitted);
|
|
1458
|
+
switch (childExecutorDecision._tag) {
|
|
1459
|
+
case OP_CONTINUE: break;
|
|
1460
|
+
case OP_CLOSE:
|
|
1461
|
+
this.finishWithDoneValue(childExecutor, parentSubexecutor, childExecutorDecision.value);
|
|
1462
|
+
break;
|
|
1463
|
+
case OP_YIELD: {
|
|
1464
|
+
const modifiedParent = parentSubexecutor.enqueuePullFromChild(subexecutor);
|
|
1465
|
+
this.replaceSubexecutor(modifiedParent);
|
|
1466
|
+
break;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
this._activeSubexecutor = new Emit(emitted, this._activeSubexecutor);
|
|
1470
|
+
}, match$9({
|
|
1471
|
+
onFailure: (cause) => {
|
|
1472
|
+
const state = this.handleSubexecutorFailure(childExecutor, parentSubexecutor, cause);
|
|
1473
|
+
return state === void 0 ? void 0 : effectOrUndefinedIgnored(state);
|
|
1474
|
+
},
|
|
1475
|
+
onSuccess: (doneValue) => {
|
|
1476
|
+
this.finishWithDoneValue(childExecutor, parentSubexecutor, doneValue);
|
|
1477
|
+
}
|
|
1478
|
+
}));
|
|
1479
|
+
}
|
|
1480
|
+
finishWithDoneValue(childExecutor, parentSubexecutor, doneValue) {
|
|
1481
|
+
const subexecutor = parentSubexecutor;
|
|
1482
|
+
switch (subexecutor._tag) {
|
|
1483
|
+
case OP_PULL_FROM_UPSTREAM: {
|
|
1484
|
+
const modifiedParent = new PullFromUpstream(subexecutor.upstreamExecutor, subexecutor.createChild, subexecutor.lastDone !== void 0 ? subexecutor.combineChildResults(subexecutor.lastDone, doneValue) : doneValue, subexecutor.activeChildExecutors, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull, subexecutor.onEmit);
|
|
1485
|
+
this._closeLastSubstream = childExecutor.close(succeed$9(doneValue));
|
|
1486
|
+
this.replaceSubexecutor(modifiedParent);
|
|
1487
|
+
break;
|
|
1488
|
+
}
|
|
1489
|
+
case OP_DRAIN_CHILD_EXECUTORS: {
|
|
1490
|
+
const modifiedParent = new DrainChildExecutors(subexecutor.upstreamExecutor, subexecutor.lastDone !== void 0 ? subexecutor.combineChildResults(subexecutor.lastDone, doneValue) : doneValue, subexecutor.activeChildExecutors, subexecutor.upstreamDone, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull);
|
|
1491
|
+
this._closeLastSubstream = childExecutor.close(succeed$9(doneValue));
|
|
1492
|
+
this.replaceSubexecutor(modifiedParent);
|
|
1493
|
+
break;
|
|
1494
|
+
}
|
|
1495
|
+
default: break;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
handleSubexecutorFailure(childExecutor, parentSubexecutor, cause) {
|
|
1499
|
+
return this.finishSubexecutorWithCloseEffect(failCause$7(cause), (exit) => parentSubexecutor.close(exit), (exit) => childExecutor.close(exit));
|
|
1500
|
+
}
|
|
1501
|
+
pullFromUpstream(subexecutor) {
|
|
1502
|
+
if (subexecutor.activeChildExecutors.length === 0) return this.performPullFromUpstream(subexecutor);
|
|
1503
|
+
const activeChild = subexecutor.activeChildExecutors[0];
|
|
1504
|
+
const parentSubexecutor = new PullFromUpstream(subexecutor.upstreamExecutor, subexecutor.createChild, subexecutor.lastDone, subexecutor.activeChildExecutors.slice(1), subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull, subexecutor.onEmit);
|
|
1505
|
+
if (activeChild === void 0) return this.performPullFromUpstream(parentSubexecutor);
|
|
1506
|
+
this.replaceSubexecutor(new PullFromChild(activeChild.childExecutor, parentSubexecutor, activeChild.onEmit));
|
|
1507
|
+
}
|
|
1508
|
+
performPullFromUpstream(subexecutor) {
|
|
1509
|
+
return Read(subexecutor.upstreamExecutor, (effect) => {
|
|
1510
|
+
const closeLastSubstream = this._closeLastSubstream === void 0 ? _void : this._closeLastSubstream;
|
|
1511
|
+
this._closeLastSubstream = void 0;
|
|
1512
|
+
return pipe(this._executeCloseLastSubstream(closeLastSubstream), zipRight$8(effect));
|
|
1513
|
+
}, (emitted) => {
|
|
1514
|
+
if (this._closeLastSubstream !== void 0) {
|
|
1515
|
+
const closeLastSubstream = this._closeLastSubstream;
|
|
1516
|
+
this._closeLastSubstream = void 0;
|
|
1517
|
+
return pipe(this._executeCloseLastSubstream(closeLastSubstream), map$10(() => {
|
|
1518
|
+
const childExecutor = new ChannelExecutor(subexecutor.createChild(emitted), this._providedEnv, this._executeCloseLastSubstream);
|
|
1519
|
+
childExecutor._input = this._input;
|
|
1520
|
+
const [emitSeparator, updatedChildExecutors] = this.applyUpstreamPullStrategy(false, subexecutor.activeChildExecutors, subexecutor.onPull(Pulled(emitted)));
|
|
1521
|
+
this._activeSubexecutor = new PullFromChild(childExecutor, new PullFromUpstream(subexecutor.upstreamExecutor, subexecutor.createChild, subexecutor.lastDone, updatedChildExecutors, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull, subexecutor.onEmit), subexecutor.onEmit);
|
|
1522
|
+
if (isSome(emitSeparator)) this._activeSubexecutor = new Emit(emitSeparator.value, this._activeSubexecutor);
|
|
1523
|
+
}));
|
|
1524
|
+
}
|
|
1525
|
+
const childExecutor = new ChannelExecutor(subexecutor.createChild(emitted), this._providedEnv, this._executeCloseLastSubstream);
|
|
1526
|
+
childExecutor._input = this._input;
|
|
1527
|
+
const [emitSeparator, updatedChildExecutors] = this.applyUpstreamPullStrategy(false, subexecutor.activeChildExecutors, subexecutor.onPull(Pulled(emitted)));
|
|
1528
|
+
this._activeSubexecutor = new PullFromChild(childExecutor, new PullFromUpstream(subexecutor.upstreamExecutor, subexecutor.createChild, subexecutor.lastDone, updatedChildExecutors, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull, subexecutor.onEmit), subexecutor.onEmit);
|
|
1529
|
+
if (isSome(emitSeparator)) this._activeSubexecutor = new Emit(emitSeparator.value, this._activeSubexecutor);
|
|
1530
|
+
}, (exit) => {
|
|
1531
|
+
if (subexecutor.activeChildExecutors.some((subexecutor) => subexecutor !== void 0)) {
|
|
1532
|
+
const drain = new DrainChildExecutors(subexecutor.upstreamExecutor, subexecutor.lastDone, [void 0, ...subexecutor.activeChildExecutors], subexecutor.upstreamExecutor.getDone(), subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull);
|
|
1533
|
+
if (this._closeLastSubstream !== void 0) {
|
|
1534
|
+
const closeLastSubstream = this._closeLastSubstream;
|
|
1535
|
+
this._closeLastSubstream = void 0;
|
|
1536
|
+
return pipe(this._executeCloseLastSubstream(closeLastSubstream), map$10(() => this.replaceSubexecutor(drain)));
|
|
1537
|
+
}
|
|
1538
|
+
this.replaceSubexecutor(drain);
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
const closeLastSubstream = this._closeLastSubstream;
|
|
1542
|
+
const state = this.finishSubexecutorWithCloseEffect(pipe(exit, map$11((a) => subexecutor.combineWithChildResult(subexecutor.lastDone, a))), () => closeLastSubstream, (exit) => subexecutor.upstreamExecutor.close(exit));
|
|
1543
|
+
return state === void 0 ? void 0 : effectOrUndefinedIgnored(state);
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
drainChildExecutors(subexecutor) {
|
|
1547
|
+
if (subexecutor.activeChildExecutors.length === 0) {
|
|
1548
|
+
const lastClose = this._closeLastSubstream;
|
|
1549
|
+
if (lastClose !== void 0) this.addFinalizer(() => succeed$10(lastClose));
|
|
1550
|
+
return this.finishSubexecutorWithCloseEffect(subexecutor.upstreamDone, () => lastClose, (exit) => subexecutor.upstreamExecutor.close(exit));
|
|
1551
|
+
}
|
|
1552
|
+
const activeChild = subexecutor.activeChildExecutors[0];
|
|
1553
|
+
const rest = subexecutor.activeChildExecutors.slice(1);
|
|
1554
|
+
if (activeChild === void 0) {
|
|
1555
|
+
const [emitSeparator, remainingExecutors] = this.applyUpstreamPullStrategy(true, rest, subexecutor.onPull(NoUpstream(rest.reduce((n, curr) => curr !== void 0 ? n + 1 : n, 0))));
|
|
1556
|
+
this.replaceSubexecutor(new DrainChildExecutors(subexecutor.upstreamExecutor, subexecutor.lastDone, remainingExecutors, subexecutor.upstreamDone, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull));
|
|
1557
|
+
if (isSome(emitSeparator)) {
|
|
1558
|
+
this._emitted = emitSeparator.value;
|
|
1559
|
+
return Emit$1();
|
|
1560
|
+
}
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
const parentSubexecutor = new DrainChildExecutors(subexecutor.upstreamExecutor, subexecutor.lastDone, rest, subexecutor.upstreamDone, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull);
|
|
1564
|
+
this.replaceSubexecutor(new PullFromChild(activeChild.childExecutor, parentSubexecutor, activeChild.onEmit));
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
const ifNotNull = (effect) => effect !== void 0 ? effect : _void;
|
|
1568
|
+
const runFinalizers = (finalizers, exit$2) => {
|
|
1569
|
+
return pipe(forEach$2(finalizers, (fin) => exit(fin(exit$2))), map$10((exits) => pipe(all$2(exits), getOrElse(() => void_$5))), flatMap$8((exit) => suspend$9(() => exit)));
|
|
1570
|
+
};
|
|
1571
|
+
/**
|
|
1572
|
+
* @internal
|
|
1573
|
+
*/
|
|
1574
|
+
const readUpstream = (r, onSuccess, onFailure) => {
|
|
1575
|
+
const readStack = [r];
|
|
1576
|
+
const read = () => {
|
|
1577
|
+
const current = readStack.pop();
|
|
1578
|
+
if (current === void 0 || current.upstream === void 0) return dieMessage$2("Unexpected end of input for channel execution");
|
|
1579
|
+
const state = current.upstream.run();
|
|
1580
|
+
switch (state._tag) {
|
|
1581
|
+
case OP_EMIT$2: {
|
|
1582
|
+
const emitEffect = current.onEmit(current.upstream.getEmit());
|
|
1583
|
+
if (readStack.length === 0) {
|
|
1584
|
+
if (emitEffect === void 0) return suspend$9(onSuccess);
|
|
1585
|
+
return pipe(emitEffect, matchCauseEffect({
|
|
1586
|
+
onFailure,
|
|
1587
|
+
onSuccess
|
|
1588
|
+
}));
|
|
1589
|
+
}
|
|
1590
|
+
if (emitEffect === void 0) return suspend$9(() => read());
|
|
1591
|
+
return pipe(emitEffect, matchCauseEffect({
|
|
1592
|
+
onFailure,
|
|
1593
|
+
onSuccess: () => read()
|
|
1594
|
+
}));
|
|
1595
|
+
}
|
|
1596
|
+
case OP_DONE$3: {
|
|
1597
|
+
const doneEffect = current.onDone(current.upstream.getDone());
|
|
1598
|
+
if (readStack.length === 0) {
|
|
1599
|
+
if (doneEffect === void 0) return suspend$9(onSuccess);
|
|
1600
|
+
return pipe(doneEffect, matchCauseEffect({
|
|
1601
|
+
onFailure,
|
|
1602
|
+
onSuccess
|
|
1603
|
+
}));
|
|
1604
|
+
}
|
|
1605
|
+
if (doneEffect === void 0) return suspend$9(() => read());
|
|
1606
|
+
return pipe(doneEffect, matchCauseEffect({
|
|
1607
|
+
onFailure,
|
|
1608
|
+
onSuccess: () => read()
|
|
1609
|
+
}));
|
|
1610
|
+
}
|
|
1611
|
+
case OP_FROM_EFFECT:
|
|
1612
|
+
readStack.push(current);
|
|
1613
|
+
return pipe(current.onEffect(state.effect), catchAllCause$5((cause) => suspend$9(() => {
|
|
1614
|
+
const doneEffect = current.onDone(failCause$7(cause));
|
|
1615
|
+
return doneEffect === void 0 ? _void : doneEffect;
|
|
1616
|
+
})), matchCauseEffect({
|
|
1617
|
+
onFailure,
|
|
1618
|
+
onSuccess: () => read()
|
|
1619
|
+
}));
|
|
1620
|
+
case OP_READ:
|
|
1621
|
+
readStack.push(current);
|
|
1622
|
+
readStack.push(state);
|
|
1623
|
+
return suspend$9(() => read());
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
return read();
|
|
1627
|
+
};
|
|
1628
|
+
/** @internal */
|
|
1629
|
+
const runIn = /* @__PURE__ */ dual(2, (self, scope) => {
|
|
1630
|
+
const run = (channelDeferred, scopeDeferred, scope) => acquireUseRelease$1(sync$8(() => new ChannelExecutor(self, void 0, identity$2)), (exec) => suspend$9(() => runScopedInterpret(exec.run(), exec).pipe(intoDeferred(channelDeferred), zipRight$8(_await(channelDeferred)), zipLeft$4(_await(scopeDeferred)))), (exec, exit) => {
|
|
1631
|
+
const finalize = exec.close(exit);
|
|
1632
|
+
if (finalize === void 0) return _void;
|
|
1633
|
+
return tapErrorCause$4(finalize, (cause) => addFinalizer$1(scope, failCause$8(cause)));
|
|
1634
|
+
});
|
|
1635
|
+
return uninterruptibleMask((restore) => all$3([
|
|
1636
|
+
fork(scope, sequential$1),
|
|
1637
|
+
make$17(),
|
|
1638
|
+
make$17()
|
|
1639
|
+
]).pipe(flatMap$8(([child, channelDeferred, scopeDeferred]) => restore(run(channelDeferred, scopeDeferred, child)).pipe(forkIn(scope), flatMap$8((fiber) => scope.addFinalizer((exit) => {
|
|
1640
|
+
const interruptors$1 = isFailure(exit) ? interruptors(exit.cause) : void 0;
|
|
1641
|
+
return isDone$1(channelDeferred).pipe(flatMap$8((isDone) => isDone ? succeed$11(scopeDeferred, void 0).pipe(zipRight$8(_await$1(fiber)), zipRight$8(inheritAll(fiber))) : succeed$11(scopeDeferred, void 0).pipe(zipRight$8(interruptors$1 && size$8(interruptors$1) > 0 ? interruptAs$1(fiber, combineAll(interruptors$1)) : interrupt$2(fiber)), zipRight$8(inheritAll(fiber)))));
|
|
1642
|
+
}).pipe(zipRight$8(restore(_await(channelDeferred)))))))));
|
|
1643
|
+
});
|
|
1644
|
+
/** @internal */
|
|
1645
|
+
const runScopedInterpret = (channelState, exec) => {
|
|
1646
|
+
const op = channelState;
|
|
1647
|
+
switch (op._tag) {
|
|
1648
|
+
case OP_FROM_EFFECT: return pipe(op.effect, flatMap$8(() => runScopedInterpret(exec.run(), exec)));
|
|
1649
|
+
case OP_EMIT$2: return runScopedInterpret(exec.run(), exec);
|
|
1650
|
+
case OP_DONE$3: return suspend$9(() => exec.getDone());
|
|
1651
|
+
case OP_READ: return readUpstream(op, () => runScopedInterpret(exec.run(), exec), failCause$8);
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
//#endregion
|
|
1655
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/channelMergeDecision.js
|
|
1656
|
+
/** @internal */
|
|
1657
|
+
const OP_DONE$2 = "Done";
|
|
1658
|
+
/** @internal */
|
|
1659
|
+
const OP_AWAIT = "Await";
|
|
1660
|
+
/** @internal */
|
|
1661
|
+
const proto$2 = { [/* @__PURE__ */ Symbol.for("effect/ChannelMergeDecision")]: {
|
|
1662
|
+
_R: (_) => _,
|
|
1663
|
+
_E0: (_) => _,
|
|
1664
|
+
_Z0: (_) => _,
|
|
1665
|
+
_E: (_) => _,
|
|
1666
|
+
_Z: (_) => _
|
|
1667
|
+
} };
|
|
1668
|
+
/** @internal */
|
|
1669
|
+
const Done$1 = (effect) => {
|
|
1670
|
+
const op = Object.create(proto$2);
|
|
1671
|
+
op._tag = OP_DONE$2;
|
|
1672
|
+
op.effect = effect;
|
|
1673
|
+
return op;
|
|
1674
|
+
};
|
|
1675
|
+
/** @internal */
|
|
1676
|
+
const Await$1 = (f) => {
|
|
1677
|
+
const op = Object.create(proto$2);
|
|
1678
|
+
op._tag = OP_AWAIT;
|
|
1679
|
+
op.f = f;
|
|
1680
|
+
return op;
|
|
1681
|
+
};
|
|
1682
|
+
//#endregion
|
|
1683
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/channelMergeState.js
|
|
1684
|
+
/** @internal */
|
|
1685
|
+
const OP_BOTH_RUNNING = "BothRunning";
|
|
1686
|
+
/** @internal */
|
|
1687
|
+
const OP_LEFT_DONE = "LeftDone";
|
|
1688
|
+
/** @internal */
|
|
1689
|
+
const OP_RIGHT_DONE = "RightDone";
|
|
1690
|
+
/** @internal */
|
|
1691
|
+
const MergeStateTypeId = /* @__PURE__ */ Symbol.for("effect/ChannelMergeState");
|
|
1692
|
+
/** @internal */
|
|
1693
|
+
const proto$1 = { [MergeStateTypeId]: MergeStateTypeId };
|
|
1694
|
+
/** @internal */
|
|
1695
|
+
const BothRunning = (left, right) => {
|
|
1696
|
+
const op = Object.create(proto$1);
|
|
1697
|
+
op._tag = OP_BOTH_RUNNING;
|
|
1698
|
+
op.left = left;
|
|
1699
|
+
op.right = right;
|
|
1700
|
+
return op;
|
|
1701
|
+
};
|
|
1702
|
+
/** @internal */
|
|
1703
|
+
const LeftDone = (f) => {
|
|
1704
|
+
const op = Object.create(proto$1);
|
|
1705
|
+
op._tag = OP_LEFT_DONE;
|
|
1706
|
+
op.f = f;
|
|
1707
|
+
return op;
|
|
1708
|
+
};
|
|
1709
|
+
/** @internal */
|
|
1710
|
+
const RightDone = (f) => {
|
|
1711
|
+
const op = Object.create(proto$1);
|
|
1712
|
+
op._tag = OP_RIGHT_DONE;
|
|
1713
|
+
op.f = f;
|
|
1714
|
+
return op;
|
|
1715
|
+
};
|
|
1716
|
+
//#endregion
|
|
1717
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/channelMergeStrategy.js
|
|
1718
|
+
/** @internal */
|
|
1719
|
+
const OP_BACK_PRESSURE = "BackPressure";
|
|
1720
|
+
/** @internal */
|
|
1721
|
+
const OP_BUFFER_SLIDING = "BufferSliding";
|
|
1722
|
+
/** @internal */
|
|
1723
|
+
const MergeStrategyTypeId = /* @__PURE__ */ Symbol.for("effect/ChannelMergeStrategy");
|
|
1724
|
+
/** @internal */
|
|
1725
|
+
const proto = { [MergeStrategyTypeId]: MergeStrategyTypeId };
|
|
1726
|
+
/** @internal */
|
|
1727
|
+
const BackPressure$1 = (_) => {
|
|
1728
|
+
const op = Object.create(proto);
|
|
1729
|
+
op._tag = OP_BACK_PRESSURE;
|
|
1730
|
+
return op;
|
|
1731
|
+
};
|
|
1732
|
+
/** @internal */
|
|
1733
|
+
const BufferSliding = (_) => {
|
|
1734
|
+
const op = Object.create(proto);
|
|
1735
|
+
op._tag = OP_BUFFER_SLIDING;
|
|
1736
|
+
return op;
|
|
1737
|
+
};
|
|
1738
|
+
/** @internal */
|
|
1739
|
+
const match$4 = /* @__PURE__ */ dual(2, (self, { onBackPressure, onBufferSliding }) => {
|
|
1740
|
+
switch (self._tag) {
|
|
1741
|
+
case OP_BACK_PRESSURE: return onBackPressure();
|
|
1742
|
+
case OP_BUFFER_SLIDING: return onBufferSliding();
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
//#endregion
|
|
1746
|
+
//#region ../../node_modules/effect/dist/esm/internal/channel/singleProducerAsyncInput.js
|
|
1747
|
+
/** @internal */
|
|
1748
|
+
const OP_STATE_EMPTY = "Empty";
|
|
1749
|
+
/** @internal */
|
|
1750
|
+
const OP_STATE_EMIT = "Emit";
|
|
1751
|
+
/** @internal */
|
|
1752
|
+
const OP_STATE_ERROR = "Error";
|
|
1753
|
+
/** @internal */
|
|
1754
|
+
const OP_STATE_DONE = "Done";
|
|
1755
|
+
/** @internal */
|
|
1756
|
+
const stateEmpty$1 = (notifyProducer) => ({
|
|
1757
|
+
_tag: OP_STATE_EMPTY,
|
|
1758
|
+
notifyProducer
|
|
1759
|
+
});
|
|
1760
|
+
/** @internal */
|
|
1761
|
+
const stateEmit = (notifyConsumers) => ({
|
|
1762
|
+
_tag: OP_STATE_EMIT,
|
|
1763
|
+
notifyConsumers
|
|
1764
|
+
});
|
|
1765
|
+
/** @internal */
|
|
1766
|
+
const stateError = (cause) => ({
|
|
1767
|
+
_tag: OP_STATE_ERROR,
|
|
1768
|
+
cause
|
|
1769
|
+
});
|
|
1770
|
+
/** @internal */
|
|
1771
|
+
const stateDone = (done) => ({
|
|
1772
|
+
_tag: OP_STATE_DONE,
|
|
1773
|
+
done
|
|
1774
|
+
});
|
|
1775
|
+
/** @internal */
|
|
1776
|
+
var SingleProducerAsyncInputImpl = class {
|
|
1777
|
+
ref;
|
|
1778
|
+
constructor(ref) {
|
|
1779
|
+
this.ref = ref;
|
|
1780
|
+
}
|
|
1781
|
+
awaitRead() {
|
|
1782
|
+
return flatten$6(modify$1(this.ref, (state) => state._tag === OP_STATE_EMPTY ? [_await(state.notifyProducer), state] : [_void, state]));
|
|
1783
|
+
}
|
|
1784
|
+
get close() {
|
|
1785
|
+
return fiberIdWith((fiberId) => this.error(interrupt$3(fiberId)));
|
|
1786
|
+
}
|
|
1787
|
+
done(value) {
|
|
1788
|
+
return flatten$6(modify$1(this.ref, (state) => {
|
|
1789
|
+
switch (state._tag) {
|
|
1790
|
+
case OP_STATE_EMPTY: return [_await(state.notifyProducer), state];
|
|
1791
|
+
case OP_STATE_EMIT: return [forEach$2(state.notifyConsumers, (deferred) => succeed$11(deferred, left(value)), { discard: true }), stateDone(value)];
|
|
1792
|
+
case OP_STATE_ERROR: return [interrupt$4, state];
|
|
1793
|
+
case OP_STATE_DONE: return [interrupt$4, state];
|
|
1794
|
+
}
|
|
1795
|
+
}));
|
|
1796
|
+
}
|
|
1797
|
+
emit(element) {
|
|
1798
|
+
return flatMap$8(make$17(), (deferred) => flatten$6(modify$1(this.ref, (state) => {
|
|
1799
|
+
switch (state._tag) {
|
|
1800
|
+
case OP_STATE_EMPTY: return [_await(state.notifyProducer), state];
|
|
1801
|
+
case OP_STATE_EMIT: {
|
|
1802
|
+
const notifyConsumer = state.notifyConsumers[0];
|
|
1803
|
+
const notifyConsumers = state.notifyConsumers.slice(1);
|
|
1804
|
+
if (notifyConsumer !== void 0) return [succeed$11(notifyConsumer, right(element)), notifyConsumers.length === 0 ? stateEmpty$1(deferred) : stateEmit(notifyConsumers)];
|
|
1805
|
+
throw new Error("Bug: Channel.SingleProducerAsyncInput.emit - Queue was empty! please report an issue at https://github.com/Effect-TS/effect/issues");
|
|
1806
|
+
}
|
|
1807
|
+
case OP_STATE_ERROR: return [interrupt$4, state];
|
|
1808
|
+
case OP_STATE_DONE: return [interrupt$4, state];
|
|
1809
|
+
}
|
|
1810
|
+
})));
|
|
1811
|
+
}
|
|
1812
|
+
error(cause) {
|
|
1813
|
+
return flatten$6(modify$1(this.ref, (state) => {
|
|
1814
|
+
switch (state._tag) {
|
|
1815
|
+
case OP_STATE_EMPTY: return [_await(state.notifyProducer), state];
|
|
1816
|
+
case OP_STATE_EMIT: return [forEach$2(state.notifyConsumers, (deferred) => failCause$9(deferred, cause), { discard: true }), stateError(cause)];
|
|
1817
|
+
case OP_STATE_ERROR: return [interrupt$4, state];
|
|
1818
|
+
case OP_STATE_DONE: return [interrupt$4, state];
|
|
1819
|
+
}
|
|
1820
|
+
}));
|
|
1821
|
+
}
|
|
1822
|
+
get take() {
|
|
1823
|
+
return this.takeWith((cause) => failCause$7(map$12(cause, left)), (elem) => succeed$9(elem), (done) => fail$9(right(done)));
|
|
1824
|
+
}
|
|
1825
|
+
takeWith(onError, onElement, onDone) {
|
|
1826
|
+
return flatMap$8(make$17(), (deferred) => flatten$6(modify$1(this.ref, (state) => {
|
|
1827
|
+
switch (state._tag) {
|
|
1828
|
+
case OP_STATE_EMPTY: return [zipRight$8(succeed$11(state.notifyProducer, void 0), matchCause$2(_await(deferred), {
|
|
1829
|
+
onFailure: onError,
|
|
1830
|
+
onSuccess: match$8({
|
|
1831
|
+
onLeft: onDone,
|
|
1832
|
+
onRight: onElement
|
|
1833
|
+
})
|
|
1834
|
+
})), stateEmit([deferred])];
|
|
1835
|
+
case OP_STATE_EMIT: return [matchCause$2(_await(deferred), {
|
|
1836
|
+
onFailure: onError,
|
|
1837
|
+
onSuccess: match$8({
|
|
1838
|
+
onLeft: onDone,
|
|
1839
|
+
onRight: onElement
|
|
1840
|
+
})
|
|
1841
|
+
}), stateEmit([...state.notifyConsumers, deferred])];
|
|
1842
|
+
case OP_STATE_ERROR: return [succeed$10(onError(state.cause)), state];
|
|
1843
|
+
case OP_STATE_DONE: return [succeed$10(onDone(state.done)), state];
|
|
1844
|
+
}
|
|
1845
|
+
})));
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
/** @internal */
|
|
1849
|
+
const make$11 = () => pipe(make$17(), flatMap$8((deferred) => make$18(stateEmpty$1(deferred))), map$10((ref) => new SingleProducerAsyncInputImpl(ref)));
|
|
1850
|
+
/** @internal */
|
|
1851
|
+
const as$4 = /* @__PURE__ */ dual(2, (self, value) => map$6(self, () => value));
|
|
1852
|
+
/** @internal */
|
|
1853
|
+
const catchAll$3 = /* @__PURE__ */ dual(2, (self, f) => catchAllCause$2(self, (cause) => match$8(failureOrCause(cause), {
|
|
1854
|
+
onLeft: f,
|
|
1855
|
+
onRight: failCause$4
|
|
1856
|
+
})));
|
|
1857
|
+
/** @internal */
|
|
1858
|
+
const concatMap$1 = /* @__PURE__ */ dual(2, (self, f) => concatMapWith(self, f, () => void 0, () => void 0));
|
|
1859
|
+
/** @internal */
|
|
1860
|
+
const drain$3 = (self) => {
|
|
1861
|
+
const drainer = readWithCause({
|
|
1862
|
+
onInput: () => drainer,
|
|
1863
|
+
onFailure: failCause$4,
|
|
1864
|
+
onDone: succeed$5
|
|
1865
|
+
});
|
|
1866
|
+
return pipeTo(self, drainer);
|
|
1867
|
+
};
|
|
1868
|
+
/** @internal */
|
|
1869
|
+
const ensuring$4 = /* @__PURE__ */ dual(2, (self, finalizer) => ensuringWith$2(self, () => finalizer));
|
|
1870
|
+
/** @internal */
|
|
1871
|
+
const flatten$3 = (self) => flatMap$4(self, identity$2);
|
|
1872
|
+
/** @internal */
|
|
1873
|
+
const fromInput$2 = (input) => unwrap$2(input.takeWith(failCause$4, (elem) => flatMap$4(write(elem), () => fromInput$2(input)), succeed$5));
|
|
1874
|
+
/** @internal */
|
|
1875
|
+
const fromQueueInternal = (queue) => pipe(fromEffect$4(take$6(queue)), flatMap$4(match$8({
|
|
1876
|
+
onLeft: match$9({
|
|
1877
|
+
onFailure: failCause$4,
|
|
1878
|
+
onSuccess: succeedNow
|
|
1879
|
+
}),
|
|
1880
|
+
onRight: (elem) => flatMap$4(write(elem), () => fromQueueInternal(queue))
|
|
1881
|
+
})));
|
|
1882
|
+
/** @internal */
|
|
1883
|
+
const identityChannel = () => readWith({
|
|
1884
|
+
onInput: (input) => flatMap$4(write(input), () => identityChannel()),
|
|
1885
|
+
onFailure: fail$5,
|
|
1886
|
+
onDone: succeedNow
|
|
1887
|
+
});
|
|
1888
|
+
/** @internal */
|
|
1889
|
+
const map$6 = /* @__PURE__ */ dual(2, (self, f) => flatMap$4(self, (a) => sync$4(() => f(a))));
|
|
1890
|
+
/** @internal */
|
|
1891
|
+
const mapOut = /* @__PURE__ */ dual(2, (self, f) => {
|
|
1892
|
+
const reader = readWith({
|
|
1893
|
+
onInput: (outElem) => flatMap$4(write(f(outElem)), () => reader),
|
|
1894
|
+
onFailure: fail$5,
|
|
1895
|
+
onDone: succeedNow
|
|
1896
|
+
});
|
|
1897
|
+
return pipeTo(self, reader);
|
|
1898
|
+
});
|
|
1899
|
+
/** @internal */
|
|
1900
|
+
const mergeAll$3 = (options) => {
|
|
1901
|
+
return (channels) => mergeAllWith(options)(channels, constVoid);
|
|
1902
|
+
};
|
|
1903
|
+
/** @internal */
|
|
1904
|
+
const mergeAllWith = ({ bufferSize = 16, concurrency, mergeStrategy = BackPressure$1() }) => (channels, f) => unwrapScopedWith$3((scope) => gen(function* () {
|
|
1905
|
+
const concurrencyN = concurrency === "unbounded" ? Number.MAX_SAFE_INTEGER : concurrency;
|
|
1906
|
+
const input = yield* make$11();
|
|
1907
|
+
const queueReader = fromInput$2(input);
|
|
1908
|
+
const queue = yield* bounded$4(bufferSize);
|
|
1909
|
+
yield* addFinalizer$1(scope, shutdown$4(queue));
|
|
1910
|
+
const cancelers = yield* unbounded$4();
|
|
1911
|
+
yield* addFinalizer$1(scope, shutdown$4(cancelers));
|
|
1912
|
+
const lastDone = yield* make$18(none());
|
|
1913
|
+
const errorSignal = yield* make$17();
|
|
1914
|
+
const withPermits = (yield* makeSemaphore(concurrencyN)).withPermits;
|
|
1915
|
+
const pull = yield* toPullIn(pipeTo(queueReader, channels), scope);
|
|
1916
|
+
function evaluatePull(pull) {
|
|
1917
|
+
return pull.pipe(flatMap$8(match$8({
|
|
1918
|
+
onLeft: (done) => succeed$10(some$2(done)),
|
|
1919
|
+
onRight: (outElem) => as$5(offer$3(queue, succeed$10(right(outElem))), none())
|
|
1920
|
+
})), repeat$3({ until: (_) => isSome(_) }), flatMap$8((outDone) => update$1(lastDone, match$10({
|
|
1921
|
+
onNone: () => some$2(outDone.value),
|
|
1922
|
+
onSome: (lastDone) => some$2(f(lastDone, outDone.value))
|
|
1923
|
+
}))), catchAllCause$5((cause) => isInterrupted(cause) ? failCause$8(cause) : offer$3(queue, failCause$8(cause)).pipe(zipRight$8(succeed$11(errorSignal, void 0)), asVoid$2)));
|
|
1924
|
+
}
|
|
1925
|
+
yield* pull.pipe(matchCauseEffect({
|
|
1926
|
+
onFailure: (cause) => offer$3(queue, failCause$8(cause)).pipe(zipRight$8(succeed$10(false))),
|
|
1927
|
+
onSuccess: match$8({
|
|
1928
|
+
onLeft: (outDone) => raceWith$1(interruptible(_await(errorSignal)), interruptible(withPermits(concurrencyN)(_void)), {
|
|
1929
|
+
onSelfDone: (_, permitAcquisition) => as$5(interrupt$2(permitAcquisition), false),
|
|
1930
|
+
onOtherDone: (_, failureAwait) => zipRight$8(interrupt$2(failureAwait), get$5(lastDone).pipe(flatMap$8(match$10({
|
|
1931
|
+
onNone: () => offer$3(queue, succeed$10(left(outDone))),
|
|
1932
|
+
onSome: (lastDone) => offer$3(queue, succeed$10(left(f(lastDone, outDone))))
|
|
1933
|
+
})), as$5(false)))
|
|
1934
|
+
}),
|
|
1935
|
+
onRight: (channel) => match$4(mergeStrategy, {
|
|
1936
|
+
onBackPressure: () => gen(function* () {
|
|
1937
|
+
const latch = yield* make$17();
|
|
1938
|
+
const raceEffects = scopedWith$3((scope) => toPullIn(pipeTo(queueReader, channel), scope).pipe(flatMap$8((pull) => race$3(exit(evaluatePull(pull)), exit(interruptible(_await(errorSignal))))), flatMap$8(identity$2)));
|
|
1939
|
+
yield* succeed$11(latch, void 0).pipe(zipRight$8(raceEffects), withPermits(1), forkIn(scope));
|
|
1940
|
+
yield* _await(latch);
|
|
1941
|
+
return !(yield* isDone$1(errorSignal));
|
|
1942
|
+
}),
|
|
1943
|
+
onBufferSliding: () => gen(function* () {
|
|
1944
|
+
const canceler = yield* make$17();
|
|
1945
|
+
const latch = yield* make$17();
|
|
1946
|
+
const size = yield* size$4(cancelers);
|
|
1947
|
+
yield* take$6(cancelers).pipe(flatMap$8((canceler) => succeed$11(canceler, void 0)), when$2(() => size >= concurrencyN));
|
|
1948
|
+
yield* offer$3(cancelers, canceler);
|
|
1949
|
+
const raceEffects = scopedWith$3((scope) => toPullIn(pipeTo(queueReader, channel), scope).pipe(flatMap$8((pull) => exit(evaluatePull(pull)).pipe(race$3(exit(interruptible(_await(errorSignal)))), race$3(exit(interruptible(_await(canceler)))))), flatMap$8(identity$2)));
|
|
1950
|
+
yield* succeed$11(latch, void 0).pipe(zipRight$8(raceEffects), withPermits(1), forkIn(scope));
|
|
1951
|
+
yield* _await(latch);
|
|
1952
|
+
return !(yield* isDone$1(errorSignal));
|
|
1953
|
+
})
|
|
1954
|
+
})
|
|
1955
|
+
})
|
|
1956
|
+
}), repeat$3({ while: (_) => _ }), forkIn(scope));
|
|
1957
|
+
const consumer = pipe(take$6(queue), flatten$6, matchCause$2({
|
|
1958
|
+
onFailure: failCause$4,
|
|
1959
|
+
onSuccess: match$8({
|
|
1960
|
+
onLeft: succeedNow,
|
|
1961
|
+
onRight: (outElem) => flatMap$4(write(outElem), () => consumer)
|
|
1962
|
+
})
|
|
1963
|
+
}), unwrap$2);
|
|
1964
|
+
return embedInput(consumer, input);
|
|
1965
|
+
}));
|
|
1966
|
+
/** @internal */
|
|
1967
|
+
const mergeMap$1 = /* @__PURE__ */ dual(3, (self, f, options) => mergeAll$3(options)(mapOut(self, f)));
|
|
1968
|
+
/** @internal */
|
|
1969
|
+
const mergeWith$2 = /* @__PURE__ */ dual(2, (self, options) => {
|
|
1970
|
+
function merge(scope) {
|
|
1971
|
+
return gen(function* () {
|
|
1972
|
+
const input = yield* make$11();
|
|
1973
|
+
const queueReader = fromInput$2(input);
|
|
1974
|
+
const pullL = yield* toPullIn(pipeTo(queueReader, self), scope);
|
|
1975
|
+
const pullR = yield* toPullIn(pipeTo(queueReader, options.other), scope);
|
|
1976
|
+
function handleSide(exit, fiber, pull) {
|
|
1977
|
+
return (done, both, single) => {
|
|
1978
|
+
function onDecision(decision) {
|
|
1979
|
+
const op = decision;
|
|
1980
|
+
if (op._tag === "Done") return succeed$10(fromEffect$4(zipRight$8(interrupt$2(fiber), op.effect)));
|
|
1981
|
+
return map$10(_await$1(fiber), match$9({
|
|
1982
|
+
onFailure: (cause) => fromEffect$4(op.f(failCause$7(cause))),
|
|
1983
|
+
onSuccess: match$8({
|
|
1984
|
+
onLeft: (done) => fromEffect$4(op.f(succeed$9(done))),
|
|
1985
|
+
onRight: (elem) => zipRight$5(write(elem), go(single(op.f)))
|
|
1986
|
+
})
|
|
1987
|
+
}));
|
|
1988
|
+
}
|
|
1989
|
+
return match$9(exit, {
|
|
1990
|
+
onFailure: (cause) => onDecision(done(failCause$7(cause))),
|
|
1991
|
+
onSuccess: match$8({
|
|
1992
|
+
onLeft: (z) => onDecision(done(succeed$9(z))),
|
|
1993
|
+
onRight: (elem) => succeed$10(flatMap$4(write(elem), () => flatMap$4(fromEffect$4(forkIn(interruptible(pull), scope)), (leftFiber) => go(both(leftFiber, fiber)))))
|
|
1994
|
+
})
|
|
1995
|
+
});
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
function go(state) {
|
|
1999
|
+
switch (state._tag) {
|
|
2000
|
+
case OP_BOTH_RUNNING: return unwrap$2(raceWith$1(interruptible(join(state.left)), interruptible(join(state.right)), {
|
|
2001
|
+
onSelfDone: (leftExit, rf) => zipRight$8(interrupt$2(rf), handleSide(leftExit, state.right, pullL)(options.onSelfDone, BothRunning, (f) => LeftDone(f))),
|
|
2002
|
+
onOtherDone: (rightExit, lf) => zipRight$8(interrupt$2(lf), handleSide(rightExit, state.left, pullR)(options.onOtherDone, (left, right) => BothRunning(right, left), (f) => RightDone(f)))
|
|
2003
|
+
}));
|
|
2004
|
+
case OP_LEFT_DONE: return unwrap$2(map$10(exit(pullR), match$9({
|
|
2005
|
+
onFailure: (cause) => fromEffect$4(state.f(failCause$7(cause))),
|
|
2006
|
+
onSuccess: match$8({
|
|
2007
|
+
onLeft: (done) => fromEffect$4(state.f(succeed$9(done))),
|
|
2008
|
+
onRight: (elem) => flatMap$4(write(elem), () => go(LeftDone(state.f)))
|
|
2009
|
+
})
|
|
2010
|
+
})));
|
|
2011
|
+
case OP_RIGHT_DONE: return unwrap$2(map$10(exit(pullL), match$9({
|
|
2012
|
+
onFailure: (cause) => fromEffect$4(state.f(failCause$7(cause))),
|
|
2013
|
+
onSuccess: match$8({
|
|
2014
|
+
onLeft: (done) => fromEffect$4(state.f(succeed$9(done))),
|
|
2015
|
+
onRight: (elem) => flatMap$4(write(elem), () => go(RightDone(state.f)))
|
|
2016
|
+
})
|
|
2017
|
+
})));
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
return fromEffect$4(withFiberRuntime$1((parent) => {
|
|
2021
|
+
const inherit = withFiberRuntime$1((state) => {
|
|
2022
|
+
state.transferChildren(parent.scope());
|
|
2023
|
+
return _void;
|
|
2024
|
+
});
|
|
2025
|
+
return zipWith$7(interruptible(pullL).pipe(ensuring$5(inherit), forkIn(scope)), interruptible(pullR).pipe(ensuring$5(inherit), forkIn(scope)), (left, right) => BothRunning(left, right));
|
|
2026
|
+
})).pipe(flatMap$4(go), embedInput(input));
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2029
|
+
return unwrapScopedWith$3(merge);
|
|
2030
|
+
});
|
|
2031
|
+
/** @internal */
|
|
2032
|
+
const pipeToOrFail = /* @__PURE__ */ dual(2, (self, that) => suspend$5(() => {
|
|
2033
|
+
let channelException = void 0;
|
|
2034
|
+
const reader = readWith({
|
|
2035
|
+
onInput: (outElem) => flatMap$4(write(outElem), () => reader),
|
|
2036
|
+
onFailure: (outErr) => {
|
|
2037
|
+
channelException = ChannelException(outErr);
|
|
2038
|
+
return failCause$4(die$7(channelException));
|
|
2039
|
+
},
|
|
2040
|
+
onDone: succeedNow
|
|
2041
|
+
});
|
|
2042
|
+
const writer = readWithCause({
|
|
2043
|
+
onInput: (outElem) => pipe(write(outElem), flatMap$4(() => writer)),
|
|
2044
|
+
onFailure: (cause) => isDieType(cause) && isChannelException(cause.defect) && equals(cause.defect, channelException) ? fail$5(cause.defect.error) : failCause$4(cause),
|
|
2045
|
+
onDone: succeedNow
|
|
2046
|
+
});
|
|
2047
|
+
return pipeTo(pipeTo(pipeTo(self, reader), that), writer);
|
|
2048
|
+
}));
|
|
2049
|
+
/** @internal */
|
|
2050
|
+
const repeated = (self) => flatMap$4(self, () => repeated(self));
|
|
2051
|
+
/** @internal */
|
|
2052
|
+
const run$3 = (self) => scopedWith$3((scope) => runIn(self, scope));
|
|
2053
|
+
/** @internal */
|
|
2054
|
+
const runDrain$2 = (self) => run$3(drain$3(self));
|
|
2055
|
+
/** @internal */
|
|
2056
|
+
const scoped$2 = (effect) => unwrap$2(uninterruptibleMask((restore) => map$10(make$19(), (scope) => acquireReleaseOut(tapErrorCause$4(restore(extend(effect, scope)), (cause) => close(scope, failCause$7(cause))), (_, exit) => close(scope, exit)))));
|
|
2057
|
+
/** @internal */
|
|
2058
|
+
const scopedWith$2 = (f) => unwrapScoped$2(map$10(scope$2, (scope) => flatMap$4(fromEffect$4(f(scope)), write)));
|
|
2059
|
+
/** @internal */
|
|
2060
|
+
const toPull$2 = (self) => flatMap$8(scope$2, (scope) => toPullIn(self, scope));
|
|
2061
|
+
/** @internal */
|
|
2062
|
+
const toPullIn = /* @__PURE__ */ dual(2, (self, scope) => zip$4(sync$8(() => new ChannelExecutor(self, void 0, identity$2)), runtime()).pipe(tap$7(([executor, runtime]) => addFinalizerExit(scope, (exit) => {
|
|
2063
|
+
const finalizer = executor.close(exit);
|
|
2064
|
+
return finalizer !== void 0 ? provide$2(finalizer, runtime) : _void;
|
|
2065
|
+
})), uninterruptible$1, map$10(([executor]) => suspend$9(() => interpretToPull(executor.run(), executor)))));
|
|
2066
|
+
/** @internal */
|
|
2067
|
+
const interpretToPull = (channelState, exec) => {
|
|
2068
|
+
const state = channelState;
|
|
2069
|
+
switch (state._tag) {
|
|
2070
|
+
case OP_DONE$3: return match$9(exec.getDone(), {
|
|
2071
|
+
onFailure: failCause$8,
|
|
2072
|
+
onSuccess: (done) => succeed$10(left(done))
|
|
2073
|
+
});
|
|
2074
|
+
case OP_EMIT$2: return succeed$10(right(exec.getEmit()));
|
|
2075
|
+
case OP_FROM_EFFECT: return pipe(state.effect, flatMap$8(() => interpretToPull(exec.run(), exec)));
|
|
2076
|
+
case OP_READ: return readUpstream(state, () => interpretToPull(exec.run(), exec), (cause) => failCause$8(cause));
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
/** @internal */
|
|
2080
|
+
const toQueueInternal = (queue) => {
|
|
2081
|
+
return readWithCause({
|
|
2082
|
+
onInput: (elem) => flatMap$4(fromEffect$4(offer$3(queue, right(elem))), () => toQueueInternal(queue)),
|
|
2083
|
+
onFailure: (cause) => fromEffect$4(offer$3(queue, left(failCause$7(cause)))),
|
|
2084
|
+
onDone: (done) => fromEffect$4(offer$3(queue, left(succeed$9(done))))
|
|
2085
|
+
});
|
|
2086
|
+
};
|
|
2087
|
+
/** @internal */
|
|
2088
|
+
const unwrap$2 = (channel) => flatten$3(fromEffect$4(channel));
|
|
2089
|
+
/** @internal */
|
|
2090
|
+
const unwrapScoped$2 = (self) => concatAllWith(scoped$2(self), (d, _) => d, (d, _) => d);
|
|
2091
|
+
/** @internal */
|
|
2092
|
+
const unwrapScopedWith$3 = (f) => concatAllWith(scopedWith$2(f), (d, _) => d, (d, _) => d);
|
|
2093
|
+
/** @internal */
|
|
2094
|
+
const writeAll = (...outs) => writeChunk(fromIterable$3(outs));
|
|
2095
|
+
/** @internal */
|
|
2096
|
+
const writeChunk = (outs) => writeChunkWriter(0, outs.length, outs);
|
|
2097
|
+
/** @internal */
|
|
2098
|
+
const writeChunkWriter = (idx, len, chunk) => {
|
|
2099
|
+
return idx === len ? void_$3 : pipe(write(pipe(chunk, unsafeGet$2(idx))), flatMap$4(() => writeChunkWriter(idx + 1, len, chunk)));
|
|
2100
|
+
};
|
|
2101
|
+
/** @internal */
|
|
2102
|
+
const zip$3 = /* @__PURE__ */ dual((args) => isChannel(args[1]), (self, that, options) => options?.concurrent ? mergeWith$2(self, {
|
|
2103
|
+
other: that,
|
|
2104
|
+
onSelfDone: (exit1) => Await$1((exit2) => suspend$9(() => zip$5(exit1, exit2))),
|
|
2105
|
+
onOtherDone: (exit2) => Await$1((exit1) => suspend$9(() => zip$5(exit1, exit2)))
|
|
2106
|
+
}) : flatMap$4(self, (a) => map$6(that, (b) => [a, b])));
|
|
2107
|
+
/** @internal */
|
|
2108
|
+
const zipRight$5 = /* @__PURE__ */ dual((args) => isChannel(args[1]), (self, that, options) => options?.concurrent ? map$6(zip$3(self, that, { concurrent: true }), (tuple) => tuple[1]) : flatMap$4(self, () => that));
|
|
2109
|
+
/** @internal */
|
|
2110
|
+
const ChannelExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Channel/ChannelException");
|
|
2111
|
+
/** @internal */
|
|
2112
|
+
const ChannelException = (error) => ({
|
|
2113
|
+
_tag: "ChannelException",
|
|
2114
|
+
[ChannelExceptionTypeId]: ChannelExceptionTypeId,
|
|
2115
|
+
error
|
|
2116
|
+
});
|
|
2117
|
+
/** @internal */
|
|
2118
|
+
const isChannelException = (u) => hasProperty(u, ChannelExceptionTypeId);
|
|
2119
|
+
//#endregion
|
|
2120
|
+
//#region ../../node_modules/effect/dist/esm/internal/sink.js
|
|
2121
|
+
/** @internal */
|
|
2122
|
+
const SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
|
|
2123
|
+
const sinkVariance = {
|
|
2124
|
+
_A: (_) => _,
|
|
2125
|
+
_In: (_) => _,
|
|
2126
|
+
_L: (_) => _,
|
|
2127
|
+
_E: (_) => _,
|
|
2128
|
+
_R: (_) => _
|
|
2129
|
+
};
|
|
2130
|
+
/** @internal */
|
|
2131
|
+
var SinkImpl = class {
|
|
2132
|
+
channel;
|
|
2133
|
+
[SinkTypeId] = sinkVariance;
|
|
2134
|
+
constructor(channel) {
|
|
2135
|
+
this.channel = channel;
|
|
2136
|
+
}
|
|
2137
|
+
pipe() {
|
|
2138
|
+
return pipeArguments(this, arguments);
|
|
2139
|
+
}
|
|
2140
|
+
};
|
|
2141
|
+
/** @internal */
|
|
2142
|
+
const suspend$4 = (evaluate) => new SinkImpl(suspend$5(() => toChannel$2(evaluate())));
|
|
2143
|
+
/** @internal */
|
|
2144
|
+
const collectAllLoop = (acc) => readWithCause({
|
|
2145
|
+
onInput: (chunk) => collectAllLoop(pipe(acc, appendAll(chunk))),
|
|
2146
|
+
onFailure: failCause$4,
|
|
2147
|
+
onDone: () => succeed$5(acc)
|
|
2148
|
+
});
|
|
2149
|
+
/** @internal */
|
|
2150
|
+
const collectAllNLoop = (n, acc) => readWithCause({
|
|
2151
|
+
onInput: (chunk) => {
|
|
2152
|
+
const [collected, leftovers] = splitAt$1(chunk, n);
|
|
2153
|
+
if (collected.length < n) return collectAllNLoop(n - collected.length, appendAll(acc, collected));
|
|
2154
|
+
if (isEmpty$8(leftovers)) return succeed$5(appendAll(acc, collected));
|
|
2155
|
+
return flatMap$4(write(leftovers), () => succeed$5(appendAll(acc, collected)));
|
|
2156
|
+
},
|
|
2157
|
+
onFailure: failCause$4,
|
|
2158
|
+
onDone: () => succeed$5(acc)
|
|
2159
|
+
});
|
|
2160
|
+
/** @internal */
|
|
2161
|
+
const fold = (s, contFn, f) => suspend$4(() => new SinkImpl(foldReader(s, contFn, f)));
|
|
2162
|
+
/** @internal */
|
|
2163
|
+
const foldReader = (s, contFn, f) => {
|
|
2164
|
+
if (!contFn(s)) return succeedNow(s);
|
|
2165
|
+
return readWith({
|
|
2166
|
+
onInput: (input) => {
|
|
2167
|
+
const [nextS, leftovers] = foldChunkSplit(s, input, contFn, f, 0, input.length);
|
|
2168
|
+
if (isNonEmpty(leftovers)) return pipe(write(leftovers), as$4(nextS));
|
|
2169
|
+
return foldReader(nextS, contFn, f);
|
|
2170
|
+
},
|
|
2171
|
+
onFailure: fail$5,
|
|
2172
|
+
onDone: () => succeedNow(s)
|
|
2173
|
+
});
|
|
2174
|
+
};
|
|
2175
|
+
/** @internal */
|
|
2176
|
+
const foldChunkSplit = (s, chunk, contFn, f, index, length) => {
|
|
2177
|
+
if (index === length) return [s, empty$5()];
|
|
2178
|
+
const s1 = f(s, pipe(chunk, unsafeGet$2(index)));
|
|
2179
|
+
if (contFn(s1)) return foldChunkSplit(s1, chunk, contFn, f, index + 1, length);
|
|
2180
|
+
return [s1, pipe(chunk, drop$2(index + 1))];
|
|
2181
|
+
};
|
|
2182
|
+
/** @internal */
|
|
2183
|
+
const foldChunksReader = (s, contFn, f) => {
|
|
2184
|
+
if (!contFn(s)) return succeedNow(s);
|
|
2185
|
+
return readWith({
|
|
2186
|
+
onInput: (input) => foldChunksReader(f(s, input), contFn, f),
|
|
2187
|
+
onFailure: fail$5,
|
|
2188
|
+
onDone: () => succeedNow(s)
|
|
2189
|
+
});
|
|
2190
|
+
};
|
|
2191
|
+
/** @internal */
|
|
2192
|
+
const foldEffectReader = (s, contFn, f) => {
|
|
2193
|
+
if (!contFn(s)) return succeedNow(s);
|
|
2194
|
+
return readWith({
|
|
2195
|
+
onInput: (input) => pipe(fromEffect$4(foldChunkSplitEffect(s, input, contFn, f)), flatMap$4(([nextS, leftovers]) => pipe(leftovers, match$10({
|
|
2196
|
+
onNone: () => foldEffectReader(nextS, contFn, f),
|
|
2197
|
+
onSome: (leftover) => pipe(write(leftover), as$4(nextS))
|
|
2198
|
+
})))),
|
|
2199
|
+
onFailure: fail$5,
|
|
2200
|
+
onDone: () => succeedNow(s)
|
|
2201
|
+
});
|
|
2202
|
+
};
|
|
2203
|
+
/** @internal */
|
|
2204
|
+
const foldChunkSplitEffect = (s, chunk, contFn, f) => foldChunkSplitEffectInternal(s, chunk, 0, chunk.length, contFn, f);
|
|
2205
|
+
/** @internal */
|
|
2206
|
+
const foldChunkSplitEffectInternal = (s, chunk, index, length, contFn, f) => {
|
|
2207
|
+
if (index === length) return succeed$10([s, none()]);
|
|
2208
|
+
return pipe(f(s, pipe(chunk, unsafeGet$2(index))), flatMap$8((s1) => contFn(s1) ? foldChunkSplitEffectInternal(s1, chunk, index + 1, length, contFn, f) : succeed$10([s1, some$2(pipe(chunk, drop$2(index + 1)))])));
|
|
2209
|
+
};
|
|
2210
|
+
/** @internal */
|
|
2211
|
+
const forEachWhileReader = (f, input, index, length, cont) => {
|
|
2212
|
+
if (index === length) return cont;
|
|
2213
|
+
return pipe(fromEffect$4(f(pipe(input, unsafeGet$2(index)))), flatMap$4((bool) => bool ? forEachWhileReader(f, input, index + 1, length, cont) : write(pipe(input, drop$2(index)))), catchAll$3((error) => pipe(write(pipe(input, drop$2(index))), zipRight$5(fail$5(error)))));
|
|
2214
|
+
};
|
|
2215
|
+
/** @internal */
|
|
2216
|
+
const fromEffect$2 = (effect) => new SinkImpl(fromEffect$4(effect));
|
|
2217
|
+
/** @internal */
|
|
2218
|
+
const head = () => fold(none(), isNone, (option, input) => match$10(option, {
|
|
2219
|
+
onNone: () => some$2(input),
|
|
2220
|
+
onSome: () => option
|
|
2221
|
+
}));
|
|
2222
|
+
/** @internal */
|
|
2223
|
+
const toChannel$2 = (self) => isEffect(self) ? toChannel$2(fromEffect$2(self)) : self.channel;
|
|
2224
|
+
/**
|
|
2225
|
+
* @since 2.0.0
|
|
2226
|
+
* @category constructors
|
|
2227
|
+
*/
|
|
2228
|
+
const Done = Done$1;
|
|
2229
|
+
/**
|
|
2230
|
+
* @since 2.0.0
|
|
2231
|
+
* @category constructors
|
|
2232
|
+
*/
|
|
2233
|
+
const Await = Await$1;
|
|
2234
|
+
//#endregion
|
|
2235
|
+
//#region ../../node_modules/effect/dist/esm/internal/opCodes/streamHaltStrategy.js
|
|
2236
|
+
/** @internal */
|
|
2237
|
+
const OP_LEFT = "Left";
|
|
2238
|
+
/** @internal */
|
|
2239
|
+
const OP_RIGHT = "Right";
|
|
2240
|
+
/** @internal */
|
|
2241
|
+
const OP_BOTH = "Both";
|
|
2242
|
+
/** @internal */
|
|
2243
|
+
const OP_EITHER = "Either";
|
|
2244
|
+
//#endregion
|
|
2245
|
+
//#region ../../node_modules/effect/dist/esm/internal/stream/haltStrategy.js
|
|
2246
|
+
/** @internal */
|
|
2247
|
+
const Left$1 = { _tag: OP_LEFT };
|
|
2248
|
+
/** @internal */
|
|
2249
|
+
const Right$1 = { _tag: OP_RIGHT };
|
|
2250
|
+
/** @internal */
|
|
2251
|
+
const Both$1 = { _tag: OP_BOTH };
|
|
2252
|
+
/** @internal */
|
|
2253
|
+
const Either$1 = { _tag: OP_EITHER };
|
|
2254
|
+
/** @internal */
|
|
2255
|
+
const fromInput$1 = (input) => {
|
|
2256
|
+
switch (input) {
|
|
2257
|
+
case "left": return Left$1;
|
|
2258
|
+
case "right": return Right$1;
|
|
2259
|
+
case "both": return Both$1;
|
|
2260
|
+
case "either": return Either$1;
|
|
2261
|
+
default: return input;
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2264
|
+
/**
|
|
2265
|
+
* @since 2.0.0
|
|
2266
|
+
* @category constructors
|
|
2267
|
+
*/
|
|
2268
|
+
const Both = Both$1;
|
|
2269
|
+
//#endregion
|
|
2270
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/versioned.js
|
|
2271
|
+
/** @internal */
|
|
2272
|
+
var Versioned = class {
|
|
2273
|
+
value;
|
|
2274
|
+
constructor(value) {
|
|
2275
|
+
this.value = value;
|
|
2276
|
+
}
|
|
2277
|
+
};
|
|
2278
|
+
/** @internal */
|
|
2279
|
+
const commit = (self) => {
|
|
2280
|
+
self.ref.versioned = new Versioned(self.newValue);
|
|
2281
|
+
};
|
|
2282
|
+
/** @internal */
|
|
2283
|
+
const isInvalid = (self) => {
|
|
2284
|
+
return self.ref.versioned !== self.expected;
|
|
2285
|
+
};
|
|
2286
|
+
/** @internal */
|
|
2287
|
+
const isChanged = (self) => {
|
|
2288
|
+
return self.isChanged;
|
|
2289
|
+
};
|
|
2290
|
+
//#endregion
|
|
2291
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/journal.js
|
|
2292
|
+
/** @internal */
|
|
2293
|
+
const JournalAnalysisInvalid = "Invalid";
|
|
2294
|
+
/** @internal */
|
|
2295
|
+
const JournalAnalysisReadWrite = "ReadWrite";
|
|
2296
|
+
/** @internal */
|
|
2297
|
+
const JournalAnalysisReadOnly = "ReadOnly";
|
|
2298
|
+
/** @internal */
|
|
2299
|
+
const commitJournal = (journal) => {
|
|
2300
|
+
for (const entry of journal) commit(entry[1]);
|
|
2301
|
+
};
|
|
2302
|
+
/**
|
|
2303
|
+
* Analyzes the journal, determining whether it is valid and whether it is
|
|
2304
|
+
* read only in a single pass. Note that information on whether the
|
|
2305
|
+
* journal is read only will only be accurate if the journal is valid, due
|
|
2306
|
+
* to short-circuiting that occurs on an invalid journal.
|
|
2307
|
+
*
|
|
2308
|
+
* @internal
|
|
2309
|
+
*/
|
|
2310
|
+
const analyzeJournal = (journal) => {
|
|
2311
|
+
let val = JournalAnalysisReadOnly;
|
|
2312
|
+
for (const [, entry] of journal) {
|
|
2313
|
+
val = isInvalid(entry) ? JournalAnalysisInvalid : isChanged(entry) ? JournalAnalysisReadWrite : val;
|
|
2314
|
+
if (val === "Invalid") return val;
|
|
2315
|
+
}
|
|
2316
|
+
return val;
|
|
2317
|
+
};
|
|
2318
|
+
/** @internal */
|
|
2319
|
+
const collectTodos = (journal) => {
|
|
2320
|
+
const allTodos = /* @__PURE__ */ new Map();
|
|
2321
|
+
for (const [, entry] of journal) {
|
|
2322
|
+
for (const todo of entry.ref.todos) allTodos.set(todo[0], todo[1]);
|
|
2323
|
+
entry.ref.todos = /* @__PURE__ */ new Map();
|
|
2324
|
+
}
|
|
2325
|
+
return allTodos;
|
|
2326
|
+
};
|
|
2327
|
+
/** @internal */
|
|
2328
|
+
const execTodos = (todos) => {
|
|
2329
|
+
const todosSorted = Array.from(todos.entries()).sort((x, y) => x[0] - y[0]);
|
|
2330
|
+
for (const [_, todo] of todosSorted) todo();
|
|
2331
|
+
};
|
|
2332
|
+
/** @internal */
|
|
2333
|
+
const addTodo = (txnId, journal, todoEffect) => {
|
|
2334
|
+
let added = false;
|
|
2335
|
+
for (const [, entry] of journal) if (!entry.ref.todos.has(txnId)) {
|
|
2336
|
+
entry.ref.todos.set(txnId, todoEffect);
|
|
2337
|
+
added = true;
|
|
2338
|
+
}
|
|
2339
|
+
return added;
|
|
2340
|
+
};
|
|
2341
|
+
//#endregion
|
|
2342
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/opCodes/stm.js
|
|
2343
|
+
/** @internal */
|
|
2344
|
+
const OP_WITH_STM_RUNTIME = "WithSTMRuntime";
|
|
2345
|
+
/** @internal */
|
|
2346
|
+
const OP_ON_FAILURE = "OnFailure";
|
|
2347
|
+
/** @internal */
|
|
2348
|
+
const OP_ON_RETRY = "OnRetry";
|
|
2349
|
+
/** @internal */
|
|
2350
|
+
const OP_ON_SUCCESS = "OnSuccess";
|
|
2351
|
+
/** @internal */
|
|
2352
|
+
const OP_PROVIDE = "Provide";
|
|
2353
|
+
/** @internal */
|
|
2354
|
+
const OP_SYNC = "Sync";
|
|
2355
|
+
/** @internal */
|
|
2356
|
+
const OP_SUCCEED$1 = "Succeed";
|
|
2357
|
+
/** @internal */
|
|
2358
|
+
const OP_RETRY$1 = "Retry";
|
|
2359
|
+
/** @internal */
|
|
2360
|
+
const OP_FAIL$1 = "Fail";
|
|
2361
|
+
/** @internal */
|
|
2362
|
+
const OP_INTERRUPT$1 = "Interrupt";
|
|
2363
|
+
//#endregion
|
|
2364
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/opCodes/tExit.js
|
|
2365
|
+
/** @internal */
|
|
2366
|
+
const OP_FAIL = "Fail";
|
|
2367
|
+
/** @internal */
|
|
2368
|
+
const OP_INTERRUPT = "Interrupt";
|
|
2369
|
+
/** @internal */
|
|
2370
|
+
const OP_SUCCEED = "Succeed";
|
|
2371
|
+
/** @internal */
|
|
2372
|
+
const OP_RETRY = "Retry";
|
|
2373
|
+
//#endregion
|
|
2374
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/opCodes/tryCommit.js
|
|
2375
|
+
/** @internal */
|
|
2376
|
+
const OP_DONE$1 = "Done";
|
|
2377
|
+
/** @internal */
|
|
2378
|
+
const OP_SUSPEND = "Suspend";
|
|
2379
|
+
//#endregion
|
|
2380
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/opCodes/stmState.js
|
|
2381
|
+
/** @internal */
|
|
2382
|
+
const OP_DONE = "Done";
|
|
2383
|
+
/** @internal */
|
|
2384
|
+
const OP_INTERRUPTED = "Interrupted";
|
|
2385
|
+
/** @internal */
|
|
2386
|
+
const OP_RUNNING = "Running";
|
|
2387
|
+
//#endregion
|
|
2388
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/stmState.js
|
|
2389
|
+
/** @internal */
|
|
2390
|
+
const STMStateSymbolKey = "effect/STM/State";
|
|
2391
|
+
/** @internal */
|
|
2392
|
+
const STMStateTypeId = /* @__PURE__ */ Symbol.for(STMStateSymbolKey);
|
|
2393
|
+
/** @internal */
|
|
2394
|
+
const isSTMState = (u) => hasProperty(u, STMStateTypeId);
|
|
2395
|
+
/** @internal */
|
|
2396
|
+
const isRunning = (self) => {
|
|
2397
|
+
return self._tag === OP_RUNNING;
|
|
2398
|
+
};
|
|
2399
|
+
/** @internal */
|
|
2400
|
+
const isDone = (self) => {
|
|
2401
|
+
return self._tag === OP_DONE;
|
|
2402
|
+
};
|
|
2403
|
+
/** @internal */
|
|
2404
|
+
const done$2 = (exit) => {
|
|
2405
|
+
return {
|
|
2406
|
+
[STMStateTypeId]: STMStateTypeId,
|
|
2407
|
+
_tag: OP_DONE,
|
|
2408
|
+
exit,
|
|
2409
|
+
[symbol]() {
|
|
2410
|
+
return pipe(hash(STMStateSymbolKey), combine$2(hash(OP_DONE)), combine$2(hash(exit)), cached(this));
|
|
2411
|
+
},
|
|
2412
|
+
[symbol$1](that) {
|
|
2413
|
+
return isSTMState(that) && that._tag === "Done" && equals(exit, that.exit);
|
|
2414
|
+
}
|
|
2415
|
+
};
|
|
2416
|
+
};
|
|
2417
|
+
const interruptedHash = /* @__PURE__ */ pipe(/* @__PURE__ */ hash(STMStateSymbolKey), /* @__PURE__ */ combine$2(/* @__PURE__ */ hash(OP_INTERRUPTED)), /* @__PURE__ */ combine$2(/* @__PURE__ */ hash("interrupted")));
|
|
2418
|
+
/** @internal */
|
|
2419
|
+
const interrupted = {
|
|
2420
|
+
[STMStateTypeId]: STMStateTypeId,
|
|
2421
|
+
_tag: OP_INTERRUPTED,
|
|
2422
|
+
[symbol]() {
|
|
2423
|
+
return interruptedHash;
|
|
2424
|
+
},
|
|
2425
|
+
[symbol$1](that) {
|
|
2426
|
+
return isSTMState(that) && that._tag === "Interrupted";
|
|
2427
|
+
}
|
|
2428
|
+
};
|
|
2429
|
+
const runningHash = /* @__PURE__ */ pipe(/* @__PURE__ */ hash(STMStateSymbolKey), /* @__PURE__ */ combine$2(/* @__PURE__ */ hash(OP_RUNNING)), /* @__PURE__ */ combine$2(/* @__PURE__ */ hash("running")));
|
|
2430
|
+
/** @internal */
|
|
2431
|
+
const running = {
|
|
2432
|
+
[STMStateTypeId]: STMStateTypeId,
|
|
2433
|
+
_tag: OP_RUNNING,
|
|
2434
|
+
[symbol]() {
|
|
2435
|
+
return runningHash;
|
|
2436
|
+
},
|
|
2437
|
+
[symbol$1](that) {
|
|
2438
|
+
return isSTMState(that) && that._tag === "Running";
|
|
2439
|
+
}
|
|
2440
|
+
};
|
|
2441
|
+
/** @internal */
|
|
2442
|
+
const fromTExit = (tExit) => {
|
|
2443
|
+
switch (tExit._tag) {
|
|
2444
|
+
case OP_FAIL: return done$2(fail$9(tExit.error));
|
|
2445
|
+
case "Die": return done$2(die$6(tExit.defect));
|
|
2446
|
+
case OP_INTERRUPT: return done$2(interrupt$5(tExit.fiberId));
|
|
2447
|
+
case OP_SUCCEED: return done$2(succeed$9(tExit.value));
|
|
2448
|
+
case OP_RETRY: throw new Error("BUG: STM.STMState.fromTExit - please report an issue at https://github.com/Effect-TS/effect/issues");
|
|
2449
|
+
}
|
|
2450
|
+
};
|
|
2451
|
+
//#endregion
|
|
2452
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/tExit.js
|
|
2453
|
+
/** @internal */
|
|
2454
|
+
const TExitSymbolKey = "effect/TExit";
|
|
2455
|
+
/** @internal */
|
|
2456
|
+
const TExitTypeId = /* @__PURE__ */ Symbol.for(TExitSymbolKey);
|
|
2457
|
+
const variance = {
|
|
2458
|
+
_A: (_) => _,
|
|
2459
|
+
_E: (_) => _
|
|
2460
|
+
};
|
|
2461
|
+
/** @internal */
|
|
2462
|
+
const isExit = (u) => hasProperty(u, TExitTypeId);
|
|
2463
|
+
/** @internal */
|
|
2464
|
+
const isSuccess = (self) => {
|
|
2465
|
+
return self._tag === OP_SUCCEED;
|
|
2466
|
+
};
|
|
2467
|
+
/** @internal */
|
|
2468
|
+
const isRetry = (self) => {
|
|
2469
|
+
return self._tag === OP_RETRY;
|
|
2470
|
+
};
|
|
2471
|
+
/** @internal */
|
|
2472
|
+
const fail$3 = (error) => ({
|
|
2473
|
+
[TExitTypeId]: variance,
|
|
2474
|
+
_tag: OP_FAIL,
|
|
2475
|
+
error,
|
|
2476
|
+
[symbol]() {
|
|
2477
|
+
return pipe(hash(TExitSymbolKey), combine$2(hash(OP_FAIL)), combine$2(hash(error)), cached(this));
|
|
2478
|
+
},
|
|
2479
|
+
[symbol$1](that) {
|
|
2480
|
+
return isExit(that) && that._tag === "Fail" && equals(error, that.error);
|
|
2481
|
+
}
|
|
2482
|
+
});
|
|
2483
|
+
/** @internal */
|
|
2484
|
+
const die$3 = (defect) => ({
|
|
2485
|
+
[TExitTypeId]: variance,
|
|
2486
|
+
_tag: "Die",
|
|
2487
|
+
defect,
|
|
2488
|
+
[symbol]() {
|
|
2489
|
+
return pipe(hash(TExitSymbolKey), combine$2(hash("Die")), combine$2(hash(defect)), cached(this));
|
|
2490
|
+
},
|
|
2491
|
+
[symbol$1](that) {
|
|
2492
|
+
return isExit(that) && that._tag === "Die" && equals(defect, that.defect);
|
|
2493
|
+
}
|
|
2494
|
+
});
|
|
2495
|
+
/** @internal */
|
|
2496
|
+
const interrupt = (fiberId) => ({
|
|
2497
|
+
[TExitTypeId]: variance,
|
|
2498
|
+
_tag: OP_INTERRUPT,
|
|
2499
|
+
fiberId,
|
|
2500
|
+
[symbol]() {
|
|
2501
|
+
return pipe(hash(TExitSymbolKey), combine$2(hash(OP_INTERRUPT)), combine$2(hash(fiberId)), cached(this));
|
|
2502
|
+
},
|
|
2503
|
+
[symbol$1](that) {
|
|
2504
|
+
return isExit(that) && that._tag === "Interrupt" && equals(fiberId, that.fiberId);
|
|
2505
|
+
}
|
|
2506
|
+
});
|
|
2507
|
+
/** @internal */
|
|
2508
|
+
const succeed$3 = (value) => ({
|
|
2509
|
+
[TExitTypeId]: variance,
|
|
2510
|
+
_tag: OP_SUCCEED,
|
|
2511
|
+
value,
|
|
2512
|
+
[symbol]() {
|
|
2513
|
+
return pipe(hash(TExitSymbolKey), combine$2(hash(OP_SUCCEED)), combine$2(hash(value)), cached(this));
|
|
2514
|
+
},
|
|
2515
|
+
[symbol$1](that) {
|
|
2516
|
+
return isExit(that) && that._tag === "Succeed" && equals(value, that.value);
|
|
2517
|
+
}
|
|
2518
|
+
});
|
|
2519
|
+
const retryHash = /* @__PURE__ */ pipe(/* @__PURE__ */ hash(TExitSymbolKey), /* @__PURE__ */ combine$2(/* @__PURE__ */ hash(OP_RETRY)), /* @__PURE__ */ combine$2(/* @__PURE__ */ hash("retry")));
|
|
2520
|
+
/** @internal */
|
|
2521
|
+
const retry$3 = {
|
|
2522
|
+
[TExitTypeId]: variance,
|
|
2523
|
+
_tag: OP_RETRY,
|
|
2524
|
+
[symbol]() {
|
|
2525
|
+
return retryHash;
|
|
2526
|
+
},
|
|
2527
|
+
[symbol$1](that) {
|
|
2528
|
+
return isExit(that) && isRetry(that);
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
//#endregion
|
|
2532
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/tryCommit.js
|
|
2533
|
+
/** @internal */
|
|
2534
|
+
const done$1 = (exit) => {
|
|
2535
|
+
return {
|
|
2536
|
+
_tag: OP_DONE$1,
|
|
2537
|
+
exit
|
|
2538
|
+
};
|
|
2539
|
+
};
|
|
2540
|
+
/** @internal */
|
|
2541
|
+
const suspend$3 = (journal) => {
|
|
2542
|
+
return {
|
|
2543
|
+
_tag: OP_SUSPEND,
|
|
2544
|
+
journal
|
|
2545
|
+
};
|
|
2546
|
+
};
|
|
2547
|
+
//#endregion
|
|
2548
|
+
//#region ../../node_modules/effect/dist/esm/internal/stm/txnId.js
|
|
2549
|
+
/** @internal */
|
|
2550
|
+
const txnCounter = { ref: 0 };
|
|
2551
|
+
/** @internal */
|
|
2552
|
+
const make$6 = () => {
|
|
2553
|
+
const newId = txnCounter.ref + 1;
|
|
2554
|
+
txnCounter.ref = newId;
|
|
2555
|
+
return newId;
|
|
2556
|
+
};
|
|
2557
|
+
/** @internal */
|
|
2558
|
+
const STMTypeId = /* @__PURE__ */ Symbol.for("effect/STM");
|
|
2559
|
+
const stmVariance = {
|
|
2560
|
+
_R: (_) => _,
|
|
2561
|
+
_E: (_) => _,
|
|
2562
|
+
_A: (_) => _
|
|
2563
|
+
};
|
|
2564
|
+
/** @internal */
|
|
2565
|
+
var STMPrimitive = class {
|
|
2566
|
+
effect_instruction_i0;
|
|
2567
|
+
_op = OP_COMMIT;
|
|
2568
|
+
effect_instruction_i1 = void 0;
|
|
2569
|
+
effect_instruction_i2 = void 0;
|
|
2570
|
+
[EffectTypeId];
|
|
2571
|
+
[StreamTypeId$2];
|
|
2572
|
+
[SinkTypeId];
|
|
2573
|
+
[ChannelTypeId];
|
|
2574
|
+
get [STMTypeId]() {
|
|
2575
|
+
return stmVariance;
|
|
2576
|
+
}
|
|
2577
|
+
constructor(effect_instruction_i0) {
|
|
2578
|
+
this.effect_instruction_i0 = effect_instruction_i0;
|
|
2579
|
+
this[EffectTypeId] = effectVariance;
|
|
2580
|
+
this[StreamTypeId$2] = stmVariance;
|
|
2581
|
+
this[SinkTypeId] = stmVariance;
|
|
2582
|
+
this[ChannelTypeId] = stmVariance;
|
|
2583
|
+
}
|
|
2584
|
+
[symbol$1](that) {
|
|
2585
|
+
return this === that;
|
|
2586
|
+
}
|
|
2587
|
+
[symbol]() {
|
|
2588
|
+
return cached(this, random(this));
|
|
2589
|
+
}
|
|
2590
|
+
[Symbol.iterator]() {
|
|
2591
|
+
return new SingleShotGen(new YieldWrap(this));
|
|
2592
|
+
}
|
|
2593
|
+
commit() {
|
|
2594
|
+
return unsafeAtomically(this, constVoid, constVoid);
|
|
2595
|
+
}
|
|
2596
|
+
pipe() {
|
|
2597
|
+
return pipeArguments(this, arguments);
|
|
2598
|
+
}
|
|
2599
|
+
};
|
|
2600
|
+
/** @internal */
|
|
2601
|
+
const unsafeAtomically = (self, onDone, onInterrupt) => withFiberRuntime((state) => {
|
|
2602
|
+
const fiberId = state.id();
|
|
2603
|
+
const env = state.getFiberRef(currentContext);
|
|
2604
|
+
const scheduler = state.getFiberRef(currentScheduler);
|
|
2605
|
+
const priority = state.getFiberRef(currentSchedulingPriority);
|
|
2606
|
+
const commitResult = tryCommitSync(fiberId, self, env, scheduler, priority);
|
|
2607
|
+
switch (commitResult._tag) {
|
|
2608
|
+
case OP_DONE$1:
|
|
2609
|
+
onDone(commitResult.exit);
|
|
2610
|
+
return commitResult.exit;
|
|
2611
|
+
case OP_SUSPEND: {
|
|
2612
|
+
const txnId = make$6();
|
|
2613
|
+
const state = { value: running };
|
|
2614
|
+
const effect = async((k) => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, priority, k));
|
|
2615
|
+
return uninterruptibleMask((restore) => pipe(restore(effect), catchAllCause$5((cause) => {
|
|
2616
|
+
let currentState = state.value;
|
|
2617
|
+
if (isRunning(currentState)) state.value = interrupted;
|
|
2618
|
+
currentState = state.value;
|
|
2619
|
+
if (isDone(currentState)) {
|
|
2620
|
+
onDone(currentState.exit);
|
|
2621
|
+
return currentState.exit;
|
|
2622
|
+
}
|
|
2623
|
+
onInterrupt();
|
|
2624
|
+
return failCause$8(cause);
|
|
2625
|
+
})));
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
});
|
|
2629
|
+
/** @internal */
|
|
2630
|
+
const tryCommit = (fiberId, stm, state, env, scheduler, priority) => {
|
|
2631
|
+
const journal = /* @__PURE__ */ new Map();
|
|
2632
|
+
const tExit = new STMDriver(stm, journal, fiberId, env).run();
|
|
2633
|
+
const analysis = analyzeJournal(journal);
|
|
2634
|
+
if (analysis === "ReadWrite") commitJournal(journal);
|
|
2635
|
+
else if (analysis === "Invalid") throw new Error("BUG: STM.TryCommit.tryCommit - please report an issue at https://github.com/Effect-TS/effect/issues");
|
|
2636
|
+
switch (tExit._tag) {
|
|
2637
|
+
case OP_SUCCEED:
|
|
2638
|
+
state.value = fromTExit(tExit);
|
|
2639
|
+
return completeTodos(succeed$9(tExit.value), journal, scheduler, priority);
|
|
2640
|
+
case OP_FAIL:
|
|
2641
|
+
state.value = fromTExit(tExit);
|
|
2642
|
+
return completeTodos(failCause$7(fail$8(tExit.error)), journal, scheduler, priority);
|
|
2643
|
+
case "Die":
|
|
2644
|
+
state.value = fromTExit(tExit);
|
|
2645
|
+
return completeTodos(failCause$7(die$7(tExit.defect)), journal, scheduler, priority);
|
|
2646
|
+
case OP_INTERRUPT:
|
|
2647
|
+
state.value = fromTExit(tExit);
|
|
2648
|
+
return completeTodos(failCause$7(interrupt$3(fiberId)), journal, scheduler, priority);
|
|
2649
|
+
case OP_RETRY: return suspend$3(journal);
|
|
2650
|
+
}
|
|
2651
|
+
};
|
|
2652
|
+
/** @internal */
|
|
2653
|
+
const tryCommitSync = (fiberId, stm, env, scheduler, priority) => {
|
|
2654
|
+
const journal = /* @__PURE__ */ new Map();
|
|
2655
|
+
const tExit = new STMDriver(stm, journal, fiberId, env).run();
|
|
2656
|
+
const analysis = analyzeJournal(journal);
|
|
2657
|
+
if (analysis === "ReadWrite" && isSuccess(tExit)) commitJournal(journal);
|
|
2658
|
+
else if (analysis === "Invalid") throw new Error("BUG: STM.TryCommit.tryCommitSync - please report an issue at https://github.com/Effect-TS/effect/issues");
|
|
2659
|
+
switch (tExit._tag) {
|
|
2660
|
+
case OP_SUCCEED: return completeTodos(succeed$9(tExit.value), journal, scheduler, priority);
|
|
2661
|
+
case OP_FAIL: return completeTodos(failCause$7(fail$8(tExit.error)), journal, scheduler, priority);
|
|
2662
|
+
case "Die": return completeTodos(failCause$7(die$7(tExit.defect)), journal, scheduler, priority);
|
|
2663
|
+
case OP_INTERRUPT: return completeTodos(failCause$7(interrupt$3(fiberId)), journal, scheduler, priority);
|
|
2664
|
+
case OP_RETRY: return suspend$3(journal);
|
|
2665
|
+
}
|
|
2666
|
+
};
|
|
2667
|
+
/** @internal */
|
|
2668
|
+
const tryCommitAsync = (fiberId, self, txnId, state, context, scheduler, priority, k) => {
|
|
2669
|
+
if (isRunning(state.value)) {
|
|
2670
|
+
const result = tryCommit(fiberId, self, state, context, scheduler, priority);
|
|
2671
|
+
switch (result._tag) {
|
|
2672
|
+
case OP_DONE$1:
|
|
2673
|
+
completeTryCommit(result.exit, k);
|
|
2674
|
+
break;
|
|
2675
|
+
case OP_SUSPEND:
|
|
2676
|
+
addTodo(txnId, result.journal, () => tryCommitAsync(fiberId, self, txnId, state, context, scheduler, priority, k));
|
|
2677
|
+
break;
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
};
|
|
2681
|
+
/** @internal */
|
|
2682
|
+
const completeTodos = (exit, journal, scheduler, priority) => {
|
|
2683
|
+
const todos = collectTodos(journal);
|
|
2684
|
+
if (todos.size > 0) scheduler.scheduleTask(() => execTodos(todos), priority);
|
|
2685
|
+
return done$1(exit);
|
|
2686
|
+
};
|
|
2687
|
+
/** @internal */
|
|
2688
|
+
const completeTryCommit = (exit, k) => {
|
|
2689
|
+
k(exit);
|
|
2690
|
+
};
|
|
2691
|
+
/** @internal */
|
|
2692
|
+
var STMDriver = class {
|
|
2693
|
+
self;
|
|
2694
|
+
journal;
|
|
2695
|
+
fiberId;
|
|
2696
|
+
contStack = [];
|
|
2697
|
+
env;
|
|
2698
|
+
constructor(self, journal, fiberId, r0) {
|
|
2699
|
+
this.self = self;
|
|
2700
|
+
this.journal = journal;
|
|
2701
|
+
this.fiberId = fiberId;
|
|
2702
|
+
this.env = r0;
|
|
2703
|
+
}
|
|
2704
|
+
getEnv() {
|
|
2705
|
+
return this.env;
|
|
2706
|
+
}
|
|
2707
|
+
pushStack(cont) {
|
|
2708
|
+
this.contStack.push(cont);
|
|
2709
|
+
}
|
|
2710
|
+
popStack() {
|
|
2711
|
+
return this.contStack.pop();
|
|
2712
|
+
}
|
|
2713
|
+
nextSuccess() {
|
|
2714
|
+
let current = this.popStack();
|
|
2715
|
+
while (current !== void 0 && current.effect_instruction_i0 !== "OnSuccess") current = this.popStack();
|
|
2716
|
+
return current;
|
|
2717
|
+
}
|
|
2718
|
+
nextFailure() {
|
|
2719
|
+
let current = this.popStack();
|
|
2720
|
+
while (current !== void 0 && current.effect_instruction_i0 !== "OnFailure") current = this.popStack();
|
|
2721
|
+
return current;
|
|
2722
|
+
}
|
|
2723
|
+
nextRetry() {
|
|
2724
|
+
let current = this.popStack();
|
|
2725
|
+
while (current !== void 0 && current.effect_instruction_i0 !== "OnRetry") current = this.popStack();
|
|
2726
|
+
return current;
|
|
2727
|
+
}
|
|
2728
|
+
run() {
|
|
2729
|
+
let curr = this.self;
|
|
2730
|
+
let exit = void 0;
|
|
2731
|
+
while (exit === void 0 && curr !== void 0) try {
|
|
2732
|
+
const current = curr;
|
|
2733
|
+
if (current) switch (current._op) {
|
|
2734
|
+
case "Tag":
|
|
2735
|
+
curr = effect((_, __, env) => unsafeGet$3(env, current));
|
|
2736
|
+
break;
|
|
2737
|
+
case "Left":
|
|
2738
|
+
curr = fail$2(current.left);
|
|
2739
|
+
break;
|
|
2740
|
+
case "None":
|
|
2741
|
+
curr = fail$2(new NoSuchElementException());
|
|
2742
|
+
break;
|
|
2743
|
+
case "Right":
|
|
2744
|
+
curr = succeed$2(current.right);
|
|
2745
|
+
break;
|
|
2746
|
+
case "Some":
|
|
2747
|
+
curr = succeed$2(current.value);
|
|
2748
|
+
break;
|
|
2749
|
+
case "Commit":
|
|
2750
|
+
switch (current.effect_instruction_i0) {
|
|
2751
|
+
case "Die":
|
|
2752
|
+
exit = die$3(internalCall(() => current.effect_instruction_i1()));
|
|
2753
|
+
break;
|
|
2754
|
+
case OP_FAIL$1: {
|
|
2755
|
+
const cont = this.nextFailure();
|
|
2756
|
+
if (cont === void 0) exit = fail$3(internalCall(() => current.effect_instruction_i1()));
|
|
2757
|
+
else curr = internalCall(() => cont.effect_instruction_i2(internalCall(() => current.effect_instruction_i1())));
|
|
2758
|
+
break;
|
|
2759
|
+
}
|
|
2760
|
+
case OP_RETRY$1: {
|
|
2761
|
+
const cont = this.nextRetry();
|
|
2762
|
+
if (cont === void 0) exit = retry$3;
|
|
2763
|
+
else curr = internalCall(() => cont.effect_instruction_i2());
|
|
2764
|
+
break;
|
|
2765
|
+
}
|
|
2766
|
+
case OP_INTERRUPT$1:
|
|
2767
|
+
exit = interrupt(this.fiberId);
|
|
2768
|
+
break;
|
|
2769
|
+
case OP_WITH_STM_RUNTIME:
|
|
2770
|
+
curr = internalCall(() => current.effect_instruction_i1(this));
|
|
2771
|
+
break;
|
|
2772
|
+
case OP_ON_SUCCESS:
|
|
2773
|
+
case OP_ON_FAILURE:
|
|
2774
|
+
case OP_ON_RETRY:
|
|
2775
|
+
this.pushStack(current);
|
|
2776
|
+
curr = current.effect_instruction_i1;
|
|
2777
|
+
break;
|
|
2778
|
+
case OP_PROVIDE: {
|
|
2779
|
+
const env = this.env;
|
|
2780
|
+
this.env = internalCall(() => current.effect_instruction_i2(env));
|
|
2781
|
+
curr = pipe(current.effect_instruction_i1, ensuring$2(sync$2(() => this.env = env)));
|
|
2782
|
+
break;
|
|
2783
|
+
}
|
|
2784
|
+
case OP_SUCCEED$1: {
|
|
2785
|
+
const value = current.effect_instruction_i1;
|
|
2786
|
+
const cont = this.nextSuccess();
|
|
2787
|
+
if (cont === void 0) exit = succeed$3(value);
|
|
2788
|
+
else curr = internalCall(() => cont.effect_instruction_i2(value));
|
|
2789
|
+
break;
|
|
2790
|
+
}
|
|
2791
|
+
case OP_SYNC: {
|
|
2792
|
+
const value = internalCall(() => current.effect_instruction_i1());
|
|
2793
|
+
const cont = this.nextSuccess();
|
|
2794
|
+
if (cont === void 0) exit = succeed$3(value);
|
|
2795
|
+
else curr = internalCall(() => cont.effect_instruction_i2(value));
|
|
2796
|
+
break;
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
break;
|
|
2800
|
+
}
|
|
2801
|
+
} catch (e) {
|
|
2802
|
+
curr = die$2(e);
|
|
2803
|
+
}
|
|
2804
|
+
return exit;
|
|
2805
|
+
}
|
|
2806
|
+
};
|
|
2807
|
+
/** @internal */
|
|
2808
|
+
const catchAll$2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
2809
|
+
const stm = new STMPrimitive(OP_ON_FAILURE);
|
|
2810
|
+
stm.effect_instruction_i1 = self;
|
|
2811
|
+
stm.effect_instruction_i2 = f;
|
|
2812
|
+
return stm;
|
|
2813
|
+
});
|
|
2814
|
+
/** @internal */
|
|
2815
|
+
const die$2 = (defect) => dieSync$2(() => defect);
|
|
2816
|
+
/** @internal */
|
|
2817
|
+
const dieSync$2 = (evaluate) => {
|
|
2818
|
+
const stm = new STMPrimitive("Die");
|
|
2819
|
+
stm.effect_instruction_i1 = evaluate;
|
|
2820
|
+
return stm;
|
|
2821
|
+
};
|
|
2822
|
+
/** @internal */
|
|
2823
|
+
const effect = (f) => withSTMRuntime((_) => succeed$2(f(_.journal, _.fiberId, _.getEnv())));
|
|
2824
|
+
/** @internal */
|
|
2825
|
+
const ensuring$2 = /* @__PURE__ */ dual(2, (self, finalizer) => matchSTM(self, {
|
|
2826
|
+
onFailure: (e) => zipRight$2(finalizer, fail$2(e)),
|
|
2827
|
+
onSuccess: (a) => zipRight$2(finalizer, succeed$2(a))
|
|
2828
|
+
}));
|
|
2829
|
+
/** @internal */
|
|
2830
|
+
const fail$2 = (error) => failSync$2(() => error);
|
|
2831
|
+
/** @internal */
|
|
2832
|
+
const failSync$2 = (evaluate) => {
|
|
2833
|
+
const stm = new STMPrimitive(OP_FAIL$1);
|
|
2834
|
+
stm.effect_instruction_i1 = evaluate;
|
|
2835
|
+
return stm;
|
|
2836
|
+
};
|
|
2837
|
+
/** @internal */
|
|
2838
|
+
const flatMap$2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
2839
|
+
const stm = new STMPrimitive(OP_ON_SUCCESS);
|
|
2840
|
+
stm.effect_instruction_i1 = self;
|
|
2841
|
+
stm.effect_instruction_i2 = f;
|
|
2842
|
+
return stm;
|
|
2843
|
+
});
|
|
2844
|
+
/** @internal */
|
|
2845
|
+
const matchSTM = /* @__PURE__ */ dual(2, (self, { onFailure, onSuccess }) => pipe(self, map$3(right), catchAll$2((e) => pipe(onFailure(e), map$3(left))), flatMap$2((either) => {
|
|
2846
|
+
switch (either._tag) {
|
|
2847
|
+
case "Left": return succeed$2(either.left);
|
|
2848
|
+
case "Right": return onSuccess(either.right);
|
|
2849
|
+
}
|
|
2850
|
+
})));
|
|
2851
|
+
/** @internal */
|
|
2852
|
+
const withSTMRuntime = (f) => {
|
|
2853
|
+
const stm = new STMPrimitive(OP_WITH_STM_RUNTIME);
|
|
2854
|
+
stm.effect_instruction_i1 = f;
|
|
2855
|
+
return stm;
|
|
2856
|
+
};
|
|
2857
|
+
/** @internal */
|
|
2858
|
+
const map$3 = /* @__PURE__ */ dual(2, (self, f) => pipe(self, flatMap$2((a) => sync$2(() => f(a)))));
|
|
2859
|
+
/** @internal */
|
|
2860
|
+
const succeed$2 = (value) => {
|
|
2861
|
+
const stm = new STMPrimitive(OP_SUCCEED$1);
|
|
2862
|
+
stm.effect_instruction_i1 = value;
|
|
2863
|
+
return stm;
|
|
2864
|
+
};
|
|
2865
|
+
/** @internal */
|
|
2866
|
+
const sync$2 = (evaluate) => {
|
|
2867
|
+
const stm = new STMPrimitive(OP_SYNC);
|
|
2868
|
+
stm.effect_instruction_i1 = evaluate;
|
|
2869
|
+
return stm;
|
|
2870
|
+
};
|
|
2871
|
+
/** @internal */
|
|
2872
|
+
const zipRight$2 = /* @__PURE__ */ dual(2, (self, that) => pipe(self, flatMap$2(() => that)));
|
|
2873
|
+
const seekLoop = (self, predicate) => flatMap$2(self.take, (a) => predicate(a) ? succeed$2(a) : seekLoop(self, predicate));
|
|
2874
|
+
/** @internal */
|
|
2875
|
+
const OP_HANDOFF_STATE_EMPTY = "Empty";
|
|
2876
|
+
/** @internal */
|
|
2877
|
+
const OP_HANDOFF_STATE_FULL = "Full";
|
|
2878
|
+
/** @internal */
|
|
2879
|
+
const handoffStateEmpty = (notifyConsumer) => ({
|
|
2880
|
+
_tag: OP_HANDOFF_STATE_EMPTY,
|
|
2881
|
+
notifyConsumer
|
|
2882
|
+
});
|
|
2883
|
+
/** @internal */
|
|
2884
|
+
const handoffStateFull = (value, notifyProducer) => ({
|
|
2885
|
+
_tag: OP_HANDOFF_STATE_FULL,
|
|
2886
|
+
value,
|
|
2887
|
+
notifyProducer
|
|
2888
|
+
});
|
|
2889
|
+
/** @internal */
|
|
2890
|
+
const handoffStateMatch = (onEmpty, onFull) => {
|
|
2891
|
+
return (self) => {
|
|
2892
|
+
switch (self._tag) {
|
|
2893
|
+
case OP_HANDOFF_STATE_EMPTY: return onEmpty(self.notifyConsumer);
|
|
2894
|
+
case OP_HANDOFF_STATE_FULL: return onFull(self.value, self.notifyProducer);
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2897
|
+
};
|
|
2898
|
+
/** @internal */
|
|
2899
|
+
const offer = /* @__PURE__ */ dual(2, (self, value) => {
|
|
2900
|
+
return flatMap$8(make$17(), (deferred) => flatten$6(modify$1(self.ref, (state) => pipe(state, handoffStateMatch((notifyConsumer) => [zipRight$8(succeed$11(notifyConsumer, void 0), _await(deferred)), handoffStateFull(value, deferred)], (_, notifyProducer) => [flatMap$8(_await(notifyProducer), () => pipe(self, offer(value))), state])))));
|
|
2901
|
+
});
|
|
2902
|
+
/** @internal */
|
|
2903
|
+
const take$3 = (self) => flatMap$8(make$17(), (deferred) => flatten$6(modify$1(self.ref, (state) => pipe(state, handoffStateMatch((notifyConsumer) => [flatMap$8(_await(notifyConsumer), () => take$3(self)), state], (value, notifyProducer) => [as$5(succeed$11(notifyProducer, void 0), value), handoffStateEmpty(deferred)])))));
|
|
2904
|
+
/** @internal */
|
|
2905
|
+
const StreamTypeId$1 = /* @__PURE__ */ Symbol.for("effect/Stream");
|
|
2906
|
+
/** @internal */
|
|
2907
|
+
const streamVariance = {
|
|
2908
|
+
_R: (_) => _,
|
|
2909
|
+
_E: (_) => _,
|
|
2910
|
+
_A: (_) => _
|
|
2911
|
+
};
|
|
2912
|
+
/** @internal */
|
|
2913
|
+
var StreamImpl = class {
|
|
2914
|
+
channel;
|
|
2915
|
+
[StreamTypeId$1] = streamVariance;
|
|
2916
|
+
constructor(channel) {
|
|
2917
|
+
this.channel = channel;
|
|
2918
|
+
}
|
|
2919
|
+
pipe() {
|
|
2920
|
+
return pipeArguments(this, arguments);
|
|
2921
|
+
}
|
|
2922
|
+
};
|
|
2923
|
+
/** @internal */
|
|
2924
|
+
const isStream = (u) => hasProperty(u, StreamTypeId$1) || isEffect(u);
|
|
2925
|
+
/** @internal */
|
|
2926
|
+
const concat$2 = /* @__PURE__ */ dual(2, (self, that) => new StreamImpl(pipe(toChannel$1(self), zipRight$5(toChannel$1(that)))));
|
|
2927
|
+
/** @internal */
|
|
2928
|
+
const empty$1 = /* @__PURE__ */ new StreamImpl(void_$3);
|
|
2929
|
+
/** @internal */
|
|
2930
|
+
const find$1 = /* @__PURE__ */ dual(2, (self, predicate) => {
|
|
2931
|
+
const loop = readWith({
|
|
2932
|
+
onInput: (input) => match$10(findFirst(input, predicate), {
|
|
2933
|
+
onNone: () => loop,
|
|
2934
|
+
onSome: (n) => write(of$2(n))
|
|
2935
|
+
}),
|
|
2936
|
+
onFailure: fail$5,
|
|
2937
|
+
onDone: () => void_$3
|
|
2938
|
+
});
|
|
2939
|
+
return new StreamImpl(pipe(toChannel$1(self), pipeTo(loop)));
|
|
2940
|
+
});
|
|
2941
|
+
/** @internal */
|
|
2942
|
+
const flatMap$1 = /* @__PURE__ */ dual((args) => isStream(args[0]), (self, f, options) => {
|
|
2943
|
+
const bufferSize = options?.bufferSize ?? 16;
|
|
2944
|
+
if (options?.switch) return matchConcurrency(options?.concurrency, () => flatMapParSwitchBuffer(self, 1, bufferSize, f), (n) => flatMapParSwitchBuffer(self, n, bufferSize, f));
|
|
2945
|
+
return matchConcurrency(options?.concurrency, () => new StreamImpl(concatMap$1(toChannel$1(self), (as) => pipe(as, map$13((a) => toChannel$1(f(a))), reduce$2(void_$3, (left, right) => pipe(left, zipRight$5(right)))))), (_) => new StreamImpl(pipe(toChannel$1(self), concatMap$1(writeChunk), mergeMap$1((out) => toChannel$1(f(out)), options))));
|
|
2946
|
+
});
|
|
2947
|
+
/** @internal */
|
|
2948
|
+
const matchConcurrency = (concurrency, sequential, bounded) => {
|
|
2949
|
+
switch (concurrency) {
|
|
2950
|
+
case void 0: return sequential();
|
|
2951
|
+
case "unbounded": return bounded(Number.MAX_SAFE_INTEGER);
|
|
2952
|
+
default: return concurrency > 1 ? bounded(concurrency) : sequential();
|
|
2953
|
+
}
|
|
2954
|
+
};
|
|
2955
|
+
const flatMapParSwitchBuffer = /* @__PURE__ */ dual(4, (self, n, bufferSize, f) => new StreamImpl(pipe(toChannel$1(self), concatMap$1(writeChunk), mergeMap$1((out) => toChannel$1(f(out)), {
|
|
2956
|
+
concurrency: n,
|
|
2957
|
+
mergeStrategy: BufferSliding(),
|
|
2958
|
+
bufferSize
|
|
2959
|
+
}))));
|
|
2960
|
+
/** @internal */
|
|
2961
|
+
const flatten$1 = /* @__PURE__ */ dual((args) => isStream(args[0]), (self, options) => flatMap$1(self, identity$2, options));
|
|
2962
|
+
/** @internal */
|
|
2963
|
+
const toChannel$1 = (stream) => {
|
|
2964
|
+
if ("channel" in stream) return stream.channel;
|
|
2965
|
+
else if (isEffect(stream)) return toChannel$1(fromEffect$1(stream));
|
|
2966
|
+
else throw new TypeError(`Expected a Stream.`);
|
|
2967
|
+
};
|
|
2968
|
+
/** @internal */
|
|
2969
|
+
const fromChunk$1 = (chunk) => new StreamImpl(isEmpty$8(chunk) ? void_$3 : write(chunk));
|
|
2970
|
+
/** @internal */
|
|
2971
|
+
const fromEffect$1 = (effect) => pipe(effect, mapError$5(some$2), fromEffectOption$1);
|
|
2972
|
+
/** @internal */
|
|
2973
|
+
const fromEffectOption$1 = (effect) => new StreamImpl(unwrap$2(match$11(effect, {
|
|
2974
|
+
onFailure: match$10({
|
|
2975
|
+
onNone: () => void_$3,
|
|
2976
|
+
onSome: fail$5
|
|
2977
|
+
}),
|
|
2978
|
+
onSuccess: (a) => write(of$2(a))
|
|
2979
|
+
})));
|
|
2980
|
+
/** @internal */
|
|
2981
|
+
const fromPull$1 = (effect) => pipe(effect, map$10(repeatEffectChunkOption$1), unwrapScoped$1);
|
|
2982
|
+
/** @internal */
|
|
2983
|
+
const map$2 = /* @__PURE__ */ dual(2, (self, f) => new StreamImpl(pipe(toChannel$1(self), mapOut(map$13(f)))));
|
|
2984
|
+
/** @internal */
|
|
2985
|
+
const mapEffectSequential = /* @__PURE__ */ dual(2, (self, f) => {
|
|
2986
|
+
const loop = (iterator) => {
|
|
2987
|
+
const next = iterator.next();
|
|
2988
|
+
if (next.done) return readWithCause({
|
|
2989
|
+
onInput: (elem) => loop(elem[Symbol.iterator]()),
|
|
2990
|
+
onFailure: failCause$4,
|
|
2991
|
+
onDone: succeed$5
|
|
2992
|
+
});
|
|
2993
|
+
else {
|
|
2994
|
+
const value = next.value;
|
|
2995
|
+
return unwrap$2(map$10(f(value), (a2) => flatMap$4(write(of$2(a2)), () => loop(iterator))));
|
|
2996
|
+
}
|
|
2997
|
+
};
|
|
2998
|
+
return new StreamImpl(pipe(toChannel$1(self), pipeTo(suspend$5(() => loop(empty$5()[Symbol.iterator]())))));
|
|
2999
|
+
});
|
|
3000
|
+
/** @internal */
|
|
3001
|
+
const mergeEither$1 = /* @__PURE__ */ dual(2, (self, that) => mergeWith$1(self, that, {
|
|
3002
|
+
onSelf: left,
|
|
3003
|
+
onOther: right
|
|
3004
|
+
}));
|
|
3005
|
+
/** @internal */
|
|
3006
|
+
const mergeWith$1 = /* @__PURE__ */ dual(3, (self, other, options) => {
|
|
3007
|
+
const strategy = options.haltStrategy ? fromInput$1(options.haltStrategy) : Both;
|
|
3008
|
+
const handler = (terminate) => (exit) => terminate || !isSuccess$1(exit) ? Done(suspend$9(() => exit)) : Await((exit) => suspend$9(() => exit));
|
|
3009
|
+
return new StreamImpl(mergeWith$2(toChannel$1(map$2(self, options.onSelf)), {
|
|
3010
|
+
other: toChannel$1(map$2(other, options.onOther)),
|
|
3011
|
+
onSelfDone: handler(strategy._tag === "Either" || strategy._tag === "Left"),
|
|
3012
|
+
onOtherDone: handler(strategy._tag === "Either" || strategy._tag === "Right")
|
|
3013
|
+
}));
|
|
3014
|
+
});
|
|
3015
|
+
/** @internal */
|
|
3016
|
+
const rechunkProcess = (rechunker, target) => readWithCause({
|
|
3017
|
+
onInput: (chunk) => {
|
|
3018
|
+
if (chunk.length === target && rechunker.isEmpty()) return flatMap$4(write(chunk), () => rechunkProcess(rechunker, target));
|
|
3019
|
+
if (chunk.length > 0) {
|
|
3020
|
+
const chunks = [];
|
|
3021
|
+
let result = void 0;
|
|
3022
|
+
let index = 0;
|
|
3023
|
+
while (index < chunk.length) {
|
|
3024
|
+
while (index < chunk.length && result === void 0) {
|
|
3025
|
+
result = rechunker.write(pipe(chunk, unsafeGet$2(index)));
|
|
3026
|
+
index = index + 1;
|
|
3027
|
+
}
|
|
3028
|
+
if (result !== void 0) {
|
|
3029
|
+
chunks.push(result);
|
|
3030
|
+
result = void 0;
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
return flatMap$4(writeAll(...chunks), () => rechunkProcess(rechunker, target));
|
|
3034
|
+
}
|
|
3035
|
+
return suspend$5(() => rechunkProcess(rechunker, target));
|
|
3036
|
+
},
|
|
3037
|
+
onFailure: (cause) => zipRight$5(rechunker.emitIfNotEmpty(), failCause$4(cause)),
|
|
3038
|
+
onDone: () => rechunker.emitIfNotEmpty()
|
|
3039
|
+
});
|
|
3040
|
+
/** @internal */
|
|
3041
|
+
const repeatEffectChunkOption$1 = (effect) => unfoldChunkEffect$1(effect, (effect) => pipe(map$10(effect, (chunk) => some$2([chunk, effect])), catchAll$7(match$10({
|
|
3042
|
+
onNone: () => succeed$10(none()),
|
|
3043
|
+
onSome: fail$10
|
|
3044
|
+
}))));
|
|
3045
|
+
/** @internal */
|
|
3046
|
+
const repeatEffectOption$1 = (effect) => repeatEffectChunkOption$1(pipe(effect, map$10(of$2)));
|
|
3047
|
+
/** @internal */
|
|
3048
|
+
const run$1 = /* @__PURE__ */ dual(2, (self, sink) => toChannel$1(self).pipe(pipeToOrFail(toChannel$2(sink)), runDrain$2));
|
|
3049
|
+
/** @internal */
|
|
3050
|
+
const runHead$1 = (self) => run$1(self, head());
|
|
3051
|
+
/** @internal */
|
|
3052
|
+
const scoped$1 = (effect) => new StreamImpl(ensuring$4(scoped$2(pipe(effect, map$10(of$2))), _void));
|
|
3053
|
+
/** @internal */
|
|
3054
|
+
const suspend$1 = (stream) => new StreamImpl(suspend$5(() => toChannel$1(stream())));
|
|
3055
|
+
/** @internal */
|
|
3056
|
+
const tap$2 = /* @__PURE__ */ dual(2, (self, f) => mapEffectSequential(self, (a) => as$5(f(a), a)));
|
|
3057
|
+
/** @internal */
|
|
3058
|
+
const toPull$1 = (self) => map$10(toPull$2(toChannel$1(self)), (pull) => pipe(pull, mapError$5(some$2), flatMap$8(match$8({
|
|
3059
|
+
onLeft: () => fail$10(none()),
|
|
3060
|
+
onRight: succeed$10
|
|
3061
|
+
}))));
|
|
3062
|
+
/** @internal */
|
|
3063
|
+
const unfoldChunkEffect$1 = (s, f) => suspend$1(() => {
|
|
3064
|
+
const loop = (s) => unwrap$2(map$10(f(s), match$10({
|
|
3065
|
+
onNone: () => void_$3,
|
|
3066
|
+
onSome: ([chunk, s]) => flatMap$4(write(chunk), () => loop(s))
|
|
3067
|
+
})));
|
|
3068
|
+
return new StreamImpl(loop(s));
|
|
3069
|
+
});
|
|
3070
|
+
/** @internal */
|
|
3071
|
+
const unwrapScoped$1 = (effect) => flatten$1(scoped$1(effect));
|
|
3072
|
+
const zipLatestAll$1 = (...streams) => {
|
|
3073
|
+
if (streams.length === 0) return empty$1;
|
|
3074
|
+
else if (streams.length === 1) return map$2(streams[0], (x) => [x]);
|
|
3075
|
+
const [head, ...tail] = streams;
|
|
3076
|
+
return zipLatestWith$1(head, zipLatestAll$1(...tail), (first, second) => [first, ...second]);
|
|
3077
|
+
};
|
|
3078
|
+
/** @internal */
|
|
3079
|
+
const zipLatestWith$1 = /* @__PURE__ */ dual(3, (left, right, f) => {
|
|
3080
|
+
const pullNonEmpty = (pull) => pipe(pull, flatMap$8((chunk) => isEmpty$8(chunk) ? pullNonEmpty(pull) : succeed$10(chunk)));
|
|
3081
|
+
return pipe(toPull$1(left), map$10(pullNonEmpty), zip$4(pipe(toPull$1(right), map$10(pullNonEmpty))), flatMap$8(([left, right]) => pipe(fromEffectOption$1(raceWith$1(left, right, {
|
|
3082
|
+
onSelfDone: (leftDone, rightFiber) => pipe(suspend$9(() => leftDone), zipWith$7(join(rightFiber), (l, r) => [
|
|
3083
|
+
l,
|
|
3084
|
+
r,
|
|
3085
|
+
true
|
|
3086
|
+
])),
|
|
3087
|
+
onOtherDone: (rightDone, leftFiber) => pipe(suspend$9(() => rightDone), zipWith$7(join(leftFiber), (l, r) => [
|
|
3088
|
+
r,
|
|
3089
|
+
l,
|
|
3090
|
+
false
|
|
3091
|
+
]))
|
|
3092
|
+
})), flatMap$1(([l, r, leftFirst]) => pipe(fromEffect$1(make$18([unsafeLast(l), unsafeLast(r)])), flatMap$1((latest) => pipe(fromChunk$1(leftFirst ? pipe(r, map$13((a2) => f(unsafeLast(l), a2))) : pipe(l, map$13((a) => f(a, unsafeLast(r))))), concat$2(pipe(repeatEffectOption$1(left), mergeEither$1(repeatEffectOption$1(right)), mapEffectSequential(match$8({
|
|
3093
|
+
onLeft: (leftChunk) => modify$1(latest, ([_, rightLatest]) => [pipe(leftChunk, map$13((a) => f(a, rightLatest))), [unsafeLast(leftChunk), rightLatest]]),
|
|
3094
|
+
onRight: (rightChunk) => modify$1(latest, ([leftLatest, _]) => [pipe(rightChunk, map$13((a2) => f(leftLatest, a2))), [leftLatest, unsafeLast(rightChunk)]])
|
|
3095
|
+
})), flatMap$1(fromChunk$1))))))), toPull$1)), fromPull$1);
|
|
3096
|
+
});
|
|
3097
|
+
/**
|
|
3098
|
+
* Finds the first element emitted by this stream that satisfies the provided
|
|
3099
|
+
* predicate.
|
|
3100
|
+
*
|
|
3101
|
+
* @since 2.0.0
|
|
3102
|
+
* @category elements
|
|
3103
|
+
*/
|
|
3104
|
+
const find = find$1;
|
|
3105
|
+
/**
|
|
3106
|
+
* Runs the stream to completion and yields the first value emitted by it,
|
|
3107
|
+
* discarding the rest of the elements.
|
|
3108
|
+
*
|
|
3109
|
+
* @since 2.0.0
|
|
3110
|
+
* @category destructors
|
|
3111
|
+
*/
|
|
3112
|
+
const runHead = runHead$1;
|
|
3113
|
+
/**
|
|
3114
|
+
* Adds an effect to consumption of every element of the stream.
|
|
3115
|
+
*
|
|
3116
|
+
* @example
|
|
3117
|
+
* ```ts
|
|
3118
|
+
* import { Console, Effect, Stream } from "effect"
|
|
3119
|
+
*
|
|
3120
|
+
* const stream = Stream.make(1, 2, 3).pipe(
|
|
3121
|
+
* Stream.tap((n) => Console.log(`before mapping: ${n}`)),
|
|
3122
|
+
* Stream.map((n) => n * 2),
|
|
3123
|
+
* Stream.tap((n) => Console.log(`after mapping: ${n}`))
|
|
3124
|
+
* )
|
|
3125
|
+
*
|
|
3126
|
+
* Effect.runPromise(Stream.runCollect(stream)).then(console.log)
|
|
3127
|
+
* // before mapping: 1
|
|
3128
|
+
* // after mapping: 2
|
|
3129
|
+
* // before mapping: 2
|
|
3130
|
+
* // after mapping: 4
|
|
3131
|
+
* // before mapping: 3
|
|
3132
|
+
* // after mapping: 6
|
|
3133
|
+
* // { _id: 'Chunk', values: [ 2, 4, 6 ] }
|
|
3134
|
+
* ```
|
|
3135
|
+
*
|
|
3136
|
+
* @since 2.0.0
|
|
3137
|
+
* @category sequencing
|
|
3138
|
+
*/
|
|
3139
|
+
const tap$1 = tap$2;
|
|
3140
|
+
//#endregion
|
|
3141
|
+
//#region ../../packages/lib/vendor/src/midnight-facade-reservations.ts
|
|
3142
|
+
const NO_BALANCING_TRANSACTION = "No balancing transaction was created. Please check your transaction.";
|
|
3143
|
+
const releasingOnFailure = async (build) => {
|
|
3144
|
+
const releases = [];
|
|
3145
|
+
const reserve = (transaction, holder) => {
|
|
3146
|
+
if (transaction) releases.push(async () => holder.revertTransaction(transaction));
|
|
3147
|
+
return transaction;
|
|
3148
|
+
};
|
|
3149
|
+
try {
|
|
3150
|
+
return await build(reserve);
|
|
3151
|
+
} catch (error) {
|
|
3152
|
+
await Promise.allSettled(releases.map(async (release) => release()));
|
|
3153
|
+
throw error;
|
|
3154
|
+
}
|
|
3155
|
+
};
|
|
3156
|
+
const merge$1 = (first, second) => first && second ? first.merge(second) : first ?? second;
|
|
3157
|
+
const kindsToBalance = (tokenKindsToBalance = "all") => {
|
|
3158
|
+
const kinds = tokenKindsToBalance === "all" ? [
|
|
3159
|
+
"shielded",
|
|
3160
|
+
"unshielded",
|
|
3161
|
+
"dust"
|
|
3162
|
+
] : tokenKindsToBalance;
|
|
3163
|
+
return {
|
|
3164
|
+
dust: kinds.includes("dust"),
|
|
3165
|
+
shielded: kinds.includes("shielded"),
|
|
3166
|
+
unshielded: kinds.includes("unshielded")
|
|
3167
|
+
};
|
|
3168
|
+
};
|
|
3169
|
+
/**
|
|
3170
|
+
* The wallet SDK's multi-step builds over `facade`, releasing the coins the
|
|
3171
|
+
* completed steps reserved when a later step fails. The wallet SDK keeps
|
|
3172
|
+
* them, and its caller gets an error with no recipe to release. Each build
|
|
3173
|
+
* takes the same steps over the same sub-wallets as its `WalletFacade`
|
|
3174
|
+
* namesake and returns the same recipe.
|
|
3175
|
+
*/
|
|
3176
|
+
const withReservationRelease = (facade) => ({
|
|
3177
|
+
balanceFinalizedTransaction: async (transaction, { shieldedSecretKeys, dustSecretKey }, { ttl, tokenKindsToBalance }) => releasingOnFailure(async (reserve) => {
|
|
3178
|
+
const balance = kindsToBalance(tokenKindsToBalance);
|
|
3179
|
+
const unshieldedBalancing = balance.unshielded ? reserve(await facade.unshielded.balanceFinalizedTransaction(transaction), facade.unshielded) : void 0;
|
|
3180
|
+
const tokenBalancing = merge$1(balance.shielded ? reserve(await facade.shielded.balanceTransaction(shieldedSecretKeys, transaction), facade.shielded) : void 0, unshieldedBalancing);
|
|
3181
|
+
const balancingTransaction = merge$1(tokenBalancing, balance.dust ? await facade.dust.balanceTransactions(dustSecretKey, tokenBalancing ? [transaction, tokenBalancing] : [transaction], ttl) : void 0);
|
|
3182
|
+
if (!balancingTransaction) throw new Error(NO_BALANCING_TRANSACTION);
|
|
3183
|
+
return {
|
|
3184
|
+
type: "FINALIZED_TRANSACTION",
|
|
3185
|
+
originalTransaction: transaction,
|
|
3186
|
+
balancingTransaction
|
|
3187
|
+
};
|
|
3188
|
+
}),
|
|
3189
|
+
balanceUnboundTransaction: async (transaction, { shieldedSecretKeys, dustSecretKey }, { ttl, tokenKindsToBalance }) => releasingOnFailure(async (reserve) => {
|
|
3190
|
+
const balance = kindsToBalance(tokenKindsToBalance);
|
|
3191
|
+
const shieldedBalancing = balance.shielded ? reserve(await facade.shielded.balanceTransaction(shieldedSecretKeys, transaction), facade.shielded) : void 0;
|
|
3192
|
+
const balancedUnshielded = balance.unshielded ? await facade.unshielded.balanceUnboundTransaction(transaction) : void 0;
|
|
3193
|
+
const baseTransaction = balancedUnshielded ?? transaction;
|
|
3194
|
+
const balancingTransaction = merge$1(shieldedBalancing, balance.dust ? await facade.dust.balanceTransactions(dustSecretKey, shieldedBalancing ? [baseTransaction, shieldedBalancing] : [baseTransaction], ttl) : void 0);
|
|
3195
|
+
if (!balancingTransaction && !balancedUnshielded) throw new Error(NO_BALANCING_TRANSACTION);
|
|
3196
|
+
return {
|
|
3197
|
+
type: "UNBOUND_TRANSACTION",
|
|
3198
|
+
baseTransaction,
|
|
3199
|
+
balancingTransaction: balancingTransaction ?? void 0
|
|
3200
|
+
};
|
|
3201
|
+
}),
|
|
3202
|
+
transferTransaction: async (outputs, { shieldedSecretKeys, dustSecretKey }, { ttl, payFees = true }) => releasingOnFailure(async (reserve) => {
|
|
3203
|
+
const shieldedOutputs = outputs.flatMap((output) => output.type === "shielded" ? output.outputs : []);
|
|
3204
|
+
const unshieldedOutputs = outputs.flatMap((output) => output.type === "unshielded" ? output.outputs : []);
|
|
3205
|
+
if (unshieldedOutputs.length === 0 && shieldedOutputs.length === 0) throw new Error("At least one shielded or unshielded output is required.");
|
|
3206
|
+
const transfer = merge$1(shieldedOutputs.length > 0 ? reserve(await facade.shielded.transferTransaction(shieldedSecretKeys, shieldedOutputs), facade.shielded) : void 0, unshieldedOutputs.length > 0 ? reserve(await facade.unshielded.transferTransaction(unshieldedOutputs, ttl), facade.unshielded) : void 0);
|
|
3207
|
+
if (!transfer) throw new Error("Unexpected transaction state.");
|
|
3208
|
+
return {
|
|
3209
|
+
type: "UNPROVEN_TRANSACTION",
|
|
3210
|
+
transaction: merge$1(transfer, payFees ? await facade.dust.balanceTransactions(dustSecretKey, [transfer], ttl) : void 0) ?? transfer
|
|
3211
|
+
};
|
|
3212
|
+
}),
|
|
3213
|
+
initSwap: async ({ desiredInputs, desiredOutputs }, { shieldedSecretKeys, dustSecretKey }, { ttl, payFees = false }) => releasingOnFailure(async (reserve) => {
|
|
3214
|
+
const { shielded: shieldedInputs, unshielded: unshieldedInputs } = desiredInputs;
|
|
3215
|
+
const shieldedOutputs = desiredOutputs.flatMap((output) => output.type === "shielded" ? output.outputs : []);
|
|
3216
|
+
const unshieldedOutputs = desiredOutputs.flatMap((output) => output.type === "unshielded" ? output.outputs : []);
|
|
3217
|
+
const hasShieldedPart = !!shieldedInputs && Object.keys(shieldedInputs).length > 0 || shieldedOutputs.length > 0;
|
|
3218
|
+
const hasUnshieldedPart = !!unshieldedInputs && Object.keys(unshieldedInputs).length > 0 || unshieldedOutputs.length > 0;
|
|
3219
|
+
if (!hasShieldedPart && !hasUnshieldedPart) throw new Error("At least one shielded or unshielded swap is required.");
|
|
3220
|
+
const swap = merge$1(hasShieldedPart && shieldedInputs !== void 0 ? reserve(await facade.shielded.initSwap(shieldedSecretKeys, shieldedInputs, shieldedOutputs), facade.shielded) : void 0, hasUnshieldedPart && unshieldedInputs !== void 0 ? reserve(await facade.unshielded.initSwap(unshieldedInputs, unshieldedOutputs, ttl), facade.unshielded) : void 0);
|
|
3221
|
+
if (!swap) throw new Error("Unexpected transaction state.");
|
|
3222
|
+
return {
|
|
3223
|
+
type: "UNPROVEN_TRANSACTION",
|
|
3224
|
+
transaction: merge$1(swap, payFees ? await facade.dust.balanceTransactions(dustSecretKey, [swap], ttl) : void 0) ?? swap
|
|
3225
|
+
};
|
|
3226
|
+
})
|
|
3227
|
+
});
|
|
3228
|
+
//#endregion
|
|
3229
|
+
//#region ../../packages/lib/vendor/src/midnight-submission-service.ts
|
|
3230
|
+
const observers = /* @__PURE__ */ new WeakMap();
|
|
3231
|
+
const awaitDisconnection = (client) => async((resume) => {
|
|
3232
|
+
if (!client.api.isConnected) {
|
|
3233
|
+
resume(_void);
|
|
3234
|
+
return;
|
|
3235
|
+
}
|
|
3236
|
+
const disconnected = () => {
|
|
3237
|
+
resume(_void);
|
|
3238
|
+
};
|
|
3239
|
+
client.api.once("disconnected", disconnected);
|
|
3240
|
+
return sync$8(() => client.api.off("disconnected", disconnected));
|
|
3241
|
+
});
|
|
3242
|
+
/** Preserve facade submission/rollback semantics while observing its single stream. */
|
|
3243
|
+
const createProgressSubmissionService = ({ relayURL }) => {
|
|
3244
|
+
const scope = runSync$1(make$19());
|
|
3245
|
+
const submissions = runSync$1(makeSemaphore(1));
|
|
3246
|
+
const connection = PolkadotNodeClient.make({ nodeURL: relayURL }).pipe(provideService$6(Scope, scope), tap$7(awaitDisconnection), cached$1, runSync$1);
|
|
3247
|
+
const submit = async (tx, waitFor = "InBlock") => {
|
|
3248
|
+
const serialized = SerializedTransaction.from(tx);
|
|
3249
|
+
return connection.pipe(flatMap$8((client) => client.sendMidnightTransaction(serialized).pipe(tap$1((event) => sync$8(() => observers.get(tx)?.(event._tag))), find((event) => event._tag === waitFor), runHead, flatMap$8(match$10({
|
|
3250
|
+
onSome: succeed$10,
|
|
3251
|
+
onNone: () => fail$10(new NodeClientError.TransactionProgressError({
|
|
3252
|
+
message: "Transaction did not reach desired stage",
|
|
3253
|
+
txData: serialized,
|
|
3254
|
+
desiredStage: waitFor
|
|
3255
|
+
}))
|
|
3256
|
+
})), ensuring$5(awaitDisconnection(client)))), submissions.withPermits(1), mapError$5((cause) => new SubmissionError({
|
|
3257
|
+
message: "Transaction submission error",
|
|
3258
|
+
cause
|
|
3259
|
+
})), runPromise$1);
|
|
3260
|
+
};
|
|
3261
|
+
return {
|
|
3262
|
+
submitTransaction: submit,
|
|
3263
|
+
close: async () => close(scope, void_$5).pipe(ignoreLogged, runPromise$1)
|
|
3264
|
+
};
|
|
3265
|
+
};
|
|
3266
|
+
//#endregion
|
|
3267
|
+
//#region ../../packages/module/midnight-sync/src/store/compute-sync-ratio.ts
|
|
3268
|
+
const computeConnectedSyncRatio = (applied, highest, isConnected) => isConnected && applied === 0n && highest === 0n ? Percent(1) : computeSyncRatio(applied, highest);
|
|
3269
|
+
const computeSyncRatio = (applied, highest) => {
|
|
3270
|
+
if (highest === 0n) {
|
|
3271
|
+
if (applied === 0n) return Percent(0);
|
|
3272
|
+
const ratio = 1 - 1 / (1 + Number(applied) / 1e3);
|
|
3273
|
+
return Percent(Math.min(.99, ratio));
|
|
3274
|
+
}
|
|
3275
|
+
return Percent(Math.min(1, Number(applied) / Number(highest)));
|
|
3276
|
+
};
|
|
3277
|
+
//#endregion
|
|
3278
|
+
//#region ../../packages/module/midnight-sync/src/store/dependencies.ts
|
|
3279
|
+
/**
|
|
3280
|
+
* Wraps keyManager.keys$ with recovery for AuthenticationCancelledError.
|
|
3281
|
+
* If the user cancels the auth prompt, waits for keys to become available
|
|
3282
|
+
* from another source (e.g., an unlock triggered by a different flow)
|
|
3283
|
+
* and retries.
|
|
3284
|
+
*/
|
|
3285
|
+
const keysWithAuthCancelledRecovery$ = (keyManager) => keyManager.keys$.pipe(take(1), catchError((error) => {
|
|
3286
|
+
if (!(error instanceof AuthenticationCancelledError)) return throwError(() => error);
|
|
3287
|
+
return keyManager.areKeysAvailable$.pipe(filter((available) => available), take(1), switchMap(() => keyManager.keys$.pipe(take(1))));
|
|
3288
|
+
}));
|
|
3289
|
+
const STATE_SERIALISATION_THROTTLE_TIME = Milliseconds(5e3);
|
|
3290
|
+
const DEFAULT_BATCH_UPDATES = {
|
|
3291
|
+
size: 12,
|
|
3292
|
+
spacing: 4
|
|
3293
|
+
};
|
|
3294
|
+
/**
|
|
3295
|
+
* Restore accepts the legacy `unshieldedTxHistory` key so profiles written
|
|
3296
|
+
* before the persisted key was renamed load without a resync; the next persist
|
|
3297
|
+
* rewrites the doc under `txHistory`, migrating it lazily.
|
|
3298
|
+
*/
|
|
3299
|
+
const readPersistedTxHistory = (serializedState) => serializedState.txHistory ?? serializedState.unshieldedTxHistory;
|
|
3300
|
+
/**
|
|
3301
|
+
* djb2 over the serialized states. The previous-persist comparator must not
|
|
3302
|
+
* RETAIN the inputs: keeping the raw serialized strings would pin ~10MB per
|
|
3303
|
+
* synced wallet in service worker memory between persist cycles.
|
|
3304
|
+
*/
|
|
3305
|
+
const fingerprintOf = (parts) => {
|
|
3306
|
+
let hash = 5381;
|
|
3307
|
+
for (const part of parts) for (let index = 0; index < part.length; index += 1) {
|
|
3308
|
+
hash = hash * 33 ^ part.charCodeAt(index);
|
|
3309
|
+
hash |= 0;
|
|
3310
|
+
}
|
|
3311
|
+
return `${hash}:${parts.map((part) => part.length).join(":")}`;
|
|
3312
|
+
};
|
|
3313
|
+
const getAccountWalletInstance = async ({ account, config, getTemenosLedgerIndexerUrl, store, keyManager }, logger, { createAttestedProver, createLocalProofServerAccess, batchUpdates = DEFAULT_BATCH_UPDATES }) => {
|
|
3314
|
+
const walletState = await firstValueFrom(store.get(String(account.accountId)).pipe(defaultIfEmpty(void 0)));
|
|
3315
|
+
const indexerClientConnection = {
|
|
3316
|
+
indexerHttpUrl: config.indexerAddress,
|
|
3317
|
+
indexerWsUrl: convertHttpUrlToWebsocket(config.indexerAddress),
|
|
3318
|
+
keepAlive: 15e3
|
|
3319
|
+
};
|
|
3320
|
+
const { networkId } = account.blockchainSpecific;
|
|
3321
|
+
const proofServerUrl = getProofServerEndpoint(config.proofServer);
|
|
3322
|
+
if (!proofServerUrl && config.proofServer.kind !== "in-process") throw new Error(`Cannot start Midnight wallet: proof server mode "${config.proofServer.kind}" has no HTTP endpoint`);
|
|
3323
|
+
assertProofServerRouting(config.proofServer, !!createAttestedProver, !!createLocalProofServerAccess);
|
|
3324
|
+
const createAccess = (onProgress) => config.proofServer.kind === "in-process" && createLocalProofServerAccess ? createLocalProofServerAccess(onProgress) : config.proofServer.kind === "tee-delegated" && createAttestedProver ? createAttestedProofServerAccess(createAttestedProver({
|
|
3325
|
+
networkId,
|
|
3326
|
+
proofServerApiUrl: config.proofServer.url,
|
|
3327
|
+
getLedgerIndexerUrl: async () => {
|
|
3328
|
+
if (!getTemenosLedgerIndexerUrl) throw new Error("Temenos attestation requires a ledger indexer resolver");
|
|
3329
|
+
return getTemenosLedgerIndexerUrl();
|
|
3330
|
+
}
|
|
3331
|
+
}), onProgress) : createProofServerAccess(createHttpProofServerTransport(proofServerUrl));
|
|
3332
|
+
const proofServer = createScopedProofServerAccess(createAccess);
|
|
3333
|
+
const { finalizeRecipe } = proofServer;
|
|
3334
|
+
const configuration = {
|
|
3335
|
+
costParameters: {
|
|
3336
|
+
additionalFeeOverhead: 300000000000000n,
|
|
3337
|
+
feeBlocksMargin: 5
|
|
3338
|
+
},
|
|
3339
|
+
networkId,
|
|
3340
|
+
batchUpdates,
|
|
3341
|
+
indexerClientConnection,
|
|
3342
|
+
relayURL: new URL(convertHttpUrlToWebsocket(config.nodeAddress)),
|
|
3343
|
+
txHistoryStorage: new InMemoryTransactionHistoryStorage(WalletEntrySchema, mergeWalletEntries)
|
|
3344
|
+
};
|
|
3345
|
+
if (walletState) {
|
|
3346
|
+
const { dust, shielded, unshielded } = walletState.serializedState;
|
|
3347
|
+
let restoredTxHistoryStorage;
|
|
3348
|
+
try {
|
|
3349
|
+
restoredTxHistoryStorage = InMemoryTransactionHistoryStorage.restore(SerialisedWalletState.toJSON(readPersistedTxHistory(walletState.serializedState)), WalletEntrySchema, mergeWalletEntries);
|
|
3350
|
+
} catch (error) {
|
|
3351
|
+
logger.warn(`Discarding unreadable persisted Midnight wallet state for account ${account.accountId}; rebuilding from seed`, error instanceof Error ? error.message : String(error));
|
|
3352
|
+
await firstValueFrom(store.removeWhere((state) => state.accountId === account.accountId).pipe(defaultIfEmpty(void 0), catchError((wipeError) => {
|
|
3353
|
+
logger.error(`Failed to discard unreadable Midnight wallet state for account ${account.accountId}`, wipeError);
|
|
3354
|
+
return of(void 0);
|
|
3355
|
+
})));
|
|
3356
|
+
}
|
|
3357
|
+
if (restoredTxHistoryStorage) {
|
|
3358
|
+
configuration.txHistoryStorage = restoredTxHistoryStorage;
|
|
3359
|
+
return {
|
|
3360
|
+
walletFacade: await WalletFacade.init({
|
|
3361
|
+
configuration,
|
|
3362
|
+
provingService: () => proofServer.provingService,
|
|
3363
|
+
submissionService: createProgressSubmissionService,
|
|
3364
|
+
shielded: (config) => ShieldedWallet(config).restore(SerialisedWalletState.toJSON(shielded)),
|
|
3365
|
+
unshielded: (config) => UnshieldedWallet(config).restore(SerialisedWalletState.toJSON(unshielded)),
|
|
3366
|
+
dust: (config) => DustWallet(config).restore(SerialisedWalletState.toJSON(dust))
|
|
3367
|
+
}),
|
|
3368
|
+
txHistoryStorage: restoredTxHistoryStorage,
|
|
3369
|
+
proofCircuitProvider: proofServer.circuits,
|
|
3370
|
+
finalizeRecipe
|
|
3371
|
+
};
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
const { walletKeys: { dustKeyBuffer, zswapKeyBuffer }, unshieldedKeystore } = await firstValueFrom(keysWithAuthCancelledRecovery$(keyManager));
|
|
3375
|
+
const dustParameters = ledger.LedgerParameters.initialParameters().dust;
|
|
3376
|
+
const txHistoryStorage = new InMemoryTransactionHistoryStorage(WalletEntrySchema, mergeWalletEntries);
|
|
3377
|
+
configuration.txHistoryStorage = txHistoryStorage;
|
|
3378
|
+
return {
|
|
3379
|
+
walletFacade: await WalletFacade.init({
|
|
3380
|
+
configuration,
|
|
3381
|
+
provingService: () => proofServer.provingService,
|
|
3382
|
+
submissionService: createProgressSubmissionService,
|
|
3383
|
+
shielded: (config) => ShieldedWallet(config).startWithSeed(zswapKeyBuffer),
|
|
3384
|
+
unshielded: (config) => UnshieldedWallet(config).startWithPublicKey(PublicKey.fromKeyStore(unshieldedKeystore)),
|
|
3385
|
+
dust: (config) => DustWallet(config).startWithSeed(dustKeyBuffer, dustParameters)
|
|
3386
|
+
}),
|
|
3387
|
+
txHistoryStorage,
|
|
3388
|
+
proofCircuitProvider: proofServer.circuits,
|
|
3389
|
+
finalizeRecipe
|
|
3390
|
+
};
|
|
3391
|
+
};
|
|
3392
|
+
/**
|
|
3393
|
+
* Creates an observable MidnightWallet from wallet instances.
|
|
3394
|
+
*
|
|
3395
|
+
* The nightVerifyingKey is obtained from the wallet state, which works
|
|
3396
|
+
* for both restored and new wallets.
|
|
3397
|
+
*/
|
|
3398
|
+
const createAccountObservableMidnightWallet = ({ account, keyManager, walletFacade, haltPersistence, proofCircuitProvider, finalizeRecipe }) => {
|
|
3399
|
+
const { networkId } = account.blockchainSpecific;
|
|
3400
|
+
const state$ = walletFacade.state().pipe(shareReplay({
|
|
3401
|
+
bufferSize: 1,
|
|
3402
|
+
refCount: true
|
|
3403
|
+
}));
|
|
3404
|
+
const releasing = withReservationRelease(walletFacade);
|
|
3405
|
+
return state$.pipe(take(1), map((initialState) => {
|
|
3406
|
+
const nightVerifyingKey = initialState.unshielded.capabilities.keys.getPublicKey(initialState.unshielded.state);
|
|
3407
|
+
return {
|
|
3408
|
+
accountId: account.accountId,
|
|
3409
|
+
areKeysAvailable$: keyManager.areKeysAvailable$,
|
|
3410
|
+
networkId,
|
|
3411
|
+
nightVerifyingKey,
|
|
3412
|
+
proofCircuitProvider,
|
|
3413
|
+
walletId: account.walletId,
|
|
3414
|
+
address$: state$.pipe(map(({ dust, shielded, unshielded }) => ({
|
|
3415
|
+
dust: MidnightDustAddress(DustAddress.codec.encode(networkId, dust.capabilities.keys.getAddress(dust.state)).asString()),
|
|
3416
|
+
shielded: MidnightShieldedAddress(ShieldedAddress.codec.encode(networkId, shielded.address).asString()),
|
|
3417
|
+
unshielded: MidnightUnshieldedAddress(UnshieldedAddress.codec.encode(networkId, unshielded.address).asString())
|
|
3418
|
+
})), distinctUntilChanged(deepEquals)),
|
|
3419
|
+
coinsByTokenType$: state$.pipe(map(({ shielded, unshielded }) => {
|
|
3420
|
+
const shieldedCoins = {};
|
|
3421
|
+
const unshieldedCoins = {};
|
|
3422
|
+
for (const { coin } of shielded.totalCoins) {
|
|
3423
|
+
const previousCoinsList = shieldedCoins[coin.type] || [];
|
|
3424
|
+
shieldedCoins[coin.type] = previousCoinsList.concat({
|
|
3425
|
+
status: "mt_index" in coin ? "available" : "pending",
|
|
3426
|
+
value: BigNumber(coin.value)
|
|
3427
|
+
});
|
|
3428
|
+
}
|
|
3429
|
+
const parseUnshieldedCoins = (status, coins) => {
|
|
3430
|
+
for (const { meta, utxo } of coins) {
|
|
3431
|
+
const tokenType = toUnshieldedTokenType(utxo.type, networkId);
|
|
3432
|
+
unshieldedCoins[tokenType] = (unshieldedCoins[tokenType] || []).concat({
|
|
3433
|
+
status,
|
|
3434
|
+
value: BigNumber(utxo.value),
|
|
3435
|
+
registeredForDustGeneration: meta.registeredForDustGeneration,
|
|
3436
|
+
ownerAddress: utxo.owner
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3439
|
+
};
|
|
3440
|
+
parseUnshieldedCoins("pending", unshielded.pendingCoins);
|
|
3441
|
+
parseUnshieldedCoins("available", unshielded.availableCoins);
|
|
3442
|
+
return {
|
|
3443
|
+
shielded: shieldedCoins,
|
|
3444
|
+
unshielded: unshieldedCoins
|
|
3445
|
+
};
|
|
3446
|
+
}), distinctUntilChanged(deepEquals)),
|
|
3447
|
+
syncProgress$: state$.pipe(map(({ dust, shielded, unshielded }) => ({
|
|
3448
|
+
dust: computeConnectedSyncRatio(dust.state.progress.appliedIndex, dust.state.progress.highestRelevantWalletIndex, dust.state.progress.isConnected),
|
|
3449
|
+
shielded: computeConnectedSyncRatio(shielded.state.progress.appliedIndex, shielded.state.progress.highestRelevantWalletIndex, shielded.state.progress.isConnected),
|
|
3450
|
+
unshielded: computeConnectedSyncRatio(unshielded.state.progress.appliedId, unshielded.state.progress.highestTransactionId, unshielded.state.progress.isConnected),
|
|
3451
|
+
isStrictlyComplete: {
|
|
3452
|
+
dust: dust.state.progress.isStrictlyComplete(),
|
|
3453
|
+
shielded: shielded.state.progress.isStrictlyComplete(),
|
|
3454
|
+
unshielded: unshielded.state.progress.isStrictlyComplete()
|
|
3455
|
+
}
|
|
3456
|
+
})), distinctUntilChanged(deepEquals)),
|
|
3457
|
+
transactionHistory$: state$.pipe(throttleTime(500, void 0, {
|
|
3458
|
+
leading: true,
|
|
3459
|
+
trailing: true
|
|
3460
|
+
}), switchMap(() => from(walletFacade.getAllFromTxHistory())), distinctUntilChanged(deepEquals)),
|
|
3461
|
+
balanceFinalizedTransaction: (tx, { ttl, tokenKindsToBalance }) => keyManager.keys$.pipe(take(1), switchMap(({ walletKeys: { dustSecretKey, zswapSecretKeys } }) => from(releasing.balanceFinalizedTransaction(tx, {
|
|
3462
|
+
shieldedSecretKeys: zswapSecretKeys,
|
|
3463
|
+
dustSecretKey
|
|
3464
|
+
}, {
|
|
3465
|
+
ttl,
|
|
3466
|
+
tokenKindsToBalance
|
|
3467
|
+
})))),
|
|
3468
|
+
balanceUnboundTransaction: (tx, { ttl, tokenKindsToBalance }) => keyManager.keys$.pipe(take(1), switchMap(({ walletKeys: { dustSecretKey, zswapSecretKeys } }) => from(releasing.balanceUnboundTransaction(tx, {
|
|
3469
|
+
shieldedSecretKeys: zswapSecretKeys,
|
|
3470
|
+
dustSecretKey
|
|
3471
|
+
}, {
|
|
3472
|
+
ttl,
|
|
3473
|
+
tokenKindsToBalance
|
|
3474
|
+
})))),
|
|
3475
|
+
balanceUnprovenTransaction: (tx, { ttl, tokenKindsToBalance }) => keyManager.keys$.pipe(take(1), switchMap(({ walletKeys: { dustSecretKey, zswapSecretKeys } }) => from(walletFacade.balanceUnprovenTransaction(tx, {
|
|
3476
|
+
shieldedSecretKeys: zswapSecretKeys,
|
|
3477
|
+
dustSecretKey
|
|
3478
|
+
}, {
|
|
3479
|
+
ttl,
|
|
3480
|
+
tokenKindsToBalance
|
|
3481
|
+
})))),
|
|
3482
|
+
calculateTransactionFee: (tx) => from(walletFacade.calculateTransactionFee(tx)),
|
|
3483
|
+
estimateTransactionFee: (tx, options) => keyManager.keys$.pipe(take(1), switchMap(({ walletKeys: { dustSecretKey } }) => from(walletFacade.estimateTransactionFee(tx, dustSecretKey, options)))),
|
|
3484
|
+
deregisterFromDustGeneration: (nightUtxos) => keyManager.keys$.pipe(take(1), switchMap(({ unshieldedKeystore }) => from(walletFacade.deregisterFromDustGeneration(nightUtxos, unshieldedKeystore.getPublicKey(), (data) => unshieldedKeystore.signData(data))))),
|
|
3485
|
+
getTransactionHistoryEntryByHash: (hash) => from(walletFacade.queryTxHistoryByHash(hash)),
|
|
3486
|
+
finalizeRecipe: (recipe, onProgress) => defer(async () => finalizeRecipe(walletFacade, recipe, onProgress)),
|
|
3487
|
+
finalizeTransaction: (recipe) => from(walletFacade.finalizeTransaction(recipe)),
|
|
3488
|
+
registerNightUtxosForDustGeneration: (nightUtxos, dustAddress) => keyManager.keys$.pipe(take(1), switchMap(({ unshieldedKeystore }) => from(walletFacade.registerNightUtxosForDustGeneration(nightUtxos, unshieldedKeystore.getPublicKey(), (data) => unshieldedKeystore.signData(data), dustAddress)))),
|
|
3489
|
+
revert: (recipe) => from(walletFacade.revert(recipe)),
|
|
3490
|
+
state: () => state$,
|
|
3491
|
+
stop: () => {
|
|
3492
|
+
haltPersistence();
|
|
3493
|
+
return from(walletFacade.stop());
|
|
3494
|
+
},
|
|
3495
|
+
signUnprovenTransaction: (tx) => keyManager.keys$.pipe(take(1), switchMap(({ unshieldedKeystore }) => from(walletFacade.signUnprovenTransaction(tx, (data) => unshieldedKeystore.signData(data))))),
|
|
3496
|
+
signRecipe: (recipe) => keyManager.keys$.pipe(take(1), switchMap(({ unshieldedKeystore }) => from(walletFacade.signRecipe(recipe, (data) => unshieldedKeystore.signData(data))))),
|
|
3497
|
+
signData: (data) => keyManager.keys$.pipe(take(1), map(({ unshieldedKeystore }) => ({
|
|
3498
|
+
signature: unshieldedKeystore.signData(data),
|
|
3499
|
+
verifyingKey: unshieldedKeystore.getPublicKey()
|
|
3500
|
+
}))),
|
|
3501
|
+
submitTransaction: (tx) => from(walletFacade.submitTransaction(tx)),
|
|
3502
|
+
transferTransaction: (outputs, { ttl, payFees }) => keyManager.keys$.pipe(take(1), switchMap(({ walletKeys: { dustSecretKey, zswapSecretKeys } }) => from(releasing.transferTransaction(outputs, {
|
|
3503
|
+
shieldedSecretKeys: zswapSecretKeys,
|
|
3504
|
+
dustSecretKey
|
|
3505
|
+
}, {
|
|
3506
|
+
ttl,
|
|
3507
|
+
payFees
|
|
3508
|
+
})))),
|
|
3509
|
+
initSwap: (desiredInputs, desiredOutputs, { ttl, payFees }) => keyManager.keys$.pipe(take(1), switchMap(({ walletKeys: { dustSecretKey, zswapSecretKeys } }) => from(releasing.initSwap({
|
|
3510
|
+
desiredInputs,
|
|
3511
|
+
desiredOutputs
|
|
3512
|
+
}, {
|
|
3513
|
+
shieldedSecretKeys: zswapSecretKeys,
|
|
3514
|
+
dustSecretKey
|
|
3515
|
+
}, {
|
|
3516
|
+
ttl,
|
|
3517
|
+
payFees
|
|
3518
|
+
}))))
|
|
3519
|
+
};
|
|
3520
|
+
}));
|
|
3521
|
+
};
|
|
3522
|
+
/**
|
|
3523
|
+
* Creates and manages the lifecycle of Midnight SDK wallet instances.
|
|
3524
|
+
*
|
|
3525
|
+
* Lifecycle:
|
|
3526
|
+
* - Creates all 3 wallets (Unshielded, Shielded, Dust) via getAccountWalletInstance
|
|
3527
|
+
* - Starts UnshieldedWallet immediately (no keys needed)
|
|
3528
|
+
* - Starts ShieldedWallet and DustWallet once account keys become available
|
|
3529
|
+
* (one auth prompt; sync then runs for the wallet's lifetime, surviving
|
|
3530
|
+
* the key manager's idle zeroization — see the start step below)
|
|
3531
|
+
* - DustWallet is never stopped once started
|
|
3532
|
+
* (SDK limitation: stop() closes Effect runtime, breaking calculateFee)
|
|
3533
|
+
* - On unsubscribe: stops all wallets and clears the sync key copy
|
|
3534
|
+
*/
|
|
3535
|
+
const createAndManageWallets = (props, { logger }, options) => {
|
|
3536
|
+
const { keyManager, account, store } = props;
|
|
3537
|
+
return new Observable((subscriber) => {
|
|
3538
|
+
let walletFacade = null;
|
|
3539
|
+
let syncSecretKeys = null;
|
|
3540
|
+
let syncDustSecretKey = null;
|
|
3541
|
+
let syncStartSubscription = null;
|
|
3542
|
+
let persistSubscription = null;
|
|
3543
|
+
let isDestroyed = false;
|
|
3544
|
+
let isPersistenceHalted = false;
|
|
3545
|
+
const init = async () => {
|
|
3546
|
+
const { walletFacade: facade, txHistoryStorage, proofCircuitProvider, finalizeRecipe } = await getAccountWalletInstance(props, logger, options);
|
|
3547
|
+
if (isDestroyed) {
|
|
3548
|
+
facade.stop();
|
|
3549
|
+
return;
|
|
3550
|
+
}
|
|
3551
|
+
walletFacade = facade;
|
|
3552
|
+
await walletFacade.unshielded.start();
|
|
3553
|
+
syncStartSubscription = keysWithAuthCancelledRecovery$(keyManager).pipe(switchMap((keys) => {
|
|
3554
|
+
if (!walletFacade) return from(Promise.resolve());
|
|
3555
|
+
syncSecretKeys = ledger.ZswapSecretKeys.fromSeed(keys.walletKeys.zswapKeyBuffer);
|
|
3556
|
+
syncDustSecretKey = ledger.DustSecretKey.fromSeed(keys.walletKeys.dustKeyBuffer);
|
|
3557
|
+
const facade = walletFacade;
|
|
3558
|
+
const syncKeys = syncSecretKeys;
|
|
3559
|
+
const dustSyncKey = syncDustSecretKey;
|
|
3560
|
+
return from((async () => {
|
|
3561
|
+
const failures = [];
|
|
3562
|
+
try {
|
|
3563
|
+
await facade.shielded.start(syncKeys);
|
|
3564
|
+
} catch (error) {
|
|
3565
|
+
logger.error(`Midnight shielded wallet failed to start for account ${account.accountId}:`, error);
|
|
3566
|
+
failures.push(error);
|
|
3567
|
+
}
|
|
3568
|
+
try {
|
|
3569
|
+
await facade.dust.start(dustSyncKey);
|
|
3570
|
+
} catch (error) {
|
|
3571
|
+
logger.error(`Midnight dust wallet failed to start for account ${account.accountId}:`, error);
|
|
3572
|
+
failures.push(error);
|
|
3573
|
+
}
|
|
3574
|
+
if (failures.length > 0) throw failures[0];
|
|
3575
|
+
})());
|
|
3576
|
+
})).subscribe({ error: (error) => {
|
|
3577
|
+
logger.error(`Wallet sync start error for account ${account.accountId}:`, error);
|
|
3578
|
+
subscriber.error(error);
|
|
3579
|
+
} });
|
|
3580
|
+
let lastPersistedFingerprint;
|
|
3581
|
+
const persistOnce = async () => {
|
|
3582
|
+
const [dust, shielded, unshielded, txHistory] = (await firstValueFrom(zip(from(walletFacade.dust.serializeState()), from(walletFacade.shielded.serializeState()), from(walletFacade.unshielded.serializeState()), from(txHistoryStorage.serialize())))).map(SerialisedWalletState);
|
|
3583
|
+
const fingerprint = fingerprintOf([
|
|
3584
|
+
dust,
|
|
3585
|
+
shielded,
|
|
3586
|
+
unshielded,
|
|
3587
|
+
txHistory
|
|
3588
|
+
]);
|
|
3589
|
+
if (fingerprint === lastPersistedFingerprint) return;
|
|
3590
|
+
if (isPersistenceHalted || isDestroyed) return;
|
|
3591
|
+
await firstValueFrom(store.upsert({
|
|
3592
|
+
serializedState: {
|
|
3593
|
+
dust,
|
|
3594
|
+
shielded,
|
|
3595
|
+
unshielded,
|
|
3596
|
+
txHistory
|
|
3597
|
+
},
|
|
3598
|
+
accountId: account.accountId,
|
|
3599
|
+
walletId: account.walletId,
|
|
3600
|
+
networkId: account.blockchainSpecific.networkId
|
|
3601
|
+
}).pipe(defaultIfEmpty(void 0)));
|
|
3602
|
+
lastPersistedFingerprint = fingerprint;
|
|
3603
|
+
};
|
|
3604
|
+
persistSubscription = walletFacade.state().pipe(throttleTime(STATE_SERIALISATION_THROTTLE_TIME, void 0, {
|
|
3605
|
+
leading: true,
|
|
3606
|
+
trailing: true
|
|
3607
|
+
}), exhaustMap(() => from(persistOnce()).pipe(catchError((error) => {
|
|
3608
|
+
logger.error(`Failed to persist wallet state for account ${account.accountId}:`, error);
|
|
3609
|
+
return of(void 0);
|
|
3610
|
+
})))).subscribe();
|
|
3611
|
+
subscriber.next({
|
|
3612
|
+
walletFacade,
|
|
3613
|
+
haltPersistence: () => {
|
|
3614
|
+
isPersistenceHalted = true;
|
|
3615
|
+
},
|
|
3616
|
+
proofCircuitProvider,
|
|
3617
|
+
finalizeRecipe
|
|
3618
|
+
});
|
|
3619
|
+
};
|
|
3620
|
+
init().catch((error) => {
|
|
3621
|
+
subscriber.error(error);
|
|
3622
|
+
});
|
|
3623
|
+
return () => {
|
|
3624
|
+
isDestroyed = true;
|
|
3625
|
+
syncStartSubscription?.unsubscribe();
|
|
3626
|
+
persistSubscription?.unsubscribe();
|
|
3627
|
+
if (walletFacade) walletFacade.stop().catch(() => void 0).finally(() => {
|
|
3628
|
+
syncSecretKeys?.clear();
|
|
3629
|
+
syncDustSecretKey?.clear();
|
|
3630
|
+
});
|
|
3631
|
+
};
|
|
3632
|
+
});
|
|
3633
|
+
};
|
|
3634
|
+
/**
|
|
3635
|
+
* Starts a Midnight account wallet with full lifecycle management.
|
|
3636
|
+
*
|
|
3637
|
+
* Creates SDK wallets, manages their start/stop lifecycle, and converts
|
|
3638
|
+
* to the MidnightWallet interface used by the rest of the application.
|
|
3639
|
+
*/
|
|
3640
|
+
const createStartMidnightAccountWallet = (dependencies, options) => (props) => createAndManageWallets(props, dependencies, options).pipe(switchMap(({ walletFacade, haltPersistence, proofCircuitProvider, finalizeRecipe }) => createAccountObservableMidnightWallet({
|
|
3641
|
+
account: props.account,
|
|
3642
|
+
keyManager: props.keyManager,
|
|
3643
|
+
walletFacade,
|
|
3644
|
+
haltPersistence,
|
|
3645
|
+
proofCircuitProvider,
|
|
3646
|
+
finalizeRecipe
|
|
3647
|
+
})));
|
|
3648
|
+
/**
|
|
3649
|
+
* The engine's side-effect dependencies. The attested prover is the
|
|
3650
|
+
* loadout's: the app proves through the bundled Temenos deployment, which a
|
|
3651
|
+
* headless loadout does not ship.
|
|
3652
|
+
*/
|
|
3653
|
+
const createMidnightSideEffectDependencies = (options = {}) => ({ runtime }, dependencies) => {
|
|
3654
|
+
const midnightWallets$ = midnightWalletsForRuntime(runtime);
|
|
3655
|
+
return {
|
|
3656
|
+
midnightWallets$,
|
|
3657
|
+
wasmProofActivities$: EMPTY,
|
|
3658
|
+
dismissWasmProofActivity: () => void 0,
|
|
3659
|
+
teeAttestationProgress$,
|
|
3660
|
+
getMidnightWalletByAccountId: (accountId) => midnightWallets$.pipe(take(1), map((wallets) => wallets[accountId]), switchMap((wallet) => wallet ? of(wallet) : throwError(() => /* @__PURE__ */ new Error(`Could not load midnight wallet for account ${accountId}`)))),
|
|
3661
|
+
stopAllMidnightWallets: () => {
|
|
3662
|
+
const walletsArray = Object.values(midnightWallets$.value);
|
|
3663
|
+
midnightWallets$.next({});
|
|
3664
|
+
if (walletsArray.length === 0) return of(void 0);
|
|
3665
|
+
return forkJoin(walletsArray.map((wallet) => wallet.stop())).pipe(map(() => void 0));
|
|
3666
|
+
},
|
|
3667
|
+
stopMidnightWallet: (accountId) => {
|
|
3668
|
+
const wallet = midnightWallets$.value[accountId];
|
|
3669
|
+
if (!wallet) return of(void 0);
|
|
3670
|
+
const { [accountId]: _, ...remaining } = midnightWallets$.value;
|
|
3671
|
+
midnightWallets$.next(remaining);
|
|
3672
|
+
return wallet.stop().pipe(map(() => void 0));
|
|
3673
|
+
},
|
|
3674
|
+
startMidnightAccountWallet: createStartMidnightAccountWallet(dependencies, options)
|
|
3675
|
+
};
|
|
3676
|
+
};
|
|
3677
|
+
//#endregion
|
|
3678
|
+
//#region ../../packages/module/midnight-sync/src/store/utils/activities.ts
|
|
3679
|
+
const toBigInt = (v) => typeof v === "bigint" ? v : BigInt(v);
|
|
3680
|
+
const buildTokenBalanceChangesFromUtxos = (createdUtxos, spentUtxos, networkId) => {
|
|
3681
|
+
const changesByToken = /* @__PURE__ */ new Map();
|
|
3682
|
+
for (const u of createdUtxos) {
|
|
3683
|
+
const tokenId = TokenId(toUnshieldedTokenType(u.tokenType, networkId));
|
|
3684
|
+
const existing = changesByToken.get(tokenId);
|
|
3685
|
+
const value = toBigInt(u.value);
|
|
3686
|
+
changesByToken.set(tokenId, {
|
|
3687
|
+
tokenId,
|
|
3688
|
+
amount: existing ? existing.amount + value : value
|
|
3689
|
+
});
|
|
3690
|
+
}
|
|
3691
|
+
for (const u of spentUtxos) {
|
|
3692
|
+
const tokenId = TokenId(toUnshieldedTokenType(u.tokenType, networkId));
|
|
3693
|
+
const existing = changesByToken.get(tokenId);
|
|
3694
|
+
const value = toBigInt(u.value);
|
|
3695
|
+
changesByToken.set(tokenId, {
|
|
3696
|
+
tokenId,
|
|
3697
|
+
amount: existing ? existing.amount - value : -value
|
|
3698
|
+
});
|
|
3699
|
+
}
|
|
3700
|
+
return [...changesByToken.values()].filter(({ amount }) => amount !== 0n).map(({ tokenId, amount }) => ({
|
|
3701
|
+
tokenId,
|
|
3702
|
+
amount: BigNumber(amount)
|
|
3703
|
+
}));
|
|
3704
|
+
};
|
|
3705
|
+
const getAddressFromUtxos = (createdUtxos, spentUtxos) => {
|
|
3706
|
+
return (createdUtxos[0] ?? spentUtxos[0])?.owner ?? "";
|
|
3707
|
+
};
|
|
3708
|
+
/**
|
|
3709
|
+
* Whether the wallet took part in an unshielded movement in this transaction —
|
|
3710
|
+
* the gate for surfacing it as an activity. True for unshielded and mixed sends,
|
|
3711
|
+
* and for dust designation (which rotates night UTxOs into the unshielded
|
|
3712
|
+
* section). False for shielded-only entries: their values are encrypted and
|
|
3713
|
+
* unreadable, and the fee-dust they spend never lands in the unshielded section,
|
|
3714
|
+
* so surfacing them would only produce an empty/unknown row.
|
|
3715
|
+
*/
|
|
3716
|
+
const entryHasUnshieldedActivity = (entry) => (entry.unshielded?.createdUtxos.length ?? 0) > 0 || (entry.unshielded?.spentUtxos.length ?? 0) > 0;
|
|
3717
|
+
const mapStatusToActivityType = (status, tokenBalanceChanges) => {
|
|
3718
|
+
switch (status) {
|
|
3719
|
+
case "SUCCESS":
|
|
3720
|
+
case "PARTIAL_SUCCESS": return !tokenBalanceChanges?.length || tokenBalanceChanges.some(({ amount }) => BigInt(amount) > 0n) ? ActivityType.Receive : ActivityType.Send;
|
|
3721
|
+
case "FAILURE": return ActivityType.Failed;
|
|
3722
|
+
}
|
|
3723
|
+
};
|
|
3724
|
+
/**
|
|
3725
|
+
* Resolves the activity type and displayed token amounts for a transaction's
|
|
3726
|
+
* unshielded section. A transaction that moved unshielded value but nets to zero
|
|
3727
|
+
* is a self-transfer — a plain self-send, or a dust designation, which rotates
|
|
3728
|
+
* NIGHT back to the owner — so it is surfaced as {@link ActivityType.Self}.
|
|
3729
|
+
* No amount is shown: no value left the wallet, and the intended amount is not
|
|
3730
|
+
* recoverable (a self output is indistinguishable from change). Failures keep
|
|
3731
|
+
* their Failed type regardless.
|
|
3732
|
+
*/
|
|
3733
|
+
const deriveUnshieldedActivity = ({ status, createdUtxos, spentUtxos, networkId }) => {
|
|
3734
|
+
const netChanges = buildTokenBalanceChangesFromUtxos(createdUtxos, spentUtxos, networkId);
|
|
3735
|
+
if (status !== "FAILURE" && netChanges.length === 0 && (createdUtxos.length > 0 || spentUtxos.length > 0)) return {
|
|
3736
|
+
type: ActivityType.Self,
|
|
3737
|
+
tokenBalanceChanges: []
|
|
3738
|
+
};
|
|
3739
|
+
return {
|
|
3740
|
+
type: mapStatusToActivityType(status, netChanges),
|
|
3741
|
+
tokenBalanceChanges: netChanges
|
|
3742
|
+
};
|
|
3743
|
+
};
|
|
3744
|
+
const formatFee = (fees) => fees === null || fees === void 0 ? "0" : String(fees);
|
|
3745
|
+
//#endregion
|
|
3746
|
+
//#region ../../packages/module/midnight-sync/src/store/side-effects/activities.ts
|
|
3747
|
+
const mapTxHistoryEntryToActivity = ({ accountId, txHistoryEntry, networkId }) => {
|
|
3748
|
+
const { hash, timestamp, status } = txHistoryEntry;
|
|
3749
|
+
const { type, tokenBalanceChanges } = deriveUnshieldedActivity({
|
|
3750
|
+
status,
|
|
3751
|
+
createdUtxos: txHistoryEntry.unshielded?.createdUtxos ?? [],
|
|
3752
|
+
spentUtxos: txHistoryEntry.unshielded?.spentUtxos ?? [],
|
|
3753
|
+
networkId
|
|
3754
|
+
});
|
|
3755
|
+
return {
|
|
3756
|
+
accountId,
|
|
3757
|
+
activityId: hash,
|
|
3758
|
+
type,
|
|
3759
|
+
timestamp: Timestamp(timestamp?.getTime() ?? 0),
|
|
3760
|
+
tokenBalanceChanges
|
|
3761
|
+
};
|
|
3762
|
+
};
|
|
3763
|
+
const mapTxHistoryEntryToActivityDetail = ({ accountId, txHistoryEntry, networkId }) => {
|
|
3764
|
+
const createdUtxos = txHistoryEntry.unshielded?.createdUtxos ?? [];
|
|
3765
|
+
const spentUtxos = txHistoryEntry.unshielded?.spentUtxos ?? [];
|
|
3766
|
+
const activity = mapTxHistoryEntryToActivity({
|
|
3767
|
+
accountId,
|
|
3768
|
+
txHistoryEntry,
|
|
3769
|
+
networkId
|
|
3770
|
+
});
|
|
3771
|
+
const address = getAddressFromUtxos(createdUtxos, spentUtxos);
|
|
3772
|
+
return {
|
|
3773
|
+
...activity,
|
|
3774
|
+
address,
|
|
3775
|
+
fee: formatFee(txHistoryEntry.fees)
|
|
3776
|
+
};
|
|
3777
|
+
};
|
|
3778
|
+
/**
|
|
3779
|
+
* Whether confirmed rows with no unshielded section are shown. They carry no
|
|
3780
|
+
* readable value or date, so they render as amount-less "unknown" / 1970 rows;
|
|
3781
|
+
* hiding them is the default and the flag restores the earlier behaviour while
|
|
3782
|
+
* the product decision is open.
|
|
3783
|
+
*/
|
|
3784
|
+
const showShieldedOnlyRows$ = (stateObservables) => stateObservables.features.selectLoadedFeatures$.pipe(map((loaded) => loaded.featureFlags.some((flag) => flag.key === FEATURE_FLAG_MIDNIGHT_SHIELDED_ACTIVITY_ROWS)), distinctUntilChanged());
|
|
3785
|
+
const updateActivities = (_, stateObservables, { actions, midnightWallets$ }) => midnightWallets$.pipe(scan((accumulator, wallets) => ({
|
|
3786
|
+
current: wallets,
|
|
3787
|
+
added: Object.values(wallets).filter((w) => !(w.accountId in accumulator.current))
|
|
3788
|
+
}), {
|
|
3789
|
+
current: {},
|
|
3790
|
+
added: []
|
|
3791
|
+
}), mergeMap(({ added }) => added), mergeMap((wallet) => combineLatest([wallet.transactionHistory$, showShieldedOnlyRows$(stateObservables)]).pipe(map(([transactionHistory, showShieldedOnlyRows]) => ({
|
|
3792
|
+
activities: transactionHistory.filter((entry) => showShieldedOnlyRows || entryHasUnshieldedActivity(entry)).map((txHistoryEntry) => mapTxHistoryEntryToActivity({
|
|
3793
|
+
accountId: wallet.accountId,
|
|
3794
|
+
txHistoryEntry,
|
|
3795
|
+
networkId: wallet.networkId
|
|
3796
|
+
})),
|
|
3797
|
+
suppressedActivityIds: showShieldedOnlyRows ? [] : transactionHistory.filter((entry) => !entryHasUnshieldedActivity(entry)).map((entry) => entry.hash)
|
|
3798
|
+
})), mergeMap(({ activities, suppressedActivityIds }) => [
|
|
3799
|
+
actions.activities.upsertActivities({
|
|
3800
|
+
accountId: wallet.accountId,
|
|
3801
|
+
activities
|
|
3802
|
+
}),
|
|
3803
|
+
...suppressedActivityIds.length > 0 ? [actions.activities.removeActivities({
|
|
3804
|
+
accountId: wallet.accountId,
|
|
3805
|
+
activityIds: suppressedActivityIds
|
|
3806
|
+
})] : [],
|
|
3807
|
+
actions.activities.setHasLoadedOldestEntry({
|
|
3808
|
+
accountId: wallet.accountId,
|
|
3809
|
+
hasLoadedOldestEntry: true
|
|
3810
|
+
}),
|
|
3811
|
+
actions.activities.setDesiredLoadedActivitiesCount({
|
|
3812
|
+
accountId: wallet.accountId,
|
|
3813
|
+
desiredLoadedActivitiesCount: activities.length
|
|
3814
|
+
})
|
|
3815
|
+
]), takeUntil(midnightWallets$.pipe(filter((wallets) => !(wallet.accountId in wallets)))))));
|
|
3816
|
+
const loadActivityDetails = ({ activities: { loadActivityDetails$ } }, _, { actions, getMidnightWalletByAccountId, logger }) => loadActivityDetails$.pipe(filter(({ payload: { blockchainName } }) => blockchainName === "Midnight"), map((action) => action.payload.activity), switchMap(({ activityId, accountId }) => getMidnightWalletByAccountId(accountId).pipe(switchMap((wallet) => wallet.getTransactionHistoryEntryByHash(activityId).pipe(map((txHistoryEntry) => {
|
|
3817
|
+
if (!txHistoryEntry) return actions.activities.setActivityDetails({ activityDetails: void 0 });
|
|
3818
|
+
return actions.activities.setActivityDetails({ activityDetails: mapTxHistoryEntryToActivityDetail({
|
|
3819
|
+
accountId: wallet.accountId,
|
|
3820
|
+
txHistoryEntry,
|
|
3821
|
+
networkId: wallet.networkId
|
|
3822
|
+
}) });
|
|
3823
|
+
}), catchError((error) => {
|
|
3824
|
+
logger.error("Failed to load Midnight activity details", error);
|
|
3825
|
+
return EMPTY;
|
|
3826
|
+
}))), catchError(() => EMPTY))));
|
|
3827
|
+
//#endregion
|
|
3828
|
+
//#region ../../packages/module/midnight-sync/src/store/side-effects/proof-activities.ts
|
|
3829
|
+
const watchProofActivities = (_actions, _state, { actions, wasmProofActivities$ }) => wasmProofActivities$.pipe(map((activities) => actions.midnightContext.proofActivitiesUpdated(activities)));
|
|
3830
|
+
const dismissProofActivity = ({ midnightContext: { proofActivityDismissRequested$ } }, _state, { dismissWasmProofActivity }) => proofActivityDismissRequested$.pipe(tap(({ payload }) => {
|
|
3831
|
+
dismissWasmProofActivity(payload);
|
|
3832
|
+
}), ignoreElements());
|
|
3833
|
+
//#endregion
|
|
3834
|
+
//#region ../../packages/module/midnight-sync/src/store/side-effects/proof-server-kill-switch.ts
|
|
3835
|
+
/** Persist the fallback when a selected provider is disabled or no longer
|
|
3836
|
+
* belongs to the source-controlled catalogue. Notify once per affected batch. */
|
|
3837
|
+
const migrateUnavailableProofServerSelection = (_, { midnightContext: { selectUnavailableProofServerNetworks$, selectNetworksConfig$, selectNetworksConfigFeatureFlagsOverrides$ } }, { actions }) => selectUnavailableProofServerNetworks$.pipe(distinctUntilChanged(isEqual), filter((networkIds) => networkIds.length > 0), withLatestFrom(selectNetworksConfig$, selectNetworksConfigFeatureFlagsOverrides$), mergeMap(([networkIds, networksConfig, featureFlagsOverrides]) => from([...networkIds.map((networkId) => actions.midnightContext.setUserNetworkConfigOverride({
|
|
3838
|
+
networkId,
|
|
3839
|
+
config: networksConfig[networkId],
|
|
3840
|
+
featureFlagsOverrides: featureFlagsOverrides[networkId] ?? {}
|
|
3841
|
+
})), actions.ui.showToast({
|
|
3842
|
+
text: "midnight.proof-server.unavailable",
|
|
3843
|
+
color: "neutral",
|
|
3844
|
+
duration: 8,
|
|
3845
|
+
leftIcon: {
|
|
3846
|
+
name: "AlertTriangle",
|
|
3847
|
+
size: 20
|
|
3848
|
+
}
|
|
3849
|
+
})])));
|
|
3850
|
+
//#endregion
|
|
3851
|
+
//#region ../../packages/module/midnight-sync/src/store/side-effects/resync.ts
|
|
3852
|
+
const withMidnightAccounts = (makeSideEffect) => (actionObservables, stateObservables, dependencies) => makeSideEffect(midnightAccounts$(stateObservables))(actionObservables, stateObservables, dependencies);
|
|
3853
|
+
const requestResyncWallet = withMidnightAccounts((midnightAccount$) => ({ midnightSync: { requestResync$ } }, _, { actions }) => merge(requestResync$.pipe(withLatestFrom(midnightAccount$), switchMap(([_, accounts]) => {
|
|
3854
|
+
return from([...accounts.map(({ accountId }) => actions.sync.addSyncOperation({
|
|
3855
|
+
accountId,
|
|
3856
|
+
operation: {
|
|
3857
|
+
operationId: `${accountId}-midnight-sync`,
|
|
3858
|
+
status: "Pending",
|
|
3859
|
+
description: "sync.operation.midnight-resync",
|
|
3860
|
+
startedAt: Timestamp(Date.now())
|
|
3861
|
+
}
|
|
3862
|
+
})), actions.midnightSync.resync()]);
|
|
3863
|
+
}))));
|
|
3864
|
+
const createClearWalletStateOnResync = (store) => withMidnightAccounts((midnightAccounts$) => ({ midnightSync: { resync$ } }, _, { actions, stopAllMidnightWallets, logger }) => resync$.pipe(withLatestFrom(midnightAccounts$), switchMap(([_, midnightAccounts]) => stopAllMidnightWallets().pipe(catchError((error) => {
|
|
3865
|
+
logger.error("Midnight resync: stop failed", error);
|
|
3866
|
+
return of(void 0);
|
|
3867
|
+
}), switchMap(() => store.clear().pipe(defaultIfEmpty(void 0), catchError((error) => {
|
|
3868
|
+
logger.error("Midnight resync: state wipe failed", error);
|
|
3869
|
+
return of(void 0);
|
|
3870
|
+
}))), switchMap(() => [...midnightAccounts.flatMap(({ accountId }) => [
|
|
3871
|
+
actions.addresses.resetAddresses({ accountId }),
|
|
3872
|
+
actions.tokens.resetAccountTokens({ accountId }),
|
|
3873
|
+
actions.activities.resetActivities({ accountId }),
|
|
3874
|
+
actions.midnightContext.resetAccountDust({ accountId })
|
|
3875
|
+
]), actions.midnightSync.restartWalletWatch()])))));
|
|
3876
|
+
/**
|
|
3877
|
+
* Side-effect that triggers a Midnight wallet resync whenever the config change
|
|
3878
|
+
* is made with a feature flag override and the wallet is unlocked.
|
|
3879
|
+
*/
|
|
3880
|
+
const resyncWalletOnConfigChangeFromFeatureFlags = withMidnightAccounts((midnightAccounts$) => (_, { appLock: { isUnlocked$ }, midnightContext: { selectCurrentNetwork$, selectNetworksConfigFeatureFlagsOverrides$ } }, { actions }) => {
|
|
3881
|
+
return selectNetworksConfigFeatureFlagsOverrides$.pipe(withLatestFrom(isUnlocked$), filter(([_, isUnlocked]) => isUnlocked), switchMap(() => selectCurrentNetwork$.pipe(take(1))), map(({ config }) => config), distinctUntilChanged(deepEquals)).pipe(withLatestFrom(midnightAccounts$), switchMap(([_, midnightAccounts]) => from([...midnightAccounts.map(({ accountId }) => actions.sync.addSyncOperation({
|
|
3882
|
+
accountId,
|
|
3883
|
+
operation: {
|
|
3884
|
+
operationId: `${accountId}-midnight-sync`,
|
|
3885
|
+
status: "Pending",
|
|
3886
|
+
description: "sync.operation.midnight-resync",
|
|
3887
|
+
startedAt: Timestamp(Date.now())
|
|
3888
|
+
}
|
|
3889
|
+
})), actions.midnightSync.resync()])));
|
|
3890
|
+
});
|
|
3891
|
+
const createDeleteWalletSideEffect = (storage) => ({ wallets: { removeWallet$ } }, { wallets: { selectAll$ } }, { stopMidnightWallet, actions, logger }) => removeWallet$.pipe(withLatestFrom(selectAll$.pipe(map((wallets) => wallets.filter(hasMidnightAccount)))), switchMap(([{ payload }, midnightWallets]) => {
|
|
3892
|
+
const walletId = typeof payload === "string" ? payload : payload.walletId;
|
|
3893
|
+
const targetWallet = midnightWallets.find((w) => w.walletId === walletId);
|
|
3894
|
+
if (!targetWallet) return EMPTY;
|
|
3895
|
+
const allMidnightAccounts = targetWallet.accounts.filter(isInMemoryMidnightAccount);
|
|
3896
|
+
return (allMidnightAccounts.length > 0 ? forkJoin(allMidnightAccounts.map(({ accountId }) => stopMidnightWallet(accountId))) : of([])).pipe(switchMap(() => storage.removeWhere((wallet) => wallet.walletId === walletId).pipe(defaultIfEmpty(void 0), catchError((error) => {
|
|
3897
|
+
logger.error("Midnight delete wallet: state wipe failed", error);
|
|
3898
|
+
return of(void 0);
|
|
3899
|
+
}))), mergeMap(() => allMidnightAccounts.flatMap(({ accountId }) => [
|
|
3900
|
+
actions.addresses.resetAddresses({ accountId }),
|
|
3901
|
+
actions.tokens.resetAccountTokens({ accountId }),
|
|
3902
|
+
actions.activities.resetActivities({ accountId })
|
|
3903
|
+
])));
|
|
3904
|
+
}));
|
|
3905
|
+
/**
|
|
3906
|
+
* Stops one Midnight account's wallet, wipes that account's persisted SDK
|
|
3907
|
+
* state, then emits the actions that clear every redux cache the wiped state
|
|
3908
|
+
* fed. Scoped to a single account, unlike `createClearWalletStateOnResync`,
|
|
3909
|
+
* which wipes the whole chain.
|
|
3910
|
+
*
|
|
3911
|
+
* A step that errors or completes without emitting is handed to
|
|
3912
|
+
* `onStepFailure`: return an observable that emits to carry on with the next
|
|
3913
|
+
* step, or one that errors to abort the reset with that error.
|
|
3914
|
+
*/
|
|
3915
|
+
const stopAndWipeAccountState$ = ({ accountId, actions, store, stop$, onStepFailure }) => stop$.pipe(take(1), throwIfEmpty(() => /* @__PURE__ */ new Error("Midnight account stop did not acknowledge completion")), catchError((error) => onStepFailure("stop", error)), switchMap(() => store.removeWhere((wallet) => wallet?.accountId === accountId).pipe(throwIfEmpty(() => /* @__PURE__ */ new Error("Midnight account storage wipe did not acknowledge completion")), catchError((error) => onStepFailure("wipe", error)))), mergeMap(() => [
|
|
3916
|
+
actions.addresses.resetAddresses({ accountId }),
|
|
3917
|
+
actions.tokens.resetAccountTokens({ accountId }),
|
|
3918
|
+
actions.activities.resetActivities({ accountId }),
|
|
3919
|
+
actions.midnightContext.resetAccountDust({ accountId }),
|
|
3920
|
+
actions.sync.resetAccountSyncStatus({ accountId })
|
|
3921
|
+
]));
|
|
3922
|
+
/**
|
|
3923
|
+
* The extension's per-account "reset sync state": stops and wipes the account,
|
|
3924
|
+
* then reloads the app so every engine restarts from empty state. Stop and wipe
|
|
3925
|
+
* failures are logged and the reset carries on, because the reload is what
|
|
3926
|
+
* recovers the account.
|
|
3927
|
+
*
|
|
3928
|
+
* The reload is emitted LAST, after the storage write settles: sequencing it
|
|
3929
|
+
* inside this chain (rather than firing it from a separate UI tap) is what stops
|
|
3930
|
+
* a hard reload from preempting the wipe and leaving the old SDK document to
|
|
3931
|
+
* restore from.
|
|
3932
|
+
*/
|
|
3933
|
+
const createResetSyncStateSideEffect = (store) => withMidnightAccounts((midnightAccounts$) => ({ midnightContext: { resetSyncState$ } }, _, { actions, stopMidnightWallet, logger }) => resetSyncState$.pipe(withLatestFrom(midnightAccounts$), switchMap(([{ payload }, midnightAccounts]) => {
|
|
3934
|
+
const account = midnightAccounts.find(({ accountId }) => accountId === payload.accountId);
|
|
3935
|
+
if (!account) return EMPTY;
|
|
3936
|
+
const { accountId } = account;
|
|
3937
|
+
return concat(stopAndWipeAccountState$({
|
|
3938
|
+
accountId,
|
|
3939
|
+
actions,
|
|
3940
|
+
store,
|
|
3941
|
+
stop$: stopMidnightWallet(accountId),
|
|
3942
|
+
onStepFailure: (step, error) => {
|
|
3943
|
+
logger.error(`Midnight reset sync state: ${step} failed`, error);
|
|
3944
|
+
return of(void 0);
|
|
3945
|
+
}
|
|
3946
|
+
}), of(actions.app.reloadApplication()));
|
|
3947
|
+
})));
|
|
3948
|
+
/**
|
|
3949
|
+
* The headless per-account "reset sync state": stops and wipes the account,
|
|
3950
|
+
* then restarts that account's watcher in place, since a headless runtime has
|
|
3951
|
+
* no application to reload. The account's sync operation reads Pending while
|
|
3952
|
+
* the reset runs and Failed if a stop or wipe fails, so the caller can observe
|
|
3953
|
+
* the outcome and retry.
|
|
3954
|
+
*/
|
|
3955
|
+
const createHeadlessResetSyncStateSideEffect = (store) => withMidnightAccounts((midnightAccounts$) => ({ midnightContext: { resetSyncState$ } }, _, { actions, stopMidnightWallet, logger }) => resetSyncState$.pipe(withLatestFrom(midnightAccounts$), groupBy(([{ payload }]) => payload.accountId), mergeMap((requests$) => requests$.pipe(exhaustMap(([{ payload }, midnightAccounts]) => {
|
|
3956
|
+
const account = midnightAccounts.find(({ accountId }) => accountId === payload.accountId);
|
|
3957
|
+
if (!account) return EMPTY;
|
|
3958
|
+
const { accountId } = account;
|
|
3959
|
+
const pendingOperation = () => actions.sync.addSyncOperation({
|
|
3960
|
+
accountId,
|
|
3961
|
+
operation: {
|
|
3962
|
+
operationId: `${accountId}-midnight-sync`,
|
|
3963
|
+
status: "Pending",
|
|
3964
|
+
description: "sync.operation.midnight-resync",
|
|
3965
|
+
startedAt: Timestamp(Date.now())
|
|
3966
|
+
}
|
|
3967
|
+
});
|
|
3968
|
+
const stop$ = merge(of(void 0), requests$).pipe(switchMap(() => defer(() => stopMidnightWallet(accountId)).pipe(throwIfEmpty(() => /* @__PURE__ */ new Error("Midnight account stop did not acknowledge completion")))));
|
|
3969
|
+
return concat(of(pendingOperation()), stopAndWipeAccountState$({
|
|
3970
|
+
accountId,
|
|
3971
|
+
actions,
|
|
3972
|
+
store,
|
|
3973
|
+
stop$,
|
|
3974
|
+
onStepFailure: (step, error) => {
|
|
3975
|
+
logger.error(`Midnight reset sync state: ${step} failed`, error);
|
|
3976
|
+
return throwError(() => error);
|
|
3977
|
+
}
|
|
3978
|
+
}), defer(() => of(pendingOperation(), actions.midnightSync.restartAccountWatch({ accountId })))).pipe(catchError((error) => {
|
|
3979
|
+
logger.error("Midnight account resync failed", error);
|
|
3980
|
+
const failedAt = Timestamp(Date.now());
|
|
3981
|
+
return of(actions.sync.addSyncOperation({
|
|
3982
|
+
accountId,
|
|
3983
|
+
operation: {
|
|
3984
|
+
operationId: `${accountId}-midnight-sync`,
|
|
3985
|
+
status: "Failed",
|
|
3986
|
+
description: "sync.operation.midnight-resync",
|
|
3987
|
+
error: "sync.error.midnight-sync-failed",
|
|
3988
|
+
startedAt: failedAt,
|
|
3989
|
+
failedAt
|
|
3990
|
+
}
|
|
3991
|
+
}));
|
|
3992
|
+
}));
|
|
3993
|
+
})))));
|
|
3994
|
+
//#endregion
|
|
3995
|
+
//#region ../../packages/module/midnight-sync/src/store/side-effects/sync-failure.ts
|
|
3996
|
+
/**
|
|
3997
|
+
* Dismiss a Midnight account's sync failure once its own sync recovers.
|
|
3998
|
+
*
|
|
3999
|
+
* The `completeSyncOperation` for `${accountId}-midnight-sync` is the
|
|
4000
|
+
* "recovered" signal, whichever route got there — transparent retry, the
|
|
4001
|
+
* failure's tap-to-retry `restartWalletWatch`, or the resubscription `whileActive`
|
|
4002
|
+
* performs on unlock.
|
|
4003
|
+
*
|
|
4004
|
+
* Keyed per-account, so no lookup is needed: a completion for a sibling Midnight
|
|
4005
|
+
* account (or a Cardano/Bitcoin one) maps to a different, non-existent
|
|
4006
|
+
* MidnightSyncFailureId and no-ops, leaving a still-broken account's failure in
|
|
4007
|
+
* place until its OWN sync completes.
|
|
4008
|
+
*/
|
|
4009
|
+
const autoDismissMidnightSyncFailureOnSyncSuccess = ({ sync: { completeSyncOperation$ } }, { failures: { selectFailureById$ } }) => completeSyncOperation$.pipe(map(({ payload }) => MidnightSyncFailureId(payload.accountId)), autoDismissFailureOnSuccess(selectFailureById$));
|
|
4010
|
+
/**
|
|
4011
|
+
* On resume, clear the sync failure for every Midnight account.
|
|
4012
|
+
*
|
|
4013
|
+
* Complements the per-account recovery dismissal above by clearing a stale error
|
|
4014
|
+
* immediately, rather than leaving it on screen for the length of the first sync
|
|
4015
|
+
* after unlock. No restart is dispatched: `watchMidnightAccounts` ends its pipe
|
|
4016
|
+
* with `whileActive`, so resuming already resubscribes every account watcher.
|
|
4017
|
+
* Accounts with no failure are a no-op.
|
|
4018
|
+
*/
|
|
4019
|
+
const autoDismissMidnightSyncFailureOnResume = (_, { wallets: { selectAll$ }, failures: { selectFailureById$ } }, { walletResumed$ }) => walletResumed$.pipe(withLatestFrom(selectAll$), mergeMap(([, wallets]) => from(wallets.flatMap((wallet) => wallet.accounts).filter(isInMemoryMidnightAccount).map((account) => MidnightSyncFailureId(account.accountId)))), autoDismissFailureOnSuccess(selectFailureById$));
|
|
4020
|
+
//#endregion
|
|
4021
|
+
//#region ../../packages/module/midnight-sync/src/store/side-effects/tee-attestation-progress.ts
|
|
4022
|
+
/**
|
|
4023
|
+
* Forwards attested-proving progress from the dependency-level stream into
|
|
4024
|
+
* redux, where the send-flow checklist UI reads it. Pure mapping — the
|
|
4025
|
+
* events originate inside the proving service (ADR 19).
|
|
4026
|
+
*/
|
|
4027
|
+
const watchTeeAttestationProgress = (_actionObservables, _stateObservables, { actions, teeAttestationProgress$ }) => teeAttestationProgress$.pipe(map((event) => event.type === "begin" ? actions.midnightContext.teeAttestationProgressStarted(event) : actions.midnightContext.teeAttestationProgressUpdated(event)));
|
|
4028
|
+
/**
|
|
4029
|
+
* Clears the previous run's checklist as soon as a new Midnight transaction
|
|
4030
|
+
* starts building, so a redone send never opens the
|
|
4031
|
+
* processing screen with stale step results. The attested proving service's
|
|
4032
|
+
* `reset` then rebuilds the pending checklist when verification actually
|
|
4033
|
+
* begins. The signer owns confirmation resets. Submit must not clear the
|
|
4034
|
+
* completed checklist while the transaction is being submitted.
|
|
4035
|
+
*/
|
|
4036
|
+
const clearTeeAttestationProgressOnNewTx = ({ txExecutor: { txPhaseRequested$ } }, _stateObservables, { actions }) => txPhaseRequested$.pipe(filter(({ payload: { config } }) => config.params.blockchainName === "Midnight" && config.type === "buildTx"), map(() => actions.midnightContext.teeAttestationProgressCleared()));
|
|
4037
|
+
//#endregion
|
|
4038
|
+
//#region ../../packages/module/midnight-sync/src/store/side-effects/index.ts
|
|
4039
|
+
/**
|
|
4040
|
+
* The engine's side effects plus the ones a loadout adds over the same
|
|
4041
|
+
* persisted wallet-state storage. The engine set reads only the contracts
|
|
4042
|
+
* the engine itself depends on; a loadout decides what else it can run.
|
|
4043
|
+
*/
|
|
4044
|
+
const createInitializeSideEffects = (loadoutSideEffects) => () => [(actionObservables, stateObservables, dependencies) => {
|
|
4045
|
+
const midnightStateStorage = dependencies.createCollectionStorage({
|
|
4046
|
+
collectionId: "midnightWalletState",
|
|
4047
|
+
computeDocId: (wallet) => String(wallet.accountId)
|
|
4048
|
+
});
|
|
4049
|
+
return merge(...[
|
|
4050
|
+
updateActivities,
|
|
4051
|
+
loadActivityDetails,
|
|
4052
|
+
createDeleteWalletSideEffect(midnightStateStorage),
|
|
4053
|
+
createClearWalletStateOnResync(midnightStateStorage),
|
|
4054
|
+
requestResyncWallet,
|
|
4055
|
+
autoDismissMidnightSyncFailureOnResume,
|
|
4056
|
+
autoDismissMidnightSyncFailureOnSyncSuccess,
|
|
4057
|
+
watchMidnightAccounts(midnightStateStorage, watchMidnightAccount),
|
|
4058
|
+
...loadoutSideEffects(midnightStateStorage)
|
|
4059
|
+
].map((sideEffect) => sideEffect(actionObservables, stateObservables, dependencies)));
|
|
4060
|
+
}];
|
|
4061
|
+
createInitializeSideEffects((storage) => [
|
|
4062
|
+
createResetSyncStateSideEffect(storage),
|
|
4063
|
+
resyncWalletOnConfigChangeFromFeatureFlags,
|
|
4064
|
+
migrateUnavailableProofServerSelection,
|
|
4065
|
+
watchProofActivities,
|
|
4066
|
+
dismissProofActivity,
|
|
4067
|
+
watchTeeAttestationProgress,
|
|
4068
|
+
clearTeeAttestationProgressOnNewTx
|
|
4069
|
+
]);
|
|
4070
|
+
//#endregion
|
|
4071
|
+
//#region ../../packages/module/midnight-sync/src/store/side-effects/network-config.ts
|
|
4072
|
+
/**
|
|
4073
|
+
* Applies a loadout's supported networks and default proof servers right
|
|
4074
|
+
* after the first action the store handles, which redux-persist dispatches
|
|
4075
|
+
* while the store is created. Both therefore hold before the store is handed
|
|
4076
|
+
* out and before any side effect starts: a side effect would land a tick
|
|
4077
|
+
* later, and a network selected in between would be checked against the
|
|
4078
|
+
* contract's full list.
|
|
4079
|
+
*/
|
|
4080
|
+
const createApplyNetworkDefaultsMiddleware = ({ supportedNetworkIds, defaultProofServers }) => {
|
|
4081
|
+
const { setDefaultProofServers, setSupportedNetworksIds } = midnightContextActions.midnightContext;
|
|
4082
|
+
return (store) => (next) => {
|
|
4083
|
+
let pending = [...supportedNetworkIds ? [setSupportedNetworksIds(supportedNetworkIds)] : [], ...defaultProofServers ? [setDefaultProofServers(defaultProofServers)] : []];
|
|
4084
|
+
return (action) => {
|
|
4085
|
+
const result = next(action);
|
|
4086
|
+
const defaults = pending;
|
|
4087
|
+
pending = [];
|
|
4088
|
+
for (const defaultAction of defaults) store.dispatch(defaultAction);
|
|
4089
|
+
return result;
|
|
4090
|
+
};
|
|
4091
|
+
};
|
|
4092
|
+
};
|
|
4093
|
+
/**
|
|
4094
|
+
* Applies a loadout's endpoint choices as user overrides on startup, so they
|
|
4095
|
+
* take precedence over the contract defaults and the feature-flag values
|
|
4096
|
+
* without a settings UI to enter them through.
|
|
4097
|
+
*/
|
|
4098
|
+
const createApplyNetworkConfigOverrides = (overrides) => (_, { midnightContext: { selectNetworksConfig$, selectNetworksConfigFeatureFlagsOverrides$ } }, { actions }) => zip(selectNetworksConfig$.pipe(take(1)), selectNetworksConfigFeatureFlagsOverrides$.pipe(take(1))).pipe(mergeMap(([networksConfig, featureFlagsOverrides]) => Object.entries(overrides).map(([networkId, override]) => actions.midnightContext.setUserNetworkConfigOverride({
|
|
4099
|
+
networkId,
|
|
4100
|
+
config: {
|
|
4101
|
+
...networksConfig[networkId],
|
|
4102
|
+
...override
|
|
4103
|
+
},
|
|
4104
|
+
featureFlagsOverrides: featureFlagsOverrides[networkId]
|
|
4105
|
+
}))));
|
|
4106
|
+
//#endregion
|
|
4107
|
+
//#region ../../packages/module/midnight-sync/src/store/sdk-init.ts
|
|
4108
|
+
const assertDefaultTestnetConfigured = (config) => {
|
|
4109
|
+
const networkId = config?.defaultMidnightTestnetNetworkId;
|
|
4110
|
+
if (!networkId || !MidnightSDKTestNetworkId.includes(networkId)) throw new Error(`createLaceWallet needs config.defaultMidnightTestnetNetworkId, the Midnight testnet a wallet starts on: one of ${MidnightSDKTestNetworkId.join(", ")}; got ${String(networkId)}`);
|
|
4111
|
+
};
|
|
4112
|
+
const createSdkStoreInit = ({ auth, batchUpdates, createAttestedProver, networks = {}, supportedNetworkIds, defaultProofServers }) => {
|
|
4113
|
+
const initializeSideEffects = createInitializeSideEffects((storage) => [
|
|
4114
|
+
registerMidnightBlockchainNetworks,
|
|
4115
|
+
createApplyNetworkConfigOverrides(networks),
|
|
4116
|
+
createHeadlessResetSyncStateSideEffect(storage)
|
|
4117
|
+
]);
|
|
4118
|
+
const initializeDependencies = createMidnightSideEffectDependencies({
|
|
4119
|
+
batchUpdates,
|
|
4120
|
+
createAttestedProver
|
|
4121
|
+
});
|
|
4122
|
+
return (props, dependencies) => {
|
|
4123
|
+
assertDefaultTestnetConfigured(props.runtime.config);
|
|
4124
|
+
return {
|
|
4125
|
+
middleware: [createApplyNetworkDefaultsMiddleware({
|
|
4126
|
+
supportedNetworkIds,
|
|
4127
|
+
defaultProofServers
|
|
4128
|
+
})],
|
|
4129
|
+
sideEffects: initializeSideEffects(props, dependencies),
|
|
4130
|
+
sideEffectDependencies: {
|
|
4131
|
+
...initializeDependencies(props, dependencies),
|
|
4132
|
+
...auth
|
|
4133
|
+
}
|
|
4134
|
+
};
|
|
4135
|
+
};
|
|
4136
|
+
};
|
|
4137
|
+
//#endregion
|
|
4138
|
+
export { createSdkStoreInit };
|