@powerhousedao/shared 6.2.3 → 6.3.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/action-id-DON1WCeY.d.ts +19 -0
- package/dist/action-id-DON1WCeY.d.ts.map +1 -0
- package/dist/clis/args/access-token.d.mts +14 -2
- package/dist/clis/args/access-token.d.mts.map +1 -0
- package/dist/clis/args/access-token.mjs +21 -1
- package/dist/clis/args/access-token.mjs.map +1 -0
- package/dist/clis/args/{common-BXabdhiO.mjs → common-DG_SF8fN.mjs} +39 -8
- package/dist/clis/args/common-DG_SF8fN.mjs.map +1 -0
- package/dist/clis/args/{common-Bnm859xU.d.mts → common-DmerPWXo.d.mts} +8 -4
- package/dist/clis/args/common-DmerPWXo.d.mts.map +1 -0
- package/dist/clis/args/common.d.mts +1 -1
- package/dist/clis/args/common.mjs +1 -1
- package/dist/clis/args/connect.d.mts +448 -2
- package/dist/clis/args/connect.d.mts.map +1 -0
- package/dist/clis/args/connect.mjs +202 -1
- package/dist/clis/args/connect.mjs.map +1 -0
- package/dist/clis/args/{generate-BOItUNvP.mjs → generate-DMKgc6et.mjs} +2 -21
- package/dist/clis/args/generate-DMKgc6et.mjs.map +1 -0
- package/dist/clis/args/generate.d.mts +92 -2
- package/dist/clis/args/generate.d.mts.map +1 -0
- package/dist/clis/args/generate.mjs +1 -1
- package/dist/clis/args/{help-DVPTARGn.d.mts → help-BnD14eCa.d.mts} +62 -2
- package/dist/clis/args/help-BnD14eCa.d.mts.map +1 -0
- package/dist/clis/args/{help-DS1NlcJQ.mjs → help-Cjoe-b7d.mjs} +55 -15
- package/dist/clis/args/help-Cjoe-b7d.mjs.map +1 -0
- package/dist/clis/args/help.d.mts +1 -1
- package/dist/clis/args/help.mjs +16 -1
- package/dist/clis/args/host.d.mts +23 -0
- package/dist/clis/args/host.d.mts.map +1 -0
- package/dist/clis/args/host.mjs +35 -0
- package/dist/clis/args/host.mjs.map +1 -0
- package/dist/clis/args/index.d.mts +23 -19
- package/dist/clis/args/index.mjs +23 -19
- package/dist/clis/args/init.d.mts +53 -2
- package/dist/clis/args/init.d.mts.map +1 -0
- package/dist/clis/args/init.mjs +77 -1
- package/dist/clis/args/init.mjs.map +1 -0
- package/dist/clis/args/inspect.d.mts +11 -2
- package/dist/clis/args/inspect.d.mts.map +1 -0
- package/dist/clis/args/inspect.mjs +14 -1
- package/dist/clis/args/inspect.mjs.map +1 -0
- package/dist/clis/args/install.d.mts +35 -2
- package/dist/clis/args/install.d.mts.map +1 -0
- package/dist/clis/args/install.mjs +31 -1
- package/dist/clis/args/install.mjs.map +1 -0
- package/dist/clis/args/{login-CXRJXg71.d.mts → keyframes.d.mts} +13 -13
- package/dist/clis/args/keyframes.d.mts.map +1 -0
- package/dist/clis/args/keyframes.mjs +42 -0
- package/dist/clis/args/keyframes.mjs.map +1 -0
- package/dist/clis/args/list.d.mts +8 -2
- package/dist/clis/args/list.d.mts.map +1 -0
- package/dist/clis/args/list.mjs +6 -1
- package/dist/clis/args/list.mjs.map +1 -0
- package/dist/clis/args/login.d.mts +23 -2
- package/dist/clis/args/login.d.mts.map +1 -0
- package/dist/clis/args/login.mjs +39 -1
- package/dist/clis/args/login.mjs.map +1 -0
- package/dist/clis/args/{access-token-C5sKsH2O.d.mts → mcp.d.mts} +6 -7
- package/dist/clis/args/mcp.d.mts.map +1 -0
- package/dist/clis/args/mcp.mjs +22 -0
- package/dist/clis/args/mcp.mjs.map +1 -0
- package/dist/clis/args/migrate.d.mts +26 -2
- package/dist/clis/args/migrate.d.mts.map +1 -0
- package/dist/clis/args/migrate.mjs +43 -1
- package/dist/clis/args/migrate.mjs.map +1 -0
- package/dist/clis/args/{uninstall-CDx7lwxn.d.mts → model.d.mts} +28 -17
- package/dist/clis/args/model.d.mts.map +1 -0
- package/dist/clis/args/model.mjs +51 -0
- package/dist/clis/args/model.mjs.map +1 -0
- package/dist/clis/args/publish.d.mts +18 -2
- package/dist/clis/args/publish.d.mts.map +1 -0
- package/dist/clis/args/publish.mjs +26 -1
- package/dist/clis/args/publish.mjs.map +1 -0
- package/dist/clis/args/registry.d.mts +15 -2
- package/dist/clis/args/registry.d.mts.map +1 -0
- package/dist/clis/args/registry.mjs +22 -1
- package/dist/clis/args/registry.mjs.map +1 -0
- package/dist/clis/args/{unpublish-CEDsk6uv.d.mts → run.d.mts} +11 -12
- package/dist/clis/args/run.d.mts.map +1 -0
- package/dist/clis/args/run.mjs +33 -0
- package/dist/clis/args/run.mjs.map +1 -0
- package/dist/clis/args/{service-BBx5GDTc.d.mts → service-CLCvH3kf.d.mts} +4 -4
- package/dist/clis/args/service-CLCvH3kf.d.mts.map +1 -0
- package/dist/clis/args/service.d.mts +1 -1
- package/dist/clis/args/service.mjs +10 -1
- package/dist/clis/args/service.mjs.map +1 -0
- package/dist/clis/args/switchboard.d.mts +68 -2
- package/dist/clis/args/switchboard.d.mts.map +1 -0
- package/dist/clis/args/switchboard.mjs +84 -1
- package/dist/clis/args/switchboard.mjs.map +1 -0
- package/dist/clis/args/uninstall.d.mts +26 -2
- package/dist/clis/args/uninstall.d.mts.map +1 -0
- package/dist/clis/args/uninstall.mjs +15 -1
- package/dist/clis/args/uninstall.mjs.map +1 -0
- package/dist/clis/args/unpublish.d.mts +20 -2
- package/dist/clis/args/unpublish.d.mts.map +1 -0
- package/dist/clis/args/unpublish.mjs +29 -1
- package/dist/clis/args/unpublish.mjs.map +1 -0
- package/dist/clis/args/{vetra-BUNlAAPp.mjs → vetra-BqjDopAP.mjs} +18 -2
- package/dist/clis/args/vetra-BqjDopAP.mjs.map +1 -0
- package/dist/clis/args/vetra.d.mts +112 -2
- package/dist/clis/args/vetra.d.mts.map +1 -0
- package/dist/clis/args/vetra.mjs +1 -1
- package/dist/clis/{build-config-CmdMi_wu.mjs → build-config-BM1RL4u_.mjs} +87 -8
- package/dist/clis/build-config-BM1RL4u_.mjs.map +1 -0
- package/dist/clis/build-config.d.mts +26 -1
- package/dist/clis/build-config.d.mts.map +1 -1
- package/dist/clis/build-config.mjs +2 -2
- package/dist/clis/build-pieces.d.mts +71 -4
- package/dist/clis/build-pieces.d.mts.map +1 -1
- package/dist/clis/build-pieces.mjs +249 -26
- package/dist/clis/build-pieces.mjs.map +1 -1
- package/dist/clis/command-names.d.mts +3 -1
- package/dist/clis/command-names.d.mts.map +1 -1
- package/dist/clis/command-names.mjs +8 -1
- package/dist/clis/command-names.mjs.map +1 -1
- package/dist/clis/constants.d.mts +2 -2
- package/dist/clis/constants.mjs +92 -20
- package/dist/clis/constants.mjs.map +1 -1
- package/dist/clis/definition-sources.d.mts +26 -0
- package/dist/clis/definition-sources.d.mts.map +1 -0
- package/dist/clis/definition-sources.mjs +27 -0
- package/dist/clis/definition-sources.mjs.map +1 -0
- package/dist/clis/deprecations.d.mts +73 -0
- package/dist/clis/deprecations.d.mts.map +1 -0
- package/dist/clis/deprecations.mjs +121 -0
- package/dist/clis/deprecations.mjs.map +1 -0
- package/dist/clis/{index-6CZwrmQi.d.mts → index-DnZYG-8g.d.mts} +2 -2
- package/dist/clis/{index-6CZwrmQi.d.mts.map → index-DnZYG-8g.d.mts.map} +1 -1
- package/dist/clis/index.d.mts +2584 -901
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +1540 -919
- package/dist/clis/index.mjs.map +1 -1
- package/dist/clis/package-style.d.mts +32 -0
- package/dist/clis/package-style.d.mts.map +1 -0
- package/dist/clis/package-style.mjs +102 -0
- package/dist/clis/package-style.mjs.map +1 -0
- package/dist/clis/ph-dir.d.mts +26 -0
- package/dist/clis/ph-dir.d.mts.map +1 -0
- package/dist/clis/ph-dir.mjs +37 -0
- package/dist/clis/ph-dir.mjs.map +1 -0
- package/dist/clis/project-env.d.mts +6 -0
- package/dist/clis/project-env.d.mts.map +1 -1
- package/dist/clis/project-env.mjs +16 -1
- package/dist/clis/project-env.mjs.map +1 -1
- package/dist/clis/real-paths.d.mts +14 -0
- package/dist/clis/real-paths.d.mts.map +1 -0
- package/dist/clis/real-paths.mjs +36 -0
- package/dist/clis/real-paths.mjs.map +1 -0
- package/dist/clis/retired-flags.d.mts +45 -0
- package/dist/clis/retired-flags.d.mts.map +1 -0
- package/dist/clis/retired-flags.mjs +55 -0
- package/dist/clis/retired-flags.mjs.map +1 -0
- package/dist/clis/rolldown-runtime-B4iAMlE-.mjs +35 -0
- package/dist/clis/types-CZU17kAm.d.mts +2510 -0
- package/dist/clis/types-CZU17kAm.d.mts.map +1 -0
- package/dist/clis/utils.d.mts.map +1 -1
- package/dist/clis/utils.mjs.map +1 -1
- package/dist/{config-loader-C6dZB_iX.js → config-loader-B7SqNz8z.js} +24 -6
- package/dist/config-loader-B7SqNz8z.js.map +1 -0
- package/dist/connect/app-shell.d.ts +48 -0
- package/dist/connect/app-shell.d.ts.map +1 -0
- package/dist/connect/app-shell.js +90 -0
- package/dist/connect/app-shell.js.map +1 -0
- package/dist/connect/config-loader.d.ts +8 -1
- package/dist/connect/config-loader.d.ts.map +1 -1
- package/dist/connect/config-loader.js +2 -2
- package/dist/connect/connect-config-schema.d.ts +3 -0
- package/dist/connect/connect-config-schema.js +486 -0
- package/dist/connect/connect-config-schema.js.map +1 -0
- package/dist/connect/image-ref.d.ts +32 -0
- package/dist/connect/image-ref.d.ts.map +1 -0
- package/dist/connect/image-ref.js +80 -0
- package/dist/connect/image-ref.js.map +1 -0
- package/dist/connect/index.d.ts +84 -635
- package/dist/connect/index.d.ts.map +1 -1
- package/dist/connect/index.js +216 -553
- package/dist/connect/index.js.map +1 -1
- package/dist/connect/origin-placeholder.d.ts +52 -0
- package/dist/connect/origin-placeholder.d.ts.map +1 -0
- package/dist/connect/origin-placeholder.js +101 -0
- package/dist/connect/origin-placeholder.js.map +1 -0
- package/dist/connect-config-schema-cBfkNo1b.d.ts +1872 -0
- package/dist/connect-config-schema-cBfkNo1b.d.ts.map +1 -0
- package/dist/constants-5UFY_rXh.d.ts +9 -0
- package/dist/constants-5UFY_rXh.d.ts.map +1 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +22 -6
- package/dist/constants.js.map +1 -1
- package/dist/document-drive/index.d.ts +3 -4
- package/dist/document-drive/index.d.ts.map +1 -1
- package/dist/document-drive/index.js +2 -13
- package/dist/document-drive/index.js.map +1 -1
- package/dist/document-model/action-id.d.ts +3 -0
- package/dist/document-model/action-id.js +59 -0
- package/dist/document-model/action-id.js.map +1 -0
- package/dist/document-model/dispatch.d.ts +25 -0
- package/dist/document-model/dispatch.d.ts.map +1 -0
- package/dist/document-model/dispatch.js +0 -0
- package/dist/document-model/errors.d.ts +3 -0
- package/dist/document-model/errors.js +214 -0
- package/dist/document-model/errors.js.map +1 -0
- package/dist/document-model/index.d.ts +5 -4
- package/dist/document-model/index.js +7 -5521
- package/dist/document-model/utils.d.ts +3 -2
- package/dist/document-model/utils.js +3 -2
- package/dist/document-model/version.d.ts +3 -0
- package/dist/document-model/version.js +8 -0
- package/dist/document-model/version.js.map +1 -0
- package/dist/document-model-CqySIaKV.js +5805 -0
- package/dist/document-model-CqySIaKV.js.map +1 -0
- package/dist/host-tokens/index.d.ts +3 -0
- package/dist/host-tokens/index.js +2 -0
- package/dist/host-tokens-DOeyxqLi.js +322 -0
- package/dist/host-tokens-DOeyxqLi.js.map +1 -0
- package/dist/{index-5gwOhPG5.d.ts → index-CUZ8eWun.d.ts} +2 -2
- package/dist/{index-5gwOhPG5.d.ts.map → index-CUZ8eWun.d.ts.map} +1 -1
- package/dist/index-D58WVj_E.d.ts +246 -0
- package/dist/index-D58WVj_E.d.ts.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/processors/index.d.ts +2 -2
- package/dist/processors/index.js +177 -68
- package/dist/processors/index.js.map +1 -1
- package/dist/processors/testing.d.ts +22 -0
- package/dist/processors/testing.d.ts.map +1 -0
- package/dist/processors/testing.js +77 -0
- package/dist/processors/testing.js.map +1 -0
- package/dist/purge-CbAV5DVh.js +631 -0
- package/dist/purge-CbAV5DVh.js.map +1 -0
- package/dist/registry/index.d.ts +3 -3
- package/dist/registry/index.js +52 -9
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest-slim.d.ts +2 -2
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/types-CV2j3BvH.d.ts +5709 -0
- package/dist/types-CV2j3BvH.d.ts.map +1 -0
- package/dist/{types-CI3ren9F.d.ts → types-D_6ZcaJj.d.ts} +20 -12
- package/dist/types-D_6ZcaJj.d.ts.map +1 -0
- package/dist/{utils-CSF716ux.js → utils-DiV32YIj.js} +45 -2
- package/dist/utils-DiV32YIj.js.map +1 -0
- package/dist/utils-MrLmLEVr.js +78 -0
- package/dist/utils-MrLmLEVr.js.map +1 -0
- package/dist/version-BxLITo9P.d.ts +6 -0
- package/dist/version-BxLITo9P.d.ts.map +1 -0
- package/package.json +37 -3
- package/dist/clis/args/access-token-3Hqv_U8I.mjs +0 -22
- package/dist/clis/args/access-token-3Hqv_U8I.mjs.map +0 -1
- package/dist/clis/args/access-token-C5sKsH2O.d.mts.map +0 -1
- package/dist/clis/args/common-BXabdhiO.mjs.map +0 -1
- package/dist/clis/args/common-Bnm859xU.d.mts.map +0 -1
- package/dist/clis/args/connect-BG3HkYBk.mjs +0 -203
- package/dist/clis/args/connect-BG3HkYBk.mjs.map +0 -1
- package/dist/clis/args/connect-DjeiqXus.d.mts +0 -450
- package/dist/clis/args/connect-DjeiqXus.d.mts.map +0 -1
- package/dist/clis/args/generate-BOItUNvP.mjs.map +0 -1
- package/dist/clis/args/generate-BPBBLeUD.d.mts +0 -103
- package/dist/clis/args/generate-BPBBLeUD.d.mts.map +0 -1
- package/dist/clis/args/help-DS1NlcJQ.mjs.map +0 -1
- package/dist/clis/args/help-DVPTARGn.d.mts.map +0 -1
- package/dist/clis/args/init-CFeTq4Cq.d.mts +0 -52
- package/dist/clis/args/init-CFeTq4Cq.d.mts.map +0 -1
- package/dist/clis/args/init-Dvb42Y87.mjs +0 -67
- package/dist/clis/args/init-Dvb42Y87.mjs.map +0 -1
- package/dist/clis/args/inspect-BjRmtB86.d.mts +0 -13
- package/dist/clis/args/inspect-BjRmtB86.d.mts.map +0 -1
- package/dist/clis/args/inspect-UNQgtuR0.mjs +0 -15
- package/dist/clis/args/inspect-UNQgtuR0.mjs.map +0 -1
- package/dist/clis/args/install-B0tMyUMw.d.mts +0 -37
- package/dist/clis/args/install-B0tMyUMw.d.mts.map +0 -1
- package/dist/clis/args/install-F-27kF6m.mjs +0 -32
- package/dist/clis/args/install-F-27kF6m.mjs.map +0 -1
- package/dist/clis/args/list-Bkfn8Yuo.mjs +0 -7
- package/dist/clis/args/list-Bkfn8Yuo.mjs.map +0 -1
- package/dist/clis/args/list-DrbxA7JJ.d.mts +0 -10
- package/dist/clis/args/list-DrbxA7JJ.d.mts.map +0 -1
- package/dist/clis/args/login-CIFkQExi.mjs +0 -40
- package/dist/clis/args/login-CIFkQExi.mjs.map +0 -1
- package/dist/clis/args/login-CXRJXg71.d.mts.map +0 -1
- package/dist/clis/args/magic-string.es-BWtG0AyA.mjs +0 -1019
- package/dist/clis/args/magic-string.es-BWtG0AyA.mjs.map +0 -1
- package/dist/clis/args/migrate-DkCQRL2D.d.mts +0 -19
- package/dist/clis/args/migrate-DkCQRL2D.d.mts.map +0 -1
- package/dist/clis/args/migrate-DwJGhc2d.mjs +0 -29
- package/dist/clis/args/migrate-DwJGhc2d.mjs.map +0 -1
- package/dist/clis/args/publish-CeW4bOrl.d.mts +0 -16
- package/dist/clis/args/publish-CeW4bOrl.d.mts.map +0 -1
- package/dist/clis/args/publish-DHqlGWmL.mjs +0 -19
- package/dist/clis/args/publish-DHqlGWmL.mjs.map +0 -1
- package/dist/clis/args/registry-DIwES3l2.mjs +0 -23
- package/dist/clis/args/registry-DIwES3l2.mjs.map +0 -1
- package/dist/clis/args/registry-DNH8xuaE.d.mts +0 -17
- package/dist/clis/args/registry-DNH8xuaE.d.mts.map +0 -1
- package/dist/clis/args/service-BBx5GDTc.d.mts.map +0 -1
- package/dist/clis/args/service-Cpjlyeu5.mjs +0 -11
- package/dist/clis/args/service-Cpjlyeu5.mjs.map +0 -1
- package/dist/clis/args/switchboard-CCaAtU56.mjs +0 -85
- package/dist/clis/args/switchboard-CCaAtU56.mjs.map +0 -1
- package/dist/clis/args/switchboard-RrNb1fUH.d.mts +0 -70
- package/dist/clis/args/switchboard-RrNb1fUH.d.mts.map +0 -1
- package/dist/clis/args/uninstall-3U0B8g5c.mjs +0 -16
- package/dist/clis/args/uninstall-3U0B8g5c.mjs.map +0 -1
- package/dist/clis/args/uninstall-CDx7lwxn.d.mts.map +0 -1
- package/dist/clis/args/unpublish-CEDsk6uv.d.mts.map +0 -1
- package/dist/clis/args/unpublish-s9zUh6Gw.mjs +0 -30
- package/dist/clis/args/unpublish-s9zUh6Gw.mjs.map +0 -1
- package/dist/clis/args/vetra-BUNlAAPp.mjs.map +0 -1
- package/dist/clis/args/vetra-DkDaWFPi.d.mts +0 -111
- package/dist/clis/args/vetra-DkDaWFPi.d.mts.map +0 -1
- package/dist/clis/args/vetra-ports.test.d.mts +0 -2
- package/dist/clis/args/vetra-ports.test.mjs +0 -13354
- package/dist/clis/args/vetra-ports.test.mjs.map +0 -1
- package/dist/clis/build-config-CmdMi_wu.mjs.map +0 -1
- package/dist/clis/types-nzer4WIr.d.mts +0 -541
- package/dist/clis/types-nzer4WIr.d.mts.map +0 -1
- package/dist/config-loader-C6dZB_iX.js.map +0 -1
- package/dist/constants-DO4IYxuR.d.ts +0 -9
- package/dist/constants-DO4IYxuR.d.ts.map +0 -1
- package/dist/document-model/index.js.map +0 -1
- package/dist/index-D6833Siv.d.ts +0 -939
- package/dist/index-D6833Siv.d.ts.map +0 -1
- package/dist/types-CI3ren9F.d.ts.map +0 -1
- package/dist/types-CmeoQg_J.d.ts +0 -3337
- package/dist/types-CmeoQg_J.d.ts.map +0 -1
- package/dist/utils-BrKxCmKx.d.ts +0 -18
- package/dist/utils-BrKxCmKx.d.ts.map +0 -1
- package/dist/utils-CSF716ux.js.map +0 -1
package/dist/processors/index.js
CHANGED
|
@@ -1,77 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../purge-CbAV5DVh.js";
|
|
2
|
+
import { a as namespaceSchemaOf, i as hashNamespace, n as createNamespacedQueryBuilder, o as relationalDbToQueryBuilder, r as createRelationalDb, t as createNamespacedDb } from "../utils-MrLmLEVr.js";
|
|
3
|
+
import { sql } from "kysely";
|
|
2
4
|
//#region processors/constants.ts
|
|
3
5
|
const PROCESSOR_APPS = ["connect", "switchboard"];
|
|
4
6
|
const DEFAULT_RELATIONAL_PROCESSOR_DB_NAME = "relational-db";
|
|
5
7
|
const DEFAULT_ANALYTICS_PROCESSOR_DB_NAME = "analytics-db";
|
|
6
8
|
//#endregion
|
|
7
|
-
//#region processors/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
1024
|
|
15
|
-
];
|
|
16
|
-
const LOG2_26 = Math.log2(26);
|
|
17
|
-
/**
|
|
18
|
-
* Hashes a string to a lowercase base-26 string.
|
|
19
|
-
* @param str The string to hash.
|
|
20
|
-
* @param length The length of the hash. Defaults to 10.
|
|
21
|
-
* @param algorithm The hashing algorithm to use. Defaults to "fnv1a".
|
|
22
|
-
* @returns The hashed string.
|
|
23
|
-
*/
|
|
24
|
-
function hashNamespace(str, length = 10) {
|
|
25
|
-
const requiredBits = Math.ceil(length * LOG2_26);
|
|
26
|
-
const bitSize = SUPPORTED_SIZES.find((size) => size && size >= requiredBits) ?? 1024;
|
|
27
|
-
return toBase26(fnv1a(str, { size: bitSize }), length);
|
|
28
|
-
}
|
|
29
|
-
function toBase26(num, length = 10) {
|
|
30
|
-
const alphabet = "abcdefghijklmnopqrstuvwxyz";
|
|
31
|
-
let out = "";
|
|
32
|
-
while (num > 0n && out.length < length) {
|
|
33
|
-
out = alphabet[Number(num % 26n)] + out;
|
|
34
|
-
num /= 26n;
|
|
35
|
-
}
|
|
36
|
-
return out.padStart(length, "a");
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Creates a RelationalDb instance with namespace support.
|
|
40
|
-
* @param baseDb The base RelationalDb instance to enhance.
|
|
41
|
-
* @param baseOptions The default options for namespace creation. Hashes namespace by default.
|
|
42
|
-
* @returns The enhanced RelationalDb instance.
|
|
43
|
-
*/
|
|
44
|
-
function createRelationalDb(baseDb, baseOptions) {
|
|
45
|
-
const relationalDb = baseDb;
|
|
46
|
-
relationalDb.createNamespace = (namespace, options) => createNamespacedDb(baseDb, namespace, options ?? baseOptions);
|
|
47
|
-
relationalDb.queryNamespace = (namespace, options) => createNamespacedQueryBuilder(baseDb, namespace, options ?? baseOptions);
|
|
48
|
-
return relationalDb;
|
|
49
|
-
}
|
|
50
|
-
async function createNamespacedDb(db, namespace, options) {
|
|
51
|
-
const hashValue = options?.hashNamespace ?? true ? hashNamespace(namespace) : namespace;
|
|
52
|
-
await db.schema.createSchema(hashValue).ifNotExists().execute();
|
|
53
|
-
return db.withSchema(hashValue);
|
|
54
|
-
}
|
|
55
|
-
function createNamespacedQueryBuilder(db, namespace, options) {
|
|
56
|
-
const hashValue = options?.hashNamespace ?? true ? hashNamespace(namespace) : namespace;
|
|
57
|
-
return relationalDbToQueryBuilder(db.withSchema(hashValue));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Returns a query builder for a RelationalDb instance.
|
|
61
|
-
* @param query The RelationalDb instance to convert.
|
|
62
|
-
* @returns The IRelationalQueryBuilder instance.
|
|
63
|
-
*/
|
|
64
|
-
function relationalDbToQueryBuilder(query) {
|
|
65
|
-
return {
|
|
66
|
-
selectFrom: query.selectFrom.bind(query),
|
|
67
|
-
selectNoFrom: query.selectNoFrom.bind(query),
|
|
68
|
-
with: query.with.bind(query),
|
|
69
|
-
withRecursive: query.withRecursive.bind(query),
|
|
70
|
-
withSchema: (schema) => relationalDbToQueryBuilder(query.withSchema(schema))
|
|
71
|
-
};
|
|
9
|
+
//#region processors/deletion.ts
|
|
10
|
+
/** The id a DELETE_DOCUMENT or PURGE_DOCUMENT removes; undefined otherwise. */
|
|
11
|
+
function deletedDocumentId(op) {
|
|
12
|
+
const { type, input } = op.operation.action;
|
|
13
|
+
if (type !== "DELETE_DOCUMENT" && type !== "PURGE_DOCUMENT") return void 0;
|
|
14
|
+
const documentId = input?.documentId;
|
|
15
|
+
return typeof documentId === "string" ? documentId : op.context.documentId;
|
|
72
16
|
}
|
|
73
17
|
//#endregion
|
|
74
18
|
//#region processors/relational/types.ts
|
|
19
|
+
/** Columns {@link RelationalDbProcessor.deleteDocumentRows} matches. */
|
|
20
|
+
const DOCUMENT_ID_COLUMNS = ["document_id", "documentId"];
|
|
75
21
|
const IS_RELATIONAL_DB_PROCESSOR = Symbol.for("ph.IS_RELATIONAL_DB_PROCESSOR");
|
|
76
22
|
/**
|
|
77
23
|
* Base class for relational db processors that require a relational database storage.
|
|
@@ -82,10 +28,12 @@ var RelationalDbProcessor = class {
|
|
|
82
28
|
_namespace;
|
|
83
29
|
_filter;
|
|
84
30
|
relationalDb;
|
|
85
|
-
|
|
31
|
+
_driveId;
|
|
32
|
+
constructor(_namespace, _filter, relationalDb, _driveId) {
|
|
86
33
|
this._namespace = _namespace;
|
|
87
34
|
this._filter = _filter;
|
|
88
35
|
this.relationalDb = relationalDb;
|
|
36
|
+
this._driveId = _driveId;
|
|
89
37
|
}
|
|
90
38
|
static [IS_RELATIONAL_DB_PROCESSOR] = true;
|
|
91
39
|
/**
|
|
@@ -111,11 +59,172 @@ var RelationalDbProcessor = class {
|
|
|
111
59
|
get namespace() {
|
|
112
60
|
return this._namespace;
|
|
113
61
|
}
|
|
62
|
+
/** Processors writing one namespace are cleared together. */
|
|
63
|
+
get clearScope() {
|
|
64
|
+
return this._namespace;
|
|
65
|
+
}
|
|
66
|
+
/** Drops the namespace and its tables, then migrates it afresh. */
|
|
67
|
+
async clear() {
|
|
68
|
+
await this.dropNamespace();
|
|
69
|
+
await this.relationalDb.schema.createSchema(this.namespaceSchema()).ifNotExists().execute();
|
|
70
|
+
await this.initAndUpgrade();
|
|
71
|
+
}
|
|
114
72
|
get query() {
|
|
115
73
|
return relationalDbToQueryBuilder(this.relationalDb);
|
|
116
74
|
}
|
|
75
|
+
/** True for this processor's drive when its namespace is that drive's alone. */
|
|
76
|
+
isNamespaceDrive(documentId) {
|
|
77
|
+
const driveId = this._driveId;
|
|
78
|
+
if (driveId === void 0 || documentId !== driveId) return false;
|
|
79
|
+
const processorClass = this.constructor;
|
|
80
|
+
if (processorClass.getNamespace(driveId) !== this._namespace) return false;
|
|
81
|
+
return processorClass.getNamespace(`${driveId}-other`) !== this._namespace;
|
|
82
|
+
}
|
|
83
|
+
/** Deletes a document's rows from every table with a document-id column. */
|
|
84
|
+
async deleteDocumentRows(documentId) {
|
|
85
|
+
const schema = this.namespaceSchema();
|
|
86
|
+
const columns = await sql`
|
|
87
|
+
select c.table_name, c.column_name
|
|
88
|
+
from information_schema.columns c
|
|
89
|
+
join information_schema.tables t
|
|
90
|
+
on t.table_schema = c.table_schema and t.table_name = c.table_name
|
|
91
|
+
where c.table_schema = ${schema}
|
|
92
|
+
and t.table_type = 'BASE TABLE'
|
|
93
|
+
and c.column_name in (${sql.join([...DOCUMENT_ID_COLUMNS])})
|
|
94
|
+
order by c.table_name, c.column_name
|
|
95
|
+
`.execute(this.relationalDb);
|
|
96
|
+
const db = this.relationalDb;
|
|
97
|
+
for (const { table_name, column_name } of columns.rows) await db.deleteFrom(table_name).where(column_name, "=", documentId).execute();
|
|
98
|
+
}
|
|
99
|
+
/** Drops this processor's namespace and every table in it. */
|
|
100
|
+
async dropNamespace() {
|
|
101
|
+
await this.relationalDb.schema.dropSchema(this.namespaceSchema()).ifExists().cascade().execute();
|
|
102
|
+
}
|
|
103
|
+
namespaceSchema() {
|
|
104
|
+
const schema = namespaceSchemaOf(this.relationalDb);
|
|
105
|
+
if (schema === void 0) throw new Error(`Namespace '${this._namespace}' was not opened with createNamespace`);
|
|
106
|
+
return schema;
|
|
107
|
+
}
|
|
117
108
|
};
|
|
118
109
|
//#endregion
|
|
119
|
-
|
|
110
|
+
//#region processors/codegen-status.ts
|
|
111
|
+
const SETTLED_CODEGEN_STATES = [
|
|
112
|
+
"done",
|
|
113
|
+
"failed",
|
|
114
|
+
"skipped"
|
|
115
|
+
];
|
|
116
|
+
function isSettledCodegenState(state) {
|
|
117
|
+
return SETTLED_CODEGEN_STATES.includes(state);
|
|
118
|
+
}
|
|
119
|
+
/** Vetra's codegen status per document, and failed package loads. The codegen
|
|
120
|
+
* processor, the package loader and reactor-mcp share it in one process. */
|
|
121
|
+
var CodegenStatusRegistry = class {
|
|
122
|
+
#documentTypes = /* @__PURE__ */ new Set();
|
|
123
|
+
#statuses = /* @__PURE__ */ new Map();
|
|
124
|
+
#loadFailures = /* @__PURE__ */ new Map();
|
|
125
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
126
|
+
/** Records that a codegen processor generates code for `documentTypes`. */
|
|
127
|
+
watch(documentTypes) {
|
|
128
|
+
for (const type of documentTypes) this.#documentTypes.add(type);
|
|
129
|
+
this.#notify();
|
|
130
|
+
}
|
|
131
|
+
/** Whether a codegen processor runs in this process. */
|
|
132
|
+
get active() {
|
|
133
|
+
return this.#documentTypes.size > 0;
|
|
134
|
+
}
|
|
135
|
+
get documentTypes() {
|
|
136
|
+
return [...this.#documentTypes];
|
|
137
|
+
}
|
|
138
|
+
watches(documentType) {
|
|
139
|
+
return this.#documentTypes.has(documentType);
|
|
140
|
+
}
|
|
141
|
+
/** Replaces a document's status; `name` carries over unless given. */
|
|
142
|
+
set(status) {
|
|
143
|
+
const name = status.name ?? this.#statuses.get(status.documentId)?.name;
|
|
144
|
+
const next = {
|
|
145
|
+
documentId: status.documentId,
|
|
146
|
+
documentType: status.documentType,
|
|
147
|
+
...name !== void 0 && { name },
|
|
148
|
+
state: status.state,
|
|
149
|
+
...status.message !== void 0 && { message: status.message },
|
|
150
|
+
...status.files !== void 0 && { files: status.files },
|
|
151
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
152
|
+
};
|
|
153
|
+
this.#statuses.set(status.documentId, next);
|
|
154
|
+
this.#notify();
|
|
155
|
+
return next;
|
|
156
|
+
}
|
|
157
|
+
get(documentId) {
|
|
158
|
+
return this.#statuses.get(documentId);
|
|
159
|
+
}
|
|
160
|
+
/** Most recently updated first. */
|
|
161
|
+
list() {
|
|
162
|
+
return [...this.#statuses.values()].sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
163
|
+
}
|
|
164
|
+
delete(documentId) {
|
|
165
|
+
if (this.#statuses.delete(documentId)) this.#notify();
|
|
166
|
+
}
|
|
167
|
+
/** Records a failed load of `kind` from `pkg`; no `failure` clears it. */
|
|
168
|
+
reportLoad(pkg, kind, failure) {
|
|
169
|
+
const key = `${pkg}\u0000${kind}`;
|
|
170
|
+
if (failure === void 0) {
|
|
171
|
+
if (this.#loadFailures.delete(key)) this.#notify();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.#loadFailures.set(key, {
|
|
175
|
+
package: pkg,
|
|
176
|
+
kind,
|
|
177
|
+
message: failure,
|
|
178
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
179
|
+
});
|
|
180
|
+
this.#notify();
|
|
181
|
+
}
|
|
182
|
+
loadFailures() {
|
|
183
|
+
return [...this.#loadFailures.values()];
|
|
184
|
+
}
|
|
185
|
+
/** Whether `documentId`'s job, or every job when omitted, has settled. */
|
|
186
|
+
settled(documentId) {
|
|
187
|
+
return (documentId === void 0 ? this.list() : [this.get(documentId)].filter((s) => s !== void 0)).every((status) => isSettledCodegenState(status.state));
|
|
188
|
+
}
|
|
189
|
+
/** Resolves to whether the jobs settled within `timeoutMs`. */
|
|
190
|
+
waitUntilSettled(documentId, timeoutMs) {
|
|
191
|
+
if (this.settled(documentId)) return Promise.resolve(true);
|
|
192
|
+
return new Promise((resolve) => {
|
|
193
|
+
const finish = (settled) => {
|
|
194
|
+
clearTimeout(timer);
|
|
195
|
+
unsubscribe();
|
|
196
|
+
resolve(settled);
|
|
197
|
+
};
|
|
198
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
199
|
+
const unsubscribe = this.subscribe(() => {
|
|
200
|
+
if (this.settled(documentId)) finish(true);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
subscribe(listener) {
|
|
205
|
+
this.#listeners.add(listener);
|
|
206
|
+
return () => {
|
|
207
|
+
this.#listeners.delete(listener);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** Forgets everything; for tests. */
|
|
211
|
+
clear() {
|
|
212
|
+
this.#documentTypes.clear();
|
|
213
|
+
this.#statuses.clear();
|
|
214
|
+
this.#loadFailures.clear();
|
|
215
|
+
this.#notify();
|
|
216
|
+
}
|
|
217
|
+
#notify() {
|
|
218
|
+
for (const listener of this.#listeners) listener();
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const REGISTRY_KEY = Symbol.for("@powerhousedao/shared/codegen-status");
|
|
222
|
+
/** The process's codegen status registry. */
|
|
223
|
+
function getCodegenStatusRegistry() {
|
|
224
|
+
const holder = globalThis;
|
|
225
|
+
return holder[REGISTRY_KEY] ??= new CodegenStatusRegistry();
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
export { CodegenStatusRegistry, DEFAULT_ANALYTICS_PROCESSOR_DB_NAME, DEFAULT_RELATIONAL_PROCESSOR_DB_NAME, DOCUMENT_ID_COLUMNS, PROCESSOR_APPS, RelationalDbProcessor, SETTLED_CODEGEN_STATES, createNamespacedDb, createNamespacedQueryBuilder, createRelationalDb, deletedDocumentId, getCodegenStatusRegistry, hashNamespace, isSettledCodegenState, namespaceSchemaOf, relationalDbToQueryBuilder };
|
|
120
229
|
|
|
121
230
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../processors/constants.ts","../../processors/relational/utils.ts","../../processors/relational/types.ts"],"sourcesContent":["export const PROCESSOR_APPS = [\"connect\", \"switchboard\"] as const;\nexport const DEFAULT_RELATIONAL_PROCESSOR_DB_NAME = \"relational-db\";\nexport const DEFAULT_ANALYTICS_PROCESSOR_DB_NAME = \"analytics-db\";\n","import type { Options } from \"@sindresorhus/fnv1a\";\nimport fnv1a from \"@sindresorhus/fnv1a\";\nimport type {\n IBaseRelationalDb,\n IRelationalDb,\n IRelationalQueryBuilder,\n} from \"./types.js\";\n\nconst SUPPORTED_SIZES: Options[\"size\"][] = [32, 64, 128, 256, 512, 1024];\nconst LOG2_26 = Math.log2(26); //\n/**\n * Hashes a string to a lowercase base-26 string.\n * @param str The string to hash.\n * @param length The length of the hash. Defaults to 10.\n * @param algorithm The hashing algorithm to use. Defaults to \"fnv1a\".\n * @returns The hashed string.\n */\nexport function hashNamespace(str: string, length = 10) {\n const requiredBits = Math.ceil(length * LOG2_26);\n const bitSize =\n SUPPORTED_SIZES.find((size) => size && size >= requiredBits) ?? 1024;\n const hash = fnv1a(str, { size: bitSize });\n return toBase26(hash, length);\n}\n\n// converts hash to lowercase letters\nfunction toBase26(num: bigint, length = 10): string {\n const alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n let out = \"\";\n while (num > 0n && out.length < length) {\n out = alphabet[Number(num % 26n)] + out;\n num /= 26n;\n }\n return out.padStart(length, \"a\"); // optional padding\n}\n\n/**\n * Creates a RelationalDb instance with namespace support.\n * @param baseDb The base RelationalDb instance to enhance.\n * @param baseOptions The default options for namespace creation. Hashes namespace by default.\n * @returns The enhanced RelationalDb instance.\n */\nexport function createRelationalDb<Schema>(\n baseDb: IBaseRelationalDb<Schema>,\n baseOptions?: NamespaceOptions,\n): IRelationalDb<Schema> {\n const relationalDb = baseDb as IRelationalDb<Schema>;\n\n relationalDb.createNamespace = <NamespaceSchema>(\n namespace: string,\n options?: NamespaceOptions,\n ) =>\n createNamespacedDb<NamespaceSchema>(\n baseDb,\n namespace,\n options ?? baseOptions,\n );\n\n relationalDb.queryNamespace = <NamespaceSchema>(\n namespace: string,\n options?: NamespaceOptions,\n ) =>\n createNamespacedQueryBuilder<NamespaceSchema>(\n baseDb,\n namespace,\n options ?? baseOptions,\n );\n\n return relationalDb;\n}\n\ntype NamespaceOptions = {\n hashNamespace?: boolean;\n};\n\nexport async function createNamespacedDb<Schema>(\n db: IBaseRelationalDb<any>,\n namespace: string,\n options?: NamespaceOptions,\n): Promise<IRelationalDb<Schema>> {\n // hash the namespace to avoid too long namespaces\n const shouldHash = options?.hashNamespace ?? true;\n const hashValue = shouldHash ? hashNamespace(namespace) : namespace;\n await db.schema.createSchema(hashValue).ifNotExists().execute();\n const schemaRelationalDb = db.withSchema(hashValue);\n return schemaRelationalDb as IRelationalDb<Schema>;\n}\n\nexport function createNamespacedQueryBuilder<Schema>(\n db: IBaseRelationalDb<any>,\n namespace: string,\n options?: NamespaceOptions,\n): IRelationalQueryBuilder<Schema> {\n const shouldHash = options?.hashNamespace ?? true;\n const hashValue = shouldHash ? hashNamespace(namespace) : namespace;\n const namespacedDb = db.withSchema(hashValue) as IRelationalDb<Schema>;\n return relationalDbToQueryBuilder(namespacedDb);\n}\n\n/**\n * Returns a query builder for a RelationalDb instance.\n * @param query The RelationalDb instance to convert.\n * @returns The IRelationalQueryBuilder instance.\n */\nexport function relationalDbToQueryBuilder<TSchema>(\n query: IBaseRelationalDb<TSchema>,\n): IRelationalQueryBuilder<TSchema> {\n return {\n selectFrom: query.selectFrom.bind(query),\n selectNoFrom: query.selectNoFrom.bind(query),\n with: query.with.bind(query),\n withRecursive: query.withRecursive.bind(query),\n withSchema: (schema: string) =>\n relationalDbToQueryBuilder<TSchema>(query.withSchema(schema)),\n };\n}\n","import type { OperationWithContext } from \"@powerhousedao/shared/document-model\";\nimport type { Kysely, QueryCreator } from \"kysely\";\nimport type { IProcessor, ProcessorFilter } from \"../types.js\";\nimport { relationalDbToQueryBuilder } from \"./utils.js\";\n\nexport type IRelationalQueryMethods =\n | \"selectFrom\"\n | \"selectNoFrom\"\n | \"with\"\n | \"withRecursive\";\n\nexport type IRelationalQueryBuilder<Schema = unknown> = Pick<\n QueryCreator<Schema>,\n IRelationalQueryMethods\n> & {\n withSchema: (schema: string) => IRelationalQueryBuilder<Schema>;\n};\n\nexport type HashAlgorithms = \"fnv1a\";\nexport type IBaseRelationalDb<Schema = unknown> = Kysely<Schema>;\n\n/**\n * The standardized relational database interface for relational db processors.\n * This abstraction provides type-safe database operations while hiding the underlying\n * database framework implementation details.\n **/\nexport type IRelationalDb<Schema = unknown> = IBaseRelationalDb<Schema> & {\n createNamespace<NamespaceSchema>(\n namespace: string,\n ): Promise<IRelationalDb<ExtractProcessorSchemaOrSelf<NamespaceSchema>>>;\n queryNamespace<NamespaceSchema>(\n namespace: string,\n ): IRelationalQueryBuilder<NamespaceSchema>;\n};\n\nexport type ExtractProcessorSchemaOrSelf<TProcessor> =\n TProcessor extends RelationalDbProcessor<infer TSchema>\n ? TSchema\n : TProcessor;\n\nexport type RelationalDbProcessorClass<TSchema> =\n typeof RelationalDbProcessor<TSchema>;\n\nexport interface IRelationalDbProcessor<\n TDatabaseSchema = unknown,\n> extends IProcessor {\n namespace: string;\n query: IRelationalQueryBuilder<TDatabaseSchema>;\n filter: ProcessorFilter;\n initAndUpgrade(): Promise<void>;\n}\n\nconst IS_RELATIONAL_DB_PROCESSOR = Symbol.for(\"ph.IS_RELATIONAL_DB_PROCESSOR\");\n\n/**\n * Base class for relational db processors that require a relational database storage.\n * This class abstracts database initialization, migration management, and resource cleanup,\n * allowing derived classes to focus on business logic.\n */\nexport abstract class RelationalDbProcessor<\n TDatabaseSchema = unknown,\n> implements IRelationalDbProcessor<TDatabaseSchema> {\n constructor(\n protected _namespace: string,\n protected _filter: ProcessorFilter,\n protected relationalDb: IRelationalDb<TDatabaseSchema>,\n ) {}\n\n static [IS_RELATIONAL_DB_PROCESSOR] = true;\n\n /**\n * Returns the namespace for a given drive id.\n * This method can be overridden by derived classes to provide a custom namespace.\n */\n static getNamespace(driveId: string): string {\n return `${this.name}_${driveId.replaceAll(\"-\", \"_\")}`;\n }\n\n static query<Schema>(\n this: RelationalDbProcessorClass<Schema>,\n driveId: string,\n db: IRelationalDb<any>,\n ): IRelationalQueryBuilder<Schema> {\n return db.queryNamespace(this.getNamespace(driveId));\n }\n\n /**\n * Processes a list of operations with context.\n * Called when operations match this processor's filter.\n */\n abstract onOperations(operations: OperationWithContext[]): Promise<void>;\n\n /**\n * Returns the filter for the processor.\n * This method can be overridden by derived classes to provide a custom filter.\n */\n get filter(): ProcessorFilter {\n return this._filter;\n }\n\n /**\n * Returns the namespace used by the processor.\n */\n get namespace(): string {\n return this._namespace;\n }\n\n get query(): IRelationalQueryBuilder<TDatabaseSchema> {\n return relationalDbToQueryBuilder(this.relationalDb);\n }\n\n /**\n * Abstract method that derived classes must implement.\n * This method is meant to be called on subclasses to initialize and upgrade the database.\n */\n abstract initAndUpgrade(): Promise<void>;\n\n /**\n * Called when the processor is disconnected.\n * This method is meant to be overridden by subclasses to clean up resources.\n */\n abstract onDisconnect(): Promise<void>;\n}\n"],"mappings":";;AAAA,MAAa,iBAAiB,CAAC,WAAW,aAAa;AACvD,MAAa,uCAAuC;AACpD,MAAa,sCAAsC;;;ACMnD,MAAM,kBAAqC;CAAC;CAAI;CAAI;CAAK;CAAK;CAAK;AAAI;AACvE,MAAM,UAAU,KAAK,KAAK,EAAE;;;;;;;;AAQ5B,SAAgB,cAAc,KAAa,SAAS,IAAI;CACtD,MAAM,eAAe,KAAK,KAAK,SAAS,OAAO;CAC/C,MAAM,UACJ,gBAAgB,MAAM,SAAS,QAAQ,QAAQ,YAAY,KAAK;CAElE,OAAO,SADM,MAAM,KAAK,EAAE,MAAM,QAAQ,CACrB,GAAG,MAAM;AAC9B;AAGA,SAAS,SAAS,KAAa,SAAS,IAAY;CAClD,MAAM,WAAW;CACjB,IAAI,MAAM;CACV,OAAO,MAAM,MAAM,IAAI,SAAS,QAAQ;EACtC,MAAM,SAAS,OAAO,MAAM,GAAG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;CAYA,IAAI,SAA0B;EAC5B,OAAO,KAAK;CACd;;;;CAKA,IAAI,YAAoB;EACtB,OAAO,KAAK;CACd;CAEA,IAAI,QAAkD;EACpD,OAAO,2BAA2B,KAAK,YAAY;CACrD;AAaF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../processors/constants.ts","../../processors/deletion.ts","../../processors/relational/types.ts","../../processors/codegen-status.ts"],"sourcesContent":["export const PROCESSOR_APPS = [\"connect\", \"switchboard\"] as const;\nexport const DEFAULT_RELATIONAL_PROCESSOR_DB_NAME = \"relational-db\";\nexport const DEFAULT_ANALYTICS_PROCESSOR_DB_NAME = \"analytics-db\";\n","import type { OperationWithContext } from \"../document-model/index.js\";\nimport { PURGE_DOCUMENT } from \"../document-model/purge.js\";\n\n/** The id a DELETE_DOCUMENT or PURGE_DOCUMENT removes; undefined otherwise. */\nexport function deletedDocumentId(\n op: OperationWithContext,\n): string | undefined {\n const { type, input } = op.operation.action;\n if (type !== \"DELETE_DOCUMENT\" && type !== PURGE_DOCUMENT) return undefined;\n const documentId = (input as { documentId?: unknown } | undefined)\n ?.documentId;\n return typeof documentId === \"string\" ? documentId : op.context.documentId;\n}\n","import type { OperationWithContext } from \"@powerhousedao/shared/document-model\";\nimport { sql, type Kysely, type QueryCreator } from \"kysely\";\nimport type { IProcessor, ProcessorFilter } from \"../types.js\";\nimport { namespaceSchemaOf, relationalDbToQueryBuilder } from \"./utils.js\";\n\n/** Columns {@link RelationalDbProcessor.deleteDocumentRows} matches. */\nexport const DOCUMENT_ID_COLUMNS = [\"document_id\", \"documentId\"] as const;\n\nexport type IRelationalQueryMethods =\n | \"selectFrom\"\n | \"selectNoFrom\"\n | \"with\"\n | \"withRecursive\";\n\nexport type IRelationalQueryBuilder<Schema = unknown> = Pick<\n QueryCreator<Schema>,\n IRelationalQueryMethods\n> & {\n withSchema: (schema: string) => IRelationalQueryBuilder<Schema>;\n};\n\nexport type HashAlgorithms = \"fnv1a\";\nexport type IBaseRelationalDb<Schema = unknown> = Kysely<Schema>;\n\n/**\n * The standardized relational database interface for relational db processors.\n * This abstraction provides type-safe database operations while hiding the underlying\n * database framework implementation details.\n **/\nexport type IRelationalDb<Schema = unknown> = IBaseRelationalDb<Schema> & {\n createNamespace<NamespaceSchema>(\n namespace: string,\n ): Promise<IRelationalDb<ExtractProcessorSchemaOrSelf<NamespaceSchema>>>;\n queryNamespace<NamespaceSchema>(\n namespace: string,\n ): IRelationalQueryBuilder<NamespaceSchema>;\n};\n\nexport type ExtractProcessorSchemaOrSelf<TProcessor> =\n TProcessor extends RelationalDbProcessor<infer TSchema>\n ? TSchema\n : TProcessor;\n\nexport type RelationalDbProcessorClass<TSchema> =\n typeof RelationalDbProcessor<TSchema>;\n\nexport interface IRelationalDbProcessor<\n TDatabaseSchema = unknown,\n> extends IProcessor {\n namespace: string;\n query: IRelationalQueryBuilder<TDatabaseSchema>;\n filter: ProcessorFilter;\n initAndUpgrade(): Promise<void>;\n}\n\nconst IS_RELATIONAL_DB_PROCESSOR = Symbol.for(\"ph.IS_RELATIONAL_DB_PROCESSOR\");\n\n/**\n * Base class for relational db processors that require a relational database storage.\n * This class abstracts database initialization, migration management, and resource cleanup,\n * allowing derived classes to focus on business logic.\n */\nexport abstract class RelationalDbProcessor<\n TDatabaseSchema = unknown,\n> implements IRelationalDbProcessor<TDatabaseSchema> {\n constructor(\n protected _namespace: string,\n protected _filter: ProcessorFilter,\n protected relationalDb: IRelationalDb<TDatabaseSchema>,\n /** The drive the factory created this processor for. */\n protected _driveId?: string,\n ) {}\n\n static [IS_RELATIONAL_DB_PROCESSOR] = true;\n\n /**\n * Returns the namespace for a given drive id.\n * This method can be overridden by derived classes to provide a custom namespace.\n */\n static getNamespace(driveId: string): string {\n return `${this.name}_${driveId.replaceAll(\"-\", \"_\")}`;\n }\n\n static query<Schema>(\n this: RelationalDbProcessorClass<Schema>,\n driveId: string,\n db: IRelationalDb<any>,\n ): IRelationalQueryBuilder<Schema> {\n return db.queryNamespace(this.getNamespace(driveId));\n }\n\n /**\n * Processes a list of operations with context.\n * Called when operations match this processor's filter.\n */\n abstract onOperations(operations: OperationWithContext[]): Promise<void>;\n\n /**\n * Returns the filter for the processor.\n * This method can be overridden by derived classes to provide a custom filter.\n */\n get filter(): ProcessorFilter {\n return this._filter;\n }\n\n /**\n * Returns the namespace used by the processor.\n */\n get namespace(): string {\n return this._namespace;\n }\n\n /** Processors writing one namespace are cleared together. */\n get clearScope(): string {\n return this._namespace;\n }\n\n /** Drops the namespace and its tables, then migrates it afresh. */\n async clear(): Promise<void> {\n await this.dropNamespace();\n await this.relationalDb.schema\n .createSchema(this.namespaceSchema())\n .ifNotExists()\n .execute();\n await this.initAndUpgrade();\n }\n\n get query(): IRelationalQueryBuilder<TDatabaseSchema> {\n return relationalDbToQueryBuilder(this.relationalDb);\n }\n\n /** True for this processor's drive when its namespace is that drive's alone. */\n protected isNamespaceDrive(documentId: string): boolean {\n const driveId = this._driveId;\n if (driveId === undefined || documentId !== driveId) return false;\n const processorClass = this.constructor as typeof RelationalDbProcessor;\n if (processorClass.getNamespace(driveId) !== this._namespace) return false;\n return processorClass.getNamespace(`${driveId}-other`) !== this._namespace;\n }\n\n /** Deletes a document's rows from every table with a document-id column. */\n protected async deleteDocumentRows(documentId: string): Promise<void> {\n const schema = this.namespaceSchema();\n const columns = await sql<{ table_name: string; column_name: string }>`\n select c.table_name, c.column_name\n from information_schema.columns c\n join information_schema.tables t\n on t.table_schema = c.table_schema and t.table_name = c.table_name\n where c.table_schema = ${schema}\n and t.table_type = 'BASE TABLE'\n and c.column_name in (${sql.join([...DOCUMENT_ID_COLUMNS])})\n order by c.table_name, c.column_name\n `.execute(this.relationalDb);\n const db = this.relationalDb as unknown as Kysely<any>;\n for (const { table_name, column_name } of columns.rows) {\n await db\n .deleteFrom(table_name)\n .where(column_name, \"=\", documentId)\n .execute();\n }\n }\n\n /** Drops this processor's namespace and every table in it. */\n protected async dropNamespace(): Promise<void> {\n await this.relationalDb.schema\n .dropSchema(this.namespaceSchema())\n .ifExists()\n .cascade()\n .execute();\n }\n\n private namespaceSchema(): string {\n const schema = namespaceSchemaOf(this.relationalDb);\n if (schema === undefined) {\n throw new Error(\n `Namespace '${this._namespace}' was not opened with createNamespace`,\n );\n }\n return schema;\n }\n\n /**\n * Abstract method that derived classes must implement.\n * This method is meant to be called on subclasses to initialize and upgrade the database.\n */\n abstract initAndUpgrade(): Promise<void>;\n\n /**\n * Called when the processor is disconnected.\n * This method is meant to be overridden by subclasses to clean up resources.\n */\n abstract onDisconnect(): Promise<void>;\n}\n","/** Where a codegen job for one document stands; `done`, `failed` and `skipped` are settled. */\nexport type CodegenState =\n | \"queued\"\n | \"running\"\n | \"waiting-for-install\"\n | \"done\"\n | \"failed\"\n | \"skipped\";\n\nexport const SETTLED_CODEGEN_STATES: readonly CodegenState[] = [\n \"done\",\n \"failed\",\n \"skipped\",\n];\n\nexport type CodegenStatus = {\n documentId: string;\n documentType: string;\n /** The module's name, once the job has read the document. */\n name?: string;\n state: CodegenState;\n /** Why it was skipped or failed, or what it waits for. */\n message?: string;\n /** Project files the job wrote, relative to the project. */\n files?: string[];\n /** ISO timestamp of the last change. */\n updatedAt: string;\n};\n\n/** A package module the reactor failed to load, e.g. broken generated code. */\nexport type PackageLoadFailure = {\n package: string;\n /** What was loaded: \"document models\", \"subgraphs\", \"processors\", ... */\n kind: string;\n message: string;\n updatedAt: string;\n};\n\nexport function isSettledCodegenState(state: CodegenState): boolean {\n return SETTLED_CODEGEN_STATES.includes(state);\n}\n\n/** Vetra's codegen status per document, and failed package loads. The codegen\n * processor, the package loader and reactor-mcp share it in one process. */\nexport class CodegenStatusRegistry {\n #documentTypes = new Set<string>();\n #statuses = new Map<string, CodegenStatus>();\n #loadFailures = new Map<string, PackageLoadFailure>();\n #listeners = new Set<() => void>();\n\n /** Records that a codegen processor generates code for `documentTypes`. */\n watch(documentTypes: readonly string[]): void {\n for (const type of documentTypes) this.#documentTypes.add(type);\n this.#notify();\n }\n\n /** Whether a codegen processor runs in this process. */\n get active(): boolean {\n return this.#documentTypes.size > 0;\n }\n\n get documentTypes(): string[] {\n return [...this.#documentTypes];\n }\n\n watches(documentType: string): boolean {\n return this.#documentTypes.has(documentType);\n }\n\n /** Replaces a document's status; `name` carries over unless given. */\n set(\n status: Omit<CodegenStatus, \"updatedAt\" | \"name\"> & { name?: string },\n ): CodegenStatus {\n const name = status.name ?? this.#statuses.get(status.documentId)?.name;\n const next: CodegenStatus = {\n documentId: status.documentId,\n documentType: status.documentType,\n ...(name !== undefined && { name }),\n state: status.state,\n ...(status.message !== undefined && { message: status.message }),\n ...(status.files !== undefined && { files: status.files }),\n updatedAt: new Date().toISOString(),\n };\n this.#statuses.set(status.documentId, next);\n this.#notify();\n return next;\n }\n\n get(documentId: string): CodegenStatus | undefined {\n return this.#statuses.get(documentId);\n }\n\n /** Most recently updated first. */\n list(): CodegenStatus[] {\n return [...this.#statuses.values()].sort((a, b) =>\n b.updatedAt.localeCompare(a.updatedAt),\n );\n }\n\n delete(documentId: string): void {\n if (this.#statuses.delete(documentId)) this.#notify();\n }\n\n /** Records a failed load of `kind` from `pkg`; no `failure` clears it. */\n reportLoad(pkg: string, kind: string, failure?: string): void {\n const key = `${pkg}\\u0000${kind}`;\n if (failure === undefined) {\n if (this.#loadFailures.delete(key)) this.#notify();\n return;\n }\n this.#loadFailures.set(key, {\n package: pkg,\n kind,\n message: failure,\n updatedAt: new Date().toISOString(),\n });\n this.#notify();\n }\n\n loadFailures(): PackageLoadFailure[] {\n return [...this.#loadFailures.values()];\n }\n\n /** Whether `documentId`'s job, or every job when omitted, has settled. */\n settled(documentId?: string): boolean {\n const statuses =\n documentId === undefined\n ? this.list()\n : [this.get(documentId)].filter((s) => s !== undefined);\n return statuses.every((status) => isSettledCodegenState(status.state));\n }\n\n /** Resolves to whether the jobs settled within `timeoutMs`. */\n waitUntilSettled(\n documentId: string | undefined,\n timeoutMs: number,\n ): Promise<boolean> {\n if (this.settled(documentId)) return Promise.resolve(true);\n return new Promise((resolve) => {\n const finish = (settled: boolean) => {\n clearTimeout(timer);\n unsubscribe();\n resolve(settled);\n };\n const timer = setTimeout(() => finish(false), timeoutMs);\n const unsubscribe = this.subscribe(() => {\n if (this.settled(documentId)) finish(true);\n });\n });\n }\n\n subscribe(listener: () => void): () => void {\n this.#listeners.add(listener);\n return () => {\n this.#listeners.delete(listener);\n };\n }\n\n /** Forgets everything; for tests. */\n clear(): void {\n this.#documentTypes.clear();\n this.#statuses.clear();\n this.#loadFailures.clear();\n this.#notify();\n }\n\n #notify(): void {\n for (const listener of this.#listeners) listener();\n }\n}\n\n// On globalThis, so two copies of this package in one process share it.\nconst REGISTRY_KEY = Symbol.for(\"@powerhousedao/shared/codegen-status\");\n\n/** The process's codegen status registry. */\nexport function getCodegenStatusRegistry(): CodegenStatusRegistry {\n const holder = globalThis as { [REGISTRY_KEY]?: CodegenStatusRegistry };\n return (holder[REGISTRY_KEY] ??= new CodegenStatusRegistry());\n}\n"],"mappings":";;;;AAAA,MAAa,iBAAiB,CAAC,WAAW,aAAa;AACvD,MAAa,uCAAuC;AACpD,MAAa,sCAAsC;;;;ACEnD,SAAgB,kBACd,IACoB;CACpB,MAAM,EAAE,MAAM,UAAU,GAAG,UAAU;CACrC,IAAI,SAAS,qBAAqB,SAAA,kBAAyB,OAAO,KAAA;CAClE,MAAM,aAAc,OAChB;CACJ,OAAO,OAAO,eAAe,WAAW,aAAa,GAAG,QAAQ;AAClE;;;;ACNA,MAAa,sBAAsB,CAAC,eAAe,YAAY;AAiD/D,MAAM,6BAA6B,OAAO,IAAI,+BAA+B;;;;;;AAO7E,IAAsB,wBAAtB,MAEqD;CAEvC;CACA;CACA;CAEA;CALZ,YACE,YACA,SACA,cAEA,UACA;EALU,KAAA,aAAA;EACA,KAAA,UAAA;EACA,KAAA,eAAA;EAEA,KAAA,WAAA;CACT;CAEH,QAAQ,8BAA8B;;;;;CAMtC,OAAO,aAAa,SAAyB;EAC3C,OAAO,GAAG,KAAK,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,KAAK,eAAe,MAAM;EAC1B,KAAK,UAAU,MAAM;EACrB,KAAK,cAAc,MAAM;EACzB,KAAK,QAAQ;CACf;CAEA,UAAgB;EACd,KAAK,MAAM,YAAY,KAAK,YAAY,SAAS;CACnD;AACF;AAGA,MAAM,eAAe,OAAO,IAAI,sCAAsC;;AAGtE,SAAgB,2BAAkD;CAChE,MAAM,SAAS;CACf,OAAQ,OAAO,kBAAkB,IAAI,sBAAsB;AAC7D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Bo as IRelationalDb, Lo as ExtractProcessorSchemaOrSelf } from "../types-CV2j3BvH.js";
|
|
2
|
+
import { OperationWithContext, PHDocument } from "@powerhousedao/shared/document-model";
|
|
3
|
+
//#region processors/testing.d.ts
|
|
4
|
+
/** An in-memory PGlite database, as a host's `module.relationalDb`. `destroy()` closes it. */
|
|
5
|
+
export declare function createTestRelationalDb(): IRelationalDb;
|
|
6
|
+
/** Opens `namespace` as a processor factory does and runs a migration's `up` in it. */
|
|
7
|
+
export declare function runProcessorMigrations<Schema>(db: IRelationalDb, namespace: string, up: (db: IRelationalDb<any>) => Promise<void>): Promise<IRelationalDb<ExtractProcessorSchemaOrSelf<Schema>>>;
|
|
8
|
+
/** A document's operations as a processor's `onOperations` receives them. */
|
|
9
|
+
export declare function operationsWithContext(document: PHDocument, scopes?: string[]): OperationWithContext[];
|
|
10
|
+
/** One operation for a processor test, without a reducer to produce it. */
|
|
11
|
+
export declare function testOperation(options: {
|
|
12
|
+
documentId: string;
|
|
13
|
+
documentType: string;
|
|
14
|
+
type: string;
|
|
15
|
+
input?: unknown;
|
|
16
|
+
scope?: string;
|
|
17
|
+
index?: number;
|
|
18
|
+
timestampUtcMs?: string;
|
|
19
|
+
}): OperationWithContext;
|
|
20
|
+
//#endregion
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","names":[],"sources":["../../processors/testing.ts"],"mappings":";;;;wBAegB,0BAA0B;;wBAYpB,uBAAuB,QAC3C,IAAI,eACJ,mBACA,KAAK,IAAI,uBAAuB,gBAC/B,QAAQ,cAAc,6BAA6B;;wBAOtC,sBACd,UAAU,YACV,oBACC;;wBAuBa,cAAc;EAC5B;EACA;EACA;EACA;EACA;EACA;EACA;IACE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { r as createRelationalDb } from "../utils-MrLmLEVr.js";
|
|
2
|
+
import { Kysely } from "kysely";
|
|
3
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
4
|
+
import { PGliteDialect } from "kysely-pglite-dialect";
|
|
5
|
+
//#region processors/testing.ts
|
|
6
|
+
/** An in-memory PGlite database, as a host's `module.relationalDb`. `destroy()` closes it. */
|
|
7
|
+
function createTestRelationalDb() {
|
|
8
|
+
const pglite = new PGlite();
|
|
9
|
+
const kysely = new Kysely({ dialect: new PGliteDialect(pglite) });
|
|
10
|
+
const destroy = kysely.destroy.bind(kysely);
|
|
11
|
+
kysely.destroy = async () => {
|
|
12
|
+
await destroy();
|
|
13
|
+
await pglite.close();
|
|
14
|
+
};
|
|
15
|
+
return createRelationalDb(kysely);
|
|
16
|
+
}
|
|
17
|
+
/** Opens `namespace` as a processor factory does and runs a migration's `up` in it. */
|
|
18
|
+
async function runProcessorMigrations(db, namespace, up) {
|
|
19
|
+
const store = await db.createNamespace(namespace);
|
|
20
|
+
await up(store);
|
|
21
|
+
return store;
|
|
22
|
+
}
|
|
23
|
+
/** A document's operations as a processor's `onOperations` receives them. */
|
|
24
|
+
function operationsWithContext(document, scopes = Object.keys(document.operations)) {
|
|
25
|
+
const operations = scopes.flatMap((scope) => (document.operations[scope] ?? []).map((operation) => ({
|
|
26
|
+
operation,
|
|
27
|
+
context: {
|
|
28
|
+
documentId: document.header.id,
|
|
29
|
+
documentType: document.header.documentType,
|
|
30
|
+
scope,
|
|
31
|
+
branch: "main",
|
|
32
|
+
ordinal: 0
|
|
33
|
+
}
|
|
34
|
+
})));
|
|
35
|
+
operations.sort((a, b) => a.operation.timestampUtcMs.localeCompare(b.operation.timestampUtcMs));
|
|
36
|
+
return operations.map((entry, index) => ({
|
|
37
|
+
...entry,
|
|
38
|
+
context: {
|
|
39
|
+
...entry.context,
|
|
40
|
+
ordinal: index + 1
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
/** One operation for a processor test, without a reducer to produce it. */
|
|
45
|
+
function testOperation(options) {
|
|
46
|
+
const scope = options.scope ?? "global";
|
|
47
|
+
const timestampUtcMs = options.timestampUtcMs ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
48
|
+
const index = options.index ?? 0;
|
|
49
|
+
const action = {
|
|
50
|
+
id: `${options.documentId}-${scope}-${index}`,
|
|
51
|
+
type: options.type,
|
|
52
|
+
input: options.input ?? {},
|
|
53
|
+
scope,
|
|
54
|
+
timestampUtcMs
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
operation: {
|
|
58
|
+
id: action.id,
|
|
59
|
+
index,
|
|
60
|
+
skip: 0,
|
|
61
|
+
timestampUtcMs,
|
|
62
|
+
hash: "",
|
|
63
|
+
action
|
|
64
|
+
},
|
|
65
|
+
context: {
|
|
66
|
+
documentId: options.documentId,
|
|
67
|
+
documentType: options.documentType,
|
|
68
|
+
scope,
|
|
69
|
+
branch: "main",
|
|
70
|
+
ordinal: index + 1
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { createTestRelationalDb, operationsWithContext, runProcessorMigrations, testOperation };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","names":[],"sources":["../../processors/testing.ts"],"sourcesContent":["import { PGlite } from \"@electric-sql/pglite\";\nimport type {\n Action,\n OperationWithContext,\n PHDocument,\n} from \"@powerhousedao/shared/document-model\";\nimport { Kysely } from \"kysely\";\nimport { PGliteDialect } from \"kysely-pglite-dialect\";\nimport type {\n ExtractProcessorSchemaOrSelf,\n IRelationalDb,\n} from \"./relational/types.js\";\nimport { createRelationalDb } from \"./relational/utils.js\";\n\n/** An in-memory PGlite database, as a host's `module.relationalDb`. `destroy()` closes it. */\nexport function createTestRelationalDb(): IRelationalDb {\n const pglite = new PGlite();\n const kysely = new Kysely<unknown>({ dialect: new PGliteDialect(pglite) });\n const destroy = kysely.destroy.bind(kysely);\n kysely.destroy = async () => {\n await destroy();\n await pglite.close();\n };\n return createRelationalDb(kysely);\n}\n\n/** Opens `namespace` as a processor factory does and runs a migration's `up` in it. */\nexport async function runProcessorMigrations<Schema>(\n db: IRelationalDb,\n namespace: string,\n up: (db: IRelationalDb<any>) => Promise<void>,\n): Promise<IRelationalDb<ExtractProcessorSchemaOrSelf<Schema>>> {\n const store = await db.createNamespace<Schema>(namespace);\n await up(store);\n return store;\n}\n\n/** A document's operations as a processor's `onOperations` receives them. */\nexport function operationsWithContext(\n document: PHDocument,\n scopes: string[] = Object.keys(document.operations),\n): OperationWithContext[] {\n const operations = scopes.flatMap((scope) =>\n (document.operations[scope] ?? []).map((operation) => ({\n operation,\n context: {\n documentId: document.header.id,\n documentType: document.header.documentType,\n scope,\n branch: \"main\",\n ordinal: 0,\n },\n })),\n );\n operations.sort((a, b) =>\n a.operation.timestampUtcMs.localeCompare(b.operation.timestampUtcMs),\n );\n return operations.map((entry, index) => ({\n ...entry,\n context: { ...entry.context, ordinal: index + 1 },\n }));\n}\n\n/** One operation for a processor test, without a reducer to produce it. */\nexport function testOperation(options: {\n documentId: string;\n documentType: string;\n type: string;\n input?: unknown;\n scope?: string;\n index?: number;\n timestampUtcMs?: string;\n}): OperationWithContext {\n const scope = options.scope ?? \"global\";\n const timestampUtcMs = options.timestampUtcMs ?? new Date().toISOString();\n const index = options.index ?? 0;\n const action: Action = {\n id: `${options.documentId}-${scope}-${index}`,\n type: options.type,\n input: options.input ?? {},\n scope,\n timestampUtcMs,\n };\n return {\n operation: {\n id: action.id,\n index,\n skip: 0,\n timestampUtcMs,\n hash: \"\",\n action,\n },\n context: {\n documentId: options.documentId,\n documentType: options.documentType,\n scope,\n branch: \"main\",\n ordinal: index + 1,\n },\n };\n}\n"],"mappings":";;;;;;AAeA,SAAgB,yBAAwC;CACtD,MAAM,SAAS,IAAI,OAAO;CAC1B,MAAM,SAAS,IAAI,OAAgB,EAAE,SAAS,IAAI,cAAc,MAAM,EAAE,CAAC;CACzE,MAAM,UAAU,OAAO,QAAQ,KAAK,MAAM;CAC1C,OAAO,UAAU,YAAY;EAC3B,MAAM,QAAQ;EACd,MAAM,OAAO,MAAM;CACrB;CACA,OAAO,mBAAmB,MAAM;AAClC;;AAGA,eAAsB,uBACpB,IACA,WACA,IAC8D;CAC9D,MAAM,QAAQ,MAAM,GAAG,gBAAwB,SAAS;CACxD,MAAM,GAAG,KAAK;CACd,OAAO;AACT;;AAGA,SAAgB,sBACd,UACA,SAAmB,OAAO,KAAK,SAAS,UAAU,GAC1B;CACxB,MAAM,aAAa,OAAO,SAAS,WAChC,SAAS,WAAW,UAAU,CAAC,EAAA,CAAG,KAAK,eAAe;EACrD;EACA,SAAS;GACP,YAAY,SAAS,OAAO;GAC5B,cAAc,SAAS,OAAO;GAC9B;GACA,QAAQ;GACR,SAAS;EACX;CACF,EAAE,CACJ;CACA,WAAW,MAAM,GAAG,MAClB,EAAE,UAAU,eAAe,cAAc,EAAE,UAAU,cAAc,CACrE;CACA,OAAO,WAAW,KAAK,OAAO,WAAW;EACvC,GAAG;EACH,SAAS;GAAE,GAAG,MAAM;GAAS,SAAS,QAAQ;EAAE;CAClD,EAAE;AACJ;;AAGA,SAAgB,cAAc,SAQL;CACvB,MAAM,QAAQ,QAAQ,SAAS;CAC/B,MAAM,iBAAiB,QAAQ,mCAAkB,IAAI,KAAK,EAAA,CAAE,YAAY;CACxE,MAAM,QAAQ,QAAQ,SAAS;CAC/B,MAAM,SAAiB;EACr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