@agimon-ai/po-cloudflare 0.0.2-alpha.7 → 0.0.2-alpha.71
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/README.md +64 -241
- package/container/Dockerfile +27 -0
- package/dist/{BrowserWebSocketTransport-C2SC2VeJ.js → BrowserWebSocketTransport-B4heNdrp.js} +1 -1
- package/dist/{NodeWebSocketTransport-CKilJesa.js → NodeWebSocketTransport-BCiOXUEz.js} +2 -2
- package/dist/{abort-signals-Bkmp_euQ.js → abort-signals-C8CttjsR.js} +1 -1
- package/dist/agent-CEqvgRl6.js +3878 -0
- package/dist/{anthropic-messages-CkYm8M3V.js → anthropic-messages-DCLLLNuM.js} +292 -64
- package/dist/apiContracts-DaOpUHnu.js +1719 -0
- package/dist/{approval-CQ3ZuoTy.js → approval-DXPV7Vm5.js} +15 -2
- package/dist/{approvalPrompt-CylV3C84.js → approvalPrompt-CBaxjb_g.js} +1 -2
- package/dist/approvalSession-C9bg7tPo.js +132 -0
- package/dist/artifactFiles-5KwXIxYf.js +1 -0
- package/dist/artifactsApi-bg2wMYWg.js +200 -0
- package/dist/assets/assets/{CodeEditorView-D4q94XH-.js → CodeEditorView-CfrVwzvL.js} +2 -2
- package/dist/assets/assets/{abnfDiagram-WEYOIA3C-C85p4OYZ.js → abnfDiagram-WEYOIA3C-B80H4Cm4.js} +2 -2
- package/dist/assets/assets/{architecture-WOLXFQ4H-Bt_NOdwE.js → architecture-WOLXFQ4H-Dr4hXaql.js} +1 -1
- package/dist/assets/assets/{architectureDiagram-ZHVYKT53-DzH1GKMm.js → architectureDiagram-ZHVYKT53-DWyt7oXu.js} +2 -2
- package/dist/assets/assets/{blockDiagram-RJAE7QA3-BmWU34j3.js → blockDiagram-RJAE7QA3-OxNTLdmi.js} +2 -2
- package/dist/assets/assets/{c4Diagram-XDPPPE54-BpGOdOuo.js → c4Diagram-XDPPPE54-B4YtcH0s.js} +2 -2
- package/dist/assets/assets/channel-bXj00dGj.js +2 -0
- package/dist/assets/assets/{chunk-2E7WHVMD-AycP1cXU.js → chunk-2E7WHVMD-CD6FFMOX.js} +2 -2
- package/dist/assets/assets/{chunk-4EMNKR2T-DX-DrZzc.js → chunk-4EMNKR2T-CEIoX5oo.js} +2 -2
- package/dist/assets/assets/{chunk-55XCU76K-BdwnLWzI.js → chunk-55XCU76K-CD3t0IJi.js} +2 -2
- package/dist/assets/assets/{chunk-7S6XSTFO-D-RBAwAn.js → chunk-7S6XSTFO-Cyt75UCF.js} +2 -2
- package/dist/assets/assets/{chunk-AQDTSKZB-CCxNNhKs.js → chunk-AQDTSKZB-DRtqYBj9.js} +2 -2
- package/dist/assets/assets/{chunk-DSNLSHJZ-D2hGwWm1.js → chunk-DSNLSHJZ-C8Fx2F8s.js} +2 -2
- package/dist/assets/assets/{chunk-HAGFOTED-BPi-cqGh.js → chunk-HAGFOTED-wOLWRRnd.js} +2 -2
- package/dist/assets/assets/{chunk-HNE4Q36P-D-r1ChHT.js → chunk-HNE4Q36P-CurJg4Hf.js} +2 -2
- package/dist/assets/assets/{chunk-NQOKRVIF-RgmZCAdn.js → chunk-NQOKRVIF-Dzcc5nOG.js} +2 -2
- package/dist/assets/assets/{chunk-UHW7PFBP-B-Hul-rZ.js → chunk-UHW7PFBP-B_ULFf2h.js} +2 -2
- package/dist/assets/assets/{chunk-VQ5W62QI-D1zlXCt8.js → chunk-VQ5W62QI-DH0VY4_p.js} +2 -2
- package/dist/assets/assets/{chunk-WQQL4CDK-CtjIbVJn.js → chunk-WQQL4CDK-DNxfLyXM.js} +2 -2
- package/dist/assets/assets/chunk-XXDRQBXY-B2bMWgN9.js +2 -0
- package/dist/assets/assets/{chunk-YZO67HFG-BQOgXG99.js → chunk-YZO67HFG-COuMUh9U.js} +2 -2
- package/dist/assets/assets/{chunk-ZAUX2LTX-CsDDxmqv.js → chunk-ZAUX2LTX-BJrCnubF.js} +2 -2
- package/dist/assets/assets/{chunk-ZCHMQSOR-deyEYMjx.js → chunk-ZCHMQSOR-D1lFKPtk.js} +2 -2
- package/dist/assets/assets/{classDiagram-v2-4MYWR3UA-DVJHeFlq.js → classDiagram-v2-4MYWR3UA-DfZIbyVL.js} +2 -2
- package/dist/assets/assets/{cose-bilkent-JH36ORCC-ipcN28Fw.js → cose-bilkent-JH36ORCC-CpGhv9_S.js} +2 -2
- package/dist/assets/assets/{cynefin-EF2NZ3EQ-s9ZkPF55.js → cynefin-EF2NZ3EQ-Cxdc6nQl.js} +1 -1
- package/dist/assets/assets/{cynefinDiagram-WF24UDRP-Ksr2qjsS.js → cynefinDiagram-WF24UDRP-qoj0w3lp.js} +2 -2
- package/dist/assets/assets/{dagre-NK4GIZVX-2_Wl-XEW.js → dagre-NK4GIZVX-DL6QbNDS.js} +2 -2
- package/dist/assets/assets/{diagram-CBK3MWTC-C7PeyT7l.js → diagram-CBK3MWTC-CJB3jq1_.js} +2 -2
- package/dist/assets/assets/{diagram-I5XIIV2D-DPYzeKdj.js → diagram-I5XIIV2D-4cPOxCxF.js} +2 -2
- package/dist/assets/assets/{diagram-ODIL2UCW-DHw1cAmn.js → diagram-ODIL2UCW-BG3-jAxE.js} +2 -2
- package/dist/assets/assets/{diagram-PFBEJUXE-C2wA8i-1.js → diagram-PFBEJUXE-Bx8dFaXj.js} +2 -2
- package/dist/assets/assets/{diagram-RJA3I4VV-tM3moCIs.js → diagram-RJA3I4VV-CUUHND91.js} +2 -2
- package/dist/assets/assets/{diagram-TYUNFSNR-CInyJxF7.js → diagram-TYUNFSNR-BDMoN-kr.js} +2 -2
- package/dist/assets/assets/{dist-BDqjNLTC.js → dist-5AxNm-uy.js} +2 -2
- package/dist/assets/assets/{dist-hpZIQBl4.js → dist-9_Rmyj2I.js} +2 -2
- package/dist/assets/assets/{dist-DSLprmec.js → dist-BE3CLKv4.js} +2 -2
- package/dist/assets/assets/{dist-BASEd5LC.js → dist-BfNCu-7x.js} +2 -2
- package/dist/assets/assets/{dist-BuYBvf4F.js → dist-BjI0b36Z.js} +2 -2
- package/dist/assets/assets/{dist-DUS0U_ge.js → dist-CM7b5P9a.js} +2 -2
- package/dist/assets/assets/{dist-CeOy6PjJ.js → dist-Ccxb9U1G.js} +2 -2
- package/dist/assets/assets/{dist-ChXoRSS6.js → dist-CjCWP21A.js} +2 -2
- package/dist/assets/assets/{dist-07dRlnp1.js → dist-DSTAktnR.js} +2 -2
- package/dist/assets/assets/{ebnfDiagram-V4P3TTPT-4nZgqaSt.js → ebnfDiagram-V4P3TTPT-BivOMXZb.js} +2 -2
- package/dist/assets/assets/{elk-QONTBCTQ-nFh54c1Q.js → elk-QONTBCTQ-CrJ1Qpy_.js} +2 -2
- package/dist/assets/assets/{erDiagram-KYQIGQAA-CIQ0_IgZ.js → erDiagram-KYQIGQAA-w9Bqp4sV.js} +2 -2
- package/dist/assets/assets/{eventmodeling-K75KTNOO-Cw4BlbYP.js → eventmodeling-K75KTNOO-CBjFM3kV.js} +1 -1
- package/dist/assets/assets/flowDiagram-IUGLLWBU-C6Fnfgm0.js +1 -0
- package/dist/assets/assets/{ganttDiagram-R7GPNTJY-C97qoUpX.js → ganttDiagram-R7GPNTJY-CsWtGaqD.js} +2 -2
- package/dist/assets/assets/{gitGraph-VSP46ZUC-B8HWVkEX.js → gitGraph-VSP46ZUC-DsBSV9_h.js} +1 -1
- package/dist/assets/assets/{gitGraphDiagram-PDYL7XHY-B4Js56_8.js → gitGraphDiagram-PDYL7XHY-D5GxuYHW.js} +2 -2
- package/dist/assets/assets/index-CNDyKUDF.css +1 -0
- package/dist/assets/assets/index-DWDYnZsq.js +256 -0
- package/dist/assets/assets/{info-OHQRW6UA-A4qythhA.js → info-OHQRW6UA-C7x5dSJu.js} +1 -1
- package/dist/assets/assets/{infoDiagram-MVDRKAX5-BSNwG9yI.js → infoDiagram-MVDRKAX5-CwpI-uAa.js} +2 -2
- package/dist/assets/assets/{ishikawaDiagram-HPEHV2GE-D4gU-3RA.js → ishikawaDiagram-HPEHV2GE-DAa7J5G6.js} +2 -2
- package/dist/assets/assets/{journeyDiagram-BOSHW7O7-CxxDrw7o.js → journeyDiagram-BOSHW7O7-BmiZnxE_.js} +2 -2
- package/dist/assets/assets/{kanban-definition-FNSA4HC5-DUxQv3v0.js → kanban-definition-FNSA4HC5-DUR_mA3L.js} +2 -2
- package/dist/assets/assets/{line-BKODXUmk.js → line-DHY49wSg.js} +2 -2
- package/dist/assets/assets/{linear-Cm5uyUun.js → linear-pTo-a9xT.js} +2 -2
- package/dist/assets/assets/{mermaid-parser.core-CYst2kCg.js → mermaid-parser.core-DMg3hN3T.js} +4 -4
- package/dist/assets/assets/{mermaid.core-B4Qq8SMa.js → mermaid.core-DKtPCltA.js} +5 -5
- package/dist/assets/assets/{mindmap-definition-6OY57UG3-CZFvUTIM.js → mindmap-definition-6OY57UG3-DwTkFbnV.js} +2 -2
- package/dist/assets/assets/{packet-JDAUHWVQ-DZMlaiuy.js → packet-JDAUHWVQ-Tu9TrQ1x.js} +1 -1
- package/dist/assets/assets/{pegDiagram-ECIUJNBX-BjM668dT.js → pegDiagram-ECIUJNBX-B7My4tsz.js} +2 -2
- package/dist/assets/assets/{pie-XZMESJXO-CmpJ6vb8.js → pie-XZMESJXO-QPQm5Gdx.js} +1 -1
- package/dist/assets/assets/{pieDiagram-GNMPY74T-BCA9DCDe.js → pieDiagram-GNMPY74T-Bv-zAD_z.js} +2 -2
- package/dist/assets/assets/{quadrantDiagram-D57K4MC3-CUnpC-Rl.js → quadrantDiagram-D57K4MC3-HTjoGQPd.js} +2 -2
- package/dist/assets/assets/{radar-ABXABTNO-C9x42-KP.js → radar-ABXABTNO-LDBlEoFo.js} +1 -1
- package/dist/assets/assets/{railroad-I3PHUGI6-CLvHKrsC.js → railroad-I3PHUGI6-Dy3_ymgZ.js} +1 -1
- package/dist/assets/assets/{railroad-abnf-LNEFI6M7-B0LGF3gx.js → railroad-abnf-LNEFI6M7-QLVvYs6e.js} +1 -1
- package/dist/assets/assets/{railroad-ebnf-DWYD2UWJ-SKnYapAj.js → railroad-ebnf-DWYD2UWJ-CFRlv9a8.js} +1 -1
- package/dist/assets/assets/{railroad-peg-JR7BVNR7-wsUpPloN.js → railroad-peg-JR7BVNR7-BOlq3d9c.js} +1 -1
- package/dist/assets/assets/{railroadDiagram-Y72NRBL7-BYJtosKO.js → railroadDiagram-Y72NRBL7-Chg32HoU.js} +2 -2
- package/dist/assets/assets/{requirementDiagram-EQYSW5RA-YYdoWMnl.js → requirementDiagram-EQYSW5RA-VenIs_eg.js} +2 -2
- package/dist/assets/assets/{sankeyDiagram-SY24JHO5-DtZyCTdM.js → sankeyDiagram-SY24JHO5-BdByqMKF.js} +2 -2
- package/dist/assets/assets/{sequenceDiagram-BLEHNHQU-BPE8f413.js → sequenceDiagram-BLEHNHQU-D3Do4GJE.js} +2 -2
- package/dist/assets/assets/{src-BNTOLq2G.js → src-DmfN-DA-.js} +2 -2
- package/dist/assets/assets/{stateDiagram-v2-A6IESKWZ-9f8Ow4Fl.js → stateDiagram-v2-A6IESKWZ-CZkRbPlf.js} +2 -2
- package/dist/assets/assets/{swimlanes-B3ENRKFQ-DdAEbxGp.js → swimlanes-B3ENRKFQ-DRTdF9AF.js} +2 -2
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-BYr_4JUb.js +9 -0
- package/dist/assets/assets/{timeline-definition-JXYKGLGB-DJNGd2mU.js → timeline-definition-JXYKGLGB-BVcuws_M.js} +2 -2
- package/dist/assets/assets/{treeView-D4JQ5SDB-BHONoCCw.js → treeView-D4JQ5SDB-BLtOJGqO.js} +1 -1
- package/dist/assets/assets/{treemap-SAJKECNS-pOaYkxq7.js → treemap-SAJKECNS-Dn3BWJ4v.js} +1 -1
- package/dist/assets/assets/{usecaseDiagram-WPOLBNNX-C3eDYL9v.js → usecaseDiagram-WPOLBNNX-CBExIKDY.js} +2 -2
- package/dist/assets/assets/{vennDiagram-Q3Y3IDCW-CJi1xfsR.js → vennDiagram-Q3Y3IDCW-C6FIx2L4.js} +2 -2
- package/dist/assets/assets/{wardley-7MLQ67FV-CEy4w7Ir.js → wardley-7MLQ67FV-Cjj2xSBp.js} +1 -1
- package/dist/assets/assets/{wardleyDiagram-IVAIDKWA-DfdLMMpN.js → wardleyDiagram-IVAIDKWA-sQPCBCFK.js} +2 -2
- package/dist/assets/assets/{webpack-v8XGbQTa.js → webpack-DDCA0aDL.js} +2 -2
- package/dist/assets/assets/{xychartDiagram-4URNHDU4-Aw-Ix4uC.js → xychartDiagram-4URNHDU4-bZ4rifSw.js} +2 -2
- package/dist/assets/bundle-asset-policy.json +1 -1
- package/dist/assets/index.html +8 -2
- package/dist/assets/mascot/cta-provider.png +0 -0
- package/dist/assets/mascot/cta-sign-in.png +0 -0
- package/dist/assets/plugins/assets/base-GzIOAd-t.css +2 -0
- package/dist/assets/plugins/assets/browserCaptureWorklet-Droj0fW0-Droj0fW0.js +13 -0
- package/dist/assets/plugins/assets/day-bottom-left-5um-x02r-5um-x02r.webp +0 -0
- package/dist/assets/plugins/assets/day-grain-CvEuNhlI-CvEuNhlI.webp +0 -0
- package/dist/assets/plugins/assets/day-right-C9W-XtjV-C9W-XtjV.webp +0 -0
- package/dist/assets/plugins/assets/day-top-left-B544Eq9J-B544Eq9J.webp +0 -0
- package/dist/assets/plugins/assets/night-bottom-left-N03ST5Uz-N03ST5Uz.webp +0 -0
- package/dist/assets/plugins/assets/night-grain-BY9q-tNN-BY9q-tNN.webp +0 -0
- package/dist/assets/plugins/assets/night-right-C6Denrqj-C6Denrqj.webp +0 -0
- package/dist/assets/plugins/assets/night-top-left-KOou6UxY-KOou6UxY.webp +0 -0
- package/dist/assets/plugins/assets/sileroVadWorker-D894njUe-DjN_BMWf.mjs +110 -0
- package/dist/assets/plugins/assets/silero_vad_v6.2.1-SjbCxFXk-SjbCxFXk.onnx +0 -0
- package/dist/assets/plugins/chunks/po-web-runtime-D8FIos2q.js +1 -0
- package/dist/assets/plugins/chunks/schemas-DVQ8BvvP.js +55 -0
- package/dist/assets/plugins/compositions.json +1 -1
- package/dist/assets/plugins/slots/approval.09e72f36-DxS_uibk.js +2 -0
- package/dist/assets/plugins/slots/artifacts.50b639bb-Cp37TAkd.js +1 -0
- package/dist/assets/plugins/slots/author.ea449ace-Ds9Y-tjN.js +93 -0
- package/dist/assets/plugins/slots/autocompact.6f428144-CDZpN7I7.js +1 -0
- package/dist/assets/plugins/slots/backdrop-bamboo.6e4c928d-qbifuMc6.js +1 -0
- package/dist/assets/plugins/slots/browse.fa1f1a50-CVYvo1M5.js +1 -0
- package/dist/assets/plugins/slots/builtin-tools.75108f21-Cq1ljoL-.js +7 -0
- package/dist/assets/plugins/slots/calendar.d8b70190-BBjpOs1v.js +2 -0
- package/dist/assets/plugins/slots/codemode.c58fb583-DOR6OR7R.js +11 -0
- package/dist/assets/plugins/slots/domain.753f9f92-CJrXxig9.js +1 -0
- package/dist/assets/plugins/slots/edit.804fec90-BFF7_xN9.js +7 -0
- package/dist/assets/plugins/slots/files.66ffc636-CzOlZrRm.js +2 -0
- package/dist/assets/plugins/slots/goal.45dffa01-BtQBp3sw.js +1 -0
- package/dist/assets/plugins/slots/grep.98262cff-9bUDfjyT.js +1 -0
- package/dist/assets/plugins/slots/help.5fbd20f7-B4-y6gYK.js +3 -0
- package/dist/assets/plugins/slots/log.cb964209-BRPa3cVs.js +4 -0
- package/dist/assets/plugins/slots/mcp.82cc1ff5-CFtzPkPC.js +55 -0
- package/dist/assets/plugins/slots/plan.3852ba52-CH59Ff49.js +3 -0
- package/dist/assets/plugins/slots/profile.ab16dcec-0e9fWWyE.js +1 -0
- package/dist/assets/plugins/slots/prompts.ae48c07a-BTqYnBX5.js +38 -0
- package/dist/assets/plugins/slots/read.4560591a-C7fMXDEH.js +1 -0
- package/dist/assets/plugins/slots/runner.6e494d59-CqrpqhW9.js +9 -0
- package/dist/assets/plugins/slots/scaffold.d87a6ee0-9qY5gkYW.js +1 -0
- package/dist/assets/plugins/slots/session-mcp.2be84084-Cf0cqopp.js +2 -0
- package/dist/assets/plugins/slots/sessions.6f47cb4c-B1_eqPJQ.js +1 -0
- package/dist/assets/plugins/slots/skill.62a0a1b3-D-SKX8iw.js +4 -0
- package/dist/assets/plugins/slots/space.65a27e5a-fbLHc-DX.js +1 -0
- package/dist/assets/plugins/slots/subagents.8bb9992c-Cm_YMEnn.js +7 -0
- package/dist/assets/plugins/slots/template-advanced.59f3f98a-L0WOM4JT.js +1 -0
- package/dist/assets/plugins/slots/template-desktop.0f0b8491-By9BZlaL.js +7 -0
- package/dist/assets/plugins/slots/template-elegant.0e3b0acf-El05x7HK.js +1 -0
- package/dist/assets/plugins/slots/vault.3cbfcdc3-DpU_65Wy.js +1 -0
- package/dist/assets/plugins/slots/voice.a952113d-CvcuL__m.js +1 -0
- package/dist/assets/plugins/slots/web-search.65013836-NVh9fdvE.js +1 -0
- package/dist/assets/plugins/slots/workflows.cbc5c5c0-OLKSY9PE.js +16 -0
- package/dist/assets/pwa/pwa.js +12 -12
- package/dist/assets/pwa/sw.js +58 -4
- package/dist/{atomicJson-wczZBXQP.js → atomicJson-XYtxz032.js} +2 -3
- package/dist/{azure-openai-config-DHMgdIa-.js → azure-openai-config-S-quxzTC.js} +2 -2
- package/dist/{azure-openai-responses-CTgRdQ4m.js → azure-openai-responses-DdpV5zh7.js} +13 -13
- package/dist/backgroundWork-Bv0ib_lY.js +49 -0
- package/dist/{layeredConfig-xmTHGrw8.js → browser-DwY5dXHX.js} +21 -983
- package/dist/{browser-EJ5_ffnN.js → browser-IsHIcvFg.js} +1 -1
- package/dist/browser-ks_k-6KA.js +36 -0
- package/dist/calendarSetup-CI3AACVo.js +3892 -0
- package/dist/childProcess-Cv8rJuUf.js +32 -0
- package/dist/childSession-BrDCrNtL.js +25 -0
- package/dist/{classifier-shared-jXm-plIK.js → classifier-shared-DFprgrML.js} +5 -5
- package/dist/{cloudflare-workers-ai-system-one-B0wH6HU5.js → cloudflare-workers-ai-system-one-B0MD19yZ.js} +3 -3
- package/dist/{codemode-CFVDmyGm.js → codemode-LpcMFMYM.js} +1 -1
- package/dist/coerce-DM9YrILC.js +13 -0
- package/dist/config-DeWkdjj7.js +1372 -0
- package/dist/contextContributions-C1bsEJef.js +13 -0
- package/dist/contracts-CW8o6Xyi.js +19 -0
- package/dist/contracts-WRa9e98H.js +40 -0
- package/dist/cordisHost-_-jtkneB.js +25 -0
- package/dist/delegation-B2rBgv8A.js +100 -0
- package/dist/{diagnostics-DPTP-yrt.js → diagnostics-BY5LXbHJ.js} +2 -2
- package/dist/{dist-BVBi6VMV.js → dist-B2ArMqge.js} +1 -1
- package/dist/{server-Cg07O2W6.js → dist-C6IqjC-m.js} +1 -546
- package/dist/{dist-PDDFdqDX.js → dist-CDz5dYMj.js} +1 -1
- package/dist/{dist-Dvx5mlIR.js → dist-kgi2Ix1y.js} +16 -3
- package/dist/{emscripten-module.cloudflare-D4Bc9Ykz.js → emscripten-module.cloudflare-B4fhfquU.js} +1 -1
- package/dist/{env-api-keys-CAnjjnsR.js → env-api-keys-BgCPpU9t.js} +1 -1
- package/dist/{error-body-DQZRsyL5.js → error-body-CeumezyR.js} +26 -4
- package/dist/esm-BKJy3O9-.js +1553 -0
- package/dist/{remoteMcp-DqE2xFWS.js → exports-BEEgtkya.js} +1588 -714
- package/dist/{exports-LjvSY7Y6.js → exports-CBp_9dVk.js} +47 -28
- package/dist/exports-CRjRvvX0.js +34 -0
- package/dist/exports-Cg0wxflf.js +1 -0
- package/dist/exports-Ct56PRB9.js +46 -0
- package/dist/extensionFile-B940JOEn.js +121 -0
- package/dist/{factory-Cs8iaUtc.js → factory-BU0cZY0I.js} +1 -1
- package/dist/{github-copilot-headers-DpQQAh-s.js → github-copilot-headers-Cq9pnpl2.js} +1 -1
- package/dist/{google-generative-ai-BTTOo5RQ.js → google-generative-ai-DmbUlCGv.js} +9 -9
- package/dist/{google-shared-S7bqOccz.js → google-shared-Diz2uk39.js} +6 -6
- package/dist/{google-vertex-BcMU_DMb.js → google-vertex-CGCpI9Po.js} +10 -10
- package/dist/{domains-B6Ae4swm.js → harnessState-Df--jB5z.js} +162 -42
- package/dist/{harnessStore-Ccbia9_u.js → harnessStore-DInwiLYb.js} +4 -5
- package/dist/{hash-B3RRpLS2.js → hash-IQBoLxOB.js} +1 -1
- package/dist/{headers-BEuxFxDI.js → headers-Dkgiqogr.js} +1 -1
- package/dist/help-C9UGKetC.js +100 -0
- package/dist/home-kwZFHqOx.js +60 -0
- package/dist/http-BekstF5S.js +64 -0
- package/dist/hubChannel-Dldv3EEb.js +32 -0
- package/dist/hubRevisions-BPoC6quI.js +364 -0
- package/dist/{identity-BIeAyilV.js → identity-BzB1N-Sn.js} +3 -3
- package/dist/index.edge-BiVQ9LoZ.js +198 -0
- package/dist/index.edge-CSGx6QOL.js +56 -0
- package/dist/index.edge-ClLTmPFz.js +191 -0
- package/dist/index.edge-CzoLWbyl.js +238 -0
- package/dist/index.edge-D1biKw71.js +946 -0
- package/dist/index.edge-D2RirEwK.js +14 -0
- package/dist/iso-BGFmgtky.js +27 -0
- package/dist/{kysely-adapter-D51abb3q.js → kysely-adapter-D8KUrWxm.js} +1 -1
- package/dist/liquid.browser-1BcykmIN.js +4596 -0
- package/dist/manualTranscription-DN56fzgj.js +96 -0
- package/dist/{mcpProjection-BXiECnW0.js → mcpProjection-D2U50Pel.js} +1 -2
- package/dist/meta-CVgfTHQP.js +1030 -0
- package/dist/migrations-DJBPDwSR.js +32 -0
- package/dist/{mistral-conversations-DN8VSERk.js → mistral-conversations-Bv_m1MRF.js} +12 -12
- package/dist/modeDefinition-Di95_IiU.js +44 -0
- package/dist/{models-D6d73jcW.js → models-D50yN8Ag.js} +41 -46
- package/dist/{node-UuMT2C3q.js → node-B4kSjHeD.js} +2 -2
- package/dist/{node-DytJOfYf.js → node-CBLSc-YH.js} +1 -1
- package/dist/notification-DjxbNoMR.js +143 -0
- package/dist/{openai-bt3ZRBZv.js → openai-D6Q-l6hT.js} +187 -187
- package/dist/{openai-codex-responses-cL36x0ml.js → openai-codex-responses-BnoiTqYV.js} +21 -25
- package/dist/{openai-completions-BWsTNYyT.js → openai-completions-C68qs5rI.js} +26 -19
- package/dist/{openai-decisions-Dfn_KgQd.js → openai-decisions-BSxU_aoV.js} +3 -3
- package/dist/{openai-responses-aa0LoyCJ.js → openai-responses-D6hXen-k.js} +17 -15
- package/dist/{openai-responses-shared-H-jH5SlM.js → openai-responses-shared-BD8K7FAC.js} +7 -7
- package/dist/{openrouter-cost-D99Qqcs6.js → openrouter-cost-BPam8wyW.js} +1 -1
- package/dist/{openrouter-images-BpwVpALC.js → openrouter-images-DylXiHy7.js} +7 -7
- package/dist/{hubChannel-Dn5NMpvu.js → packageApi-DYkaxP59.js} +33 -42
- package/dist/photon_rs_bg.wasm +0 -0
- package/dist/{pi-messages-BHAIkYBj.js → pi-messages-DaIlYYlO.js} +6 -6
- package/dist/piConfig-5tRPD0ov.js +126 -0
- package/dist/piSettings-ekBG5OeF.js +1 -0
- package/dist/platform-CQahdzpG.js +138 -0
- package/dist/pluginCatalog-BAALyedS.js +30 -0
- package/dist/pluginContributions-Be9EnCAW.js +16 -0
- package/dist/pluginProtocol-7_gVUeM9.js +1 -0
- package/dist/pluginProtocol-DVIfJnav.js +135 -0
- package/dist/portableConfig-0tnk9anb.js +49 -0
- package/dist/presetConfig-n-oiNd3h.js +541 -0
- package/dist/profileSources-D1rymC97.js +537 -0
- package/dist/{protocol-DUeE0Q8z.js → protocol-Cri0GpZR.js} +1 -2
- package/dist/{provider-env-DgfpjgTa.js → provider-env-DJb40UF7.js} +2 -2
- package/dist/{provider-retry-ChD-K2Gv.js → provider-retry-jpvs7ixx.js} +1 -1
- package/dist/{puppeteer-cloudflare-B-GHrPGO.js → puppeteer-cloudflare-D4l8smMS.js} +3 -3
- package/dist/{server-BWJmxCrm.js → readiness-Ydw5zrKy.js} +4 -169
- package/dist/{rolldown-runtime-B-lAHAz2.js → rolldown-runtime-DbVrKiKs.js} +1 -1
- package/dist/{sanitize-unicode-Dl4ROF7y.js → sanitize-unicode-B1ZFaEtf.js} +1 -1
- package/dist/scaffoldRegistry-CeFe3Pf0.js +1240 -0
- package/dist/{schemas-Vj8-rCR4.js → schemas-D2dRon18.js} +1901 -53
- package/dist/server-AKM07WcM.js +466 -0
- package/dist/server-B0tM5Ygf.js +1300 -0
- package/dist/server-B8-vStCx.js +1116 -0
- package/dist/server-BAbdiL38.js +15108 -0
- package/dist/server-BCZ_R3kX.js +3326 -0
- package/dist/server-BGKAeB3M.js +492 -0
- package/dist/server-BIQhg1jS.js +26985 -0
- package/dist/server-BcPD_6a2.js +1533 -0
- package/dist/server-BeoA0QB-.js +580 -0
- package/dist/server-BsgvOpBF.js +24 -0
- package/dist/server-BtnOqSB5.js +156 -0
- package/dist/server-C-HBjWRo.js +2800 -0
- package/dist/{server-CWg0m_wq.js → server-C0Lt6nTt.js} +269 -1062
- package/dist/server-C8NPfG1H.js +148 -0
- package/dist/server-CKkaxOc0.js +978 -0
- package/dist/server-CMaWF5UA.js +1379 -0
- package/dist/server-CQPI6jIa.js +295 -0
- package/dist/{server-BhYE7Vqk.js → server-CQmb0lYL.js} +114 -176
- package/dist/server-CWR34Vx6.js +1884 -0
- package/dist/server-CZiAy2v5.js +641 -0
- package/dist/server-Cjtr0oVJ.js +584 -0
- package/dist/server-CkJQJ3Oo.js +571 -0
- package/dist/server-ClQQGtsI.js +679 -0
- package/dist/server-Cy2FhGBm.js +1744 -0
- package/dist/server-D8yEblCB.js +24 -0
- package/dist/server-DF0YIUeI.js +9603 -0
- package/dist/server-DRFESCq1.js +1527 -0
- package/dist/{server-zkcrP99W.js → server-Df1defzp.js} +89 -87
- package/dist/server-DgZd_TuT.js +189 -0
- package/dist/server-Dkc9Kth2.js +1830 -0
- package/dist/server-DlRePYOB.js +343 -0
- package/dist/{server-BpPEzRes.js → server-_HZm8wEC.js} +654 -745
- package/dist/{server-yABhJa2K.js → server-_jWkMESg.js} +60 -39
- package/dist/server-lgV6liTt.js +140 -0
- package/dist/server-nHPXbRDA.js +742 -0
- package/dist/server-p7qANgrf.js +877 -0
- package/dist/server-vhmQi3co.js +112 -0
- package/dist/{server-SA0dsIJ2.js → server-w1aKMZOs.js} +3 -10
- package/dist/serverPlugin-4nI5J6Zt.js +39622 -0
- package/dist/session-resources-BvR3cwiH.js +10 -0
- package/dist/{sessionConfig-DgnPcGBu.js → sessionConfig-UMlgu98q.js} +926 -844
- package/dist/{simple-options-DWrW31_K.js → simple-options-Cp5p46f9.js} +13 -6
- package/dist/space-C3Wnli1l.js +92 -0
- package/dist/sse-XlzXs1es.js +151 -0
- package/dist/{streaming-json-t4rzNHEp.js → streaming-json-CZyrX_Ux.js} +6 -6
- package/dist/{system-one-shared-DLVLdzYL.js → system-one-shared-Du6bka0h.js} +3 -3
- package/dist/{notification-valMY1zH.js → telemetry-CrTcxeA5.js} +2 -93
- package/dist/{transform-messages-CjTSwW9q.js → transform-messages-CBj9g2mx.js} +3 -16
- package/dist/truncate-M3KbFyVj.js +89 -0
- package/dist/{server-BXjfQYeU.js → type-DppaYz6F.js} +955 -1187
- package/dist/type-yokaDI_F.js +7 -0
- package/dist/{typesafe-system-one-DBVcjcUQ.js → typesafe-system-one-C7YFgvrX.js} +3 -3
- package/dist/{uuid-mkNGilLv.js → uuid-BVI0BZsx.js} +1 -1
- package/dist/{validation-BLnxgJU_.js → validation-QWuk6kwJ.js} +79 -74
- package/dist/vaultSettings-Bq8wkbDv.js +292 -0
- package/dist/voiceTools-BdJyfzwB.js +246 -0
- package/dist/web-B2sdV-F2.js +4 -0
- package/dist/worker.js +97821 -72579
- package/dist/workflow-DTCt4n6k.js +171 -0
- package/dist/workflowServices-RlswfHWp.js +300 -0
- package/package.json +55 -25
- package/wrangler.jsonc +16 -3
- package/dist/apiContracts-sG5b90Qa.js +0 -4451
- package/dist/assets/assets/channel-BOT7In0s.js +0 -2
- package/dist/assets/assets/chunk-XXDRQBXY-Dp9-QbR6.js +0 -2
- package/dist/assets/assets/flowDiagram-IUGLLWBU-B9D9uWwn.js +0 -1
- package/dist/assets/assets/index-BlPEYpuN.css +0 -1
- package/dist/assets/assets/index-DS9w_Q1B.js +0 -155
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-CyUKtW7v.js +0 -9
- package/dist/assets/plugins/assets/base-DyDpY0zD.css +0 -2
- package/dist/assets/plugins/chunks/po-web-runtime-4JiBsb_c.js +0 -1
- package/dist/assets/plugins/slots/approval.09e72f36-DwFz-UMh.js +0 -2
- package/dist/assets/plugins/slots/artifacts.50b639bb-CUtFC806.js +0 -1
- package/dist/assets/plugins/slots/builtin-tools.75108f21-B69GLfY_.js +0 -7
- package/dist/assets/plugins/slots/codemode.c58fb583-C0Gmb7_s.js +0 -9
- package/dist/assets/plugins/slots/domain.753f9f92-BTBYRLkE.js +0 -1
- package/dist/assets/plugins/slots/mcp.82cc1ff5-Ecacjn0a.js +0 -109
- package/dist/assets/plugins/slots/profile.ab16dcec-DIVXNHmh.js +0 -1
- package/dist/assets/plugins/slots/skill.62a0a1b3-BNr7DmPH.js +0 -4
- package/dist/backgroundWork-CSpsJ-Rg.js +0 -25
- package/dist/contextProjection-DDIQRgN4.js +0 -188
- package/dist/extensionFile-CacKVegY.js +0 -409
- package/dist/harnessState-gmzJcPGt.js +0 -88
- package/dist/harnessStore-Ch6hdYYe.js +0 -1
- package/dist/index.edge-BgSx_gRO.js +0 -45
- package/dist/majorModes-CCnwAjfF.js +0 -333
- package/dist/majorModes-DNQbxkpt.js +0 -1
- package/dist/piSettings-B6fsgIBA.js +0 -1
- package/dist/platform-Bs2_X_dK.js +0 -16
- package/dist/platformFiles-CCGujP9o.js +0 -39
- package/dist/server-5hLs7M43.js +0 -656
- package/dist/server-B3iqBHOP.js +0 -118
- package/dist/server-Dv0EKLwc.js +0 -108
- package/dist/server-Y5A21sJf.js +0 -591
- package/dist/server-a1K226XK.js +0 -279
- package/dist/serverPlugin-DUc4gGep.js +0 -7279
- package/dist/value-Bd477RDX.js +0 -2247
|
@@ -0,0 +1,3892 @@
|
|
|
1
|
+
import { $t as Boolean$1, Gt as Record, Jt as String$1, Qt as Integer, Ut as Partial, V as Check, Wt as Omit, Xt as Null, Yt as Number$1, Zt as Literal, an as _Array_, in as Optional, nn as Unknown, qt as Union, rn as _Object_, sn as defineServiceContract } from "./serverPlugin-4nI5J6Zt.js";
|
|
2
|
+
import { u as poApiCallerFrom } from "./packageApi-DYkaxP59.js";
|
|
3
|
+
import { c as PoWorkflowDefinitionRefSchema, d as PoWorkflowRunRefSchema } from "./workflow-DTCt4n6k.js";
|
|
4
|
+
import "./profileSources-D1rymC97.js";
|
|
5
|
+
//#region ../../../layers/automation/po-calendar/src/constants/calendar.ts
|
|
6
|
+
/** Pending start deadline, not a running-job timeout. */
|
|
7
|
+
const DEFAULT_CALENDAR_PENDING_EXPIRY_MS = 36e5;
|
|
8
|
+
const MAX_INTERVAL_SECONDS = 3600;
|
|
9
|
+
const MAX_CALENDAR_PROMPT_LENGTH = 32768;
|
|
10
|
+
/** Longest action summary Calendar keeps on an occurrence. */
|
|
11
|
+
const MAX_CALENDAR_SUMMARY_LENGTH = 2048;
|
|
12
|
+
/** Wall-clock time an agent may give for a one-off event, read in the schedule's zone: `2026-05-01T09:00`. */
|
|
13
|
+
const CALENDAR_LOCAL_TIME_PATTERN = "^(\\d{4}-\\d{2}-\\d{2})T(\\d{2}:\\d{2})(?::(\\d{2}))?$";
|
|
14
|
+
/**
|
|
15
|
+
* Calendar's tables, created idempotently on every database it runs on: the shared Po
|
|
16
|
+
* database on Node and the workspace Durable Object on the edge. `calendar_import` holds
|
|
17
|
+
* one row once an old `calendar.sqlite` has been copied in.
|
|
18
|
+
*/
|
|
19
|
+
const CALENDAR_SCHEMA_SQL = `
|
|
20
|
+
CREATE TABLE IF NOT EXISTS calendar_queue_sequence (id INTEGER PRIMARY KEY, value INTEGER NOT NULL);
|
|
21
|
+
INSERT OR IGNORE INTO calendar_queue_sequence VALUES (1, 0);
|
|
22
|
+
CREATE TABLE IF NOT EXISTS calendar_queue_reservations (occurrence_id TEXT PRIMARY KEY, data TEXT NOT NULL);
|
|
23
|
+
CREATE TABLE IF NOT EXISTS calendar_queue_requests (id TEXT PRIMARY KEY, data TEXT NOT NULL);
|
|
24
|
+
CREATE TABLE IF NOT EXISTS calendar_outbox (occurrence_id TEXT PRIMARY KEY, data TEXT NOT NULL);
|
|
25
|
+
CREATE TABLE IF NOT EXISTS calendar_events (id TEXT PRIMARY KEY, data TEXT NOT NULL);
|
|
26
|
+
CREATE TABLE IF NOT EXISTS calendar_occurrences (
|
|
27
|
+
id TEXT PRIMARY KEY, event_id TEXT NOT NULL, revision INTEGER NOT NULL,
|
|
28
|
+
due_at INTEGER NOT NULL, data TEXT NOT NULL,
|
|
29
|
+
UNIQUE(event_id, revision, due_at)
|
|
30
|
+
);
|
|
31
|
+
CREATE INDEX IF NOT EXISTS calendar_occurrences_event ON calendar_occurrences(event_id, due_at);
|
|
32
|
+
CREATE TABLE IF NOT EXISTS calendar_import (id INTEGER PRIMARY KEY CHECK (id = 1), done_at INTEGER NOT NULL) STRICT;
|
|
33
|
+
`;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../../../layers/automation/po-calendar/src/schemas/calendar.ts
|
|
36
|
+
const id = String$1({
|
|
37
|
+
minLength: 1,
|
|
38
|
+
maxLength: 256
|
|
39
|
+
});
|
|
40
|
+
const name = String$1({
|
|
41
|
+
minLength: 1,
|
|
42
|
+
maxLength: 128
|
|
43
|
+
});
|
|
44
|
+
const CalendarOwnerSchema = Union([
|
|
45
|
+
_Object_({
|
|
46
|
+
level: Literal("global"),
|
|
47
|
+
principal: Optional(_Object_({
|
|
48
|
+
issuer: id,
|
|
49
|
+
subject: id
|
|
50
|
+
}, { additionalProperties: false }))
|
|
51
|
+
}, { additionalProperties: false }),
|
|
52
|
+
_Object_({
|
|
53
|
+
level: Literal("workspace"),
|
|
54
|
+
workspaceId: id,
|
|
55
|
+
hostId: Optional(id)
|
|
56
|
+
}, { additionalProperties: false }),
|
|
57
|
+
_Object_({
|
|
58
|
+
level: Literal("session"),
|
|
59
|
+
workspaceId: id,
|
|
60
|
+
sessionId: id,
|
|
61
|
+
hostId: Optional(id)
|
|
62
|
+
}, { additionalProperties: false })
|
|
63
|
+
]);
|
|
64
|
+
const epochMs = Integer({
|
|
65
|
+
minimum: 0,
|
|
66
|
+
maximum: 864e13
|
|
67
|
+
});
|
|
68
|
+
const cronExpr = String$1({
|
|
69
|
+
minLength: 1,
|
|
70
|
+
maxLength: 256
|
|
71
|
+
});
|
|
72
|
+
const IntervalScheduleSchema = _Object_({
|
|
73
|
+
kind: Literal("interval"),
|
|
74
|
+
seconds: Integer({
|
|
75
|
+
minimum: 30,
|
|
76
|
+
maximum: MAX_INTERVAL_SECONDS
|
|
77
|
+
})
|
|
78
|
+
}, { additionalProperties: false });
|
|
79
|
+
/** The stored form: an instant and the zone it was meant in. */
|
|
80
|
+
const CalendarScheduleSchema = Union([
|
|
81
|
+
_Object_({
|
|
82
|
+
kind: Literal("once"),
|
|
83
|
+
at: epochMs,
|
|
84
|
+
tz: id
|
|
85
|
+
}, { additionalProperties: false }),
|
|
86
|
+
IntervalScheduleSchema,
|
|
87
|
+
_Object_({
|
|
88
|
+
kind: Literal("cron"),
|
|
89
|
+
expr: cronExpr,
|
|
90
|
+
tz: id
|
|
91
|
+
}, { additionalProperties: false })
|
|
92
|
+
]);
|
|
93
|
+
/**
|
|
94
|
+
* What an agent may write. `tz` defaults to the person's zone, and `once.at` may be wall-clock time in that zone,
|
|
95
|
+
* which Calendar turns into the stored instant.
|
|
96
|
+
*/
|
|
97
|
+
const CalendarScheduleInputSchema = Union([
|
|
98
|
+
_Object_({
|
|
99
|
+
kind: Literal("once"),
|
|
100
|
+
at: Union([epochMs, String$1({ pattern: CALENDAR_LOCAL_TIME_PATTERN })]),
|
|
101
|
+
tz: Optional(id)
|
|
102
|
+
}, { additionalProperties: false }),
|
|
103
|
+
IntervalScheduleSchema,
|
|
104
|
+
_Object_({
|
|
105
|
+
kind: Literal("cron"),
|
|
106
|
+
expr: cronExpr,
|
|
107
|
+
tz: Optional(id)
|
|
108
|
+
}, { additionalProperties: false })
|
|
109
|
+
]);
|
|
110
|
+
const CalendarTargetSchema = Union([_Object_({
|
|
111
|
+
kind: Literal("newSession"),
|
|
112
|
+
workspaceId: id,
|
|
113
|
+
cwd: String$1({ minLength: 1 }),
|
|
114
|
+
hostId: Optional(id)
|
|
115
|
+
}, { additionalProperties: false }), _Object_({
|
|
116
|
+
kind: Literal("existingSession"),
|
|
117
|
+
sessionId: id,
|
|
118
|
+
hostId: Optional(id)
|
|
119
|
+
}, { additionalProperties: false })]);
|
|
120
|
+
const CalendarAssignmentSchema = _Object_({
|
|
121
|
+
profile: Optional(name),
|
|
122
|
+
domains: Optional(_Array_(name, { maxItems: 32 })),
|
|
123
|
+
preset: Optional(name),
|
|
124
|
+
modes: Optional(_Array_(name, { maxItems: 32 }))
|
|
125
|
+
}, { additionalProperties: false });
|
|
126
|
+
const CalendarWorkflowSchema = _Object_({
|
|
127
|
+
key: String$1({
|
|
128
|
+
minLength: 1,
|
|
129
|
+
maxLength: 512
|
|
130
|
+
}),
|
|
131
|
+
inputs: Optional(Record(String$1({
|
|
132
|
+
minLength: 1,
|
|
133
|
+
maxLength: 128
|
|
134
|
+
}), String$1({ maxLength: 8192 }), { maxProperties: 64 })),
|
|
135
|
+
prompt: Optional(String$1({
|
|
136
|
+
minLength: 1,
|
|
137
|
+
maxLength: MAX_CALENDAR_PROMPT_LENGTH
|
|
138
|
+
}))
|
|
139
|
+
}, { additionalProperties: false });
|
|
140
|
+
const CalendarActionSchema = _Object_({
|
|
141
|
+
launcherId: id,
|
|
142
|
+
input: Record(String$1({ maxLength: 256 }), Unknown())
|
|
143
|
+
}, { additionalProperties: false });
|
|
144
|
+
const CalendarEventSourceSchema = _Object_({
|
|
145
|
+
packageName: String$1({
|
|
146
|
+
minLength: 1,
|
|
147
|
+
maxLength: 214
|
|
148
|
+
}),
|
|
149
|
+
externalId: id
|
|
150
|
+
}, { additionalProperties: false });
|
|
151
|
+
const CalendarJobLaneSchema = _Object_({
|
|
152
|
+
securityScope: id,
|
|
153
|
+
setupDigest: id,
|
|
154
|
+
targetHostId: Optional(id)
|
|
155
|
+
}, { additionalProperties: false });
|
|
156
|
+
const CalendarCentralJobSchema = _Object_({
|
|
157
|
+
origin: _Object_({
|
|
158
|
+
hostId: id,
|
|
159
|
+
owner: CalendarOwnerSchema,
|
|
160
|
+
workspaceId: Optional(id),
|
|
161
|
+
principal: Optional(_Object_({
|
|
162
|
+
issuer: id,
|
|
163
|
+
subject: id
|
|
164
|
+
}, { additionalProperties: false }))
|
|
165
|
+
}, { additionalProperties: false }),
|
|
166
|
+
lane: CalendarJobLaneSchema,
|
|
167
|
+
portable: Optional(Boolean$1()),
|
|
168
|
+
pendingExpiryMs: Optional(Integer({
|
|
169
|
+
minimum: 1,
|
|
170
|
+
maximum: 864e13
|
|
171
|
+
})),
|
|
172
|
+
visibility: Optional(Union([Literal("private"), Literal("shared")]))
|
|
173
|
+
}, { additionalProperties: false });
|
|
174
|
+
const prompt = String$1({
|
|
175
|
+
minLength: 1,
|
|
176
|
+
maxLength: MAX_CALENDAR_PROMPT_LENGTH
|
|
177
|
+
});
|
|
178
|
+
const editable = {
|
|
179
|
+
centralJob: Optional(CalendarCentralJobSchema),
|
|
180
|
+
title: String$1({
|
|
181
|
+
minLength: 1,
|
|
182
|
+
maxLength: 256
|
|
183
|
+
}),
|
|
184
|
+
prompt: Optional(prompt),
|
|
185
|
+
workflow: Optional(CalendarWorkflowSchema),
|
|
186
|
+
action: Optional(CalendarActionSchema),
|
|
187
|
+
assignment: Optional(CalendarAssignmentSchema),
|
|
188
|
+
schedule: CalendarScheduleSchema,
|
|
189
|
+
target: CalendarTargetSchema
|
|
190
|
+
};
|
|
191
|
+
const CalendarEventInputSchema = _Object_({
|
|
192
|
+
...editable,
|
|
193
|
+
owner: CalendarOwnerSchema
|
|
194
|
+
}, { additionalProperties: false });
|
|
195
|
+
const nullable = (schema) => Optional(Union([schema, Null()]));
|
|
196
|
+
const CalendarEventPatchSchema = _Object_({
|
|
197
|
+
title: Optional(editable.title),
|
|
198
|
+
prompt: nullable(prompt),
|
|
199
|
+
workflow: nullable(CalendarWorkflowSchema),
|
|
200
|
+
action: nullable(CalendarActionSchema),
|
|
201
|
+
assignment: nullable(CalendarAssignmentSchema),
|
|
202
|
+
centralJob: nullable(CalendarCentralJobSchema),
|
|
203
|
+
schedule: Optional(CalendarScheduleSchema),
|
|
204
|
+
target: Optional(CalendarTargetSchema),
|
|
205
|
+
status: Optional(Union([
|
|
206
|
+
"active",
|
|
207
|
+
"paused",
|
|
208
|
+
"cancelled",
|
|
209
|
+
"done"
|
|
210
|
+
].map((value) => Literal(value)))),
|
|
211
|
+
pauseReason: Optional(String$1({ maxLength: 512 }))
|
|
212
|
+
}, { additionalProperties: false });
|
|
213
|
+
const CalendarEventSchema = _Object_({
|
|
214
|
+
...editable,
|
|
215
|
+
owner: CalendarOwnerSchema,
|
|
216
|
+
homeHostId: id,
|
|
217
|
+
id,
|
|
218
|
+
revision: Integer({ minimum: 1 }),
|
|
219
|
+
status: Union([
|
|
220
|
+
"active",
|
|
221
|
+
"paused",
|
|
222
|
+
"cancelled",
|
|
223
|
+
"done"
|
|
224
|
+
].map((value) => Literal(value))),
|
|
225
|
+
pauseReason: Optional(String$1()),
|
|
226
|
+
source: Optional(CalendarEventSourceSchema),
|
|
227
|
+
nextDueAt: Union([Number$1(), Null()]),
|
|
228
|
+
createdAt: Number$1(),
|
|
229
|
+
updatedAt: Number$1()
|
|
230
|
+
}, { additionalProperties: false });
|
|
231
|
+
const CalendarOccurrenceJobSchema = _Object_({
|
|
232
|
+
sequence: Integer({
|
|
233
|
+
minimum: 1,
|
|
234
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
235
|
+
}),
|
|
236
|
+
enqueuedAt: epochMs,
|
|
237
|
+
expiresAt: epochMs,
|
|
238
|
+
idempotencyKey: id,
|
|
239
|
+
lane: CalendarJobLaneSchema,
|
|
240
|
+
snapshot: _Object_({
|
|
241
|
+
event: CalendarEventInputSchema,
|
|
242
|
+
digest: id
|
|
243
|
+
}, { additionalProperties: false }),
|
|
244
|
+
phase: Union([
|
|
245
|
+
"pending",
|
|
246
|
+
"reserved",
|
|
247
|
+
"started",
|
|
248
|
+
"settled",
|
|
249
|
+
"expired",
|
|
250
|
+
"cancelled",
|
|
251
|
+
"unknown"
|
|
252
|
+
].map((phase) => Literal(phase))),
|
|
253
|
+
claimantHostId: Optional(id)
|
|
254
|
+
}, { additionalProperties: false });
|
|
255
|
+
const CalendarOccurrenceSchema = _Object_({
|
|
256
|
+
id,
|
|
257
|
+
eventId: id,
|
|
258
|
+
centralJob: Optional(CalendarOccurrenceJobSchema),
|
|
259
|
+
revision: Integer({ minimum: 1 }),
|
|
260
|
+
dueAt: Number$1(),
|
|
261
|
+
state: Union([
|
|
262
|
+
"queued",
|
|
263
|
+
"running",
|
|
264
|
+
"succeeded",
|
|
265
|
+
"failed",
|
|
266
|
+
"skipped",
|
|
267
|
+
"interrupted",
|
|
268
|
+
"blocked"
|
|
269
|
+
].map((value) => Literal(value))),
|
|
270
|
+
skippedCount: Integer({ minimum: 0 }),
|
|
271
|
+
skipUntil: Optional(Number$1()),
|
|
272
|
+
sessionId: Optional(id),
|
|
273
|
+
error: Optional(String$1()),
|
|
274
|
+
workflowRun: Optional(PoWorkflowRunRefSchema),
|
|
275
|
+
summary: Optional(String$1({ maxLength: MAX_CALENDAR_SUMMARY_LENGTH })),
|
|
276
|
+
createdAt: Number$1(),
|
|
277
|
+
updatedAt: Number$1()
|
|
278
|
+
}, { additionalProperties: false });
|
|
279
|
+
/** True for plain JSON within Calendar's depth and size limits. Rejects non-finite numbers and class instances. */
|
|
280
|
+
function isCalendarJson(value) {
|
|
281
|
+
const visit = (entry, depth) => {
|
|
282
|
+
if (depth > 16) return false;
|
|
283
|
+
if (entry === null || typeof entry === "string" || typeof entry === "boolean") return true;
|
|
284
|
+
if (typeof entry === "number") return Number.isFinite(entry);
|
|
285
|
+
if (Array.isArray(entry)) return entry.every((item) => visit(item, depth + 1));
|
|
286
|
+
if (typeof entry !== "object" || Object.getPrototypeOf(entry) !== Object.prototype) return false;
|
|
287
|
+
return Object.values(entry).every((item) => visit(item, depth + 1));
|
|
288
|
+
};
|
|
289
|
+
return visit(value, 0) && new TextEncoder().encode(JSON.stringify(value)).byteLength <= 16384;
|
|
290
|
+
}
|
|
291
|
+
/** Serializes with sorted object keys, so values compare structurally. */
|
|
292
|
+
function canonicalCalendarJson(value) {
|
|
293
|
+
const sort = (entry) => Array.isArray(entry) ? entry.map(sort) : entry && typeof entry === "object" ? Object.fromEntries(Object.entries(entry).filter(([, item]) => item !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, item]) => [key, sort(item)])) : entry;
|
|
294
|
+
return JSON.stringify(sort(value)) ?? "undefined";
|
|
295
|
+
}
|
|
296
|
+
/** Checks the rules a single field schema cannot: one driver, new-session-only setup, and well-formed values. */
|
|
297
|
+
function validateCalendarExecution(event) {
|
|
298
|
+
if (event.centralJob?.portable && (event.target.kind !== "newSession" || !event.assignment?.profile)) throw new Error("Portable jobs require a new-session target and an explicit profile.");
|
|
299
|
+
if ([
|
|
300
|
+
event.prompt,
|
|
301
|
+
event.workflow,
|
|
302
|
+
event.action
|
|
303
|
+
].filter((value) => value !== void 0).length !== 1) throw new Error("Give exactly one of prompt, workflow or action.");
|
|
304
|
+
if (event.prompt !== void 0 && !event.prompt.trim()) throw new Error("Give a non-empty prompt.");
|
|
305
|
+
if ((event.workflow || event.assignment) && event.target.kind !== "newSession") throw new Error("Workflows and agent assignments need a new-session target.");
|
|
306
|
+
if (event.workflow && !Check(PoWorkflowDefinitionRefSchema, {
|
|
307
|
+
source: "repo",
|
|
308
|
+
key: event.workflow.key
|
|
309
|
+
})) throw new Error("Give a workflow key relative to the repository workflow folder.");
|
|
310
|
+
if (event.action && !isCalendarJson(event.action.input)) throw new Error("Action input must be plain JSON within Calendar limits.");
|
|
311
|
+
}
|
|
312
|
+
function parseCalendarEventInput(value) {
|
|
313
|
+
if (!Check(CalendarEventInputSchema, value) || !value.title.trim()) throw new Error("Invalid calendar event");
|
|
314
|
+
validateCalendarExecution(value);
|
|
315
|
+
return value;
|
|
316
|
+
}
|
|
317
|
+
function parseCalendarEventPatch(value) {
|
|
318
|
+
if (!Check(CalendarEventPatchSchema, value) || value.title !== void 0 && !value.title.trim()) throw new Error("Invalid calendar event patch");
|
|
319
|
+
return value;
|
|
320
|
+
}
|
|
321
|
+
/** Applies a patch: omission keeps a field, `null` removes it. Status changes are left to the caller. */
|
|
322
|
+
function mergeCalendarEvent(current, patch) {
|
|
323
|
+
const next = { ...current };
|
|
324
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
325
|
+
if (value === void 0) continue;
|
|
326
|
+
if (value === null) delete next[key];
|
|
327
|
+
else next[key] = value;
|
|
328
|
+
}
|
|
329
|
+
return next;
|
|
330
|
+
}
|
|
331
|
+
const reservation = {
|
|
332
|
+
requestId: id,
|
|
333
|
+
occurrenceId: id,
|
|
334
|
+
generation: Integer({
|
|
335
|
+
minimum: 1,
|
|
336
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
337
|
+
}),
|
|
338
|
+
token: id
|
|
339
|
+
};
|
|
340
|
+
const CalendarWorkerReceiveRequestSchema = _Object_({
|
|
341
|
+
requestId: id,
|
|
342
|
+
lane: CalendarJobLaneSchema
|
|
343
|
+
}, { additionalProperties: false });
|
|
344
|
+
const CalendarWorkerStartRequestSchema = _Object_(reservation, { additionalProperties: false });
|
|
345
|
+
const workerResult = _Object_({
|
|
346
|
+
state: Union([
|
|
347
|
+
"succeeded",
|
|
348
|
+
"failed",
|
|
349
|
+
"interrupted"
|
|
350
|
+
].map((state) => Literal(state))),
|
|
351
|
+
sessionId: Optional(id),
|
|
352
|
+
error: Optional(String$1({ maxLength: MAX_CALENDAR_SUMMARY_LENGTH })),
|
|
353
|
+
summary: Optional(String$1({ maxLength: MAX_CALENDAR_SUMMARY_LENGTH })),
|
|
354
|
+
workflowRun: Optional(PoWorkflowRunRefSchema)
|
|
355
|
+
}, { additionalProperties: false });
|
|
356
|
+
const CalendarWorkerSettleRequestSchema = _Object_({
|
|
357
|
+
...reservation,
|
|
358
|
+
result: workerResult
|
|
359
|
+
}, { additionalProperties: false });
|
|
360
|
+
const CalendarWorkerReconcileRequestSchema = _Object_({
|
|
361
|
+
...reservation,
|
|
362
|
+
result: Optional(workerResult)
|
|
363
|
+
}, { additionalProperties: false });
|
|
364
|
+
const CalendarWorkerRequestSchema = Union([
|
|
365
|
+
_Object_({
|
|
366
|
+
operation: Literal("receive"),
|
|
367
|
+
input: CalendarWorkerReceiveRequestSchema
|
|
368
|
+
}, { additionalProperties: false }),
|
|
369
|
+
_Object_({
|
|
370
|
+
operation: Literal("start"),
|
|
371
|
+
input: CalendarWorkerStartRequestSchema
|
|
372
|
+
}, { additionalProperties: false }),
|
|
373
|
+
_Object_({
|
|
374
|
+
operation: Literal("settle"),
|
|
375
|
+
input: CalendarWorkerSettleRequestSchema
|
|
376
|
+
}, { additionalProperties: false }),
|
|
377
|
+
_Object_({
|
|
378
|
+
operation: Literal("reconcile"),
|
|
379
|
+
input: CalendarWorkerReconcileRequestSchema
|
|
380
|
+
}, { additionalProperties: false })
|
|
381
|
+
]);
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region ../../../layers/automation/po-calendar/src/schemas/calendarApi.ts
|
|
384
|
+
const CalendarDraftSchema = _Object_({
|
|
385
|
+
...Omit(CalendarEventInputSchema, ["owner", "centralJob"]).properties,
|
|
386
|
+
centralJob: Optional(Partial(CalendarCentralJobSchema))
|
|
387
|
+
}, { additionalProperties: false });
|
|
388
|
+
/** The draft an agent writes: its schedule may omit `tz` and give a one-off time as local wall-clock time. */
|
|
389
|
+
const CalendarAgentDraftSchema = _Object_({
|
|
390
|
+
...CalendarDraftSchema.properties,
|
|
391
|
+
schedule: CalendarScheduleInputSchema
|
|
392
|
+
}, { additionalProperties: false });
|
|
393
|
+
const CalendarCreateRequestSchema = _Object_({
|
|
394
|
+
...CalendarDraftSchema.properties,
|
|
395
|
+
destinationHostId: Optional(String$1({
|
|
396
|
+
minLength: 1,
|
|
397
|
+
maxLength: 256
|
|
398
|
+
})),
|
|
399
|
+
grant: Optional(Unknown())
|
|
400
|
+
}, { additionalProperties: false });
|
|
401
|
+
const CalendarListInputSchema = _Object_({}, { additionalProperties: false });
|
|
402
|
+
const CalendarCancelInputSchema = _Object_({ id: String$1({
|
|
403
|
+
minLength: 1,
|
|
404
|
+
maxLength: 256
|
|
405
|
+
}) }, { additionalProperties: false });
|
|
406
|
+
function parseCalendarDraft(value) {
|
|
407
|
+
if (!Check(CalendarDraftSchema, value) || !value.title.trim()) throw new Error("Provide title, schedule, target and one of prompt, workflow or action. Ownership comes from this route.");
|
|
408
|
+
validateCalendarExecution(value);
|
|
409
|
+
return value;
|
|
410
|
+
}
|
|
411
|
+
/** What the person wants changed about one event, in their own words. */
|
|
412
|
+
const CalendarAskSchema = _Object_({ request: String$1({
|
|
413
|
+
minLength: 1,
|
|
414
|
+
maxLength: 2e3
|
|
415
|
+
}) }, { additionalProperties: false });
|
|
416
|
+
function parseCalendarAsk(value) {
|
|
417
|
+
if (!Check(CalendarAskSchema, value) || !value.request.trim()) throw new Error("Say what to change, in at most 2,000 characters.");
|
|
418
|
+
return value.request.trim();
|
|
419
|
+
}
|
|
420
|
+
const CalendarListFiltersSchema = _Object_({
|
|
421
|
+
status: Optional(Union([
|
|
422
|
+
"open",
|
|
423
|
+
"active",
|
|
424
|
+
"paused",
|
|
425
|
+
"done",
|
|
426
|
+
"cancelled"
|
|
427
|
+
].map((status) => Literal(status)))),
|
|
428
|
+
workspace: Optional(String$1({
|
|
429
|
+
minLength: 1,
|
|
430
|
+
maxLength: 256
|
|
431
|
+
})),
|
|
432
|
+
kind: Optional(Union([
|
|
433
|
+
Literal("once"),
|
|
434
|
+
Literal("interval"),
|
|
435
|
+
Literal("cron")
|
|
436
|
+
])),
|
|
437
|
+
q: Optional(String$1({ maxLength: 200 })),
|
|
438
|
+
limit: Optional(Integer({
|
|
439
|
+
minimum: 1,
|
|
440
|
+
maximum: 200
|
|
441
|
+
}))
|
|
442
|
+
}, { additionalProperties: false });
|
|
443
|
+
function parseCalendarListFilters(value) {
|
|
444
|
+
if (!Check(CalendarListFiltersSchema, value)) throw new Error("Filter by status (open, active, paused, done or cancelled), workspace, kind (once, interval or cron), q of at most 200 characters, and limit from 1 to 200.");
|
|
445
|
+
return value;
|
|
446
|
+
}
|
|
447
|
+
/** Validate consent binding here; the destination verifies the device signature at fire time. */
|
|
448
|
+
function parseCalendarRemoteGrant(value, homeHostId, destinationHostId, workspaceId, now) {
|
|
449
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Cross-host events require a device-signed unattended grant.");
|
|
450
|
+
const grant = value;
|
|
451
|
+
const payload = grant.payload;
|
|
452
|
+
if (grant.tag !== "po/grant/v1" || typeof grant.signature !== "string" || !grant.signature || !payload || typeof payload.constraints?.eventId !== "string" || !payload.constraints.eventId || payload.constraints.eventId.length > 256 || payload.constraints.eventId.includes("/") || payload.constraints.package !== "@agimon-ai/po-calendar" || payload.targetHostId !== destinationHostId || payload.callingHostId !== homeHostId || payload.workspaceId !== workspaceId || !Array.isArray(payload.operations) || !payload.operations.includes("fire") || !Number.isSafeInteger(payload.issuedAt) || !Number.isSafeInteger(payload.expiresAt) || payload.expiresAt <= now || payload.issuedAt > now || payload.expiresAt <= payload.issuedAt || payload.expiresAt - payload.issuedAt > 2592e6) throw new Error("The unattended grant does not match this calendar event or its 30-day expiry limit.");
|
|
453
|
+
return grant;
|
|
454
|
+
}
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/compose.js
|
|
457
|
+
var compose = (middleware, onError, onNotFound) => {
|
|
458
|
+
return (context, next) => {
|
|
459
|
+
let index = -1;
|
|
460
|
+
return dispatch(0);
|
|
461
|
+
async function dispatch(i) {
|
|
462
|
+
if (i <= index) throw new Error("next() called multiple times");
|
|
463
|
+
index = i;
|
|
464
|
+
let res;
|
|
465
|
+
let isError = false;
|
|
466
|
+
let handler;
|
|
467
|
+
if (middleware[i]) {
|
|
468
|
+
handler = middleware[i][0][0];
|
|
469
|
+
context.req.routeIndex = i;
|
|
470
|
+
} else handler = i === middleware.length && next || void 0;
|
|
471
|
+
if (handler) try {
|
|
472
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
473
|
+
} catch (err) {
|
|
474
|
+
if (err instanceof Error && onError) {
|
|
475
|
+
context.error = err;
|
|
476
|
+
res = await onError(err, context);
|
|
477
|
+
isError = true;
|
|
478
|
+
} else throw err;
|
|
479
|
+
}
|
|
480
|
+
else if (context.finalized === false && onNotFound) res = await onNotFound(context);
|
|
481
|
+
if (res && (context.finalized === false || isError)) context.res = res;
|
|
482
|
+
return context;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/http-exception.js
|
|
488
|
+
var HTTPException = class extends Error {
|
|
489
|
+
res;
|
|
490
|
+
status;
|
|
491
|
+
/**
|
|
492
|
+
* Creates an instance of `HTTPException`.
|
|
493
|
+
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
494
|
+
* @param options - Additional options for the exception.
|
|
495
|
+
*/
|
|
496
|
+
constructor(status = 500, options) {
|
|
497
|
+
super(options?.message, { cause: options?.cause });
|
|
498
|
+
this.res = options?.res;
|
|
499
|
+
this.status = status;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Returns the response object associated with the exception.
|
|
503
|
+
* If a response object is not provided, a new response is created with the error message and status code.
|
|
504
|
+
* @returns The response object.
|
|
505
|
+
*/
|
|
506
|
+
getResponse() {
|
|
507
|
+
if (this.res) return new Response(this.res.body, {
|
|
508
|
+
status: this.status,
|
|
509
|
+
headers: this.res.headers
|
|
510
|
+
});
|
|
511
|
+
return new Response(this.message, { status: this.status });
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/request/constants.js
|
|
516
|
+
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/utils/buffer.js
|
|
519
|
+
var bufferToFormData = (arrayBuffer, contentType) => {
|
|
520
|
+
return new Response(arrayBuffer, { headers: { "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase()) } }).formData();
|
|
521
|
+
};
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/utils/body.js
|
|
524
|
+
var MAX_NESTING_DEPTH = 32;
|
|
525
|
+
var MAX_NESTED_OBJECTS = 1e4;
|
|
526
|
+
var isRawRequest = (request) => "headers" in request;
|
|
527
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
528
|
+
const { all = false, dot = false } = options;
|
|
529
|
+
const mediaType = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
|
|
530
|
+
if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") return parseFormData(request, {
|
|
531
|
+
all,
|
|
532
|
+
dot
|
|
533
|
+
});
|
|
534
|
+
return {};
|
|
535
|
+
};
|
|
536
|
+
async function parseFormData(request, options) {
|
|
537
|
+
if (!isRawRequest(request) && request.bodyCache.formData) return convertFormDataToBodyData(await request.bodyCache.formData, options);
|
|
538
|
+
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
|
|
539
|
+
const formDataPromise = bufferToFormData(await request.arrayBuffer(), headers.get("Content-Type") || "");
|
|
540
|
+
if (!isRawRequest(request)) request.bodyCache.formData = formDataPromise;
|
|
541
|
+
const formData = await formDataPromise;
|
|
542
|
+
if (formData) return convertFormDataToBodyData(formData, options);
|
|
543
|
+
return {};
|
|
544
|
+
}
|
|
545
|
+
function convertFormDataToBodyData(formData, options) {
|
|
546
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
547
|
+
const nestingState = { count: 0 };
|
|
548
|
+
formData.forEach((value, key) => {
|
|
549
|
+
if (!(options.all || key.endsWith("[]"))) form[key] = value;
|
|
550
|
+
else handleParsingAllValues(form, key, value);
|
|
551
|
+
});
|
|
552
|
+
if (options.dot) Object.entries(form).forEach(([key, value]) => {
|
|
553
|
+
if (key.includes(".")) {
|
|
554
|
+
handleParsingNestedValues(form, key, value, nestingState);
|
|
555
|
+
delete form[key];
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
return form;
|
|
559
|
+
}
|
|
560
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
561
|
+
if (form[key] !== void 0) {
|
|
562
|
+
if (Array.isArray(form[key])) form[key].push(value);
|
|
563
|
+
else form[key] = [form[key], value];
|
|
564
|
+
} else if (!key.endsWith("[]")) form[key] = value;
|
|
565
|
+
else form[key] = [value];
|
|
566
|
+
};
|
|
567
|
+
var handleParsingNestedValues = (form, key, value, state) => {
|
|
568
|
+
if (/(?:^|\.)__proto__\./.test(key)) return;
|
|
569
|
+
let nestedForm = form;
|
|
570
|
+
const keys = key.split(".", MAX_NESTING_DEPTH + 2);
|
|
571
|
+
if (keys.length > MAX_NESTING_DEPTH + 1) throwNestingLimitExceeded();
|
|
572
|
+
keys.forEach((key2, index) => {
|
|
573
|
+
if (index === keys.length - 1) nestedForm[key2] = value;
|
|
574
|
+
else {
|
|
575
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
576
|
+
if (state.count++ >= MAX_NESTED_OBJECTS) throwNestingLimitExceeded();
|
|
577
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
578
|
+
}
|
|
579
|
+
nestedForm = nestedForm[key2];
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
};
|
|
583
|
+
var throwNestingLimitExceeded = () => {
|
|
584
|
+
throw new Error("Nesting limit exceeded");
|
|
585
|
+
};
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/utils/url.js
|
|
588
|
+
var splitPath = (path) => {
|
|
589
|
+
const paths = path.split("/");
|
|
590
|
+
if (paths[0] === "") paths.shift();
|
|
591
|
+
return paths;
|
|
592
|
+
};
|
|
593
|
+
var splitRoutingPath = (routePath) => {
|
|
594
|
+
const { groups, path } = extractGroupsFromPath(routePath);
|
|
595
|
+
return replaceGroupMarks(splitPath(path), groups);
|
|
596
|
+
};
|
|
597
|
+
var extractGroupsFromPath = (path) => {
|
|
598
|
+
const groups = [];
|
|
599
|
+
path = path.replace(/\{[^}]+\}/g, (match, index) => {
|
|
600
|
+
const mark = `@${index}`;
|
|
601
|
+
groups.push([mark, match]);
|
|
602
|
+
return mark;
|
|
603
|
+
});
|
|
604
|
+
return {
|
|
605
|
+
groups,
|
|
606
|
+
path
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
var replaceGroupMarks = (paths, groups) => {
|
|
610
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
611
|
+
const [mark] = groups[i];
|
|
612
|
+
for (let j = paths.length - 1; j >= 0; j--) if (paths[j].includes(mark)) {
|
|
613
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return paths;
|
|
618
|
+
};
|
|
619
|
+
var patternCache = {};
|
|
620
|
+
var getPattern = (label, next) => {
|
|
621
|
+
if (label === "*") return "*";
|
|
622
|
+
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
623
|
+
if (match) {
|
|
624
|
+
const cacheKey = `${label}#${next}`;
|
|
625
|
+
if (!patternCache[cacheKey]) {
|
|
626
|
+
if (match[2]) patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
|
|
627
|
+
cacheKey,
|
|
628
|
+
match[1],
|
|
629
|
+
new RegExp(`^${match[2]}(?=/${next})`)
|
|
630
|
+
] : [
|
|
631
|
+
label,
|
|
632
|
+
match[1],
|
|
633
|
+
new RegExp(`^${match[2]}$`)
|
|
634
|
+
];
|
|
635
|
+
else patternCache[cacheKey] = [
|
|
636
|
+
label,
|
|
637
|
+
match[1],
|
|
638
|
+
true
|
|
639
|
+
];
|
|
640
|
+
}
|
|
641
|
+
return patternCache[cacheKey];
|
|
642
|
+
}
|
|
643
|
+
return null;
|
|
644
|
+
};
|
|
645
|
+
var tryDecode = (str, decoder) => {
|
|
646
|
+
try {
|
|
647
|
+
return decoder(str);
|
|
648
|
+
} catch {
|
|
649
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
650
|
+
try {
|
|
651
|
+
return decoder(match);
|
|
652
|
+
} catch {
|
|
653
|
+
return match;
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
659
|
+
var getPath = (request) => {
|
|
660
|
+
const url = request.url;
|
|
661
|
+
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
662
|
+
let i = start;
|
|
663
|
+
for (; i < url.length; i++) {
|
|
664
|
+
const charCode = url.charCodeAt(i);
|
|
665
|
+
if (charCode === 37) {
|
|
666
|
+
const queryIndex = url.indexOf("?", i);
|
|
667
|
+
const hashIndex = url.indexOf("#", i);
|
|
668
|
+
const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
669
|
+
const path = url.slice(start, end);
|
|
670
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
671
|
+
} else if (charCode === 63 || charCode === 35) break;
|
|
672
|
+
}
|
|
673
|
+
return url.slice(start, i);
|
|
674
|
+
};
|
|
675
|
+
var getPathNoStrict = (request) => {
|
|
676
|
+
const result = getPath(request);
|
|
677
|
+
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
678
|
+
};
|
|
679
|
+
var mergePath = (base, sub, ...rest) => {
|
|
680
|
+
if (rest.length) sub = mergePath(sub, ...rest);
|
|
681
|
+
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
682
|
+
};
|
|
683
|
+
var checkOptionalParameter = (path) => {
|
|
684
|
+
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) return null;
|
|
685
|
+
const segments = path.split("/");
|
|
686
|
+
const results = [];
|
|
687
|
+
let basePath = "";
|
|
688
|
+
segments.forEach((segment) => {
|
|
689
|
+
if (segment !== "" && !/\:/.test(segment)) basePath += "/" + segment;
|
|
690
|
+
else if (/\:/.test(segment)) {
|
|
691
|
+
if (segment.charCodeAt(segment.length - 1) === 63) {
|
|
692
|
+
if (results.length === 0 && basePath === "") results.push("/");
|
|
693
|
+
else results.push(basePath);
|
|
694
|
+
const optionalSegment = segment.slice(0, -1);
|
|
695
|
+
basePath += "/" + optionalSegment;
|
|
696
|
+
results.push(basePath);
|
|
697
|
+
} else basePath += "/" + segment;
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
701
|
+
};
|
|
702
|
+
var tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
|
|
703
|
+
var _decodeURI = (value) => {
|
|
704
|
+
if (value.indexOf("+") !== -1) value = value.replace(/\+/g, " ");
|
|
705
|
+
return tryDecodeURIComponent(value);
|
|
706
|
+
};
|
|
707
|
+
var _getQueryParam = (url, key, multiple) => {
|
|
708
|
+
const hashIndex = url.indexOf("#", 8);
|
|
709
|
+
if (hashIndex !== -1) url = url.slice(0, hashIndex);
|
|
710
|
+
let encoded;
|
|
711
|
+
if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
|
|
712
|
+
let keyIndex2 = url.indexOf("?", 8);
|
|
713
|
+
if (keyIndex2 === -1) return;
|
|
714
|
+
if (!url.startsWith(key, keyIndex2 + 1)) keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
715
|
+
while (keyIndex2 !== -1) {
|
|
716
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
717
|
+
if (trailingKeyCode === 61) {
|
|
718
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
719
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
720
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
721
|
+
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) return "";
|
|
722
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
723
|
+
}
|
|
724
|
+
encoded = /[%+]/.test(url);
|
|
725
|
+
if (!encoded) return;
|
|
726
|
+
}
|
|
727
|
+
const results = /* @__PURE__ */ Object.create(null);
|
|
728
|
+
encoded ??= /[%+]/.test(url);
|
|
729
|
+
let keyIndex = url.indexOf("?", 8);
|
|
730
|
+
while (keyIndex !== -1) {
|
|
731
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
732
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
733
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) valueIndex = -1;
|
|
734
|
+
let name = url.slice(keyIndex + 1, valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex);
|
|
735
|
+
if (encoded) name = _decodeURI(name);
|
|
736
|
+
keyIndex = nextKeyIndex;
|
|
737
|
+
if (name === "") continue;
|
|
738
|
+
let value;
|
|
739
|
+
if (valueIndex === -1) value = "";
|
|
740
|
+
else {
|
|
741
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
742
|
+
if (encoded) value = _decodeURI(value);
|
|
743
|
+
}
|
|
744
|
+
if (multiple) {
|
|
745
|
+
if (!(results[name] && Array.isArray(results[name]))) results[name] = [];
|
|
746
|
+
results[name].push(value);
|
|
747
|
+
} else results[name] ??= value;
|
|
748
|
+
}
|
|
749
|
+
return key ? results[key] : results;
|
|
750
|
+
};
|
|
751
|
+
var getQueryParam = _getQueryParam;
|
|
752
|
+
var getQueryParams = (url, key) => {
|
|
753
|
+
return _getQueryParam(url, key, true);
|
|
754
|
+
};
|
|
755
|
+
var decodeURIComponent_ = decodeURIComponent;
|
|
756
|
+
//#endregion
|
|
757
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/request.js
|
|
758
|
+
var HonoRequest = class {
|
|
759
|
+
/**
|
|
760
|
+
* `.raw` can get the raw Request object.
|
|
761
|
+
*
|
|
762
|
+
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
763
|
+
*
|
|
764
|
+
* @example
|
|
765
|
+
* ```ts
|
|
766
|
+
* // For Cloudflare Workers
|
|
767
|
+
* app.post('/', async (c) => {
|
|
768
|
+
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
769
|
+
* ...
|
|
770
|
+
* })
|
|
771
|
+
* ```
|
|
772
|
+
*/
|
|
773
|
+
raw;
|
|
774
|
+
#validatedData;
|
|
775
|
+
#matchResult;
|
|
776
|
+
routeIndex = 0;
|
|
777
|
+
/**
|
|
778
|
+
* `.path` can get the pathname of the request.
|
|
779
|
+
*
|
|
780
|
+
* @see {@link https://hono.dev/docs/api/request#path}
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```ts
|
|
784
|
+
* app.get('/about/me', (c) => {
|
|
785
|
+
* const pathname = c.req.path // `/about/me`
|
|
786
|
+
* })
|
|
787
|
+
* ```
|
|
788
|
+
*/
|
|
789
|
+
path;
|
|
790
|
+
bodyCache = {};
|
|
791
|
+
constructor(request, path = "/", matchResult = [[]]) {
|
|
792
|
+
this.raw = request;
|
|
793
|
+
this.path = path;
|
|
794
|
+
this.#matchResult = matchResult;
|
|
795
|
+
}
|
|
796
|
+
param(key) {
|
|
797
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
798
|
+
}
|
|
799
|
+
#getDecodedParam(key) {
|
|
800
|
+
const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
|
|
801
|
+
const param = this.#getParamValue(paramKey);
|
|
802
|
+
return param && tryDecodeURIComponent(param);
|
|
803
|
+
}
|
|
804
|
+
#getAllDecodedParams() {
|
|
805
|
+
const decoded = {};
|
|
806
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
|
|
807
|
+
for (const key of keys) {
|
|
808
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
809
|
+
if (value !== void 0) decoded[key] = tryDecodeURIComponent(value);
|
|
810
|
+
}
|
|
811
|
+
return decoded;
|
|
812
|
+
}
|
|
813
|
+
#getParamValue(paramKey) {
|
|
814
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
815
|
+
}
|
|
816
|
+
query(key) {
|
|
817
|
+
return getQueryParam(this.url, key);
|
|
818
|
+
}
|
|
819
|
+
queries(key) {
|
|
820
|
+
return getQueryParams(this.url, key);
|
|
821
|
+
}
|
|
822
|
+
header(name) {
|
|
823
|
+
if (name) return this.raw.headers.get(name) ?? void 0;
|
|
824
|
+
const headerData = /* @__PURE__ */ Object.create(null);
|
|
825
|
+
this.raw.headers.forEach((value, key) => {
|
|
826
|
+
headerData[key] = value;
|
|
827
|
+
});
|
|
828
|
+
return headerData;
|
|
829
|
+
}
|
|
830
|
+
async parseBody(options) {
|
|
831
|
+
return parseBody(this, options);
|
|
832
|
+
}
|
|
833
|
+
#cachedBody = (key) => {
|
|
834
|
+
const { bodyCache, raw } = this;
|
|
835
|
+
const cachedBody = bodyCache[key];
|
|
836
|
+
if (cachedBody) return cachedBody;
|
|
837
|
+
for (const anyCachedKey in bodyCache) return bodyCache[anyCachedKey].then((body) => {
|
|
838
|
+
if (anyCachedKey === "json") body = JSON.stringify(body);
|
|
839
|
+
const contentType = anyCachedKey === "formData" ? void 0 : raw.headers.get("content-type");
|
|
840
|
+
return new Response(body, { headers: contentType ? { "Content-Type": contentType } : void 0 })[key]();
|
|
841
|
+
});
|
|
842
|
+
return bodyCache[key] = raw[key]();
|
|
843
|
+
};
|
|
844
|
+
/**
|
|
845
|
+
* `.json()` can parse Request body of type `application/json`
|
|
846
|
+
*
|
|
847
|
+
* @see {@link https://hono.dev/docs/api/request#json}
|
|
848
|
+
*
|
|
849
|
+
* @example
|
|
850
|
+
* ```ts
|
|
851
|
+
* app.post('/entry', async (c) => {
|
|
852
|
+
* const body = await c.req.json()
|
|
853
|
+
* })
|
|
854
|
+
* ```
|
|
855
|
+
*/
|
|
856
|
+
json() {
|
|
857
|
+
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* `.text()` can parse Request body of type `text/plain`
|
|
861
|
+
*
|
|
862
|
+
* @see {@link https://hono.dev/docs/api/request#text}
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```ts
|
|
866
|
+
* app.post('/entry', async (c) => {
|
|
867
|
+
* const body = await c.req.text()
|
|
868
|
+
* })
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
text() {
|
|
872
|
+
return this.#cachedBody("text");
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
876
|
+
*
|
|
877
|
+
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
878
|
+
*
|
|
879
|
+
* @example
|
|
880
|
+
* ```ts
|
|
881
|
+
* app.post('/entry', async (c) => {
|
|
882
|
+
* const body = await c.req.arrayBuffer()
|
|
883
|
+
* })
|
|
884
|
+
* ```
|
|
885
|
+
*/
|
|
886
|
+
arrayBuffer() {
|
|
887
|
+
return this.#cachedBody("arrayBuffer");
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* `.bytes()` parses the request body as a `Uint8Array`.
|
|
891
|
+
*
|
|
892
|
+
* @see {@link https://hono.dev/docs/api/request#bytes}
|
|
893
|
+
*
|
|
894
|
+
* @example
|
|
895
|
+
* ```ts
|
|
896
|
+
* app.post('/entry', async (c) => {
|
|
897
|
+
* const body = await c.req.bytes()
|
|
898
|
+
* })
|
|
899
|
+
* ```
|
|
900
|
+
*/
|
|
901
|
+
bytes() {
|
|
902
|
+
return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Parses the request body as a `Blob`.
|
|
906
|
+
* @example
|
|
907
|
+
* ```ts
|
|
908
|
+
* app.post('/entry', async (c) => {
|
|
909
|
+
* const body = await c.req.blob();
|
|
910
|
+
* });
|
|
911
|
+
* ```
|
|
912
|
+
* @see https://hono.dev/docs/api/request#blob
|
|
913
|
+
*/
|
|
914
|
+
blob() {
|
|
915
|
+
return this.#cachedBody("blob");
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Parses the request body as `FormData`.
|
|
919
|
+
* @example
|
|
920
|
+
* ```ts
|
|
921
|
+
* app.post('/entry', async (c) => {
|
|
922
|
+
* const body = await c.req.formData();
|
|
923
|
+
* });
|
|
924
|
+
* ```
|
|
925
|
+
* @see https://hono.dev/docs/api/request#formdata
|
|
926
|
+
*/
|
|
927
|
+
formData() {
|
|
928
|
+
return this.#cachedBody("formData");
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Adds validated data to the request.
|
|
932
|
+
*
|
|
933
|
+
* @param target - The target of the validation.
|
|
934
|
+
* @param data - The validated data to add.
|
|
935
|
+
*/
|
|
936
|
+
addValidatedData(target, data) {
|
|
937
|
+
(this.#validatedData ??= {})[target] = data;
|
|
938
|
+
}
|
|
939
|
+
valid(target) {
|
|
940
|
+
return this.#validatedData?.[target];
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* `.url()` can get the request url strings.
|
|
944
|
+
*
|
|
945
|
+
* @see {@link https://hono.dev/docs/api/request#url}
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* ```ts
|
|
949
|
+
* app.get('/about/me', (c) => {
|
|
950
|
+
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
951
|
+
* ...
|
|
952
|
+
* })
|
|
953
|
+
* ```
|
|
954
|
+
*/
|
|
955
|
+
get url() {
|
|
956
|
+
return this.raw.url;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* `.method()` can get the method name of the request.
|
|
960
|
+
*
|
|
961
|
+
* @see {@link https://hono.dev/docs/api/request#method}
|
|
962
|
+
*
|
|
963
|
+
* @example
|
|
964
|
+
* ```ts
|
|
965
|
+
* app.get('/about/me', (c) => {
|
|
966
|
+
* const method = c.req.method // `GET`
|
|
967
|
+
* })
|
|
968
|
+
* ```
|
|
969
|
+
*/
|
|
970
|
+
get method() {
|
|
971
|
+
return this.raw.method;
|
|
972
|
+
}
|
|
973
|
+
get [GET_MATCH_RESULT]() {
|
|
974
|
+
return this.#matchResult;
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* `.matchedRoutes()` can return a matched route in the handler
|
|
978
|
+
*
|
|
979
|
+
* @deprecated
|
|
980
|
+
*
|
|
981
|
+
* Use matchedRoutes helper defined in "hono/route" instead.
|
|
982
|
+
*
|
|
983
|
+
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
|
984
|
+
*
|
|
985
|
+
* @example
|
|
986
|
+
* ```ts
|
|
987
|
+
* app.use('*', async function logger(c, next) {
|
|
988
|
+
* await next()
|
|
989
|
+
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
|
990
|
+
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
991
|
+
* console.log(
|
|
992
|
+
* method,
|
|
993
|
+
* ' ',
|
|
994
|
+
* path,
|
|
995
|
+
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
996
|
+
* name,
|
|
997
|
+
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
998
|
+
* )
|
|
999
|
+
* })
|
|
1000
|
+
* })
|
|
1001
|
+
* ```
|
|
1002
|
+
*/
|
|
1003
|
+
get matchedRoutes() {
|
|
1004
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* `routePath()` can retrieve the path registered within the handler
|
|
1008
|
+
*
|
|
1009
|
+
* @deprecated
|
|
1010
|
+
*
|
|
1011
|
+
* Use routePath helper defined in "hono/route" instead.
|
|
1012
|
+
*
|
|
1013
|
+
* @see {@link https://hono.dev/docs/api/request#routepath}
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* ```ts
|
|
1017
|
+
* app.get('/posts/:id', (c) => {
|
|
1018
|
+
* return c.json({ path: c.req.routePath })
|
|
1019
|
+
* })
|
|
1020
|
+
* ```
|
|
1021
|
+
*/
|
|
1022
|
+
get routePath() {
|
|
1023
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
//#endregion
|
|
1027
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/utils/html.js
|
|
1028
|
+
var HtmlEscapedCallbackPhase = {
|
|
1029
|
+
Stringify: 1,
|
|
1030
|
+
BeforeStream: 2,
|
|
1031
|
+
Stream: 3
|
|
1032
|
+
};
|
|
1033
|
+
var raw = (value, callbacks) => {
|
|
1034
|
+
const escapedString = new String(value);
|
|
1035
|
+
escapedString.isEscaped = true;
|
|
1036
|
+
escapedString.callbacks = callbacks;
|
|
1037
|
+
return escapedString;
|
|
1038
|
+
};
|
|
1039
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
1040
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
1041
|
+
if (!(str instanceof Promise)) str = str.toString();
|
|
1042
|
+
if (str instanceof Promise) str = await str;
|
|
1043
|
+
}
|
|
1044
|
+
const callbacks = str.callbacks;
|
|
1045
|
+
if (!callbacks?.length) return Promise.resolve(str);
|
|
1046
|
+
if (buffer) buffer[0] += str;
|
|
1047
|
+
else buffer = [str];
|
|
1048
|
+
const resStr = Promise.all(callbacks.map((c) => c({
|
|
1049
|
+
phase,
|
|
1050
|
+
buffer,
|
|
1051
|
+
context
|
|
1052
|
+
}))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
|
|
1053
|
+
if (preserveCallbacks) return raw(await resStr, callbacks);
|
|
1054
|
+
else return resStr;
|
|
1055
|
+
};
|
|
1056
|
+
//#endregion
|
|
1057
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/context.js
|
|
1058
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
1059
|
+
var setDefaultContentType = (contentType, headers) => {
|
|
1060
|
+
return {
|
|
1061
|
+
"Content-Type": contentType,
|
|
1062
|
+
...headers
|
|
1063
|
+
};
|
|
1064
|
+
};
|
|
1065
|
+
var createResponseInstance = (body, init) => new Response(body, init);
|
|
1066
|
+
var Context = class {
|
|
1067
|
+
#rawRequest;
|
|
1068
|
+
#req;
|
|
1069
|
+
/**
|
|
1070
|
+
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
1071
|
+
*
|
|
1072
|
+
* @see {@link https://hono.dev/docs/api/context#env}
|
|
1073
|
+
*
|
|
1074
|
+
* @example
|
|
1075
|
+
* ```ts
|
|
1076
|
+
* // Environment object for Cloudflare Workers
|
|
1077
|
+
* app.get('*', async c => {
|
|
1078
|
+
* const counter = c.env.COUNTER
|
|
1079
|
+
* })
|
|
1080
|
+
* ```
|
|
1081
|
+
*/
|
|
1082
|
+
env = {};
|
|
1083
|
+
#var;
|
|
1084
|
+
finalized = false;
|
|
1085
|
+
/**
|
|
1086
|
+
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
1087
|
+
*
|
|
1088
|
+
* @see {@link https://hono.dev/docs/api/context#error}
|
|
1089
|
+
*
|
|
1090
|
+
* @example
|
|
1091
|
+
* ```ts
|
|
1092
|
+
* app.use('*', async (c, next) => {
|
|
1093
|
+
* await next()
|
|
1094
|
+
* if (c.error) {
|
|
1095
|
+
* // do something...
|
|
1096
|
+
* }
|
|
1097
|
+
* })
|
|
1098
|
+
* ```
|
|
1099
|
+
*/
|
|
1100
|
+
error;
|
|
1101
|
+
#status;
|
|
1102
|
+
#executionCtx;
|
|
1103
|
+
#res;
|
|
1104
|
+
#layout;
|
|
1105
|
+
#renderer;
|
|
1106
|
+
#notFoundHandler;
|
|
1107
|
+
#preparedHeaders;
|
|
1108
|
+
#matchResult;
|
|
1109
|
+
#path;
|
|
1110
|
+
/**
|
|
1111
|
+
* Creates an instance of the Context class.
|
|
1112
|
+
*
|
|
1113
|
+
* @param req - The Request object.
|
|
1114
|
+
* @param options - Optional configuration options for the context.
|
|
1115
|
+
*/
|
|
1116
|
+
constructor(req, options) {
|
|
1117
|
+
this.#rawRequest = req;
|
|
1118
|
+
if (options) {
|
|
1119
|
+
this.#executionCtx = options.executionCtx;
|
|
1120
|
+
this.env = options.env;
|
|
1121
|
+
this.#notFoundHandler = options.notFoundHandler;
|
|
1122
|
+
this.#path = options.path;
|
|
1123
|
+
this.#matchResult = options.matchResult;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* `.req` is the instance of {@link HonoRequest}.
|
|
1128
|
+
*/
|
|
1129
|
+
get req() {
|
|
1130
|
+
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
1131
|
+
return this.#req;
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* @see {@link https://hono.dev/docs/api/context#event}
|
|
1135
|
+
* The FetchEvent associated with the current request.
|
|
1136
|
+
*
|
|
1137
|
+
* @throws Will throw an error if the context does not have a FetchEvent.
|
|
1138
|
+
*/
|
|
1139
|
+
get event() {
|
|
1140
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) return this.#executionCtx;
|
|
1141
|
+
else throw Error("This context has no FetchEvent");
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* @see {@link https://hono.dev/docs/api/context#executionctx}
|
|
1145
|
+
* The ExecutionContext associated with the current request.
|
|
1146
|
+
*
|
|
1147
|
+
* @throws Will throw an error if the context does not have an ExecutionContext.
|
|
1148
|
+
*/
|
|
1149
|
+
get executionCtx() {
|
|
1150
|
+
if (this.#executionCtx) return this.#executionCtx;
|
|
1151
|
+
else throw Error("This context has no ExecutionContext");
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* @see {@link https://hono.dev/docs/api/context#res}
|
|
1155
|
+
* The Response object for the current request.
|
|
1156
|
+
*/
|
|
1157
|
+
get res() {
|
|
1158
|
+
return this.#res ||= createResponseInstance(null, { headers: this.#preparedHeaders ??= new Headers() });
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Sets the Response object for the current request.
|
|
1162
|
+
*
|
|
1163
|
+
* @param _res - The Response object to set.
|
|
1164
|
+
*/
|
|
1165
|
+
set res(_res) {
|
|
1166
|
+
if (this.#res && _res) {
|
|
1167
|
+
_res = createResponseInstance(_res.body, _res);
|
|
1168
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
1169
|
+
if (k === "content-type") continue;
|
|
1170
|
+
if (k === "set-cookie") {
|
|
1171
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
1172
|
+
_res.headers.delete("set-cookie");
|
|
1173
|
+
for (const cookie of cookies) _res.headers.append("set-cookie", cookie);
|
|
1174
|
+
} else _res.headers.set(k, v);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
this.#res = _res;
|
|
1178
|
+
this.finalized = true;
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* `.render()` can create a response within a layout.
|
|
1182
|
+
*
|
|
1183
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
1184
|
+
*
|
|
1185
|
+
* @example
|
|
1186
|
+
* ```ts
|
|
1187
|
+
* app.get('/', (c) => {
|
|
1188
|
+
* return c.render('Hello!')
|
|
1189
|
+
* })
|
|
1190
|
+
* ```
|
|
1191
|
+
*/
|
|
1192
|
+
render = (...args) => {
|
|
1193
|
+
this.#renderer ??= (content) => this.html(content);
|
|
1194
|
+
return this.#renderer(...args);
|
|
1195
|
+
};
|
|
1196
|
+
/**
|
|
1197
|
+
* Sets the layout for the response.
|
|
1198
|
+
*
|
|
1199
|
+
* @param layout - The layout to set.
|
|
1200
|
+
* @returns The layout function.
|
|
1201
|
+
*/
|
|
1202
|
+
setLayout = (layout) => this.#layout = layout;
|
|
1203
|
+
/**
|
|
1204
|
+
* Gets the current layout for the response.
|
|
1205
|
+
*
|
|
1206
|
+
* @returns The current layout function.
|
|
1207
|
+
*/
|
|
1208
|
+
getLayout = () => this.#layout;
|
|
1209
|
+
/**
|
|
1210
|
+
* `.setRenderer()` can set the layout in the custom middleware.
|
|
1211
|
+
*
|
|
1212
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
1213
|
+
*
|
|
1214
|
+
* @example
|
|
1215
|
+
* ```tsx
|
|
1216
|
+
* app.use('*', async (c, next) => {
|
|
1217
|
+
* c.setRenderer((content) => {
|
|
1218
|
+
* return c.html(
|
|
1219
|
+
* <html>
|
|
1220
|
+
* <body>
|
|
1221
|
+
* <p>{content}</p>
|
|
1222
|
+
* </body>
|
|
1223
|
+
* </html>
|
|
1224
|
+
* )
|
|
1225
|
+
* })
|
|
1226
|
+
* await next()
|
|
1227
|
+
* })
|
|
1228
|
+
* ```
|
|
1229
|
+
*/
|
|
1230
|
+
setRenderer = (renderer) => {
|
|
1231
|
+
this.#renderer = renderer;
|
|
1232
|
+
};
|
|
1233
|
+
/**
|
|
1234
|
+
* `.header()` can set headers.
|
|
1235
|
+
*
|
|
1236
|
+
* @see {@link https://hono.dev/docs/api/context#header}
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* ```ts
|
|
1240
|
+
* app.get('/welcome', (c) => {
|
|
1241
|
+
* // Set headers
|
|
1242
|
+
* c.header('X-Message', 'Hello!')
|
|
1243
|
+
* c.header('Content-Type', 'text/plain')
|
|
1244
|
+
*
|
|
1245
|
+
* // Append multiple headers using the append option (e.g. Vary)
|
|
1246
|
+
* c.header('Vary', 'Accept-Encoding', { append: true })
|
|
1247
|
+
* c.header('Vary', 'User-Agent', { append: true })
|
|
1248
|
+
*
|
|
1249
|
+
* return c.body('Thank you for coming')
|
|
1250
|
+
* })
|
|
1251
|
+
* ```
|
|
1252
|
+
*/
|
|
1253
|
+
header = (name, value, options) => {
|
|
1254
|
+
if (this.finalized) this.#res = createResponseInstance(this.#res.body, this.#res);
|
|
1255
|
+
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
1256
|
+
if (value === void 0) headers.delete(name);
|
|
1257
|
+
else if (options?.append) headers.append(name, value);
|
|
1258
|
+
else headers.set(name, value);
|
|
1259
|
+
};
|
|
1260
|
+
status = (status) => {
|
|
1261
|
+
this.#status = status;
|
|
1262
|
+
};
|
|
1263
|
+
/**
|
|
1264
|
+
* `.set()` can set the value specified by the key.
|
|
1265
|
+
*
|
|
1266
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* ```ts
|
|
1270
|
+
* app.use('*', async (c, next) => {
|
|
1271
|
+
* c.set('message', 'Hono is hot!!')
|
|
1272
|
+
* await next()
|
|
1273
|
+
* })
|
|
1274
|
+
* ```
|
|
1275
|
+
*/
|
|
1276
|
+
set = (key, value) => {
|
|
1277
|
+
this.#var ??= /* @__PURE__ */ new Map();
|
|
1278
|
+
this.#var.set(key, value);
|
|
1279
|
+
};
|
|
1280
|
+
/**
|
|
1281
|
+
* `.get()` can use the value specified by the key.
|
|
1282
|
+
*
|
|
1283
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
1284
|
+
*
|
|
1285
|
+
* @example
|
|
1286
|
+
* ```ts
|
|
1287
|
+
* app.get('/', (c) => {
|
|
1288
|
+
* const message = c.get('message')
|
|
1289
|
+
* return c.text(`The message is "${message}"`)
|
|
1290
|
+
* })
|
|
1291
|
+
* ```
|
|
1292
|
+
*/
|
|
1293
|
+
get = (key) => {
|
|
1294
|
+
return this.#var ? this.#var.get(key) : void 0;
|
|
1295
|
+
};
|
|
1296
|
+
/**
|
|
1297
|
+
* `.var` can access the value of a variable.
|
|
1298
|
+
*
|
|
1299
|
+
* @see {@link https://hono.dev/docs/api/context#var}
|
|
1300
|
+
*
|
|
1301
|
+
* @example
|
|
1302
|
+
* ```ts
|
|
1303
|
+
* const result = c.var.client.oneMethod()
|
|
1304
|
+
* ```
|
|
1305
|
+
*/
|
|
1306
|
+
get var() {
|
|
1307
|
+
if (!this.#var) return {};
|
|
1308
|
+
return Object.fromEntries(this.#var);
|
|
1309
|
+
}
|
|
1310
|
+
#newResponse(data, arg, headers) {
|
|
1311
|
+
let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
|
|
1312
|
+
if (typeof arg === "object" && arg.headers) {
|
|
1313
|
+
responseHeaders ??= new Headers();
|
|
1314
|
+
for (const [key, value] of new Headers(arg.headers)) if (key === "set-cookie") responseHeaders.append(key, value);
|
|
1315
|
+
else responseHeaders.set(key, value);
|
|
1316
|
+
}
|
|
1317
|
+
if (headers) {
|
|
1318
|
+
if (!responseHeaders) {
|
|
1319
|
+
let count = 0;
|
|
1320
|
+
for (const k in headers) if (++count > 1 || typeof headers[k] !== "string") {
|
|
1321
|
+
responseHeaders = new Headers();
|
|
1322
|
+
break;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
if (responseHeaders) for (const k in headers) {
|
|
1326
|
+
const v = headers[k];
|
|
1327
|
+
if (typeof v === "string") responseHeaders.set(k, v);
|
|
1328
|
+
else {
|
|
1329
|
+
responseHeaders.delete(k);
|
|
1330
|
+
for (const v2 of v) responseHeaders.append(k, v2);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
return createResponseInstance(data, {
|
|
1335
|
+
status: typeof arg === "number" ? arg : arg?.status ?? this.#status,
|
|
1336
|
+
headers: responseHeaders ?? headers
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
newResponse = (...args) => this.#newResponse(...args);
|
|
1340
|
+
/**
|
|
1341
|
+
* `.body()` can return the HTTP response.
|
|
1342
|
+
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
|
1343
|
+
* This can also be set in `.text()`, `.json()` and so on.
|
|
1344
|
+
*
|
|
1345
|
+
* @see {@link https://hono.dev/docs/api/context#body}
|
|
1346
|
+
*
|
|
1347
|
+
* @example
|
|
1348
|
+
* ```ts
|
|
1349
|
+
* app.get('/welcome', (c) => {
|
|
1350
|
+
* // Set headers
|
|
1351
|
+
* c.header('X-Message', 'Hello!')
|
|
1352
|
+
* c.header('Content-Type', 'text/plain')
|
|
1353
|
+
* // Set HTTP status code
|
|
1354
|
+
* c.status(201)
|
|
1355
|
+
*
|
|
1356
|
+
* // Return the response body
|
|
1357
|
+
* return c.body('Thank you for coming')
|
|
1358
|
+
* })
|
|
1359
|
+
* ```
|
|
1360
|
+
*/
|
|
1361
|
+
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
1362
|
+
/**
|
|
1363
|
+
* `.text()` can render text as `Content-Type:text/plain`.
|
|
1364
|
+
*
|
|
1365
|
+
* @see {@link https://hono.dev/docs/api/context#text}
|
|
1366
|
+
*
|
|
1367
|
+
* @example
|
|
1368
|
+
* ```ts
|
|
1369
|
+
* app.get('/say', (c) => {
|
|
1370
|
+
* return c.text('Hello!')
|
|
1371
|
+
* })
|
|
1372
|
+
* ```
|
|
1373
|
+
*/
|
|
1374
|
+
text = (text, arg, headers) => {
|
|
1375
|
+
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(text, arg, setDefaultContentType(TEXT_PLAIN, headers));
|
|
1376
|
+
};
|
|
1377
|
+
/**
|
|
1378
|
+
* `.json()` can render JSON as `Content-Type:application/json`.
|
|
1379
|
+
*
|
|
1380
|
+
* @see {@link https://hono.dev/docs/api/context#json}
|
|
1381
|
+
*
|
|
1382
|
+
* @example
|
|
1383
|
+
* ```ts
|
|
1384
|
+
* app.get('/api', (c) => {
|
|
1385
|
+
* return c.json({ message: 'Hello!' })
|
|
1386
|
+
* })
|
|
1387
|
+
* ```
|
|
1388
|
+
*/
|
|
1389
|
+
json = (object, arg, headers) => {
|
|
1390
|
+
return this.#newResponse(JSON.stringify(object), arg, setDefaultContentType("application/json", headers));
|
|
1391
|
+
};
|
|
1392
|
+
html = (html, arg, headers) => {
|
|
1393
|
+
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
1394
|
+
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
1395
|
+
};
|
|
1396
|
+
/**
|
|
1397
|
+
* `.redirect()` can Redirect, default status code is 302.
|
|
1398
|
+
*
|
|
1399
|
+
* @see {@link https://hono.dev/docs/api/context#redirect}
|
|
1400
|
+
*
|
|
1401
|
+
* @example
|
|
1402
|
+
* ```ts
|
|
1403
|
+
* app.get('/redirect', (c) => {
|
|
1404
|
+
* return c.redirect('/')
|
|
1405
|
+
* })
|
|
1406
|
+
* app.get('/redirect-permanently', (c) => {
|
|
1407
|
+
* return c.redirect('/', 301)
|
|
1408
|
+
* })
|
|
1409
|
+
* ```
|
|
1410
|
+
*/
|
|
1411
|
+
redirect = (location, status) => {
|
|
1412
|
+
const locationString = String(location);
|
|
1413
|
+
this.header("Location", !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString));
|
|
1414
|
+
return this.newResponse(null, status ?? 302);
|
|
1415
|
+
};
|
|
1416
|
+
/**
|
|
1417
|
+
* `.notFound()` can return the Not Found Response.
|
|
1418
|
+
*
|
|
1419
|
+
* @see {@link https://hono.dev/docs/api/context#notfound}
|
|
1420
|
+
*
|
|
1421
|
+
* @example
|
|
1422
|
+
* ```ts
|
|
1423
|
+
* app.get('/notfound', (c) => {
|
|
1424
|
+
* return c.notFound()
|
|
1425
|
+
* })
|
|
1426
|
+
* ```
|
|
1427
|
+
*/
|
|
1428
|
+
notFound = () => {
|
|
1429
|
+
this.#notFoundHandler ??= () => createResponseInstance();
|
|
1430
|
+
return this.#notFoundHandler(this);
|
|
1431
|
+
};
|
|
1432
|
+
};
|
|
1433
|
+
//#endregion
|
|
1434
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router.js
|
|
1435
|
+
var METHODS = [
|
|
1436
|
+
"get",
|
|
1437
|
+
"post",
|
|
1438
|
+
"put",
|
|
1439
|
+
"delete",
|
|
1440
|
+
"options",
|
|
1441
|
+
"patch",
|
|
1442
|
+
"query"
|
|
1443
|
+
];
|
|
1444
|
+
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
1445
|
+
var UnsupportedPathError = class extends Error {};
|
|
1446
|
+
//#endregion
|
|
1447
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/utils/constants.js
|
|
1448
|
+
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
1449
|
+
//#endregion
|
|
1450
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/hono-base.js
|
|
1451
|
+
var notFoundHandler = (c) => {
|
|
1452
|
+
return c.text("404 Not Found", 404);
|
|
1453
|
+
};
|
|
1454
|
+
var errorHandler = (err, c) => {
|
|
1455
|
+
if ("getResponse" in err) {
|
|
1456
|
+
const res = err.getResponse();
|
|
1457
|
+
return c.newResponse(res.body, res);
|
|
1458
|
+
}
|
|
1459
|
+
console.error(err);
|
|
1460
|
+
return c.text("Internal Server Error", 500);
|
|
1461
|
+
};
|
|
1462
|
+
var Hono$1 = class _Hono {
|
|
1463
|
+
get;
|
|
1464
|
+
post;
|
|
1465
|
+
put;
|
|
1466
|
+
delete;
|
|
1467
|
+
options;
|
|
1468
|
+
patch;
|
|
1469
|
+
query;
|
|
1470
|
+
all;
|
|
1471
|
+
on;
|
|
1472
|
+
use;
|
|
1473
|
+
router;
|
|
1474
|
+
getPath;
|
|
1475
|
+
_basePath = "/";
|
|
1476
|
+
#path = "/";
|
|
1477
|
+
routes = [];
|
|
1478
|
+
constructor(options = {}) {
|
|
1479
|
+
[...METHODS, "all"].forEach((method) => {
|
|
1480
|
+
this[method] = (args1, ...args) => {
|
|
1481
|
+
const methodName = method.toUpperCase();
|
|
1482
|
+
if (typeof args1 === "string") this.#path = args1;
|
|
1483
|
+
else this.#addRoute(methodName, this.#path, args1);
|
|
1484
|
+
args.forEach((handler) => {
|
|
1485
|
+
this.#addRoute(methodName, this.#path, handler);
|
|
1486
|
+
});
|
|
1487
|
+
return this;
|
|
1488
|
+
};
|
|
1489
|
+
});
|
|
1490
|
+
this.on = (method, path, ...handlers) => {
|
|
1491
|
+
for (const p of [path].flat()) {
|
|
1492
|
+
this.#path = p;
|
|
1493
|
+
for (const m of [method].flat()) {
|
|
1494
|
+
const methodName = m.toUpperCase();
|
|
1495
|
+
for (const handler of handlers) this.#addRoute(methodName, this.#path, handler);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return this;
|
|
1499
|
+
};
|
|
1500
|
+
this.use = (arg1, ...handlers) => {
|
|
1501
|
+
if (typeof arg1 === "string") this.#path = arg1;
|
|
1502
|
+
else {
|
|
1503
|
+
this.#path = "*";
|
|
1504
|
+
handlers.unshift(arg1);
|
|
1505
|
+
}
|
|
1506
|
+
handlers.forEach((handler) => {
|
|
1507
|
+
this.#addRoute("ALL", this.#path, handler);
|
|
1508
|
+
});
|
|
1509
|
+
return this;
|
|
1510
|
+
};
|
|
1511
|
+
const { strict, ...optionsWithoutStrict } = options;
|
|
1512
|
+
Object.assign(this, optionsWithoutStrict);
|
|
1513
|
+
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
1514
|
+
}
|
|
1515
|
+
#clone() {
|
|
1516
|
+
const clone = new _Hono({
|
|
1517
|
+
router: this.router,
|
|
1518
|
+
getPath: this.getPath
|
|
1519
|
+
});
|
|
1520
|
+
clone.errorHandler = this.errorHandler;
|
|
1521
|
+
clone.#notFoundHandler = this.#notFoundHandler;
|
|
1522
|
+
clone.routes = this.routes;
|
|
1523
|
+
return clone;
|
|
1524
|
+
}
|
|
1525
|
+
#notFoundHandler = notFoundHandler;
|
|
1526
|
+
errorHandler = errorHandler;
|
|
1527
|
+
/**
|
|
1528
|
+
* `.route()` allows grouping other Hono instance in routes.
|
|
1529
|
+
*
|
|
1530
|
+
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
|
1531
|
+
*
|
|
1532
|
+
* @param {string} path - base Path
|
|
1533
|
+
* @param {Hono} app - other Hono instance
|
|
1534
|
+
* @returns {Hono} routed Hono instance
|
|
1535
|
+
*
|
|
1536
|
+
* @example
|
|
1537
|
+
* ```ts
|
|
1538
|
+
* const app = new Hono()
|
|
1539
|
+
* const app2 = new Hono()
|
|
1540
|
+
*
|
|
1541
|
+
* app2.get("/user", (c) => c.text("user"))
|
|
1542
|
+
* app.route("/api", app2) // GET /api/user
|
|
1543
|
+
* ```
|
|
1544
|
+
*/
|
|
1545
|
+
route(path, app) {
|
|
1546
|
+
const subApp = this.basePath(path);
|
|
1547
|
+
app.routes.map((r) => {
|
|
1548
|
+
let handler;
|
|
1549
|
+
if (app.errorHandler === errorHandler) handler = r.handler;
|
|
1550
|
+
else {
|
|
1551
|
+
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
1552
|
+
handler[COMPOSED_HANDLER] = r.handler;
|
|
1553
|
+
}
|
|
1554
|
+
subApp.#addRoute(r.method, r.path, handler, r.basePath);
|
|
1555
|
+
});
|
|
1556
|
+
return this;
|
|
1557
|
+
}
|
|
1558
|
+
/**
|
|
1559
|
+
* `.basePath()` allows base paths to be specified.
|
|
1560
|
+
*
|
|
1561
|
+
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
|
1562
|
+
*
|
|
1563
|
+
* @param {string} path - base Path
|
|
1564
|
+
* @returns {Hono} changed Hono instance
|
|
1565
|
+
*
|
|
1566
|
+
* @example
|
|
1567
|
+
* ```ts
|
|
1568
|
+
* const api = new Hono().basePath('/api')
|
|
1569
|
+
* ```
|
|
1570
|
+
*/
|
|
1571
|
+
basePath(path) {
|
|
1572
|
+
const subApp = this.#clone();
|
|
1573
|
+
subApp._basePath = mergePath(this._basePath, path);
|
|
1574
|
+
return subApp;
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* `.onError()` handles an error and returns a customized Response.
|
|
1578
|
+
*
|
|
1579
|
+
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
1580
|
+
*
|
|
1581
|
+
* @param {ErrorHandler} handler - request Handler for error
|
|
1582
|
+
* @returns {Hono} changed Hono instance
|
|
1583
|
+
*
|
|
1584
|
+
* @example
|
|
1585
|
+
* ```ts
|
|
1586
|
+
* app.onError((err, c) => {
|
|
1587
|
+
* console.error(`${err}`)
|
|
1588
|
+
* return c.text('Custom Error Message', 500)
|
|
1589
|
+
* })
|
|
1590
|
+
* ```
|
|
1591
|
+
*/
|
|
1592
|
+
onError = (handler) => {
|
|
1593
|
+
this.errorHandler = handler;
|
|
1594
|
+
return this;
|
|
1595
|
+
};
|
|
1596
|
+
/**
|
|
1597
|
+
* `.notFound()` allows you to customize a Not Found Response.
|
|
1598
|
+
*
|
|
1599
|
+
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
1600
|
+
*
|
|
1601
|
+
* @param {NotFoundHandler} handler - request handler for not-found
|
|
1602
|
+
* @returns {Hono} changed Hono instance
|
|
1603
|
+
*
|
|
1604
|
+
* @example
|
|
1605
|
+
* ```ts
|
|
1606
|
+
* app.notFound((c) => {
|
|
1607
|
+
* return c.text('Custom 404 Message', 404)
|
|
1608
|
+
* })
|
|
1609
|
+
* ```
|
|
1610
|
+
*/
|
|
1611
|
+
notFound = (handler) => {
|
|
1612
|
+
this.#notFoundHandler = handler;
|
|
1613
|
+
return this;
|
|
1614
|
+
};
|
|
1615
|
+
/**
|
|
1616
|
+
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
|
1617
|
+
*
|
|
1618
|
+
* @see {@link https://hono.dev/docs/api/hono#mount}
|
|
1619
|
+
*
|
|
1620
|
+
* @param {string} path - base Path
|
|
1621
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
1622
|
+
* @param {MountOptions} [options] - options of `.mount()`
|
|
1623
|
+
* @returns {Hono} mounted Hono instance
|
|
1624
|
+
*
|
|
1625
|
+
* @example
|
|
1626
|
+
* ```ts
|
|
1627
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
1628
|
+
* import { Hono } from 'hono'
|
|
1629
|
+
* // Create itty-router application
|
|
1630
|
+
* const ittyRouter = IttyRouter()
|
|
1631
|
+
* // GET /itty-router/hello
|
|
1632
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
1633
|
+
*
|
|
1634
|
+
* const app = new Hono()
|
|
1635
|
+
* app.mount('/itty-router', ittyRouter.handle)
|
|
1636
|
+
* ```
|
|
1637
|
+
*
|
|
1638
|
+
* @example
|
|
1639
|
+
* ```ts
|
|
1640
|
+
* const app = new Hono()
|
|
1641
|
+
* // Send the request to another application without modification.
|
|
1642
|
+
* app.mount('/app', anotherApp, {
|
|
1643
|
+
* replaceRequest: (req) => req,
|
|
1644
|
+
* })
|
|
1645
|
+
* ```
|
|
1646
|
+
*/
|
|
1647
|
+
mount(path, applicationHandler, options) {
|
|
1648
|
+
let replaceRequest;
|
|
1649
|
+
let optionHandler;
|
|
1650
|
+
if (options) {
|
|
1651
|
+
if (typeof options === "function") optionHandler = options;
|
|
1652
|
+
else {
|
|
1653
|
+
optionHandler = options.optionHandler;
|
|
1654
|
+
if (options.replaceRequest === false) replaceRequest = (request) => request;
|
|
1655
|
+
else replaceRequest = options.replaceRequest;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
const getOptions = optionHandler ? (c) => {
|
|
1659
|
+
const options2 = optionHandler(c);
|
|
1660
|
+
return Array.isArray(options2) ? options2 : [options2];
|
|
1661
|
+
} : (c) => {
|
|
1662
|
+
let executionContext = void 0;
|
|
1663
|
+
try {
|
|
1664
|
+
executionContext = c.executionCtx;
|
|
1665
|
+
} catch {}
|
|
1666
|
+
return [c.env, executionContext];
|
|
1667
|
+
};
|
|
1668
|
+
replaceRequest ||= (() => {
|
|
1669
|
+
const mergedPath = mergePath(this._basePath, path);
|
|
1670
|
+
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
1671
|
+
return (request) => {
|
|
1672
|
+
const url = new URL(request.url);
|
|
1673
|
+
url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
|
|
1674
|
+
return new Request(url, request);
|
|
1675
|
+
};
|
|
1676
|
+
})();
|
|
1677
|
+
const handler = async (c, next) => {
|
|
1678
|
+
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
1679
|
+
if (res) return res;
|
|
1680
|
+
await next();
|
|
1681
|
+
};
|
|
1682
|
+
this.#addRoute("ALL", mergePath(path, "*"), handler);
|
|
1683
|
+
return this;
|
|
1684
|
+
}
|
|
1685
|
+
#addRoute(method, path, handler, baseRoutePath) {
|
|
1686
|
+
path = mergePath(this._basePath, path);
|
|
1687
|
+
const r = {
|
|
1688
|
+
basePath: baseRoutePath !== void 0 ? mergePath(this._basePath, baseRoutePath) : this._basePath,
|
|
1689
|
+
path,
|
|
1690
|
+
method,
|
|
1691
|
+
handler
|
|
1692
|
+
};
|
|
1693
|
+
this.router.add(method, path, [handler, r]);
|
|
1694
|
+
this.routes.push(r);
|
|
1695
|
+
}
|
|
1696
|
+
#handleError(err, c) {
|
|
1697
|
+
if (err instanceof Error) return this.errorHandler(err, c);
|
|
1698
|
+
throw err;
|
|
1699
|
+
}
|
|
1700
|
+
#dispatch(request, executionCtx, env, method) {
|
|
1701
|
+
if (method === "HEAD") return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
1702
|
+
const path = this.getPath(request, { env });
|
|
1703
|
+
const matchResult = this.router.match(method, path);
|
|
1704
|
+
const c = new Context(request, {
|
|
1705
|
+
path,
|
|
1706
|
+
matchResult,
|
|
1707
|
+
env,
|
|
1708
|
+
executionCtx,
|
|
1709
|
+
notFoundHandler: this.#notFoundHandler
|
|
1710
|
+
});
|
|
1711
|
+
if (matchResult[0].length === 1) {
|
|
1712
|
+
let res;
|
|
1713
|
+
try {
|
|
1714
|
+
res = matchResult[0][0][0][0](c, async () => {
|
|
1715
|
+
c.res = await this.#notFoundHandler(c);
|
|
1716
|
+
});
|
|
1717
|
+
} catch (err) {
|
|
1718
|
+
return this.#handleError(err, c);
|
|
1719
|
+
}
|
|
1720
|
+
return res instanceof Promise ? res.then((resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
1721
|
+
}
|
|
1722
|
+
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
1723
|
+
return (async () => {
|
|
1724
|
+
try {
|
|
1725
|
+
const context = await composed(c);
|
|
1726
|
+
if (!context.finalized) throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
1727
|
+
return context.res;
|
|
1728
|
+
} catch (err) {
|
|
1729
|
+
return this.#handleError(err, c);
|
|
1730
|
+
}
|
|
1731
|
+
})();
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* `.fetch()` will be entry point of your app.
|
|
1735
|
+
*
|
|
1736
|
+
* @see {@link https://hono.dev/docs/api/hono#fetch}
|
|
1737
|
+
*
|
|
1738
|
+
* @param {Request} request - request Object of request
|
|
1739
|
+
* @param {Env} env - env Object
|
|
1740
|
+
* @param {ExecutionContext} executionCtx - context of execution
|
|
1741
|
+
* @returns {Response | Promise<Response>} response of request
|
|
1742
|
+
*
|
|
1743
|
+
*/
|
|
1744
|
+
fetch = (request, ...rest) => {
|
|
1745
|
+
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
1746
|
+
};
|
|
1747
|
+
/**
|
|
1748
|
+
* `.request()` is a useful method for testing.
|
|
1749
|
+
* You can pass a URL or pathname to send a GET request.
|
|
1750
|
+
* app will return a Response object.
|
|
1751
|
+
* ```ts
|
|
1752
|
+
* test('GET /hello is ok', async () => {
|
|
1753
|
+
* const res = await app.request('/hello')
|
|
1754
|
+
* expect(res.status).toBe(200)
|
|
1755
|
+
* })
|
|
1756
|
+
* ```
|
|
1757
|
+
* @see https://hono.dev/docs/api/hono#request
|
|
1758
|
+
*/
|
|
1759
|
+
request = (input, requestInit, Env, executionCtx) => {
|
|
1760
|
+
if (input instanceof Request) return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
1761
|
+
input = input.toString();
|
|
1762
|
+
return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
|
|
1763
|
+
};
|
|
1764
|
+
/**
|
|
1765
|
+
* `.fire()` automatically adds a global fetch event listener.
|
|
1766
|
+
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
|
1767
|
+
* @deprecated
|
|
1768
|
+
* Use `fire` from `hono/service-worker` instead.
|
|
1769
|
+
* ```ts
|
|
1770
|
+
* import { Hono } from 'hono'
|
|
1771
|
+
* import { fire } from 'hono/service-worker'
|
|
1772
|
+
*
|
|
1773
|
+
* const app = new Hono()
|
|
1774
|
+
* // ...
|
|
1775
|
+
* fire(app)
|
|
1776
|
+
* ```
|
|
1777
|
+
* @see https://hono.dev/docs/api/hono#fire
|
|
1778
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
1779
|
+
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
|
1780
|
+
*/
|
|
1781
|
+
fire = () => {
|
|
1782
|
+
addEventListener("fetch", (event) => {
|
|
1783
|
+
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
1784
|
+
});
|
|
1785
|
+
};
|
|
1786
|
+
};
|
|
1787
|
+
//#endregion
|
|
1788
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/utils.js
|
|
1789
|
+
var createNullObject = () => /* @__PURE__ */ Object.create(null);
|
|
1790
|
+
//#endregion
|
|
1791
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
1792
|
+
var emptyParam = [];
|
|
1793
|
+
function match(method, path) {
|
|
1794
|
+
const matchers = this.buildAllMatchers();
|
|
1795
|
+
const match2 = ((method2, path2) => {
|
|
1796
|
+
const matcher = matchers[method2] || matchers["ALL"];
|
|
1797
|
+
const staticMatch = matcher[2][path2];
|
|
1798
|
+
if (staticMatch) return staticMatch;
|
|
1799
|
+
const match3 = path2.match(matcher[0]);
|
|
1800
|
+
if (!match3) return [[], emptyParam];
|
|
1801
|
+
const index = match3.indexOf("", 1);
|
|
1802
|
+
return [matcher[1][index], match3];
|
|
1803
|
+
});
|
|
1804
|
+
this.match = match2;
|
|
1805
|
+
return match2(method, path);
|
|
1806
|
+
}
|
|
1807
|
+
//#endregion
|
|
1808
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
1809
|
+
var LABEL_REG_EXP_STR = "[^/]+";
|
|
1810
|
+
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
1811
|
+
var PATH_ERROR = /* @__PURE__ */ Symbol();
|
|
1812
|
+
var regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
|
|
1813
|
+
function compareKey(a, b) {
|
|
1814
|
+
if (a.length === 1) return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
1815
|
+
if (b.length === 1) return 1;
|
|
1816
|
+
if (a === ".*" || a === "(?:|/.*)") return b === "(?:|/.*)" ? -1 : 1;
|
|
1817
|
+
else if (b === ".*" || b === "(?:|/.*)") return -1;
|
|
1818
|
+
if (a === "[^/]+") return 1;
|
|
1819
|
+
else if (b === "[^/]+") return -1;
|
|
1820
|
+
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
1821
|
+
}
|
|
1822
|
+
var Node$1 = class _Node {
|
|
1823
|
+
#index;
|
|
1824
|
+
#varIndex;
|
|
1825
|
+
#children = createNullObject();
|
|
1826
|
+
insert(tokens, index, paramMap, context, isStatic) {
|
|
1827
|
+
let node = this;
|
|
1828
|
+
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
1829
|
+
const token = tokens[i];
|
|
1830
|
+
const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? [
|
|
1831
|
+
"",
|
|
1832
|
+
"",
|
|
1833
|
+
".*"
|
|
1834
|
+
] : [
|
|
1835
|
+
"",
|
|
1836
|
+
"",
|
|
1837
|
+
LABEL_REG_EXP_STR
|
|
1838
|
+
] : null : token === "/*" ? [
|
|
1839
|
+
"",
|
|
1840
|
+
"",
|
|
1841
|
+
TAIL_WILDCARD_REG_EXP_STR
|
|
1842
|
+
] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1843
|
+
let nextNode;
|
|
1844
|
+
if (pattern) {
|
|
1845
|
+
const name = pattern[1];
|
|
1846
|
+
let regexpStr = pattern[2] || "[^/]+";
|
|
1847
|
+
if (name && pattern[2]) {
|
|
1848
|
+
if (regexpStr === ".*") throw PATH_ERROR;
|
|
1849
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
1850
|
+
if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
|
|
1851
|
+
if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) throw PATH_ERROR;
|
|
1852
|
+
}
|
|
1853
|
+
nextNode = node.#children[regexpStr];
|
|
1854
|
+
if (!nextNode) {
|
|
1855
|
+
if (regexpStr !== ".*" && regexpStr !== "(?:|/.*)") {
|
|
1856
|
+
for (const k in node.#children) if ((regexpStr.length > 1 || k.length > 1) && k !== ".*" && k !== "(?:|/.*)") throw PATH_ERROR;
|
|
1857
|
+
}
|
|
1858
|
+
nextNode = node.#children[regexpStr] = new _Node();
|
|
1859
|
+
}
|
|
1860
|
+
if (name !== "") {
|
|
1861
|
+
nextNode.#varIndex ??= context.varIndex++;
|
|
1862
|
+
paramMap.push([name, nextNode.#varIndex]);
|
|
1863
|
+
}
|
|
1864
|
+
} else {
|
|
1865
|
+
nextNode = node.#children[token];
|
|
1866
|
+
if (!nextNode) {
|
|
1867
|
+
for (const k in node.#children) if (k.length > 1 && k !== ".*" && k !== "(?:|/.*)") throw PATH_ERROR;
|
|
1868
|
+
nextNode = node.#children[token] = new _Node();
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
node = nextNode;
|
|
1872
|
+
}
|
|
1873
|
+
if (node.#index !== void 0) throw PATH_ERROR;
|
|
1874
|
+
node.#index = isStatic ? -1 : index;
|
|
1875
|
+
}
|
|
1876
|
+
buildRegExpStr() {
|
|
1877
|
+
const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
|
|
1878
|
+
const c = this.#children[k];
|
|
1879
|
+
const childStr = c.buildRegExpStr();
|
|
1880
|
+
return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
|
|
1881
|
+
}).filter(Boolean);
|
|
1882
|
+
if (typeof this.#index === "number" && this.#index !== -1) strList.unshift(`#${this.#index}`);
|
|
1883
|
+
if (strList.length === 0) return "";
|
|
1884
|
+
if (strList.length === 1) return strList[0];
|
|
1885
|
+
return "(?:" + strList.join("|") + ")";
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
//#endregion
|
|
1889
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
1890
|
+
var Trie = class {
|
|
1891
|
+
#context = { varIndex: 0 };
|
|
1892
|
+
#root = new Node$1();
|
|
1893
|
+
#index = 0;
|
|
1894
|
+
paths = createNullObject();
|
|
1895
|
+
insert(path, isStatic) {
|
|
1896
|
+
if (isStatic) {
|
|
1897
|
+
this.#root.insert(path.split(""), 0, [], this.#context, true);
|
|
1898
|
+
return;
|
|
1899
|
+
}
|
|
1900
|
+
const paramAssoc = [];
|
|
1901
|
+
const groups = [];
|
|
1902
|
+
let markedPath = path;
|
|
1903
|
+
for (let i = 0;;) {
|
|
1904
|
+
let replaced = false;
|
|
1905
|
+
markedPath = markedPath.replace(/\{[^}]+\}/g, (m) => {
|
|
1906
|
+
const mark = `@\\${i}`;
|
|
1907
|
+
groups[i] = [mark, m];
|
|
1908
|
+
i++;
|
|
1909
|
+
replaced = true;
|
|
1910
|
+
return mark;
|
|
1911
|
+
});
|
|
1912
|
+
if (!replaced) break;
|
|
1913
|
+
}
|
|
1914
|
+
const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
1915
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
1916
|
+
const [mark] = groups[i];
|
|
1917
|
+
for (let j = tokens.length - 1; j >= 0; j--) if (tokens[j].indexOf(mark) !== -1) {
|
|
1918
|
+
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
1919
|
+
break;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
this.#root.insert(tokens, this.#index, paramAssoc, this.#context, false);
|
|
1923
|
+
this.paths[path] = [this.#index++, paramAssoc];
|
|
1924
|
+
}
|
|
1925
|
+
buildRegExp() {
|
|
1926
|
+
let regexp = this.#root.buildRegExpStr();
|
|
1927
|
+
if (regexp === "") return [
|
|
1928
|
+
/^$/,
|
|
1929
|
+
[],
|
|
1930
|
+
[]
|
|
1931
|
+
];
|
|
1932
|
+
let captureIndex = 0;
|
|
1933
|
+
const indexReplacementMap = [];
|
|
1934
|
+
const paramReplacementMap = [];
|
|
1935
|
+
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
1936
|
+
if (handlerIndex !== void 0) {
|
|
1937
|
+
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
1938
|
+
return "$()";
|
|
1939
|
+
}
|
|
1940
|
+
if (paramIndex !== void 0) {
|
|
1941
|
+
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
1942
|
+
return "";
|
|
1943
|
+
}
|
|
1944
|
+
return "";
|
|
1945
|
+
});
|
|
1946
|
+
return [
|
|
1947
|
+
new RegExp(`^${regexp}`),
|
|
1948
|
+
indexReplacementMap,
|
|
1949
|
+
paramReplacementMap
|
|
1950
|
+
];
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
//#endregion
|
|
1954
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
1955
|
+
var wildcardRegExpCache = createNullObject();
|
|
1956
|
+
function buildWildcardRegExp(path) {
|
|
1957
|
+
return wildcardRegExpCache[path] ??= new RegExp(`^${path.replace(/\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g, (match2, metaChar) => metaChar ? `\\${metaChar}` : match2 === "/*" ? TAIL_WILDCARD_REG_EXP_STR : match2 === "*" ? ".*" : `/:${LABEL_REG_EXP_STR}`)}$`);
|
|
1958
|
+
}
|
|
1959
|
+
function findMiddleware(middleware, path) {
|
|
1960
|
+
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) if (buildWildcardRegExp(k).test(path)) return [...middleware[k]];
|
|
1961
|
+
}
|
|
1962
|
+
var RegExpRouter = class {
|
|
1963
|
+
name = "RegExpRouter";
|
|
1964
|
+
#middleware;
|
|
1965
|
+
#routes;
|
|
1966
|
+
#tries;
|
|
1967
|
+
constructor() {
|
|
1968
|
+
this.#middleware = { ["ALL"]: createNullObject() };
|
|
1969
|
+
this.#routes = { ["ALL"]: createNullObject() };
|
|
1970
|
+
this.#tries = { ["ALL"]: new Trie() };
|
|
1971
|
+
}
|
|
1972
|
+
#insertPath(method, path) {
|
|
1973
|
+
try {
|
|
1974
|
+
this.#tries[method].insert(path, !/\*|\/:/.test(path));
|
|
1975
|
+
} catch (e) {
|
|
1976
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
add(method, path, handler) {
|
|
1980
|
+
const middleware = this.#middleware;
|
|
1981
|
+
const routes = this.#routes;
|
|
1982
|
+
if (!middleware) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1983
|
+
if (!middleware[method]) {
|
|
1984
|
+
this.#tries[method] = new Trie();
|
|
1985
|
+
for (const handlerMap of [middleware, routes]) {
|
|
1986
|
+
handlerMap[method] = createNullObject();
|
|
1987
|
+
for (const p in handlerMap["ALL"]) {
|
|
1988
|
+
handlerMap[method][p] = [...handlerMap["ALL"][p]];
|
|
1989
|
+
this.#insertPath(method, p);
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
if (path === "/*") path = "*";
|
|
1994
|
+
const methods = method === "ALL" ? Object.keys(middleware) : [method];
|
|
1995
|
+
if (/\*$/.test(path)) {
|
|
1996
|
+
const re = buildWildcardRegExp(path);
|
|
1997
|
+
for (const m of methods) if (!middleware[m][path]) {
|
|
1998
|
+
this.#insertPath(m, path);
|
|
1999
|
+
middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware["ALL"], path) || [];
|
|
2000
|
+
}
|
|
2001
|
+
for (const handlerMap of [middleware, routes]) for (const m of methods) for (const p in handlerMap[m]) re.test(p) && handlerMap[m][p].push([handler, path]);
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
const paths = checkOptionalParameter(path) || [path];
|
|
2005
|
+
for (const path2 of paths) for (const m of methods) {
|
|
2006
|
+
if (!routes[m][path2]) {
|
|
2007
|
+
this.#insertPath(m, path2);
|
|
2008
|
+
routes[m][path2] = findMiddleware(middleware[m], path2) || findMiddleware(middleware["ALL"], path2) || [];
|
|
2009
|
+
}
|
|
2010
|
+
routes[m][path2].push([handler, path2]);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
match = match;
|
|
2014
|
+
buildAllMatchers() {
|
|
2015
|
+
const matchers = createNullObject();
|
|
2016
|
+
for (const method of Object.keys(this.#routes)) matchers[method] = this.#buildMatcher(method);
|
|
2017
|
+
this.#middleware = this.#routes = this.#tries = void 0;
|
|
2018
|
+
wildcardRegExpCache = createNullObject();
|
|
2019
|
+
return matchers;
|
|
2020
|
+
}
|
|
2021
|
+
#buildMatcher(method) {
|
|
2022
|
+
const middleware = this.#middleware[method];
|
|
2023
|
+
const routes = this.#routes[method];
|
|
2024
|
+
const trie = this.#tries[method];
|
|
2025
|
+
const staticMap = createNullObject();
|
|
2026
|
+
const handlerData = [];
|
|
2027
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
2028
|
+
for (const r of [middleware, routes]) for (const path in r) {
|
|
2029
|
+
const handlers = r[path];
|
|
2030
|
+
const pathData = trie.paths[path];
|
|
2031
|
+
if (!pathData) {
|
|
2032
|
+
staticMap[path] = [handlers.map(([h]) => [h, createNullObject()]), emptyParam];
|
|
2033
|
+
continue;
|
|
2034
|
+
}
|
|
2035
|
+
handlerData[pathData[0]] = handlers.map(([h, handlerPath]) => [h, trie.paths[handlerPath][1].reduceRight((map, [key], i) => {
|
|
2036
|
+
map[key] = paramReplacementMap[pathData[1][i][1]];
|
|
2037
|
+
return map;
|
|
2038
|
+
}, createNullObject())]);
|
|
2039
|
+
}
|
|
2040
|
+
return [
|
|
2041
|
+
regexp,
|
|
2042
|
+
indexReplacementMap.map((i) => handlerData[i]),
|
|
2043
|
+
staticMap
|
|
2044
|
+
];
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
//#endregion
|
|
2048
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/smart-router/router.js
|
|
2049
|
+
var SmartRouter = class {
|
|
2050
|
+
name = "SmartRouter";
|
|
2051
|
+
#routers = [];
|
|
2052
|
+
#routes = [];
|
|
2053
|
+
constructor(init) {
|
|
2054
|
+
this.#routers = init.routers;
|
|
2055
|
+
}
|
|
2056
|
+
add(method, path, handler) {
|
|
2057
|
+
if (!this.#routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
2058
|
+
this.#routes.push([
|
|
2059
|
+
method,
|
|
2060
|
+
path,
|
|
2061
|
+
handler
|
|
2062
|
+
]);
|
|
2063
|
+
}
|
|
2064
|
+
match(method, path) {
|
|
2065
|
+
if (!this.#routes) throw new Error("Fatal error");
|
|
2066
|
+
const routers = this.#routers;
|
|
2067
|
+
const routes = this.#routes;
|
|
2068
|
+
const len = routers.length;
|
|
2069
|
+
let i = 0;
|
|
2070
|
+
let res;
|
|
2071
|
+
for (; i < len; i++) {
|
|
2072
|
+
const router = routers[i];
|
|
2073
|
+
try {
|
|
2074
|
+
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) router.add(...routes[i2]);
|
|
2075
|
+
res = router.match(method, path);
|
|
2076
|
+
} catch (e) {
|
|
2077
|
+
if (e instanceof UnsupportedPathError) continue;
|
|
2078
|
+
throw e;
|
|
2079
|
+
}
|
|
2080
|
+
this.match = router.match.bind(router);
|
|
2081
|
+
this.#routers = [router];
|
|
2082
|
+
this.#routes = void 0;
|
|
2083
|
+
break;
|
|
2084
|
+
}
|
|
2085
|
+
if (i === len) throw new Error("Fatal error");
|
|
2086
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
2087
|
+
return res;
|
|
2088
|
+
}
|
|
2089
|
+
get activeRouter() {
|
|
2090
|
+
if (this.#routes || this.#routers.length !== 1) throw new Error("No active router has been determined yet.");
|
|
2091
|
+
return this.#routers[0];
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
//#endregion
|
|
2095
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/trie-router/node.js
|
|
2096
|
+
var emptyParams = createNullObject();
|
|
2097
|
+
var order = 0;
|
|
2098
|
+
var Node = class _Node {
|
|
2099
|
+
#methods = [];
|
|
2100
|
+
#children = createNullObject();
|
|
2101
|
+
#patterns = [];
|
|
2102
|
+
#pattern;
|
|
2103
|
+
#params = emptyParams;
|
|
2104
|
+
insert(method, path, handler) {
|
|
2105
|
+
let curNode = this;
|
|
2106
|
+
const parts = splitRoutingPath(path);
|
|
2107
|
+
const possibleKeys = /* @__PURE__ */ new Set();
|
|
2108
|
+
let i = 0;
|
|
2109
|
+
for (const p of parts) {
|
|
2110
|
+
const nextP = parts[++i];
|
|
2111
|
+
const pattern = getPattern(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
|
|
2112
|
+
const isParam = Array.isArray(pattern);
|
|
2113
|
+
const key = isParam ? pattern[0] : pattern || p;
|
|
2114
|
+
const child = curNode.#children[key] ||= new _Node();
|
|
2115
|
+
if (pattern && !child.#pattern) {
|
|
2116
|
+
child.#pattern = pattern;
|
|
2117
|
+
curNode.#patterns.push(child);
|
|
2118
|
+
}
|
|
2119
|
+
curNode = child;
|
|
2120
|
+
if (isParam) possibleKeys.add(pattern[1]);
|
|
2121
|
+
}
|
|
2122
|
+
curNode.#methods.push({ [method]: {
|
|
2123
|
+
handler,
|
|
2124
|
+
possibleKeys: [...possibleKeys],
|
|
2125
|
+
score: ++order
|
|
2126
|
+
} });
|
|
2127
|
+
}
|
|
2128
|
+
#pushHandlerSets(handlerSets, node, method, nodeParams, params) {
|
|
2129
|
+
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
2130
|
+
const m = node.#methods[i];
|
|
2131
|
+
const handlerSet = m[method] || m["ALL"];
|
|
2132
|
+
if (handlerSet) {
|
|
2133
|
+
handlerSet.params = createNullObject();
|
|
2134
|
+
handlerSets.push(handlerSet);
|
|
2135
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
2136
|
+
const key = handlerSet.possibleKeys[i2];
|
|
2137
|
+
handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
search(method, path) {
|
|
2143
|
+
const handlerSets = [];
|
|
2144
|
+
this.#params = emptyParams;
|
|
2145
|
+
let curNodes = [this];
|
|
2146
|
+
const parts = splitPath(path);
|
|
2147
|
+
const curNodesQueue = [];
|
|
2148
|
+
const len = parts.length;
|
|
2149
|
+
let partOffsets = null;
|
|
2150
|
+
for (let i = 0; i < len; i++) {
|
|
2151
|
+
const part = parts[i];
|
|
2152
|
+
const isLast = i === len - 1;
|
|
2153
|
+
const tempNodes = [];
|
|
2154
|
+
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
2155
|
+
const node = curNodes[j];
|
|
2156
|
+
const nextNode = node.#children[part];
|
|
2157
|
+
if (nextNode) {
|
|
2158
|
+
nextNode.#params = node.#params;
|
|
2159
|
+
if (isLast) {
|
|
2160
|
+
if (nextNode.#children["*"]) this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
|
|
2161
|
+
this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
|
|
2162
|
+
} else tempNodes.push(nextNode);
|
|
2163
|
+
}
|
|
2164
|
+
for (const child of node.#patterns) {
|
|
2165
|
+
const pattern = child.#pattern;
|
|
2166
|
+
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
2167
|
+
if (typeof pattern === "string") {
|
|
2168
|
+
if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
|
|
2169
|
+
this.#pushHandlerSets(handlerSets, child, method, node.#params);
|
|
2170
|
+
if (pattern === "*") {
|
|
2171
|
+
child.#params = params;
|
|
2172
|
+
tempNodes.push(child);
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
continue;
|
|
2176
|
+
}
|
|
2177
|
+
const [, name, matcher] = pattern;
|
|
2178
|
+
if (!part && matcher === true) continue;
|
|
2179
|
+
if (matcher !== true) {
|
|
2180
|
+
if (!partOffsets) {
|
|
2181
|
+
partOffsets = [];
|
|
2182
|
+
let offset = path[0] === "/" ? 1 : 0;
|
|
2183
|
+
for (let p = 0; p < len; p++) {
|
|
2184
|
+
partOffsets[p] = offset;
|
|
2185
|
+
offset += parts[p].length + 1;
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
const restPathString = path.slice(partOffsets[i]);
|
|
2189
|
+
const m = matcher.exec(restPathString);
|
|
2190
|
+
if (m) {
|
|
2191
|
+
params[name] = m[0];
|
|
2192
|
+
this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
|
|
2193
|
+
if (m[0].length === restPathString.length && child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
|
|
2194
|
+
for (const _ in child.#children) {
|
|
2195
|
+
child.#params = params;
|
|
2196
|
+
const componentCount = m[0].match(/\//g)?.length ?? 0;
|
|
2197
|
+
(curNodesQueue[componentCount] ||= []).push(child);
|
|
2198
|
+
break;
|
|
2199
|
+
}
|
|
2200
|
+
continue;
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
if (matcher === true || matcher.test(part)) {
|
|
2204
|
+
params[name] = part;
|
|
2205
|
+
if (isLast) {
|
|
2206
|
+
this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
|
|
2207
|
+
if (child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
|
|
2208
|
+
} else {
|
|
2209
|
+
child.#params = params;
|
|
2210
|
+
tempNodes.push(child);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
const shifted = curNodesQueue.shift();
|
|
2216
|
+
curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
|
|
2217
|
+
}
|
|
2218
|
+
if (handlerSets[1]) handlerSets.sort((a, b) => {
|
|
2219
|
+
return a.score - b.score;
|
|
2220
|
+
});
|
|
2221
|
+
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
2222
|
+
}
|
|
2223
|
+
};
|
|
2224
|
+
//#endregion
|
|
2225
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/trie-router/router.js
|
|
2226
|
+
var TrieRouter = class {
|
|
2227
|
+
name = "TrieRouter";
|
|
2228
|
+
#node = new Node();
|
|
2229
|
+
add(method, path, handler) {
|
|
2230
|
+
for (const result of checkOptionalParameter(path) || [path]) this.#node.insert(method, result, handler);
|
|
2231
|
+
}
|
|
2232
|
+
match(method, path) {
|
|
2233
|
+
return this.#node.search(method, path);
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
//#endregion
|
|
2237
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/hono.js
|
|
2238
|
+
var Hono = class extends Hono$1 {
|
|
2239
|
+
/**
|
|
2240
|
+
* Creates an instance of the Hono class.
|
|
2241
|
+
*
|
|
2242
|
+
* @param options - Optional configuration options for the Hono instance.
|
|
2243
|
+
*/
|
|
2244
|
+
constructor(options = {}) {
|
|
2245
|
+
super(options);
|
|
2246
|
+
this.router = options.router ?? new SmartRouter({ routers: [new RegExpRouter(), new TrieRouter()] });
|
|
2247
|
+
}
|
|
2248
|
+
};
|
|
2249
|
+
//#endregion
|
|
2250
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/middleware/body-limit/index.js
|
|
2251
|
+
var ERROR_MESSAGE = "Payload Too Large";
|
|
2252
|
+
var bodyLimit = (options) => {
|
|
2253
|
+
const onError = options.onError || (() => {
|
|
2254
|
+
throw new HTTPException(413, { res: new Response(ERROR_MESSAGE, { status: 413 }) });
|
|
2255
|
+
});
|
|
2256
|
+
const maxSize = options.maxSize;
|
|
2257
|
+
return async function bodyLimit2(c, next) {
|
|
2258
|
+
if (!c.req.raw.body) return next();
|
|
2259
|
+
const hasTransferEncoding = c.req.raw.headers.has("transfer-encoding");
|
|
2260
|
+
if (c.req.raw.headers.has("content-length") && !hasTransferEncoding) return parseInt(c.req.raw.headers.get("content-length") || "0", 10) > maxSize ? onError(c) : next();
|
|
2261
|
+
let size = 0;
|
|
2262
|
+
const chunks = [];
|
|
2263
|
+
const rawReader = c.req.raw.body.getReader();
|
|
2264
|
+
for (;;) {
|
|
2265
|
+
const { done, value } = await rawReader.read();
|
|
2266
|
+
if (done) break;
|
|
2267
|
+
size += value.length;
|
|
2268
|
+
if (size > maxSize) return onError(c);
|
|
2269
|
+
chunks.push(value);
|
|
2270
|
+
}
|
|
2271
|
+
const requestInit = {
|
|
2272
|
+
body: new ReadableStream({ start(controller) {
|
|
2273
|
+
for (const chunk of chunks) controller.enqueue(chunk);
|
|
2274
|
+
controller.close();
|
|
2275
|
+
} }),
|
|
2276
|
+
duplex: "half"
|
|
2277
|
+
};
|
|
2278
|
+
c.req.raw = new Request(c.req.raw, requestInit);
|
|
2279
|
+
return next();
|
|
2280
|
+
};
|
|
2281
|
+
};
|
|
2282
|
+
//#endregion
|
|
2283
|
+
//#region ../../../layers/automation/po-calendar/src/types/apiRoutes.ts
|
|
2284
|
+
const routes = {
|
|
2285
|
+
list: {
|
|
2286
|
+
method: "GET",
|
|
2287
|
+
path: "/events",
|
|
2288
|
+
query: [
|
|
2289
|
+
"from",
|
|
2290
|
+
"to",
|
|
2291
|
+
"cursor",
|
|
2292
|
+
"tz",
|
|
2293
|
+
"status",
|
|
2294
|
+
"workspace",
|
|
2295
|
+
"kind",
|
|
2296
|
+
"q",
|
|
2297
|
+
"limit"
|
|
2298
|
+
],
|
|
2299
|
+
response: void 0
|
|
2300
|
+
},
|
|
2301
|
+
create: {
|
|
2302
|
+
method: "POST",
|
|
2303
|
+
path: "/events",
|
|
2304
|
+
response: void 0
|
|
2305
|
+
},
|
|
2306
|
+
update: {
|
|
2307
|
+
method: "PATCH",
|
|
2308
|
+
path: "/events/:id",
|
|
2309
|
+
response: void 0
|
|
2310
|
+
},
|
|
2311
|
+
cancel: {
|
|
2312
|
+
method: "DELETE",
|
|
2313
|
+
path: "/events/:id",
|
|
2314
|
+
response: void 0
|
|
2315
|
+
},
|
|
2316
|
+
pause: {
|
|
2317
|
+
method: "POST",
|
|
2318
|
+
path: "/events/:id/pause",
|
|
2319
|
+
response: void 0
|
|
2320
|
+
},
|
|
2321
|
+
resume: {
|
|
2322
|
+
method: "POST",
|
|
2323
|
+
path: "/events/:id/resume",
|
|
2324
|
+
response: void 0
|
|
2325
|
+
},
|
|
2326
|
+
runNow: {
|
|
2327
|
+
method: "POST",
|
|
2328
|
+
path: "/events/:id/run-now",
|
|
2329
|
+
response: void 0
|
|
2330
|
+
},
|
|
2331
|
+
ask: {
|
|
2332
|
+
method: "POST",
|
|
2333
|
+
path: "/events/:id/ask",
|
|
2334
|
+
response: void 0
|
|
2335
|
+
},
|
|
2336
|
+
history: {
|
|
2337
|
+
method: "GET",
|
|
2338
|
+
path: "/events/:id/history",
|
|
2339
|
+
query: ["cursor"],
|
|
2340
|
+
response: void 0
|
|
2341
|
+
},
|
|
2342
|
+
targets: {
|
|
2343
|
+
method: "GET",
|
|
2344
|
+
path: "/targets",
|
|
2345
|
+
response: void 0
|
|
2346
|
+
}
|
|
2347
|
+
};
|
|
2348
|
+
//#endregion
|
|
2349
|
+
//#region ../../../node_modules/.pnpm/croner@10.0.1/node_modules/croner/dist/croner.js
|
|
2350
|
+
function T(s) {
|
|
2351
|
+
return Date.UTC(s.y, s.m - 1, s.d, s.h, s.i, s.s);
|
|
2352
|
+
}
|
|
2353
|
+
function D(s, e) {
|
|
2354
|
+
return s.y === e.y && s.m === e.m && s.d === e.d && s.h === e.h && s.i === e.i && s.s === e.s;
|
|
2355
|
+
}
|
|
2356
|
+
function A(s, e) {
|
|
2357
|
+
let t = new Date(Date.parse(s));
|
|
2358
|
+
if (isNaN(t)) throw new Error("Invalid ISO8601 passed to timezone parser.");
|
|
2359
|
+
let r = s.substring(9);
|
|
2360
|
+
return r.includes("Z") || r.includes("+") || r.includes("-") ? b(t.getUTCFullYear(), t.getUTCMonth() + 1, t.getUTCDate(), t.getUTCHours(), t.getUTCMinutes(), t.getUTCSeconds(), "Etc/UTC") : b(t.getFullYear(), t.getMonth() + 1, t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds(), e);
|
|
2361
|
+
}
|
|
2362
|
+
function v(s, e, t) {
|
|
2363
|
+
return k(A(s, e), t);
|
|
2364
|
+
}
|
|
2365
|
+
function k(s, e) {
|
|
2366
|
+
let t = new Date(T(s)), r = g(t, s.tz), a = T(s) - T(r), o = new Date(t.getTime() + a), h = g(o, s.tz);
|
|
2367
|
+
if (D(h, s)) {
|
|
2368
|
+
let u = /* @__PURE__ */ new Date(o.getTime() - 36e5);
|
|
2369
|
+
return D(g(u, s.tz), s) ? u : o;
|
|
2370
|
+
}
|
|
2371
|
+
let l = new Date(o.getTime() + T(s) - T(h));
|
|
2372
|
+
if (D(g(l, s.tz), s)) return l;
|
|
2373
|
+
if (e) throw new Error("Invalid date passed to fromTZ()");
|
|
2374
|
+
return o.getTime() > l.getTime() ? o : l;
|
|
2375
|
+
}
|
|
2376
|
+
function g(s, e) {
|
|
2377
|
+
let t, r;
|
|
2378
|
+
try {
|
|
2379
|
+
t = new Intl.DateTimeFormat("en-US", {
|
|
2380
|
+
timeZone: e,
|
|
2381
|
+
year: "numeric",
|
|
2382
|
+
month: "numeric",
|
|
2383
|
+
day: "numeric",
|
|
2384
|
+
hour: "numeric",
|
|
2385
|
+
minute: "numeric",
|
|
2386
|
+
second: "numeric",
|
|
2387
|
+
hour12: !1
|
|
2388
|
+
}), r = t.formatToParts(s);
|
|
2389
|
+
} catch (i) {
|
|
2390
|
+
let a = i instanceof Error ? i.message : String(i);
|
|
2391
|
+
throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`);
|
|
2392
|
+
}
|
|
2393
|
+
let n = {
|
|
2394
|
+
year: 0,
|
|
2395
|
+
month: 0,
|
|
2396
|
+
day: 0,
|
|
2397
|
+
hour: 0,
|
|
2398
|
+
minute: 0,
|
|
2399
|
+
second: 0
|
|
2400
|
+
};
|
|
2401
|
+
for (let i of r) (i.type === "year" || i.type === "month" || i.type === "day" || i.type === "hour" || i.type === "minute" || i.type === "second") && (n[i.type] = parseInt(i.value, 10));
|
|
2402
|
+
if (isNaN(n.year) || isNaN(n.month) || isNaN(n.day) || isNaN(n.hour) || isNaN(n.minute) || isNaN(n.second)) throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(n)}`);
|
|
2403
|
+
return n.hour === 24 && (n.hour = 0), {
|
|
2404
|
+
y: n.year,
|
|
2405
|
+
m: n.month,
|
|
2406
|
+
d: n.day,
|
|
2407
|
+
h: n.hour,
|
|
2408
|
+
i: n.minute,
|
|
2409
|
+
s: n.second,
|
|
2410
|
+
tz: e
|
|
2411
|
+
};
|
|
2412
|
+
}
|
|
2413
|
+
function b(s, e, t, r, n, i, a) {
|
|
2414
|
+
return {
|
|
2415
|
+
y: s,
|
|
2416
|
+
m: e,
|
|
2417
|
+
d: t,
|
|
2418
|
+
h: r,
|
|
2419
|
+
i: n,
|
|
2420
|
+
s: i,
|
|
2421
|
+
tz: a
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
var O = [
|
|
2425
|
+
1,
|
|
2426
|
+
2,
|
|
2427
|
+
4,
|
|
2428
|
+
8,
|
|
2429
|
+
16
|
|
2430
|
+
];
|
|
2431
|
+
var C = class {
|
|
2432
|
+
pattern;
|
|
2433
|
+
timezone;
|
|
2434
|
+
mode;
|
|
2435
|
+
alternativeWeekdays;
|
|
2436
|
+
sloppyRanges;
|
|
2437
|
+
second;
|
|
2438
|
+
minute;
|
|
2439
|
+
hour;
|
|
2440
|
+
day;
|
|
2441
|
+
month;
|
|
2442
|
+
dayOfWeek;
|
|
2443
|
+
year;
|
|
2444
|
+
lastDayOfMonth;
|
|
2445
|
+
lastWeekday;
|
|
2446
|
+
nearestWeekdays;
|
|
2447
|
+
starDOM;
|
|
2448
|
+
starDOW;
|
|
2449
|
+
starYear;
|
|
2450
|
+
useAndLogic;
|
|
2451
|
+
constructor(e, t, r) {
|
|
2452
|
+
this.pattern = e, this.timezone = t, this.mode = r?.mode ?? "auto", this.alternativeWeekdays = r?.alternativeWeekdays ?? !1, this.sloppyRanges = r?.sloppyRanges ?? !1, this.second = Array(60).fill(0), this.minute = Array(60).fill(0), this.hour = Array(24).fill(0), this.day = Array(31).fill(0), this.month = Array(12).fill(0), this.dayOfWeek = Array(7).fill(0), this.year = Array(1e4).fill(0), this.lastDayOfMonth = !1, this.lastWeekday = !1, this.nearestWeekdays = Array(31).fill(0), this.starDOM = !1, this.starDOW = !1, this.starYear = !1, this.useAndLogic = !1, this.parse();
|
|
2453
|
+
}
|
|
2454
|
+
parse() {
|
|
2455
|
+
if (!(typeof this.pattern == "string" || this.pattern instanceof String)) throw new TypeError("CronPattern: Pattern has to be of type string.");
|
|
2456
|
+
this.pattern.indexOf("@") >= 0 && (this.pattern = this.handleNicknames(this.pattern).trim());
|
|
2457
|
+
let e = this.pattern.match(/\S+/g) || [""], t = e.length;
|
|
2458
|
+
if (e.length < 5 || e.length > 7) throw new TypeError("CronPattern: invalid configuration format ('" + this.pattern + "'), exactly five, six, or seven space separated parts are required.");
|
|
2459
|
+
if (this.mode !== "auto") {
|
|
2460
|
+
let n;
|
|
2461
|
+
switch (this.mode) {
|
|
2462
|
+
case "5-part":
|
|
2463
|
+
n = 5;
|
|
2464
|
+
break;
|
|
2465
|
+
case "6-part":
|
|
2466
|
+
n = 6;
|
|
2467
|
+
break;
|
|
2468
|
+
case "7-part":
|
|
2469
|
+
n = 7;
|
|
2470
|
+
break;
|
|
2471
|
+
case "5-or-6-parts":
|
|
2472
|
+
n = [5, 6];
|
|
2473
|
+
break;
|
|
2474
|
+
case "6-or-7-parts":
|
|
2475
|
+
n = [6, 7];
|
|
2476
|
+
break;
|
|
2477
|
+
default: n = 0;
|
|
2478
|
+
}
|
|
2479
|
+
if (!(Array.isArray(n) ? n.includes(t) : t === n)) {
|
|
2480
|
+
let a = Array.isArray(n) ? n.join(" or ") : n.toString();
|
|
2481
|
+
throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`);
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
if (e.length === 5 && e.unshift("0"), e.length === 6 && e.push("*"), e[3].toUpperCase() === "LW" ? (this.lastWeekday = !0, e[3] = "") : e[3].toUpperCase().indexOf("L") >= 0 && (e[3] = e[3].replace(/L/gi, ""), this.lastDayOfMonth = !0), e[3] == "*" && (this.starDOM = !0), e[6] == "*" && (this.starYear = !0), e[4].length >= 3 && (e[4] = this.replaceAlphaMonths(e[4])), e[5].length >= 3 && (e[5] = this.alternativeWeekdays ? this.replaceAlphaDaysQuartz(e[5]) : this.replaceAlphaDays(e[5])), e[5].startsWith("+") && (this.useAndLogic = !0, e[5] = e[5].substring(1), e[5] === "")) throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");
|
|
2485
|
+
switch (e[5] == "*" && (this.starDOW = !0), this.pattern.indexOf("?") >= 0 && (e[0] = e[0].replace(/\?/g, "*"), e[1] = e[1].replace(/\?/g, "*"), e[2] = e[2].replace(/\?/g, "*"), e[3] = e[3].replace(/\?/g, "*"), e[4] = e[4].replace(/\?/g, "*"), e[5] = e[5].replace(/\?/g, "*"), e[6] && (e[6] = e[6].replace(/\?/g, "*"))), this.mode) {
|
|
2486
|
+
case "5-part":
|
|
2487
|
+
e[0] = "0", e[6] = "*";
|
|
2488
|
+
break;
|
|
2489
|
+
case "6-part":
|
|
2490
|
+
e[6] = "*";
|
|
2491
|
+
break;
|
|
2492
|
+
case "5-or-6-parts": e[6] = "*";
|
|
2493
|
+
}
|
|
2494
|
+
this.throwAtIllegalCharacters(e), this.partToArray("second", e[0], 0, 1), this.partToArray("minute", e[1], 0, 1), this.partToArray("hour", e[2], 0, 1), this.partToArray("day", e[3], -1, 1), this.partToArray("month", e[4], -1, 1);
|
|
2495
|
+
let r = this.alternativeWeekdays ? -1 : 0;
|
|
2496
|
+
this.partToArray("dayOfWeek", e[5], r, 63), this.partToArray("year", e[6], 0, 1), !this.alternativeWeekdays && this.dayOfWeek[7] && (this.dayOfWeek[0] = this.dayOfWeek[7]);
|
|
2497
|
+
}
|
|
2498
|
+
partToArray(e, t, r, n) {
|
|
2499
|
+
let i = this[e], a = e === "day" && this.lastDayOfMonth, o = e === "day" && this.lastWeekday;
|
|
2500
|
+
if (t === "" && !a && !o) throw new TypeError("CronPattern: configuration entry " + e + " (" + t + ") is empty, check for trailing spaces.");
|
|
2501
|
+
if (t === "*") return i.fill(n);
|
|
2502
|
+
let h = t.split(",");
|
|
2503
|
+
if (h.length > 1) for (let l = 0; l < h.length; l++) this.partToArray(e, h[l], r, n);
|
|
2504
|
+
else t.indexOf("-") !== -1 && t.indexOf("/") !== -1 ? this.handleRangeWithStepping(t, e, r, n) : t.indexOf("-") !== -1 ? this.handleRange(t, e, r, n) : t.indexOf("/") !== -1 ? this.handleStepping(t, e, r, n) : t !== "" && this.handleNumber(t, e, r, n);
|
|
2505
|
+
}
|
|
2506
|
+
throwAtIllegalCharacters(e) {
|
|
2507
|
+
for (let t = 0; t < e.length; t++) if ((t === 3 ? /[^/*0-9,\-WwLl]+/ : t === 5 ? /[^/*0-9,\-#Ll]+/ : /[^/*0-9,\-]+/).test(e[t])) throw new TypeError("CronPattern: configuration entry " + t + " (" + e[t] + ") contains illegal characters.");
|
|
2508
|
+
}
|
|
2509
|
+
handleNumber(e, t, r, n) {
|
|
2510
|
+
let i = this.extractNth(e, t), a = e.toUpperCase().includes("W");
|
|
2511
|
+
if (t !== "day" && a) throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");
|
|
2512
|
+
a && (t = "nearestWeekdays");
|
|
2513
|
+
let o = parseInt(i[0], 10) + r;
|
|
2514
|
+
if (isNaN(o)) throw new TypeError("CronPattern: " + t + " is not a number: '" + e + "'");
|
|
2515
|
+
this.setPart(t, o, i[1] || n);
|
|
2516
|
+
}
|
|
2517
|
+
setPart(e, t, r) {
|
|
2518
|
+
if (!Object.prototype.hasOwnProperty.call(this, e)) throw new TypeError("CronPattern: Invalid part specified: " + e);
|
|
2519
|
+
if (e === "dayOfWeek") {
|
|
2520
|
+
if (t === 7 && (t = 0), t < 0 || t > 6) throw new RangeError("CronPattern: Invalid value for dayOfWeek: " + t);
|
|
2521
|
+
this.setNthWeekdayOfMonth(t, r);
|
|
2522
|
+
return;
|
|
2523
|
+
}
|
|
2524
|
+
if (e === "second" || e === "minute") {
|
|
2525
|
+
if (t < 0 || t >= 60) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
2526
|
+
} else if (e === "hour") {
|
|
2527
|
+
if (t < 0 || t >= 24) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
2528
|
+
} else if (e === "day" || e === "nearestWeekdays") {
|
|
2529
|
+
if (t < 0 || t >= 31) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
2530
|
+
} else if (e === "month") {
|
|
2531
|
+
if (t < 0 || t >= 12) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
2532
|
+
} else if (e === "year" && (t < 1 || t >= 1e4)) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t + " (supported range: 1-9999)");
|
|
2533
|
+
this[e][t] = r;
|
|
2534
|
+
}
|
|
2535
|
+
validateNotNaN(e, t) {
|
|
2536
|
+
if (isNaN(e)) throw new TypeError(t);
|
|
2537
|
+
}
|
|
2538
|
+
validateRange(e, t, r, n, i) {
|
|
2539
|
+
if (e > t) throw new TypeError("CronPattern: From value is larger than to value: '" + i + "'");
|
|
2540
|
+
if (r !== void 0) {
|
|
2541
|
+
if (r === 0) throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");
|
|
2542
|
+
if (r > this[n].length) throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part (" + this[n].length + ")");
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
handleRangeWithStepping(e, t, r, n) {
|
|
2546
|
+
if (e.toUpperCase().includes("W")) throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");
|
|
2547
|
+
let i = this.extractNth(e, t), a = i[0].match(/^(\d+)-(\d+)\/(\d+)$/);
|
|
2548
|
+
if (a === null) throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '" + e + "'");
|
|
2549
|
+
let [, o, h, l] = a, y = parseInt(o, 10) + r, u = parseInt(h, 10) + r, d = parseInt(l, 10);
|
|
2550
|
+
this.validateNotNaN(y, "CronPattern: Syntax error, illegal lower range (NaN)"), this.validateNotNaN(u, "CronPattern: Syntax error, illegal upper range (NaN)"), this.validateNotNaN(d, "CronPattern: Syntax error, illegal stepping: (NaN)"), this.validateRange(y, u, d, t, e);
|
|
2551
|
+
for (let c = y; c <= u; c += d) this.setPart(t, c, i[1] || n);
|
|
2552
|
+
}
|
|
2553
|
+
extractNth(e, t) {
|
|
2554
|
+
let r = e, n;
|
|
2555
|
+
if (r.includes("#")) {
|
|
2556
|
+
if (t !== "dayOfWeek") throw new Error("CronPattern: nth (#) only allowed in day-of-week field");
|
|
2557
|
+
n = r.split("#")[1], r = r.split("#")[0];
|
|
2558
|
+
} else if (r.toUpperCase().endsWith("L")) {
|
|
2559
|
+
if (t !== "dayOfWeek") throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");
|
|
2560
|
+
n = "L", r = r.slice(0, -1);
|
|
2561
|
+
}
|
|
2562
|
+
return [r, n];
|
|
2563
|
+
}
|
|
2564
|
+
handleRange(e, t, r, n) {
|
|
2565
|
+
if (e.toUpperCase().includes("W")) throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");
|
|
2566
|
+
let i = this.extractNth(e, t), a = i[0].split("-");
|
|
2567
|
+
if (a.length !== 2) throw new TypeError("CronPattern: Syntax error, illegal range: '" + e + "'");
|
|
2568
|
+
let o = parseInt(a[0], 10) + r, h = parseInt(a[1], 10) + r;
|
|
2569
|
+
this.validateNotNaN(o, "CronPattern: Syntax error, illegal lower range (NaN)"), this.validateNotNaN(h, "CronPattern: Syntax error, illegal upper range (NaN)"), this.validateRange(o, h, void 0, t, e);
|
|
2570
|
+
for (let l = o; l <= h; l++) this.setPart(t, l, i[1] || n);
|
|
2571
|
+
}
|
|
2572
|
+
handleStepping(e, t, r, n) {
|
|
2573
|
+
if (e.toUpperCase().includes("W")) throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");
|
|
2574
|
+
let i = this.extractNth(e, t), a = i[0].split("/");
|
|
2575
|
+
if (a.length !== 2) throw new TypeError("CronPattern: Syntax error, illegal stepping: '" + e + "'");
|
|
2576
|
+
if (this.sloppyRanges) a[0] === "" && (a[0] = "*");
|
|
2577
|
+
else {
|
|
2578
|
+
if (a[0] === "") throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('" + e + "') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");
|
|
2579
|
+
if (a[0] !== "*") throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('" + e + "') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");
|
|
2580
|
+
}
|
|
2581
|
+
let o = 0;
|
|
2582
|
+
a[0] !== "*" && (o = parseInt(a[0], 10) + r);
|
|
2583
|
+
let h = parseInt(a[1], 10);
|
|
2584
|
+
this.validateNotNaN(h, "CronPattern: Syntax error, illegal stepping: (NaN)"), this.validateRange(0, this[t].length - 1, h, t, e);
|
|
2585
|
+
for (let l = o; l < this[t].length; l += h) this.setPart(t, l, i[1] || n);
|
|
2586
|
+
}
|
|
2587
|
+
replaceAlphaDays(e) {
|
|
2588
|
+
return e.replace(/-sun/gi, "-7").replace(/sun/gi, "0").replace(/mon/gi, "1").replace(/tue/gi, "2").replace(/wed/gi, "3").replace(/thu/gi, "4").replace(/fri/gi, "5").replace(/sat/gi, "6");
|
|
2589
|
+
}
|
|
2590
|
+
replaceAlphaDaysQuartz(e) {
|
|
2591
|
+
return e.replace(/sun/gi, "1").replace(/mon/gi, "2").replace(/tue/gi, "3").replace(/wed/gi, "4").replace(/thu/gi, "5").replace(/fri/gi, "6").replace(/sat/gi, "7");
|
|
2592
|
+
}
|
|
2593
|
+
replaceAlphaMonths(e) {
|
|
2594
|
+
return e.replace(/jan/gi, "1").replace(/feb/gi, "2").replace(/mar/gi, "3").replace(/apr/gi, "4").replace(/may/gi, "5").replace(/jun/gi, "6").replace(/jul/gi, "7").replace(/aug/gi, "8").replace(/sep/gi, "9").replace(/oct/gi, "10").replace(/nov/gi, "11").replace(/dec/gi, "12");
|
|
2595
|
+
}
|
|
2596
|
+
handleNicknames(e) {
|
|
2597
|
+
let t = e.trim().toLowerCase();
|
|
2598
|
+
if (t === "@yearly" || t === "@annually") return "0 0 1 1 *";
|
|
2599
|
+
if (t === "@monthly") return "0 0 1 * *";
|
|
2600
|
+
if (t === "@weekly") return "0 0 * * 0";
|
|
2601
|
+
if (t === "@daily" || t === "@midnight") return "0 0 * * *";
|
|
2602
|
+
if (t === "@hourly") return "0 * * * *";
|
|
2603
|
+
if (t === "@reboot") throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");
|
|
2604
|
+
return e;
|
|
2605
|
+
}
|
|
2606
|
+
setNthWeekdayOfMonth(e, t) {
|
|
2607
|
+
if (typeof t != "number" && t.toUpperCase() === "L") this.dayOfWeek[e] = this.dayOfWeek[e] | 32;
|
|
2608
|
+
else if (t === 63) this.dayOfWeek[e] = 63;
|
|
2609
|
+
else if (t < 6 && t > 0) this.dayOfWeek[e] = this.dayOfWeek[e] | O[t - 1];
|
|
2610
|
+
else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`);
|
|
2611
|
+
}
|
|
2612
|
+
};
|
|
2613
|
+
var P = [
|
|
2614
|
+
31,
|
|
2615
|
+
28,
|
|
2616
|
+
31,
|
|
2617
|
+
30,
|
|
2618
|
+
31,
|
|
2619
|
+
30,
|
|
2620
|
+
31,
|
|
2621
|
+
31,
|
|
2622
|
+
30,
|
|
2623
|
+
31,
|
|
2624
|
+
30,
|
|
2625
|
+
31
|
|
2626
|
+
];
|
|
2627
|
+
var f = [
|
|
2628
|
+
[
|
|
2629
|
+
"month",
|
|
2630
|
+
"year",
|
|
2631
|
+
0
|
|
2632
|
+
],
|
|
2633
|
+
[
|
|
2634
|
+
"day",
|
|
2635
|
+
"month",
|
|
2636
|
+
-1
|
|
2637
|
+
],
|
|
2638
|
+
[
|
|
2639
|
+
"hour",
|
|
2640
|
+
"day",
|
|
2641
|
+
0
|
|
2642
|
+
],
|
|
2643
|
+
[
|
|
2644
|
+
"minute",
|
|
2645
|
+
"hour",
|
|
2646
|
+
0
|
|
2647
|
+
],
|
|
2648
|
+
[
|
|
2649
|
+
"second",
|
|
2650
|
+
"minute",
|
|
2651
|
+
0
|
|
2652
|
+
]
|
|
2653
|
+
];
|
|
2654
|
+
var m = class s {
|
|
2655
|
+
tz;
|
|
2656
|
+
ms;
|
|
2657
|
+
second;
|
|
2658
|
+
minute;
|
|
2659
|
+
hour;
|
|
2660
|
+
day;
|
|
2661
|
+
month;
|
|
2662
|
+
year;
|
|
2663
|
+
constructor(e, t) {
|
|
2664
|
+
if (this.tz = t, e && e instanceof Date) if (!isNaN(e)) this.fromDate(e);
|
|
2665
|
+
else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");
|
|
2666
|
+
else if (e == null) this.fromDate(/* @__PURE__ */ new Date());
|
|
2667
|
+
else if (e && typeof e == "string") this.fromString(e);
|
|
2668
|
+
else if (e instanceof s) this.fromCronDate(e);
|
|
2669
|
+
else throw new TypeError("CronDate: Invalid type (" + typeof e + ") passed to CronDate constructor");
|
|
2670
|
+
}
|
|
2671
|
+
getLastDayOfMonth(e, t) {
|
|
2672
|
+
return t !== 1 ? P[t] : new Date(Date.UTC(e, t + 1, 0)).getUTCDate();
|
|
2673
|
+
}
|
|
2674
|
+
getLastWeekday(e, t) {
|
|
2675
|
+
let r = this.getLastDayOfMonth(e, t), i = new Date(Date.UTC(e, t, r)).getUTCDay();
|
|
2676
|
+
return i === 0 ? r - 2 : i === 6 ? r - 1 : r;
|
|
2677
|
+
}
|
|
2678
|
+
getNearestWeekday(e, t, r) {
|
|
2679
|
+
let n = this.getLastDayOfMonth(e, t);
|
|
2680
|
+
if (r > n) return -1;
|
|
2681
|
+
let a = new Date(Date.UTC(e, t, r)).getUTCDay();
|
|
2682
|
+
return a === 0 ? r === n ? r - 2 : r + 1 : a === 6 ? r === 1 ? r + 2 : r - 1 : r;
|
|
2683
|
+
}
|
|
2684
|
+
isNthWeekdayOfMonth(e, t, r, n) {
|
|
2685
|
+
let a = new Date(Date.UTC(e, t, r)).getUTCDay(), o = 0;
|
|
2686
|
+
for (let h = 1; h <= r; h++) new Date(Date.UTC(e, t, h)).getUTCDay() === a && o++;
|
|
2687
|
+
if (n & 63 && O[o - 1] & n) return !0;
|
|
2688
|
+
if (n & 32) {
|
|
2689
|
+
let h = this.getLastDayOfMonth(e, t);
|
|
2690
|
+
for (let l = r + 1; l <= h; l++) if (new Date(Date.UTC(e, t, l)).getUTCDay() === a) return !1;
|
|
2691
|
+
return !0;
|
|
2692
|
+
}
|
|
2693
|
+
return !1;
|
|
2694
|
+
}
|
|
2695
|
+
fromDate(e) {
|
|
2696
|
+
if (this.tz !== void 0) if (typeof this.tz == "number") this.ms = e.getUTCMilliseconds(), this.second = e.getUTCSeconds(), this.minute = e.getUTCMinutes() + this.tz, this.hour = e.getUTCHours(), this.day = e.getUTCDate(), this.month = e.getUTCMonth(), this.year = e.getUTCFullYear(), this.apply();
|
|
2697
|
+
else try {
|
|
2698
|
+
let t = g(e, this.tz);
|
|
2699
|
+
this.ms = e.getMilliseconds(), this.second = t.s, this.minute = t.i, this.hour = t.h, this.day = t.d, this.month = t.m - 1, this.year = t.y;
|
|
2700
|
+
} catch (t) {
|
|
2701
|
+
let r = t instanceof Error ? t.message : String(t);
|
|
2702
|
+
throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`);
|
|
2703
|
+
}
|
|
2704
|
+
else this.ms = e.getMilliseconds(), this.second = e.getSeconds(), this.minute = e.getMinutes(), this.hour = e.getHours(), this.day = e.getDate(), this.month = e.getMonth(), this.year = e.getFullYear();
|
|
2705
|
+
}
|
|
2706
|
+
fromCronDate(e) {
|
|
2707
|
+
this.tz = e.tz, this.year = e.year, this.month = e.month, this.day = e.day, this.hour = e.hour, this.minute = e.minute, this.second = e.second, this.ms = e.ms;
|
|
2708
|
+
}
|
|
2709
|
+
apply() {
|
|
2710
|
+
if (this.month > 11 || this.month < 0 || this.day > P[this.month] || this.day < 1 || this.hour > 59 || this.minute > 59 || this.second > 59 || this.hour < 0 || this.minute < 0 || this.second < 0) {
|
|
2711
|
+
let e = new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms));
|
|
2712
|
+
return this.ms = e.getUTCMilliseconds(), this.second = e.getUTCSeconds(), this.minute = e.getUTCMinutes(), this.hour = e.getUTCHours(), this.day = e.getUTCDate(), this.month = e.getUTCMonth(), this.year = e.getUTCFullYear(), !0;
|
|
2713
|
+
} else return !1;
|
|
2714
|
+
}
|
|
2715
|
+
fromString(e) {
|
|
2716
|
+
if (typeof this.tz == "number") {
|
|
2717
|
+
let t = v(e);
|
|
2718
|
+
this.ms = t.getUTCMilliseconds(), this.second = t.getUTCSeconds(), this.minute = t.getUTCMinutes(), this.hour = t.getUTCHours(), this.day = t.getUTCDate(), this.month = t.getUTCMonth(), this.year = t.getUTCFullYear(), this.apply();
|
|
2719
|
+
} else return this.fromDate(v(e, this.tz));
|
|
2720
|
+
}
|
|
2721
|
+
findNext(e, t, r, n) {
|
|
2722
|
+
return this._findMatch(e, t, r, n, 1);
|
|
2723
|
+
}
|
|
2724
|
+
_findMatch(e, t, r, n, i) {
|
|
2725
|
+
let a = this[t], o;
|
|
2726
|
+
r.lastDayOfMonth && (o = this.getLastDayOfMonth(this.year, this.month));
|
|
2727
|
+
let h = !r.starDOW && t == "day" ? new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay() : void 0, l = this[t] + n, y = i === 1 ? (u) => u < r[t].length : (u) => u >= 0;
|
|
2728
|
+
for (let u = l; y(u); u += i) {
|
|
2729
|
+
let d = r[t][u];
|
|
2730
|
+
if (t === "day" && !d) {
|
|
2731
|
+
for (let c = 0; c < r.nearestWeekdays.length; c++) if (r.nearestWeekdays[c]) {
|
|
2732
|
+
let M = this.getNearestWeekday(this.year, this.month, c - n);
|
|
2733
|
+
if (M === -1) continue;
|
|
2734
|
+
if (M === u - n) {
|
|
2735
|
+
d = 1;
|
|
2736
|
+
break;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
if (t === "day" && r.lastWeekday) {
|
|
2741
|
+
let c = this.getLastWeekday(this.year, this.month);
|
|
2742
|
+
u - n === c && (d = 1);
|
|
2743
|
+
}
|
|
2744
|
+
if (t === "day" && r.lastDayOfMonth && u - n == o && (d = 1), t === "day" && !r.starDOW) {
|
|
2745
|
+
let c = r.dayOfWeek[(h + (u - n - 1)) % 7];
|
|
2746
|
+
if (c && c & 63) c = this.isNthWeekdayOfMonth(this.year, this.month, u - n, c) ? 1 : 0;
|
|
2747
|
+
else if (c) throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${c}`);
|
|
2748
|
+
r.useAndLogic ? d = d && c : !e.domAndDow && !r.starDOM ? d = d || c : d = d && c;
|
|
2749
|
+
}
|
|
2750
|
+
if (d) return this[t] = u - n, a !== this[t] ? 2 : 1;
|
|
2751
|
+
}
|
|
2752
|
+
return 3;
|
|
2753
|
+
}
|
|
2754
|
+
recurse(e, t, r) {
|
|
2755
|
+
if (r === 0 && !e.starYear) {
|
|
2756
|
+
if (this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0) {
|
|
2757
|
+
let i = -1;
|
|
2758
|
+
for (let a = this.year + 1; a < e.year.length && a < 1e4; a++) if (e.year[a] === 1) {
|
|
2759
|
+
i = a;
|
|
2760
|
+
break;
|
|
2761
|
+
}
|
|
2762
|
+
if (i === -1) return null;
|
|
2763
|
+
this.year = i, this.month = 0, this.day = 1, this.hour = 0, this.minute = 0, this.second = 0, this.ms = 0;
|
|
2764
|
+
}
|
|
2765
|
+
if (this.year >= 1e4) return null;
|
|
2766
|
+
}
|
|
2767
|
+
let n = this.findNext(t, f[r][0], e, f[r][2]);
|
|
2768
|
+
if (n > 1) {
|
|
2769
|
+
let i = r + 1;
|
|
2770
|
+
for (; i < f.length;) this[f[i][0]] = -f[i][2], i++;
|
|
2771
|
+
if (n === 3) {
|
|
2772
|
+
if (this[f[r][1]]++, this[f[r][0]] = -f[r][2], this.apply(), r === 0 && !e.starYear) {
|
|
2773
|
+
for (; this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0 && this.year < 1e4;) this.year++;
|
|
2774
|
+
if (this.year >= 1e4 || this.year >= e.year.length) return null;
|
|
2775
|
+
}
|
|
2776
|
+
return this.recurse(e, t, 0);
|
|
2777
|
+
} else if (this.apply()) return this.recurse(e, t, r - 1);
|
|
2778
|
+
}
|
|
2779
|
+
return r += 1, r >= f.length ? this : (e.starYear ? this.year >= 3e3 : this.year >= 1e4) ? null : this.recurse(e, t, r);
|
|
2780
|
+
}
|
|
2781
|
+
increment(e, t, r) {
|
|
2782
|
+
return this.second += t.interval !== void 0 && t.interval > 1 && r ? t.interval : 1, this.ms = 0, this.apply(), this.recurse(e, t, 0);
|
|
2783
|
+
}
|
|
2784
|
+
decrement(e, t) {
|
|
2785
|
+
return this.second -= t.interval !== void 0 && t.interval > 1 ? t.interval : 1, this.ms = 0, this.apply(), this.recurseBackward(e, t, 0, 0);
|
|
2786
|
+
}
|
|
2787
|
+
recurseBackward(e, t, r, n = 0) {
|
|
2788
|
+
if (n > 1e4) return null;
|
|
2789
|
+
if (r === 0 && !e.starYear) {
|
|
2790
|
+
if (this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0) {
|
|
2791
|
+
let a = -1;
|
|
2792
|
+
for (let o = this.year - 1; o >= 0; o--) if (e.year[o] === 1) {
|
|
2793
|
+
a = o;
|
|
2794
|
+
break;
|
|
2795
|
+
}
|
|
2796
|
+
if (a === -1) return null;
|
|
2797
|
+
this.year = a, this.month = 11, this.day = 31, this.hour = 23, this.minute = 59, this.second = 59, this.ms = 0;
|
|
2798
|
+
}
|
|
2799
|
+
if (this.year < 0) return null;
|
|
2800
|
+
}
|
|
2801
|
+
let i = this.findPrevious(t, f[r][0], e, f[r][2]);
|
|
2802
|
+
if (i > 1) {
|
|
2803
|
+
let a = r + 1;
|
|
2804
|
+
for (; a < f.length;) {
|
|
2805
|
+
let o = f[a][0], h = f[a][2], l = this.getMaxPatternValue(o, e, h);
|
|
2806
|
+
this[o] = l, a++;
|
|
2807
|
+
}
|
|
2808
|
+
if (i === 3) {
|
|
2809
|
+
if (this[f[r][1]]--, r === 0) {
|
|
2810
|
+
let y = this.getLastDayOfMonth(this.year, this.month);
|
|
2811
|
+
this.day > y && (this.day = y);
|
|
2812
|
+
}
|
|
2813
|
+
if (r === 1) if (this.day <= 0) this.day = 1;
|
|
2814
|
+
else {
|
|
2815
|
+
let y = this.year, u = this.month;
|
|
2816
|
+
for (; u < 0;) u += 12, y--;
|
|
2817
|
+
for (; u > 11;) u -= 12, y++;
|
|
2818
|
+
let d = u !== 1 ? P[u] : new Date(Date.UTC(y, u + 1, 0)).getUTCDate();
|
|
2819
|
+
this.day > d && (this.day = d);
|
|
2820
|
+
}
|
|
2821
|
+
this.apply();
|
|
2822
|
+
let o = f[r][0], h = f[r][2], l = this.getMaxPatternValue(o, e, h);
|
|
2823
|
+
if (o === "day") {
|
|
2824
|
+
let y = this.getLastDayOfMonth(this.year, this.month);
|
|
2825
|
+
this[o] = Math.min(l, y);
|
|
2826
|
+
} else this[o] = l;
|
|
2827
|
+
if (this.apply(), r === 0) {
|
|
2828
|
+
let y = f[1][2], u = this.getMaxPatternValue("day", e, y), d = this.getLastDayOfMonth(this.year, this.month), c = Math.min(u, d);
|
|
2829
|
+
c !== this.day && (this.day = c, this.hour = this.getMaxPatternValue("hour", e, f[2][2]), this.minute = this.getMaxPatternValue("minute", e, f[3][2]), this.second = this.getMaxPatternValue("second", e, f[4][2]));
|
|
2830
|
+
}
|
|
2831
|
+
if (r === 0 && !e.starYear) {
|
|
2832
|
+
for (; this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0;) this.year--;
|
|
2833
|
+
if (this.year < 0) return null;
|
|
2834
|
+
}
|
|
2835
|
+
return this.recurseBackward(e, t, 0, n + 1);
|
|
2836
|
+
} else if (this.apply()) return this.recurseBackward(e, t, r - 1, n + 1);
|
|
2837
|
+
}
|
|
2838
|
+
return r += 1, r >= f.length ? this : this.year < 0 ? null : this.recurseBackward(e, t, r, n + 1);
|
|
2839
|
+
}
|
|
2840
|
+
getMaxPatternValue(e, t, r) {
|
|
2841
|
+
if (e === "day" && t.lastDayOfMonth) return this.getLastDayOfMonth(this.year, this.month);
|
|
2842
|
+
if (e === "day" && !t.starDOW) return this.getLastDayOfMonth(this.year, this.month);
|
|
2843
|
+
for (let n = t[e].length - 1; n >= 0; n--) if (t[e][n]) return n - r;
|
|
2844
|
+
return t[e].length - 1 - r;
|
|
2845
|
+
}
|
|
2846
|
+
findPrevious(e, t, r, n) {
|
|
2847
|
+
return this._findMatch(e, t, r, n, -1);
|
|
2848
|
+
}
|
|
2849
|
+
getDate(e) {
|
|
2850
|
+
return e || this.tz === void 0 ? new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms) : typeof this.tz == "number" ? new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute - this.tz, this.second, this.ms)) : k(b(this.year, this.month + 1, this.day, this.hour, this.minute, this.second, this.tz), !1);
|
|
2851
|
+
}
|
|
2852
|
+
getTime() {
|
|
2853
|
+
return this.getDate(!1).getTime();
|
|
2854
|
+
}
|
|
2855
|
+
match(e, t) {
|
|
2856
|
+
if (!e.starYear && (this.year < 0 || this.year >= e.year.length || e.year[this.year] === 0)) return !1;
|
|
2857
|
+
for (let r = 0; r < f.length; r++) {
|
|
2858
|
+
let n = f[r][0], i = f[r][2], a = this[n];
|
|
2859
|
+
if (a + i < 0 || a + i >= e[n].length) return !1;
|
|
2860
|
+
let o = e[n][a + i];
|
|
2861
|
+
if (n === "day") {
|
|
2862
|
+
if (!o) {
|
|
2863
|
+
for (let h = 0; h < e.nearestWeekdays.length; h++) if (e.nearestWeekdays[h]) {
|
|
2864
|
+
let l = this.getNearestWeekday(this.year, this.month, h - i);
|
|
2865
|
+
if (l !== -1 && l === a) {
|
|
2866
|
+
o = 1;
|
|
2867
|
+
break;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
if (e.lastWeekday) a === this.getLastWeekday(this.year, this.month) && (o = 1);
|
|
2872
|
+
if (e.lastDayOfMonth) a === this.getLastDayOfMonth(this.year, this.month) && (o = 1);
|
|
2873
|
+
if (!e.starDOW) {
|
|
2874
|
+
let h = new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay(), l = e.dayOfWeek[(h + (a - 1)) % 7];
|
|
2875
|
+
l && l & 63 && (l = this.isNthWeekdayOfMonth(this.year, this.month, a, l) ? 1 : 0), e.useAndLogic ? o = o && l : !t.domAndDow && !e.starDOM ? o = o || l : o = o && l;
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
if (!o) return !1;
|
|
2879
|
+
}
|
|
2880
|
+
return !0;
|
|
2881
|
+
}
|
|
2882
|
+
};
|
|
2883
|
+
function R(s) {
|
|
2884
|
+
if (s === void 0 && (s = {}), delete s.name, s.legacyMode !== void 0 && s.domAndDow === void 0 ? s.domAndDow = !s.legacyMode : s.domAndDow === void 0 && (s.domAndDow = !1), s.legacyMode = !s.domAndDow, s.paused = s.paused === void 0 ? !1 : s.paused, s.maxRuns = s.maxRuns === void 0 ? 1 / 0 : s.maxRuns, s.catch = s.catch === void 0 ? !1 : s.catch, s.interval = s.interval === void 0 ? 0 : parseInt(s.interval.toString(), 10), s.utcOffset = s.utcOffset === void 0 ? void 0 : parseInt(s.utcOffset.toString(), 10), s.dayOffset = s.dayOffset === void 0 ? 0 : parseInt(s.dayOffset.toString(), 10), s.unref = s.unref === void 0 ? !1 : s.unref, s.mode = s.mode === void 0 ? "auto" : s.mode, s.alternativeWeekdays = s.alternativeWeekdays === void 0 ? !1 : s.alternativeWeekdays, s.sloppyRanges = s.sloppyRanges === void 0 ? !1 : s.sloppyRanges, ![
|
|
2885
|
+
"auto",
|
|
2886
|
+
"5-part",
|
|
2887
|
+
"6-part",
|
|
2888
|
+
"7-part",
|
|
2889
|
+
"5-or-6-parts",
|
|
2890
|
+
"6-or-7-parts"
|
|
2891
|
+
].includes(s.mode)) throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");
|
|
2892
|
+
if (s.startAt && (s.startAt = new m(s.startAt, s.timezone)), s.stopAt && (s.stopAt = new m(s.stopAt, s.timezone)), s.interval !== null) {
|
|
2893
|
+
if (isNaN(s.interval)) throw new Error("CronOptions: Supplied value for interval is not a number");
|
|
2894
|
+
if (s.interval < 0) throw new Error("CronOptions: Supplied value for interval can not be negative");
|
|
2895
|
+
}
|
|
2896
|
+
if (s.utcOffset !== void 0) {
|
|
2897
|
+
if (isNaN(s.utcOffset)) throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");
|
|
2898
|
+
if (s.utcOffset < -870 || s.utcOffset > 870) throw new Error("CronOptions: utcOffset out of bounds.");
|
|
2899
|
+
if (s.utcOffset !== void 0 && s.timezone) throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.");
|
|
2900
|
+
}
|
|
2901
|
+
if (s.unref !== !0 && s.unref !== !1) throw new Error("CronOptions: Unref should be either true, false or undefined(false).");
|
|
2902
|
+
if (s.dayOffset !== void 0 && s.dayOffset !== 0 && isNaN(s.dayOffset)) throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");
|
|
2903
|
+
return s;
|
|
2904
|
+
}
|
|
2905
|
+
function p(s) {
|
|
2906
|
+
return Object.prototype.toString.call(s) === "[object Function]" || typeof s == "function" || s instanceof Function;
|
|
2907
|
+
}
|
|
2908
|
+
function _(s) {
|
|
2909
|
+
return p(s);
|
|
2910
|
+
}
|
|
2911
|
+
function x(s) {
|
|
2912
|
+
typeof Deno < "u" && typeof Deno.unrefTimer < "u" ? Deno.unrefTimer(s) : s && typeof s.unref < "u" && s.unref();
|
|
2913
|
+
}
|
|
2914
|
+
var W = 3e4;
|
|
2915
|
+
var w = [];
|
|
2916
|
+
var E = class {
|
|
2917
|
+
name;
|
|
2918
|
+
options;
|
|
2919
|
+
_states;
|
|
2920
|
+
fn;
|
|
2921
|
+
getTz() {
|
|
2922
|
+
return this.options.timezone || this.options.utcOffset;
|
|
2923
|
+
}
|
|
2924
|
+
applyDayOffset(e) {
|
|
2925
|
+
if (this.options.dayOffset !== void 0 && this.options.dayOffset !== 0) {
|
|
2926
|
+
let t = this.options.dayOffset * 24 * 60 * 60 * 1e3;
|
|
2927
|
+
return new Date(e.getTime() + t);
|
|
2928
|
+
}
|
|
2929
|
+
return e;
|
|
2930
|
+
}
|
|
2931
|
+
constructor(e, t, r) {
|
|
2932
|
+
let n, i;
|
|
2933
|
+
if (p(t)) i = t;
|
|
2934
|
+
else if (typeof t == "object") n = t;
|
|
2935
|
+
else if (t !== void 0) throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");
|
|
2936
|
+
if (p(r)) i = r;
|
|
2937
|
+
else if (typeof r == "object") n = r;
|
|
2938
|
+
else if (r !== void 0) throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");
|
|
2939
|
+
if (this.name = n?.name, this.options = R(n), this._states = {
|
|
2940
|
+
kill: !1,
|
|
2941
|
+
blocking: !1,
|
|
2942
|
+
previousRun: void 0,
|
|
2943
|
+
currentRun: void 0,
|
|
2944
|
+
once: void 0,
|
|
2945
|
+
currentTimeout: void 0,
|
|
2946
|
+
maxRuns: n ? n.maxRuns : void 0,
|
|
2947
|
+
paused: n ? n.paused : !1,
|
|
2948
|
+
pattern: new C("* * * * *", void 0, { mode: "auto" })
|
|
2949
|
+
}, e && (e instanceof Date || typeof e == "string" && e.indexOf(":") > 0) ? this._states.once = new m(e, this.getTz()) : this._states.pattern = new C(e, this.options.timezone, {
|
|
2950
|
+
mode: this.options.mode,
|
|
2951
|
+
alternativeWeekdays: this.options.alternativeWeekdays,
|
|
2952
|
+
sloppyRanges: this.options.sloppyRanges
|
|
2953
|
+
}), this.name) {
|
|
2954
|
+
if (w.find((o) => o.name === this.name)) throw new Error("Cron: Tried to initialize new named job '" + this.name + "', but name already taken.");
|
|
2955
|
+
w.push(this);
|
|
2956
|
+
}
|
|
2957
|
+
return i !== void 0 && _(i) && (this.fn = i, this.schedule()), this;
|
|
2958
|
+
}
|
|
2959
|
+
nextRun(e) {
|
|
2960
|
+
let t = this._next(e);
|
|
2961
|
+
return t ? this.applyDayOffset(t.getDate(!1)) : null;
|
|
2962
|
+
}
|
|
2963
|
+
nextRuns(e, t) {
|
|
2964
|
+
this._states.maxRuns !== void 0 && e > this._states.maxRuns && (e = this._states.maxRuns);
|
|
2965
|
+
let r = t || this._states.currentRun || void 0;
|
|
2966
|
+
return this._enumerateRuns(e, r, "next");
|
|
2967
|
+
}
|
|
2968
|
+
previousRuns(e, t) {
|
|
2969
|
+
return this._enumerateRuns(e, t || void 0, "previous");
|
|
2970
|
+
}
|
|
2971
|
+
_enumerateRuns(e, t, r) {
|
|
2972
|
+
let n = [], i = t ? new m(t, this.getTz()) : null, a = r === "next" ? this._next : this._previous;
|
|
2973
|
+
for (; e--;) {
|
|
2974
|
+
let o = a.call(this, i);
|
|
2975
|
+
if (!o) break;
|
|
2976
|
+
let h = o.getDate(!1);
|
|
2977
|
+
n.push(this.applyDayOffset(h)), i = o;
|
|
2978
|
+
}
|
|
2979
|
+
return n;
|
|
2980
|
+
}
|
|
2981
|
+
match(e) {
|
|
2982
|
+
if (this._states.once) {
|
|
2983
|
+
let r = new m(e, this.getTz());
|
|
2984
|
+
r.ms = 0;
|
|
2985
|
+
let n = new m(this._states.once, this.getTz());
|
|
2986
|
+
return n.ms = 0, r.getTime() === n.getTime();
|
|
2987
|
+
}
|
|
2988
|
+
let t = new m(e, this.getTz());
|
|
2989
|
+
return t.ms = 0, t.match(this._states.pattern, this.options);
|
|
2990
|
+
}
|
|
2991
|
+
getPattern() {
|
|
2992
|
+
if (!this._states.once) return this._states.pattern ? this._states.pattern.pattern : void 0;
|
|
2993
|
+
}
|
|
2994
|
+
getOnce() {
|
|
2995
|
+
return this._states.once ? this._states.once.getDate() : null;
|
|
2996
|
+
}
|
|
2997
|
+
isRunning() {
|
|
2998
|
+
let e = this.nextRun(this._states.currentRun), t = !this._states.paused, r = this.fn !== void 0, n = !this._states.kill;
|
|
2999
|
+
return t && r && n && e !== null;
|
|
3000
|
+
}
|
|
3001
|
+
isStopped() {
|
|
3002
|
+
return this._states.kill;
|
|
3003
|
+
}
|
|
3004
|
+
isBusy() {
|
|
3005
|
+
return this._states.blocking;
|
|
3006
|
+
}
|
|
3007
|
+
currentRun() {
|
|
3008
|
+
return this._states.currentRun ? this._states.currentRun.getDate() : null;
|
|
3009
|
+
}
|
|
3010
|
+
previousRun() {
|
|
3011
|
+
return this._states.previousRun ? this._states.previousRun.getDate() : null;
|
|
3012
|
+
}
|
|
3013
|
+
msToNext(e) {
|
|
3014
|
+
let t = this._next(e);
|
|
3015
|
+
return t ? e instanceof m || e instanceof Date ? t.getTime() - e.getTime() : t.getTime() - new m(e).getTime() : null;
|
|
3016
|
+
}
|
|
3017
|
+
stop() {
|
|
3018
|
+
this._states.kill = !0, this._states.currentTimeout && clearTimeout(this._states.currentTimeout);
|
|
3019
|
+
let e = w.indexOf(this);
|
|
3020
|
+
e >= 0 && w.splice(e, 1);
|
|
3021
|
+
}
|
|
3022
|
+
pause() {
|
|
3023
|
+
return this._states.paused = !0, !this._states.kill;
|
|
3024
|
+
}
|
|
3025
|
+
resume() {
|
|
3026
|
+
return this._states.paused = !1, !this._states.kill;
|
|
3027
|
+
}
|
|
3028
|
+
schedule(e) {
|
|
3029
|
+
if (e && this.fn) throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");
|
|
3030
|
+
e && (this.fn = e);
|
|
3031
|
+
let t = this.msToNext(), r = this.nextRun(this._states.currentRun);
|
|
3032
|
+
return t == null || isNaN(t) || r === null ? this : (t > W && (t = W), this._states.currentTimeout = setTimeout(() => this._checkTrigger(r), t), this._states.currentTimeout && this.options.unref && x(this._states.currentTimeout), this);
|
|
3033
|
+
}
|
|
3034
|
+
async _trigger(e) {
|
|
3035
|
+
this._states.blocking = !0, this._states.currentRun = new m(void 0, this.getTz());
|
|
3036
|
+
try {
|
|
3037
|
+
if (this.options.catch) try {
|
|
3038
|
+
this.fn !== void 0 && await this.fn(this, this.options.context);
|
|
3039
|
+
} catch (t) {
|
|
3040
|
+
if (p(this.options.catch)) try {
|
|
3041
|
+
this.options.catch(t, this);
|
|
3042
|
+
} catch {}
|
|
3043
|
+
}
|
|
3044
|
+
else this.fn !== void 0 && await this.fn(this, this.options.context);
|
|
3045
|
+
} finally {
|
|
3046
|
+
this._states.previousRun = new m(e, this.getTz()), this._states.blocking = !1;
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
async trigger() {
|
|
3050
|
+
await this._trigger();
|
|
3051
|
+
}
|
|
3052
|
+
runsLeft() {
|
|
3053
|
+
return this._states.maxRuns;
|
|
3054
|
+
}
|
|
3055
|
+
_checkTrigger(e) {
|
|
3056
|
+
let t = /* @__PURE__ */ new Date(), r = !this._states.paused && t.getTime() >= e.getTime(), n = this._states.blocking && this.options.protect;
|
|
3057
|
+
r && !n ? (this._states.maxRuns !== void 0 && this._states.maxRuns--, this._trigger()) : r && n && p(this.options.protect) && setTimeout(() => this.options.protect(this), 0), this.schedule();
|
|
3058
|
+
}
|
|
3059
|
+
_next(e) {
|
|
3060
|
+
let t = !!(e || this._states.currentRun), r = !1;
|
|
3061
|
+
!e && this.options.startAt && this.options.interval && ([e, t] = this._calculatePreviousRun(e, t), r = !e), e = new m(e, this.getTz()), this.options.startAt && e && e.getTime() < this.options.startAt.getTime() && (e = this.options.startAt);
|
|
3062
|
+
let n = this._states.once || new m(e, this.getTz());
|
|
3063
|
+
return !r && n !== this._states.once && (n = n.increment(this._states.pattern, this.options, t)), this._states.once && this._states.once.getTime() <= e.getTime() || n === null || this._states.maxRuns !== void 0 && this._states.maxRuns <= 0 || this._states.kill || this.options.stopAt && n.getTime() >= this.options.stopAt.getTime() ? null : n;
|
|
3064
|
+
}
|
|
3065
|
+
_previous(e) {
|
|
3066
|
+
let t = new m(e, this.getTz());
|
|
3067
|
+
this.options.stopAt && t.getTime() > this.options.stopAt.getTime() && (t = this.options.stopAt);
|
|
3068
|
+
let r = new m(t, this.getTz());
|
|
3069
|
+
return this._states.once ? this._states.once.getTime() < t.getTime() ? this._states.once : null : (r = r.decrement(this._states.pattern, this.options), r === null || this.options.startAt && r.getTime() < this.options.startAt.getTime() ? null : r);
|
|
3070
|
+
}
|
|
3071
|
+
_calculatePreviousRun(e, t) {
|
|
3072
|
+
let r = new m(void 0, this.getTz()), n = e;
|
|
3073
|
+
if (this.options.startAt.getTime() <= r.getTime()) {
|
|
3074
|
+
n = this.options.startAt;
|
|
3075
|
+
let i = n.getTime() + this.options.interval * 1e3;
|
|
3076
|
+
for (; i <= r.getTime();) n = new m(n, this.getTz()).increment(this._states.pattern, this.options, !0), i = n.getTime() + this.options.interval * 1e3;
|
|
3077
|
+
t = !0;
|
|
3078
|
+
}
|
|
3079
|
+
return n === null && (n = void 0), [n, t];
|
|
3080
|
+
}
|
|
3081
|
+
};
|
|
3082
|
+
//#endregion
|
|
3083
|
+
//#region ../../../layers/automation/po-calendar/src/services/calendarSchedule/index.ts
|
|
3084
|
+
const LOCAL_TIME = new RegExp(CALENDAR_LOCAL_TIME_PATTERN, "u");
|
|
3085
|
+
/**
|
|
3086
|
+
* Wall-clock time in an IANA zone as an instant. A time that daylight saving skips is refused, never shifted.
|
|
3087
|
+
* ponytail: twin of the editor's `calendarInstant` (frontend `_lib/calendarDates`), kept apart so the browser and
|
|
3088
|
+
* native bundles do not pull croner; fold them together if a shared pure module appears.
|
|
3089
|
+
*/
|
|
3090
|
+
function localInstant(local, tz) {
|
|
3091
|
+
const match = LOCAL_TIME.exec(local);
|
|
3092
|
+
if (!match) throw new Error("Give a one-off time as YYYY-MM-DDTHH:mm in the schedule zone, such as 2026-05-01T09:00.");
|
|
3093
|
+
const wanted = Date.parse(`${match[1]}T${match[2]}:${match[3] ?? "00"}Z`);
|
|
3094
|
+
if (!Number.isFinite(wanted)) throw new Error(`${local} is not a real date and time.`);
|
|
3095
|
+
const format = new Intl.DateTimeFormat("sv-SE", {
|
|
3096
|
+
timeZone: tz,
|
|
3097
|
+
year: "numeric",
|
|
3098
|
+
month: "2-digit",
|
|
3099
|
+
day: "2-digit",
|
|
3100
|
+
hour: "2-digit",
|
|
3101
|
+
minute: "2-digit",
|
|
3102
|
+
second: "2-digit",
|
|
3103
|
+
hourCycle: "h23"
|
|
3104
|
+
});
|
|
3105
|
+
let instant = wanted;
|
|
3106
|
+
for (let i = 0; i < 4; i++) {
|
|
3107
|
+
const delta = wanted - Date.parse(`${format.format(instant).replace(" ", "T")}Z`);
|
|
3108
|
+
if (delta === 0) return instant;
|
|
3109
|
+
instant += delta;
|
|
3110
|
+
}
|
|
3111
|
+
throw new Error(`${local} does not exist in ${tz} because of a daylight saving change. Choose another time.`);
|
|
3112
|
+
}
|
|
3113
|
+
/**
|
|
3114
|
+
* An agent's schedule in stored form: a missing `tz` becomes the person's zone, and a local `once.at` becomes an
|
|
3115
|
+
* instant in that zone. Anything else passes through for `validateSchedule` to judge.
|
|
3116
|
+
*/
|
|
3117
|
+
function resolveScheduleInput(schedule, personTimeZone) {
|
|
3118
|
+
if (!schedule || typeof schedule !== "object" || Array.isArray(schedule)) return schedule;
|
|
3119
|
+
const value = schedule;
|
|
3120
|
+
if (value.kind !== "once" && value.kind !== "cron") return schedule;
|
|
3121
|
+
const tz = value.tz ?? personTimeZone;
|
|
3122
|
+
if (typeof tz !== "string") throw new Error("The timezone is not known yet. Ask the person for it, then pass schedule.tz as an IANA zone such as Australia/Sydney.");
|
|
3123
|
+
new Intl.DateTimeFormat("en", { timeZone: tz }).format();
|
|
3124
|
+
return value.kind === "once" && typeof value.at === "string" ? {
|
|
3125
|
+
...value,
|
|
3126
|
+
tz,
|
|
3127
|
+
at: localInstant(value.at, tz)
|
|
3128
|
+
} : {
|
|
3129
|
+
...value,
|
|
3130
|
+
tz
|
|
3131
|
+
};
|
|
3132
|
+
}
|
|
3133
|
+
function validateSchedule(schedule) {
|
|
3134
|
+
if (!Check(CalendarScheduleSchema, schedule)) throw new Error("Invalid calendar schedule");
|
|
3135
|
+
if (schedule.kind !== "interval") new Intl.DateTimeFormat("en", { timeZone: schedule.tz }).format();
|
|
3136
|
+
if (schedule.kind === "cron") {
|
|
3137
|
+
if (schedule.expr.trim().split(/\s+/u).length !== 5) throw new Error("Provide a five-field cron expression");
|
|
3138
|
+
new E(schedule.expr, {
|
|
3139
|
+
timezone: schedule.tz,
|
|
3140
|
+
paused: true
|
|
3141
|
+
});
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
/** Strictly after `after`, except a once schedule returned only if still in the future. */
|
|
3145
|
+
function nextDue(schedule, after) {
|
|
3146
|
+
validateSchedule(schedule);
|
|
3147
|
+
if (schedule.kind === "once") return schedule.at > after ? schedule.at : null;
|
|
3148
|
+
if (schedule.kind === "interval") return after + schedule.seconds * 1e3;
|
|
3149
|
+
return new E(schedule.expr, {
|
|
3150
|
+
timezone: schedule.tz,
|
|
3151
|
+
paused: true
|
|
3152
|
+
}).nextRun(new Date(after))?.getTime() ?? null;
|
|
3153
|
+
}
|
|
3154
|
+
/** Interval events are immediate. Once and cron events preserve their specified first tick. */
|
|
3155
|
+
function firstDue(schedule, now) {
|
|
3156
|
+
validateSchedule(schedule);
|
|
3157
|
+
return schedule.kind === "interval" ? now : schedule.kind === "once" ? schedule.at : nextDue(schedule, now);
|
|
3158
|
+
}
|
|
3159
|
+
/** The first instant of the calendar day after `at` in `tz`. A skipped midnight lands within its DST gap. */
|
|
3160
|
+
function nextLocalDay(at, tz) {
|
|
3161
|
+
const format = new Intl.DateTimeFormat("en-US", {
|
|
3162
|
+
timeZone: tz,
|
|
3163
|
+
year: "numeric",
|
|
3164
|
+
month: "numeric",
|
|
3165
|
+
day: "numeric",
|
|
3166
|
+
hour: "numeric",
|
|
3167
|
+
minute: "numeric",
|
|
3168
|
+
second: "numeric",
|
|
3169
|
+
hourCycle: "h23"
|
|
3170
|
+
});
|
|
3171
|
+
const wall = (instant) => {
|
|
3172
|
+
const part = (type) => Number(format.formatToParts(instant).find((p) => p.type === type)?.value);
|
|
3173
|
+
return Date.UTC(part("year"), part("month") - 1, part("day"), part("hour"), part("minute"), part("second"));
|
|
3174
|
+
};
|
|
3175
|
+
const local = new Date(wall(at));
|
|
3176
|
+
const midnight = Date.UTC(local.getUTCFullYear(), local.getUTCMonth(), local.getUTCDate() + 1);
|
|
3177
|
+
const guess = Math.floor(at / 1e3) * 1e3 + midnight - local.getTime();
|
|
3178
|
+
return guess + midnight - wall(guess);
|
|
3179
|
+
}
|
|
3180
|
+
/** Compress a downtime range without losing its first, last or count. `now` itself is not missed. */
|
|
3181
|
+
function missedRange(schedule, first, now) {
|
|
3182
|
+
if (first >= now) return {
|
|
3183
|
+
count: 0,
|
|
3184
|
+
last: first,
|
|
3185
|
+
next: first
|
|
3186
|
+
};
|
|
3187
|
+
if (schedule.kind === "once") return {
|
|
3188
|
+
count: 1,
|
|
3189
|
+
last: first,
|
|
3190
|
+
next: null
|
|
3191
|
+
};
|
|
3192
|
+
if (schedule.kind === "interval") {
|
|
3193
|
+
const step = schedule.seconds * 1e3;
|
|
3194
|
+
const count = Math.ceil((now - first) / step);
|
|
3195
|
+
return {
|
|
3196
|
+
count,
|
|
3197
|
+
last: first + (count - 1) * step,
|
|
3198
|
+
next: first + count * step
|
|
3199
|
+
};
|
|
3200
|
+
}
|
|
3201
|
+
const cron = new E(schedule.expr, {
|
|
3202
|
+
timezone: schedule.tz,
|
|
3203
|
+
paused: true
|
|
3204
|
+
});
|
|
3205
|
+
let count = 0;
|
|
3206
|
+
let last = first;
|
|
3207
|
+
let cursor = first;
|
|
3208
|
+
while (cursor !== null && cursor < now) {
|
|
3209
|
+
count++;
|
|
3210
|
+
last = cursor;
|
|
3211
|
+
cursor = cron.nextRun(new Date(cursor))?.getTime() ?? null;
|
|
3212
|
+
}
|
|
3213
|
+
return {
|
|
3214
|
+
count,
|
|
3215
|
+
last,
|
|
3216
|
+
next: cursor
|
|
3217
|
+
};
|
|
3218
|
+
}
|
|
3219
|
+
//#endregion
|
|
3220
|
+
//#region ../../../layers/automation/po-calendar/src/services/calendarScope/index.ts
|
|
3221
|
+
const MAX_RANGE_DAYS = 62;
|
|
3222
|
+
const MAX_RANGE_MS = 53568e5;
|
|
3223
|
+
const PAGE_SIZE = 200;
|
|
3224
|
+
var CalendarRequestError = class extends Error {
|
|
3225
|
+
status;
|
|
3226
|
+
constructor(message, status = 400) {
|
|
3227
|
+
super(message);
|
|
3228
|
+
this.status = status;
|
|
3229
|
+
}
|
|
3230
|
+
};
|
|
3231
|
+
function sameCalendarOwner(left, right) {
|
|
3232
|
+
return left.level === right.level && (left.level === "global" && right.level === "global" && canonicalCalendarJson(left.principal) === canonicalCalendarJson(right.principal) || left.level !== "global" && right.level !== "global" && left.workspaceId === right.workspaceId && left.hostId === right.hostId && (left.level !== "session" || right.level === "session" && left.sessionId === right.sessionId));
|
|
3233
|
+
}
|
|
3234
|
+
function createCalendarScope({ owner, store, scheduler, directory, validateAction, validateAssignment, abort, startChange, client, central, now = Date.now }) {
|
|
3235
|
+
const visible = (event) => {
|
|
3236
|
+
if (owner.level === "global" && owner.principal && event.centralJob) {
|
|
3237
|
+
const principal = event.centralJob.origin.principal ?? (event.owner.level === "global" ? event.owner.principal : void 0);
|
|
3238
|
+
return event.centralJob.visibility === "shared" || !!principal && canonicalCalendarJson(principal) === canonicalCalendarJson(owner.principal);
|
|
3239
|
+
}
|
|
3240
|
+
return owner.level === "global" && (event.owner.level !== "global" || !owner.principal || sameCalendarOwner(owner, event.owner)) || sameCalendarOwner(owner, event.owner) || owner.level === "workspace" && event.owner.level === "session" && owner.workspaceId === event.owner.workspaceId && owner.hostId === event.owner.hostId;
|
|
3241
|
+
};
|
|
3242
|
+
const owned = async (id) => {
|
|
3243
|
+
const event = await store.get(id);
|
|
3244
|
+
if (!event || !visible(event)) throw new CalendarRequestError("Calendar event was not found.", 404);
|
|
3245
|
+
if (!sameCalendarOwner(owner, event.owner)) throw new CalendarRequestError("Change this event through its owning level.", 403);
|
|
3246
|
+
if (event.status === "cancelled" || event.status === "done") throw new CalendarRequestError(`This event is ${event.status} and can no longer change.`, 409);
|
|
3247
|
+
return event;
|
|
3248
|
+
};
|
|
3249
|
+
const remote = (target) => !!target.hostId && target.hostId !== store.hostId;
|
|
3250
|
+
const validateTarget = async (target) => {
|
|
3251
|
+
if (remote(target)) {
|
|
3252
|
+
if (!client?.hostId()) throw new CalendarRequestError("Cross-host events need a networked host.", 409);
|
|
3253
|
+
if (owner.level === "session" && target.kind === "existingSession" && target.sessionId !== owner.sessionId) throw new CalendarRequestError("A session event can only drive its own existing session.", 403);
|
|
3254
|
+
if (owner.level !== "global" && target.kind === "newSession" && target.workspaceId !== owner.workspaceId) throw new CalendarRequestError("The target is outside this workspace.", 403);
|
|
3255
|
+
return;
|
|
3256
|
+
}
|
|
3257
|
+
const workspaceId = target.kind === "newSession" ? target.workspaceId : [...directory.sessions(), ...directory.dormant()].find((entry) => entry.sessionId === target.sessionId)?.workspaceId;
|
|
3258
|
+
if (!workspaceId) throw new CalendarRequestError("The target session is no longer available.");
|
|
3259
|
+
if (owner.level !== "global" && workspaceId !== owner.workspaceId) throw new CalendarRequestError("The target is outside this workspace.", 403);
|
|
3260
|
+
if (target.kind === "existingSession" && owner.level === "session" && target.sessionId !== owner.sessionId) throw new CalendarRequestError("A session event can only drive its own existing session.", 403);
|
|
3261
|
+
if (target.kind === "newSession") {
|
|
3262
|
+
if (!directory.workspaces().find((entry) => entry.id === workspaceId && entry.active)) throw new CalendarRequestError("Choose an available workspace.");
|
|
3263
|
+
if (!directory.validateCwd) throw new CalendarRequestError("This host cannot validate a session directory.", 409);
|
|
3264
|
+
await directory.validateCwd(target);
|
|
3265
|
+
}
|
|
3266
|
+
};
|
|
3267
|
+
const parse = (read) => {
|
|
3268
|
+
try {
|
|
3269
|
+
return read();
|
|
3270
|
+
} catch (error) {
|
|
3271
|
+
throw new CalendarRequestError(error instanceof Error ? error.message : String(error));
|
|
3272
|
+
}
|
|
3273
|
+
};
|
|
3274
|
+
const validateFuture = (schedule) => parse(() => {
|
|
3275
|
+
validateSchedule(schedule);
|
|
3276
|
+
if (schedule.kind === "once" && schedule.at <= now() || firstDue(schedule, now()) === null) throw new Error("Choose a schedule with a future run.");
|
|
3277
|
+
});
|
|
3278
|
+
const checkAssignment = async ({ centralJob: _policy, ...event }) => {
|
|
3279
|
+
try {
|
|
3280
|
+
await validateAssignment?.(event);
|
|
3281
|
+
} catch (error) {
|
|
3282
|
+
throw new CalendarRequestError(error instanceof Error ? error.message : String(error));
|
|
3283
|
+
}
|
|
3284
|
+
};
|
|
3285
|
+
const checkAction = async (action) => {
|
|
3286
|
+
if (!validateAction) throw new CalendarRequestError("Use a Calendar session with this action installed.", 409);
|
|
3287
|
+
try {
|
|
3288
|
+
await validateAction(action);
|
|
3289
|
+
} catch (error) {
|
|
3290
|
+
throw new CalendarRequestError(error instanceof Error ? error.message : String(error));
|
|
3291
|
+
}
|
|
3292
|
+
};
|
|
3293
|
+
const draftOf = (input) => {
|
|
3294
|
+
const draft = parse(() => parseCalendarDraft(input));
|
|
3295
|
+
validateFuture(draft.schedule);
|
|
3296
|
+
return draft;
|
|
3297
|
+
};
|
|
3298
|
+
/** The workspace each event runs in: its owner's, else its target's. Build once per request. */
|
|
3299
|
+
const eventWorkspaces = () => {
|
|
3300
|
+
const bySession = new Map([...directory.dormant(), ...directory.sessions()].map((entry) => [entry.sessionId, entry.workspaceId]));
|
|
3301
|
+
return (event) => event.owner.level !== "global" ? event.owner.workspaceId : event.target.kind === "newSession" ? event.target.workspaceId : bySession.get(event.target.sessionId);
|
|
3302
|
+
};
|
|
3303
|
+
return {
|
|
3304
|
+
owner,
|
|
3305
|
+
async list(from, to, cursor, tz, filters = {}) {
|
|
3306
|
+
if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 0 || to <= from || to - from > MAX_RANGE_MS) throw new CalendarRequestError("Choose a date range of at most 62 days.");
|
|
3307
|
+
if (tz !== void 0) try {
|
|
3308
|
+
new Intl.DateTimeFormat("en", { timeZone: tz });
|
|
3309
|
+
} catch {
|
|
3310
|
+
throw new CalendarRequestError("Choose a valid timezone.");
|
|
3311
|
+
}
|
|
3312
|
+
const { status, workspace, kind, q, limit = PAGE_SIZE } = parse(() => parseCalendarListFilters(filters));
|
|
3313
|
+
const after = cursor === void 0 ? void 0 : /^(\d+):(.+)$/.exec(cursor);
|
|
3314
|
+
if (after === null) throw new CalendarRequestError("Use the cursor a previous page returned.");
|
|
3315
|
+
const inRange = (await store.list()).filter(visible).map((event) => {
|
|
3316
|
+
const schedule = event.schedule;
|
|
3317
|
+
const project = (at) => {
|
|
3318
|
+
if (schedule.kind === "once") return schedule.at >= at ? schedule.at : null;
|
|
3319
|
+
if (schedule.kind === "cron") return nextDue(schedule, at - 1);
|
|
3320
|
+
const step = schedule.seconds * 1e3;
|
|
3321
|
+
const anchor = event.nextDueAt ?? event.updatedAt;
|
|
3322
|
+
return anchor + Math.ceil((at - anchor) / step) * step;
|
|
3323
|
+
};
|
|
3324
|
+
const projectedDueAt = schedule.kind === "once" ? schedule.at : project(Math.max(from, event.createdAt));
|
|
3325
|
+
if (projectedDueAt === null) return event;
|
|
3326
|
+
if (tz === void 0 || event.status !== "active" || projectedDueAt < from || projectedDueAt >= to) return {
|
|
3327
|
+
...event,
|
|
3328
|
+
projectedDueAt
|
|
3329
|
+
};
|
|
3330
|
+
const occurrences = [];
|
|
3331
|
+
for (let at = projectedDueAt; at !== null && at < to && occurrences.length <= MAX_RANGE_DAYS; at = project(nextLocalDay(at, tz))) occurrences.push(at);
|
|
3332
|
+
return {
|
|
3333
|
+
...event,
|
|
3334
|
+
projectedDueAt,
|
|
3335
|
+
occurrences
|
|
3336
|
+
};
|
|
3337
|
+
}).filter((event) => event.projectedDueAt !== void 0 && event.projectedDueAt >= from && event.projectedDueAt < to && event.createdAt < to);
|
|
3338
|
+
const workspaceOf = eventWorkspaces();
|
|
3339
|
+
const names = new Map(directory.workspaces().map((entry) => [entry.id, entry.name]));
|
|
3340
|
+
const query = q?.trim().toLowerCase();
|
|
3341
|
+
const matched = inRange.filter((event) => {
|
|
3342
|
+
const runsIn = workspaceOf(event);
|
|
3343
|
+
if (workspace !== void 0 && runsIn !== workspace) return false;
|
|
3344
|
+
if (status === "open" ? event.status !== "active" && event.status !== "paused" : status !== void 0 && event.status !== status) return false;
|
|
3345
|
+
if (kind !== void 0 && event.schedule.kind !== kind) return false;
|
|
3346
|
+
const target = event.target.kind === "existingSession" ? event.target.sessionId : void 0;
|
|
3347
|
+
return !query || [
|
|
3348
|
+
event.title,
|
|
3349
|
+
event.prompt,
|
|
3350
|
+
target,
|
|
3351
|
+
runsIn,
|
|
3352
|
+
runsIn && names.get(runsIn)
|
|
3353
|
+
].some((text) => text?.toLowerCase().includes(query));
|
|
3354
|
+
}).sort((a, b) => a.projectedDueAt - b.projectedDueAt || (a.id < b.id ? -1 : 1));
|
|
3355
|
+
const at = Number(after?.[1]);
|
|
3356
|
+
const rest = after ? matched.filter((event) => event.projectedDueAt > at || event.projectedDueAt === at && event.id > after[2]) : matched;
|
|
3357
|
+
const page = rest.slice(0, limit);
|
|
3358
|
+
const last = page.at(-1);
|
|
3359
|
+
return {
|
|
3360
|
+
events: page,
|
|
3361
|
+
...last && rest.length > limit ? { cursor: `${last.projectedDueAt}:${last.id}` } : {},
|
|
3362
|
+
total: inRange.length,
|
|
3363
|
+
matched: matched.length
|
|
3364
|
+
};
|
|
3365
|
+
},
|
|
3366
|
+
async listOwned() {
|
|
3367
|
+
return (await store.list()).filter((event) => sameCalendarOwner(owner, event.owner));
|
|
3368
|
+
},
|
|
3369
|
+
async create(input) {
|
|
3370
|
+
const { grant, destinationHostId, ...body } = input && typeof input === "object" && !Array.isArray(input) ? input : {};
|
|
3371
|
+
if (destinationHostId !== void 0 && destinationHostId !== store.hostId) throw new CalendarRequestError("Write destination does not match this host.");
|
|
3372
|
+
const draft = draftOf(body);
|
|
3373
|
+
await validateTarget(draft.target);
|
|
3374
|
+
if (remote(draft.target)) {
|
|
3375
|
+
if (!draft.prompt || draft.workflow || draft.action || draft.assignment) throw new CalendarRequestError("Cross-host events support prompt only, without workflow, action or assignment.");
|
|
3376
|
+
if (!grant) throw new CalendarRequestError("Cross-host events require a device-signed unattended grant.");
|
|
3377
|
+
if (owner.level === "global" && draft.target.kind === "existingSession") throw new CalendarRequestError("A remote existing-session event needs workspace ownership.");
|
|
3378
|
+
}
|
|
3379
|
+
await checkAssignment({
|
|
3380
|
+
...draft,
|
|
3381
|
+
owner
|
|
3382
|
+
});
|
|
3383
|
+
if (draft.action) await checkAction(draft.action);
|
|
3384
|
+
if (central?.enabled() && !remote(draft.target)) {
|
|
3385
|
+
const prepared = await central.prepare({
|
|
3386
|
+
...draft,
|
|
3387
|
+
owner
|
|
3388
|
+
}, grant);
|
|
3389
|
+
return await central.call("create", [{
|
|
3390
|
+
...draft,
|
|
3391
|
+
assignment: prepared.assignment,
|
|
3392
|
+
centralJob: prepared.centralJob
|
|
3393
|
+
}]);
|
|
3394
|
+
}
|
|
3395
|
+
const consent = remote(draft.target) ? parse(() => parseCalendarRemoteGrant(grant, store.hostId, draft.target.hostId, owner.level !== "global" ? owner.workspaceId : draft.target.kind === "newSession" ? draft.target.workspaceId : "", now())) : void 0;
|
|
3396
|
+
const requestedId = consent?.payload.constraints.eventId;
|
|
3397
|
+
if (requestedId && await store.get(requestedId)) throw new CalendarRequestError("Calendar event id already exists.", 409);
|
|
3398
|
+
let event;
|
|
3399
|
+
try {
|
|
3400
|
+
event = await store.create(parseCalendarEventInput({
|
|
3401
|
+
...draft,
|
|
3402
|
+
owner
|
|
3403
|
+
}), requestedId, consent ? (created) => client.saveGrant(`${created.homeHostId}/${created.id}`, consent) : void 0);
|
|
3404
|
+
} catch (error) {
|
|
3405
|
+
throw new CalendarRequestError(error instanceof Error ? error.message : String(error), error instanceof Error && error.message === "Calendar event id already exists." ? 409 : 400);
|
|
3406
|
+
}
|
|
3407
|
+
await scheduler.changed();
|
|
3408
|
+
return event;
|
|
3409
|
+
},
|
|
3410
|
+
async update(id, input) {
|
|
3411
|
+
if (central?.enabled() && !await store.get(id)) return await central.call("update", [id, input]);
|
|
3412
|
+
const current = await owned(id);
|
|
3413
|
+
if (current.source) throw new CalendarRequestError(`${current.source.packageName} manages this event. Pause, resume, run or cancel it instead.`, 403);
|
|
3414
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) throw new CalendarRequestError("Invalid calendar event patch");
|
|
3415
|
+
const { destinationHostId, ...fields } = input && typeof input === "object" && !Array.isArray(input) ? input : {};
|
|
3416
|
+
if (destinationHostId !== void 0 && destinationHostId !== store.hostId) throw new CalendarRequestError("Write destination does not match this host.");
|
|
3417
|
+
const patch = parse(() => parseCalendarEventPatch(fields));
|
|
3418
|
+
const candidate = mergeCalendarEvent(current, patch);
|
|
3419
|
+
parse(() => validateCalendarExecution(candidate));
|
|
3420
|
+
if (patch.schedule) validateFuture(patch.schedule);
|
|
3421
|
+
if (patch.target) await validateTarget(patch.target);
|
|
3422
|
+
if (remote(candidate.target)) {
|
|
3423
|
+
if (!remote(current.target) || candidate.target.hostId !== current.target.hostId) throw new CalendarRequestError("Create a new event with a grant to change its destination.");
|
|
3424
|
+
if (!candidate.prompt || candidate.workflow || candidate.action || candidate.assignment) throw new CalendarRequestError("Cross-host events support prompt only.");
|
|
3425
|
+
}
|
|
3426
|
+
await checkAssignment(candidate);
|
|
3427
|
+
if (patch.action && canonicalCalendarJson(patch.action) !== canonicalCalendarJson(current.action)) await checkAction(patch.action);
|
|
3428
|
+
const event = await store.update(id, patch);
|
|
3429
|
+
await scheduler.changed();
|
|
3430
|
+
return event;
|
|
3431
|
+
},
|
|
3432
|
+
async action(id, action) {
|
|
3433
|
+
if (central?.enabled() && !await store.get(id)) return await central.call("action", [id, action]);
|
|
3434
|
+
const event = await owned(id);
|
|
3435
|
+
if (action === "run-now") {
|
|
3436
|
+
await validateTarget(event.target);
|
|
3437
|
+
if ((await scheduler.runNow(id)).state === "skipped") throw new CalendarRequestError("An earlier run of this event is still going, so this one was skipped.", 409);
|
|
3438
|
+
return await store.get(id);
|
|
3439
|
+
}
|
|
3440
|
+
if (action === "resume") await validateTarget(event.target);
|
|
3441
|
+
const updated = await store.update(id, {
|
|
3442
|
+
status: action === "pause" ? "paused" : action === "resume" ? "active" : "cancelled",
|
|
3443
|
+
pauseReason: action === "pause" ? "manual" : ""
|
|
3444
|
+
});
|
|
3445
|
+
if (action === "cancel") abort?.(id);
|
|
3446
|
+
await scheduler.changed();
|
|
3447
|
+
return updated;
|
|
3448
|
+
},
|
|
3449
|
+
async history(id, cursor) {
|
|
3450
|
+
if (central?.enabled() && !await store.get(id)) return await central.call("history", [id, cursor]);
|
|
3451
|
+
const event = await store.get(id);
|
|
3452
|
+
if (!event || !visible(event)) throw new CalendarRequestError("Calendar event was not found.", 404);
|
|
3453
|
+
const occurrences = await store.history(id, cursor, 201);
|
|
3454
|
+
const page = occurrences.slice(0, PAGE_SIZE);
|
|
3455
|
+
return {
|
|
3456
|
+
occurrences: page,
|
|
3457
|
+
...occurrences.length > PAGE_SIZE ? { cursor: page.at(-1).id } : {}
|
|
3458
|
+
};
|
|
3459
|
+
},
|
|
3460
|
+
async ask(id, input) {
|
|
3461
|
+
const event = await owned(id);
|
|
3462
|
+
if (event.source) throw new CalendarRequestError(`${event.source.packageName} manages this event. Pause, resume, run or cancel it instead.`, 403);
|
|
3463
|
+
const request = parse(() => parseCalendarAsk(input));
|
|
3464
|
+
if (!startChange) throw new CalendarRequestError("Ask Po from the Calendar page on this host.", 409);
|
|
3465
|
+
const target = event.target;
|
|
3466
|
+
const workspaceId = eventWorkspaces()(event);
|
|
3467
|
+
const workspace = directory.workspaces().find((entry) => entry.id === workspaceId);
|
|
3468
|
+
if (!workspace) throw new CalendarRequestError("This event's workspace is unavailable.", 409);
|
|
3469
|
+
const { title, schedule, prompt, workflow, action, assignment, status } = event;
|
|
3470
|
+
return startChange({
|
|
3471
|
+
eventId: id,
|
|
3472
|
+
workspaceId: workspace.id,
|
|
3473
|
+
cwd: target.kind === "newSession" ? target.cwd : workspace.path,
|
|
3474
|
+
name: `Change: ${title}`.slice(0, 80),
|
|
3475
|
+
prompt: [
|
|
3476
|
+
`The person asked, from the Calendar page, to change Calendar event ${id}:`,
|
|
3477
|
+
request,
|
|
3478
|
+
`The event now: ${JSON.stringify({
|
|
3479
|
+
title,
|
|
3480
|
+
schedule,
|
|
3481
|
+
target,
|
|
3482
|
+
prompt,
|
|
3483
|
+
workflow,
|
|
3484
|
+
action,
|
|
3485
|
+
assignment,
|
|
3486
|
+
status
|
|
3487
|
+
})}`,
|
|
3488
|
+
`This session may change this one event. Use calendar.update('${id}', patch) for its title, schedule, target or prompt, and calendar.action('${id}', 'pause' | 'resume' | 'run-now' | 'cancel') otherwise. Ask before cancelling it. Then say what changed.`
|
|
3489
|
+
].join("\n\n")
|
|
3490
|
+
});
|
|
3491
|
+
},
|
|
3492
|
+
async writeSourced(source, input, mode) {
|
|
3493
|
+
if (owner.level === "global") throw new CalendarRequestError("Plugins own events in a session or workspace.", 403);
|
|
3494
|
+
const draft = draftOf(input);
|
|
3495
|
+
if (remote(draft.target)) throw new CalendarRequestError("Plugin events need a local target until typed unattended consent is available.");
|
|
3496
|
+
await validateTarget(draft.target);
|
|
3497
|
+
await checkAssignment({
|
|
3498
|
+
...draft,
|
|
3499
|
+
owner
|
|
3500
|
+
});
|
|
3501
|
+
const previous = (await store.list()).filter((event) => event.source?.packageName === source.packageName && sameCalendarOwner(owner, event.owner)).find((event) => event.source?.externalId === source.externalId);
|
|
3502
|
+
if (draft.action && canonicalCalendarJson(draft.action) !== canonicalCalendarJson(previous?.action)) await checkAction(draft.action);
|
|
3503
|
+
if (!previous && central?.enabled()) {
|
|
3504
|
+
const prepared = await central.prepare({
|
|
3505
|
+
...draft,
|
|
3506
|
+
owner
|
|
3507
|
+
});
|
|
3508
|
+
return await central.call("writeSourced", [
|
|
3509
|
+
source,
|
|
3510
|
+
{
|
|
3511
|
+
...draft,
|
|
3512
|
+
assignment: prepared.assignment,
|
|
3513
|
+
centralJob: prepared.centralJob
|
|
3514
|
+
},
|
|
3515
|
+
mode
|
|
3516
|
+
]);
|
|
3517
|
+
}
|
|
3518
|
+
let written;
|
|
3519
|
+
try {
|
|
3520
|
+
written = await store.writeSourced(parseCalendarEventInput({
|
|
3521
|
+
...draft,
|
|
3522
|
+
owner
|
|
3523
|
+
}), source, mode);
|
|
3524
|
+
} catch (error) {
|
|
3525
|
+
throw new CalendarRequestError(error instanceof Error ? error.message : String(error), 409);
|
|
3526
|
+
}
|
|
3527
|
+
if (written.changed) await scheduler.changed();
|
|
3528
|
+
return written.event;
|
|
3529
|
+
},
|
|
3530
|
+
async cancelSourced(source) {
|
|
3531
|
+
if (!(await store.list()).some((event) => sameCalendarOwner(owner, event.owner) && event.source?.packageName === source.packageName && event.source.externalId === source.externalId) && central?.enabled()) return await central.call("cancelSourced", [source]);
|
|
3532
|
+
const event = await store.cancelSourced(owner, source);
|
|
3533
|
+
if (event) {
|
|
3534
|
+
abort?.(event.id);
|
|
3535
|
+
await scheduler.changed();
|
|
3536
|
+
}
|
|
3537
|
+
return event;
|
|
3538
|
+
},
|
|
3539
|
+
async listSourced(packageName) {
|
|
3540
|
+
return (await store.list()).filter((event) => event.source?.packageName === packageName && sameCalendarOwner(owner, event.owner));
|
|
3541
|
+
},
|
|
3542
|
+
async listVisibleSourced(packageName) {
|
|
3543
|
+
return (await store.list()).filter((event) => event.source?.packageName === packageName && visible(event));
|
|
3544
|
+
},
|
|
3545
|
+
targets() {
|
|
3546
|
+
const workspaces = directory.workspaces().filter((entry) => owner.level === "global" || owner.workspaceId === entry.id);
|
|
3547
|
+
const live = directory.sessions();
|
|
3548
|
+
const liveIds = new Set(live.map((entry) => entry.sessionId));
|
|
3549
|
+
return {
|
|
3550
|
+
workspaces,
|
|
3551
|
+
sessions: [...live.map((entry) => ({
|
|
3552
|
+
...entry,
|
|
3553
|
+
name: entry.sessionId,
|
|
3554
|
+
asleep: false
|
|
3555
|
+
})), ...directory.dormant().filter((entry) => !liveIds.has(entry.sessionId)).map((entry) => ({
|
|
3556
|
+
...entry,
|
|
3557
|
+
asleep: true
|
|
3558
|
+
}))].filter((entry) => owner.level === "global" || entry.workspaceId === owner.workspaceId && (owner.level !== "session" || entry.sessionId === owner.sessionId)).map(({ sessionId, workspaceId, name, asleep }) => ({
|
|
3559
|
+
sessionId,
|
|
3560
|
+
workspaceId,
|
|
3561
|
+
name,
|
|
3562
|
+
asleep
|
|
3563
|
+
}))
|
|
3564
|
+
};
|
|
3565
|
+
}
|
|
3566
|
+
};
|
|
3567
|
+
}
|
|
3568
|
+
//#endregion
|
|
3569
|
+
//#region ../../../layers/automation/po-calendar/src/services/calendarFederation/index.ts
|
|
3570
|
+
function createCalendarFederation({ store, forOwner, member = false }) {
|
|
3571
|
+
return { async handle(operation, owner, input, caller) {
|
|
3572
|
+
if (!caller?.principal?.issuer || !caller.principal.subject) throw new CalendarRequestError("A verified federation caller is required.", 403);
|
|
3573
|
+
const admittedOwner = owner.level === "global" ? {
|
|
3574
|
+
level: "global",
|
|
3575
|
+
principal: caller.principal
|
|
3576
|
+
} : owner;
|
|
3577
|
+
const scope = forOwner(admittedOwner);
|
|
3578
|
+
const body = input && typeof input === "object" && !Array.isArray(input) ? input : {};
|
|
3579
|
+
if (!member && [
|
|
3580
|
+
"create",
|
|
3581
|
+
"update",
|
|
3582
|
+
"action"
|
|
3583
|
+
].includes(operation) && body.destinationHostId !== store.hostId) throw new CalendarRequestError("Write destination does not match this host.");
|
|
3584
|
+
const visible = (event) => {
|
|
3585
|
+
const policy = event.centralJob;
|
|
3586
|
+
if (policy) {
|
|
3587
|
+
const principal = policy.origin.principal ?? (event.owner.level === "global" ? event.owner.principal : void 0);
|
|
3588
|
+
return policy.visibility === "shared" || !!principal && principal.issuer === caller.principal.issuer && principal.subject === caller.principal.subject;
|
|
3589
|
+
}
|
|
3590
|
+
return event.owner.level !== "global" || !!event.owner.principal && sameCalendarOwner(event.owner, {
|
|
3591
|
+
level: "global",
|
|
3592
|
+
principal: caller.principal
|
|
3593
|
+
});
|
|
3594
|
+
};
|
|
3595
|
+
if (operation === "list") {
|
|
3596
|
+
let result = await scope.list(Number(body.from), Number(body.to), body.cursor, body.tz, body.filters ?? {});
|
|
3597
|
+
const events = result.events.filter(visible);
|
|
3598
|
+
while (result.cursor) {
|
|
3599
|
+
result = await scope.list(Number(body.from), Number(body.to), result.cursor, body.tz, body.filters ?? {});
|
|
3600
|
+
events.push(...result.events.filter(visible));
|
|
3601
|
+
}
|
|
3602
|
+
return {
|
|
3603
|
+
events,
|
|
3604
|
+
total: events.length,
|
|
3605
|
+
matched: events.length
|
|
3606
|
+
};
|
|
3607
|
+
}
|
|
3608
|
+
if (operation === "targets" && member) return {
|
|
3609
|
+
owner: admittedOwner,
|
|
3610
|
+
...await scope.targets()
|
|
3611
|
+
};
|
|
3612
|
+
if (operation === "create") return scope.create(body);
|
|
3613
|
+
const id = body.id;
|
|
3614
|
+
if (typeof id !== "string") throw new CalendarRequestError("An event id is required.");
|
|
3615
|
+
const event = await store.get(id);
|
|
3616
|
+
if (!event || !visible(event)) throw new CalendarRequestError("Calendar event was not found.", 404);
|
|
3617
|
+
const eventScope = member && (event.owner.level !== "global" || event.centralJob?.visibility === "shared") ? forOwner(event.owner) : scope;
|
|
3618
|
+
await eventScope.history(id);
|
|
3619
|
+
if (operation === "get") return event;
|
|
3620
|
+
if (operation === "history") return eventScope.history(id, body.cursor);
|
|
3621
|
+
if (operation === "update") return eventScope.update(id, body.patch);
|
|
3622
|
+
if (operation === "ask" && member) return eventScope.ask(id, body);
|
|
3623
|
+
if (operation === "action") {
|
|
3624
|
+
if (![
|
|
3625
|
+
"pause",
|
|
3626
|
+
"resume",
|
|
3627
|
+
"cancel",
|
|
3628
|
+
"run-now"
|
|
3629
|
+
].includes(String(body.action))) throw new CalendarRequestError("Invalid calendar action.");
|
|
3630
|
+
return eventScope.action(id, body.action);
|
|
3631
|
+
}
|
|
3632
|
+
throw new CalendarRequestError("Calendar fire is handled by the destination host.");
|
|
3633
|
+
} };
|
|
3634
|
+
}
|
|
3635
|
+
//#endregion
|
|
3636
|
+
//#region ../../../layers/automation/po-calendar/src/services/calendarApi/index.ts
|
|
3637
|
+
const MAX_BODY_BYTES = 65536;
|
|
3638
|
+
function createCalendarApi(scope, onError, scopeForEvent = () => scope, store, federationScope, member) {
|
|
3639
|
+
return {
|
|
3640
|
+
basePath: "calendar",
|
|
3641
|
+
start() {
|
|
3642
|
+
const app = new Hono();
|
|
3643
|
+
app.onError((error, context) => {
|
|
3644
|
+
if (error instanceof CalendarRequestError) return context.json({ error: error.message }, error.status);
|
|
3645
|
+
onError(error);
|
|
3646
|
+
return context.json({ error: "Calendar could not complete this request. Saved events are unchanged unless the write already completed." }, 500);
|
|
3647
|
+
});
|
|
3648
|
+
app.use("*", bodyLimit({
|
|
3649
|
+
maxSize: MAX_BODY_BYTES,
|
|
3650
|
+
onError: (context) => context.json({ error: "Calendar request is too large." }, 413)
|
|
3651
|
+
}));
|
|
3652
|
+
const json = async (request) => {
|
|
3653
|
+
const text = await request.text();
|
|
3654
|
+
if (new TextEncoder().encode(text).byteLength > MAX_BODY_BYTES) throw new CalendarRequestError("Calendar request is too large.");
|
|
3655
|
+
try {
|
|
3656
|
+
return JSON.parse(text);
|
|
3657
|
+
} catch {
|
|
3658
|
+
throw new CalendarRequestError("Calendar request must be JSON.");
|
|
3659
|
+
}
|
|
3660
|
+
};
|
|
3661
|
+
app.use("*", async (context, next) => {
|
|
3662
|
+
const caller = poApiCallerFrom(context.req.raw.headers);
|
|
3663
|
+
if (!context.req.raw.headers.has("x-po-api-caller-federation")) {
|
|
3664
|
+
if (member) throw new CalendarRequestError("A verified member caller is required.", 403);
|
|
3665
|
+
return next();
|
|
3666
|
+
}
|
|
3667
|
+
if (!caller?.principal || !caller.org || !caller.device) throw new CalendarRequestError("A verified federation caller is required.", 403);
|
|
3668
|
+
if (!store) throw new CalendarRequestError("Calendar federation is unavailable on this mount.", 409);
|
|
3669
|
+
const verifiedMember = member ? await member(caller) : false;
|
|
3670
|
+
if (member && !verifiedMember) throw new CalendarRequestError("Current organization membership is required.", 403);
|
|
3671
|
+
const path = context.req.path;
|
|
3672
|
+
if (path === "/targets" && context.req.method === "GET" && verifiedMember) {
|
|
3673
|
+
const owner = {
|
|
3674
|
+
level: "global",
|
|
3675
|
+
principal: caller.principal
|
|
3676
|
+
};
|
|
3677
|
+
const selected = federationScope?.(owner);
|
|
3678
|
+
if (!selected) throw new CalendarRequestError("Calendar member scope is unavailable.", 403);
|
|
3679
|
+
return context.json({
|
|
3680
|
+
owner,
|
|
3681
|
+
...await selected.targets()
|
|
3682
|
+
});
|
|
3683
|
+
}
|
|
3684
|
+
const match = /^\/events(?:\/([^/]+)(?:\/(history|action|pause|resume|run-now|ask))?)?$/.exec(path);
|
|
3685
|
+
if (!match) throw new CalendarRequestError("Unsupported calendar federation route.", 403);
|
|
3686
|
+
const id = match[1] && decodeURIComponent(match[1]);
|
|
3687
|
+
const method = context.req.method;
|
|
3688
|
+
const operation = !id ? method === "GET" ? "list" : method === "POST" ? "create" : void 0 : match[2] === "ask" && method === "POST" && verifiedMember ? "ask" : ([
|
|
3689
|
+
"pause",
|
|
3690
|
+
"resume",
|
|
3691
|
+
"run-now"
|
|
3692
|
+
].includes(match[2] ?? "") && method === "POST" || !match[2] && method === "DELETE") && verifiedMember ? "action" : match[2] === "history" && method === "GET" ? "history" : match[2] === "action" && method === "POST" ? "action" : !match[2] && method === "GET" ? "get" : !match[2] && method === "PATCH" ? "update" : void 0;
|
|
3693
|
+
if (!operation) throw new CalendarRequestError("Unsupported calendar federation route.", 403);
|
|
3694
|
+
const shorthand = verifiedMember && operation === "action" && match[2] !== "action";
|
|
3695
|
+
const body = method === "GET" || shorthand ? {} : await json(context.req.raw);
|
|
3696
|
+
const record = body && typeof body === "object" && !Array.isArray(body) ? body : {};
|
|
3697
|
+
const query = context.req.query();
|
|
3698
|
+
const filters = Object.fromEntries([
|
|
3699
|
+
"status",
|
|
3700
|
+
"workspace",
|
|
3701
|
+
"kind",
|
|
3702
|
+
"q",
|
|
3703
|
+
"limit"
|
|
3704
|
+
].filter((key) => query[key] !== void 0).map((key) => [key, key === "limit" ? Number(query[key]) : query[key]]));
|
|
3705
|
+
const input = operation === "list" ? {
|
|
3706
|
+
...query,
|
|
3707
|
+
filters
|
|
3708
|
+
} : operation === "update" ? {
|
|
3709
|
+
id,
|
|
3710
|
+
patch: body,
|
|
3711
|
+
destinationHostId: record.destinationHostId
|
|
3712
|
+
} : operation === "history" || operation === "get" ? {
|
|
3713
|
+
id,
|
|
3714
|
+
cursor: query.cursor
|
|
3715
|
+
} : {
|
|
3716
|
+
...record,
|
|
3717
|
+
...id ? { id } : {},
|
|
3718
|
+
...shorthand ? { action: method === "DELETE" ? "cancel" : match[2] } : {}
|
|
3719
|
+
};
|
|
3720
|
+
const result = await createCalendarFederation({
|
|
3721
|
+
store,
|
|
3722
|
+
forOwner: federationScope ?? (() => scope),
|
|
3723
|
+
member: verifiedMember
|
|
3724
|
+
}).handle(operation, scope.owner, input, {
|
|
3725
|
+
principal: caller.principal,
|
|
3726
|
+
org: caller.org,
|
|
3727
|
+
device: caller.device,
|
|
3728
|
+
...caller.via ? { via: caller.via } : {}
|
|
3729
|
+
});
|
|
3730
|
+
return context.body(JSON.stringify(result), operation === "create" ? 201 : 200, { "Content-Type": "application/json" });
|
|
3731
|
+
});
|
|
3732
|
+
app.get("/events/:id", async (context) => {
|
|
3733
|
+
if (!store) throw new CalendarRequestError("Calendar event was not found.", 404);
|
|
3734
|
+
await scope.history(context.req.param("id"));
|
|
3735
|
+
return context.json(await store.get(context.req.param("id")));
|
|
3736
|
+
});
|
|
3737
|
+
app.post("/events/:id/action", async (context) => {
|
|
3738
|
+
const body = await json(context.req.raw);
|
|
3739
|
+
if (![
|
|
3740
|
+
"pause",
|
|
3741
|
+
"resume",
|
|
3742
|
+
"cancel",
|
|
3743
|
+
"run-now"
|
|
3744
|
+
].includes(body?.action ?? "")) throw new CalendarRequestError("Invalid calendar action.");
|
|
3745
|
+
return context.json(await (await scopeForEvent(context.req.param("id"))).action(context.req.param("id"), body.action));
|
|
3746
|
+
});
|
|
3747
|
+
app.post("/claim", async (context) => {
|
|
3748
|
+
if (!store || poApiCallerFrom(context.req.raw.headers)?.locality !== "local" || scope.owner.level !== "global") throw new CalendarRequestError("Only a local owner may claim calendar events.", 403);
|
|
3749
|
+
const principal = await json(context.req.raw);
|
|
3750
|
+
if (typeof principal?.issuer !== "string" || typeof principal.subject !== "string" || !principal.issuer || !principal.subject) throw new CalendarRequestError("A principal is required.");
|
|
3751
|
+
await store.claimGlobals({
|
|
3752
|
+
issuer: principal.issuer,
|
|
3753
|
+
subject: principal.subject
|
|
3754
|
+
}, true);
|
|
3755
|
+
return context.json({ claimed: true });
|
|
3756
|
+
});
|
|
3757
|
+
app.get(routes.list.path, async (context) => {
|
|
3758
|
+
const { status, workspace, kind, q, limit } = context.req.query();
|
|
3759
|
+
return context.json(await scope.list(Number(context.req.query("from")), Number(context.req.query("to")), context.req.query("cursor"), context.req.query("tz"), Object.fromEntries(Object.entries({
|
|
3760
|
+
status,
|
|
3761
|
+
workspace,
|
|
3762
|
+
kind,
|
|
3763
|
+
q,
|
|
3764
|
+
limit: limit && Number(limit)
|
|
3765
|
+
}).filter(([, value]) => value !== void 0 && value !== ""))));
|
|
3766
|
+
});
|
|
3767
|
+
app.get(routes.targets.path, async (context) => context.json({
|
|
3768
|
+
owner: scope.owner,
|
|
3769
|
+
...await scope.targets()
|
|
3770
|
+
}));
|
|
3771
|
+
app.post(routes.create.path, async (context) => context.json(await scope.create(await json(context.req.raw)), 201));
|
|
3772
|
+
app.patch(routes.update.path, async (context) => context.json(await (await scopeForEvent(context.req.param("id"))).update(context.req.param("id"), await json(context.req.raw))));
|
|
3773
|
+
app.delete(routes.cancel.path, async (context) => context.json(await (await scopeForEvent(context.req.param("id"))).action(context.req.param("id"), "cancel")));
|
|
3774
|
+
app.post(routes.pause.path, async (context) => context.json(await (await scopeForEvent(context.req.param("id"))).action(context.req.param("id"), "pause")));
|
|
3775
|
+
app.post(routes.resume.path, async (context) => context.json(await (await scopeForEvent(context.req.param("id"))).action(context.req.param("id"), "resume")));
|
|
3776
|
+
app.post(routes.runNow.path, async (context) => context.json(await (await scopeForEvent(context.req.param("id"))).action(context.req.param("id"), "run-now")));
|
|
3777
|
+
app.post(routes.ask.path, async (context) => context.json(await (await scopeForEvent(context.req.param("id"))).ask(context.req.param("id"), await json(context.req.raw)), 201));
|
|
3778
|
+
app.get(routes.history.path, async (context) => context.json(await scope.history(context.req.param("id"), context.req.query("cursor"))));
|
|
3779
|
+
return {
|
|
3780
|
+
fetch: (request) => app.fetch(request),
|
|
3781
|
+
close: () => void 0
|
|
3782
|
+
};
|
|
3783
|
+
}
|
|
3784
|
+
};
|
|
3785
|
+
}
|
|
3786
|
+
//#endregion
|
|
3787
|
+
//#region ../../../layers/automation/po-calendar/src/services/calendarExecutor/index.ts
|
|
3788
|
+
function createCalendarExecutors() {
|
|
3789
|
+
const executors = /* @__PURE__ */ new Map();
|
|
3790
|
+
return {
|
|
3791
|
+
register(sessionId, executor) {
|
|
3792
|
+
executors.set(sessionId, executor);
|
|
3793
|
+
return () => {
|
|
3794
|
+
if (executors.get(sessionId) === executor) executors.delete(sessionId);
|
|
3795
|
+
};
|
|
3796
|
+
},
|
|
3797
|
+
get: (sessionId) => executors.get(sessionId)
|
|
3798
|
+
};
|
|
3799
|
+
}
|
|
3800
|
+
/** Executes one fire for its own session. The fire must be running here at the event's current revision. */
|
|
3801
|
+
function createCalendarSessionExecutor({ sessionId, store, launchers, workflows, modes }) {
|
|
3802
|
+
return { async run({ event: requested, occurrence: claimed, signal }) {
|
|
3803
|
+
signal.throwIfAborted();
|
|
3804
|
+
const occurrence = await store.getOccurrence(claimed.id);
|
|
3805
|
+
const event = occurrence?.centralJob ? {
|
|
3806
|
+
...occurrence.centralJob.snapshot.event,
|
|
3807
|
+
id: occurrence.eventId,
|
|
3808
|
+
revision: occurrence.revision
|
|
3809
|
+
} : await store.get(requested.id);
|
|
3810
|
+
signal.throwIfAborted();
|
|
3811
|
+
if (!event || !occurrence || occurrence.eventId !== requested.id || occurrence.centralJob && occurrence.revision !== claimed.revision || occurrence.eventId !== event.id || occurrence.sessionId !== sessionId || occurrence.state !== "running" || occurrence.revision !== event.revision) throw new Error("Calendar fire no longer matches this session.");
|
|
3812
|
+
const active = modes();
|
|
3813
|
+
const missing = (event.assignment?.modes ?? []).filter((mode) => !active.includes(mode));
|
|
3814
|
+
if (missing.length) throw new Error(`Modes are not active in the new session: ${missing.join(", ")}.`);
|
|
3815
|
+
if (event.workflow) {
|
|
3816
|
+
const service = workflows();
|
|
3817
|
+
if (!service) throw new Error("Workflows are unavailable in this session. Add the workflow layer.");
|
|
3818
|
+
const { key, inputs, prompt } = event.workflow;
|
|
3819
|
+
const run = await service.launch({
|
|
3820
|
+
source: "repo",
|
|
3821
|
+
key
|
|
3822
|
+
}, {
|
|
3823
|
+
...inputs ? { inputs } : {},
|
|
3824
|
+
...prompt ? { prompt } : {}
|
|
3825
|
+
});
|
|
3826
|
+
signal.throwIfAborted();
|
|
3827
|
+
if (!Check(PoWorkflowRunRefSchema, run)) throw new Error("Workflow launch returned an invalid receipt.");
|
|
3828
|
+
const { runId, ownerSessionId, runKey, registryWorkspace } = run;
|
|
3829
|
+
return { workflowRun: {
|
|
3830
|
+
runId,
|
|
3831
|
+
ownerSessionId,
|
|
3832
|
+
runKey,
|
|
3833
|
+
registryWorkspace
|
|
3834
|
+
} };
|
|
3835
|
+
}
|
|
3836
|
+
if (event.action) {
|
|
3837
|
+
const result = await launchers.runOnce(event.action.launcherId, event.action.input, {
|
|
3838
|
+
eventId: event.id,
|
|
3839
|
+
occurrenceId: occurrence.id,
|
|
3840
|
+
sessionId,
|
|
3841
|
+
signal
|
|
3842
|
+
});
|
|
3843
|
+
return result.summary ? { summary: result.summary } : {};
|
|
3844
|
+
}
|
|
3845
|
+
throw new Error("Prompt fires are delivered by the dispatcher.");
|
|
3846
|
+
} };
|
|
3847
|
+
}
|
|
3848
|
+
//#endregion
|
|
3849
|
+
//#region ../../../layers/automation/po-calendar/src/services/calendarCloud/type.ts
|
|
3850
|
+
/** Bound by a cloud host: the Calendar root its edge mounts serve instead of refusing. */
|
|
3851
|
+
const CALENDAR_CLOUD_ROOT_SERVICE = defineServiceContract("po/calendar-cloud-root", { scope: "host" });
|
|
3852
|
+
//#endregion
|
|
3853
|
+
//#region ../../../layers/automation/po-calendar/src/services/calendarSetup/index.ts
|
|
3854
|
+
const localPath = (value) => {
|
|
3855
|
+
if (typeof value === "string") return /^(?:\/|[a-z]:[\\/]|\\\\|~[\\/])/iu.test(value);
|
|
3856
|
+
if (value && typeof value === "object") return Object.values(value).some(localPath);
|
|
3857
|
+
return false;
|
|
3858
|
+
};
|
|
3859
|
+
/** Hash applied host metadata, never a profile name or a fresh read of configuration files. */
|
|
3860
|
+
async function calendarSetup({ runtime, profile, settings }) {
|
|
3861
|
+
if (!runtime.packages.length || runtime.packages.some((entry) => !entry.contentRevision)) throw new Error("The loaded package implementations cannot establish Calendar compatibility.");
|
|
3862
|
+
if (runtime.selection.profile !== (profile.profileName ?? null)) throw new Error("The applied Calendar profile changed.");
|
|
3863
|
+
const assignment = {
|
|
3864
|
+
...profile.profileName ? { profile: profile.profileName } : {},
|
|
3865
|
+
preset: runtime.selection.preset,
|
|
3866
|
+
domains: [...runtime.selection.domains],
|
|
3867
|
+
modes: [...runtime.selection.modes]
|
|
3868
|
+
};
|
|
3869
|
+
const metadata = {
|
|
3870
|
+
env: profile.env,
|
|
3871
|
+
integration: profile.integration,
|
|
3872
|
+
secrets: profile.secrets,
|
|
3873
|
+
settings
|
|
3874
|
+
};
|
|
3875
|
+
const bytes = new TextEncoder().encode(canonicalCalendarJson({
|
|
3876
|
+
version: 1,
|
|
3877
|
+
assignment,
|
|
3878
|
+
layers: runtime.selection.activeLayers,
|
|
3879
|
+
packages: runtime.packages.map(canonicalCalendarJson).sort(),
|
|
3880
|
+
capabilities: runtime.capabilities.map(canonicalCalendarJson).sort(),
|
|
3881
|
+
persona: runtime.persona,
|
|
3882
|
+
metadata
|
|
3883
|
+
}));
|
|
3884
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
3885
|
+
return {
|
|
3886
|
+
digest: Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""),
|
|
3887
|
+
portable: !!profile.profileName && !localPath(metadata),
|
|
3888
|
+
assignment
|
|
3889
|
+
};
|
|
3890
|
+
}
|
|
3891
|
+
//#endregion
|
|
3892
|
+
export { validateCalendarExecution as A, CalendarOwnerSchema as C, mergeCalendarEvent as D, isCalendarJson as E, DEFAULT_CALENDAR_PENDING_EXPIRY_MS as M, MAX_CALENDAR_SUMMARY_LENGTH as N, parseCalendarEventInput as O, CalendarOccurrenceSchema as S, canonicalCalendarJson as T, CalendarListInputSchema as _, createCalendarApi as a, CalendarEventSchema as b, firstDue as c, resolveScheduleInput as d, validateSchedule as f, CalendarCreateRequestSchema as g, CalendarCancelInputSchema as h, createCalendarSessionExecutor as i, CALENDAR_SCHEMA_SQL as j, parseCalendarEventPatch as k, missedRange as l, CalendarAskSchema as m, CALENDAR_CLOUD_ROOT_SERVICE as n, CalendarRequestError as o, CalendarAgentDraftSchema as p, createCalendarExecutors as r, createCalendarScope as s, calendarSetup as t, nextDue as u, CalendarAssignmentSchema as v, CalendarWorkerRequestSchema as w, CalendarEventSourceSchema as x, CalendarEventPatchSchema as y };
|