@shware/workflow 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +154 -2
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/apns-relay.cjs +105 -0
- package/dist/apns-relay.cjs.map +1 -0
- package/dist/apns-relay.d.cts +28 -0
- package/dist/apns-relay.d.cts.map +1 -0
- package/dist/apns-relay.d.mts +28 -0
- package/dist/apns-relay.d.mts.map +1 -0
- package/dist/apns-relay.mjs +104 -0
- package/dist/apns-relay.mjs.map +1 -0
- package/dist/apns.cjs +121 -0
- package/dist/apns.cjs.map +1 -0
- package/dist/apns.d.cts +63 -0
- package/dist/apns.d.cts.map +1 -0
- package/dist/apns.d.mts +63 -0
- package/dist/apns.d.mts.map +1 -0
- package/dist/apns.mjs +116 -0
- package/dist/apns.mjs.map +1 -0
- package/dist/client.cjs +125 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +108 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.mts +108 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +122 -0
- package/dist/client.mjs.map +1 -0
- package/dist/cloudflare/bindings.cjs +28 -0
- package/dist/cloudflare/bindings.cjs.map +1 -0
- package/dist/cloudflare/bindings.d.cts +144 -0
- package/dist/cloudflare/bindings.d.cts.map +1 -0
- package/dist/cloudflare/bindings.d.mts +144 -0
- package/dist/cloudflare/bindings.d.mts.map +1 -0
- package/dist/cloudflare/bindings.mjs +25 -0
- package/dist/cloudflare/bindings.mjs.map +1 -0
- package/dist/cloudflare/channels.cjs +164 -0
- package/dist/cloudflare/channels.cjs.map +1 -0
- package/dist/cloudflare/channels.d.cts +29 -0
- package/dist/cloudflare/channels.d.cts.map +1 -0
- package/dist/cloudflare/channels.d.mts +29 -0
- package/dist/cloudflare/channels.d.mts.map +1 -0
- package/dist/cloudflare/channels.mjs +161 -0
- package/dist/cloudflare/channels.mjs.map +1 -0
- package/dist/cloudflare/d1-env.cjs +17 -0
- package/dist/cloudflare/d1-env.cjs.map +1 -0
- package/dist/cloudflare/d1-env.d.cts +12 -0
- package/dist/cloudflare/d1-env.d.cts.map +1 -0
- package/dist/cloudflare/d1-env.d.mts +12 -0
- package/dist/cloudflare/d1-env.d.mts.map +1 -0
- package/dist/cloudflare/d1-env.mjs +16 -0
- package/dist/cloudflare/d1-env.mjs.map +1 -0
- package/dist/cloudflare/index.cjs +54 -0
- package/dist/cloudflare/index.d.cts +19 -0
- package/dist/cloudflare/index.d.mts +19 -0
- package/dist/cloudflare/index.mjs +16 -0
- package/dist/cloudflare/router.cjs +516 -0
- package/dist/cloudflare/router.cjs.map +1 -0
- package/dist/cloudflare/router.d.cts +157 -0
- package/dist/cloudflare/router.d.cts.map +1 -0
- package/dist/cloudflare/router.d.mts +157 -0
- package/dist/cloudflare/router.d.mts.map +1 -0
- package/dist/cloudflare/router.mjs +503 -0
- package/dist/cloudflare/router.mjs.map +1 -0
- package/dist/cloudflare/runner.cjs +225 -0
- package/dist/cloudflare/runner.cjs.map +1 -0
- package/dist/cloudflare/runner.d.cts +73 -0
- package/dist/cloudflare/runner.d.cts.map +1 -0
- package/dist/cloudflare/runner.d.mts +73 -0
- package/dist/cloudflare/runner.d.mts.map +1 -0
- package/dist/cloudflare/runner.mjs +224 -0
- package/dist/cloudflare/runner.mjs.map +1 -0
- package/dist/cloudflare/schema.sql +127 -0
- package/dist/cloudflare/senders.cjs +114 -0
- package/dist/cloudflare/senders.cjs.map +1 -0
- package/dist/cloudflare/senders.d.cts +68 -0
- package/dist/cloudflare/senders.d.cts.map +1 -0
- package/dist/cloudflare/senders.d.mts +68 -0
- package/dist/cloudflare/senders.d.mts.map +1 -0
- package/dist/cloudflare/senders.mjs +108 -0
- package/dist/cloudflare/senders.mjs.map +1 -0
- package/dist/cloudflare/worker.cjs +228 -0
- package/dist/cloudflare/worker.cjs.map +1 -0
- package/dist/cloudflare/worker.d.cts +92 -0
- package/dist/cloudflare/worker.d.cts.map +1 -0
- package/dist/cloudflare/worker.d.mts +92 -0
- package/dist/cloudflare/worker.d.mts.map +1 -0
- package/dist/cloudflare/worker.mjs +224 -0
- package/dist/cloudflare/worker.mjs.map +1 -0
- package/dist/cloudflare/workers.d.cjs +0 -0
- package/dist/cloudflare/workers.d.cts +44 -0
- package/dist/cloudflare/workers.d.cts.map +1 -0
- package/dist/cloudflare/workers.d.mts +44 -0
- package/dist/cloudflare/workers.d.mts.map +1 -0
- package/dist/config.cjs +151 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +149 -0
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.mts +149 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +143 -0
- package/dist/config.mjs.map +1 -0
- package/dist/contract.cjs +212 -0
- package/dist/contract.cjs.map +1 -0
- package/dist/contract.d.cts +90 -0
- package/dist/contract.d.cts.map +1 -0
- package/dist/contract.d.mts +90 -0
- package/dist/contract.d.mts.map +1 -0
- package/dist/contract.mjs +206 -0
- package/dist/contract.mjs.map +1 -0
- package/dist/dsl/action.cjs +29 -0
- package/dist/dsl/action.cjs.map +1 -0
- package/dist/dsl/action.d.cts +64 -0
- package/dist/dsl/action.d.cts.map +1 -0
- package/dist/dsl/action.d.mts +64 -0
- package/dist/dsl/action.d.mts.map +1 -0
- package/dist/dsl/action.mjs +28 -0
- package/dist/dsl/action.mjs.map +1 -0
- package/dist/dsl/base.cjs +34 -0
- package/dist/dsl/base.cjs.map +1 -0
- package/dist/dsl/base.d.cts +45 -0
- package/dist/dsl/base.d.cts.map +1 -0
- package/dist/dsl/base.d.mts +45 -0
- package/dist/dsl/base.d.mts.map +1 -0
- package/dist/dsl/base.mjs +30 -0
- package/dist/dsl/base.mjs.map +1 -0
- package/dist/dsl/bundle.cjs +207 -0
- package/dist/dsl/bundle.cjs.map +1 -0
- package/dist/dsl/bundle.d.cts +19 -0
- package/dist/dsl/bundle.d.cts.map +1 -0
- package/dist/dsl/bundle.d.mts +19 -0
- package/dist/dsl/bundle.d.mts.map +1 -0
- package/dist/dsl/bundle.mjs +206 -0
- package/dist/dsl/bundle.mjs.map +1 -0
- package/dist/dsl/condition.cjs +177 -0
- package/dist/dsl/condition.cjs.map +1 -0
- package/dist/dsl/condition.d.cts +140 -0
- package/dist/dsl/condition.d.cts.map +1 -0
- package/dist/dsl/condition.d.mts +140 -0
- package/dist/dsl/condition.d.mts.map +1 -0
- package/dist/dsl/condition.mjs +156 -0
- package/dist/dsl/condition.mjs.map +1 -0
- package/dist/dsl/flow.cjs +228 -0
- package/dist/dsl/flow.cjs.map +1 -0
- package/dist/dsl/flow.d.cts +223 -0
- package/dist/dsl/flow.d.cts.map +1 -0
- package/dist/dsl/flow.d.mts +223 -0
- package/dist/dsl/flow.d.mts.map +1 -0
- package/dist/dsl/flow.mjs +226 -0
- package/dist/dsl/flow.mjs.map +1 -0
- package/dist/dsl/index.cjs +38 -0
- package/dist/dsl/index.d.cts +10 -0
- package/dist/dsl/index.d.mts +10 -0
- package/dist/dsl/index.mjs +9 -0
- package/dist/dsl/refs.cjs +59 -0
- package/dist/dsl/refs.cjs.map +1 -0
- package/dist/dsl/refs.d.cts +88 -0
- package/dist/dsl/refs.d.cts.map +1 -0
- package/dist/dsl/refs.d.mts +88 -0
- package/dist/dsl/refs.d.mts.map +1 -0
- package/dist/dsl/refs.mjs +55 -0
- package/dist/dsl/refs.mjs.map +1 -0
- package/dist/dsl/template.cjs +65 -0
- package/dist/dsl/template.cjs.map +1 -0
- package/dist/dsl/template.d.cts +75 -0
- package/dist/dsl/template.d.cts.map +1 -0
- package/dist/dsl/template.d.mts +75 -0
- package/dist/dsl/template.d.mts.map +1 -0
- package/dist/dsl/template.mjs +63 -0
- package/dist/dsl/template.mjs.map +1 -0
- package/dist/dsl/trigger.cjs +40 -0
- package/dist/dsl/trigger.cjs.map +1 -0
- package/dist/dsl/trigger.d.cts +65 -0
- package/dist/dsl/trigger.d.cts.map +1 -0
- package/dist/dsl/trigger.d.mts +65 -0
- package/dist/dsl/trigger.d.mts.map +1 -0
- package/dist/dsl/trigger.mjs +39 -0
- package/dist/dsl/trigger.mjs.map +1 -0
- package/dist/dsl/workflow.cjs +121 -0
- package/dist/dsl/workflow.cjs.map +1 -0
- package/dist/dsl/workflow.d.cts +59 -0
- package/dist/dsl/workflow.d.cts.map +1 -0
- package/dist/dsl/workflow.d.mts +59 -0
- package/dist/dsl/workflow.d.mts.map +1 -0
- package/dist/dsl/workflow.mjs +120 -0
- package/dist/dsl/workflow.mjs.map +1 -0
- package/dist/engine/actions.cjs +27 -0
- package/dist/engine/actions.cjs.map +1 -0
- package/dist/engine/actions.d.cts +40 -0
- package/dist/engine/actions.d.cts.map +1 -0
- package/dist/engine/actions.d.mts +40 -0
- package/dist/engine/actions.d.mts.map +1 -0
- package/dist/engine/actions.mjs +26 -0
- package/dist/engine/actions.mjs.map +1 -0
- package/dist/engine/bucket.cjs +72 -0
- package/dist/engine/bucket.cjs.map +1 -0
- package/dist/engine/bucket.d.cts +32 -0
- package/dist/engine/bucket.d.cts.map +1 -0
- package/dist/engine/bucket.d.mts +32 -0
- package/dist/engine/bucket.d.mts.map +1 -0
- package/dist/engine/bucket.mjs +69 -0
- package/dist/engine/bucket.mjs.map +1 -0
- package/dist/engine/condition.cjs +166 -0
- package/dist/engine/condition.cjs.map +1 -0
- package/dist/engine/condition.d.cts +52 -0
- package/dist/engine/condition.d.cts.map +1 -0
- package/dist/engine/condition.d.mts +52 -0
- package/dist/engine/condition.d.mts.map +1 -0
- package/dist/engine/condition.mjs +161 -0
- package/dist/engine/condition.mjs.map +1 -0
- package/dist/engine/index.cjs +20 -0
- package/dist/engine/index.d.cts +8 -0
- package/dist/engine/index.d.mts +8 -0
- package/dist/engine/index.mjs +7 -0
- package/dist/engine/interpreter.cjs +428 -0
- package/dist/engine/interpreter.cjs.map +1 -0
- package/dist/engine/interpreter.d.cts +6 -0
- package/dist/engine/interpreter.d.cts.map +1 -0
- package/dist/engine/interpreter.d.mts +6 -0
- package/dist/engine/interpreter.d.mts.map +1 -0
- package/dist/engine/interpreter.mjs +427 -0
- package/dist/engine/interpreter.mjs.map +1 -0
- package/dist/engine/ports.cjs +0 -0
- package/dist/engine/ports.d.cts +252 -0
- package/dist/engine/ports.d.cts.map +1 -0
- package/dist/engine/ports.d.mts +252 -0
- package/dist/engine/ports.d.mts.map +1 -0
- package/dist/engine/ports.mjs +1 -0
- package/dist/engine/recipient.cjs +23 -0
- package/dist/engine/recipient.cjs.map +1 -0
- package/dist/engine/recipient.d.cts +13 -0
- package/dist/engine/recipient.d.cts.map +1 -0
- package/dist/engine/recipient.d.mts +13 -0
- package/dist/engine/recipient.d.mts.map +1 -0
- package/dist/engine/recipient.mjs +22 -0
- package/dist/engine/recipient.mjs.map +1 -0
- package/dist/engine/time-scale.cjs +54 -0
- package/dist/engine/time-scale.cjs.map +1 -0
- package/dist/engine/time-scale.d.cts +31 -0
- package/dist/engine/time-scale.d.cts.map +1 -0
- package/dist/engine/time-scale.d.mts +31 -0
- package/dist/engine/time-scale.d.mts.map +1 -0
- package/dist/engine/time-scale.mjs +52 -0
- package/dist/engine/time-scale.mjs.map +1 -0
- package/dist/engine/time-window.cjs +149 -0
- package/dist/engine/time-window.cjs.map +1 -0
- package/dist/engine/time-window.d.cts +22 -0
- package/dist/engine/time-window.d.cts.map +1 -0
- package/dist/engine/time-window.d.mts +22 -0
- package/dist/engine/time-window.d.mts.map +1 -0
- package/dist/engine/time-window.mjs +147 -0
- package/dist/engine/time-window.mjs.map +1 -0
- package/dist/fcm.cjs +125 -0
- package/dist/fcm.cjs.map +1 -0
- package/dist/fcm.d.cts +48 -0
- package/dist/fcm.d.cts.map +1 -0
- package/dist/fcm.d.mts +48 -0
- package/dist/fcm.d.mts.map +1 -0
- package/dist/fcm.mjs +121 -0
- package/dist/fcm.mjs.map +1 -0
- package/dist/hash.cjs +245 -0
- package/dist/hash.cjs.map +1 -0
- package/dist/hash.d.cts +30 -0
- package/dist/hash.d.cts.map +1 -0
- package/dist/hash.d.mts +30 -0
- package/dist/hash.d.mts.map +1 -0
- package/dist/hash.mjs +239 -0
- package/dist/hash.mjs.map +1 -0
- package/dist/index.cjs +100 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.mjs +17 -0
- package/dist/ir.cjs +366 -0
- package/dist/ir.cjs.map +1 -0
- package/dist/ir.d.cts +486 -0
- package/dist/ir.d.cts.map +1 -0
- package/dist/ir.d.mts +486 -0
- package/dist/ir.d.mts.map +1 -0
- package/dist/ir.mjs +344 -0
- package/dist/ir.mjs.map +1 -0
- package/dist/jwt.cjs +22 -0
- package/dist/jwt.cjs.map +1 -0
- package/dist/jwt.d.cts +9 -0
- package/dist/jwt.d.cts.map +1 -0
- package/dist/jwt.d.mts +9 -0
- package/dist/jwt.d.mts.map +1 -0
- package/dist/jwt.mjs +20 -0
- package/dist/jwt.mjs.map +1 -0
- package/dist/plan.cjs +223 -0
- package/dist/plan.cjs.map +1 -0
- package/dist/plan.d.cts +68 -0
- package/dist/plan.d.cts.map +1 -0
- package/dist/plan.d.mts +68 -0
- package/dist/plan.d.mts.map +1 -0
- package/dist/plan.mjs +221 -0
- package/dist/plan.mjs.map +1 -0
- package/dist/postgres-js.cjs +42 -0
- package/dist/postgres-js.cjs.map +1 -0
- package/dist/postgres-js.d.cts +28 -0
- package/dist/postgres-js.d.cts.map +1 -0
- package/dist/postgres-js.d.mts +28 -0
- package/dist/postgres-js.d.mts.map +1 -0
- package/dist/postgres-js.mjs +38 -0
- package/dist/postgres-js.mjs.map +1 -0
- package/dist/provenance.cjs +67 -0
- package/dist/provenance.cjs.map +1 -0
- package/dist/provenance.d.cts +41 -0
- package/dist/provenance.d.cts.map +1 -0
- package/dist/provenance.d.mts +41 -0
- package/dist/provenance.d.mts.map +1 -0
- package/dist/provenance.mjs +65 -0
- package/dist/provenance.mjs.map +1 -0
- package/dist/push.cjs +14 -0
- package/dist/push.cjs.map +1 -0
- package/dist/push.d.cts +16 -0
- package/dist/push.d.cts.map +1 -0
- package/dist/push.d.mts +16 -0
- package/dist/push.d.mts.map +1 -0
- package/dist/push.mjs +13 -0
- package/dist/push.mjs.map +1 -0
- package/dist/react-email.cjs +48 -0
- package/dist/react-email.cjs.map +1 -0
- package/dist/react-email.d.cts +7 -0
- package/dist/react-email.d.cts.map +1 -0
- package/dist/react-email.d.mts +7 -0
- package/dist/react-email.d.mts.map +1 -0
- package/dist/react-email.mjs +47 -0
- package/dist/react-email.mjs.map +1 -0
- package/dist/reporting/classify.cjs +42 -0
- package/dist/reporting/classify.cjs.map +1 -0
- package/dist/reporting/classify.d.cts +60 -0
- package/dist/reporting/classify.d.cts.map +1 -0
- package/dist/reporting/classify.d.mts +60 -0
- package/dist/reporting/classify.d.mts.map +1 -0
- package/dist/reporting/classify.mjs +38 -0
- package/dist/reporting/classify.mjs.map +1 -0
- package/dist/reporting/observer.cjs +63 -0
- package/dist/reporting/observer.cjs.map +1 -0
- package/dist/reporting/observer.d.cts +18 -0
- package/dist/reporting/observer.d.cts.map +1 -0
- package/dist/reporting/observer.d.mts +18 -0
- package/dist/reporting/observer.d.mts.map +1 -0
- package/dist/reporting/observer.mjs +62 -0
- package/dist/reporting/observer.mjs.map +1 -0
- package/dist/reporting/tracking.cjs +153 -0
- package/dist/reporting/tracking.cjs.map +1 -0
- package/dist/reporting/tracking.d.cts +43 -0
- package/dist/reporting/tracking.d.cts.map +1 -0
- package/dist/reporting/tracking.d.mts +43 -0
- package/dist/reporting/tracking.d.mts.map +1 -0
- package/dist/reporting/tracking.mjs +151 -0
- package/dist/reporting/tracking.mjs.map +1 -0
- package/dist/runtime.cjs +19 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +30 -0
- package/dist/runtime.d.cts.map +1 -0
- package/dist/runtime.d.mts +30 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +18 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/store/d1.cjs +185 -0
- package/dist/store/d1.cjs.map +1 -0
- package/dist/store/d1.d.cts +55 -0
- package/dist/store/d1.d.cts.map +1 -0
- package/dist/store/d1.d.mts +55 -0
- package/dist/store/d1.d.mts.map +1 -0
- package/dist/store/d1.mjs +184 -0
- package/dist/store/d1.mjs.map +1 -0
- package/dist/store/facts.cjs +60 -0
- package/dist/store/facts.cjs.map +1 -0
- package/dist/store/facts.d.cts +38 -0
- package/dist/store/facts.d.cts.map +1 -0
- package/dist/store/facts.d.mts +38 -0
- package/dist/store/facts.d.mts.map +1 -0
- package/dist/store/facts.mjs +58 -0
- package/dist/store/facts.mjs.map +1 -0
- package/dist/store/index.cjs +31 -0
- package/dist/store/index.cjs.map +1 -0
- package/dist/store/index.d.cts +291 -0
- package/dist/store/index.d.cts.map +1 -0
- package/dist/store/index.d.mts +291 -0
- package/dist/store/index.d.mts.map +1 -0
- package/dist/store/index.mjs +22 -0
- package/dist/store/index.mjs.map +1 -0
- package/dist/store/postgres-reporting.cjs +213 -0
- package/dist/store/postgres-reporting.cjs.map +1 -0
- package/dist/store/postgres-reporting.d.cts +63 -0
- package/dist/store/postgres-reporting.d.cts.map +1 -0
- package/dist/store/postgres-reporting.d.mts +63 -0
- package/dist/store/postgres-reporting.d.mts.map +1 -0
- package/dist/store/postgres-reporting.mjs +212 -0
- package/dist/store/postgres-reporting.mjs.map +1 -0
- package/dist/store/postgres.cjs +309 -0
- package/dist/store/postgres.cjs.map +1 -0
- package/dist/store/postgres.d.cts +77 -0
- package/dist/store/postgres.d.cts.map +1 -0
- package/dist/store/postgres.d.mts +77 -0
- package/dist/store/postgres.d.mts.map +1 -0
- package/dist/store/postgres.mjs +306 -0
- package/dist/store/postgres.mjs.map +1 -0
- package/dist/store/sql.cjs +24 -0
- package/dist/store/sql.cjs.map +1 -0
- package/dist/store/sql.d.cts +25 -0
- package/dist/store/sql.d.cts.map +1 -0
- package/dist/store/sql.d.mts +25 -0
- package/dist/store/sql.d.mts.map +1 -0
- package/dist/store/sql.mjs +23 -0
- package/dist/store/sql.mjs.map +1 -0
- package/dist/store/tables.cjs +404 -0
- package/dist/store/tables.cjs.map +1 -0
- package/dist/store/tables.d.cts +81 -0
- package/dist/store/tables.d.cts.map +1 -0
- package/dist/store/tables.d.mts +81 -0
- package/dist/store/tables.d.mts.map +1 -0
- package/dist/store/tables.mjs +399 -0
- package/dist/store/tables.mjs.map +1 -0
- package/dist/templates.cjs +247 -0
- package/dist/templates.cjs.map +1 -0
- package/dist/templates.d.cts +187 -0
- package/dist/templates.d.cts.map +1 -0
- package/dist/templates.d.mts +187 -0
- package/dist/templates.d.mts.map +1 -0
- package/dist/templates.mjs +230 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/webhooks.cjs +96 -0
- package/dist/webhooks.cjs.map +1 -0
- package/dist/webhooks.d.cts +25 -0
- package/dist/webhooks.d.cts.map +1 -0
- package/dist/webhooks.d.mts +25 -0
- package/dist/webhooks.d.mts.map +1 -0
- package/dist/webhooks.mjs +94 -0
- package/dist/webhooks.mjs.map +1 -0
- package/dist/webpush.cjs +180 -0
- package/dist/webpush.cjs.map +1 -0
- package/dist/webpush.d.cts +53 -0
- package/dist/webpush.d.cts.map +1 -0
- package/dist/webpush.d.mts +53 -0
- package/dist/webpush.d.mts.map +1 -0
- package/dist/webpush.mjs +175 -0
- package/dist/webpush.mjs.map +1 -0
- package/package.json +189 -3
- package/src/cloudflare/schema.sql +127 -0
- package/src/cloudflare/workers.d.ts +44 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { NodeIR } from "../ir.mjs";
|
|
2
|
+
import { ActionRef } from "./action.mjs";
|
|
3
|
+
import { Duration, TimeOfDay, Weekday } from "./base.mjs";
|
|
4
|
+
import { EventRef, MessageArgs, PropInput } from "./refs.mjs";
|
|
5
|
+
import { TemplateRef } from "./template.mjs";
|
|
6
|
+
import { Condition } from "./condition.mjs";
|
|
7
|
+
//#region src/dsl/flow.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* The flow chain — FlowBuilder is the DSL's step surface (messages, delays,
|
|
10
|
+
* flow control, data), and its implementation is the compiler front half: each
|
|
11
|
+
* chained call executes no logic, it just collects one IR node (ids are
|
|
12
|
+
* assigned later, in workflow.toIR()). Sub-flow callbacks run exactly once at
|
|
13
|
+
* construction — builder in, builder out — so the output is always a static
|
|
14
|
+
* tree.
|
|
15
|
+
*
|
|
16
|
+
* Every public method also captures its callsite (provenance): the loc lands
|
|
17
|
+
* in the node's hash-excluded meta and is the anchor for future in-place
|
|
18
|
+
* editing from the studio.
|
|
19
|
+
*/
|
|
20
|
+
type Scalar = string | number | boolean;
|
|
21
|
+
/** An emitted field: a scalar (or a profile ref to one); a nested field cannot be sent. */
|
|
22
|
+
type EmitValue<T> = [NonNullable<T>] extends [Scalar] ? PropInput<T> : never;
|
|
23
|
+
/** The payload `sendEvent` accepts for an event: its fields, scalar ones only. */
|
|
24
|
+
export type EmitPayload<P> = { [K in keyof P]: EmitValue<P[K]>; };
|
|
25
|
+
/** Payload may be omitted when the event declares no required field. */
|
|
26
|
+
export type EmitArgs<P> = Record<never, never> extends P ? [payload?: EmitPayload<P>] : [payload: EmitPayload<P>];
|
|
27
|
+
/** Per-node push options. */
|
|
28
|
+
export interface PushOptions {
|
|
29
|
+
/** Which devices get a copy: 'all' (the default) or only the most recently registered. */
|
|
30
|
+
devices?: 'all' | 'latest';
|
|
31
|
+
}
|
|
32
|
+
/** A reusable flow fragment (what `flow(...)` returns), referenced directly by branch arms. */
|
|
33
|
+
export interface Flow {
|
|
34
|
+
readonly __flow: true;
|
|
35
|
+
}
|
|
36
|
+
/** Sub-flow: a named fragment, or an inline callback (runs once at construction — builder in, builder out). */
|
|
37
|
+
export type SubFlow = Flow | ((w: FlowBuilder) => FlowBuilder);
|
|
38
|
+
/** A branch arm: the [condition, sub-flow] tuple — an [if, then] ordering convention. */
|
|
39
|
+
export type BranchCase = readonly [condition: Condition, flow: SubFlow];
|
|
40
|
+
/**
|
|
41
|
+
* A branch argument: either a tuple arm, or a bare sub-flow meaning the default
|
|
42
|
+
* arm. The bare form may appear once, and must come last (checked at runtime).
|
|
43
|
+
*/
|
|
44
|
+
export type BranchArm = BranchCase | SubFlow;
|
|
45
|
+
export interface FlowBuilder {
|
|
46
|
+
email<P extends object>(template: TemplateRef<'email', P>, ...props: MessageArgs<P>): this;
|
|
47
|
+
sms<P extends object>(template: TemplateRef<'sms', P>, ...props: MessageArgs<P>): this;
|
|
48
|
+
/**
|
|
49
|
+
* Push to the user's devices — every device the host's directory lists, or
|
|
50
|
+
* only the most recently registered with `{ devices: 'latest' }`. A user with
|
|
51
|
+
* no device is skipped (branch on `reachable('push')` to fall back to email).
|
|
52
|
+
*/
|
|
53
|
+
push<P extends object>(template: TemplateRef<'push', P>, ...args: [...props: MessageArgs<P>, options?: PushOptions]): this;
|
|
54
|
+
inApp<P extends object>(template: TemplateRef<'in_app', P>, ...props: MessageArgs<P>): this;
|
|
55
|
+
slack<P extends object>(template: TemplateRef<'slack', P>, ...props: MessageArgs<P>): this;
|
|
56
|
+
discord<P extends object>(template: TemplateRef<'discord', P>, ...props: MessageArgs<P>): this;
|
|
57
|
+
survey<P extends object>(template: TemplateRef<'survey', P>, ...props: MessageArgs<P>): this;
|
|
58
|
+
/** Time Delay; passing { min, max } makes it a Randomized Delay. */
|
|
59
|
+
delay(duration: Duration): this;
|
|
60
|
+
delay(range: {
|
|
61
|
+
min: Duration;
|
|
62
|
+
max: Duration;
|
|
63
|
+
}): this;
|
|
64
|
+
/** Time Window: hold until inside the window (e.g. weekdays 09:00–17:00). tz: 'user' uses the user's timezone. */
|
|
65
|
+
timeWindow(opts: {
|
|
66
|
+
days?: readonly Weekday[];
|
|
67
|
+
between: readonly [TimeOfDay, TimeOfDay];
|
|
68
|
+
tz?: 'user' | (string & {});
|
|
69
|
+
}): this;
|
|
70
|
+
/**
|
|
71
|
+
* Wait Until: continue on the main line once the condition holds, or take
|
|
72
|
+
* onTimeout when it expires (default 'continue'). On the engine side this is
|
|
73
|
+
* "await event racing a timer" — a native primitive of durable runtimes.
|
|
74
|
+
*/
|
|
75
|
+
waitUntil(condition: Condition, opts: {
|
|
76
|
+
timeout: Duration;
|
|
77
|
+
onTimeout?: 'continue' | 'exit' | SubFlow;
|
|
78
|
+
}): this;
|
|
79
|
+
/**
|
|
80
|
+
* Splice a fragment in place: a named `flow(...)` or a callback, expanded
|
|
81
|
+
* once while the workflow is defined — a composition step before compiling,
|
|
82
|
+
* not a node (the IR has no trace of it, and ids are assigned over the whole
|
|
83
|
+
* workflow as if the steps were written inline). Each use gets its own copy,
|
|
84
|
+
* so one fragment can be used in several places and workflows.
|
|
85
|
+
*
|
|
86
|
+
* const preferPush = (push, email, props) =>
|
|
87
|
+
* flow((w) => w.branch([reachable('push'), (b) => b.push(push, props)], (b) => b.email(email, props)));
|
|
88
|
+
* workflow({ id: 'onboarding', ... }).use(preferPush(tipPush, tipEmail, { name: u.name }))
|
|
89
|
+
*/
|
|
90
|
+
use(fragment: SubFlow): this;
|
|
91
|
+
/**
|
|
92
|
+
* Conditional branch: ordered first-match (same semantics as Step Functions
|
|
93
|
+
* Choice / Knock branch). This one primitive covers both the UI's True/False
|
|
94
|
+
* Branch (two arms) and Multi-Split Branch (N arms). Arms are
|
|
95
|
+
* [condition, sub-flow] tuples; a bare sub-flow in tail position is the
|
|
96
|
+
* default arm. With no match and no default, execution simply continues.
|
|
97
|
+
* Rejoin is structural: after the matching arm finishes, execution resumes
|
|
98
|
+
* at the node following the branch — to opt out, call .exit() inside the arm.
|
|
99
|
+
*
|
|
100
|
+
* .branch([activeSubscriber, upgradeFlow], firstTimeFlow) // True/False
|
|
101
|
+
* .branch([vip, vipFlow], [trial, trialFlow], defaultFlow) // Multi-Split
|
|
102
|
+
* .branch([not(usedStaging), eduFlow]) // single arm: no match continues
|
|
103
|
+
*
|
|
104
|
+
* The optional first argument `label` becomes the node's name in IR (UI title
|
|
105
|
+
* / observability handle). It is not a jump target — there is no goto here;
|
|
106
|
+
* looping is a future re-entry-policy topic (see sendEvent). Arm labels in
|
|
107
|
+
* the UI are derived from the condition.
|
|
108
|
+
*/
|
|
109
|
+
branch(...arms: readonly BranchArm[]): this;
|
|
110
|
+
branch(label: string, ...arms: readonly BranchArm[]): this;
|
|
111
|
+
/**
|
|
112
|
+
* Gate: exit unless the condition holds, otherwise continue. A first-class
|
|
113
|
+
* node rather than sugar over branch — same semantics as Zapier's "only
|
|
114
|
+
* continue if" / Iterable's Filter tile, and rendered on its own in the UI.
|
|
115
|
+
* `reason` is the audit-log line — metadata, so rewording it is free
|
|
116
|
+
* (excluded from contentHash, see hash.ts).
|
|
117
|
+
*/
|
|
118
|
+
filter(condition: Condition, opts?: {
|
|
119
|
+
reason?: string;
|
|
120
|
+
}): this;
|
|
121
|
+
/**
|
|
122
|
+
* Random Cohort Branch (A/B): weights must sum to 100 (checked at runtime).
|
|
123
|
+
* `key` names the experiment: bucketing hashes `userId:key` instead of the
|
|
124
|
+
* structural node id, so assignments survive node insertion/moves and the
|
|
125
|
+
* experiment keeps one identity across workflow versions — set it for any
|
|
126
|
+
* A/B whose results you intend to read.
|
|
127
|
+
*
|
|
128
|
+
* Arm names become node id segments and are read back in authoring order, so
|
|
129
|
+
* they are restricted to letters, digits, '_' and '-', never starting with a
|
|
130
|
+
* digit (checked at runtime).
|
|
131
|
+
*/
|
|
132
|
+
cohort(arms: Record<string, {
|
|
133
|
+
weight: number;
|
|
134
|
+
flow?: SubFlow;
|
|
135
|
+
}>, opts?: {
|
|
136
|
+
key?: string;
|
|
137
|
+
}): this;
|
|
138
|
+
/**
|
|
139
|
+
* Exit: end the whole workflow immediately (the UI's Exit node); `reason`
|
|
140
|
+
* goes into the audit log and is metadata, so rewording it neither repins
|
|
141
|
+
* in-flight journeys nor shows up in plan. Inside a branch arm this means
|
|
142
|
+
* "terminate, do not rejoin" — it stops here instead of falling through,
|
|
143
|
+
* while an arm without exit rejoins naturally.
|
|
144
|
+
*/
|
|
145
|
+
exit(reason?: string): this;
|
|
146
|
+
/**
|
|
147
|
+
* Emit a typed event (customer.io's Send Event). The event comes from an
|
|
148
|
+
* e.xxx reference, so payload types flow in the same way trigger.event works.
|
|
149
|
+
* This is how workflows compose: an event can trigger another workflow, and
|
|
150
|
+
* the resulting call graph is statically analyzable. Payload values may
|
|
151
|
+
* reference u.xxx. Only scalar fields can be sent (IR carries literals and
|
|
152
|
+
* profile refs, not nested JSON): an event whose payload requires a nested
|
|
153
|
+
* field cannot be emitted from a journey, and the types say so.
|
|
154
|
+
*
|
|
155
|
+
* Note on loops: a trailing self-triggering sendEvent will become the
|
|
156
|
+
* official periodic-flow shape *once a re-entry policy exists* — today the
|
|
157
|
+
* entry policy is once-per-user, so a self-trigger cannot re-enter and does
|
|
158
|
+
* not loop.
|
|
159
|
+
* TODO: the rest of the Data category — outbound webhook / profile update /
|
|
160
|
+
* journey attributes.
|
|
161
|
+
*/
|
|
162
|
+
sendEvent<P extends object>(event: EventRef<P>, ...payload: EmitArgs<P>): this;
|
|
163
|
+
/**
|
|
164
|
+
* Run a custom action (see dsl/action.ts for the model). The chain records
|
|
165
|
+
* identity only — name, args, codeHash — never the code: the implementation
|
|
166
|
+
* ships inside the deployed Worker bundle and is resolved by name from the
|
|
167
|
+
* runtime registry. Args are typed by the ActionRef and may reference u.xxx,
|
|
168
|
+
* resolved at run time exactly like message props. Executed inside a durable
|
|
169
|
+
* step: retried on throw, checkpointed on success.
|
|
170
|
+
*/
|
|
171
|
+
run<A extends object>(action: ActionRef<A>, ...args: MessageArgs<A>): this;
|
|
172
|
+
}
|
|
173
|
+
/** @internal extended by WorkflowBuilderImpl; not part of the public API */
|
|
174
|
+
export declare class FlowBuilderImpl implements FlowBuilder {
|
|
175
|
+
/** Nodes as collected; ids are assigned in one pass inside toIR, so '' is a placeholder here. */
|
|
176
|
+
readonly nodes: NodeIR[];
|
|
177
|
+
/** Provenance: the callsite (captured in the public method) lands in meta.loc, outside the hash. */
|
|
178
|
+
private pushNode;
|
|
179
|
+
private message;
|
|
180
|
+
email<P extends object>(t: TemplateRef<'email', P>, ...args: MessageArgs<P>): this;
|
|
181
|
+
sms<P extends object>(t: TemplateRef<'sms', P>, ...args: MessageArgs<P>): this;
|
|
182
|
+
push<P extends object>(t: TemplateRef<'push', P>, ...args: [...props: MessageArgs<P>, options?: PushOptions]): this;
|
|
183
|
+
inApp<P extends object>(t: TemplateRef<'in_app', P>, ...args: MessageArgs<P>): this;
|
|
184
|
+
slack<P extends object>(t: TemplateRef<'slack', P>, ...args: MessageArgs<P>): this;
|
|
185
|
+
discord<P extends object>(t: TemplateRef<'discord', P>, ...args: MessageArgs<P>): this;
|
|
186
|
+
survey<P extends object>(t: TemplateRef<'survey', P>, ...args: MessageArgs<P>): this;
|
|
187
|
+
delay(duration: Duration): this;
|
|
188
|
+
delay(range: {
|
|
189
|
+
min: Duration;
|
|
190
|
+
max: Duration;
|
|
191
|
+
}): this;
|
|
192
|
+
timeWindow(opts: {
|
|
193
|
+
days?: readonly Weekday[];
|
|
194
|
+
between: readonly [TimeOfDay, TimeOfDay];
|
|
195
|
+
tz?: 'user' | (string & {});
|
|
196
|
+
}): this;
|
|
197
|
+
waitUntil(condition: Condition, opts: {
|
|
198
|
+
timeout: Duration;
|
|
199
|
+
onTimeout?: 'continue' | 'exit' | SubFlow;
|
|
200
|
+
}): this;
|
|
201
|
+
use(fragment: SubFlow): this;
|
|
202
|
+
branch(...arms: readonly BranchArm[]): this;
|
|
203
|
+
branch(label: string, ...arms: readonly BranchArm[]): this;
|
|
204
|
+
filter(condition: Condition, opts?: {
|
|
205
|
+
reason?: string;
|
|
206
|
+
}): this;
|
|
207
|
+
cohort(arms: Record<string, {
|
|
208
|
+
weight: number;
|
|
209
|
+
flow?: SubFlow;
|
|
210
|
+
}>, opts?: {
|
|
211
|
+
key?: string;
|
|
212
|
+
}): this;
|
|
213
|
+
exit(reason?: string): this;
|
|
214
|
+
sendEvent<P extends object>(ev: EventRef<P>, ...payload: EmitArgs<P>): this;
|
|
215
|
+
run<A extends object>(a: ActionRef<A>, ...args: MessageArgs<A>): this;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* A reusable flow fragment: a free function. Once personalization goes through
|
|
219
|
+
* u.xxx and events through e.xxx, the flow layer carries no schema generics.
|
|
220
|
+
*/
|
|
221
|
+
export declare function flow(build: (w: FlowBuilder) => FlowBuilder): Flow;
|
|
222
|
+
//#endregion
|
|
223
|
+
//# sourceMappingURL=flow.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.d.mts","names":[],"sources":["../../src/dsl/flow.ts"],"mappings":";;;;;;;;;;;;;;;;;;;KAqBK;;KAGA,UAAU,MAAM,YAAY,aAAa,UAAU,UAAU;;YAGtD,YAAY,QAAQ,WAAW,IAAI,UAAU,EAAE;;YAG/C,SAAS,KACnB,6BAA6B,KAAK,UAAU,YAAY,OAAO,SAAS,YAAY;;iBAGrE;;EAEf;;;iBAIe;WACN;;;YAQC,UAAU,SAAS,GAAG,gBAAgB;;YAGtC,uBAAuB,WAAW,WAAW,MAAM;;;;;YAMnD,YAAY,aAAa;iBAsCpB;EAEf,MAAM,kBAAkB,UAAU,qBAAqB,OAAO,OAAO,YAAY;EACjF,IAAI,kBAAkB,UAAU,mBAAmB,OAAO,OAAO,YAAY;;;;;;EAM7E,KAAK,kBACH,UAAU,oBAAoB,OAC3B,UAAU,OAAO,YAAY,IAAI,UAAU;EAEhD,MAAM,kBAAkB,UAAU,sBAAsB,OAAO,OAAO,YAAY;EAClF,MAAM,kBAAkB,UAAU,qBAAqB,OAAO,OAAO,YAAY;EACjF,QAAQ,kBAAkB,UAAU,uBAAuB,OAAO,OAAO,YAAY;EACrF,OAAO,kBAAkB,UAAU,sBAAsB,OAAO,OAAO,YAAY;;EAInF,MAAM,UAAU;EAChB,MAAM;IAAS,KAAK;IAAU,KAAK;;;EAGnC,WAAW;IACT,gBAAgB;IAChB,mBAAmB,WAAW;IAC9B;;;;;;;EAQF,UACE,WAAW,WACX;IAAQ,SAAS;IAAU,kCAAkC;;;;;;;;;;;;;EAc/D,IAAI,UAAU;;;;;;;;;;;;;;;;;;;EAqBd,UAAU,eAAe;EACzB,OAAO,kBAAkB,eAAe;;;;;;;;EASxC,OAAO,WAAW,WAAW;IAAS;;;;;;;;;;;;;EAatC,OAAO,MAAM;IAAiB;IAAgB,OAAO;MAAY;IAAS;;;;;;;;;EAS1E,KAAK;;;;;;;;;;;;;;;;;EAmBL,UAAU,kBAAkB,OAAO,SAAS,OAAO,SAAS,SAAS;;;;;;;;;EAUrE,IAAI,kBAAkB,QAAQ,UAAU,OAAO,MAAM,YAAY;;;qBAQtD,2BAA2B;;WAE7B,OAAO;;UAGR;UAKA;EAqBR,MAAM,kBAAkB,GAAG,qBAAqB,OAAO,MAAM,YAAY;EAGzE,IAAI,kBAAkB,GAAG,mBAAmB,OAAO,MAAM,YAAY;EAGrE,KAAK,kBACH,GAAG,oBAAoB,OACpB,UAAU,OAAO,YAAY,IAAI,UAAU;EAMhD,MAAM,kBAAkB,GAAG,sBAAsB,OAAO,MAAM,YAAY;EAG1E,MAAM,kBAAkB,GAAG,qBAAqB,OAAO,MAAM,YAAY;EAGzE,QAAQ,kBAAkB,GAAG,uBAAuB,OAAO,MAAM,YAAY;EAG7E,OAAO,kBAAkB,GAAG,sBAAsB,OAAO,MAAM,YAAY;EAI3E,MAAM,UAAU;EAChB,MAAM;IAAS,KAAK;IAAU,KAAK;;EAqBnC,WAAW;IACT,gBAAgB;IAChB,mBAAmB,WAAW;IAC9B;;EAsBF,UACE,WAAW,WACX;IAAQ,SAAS;IAAU,kCAAkC;;EAiB/D,IAAI,UAAU;EAMd,UAAU,eAAe;EACzB,OAAO,kBAAkB,eAAe;EAsCxC,OAAO,WAAW,WAAW;IAAS;;EAYtC,OAAO,MAAM;IAAiB;IAAgB,OAAO;MAAY;IAAS;;EAmD1E,KAAK;EAOL,UAAU,kBAAkB,IAAI,SAAS,OAAO,SAAS,SAAS;EAwBlE,IAAI,kBAAkB,GAAG,UAAU,OAAO,MAAM,YAAY;;;;;;wBAmB9C,KAAK,QAAQ,GAAG,gBAAgB,cAAc"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { captureLoc } from "../provenance.mjs";
|
|
2
|
+
import { durationIR, timeOfDayMinutes } from "./base.mjs";
|
|
3
|
+
import { condIR } from "./condition.mjs";
|
|
4
|
+
//#region src/dsl/flow.ts
|
|
5
|
+
/**
|
|
6
|
+
* A cohort arm name has two jobs, and both constrain its spelling:
|
|
7
|
+
* - it is interpolated into the node ids of the arm's flow ('{id}.{name}.{j}'),
|
|
8
|
+
* and an id is a durable step name — a dot would fake a nesting level and can
|
|
9
|
+
* collide with a real one, an empty name gives '{id}..{j}';
|
|
10
|
+
* - it is an object key, and JavaScript lists integer-like keys first in
|
|
11
|
+
* ascending numeric order however the author wrote them. The arms array is
|
|
12
|
+
* documented (and interpreted) as authoring order, and the bucketing walk
|
|
13
|
+
* accumulates weights along it, so an arm named '0' added to a live
|
|
14
|
+
* experiment would prepend itself and re-bucket everyone already in it.
|
|
15
|
+
*/
|
|
16
|
+
const ARM_NAME = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
17
|
+
function resolveSubFlow(sub) {
|
|
18
|
+
if (typeof sub === "function") {
|
|
19
|
+
const builder = new FlowBuilderImpl();
|
|
20
|
+
if (typeof sub(builder)?.then === "function") throw new TypeError("sub-flow callbacks must be synchronous: they run once, while the workflow is defined");
|
|
21
|
+
return builder.nodes;
|
|
22
|
+
}
|
|
23
|
+
return structuredClone(sub.nodes);
|
|
24
|
+
}
|
|
25
|
+
/** @internal extended by WorkflowBuilderImpl; not part of the public API */
|
|
26
|
+
var FlowBuilderImpl = class {
|
|
27
|
+
/** Nodes as collected; ids are assigned in one pass inside toIR, so '' is a placeholder here. */
|
|
28
|
+
nodes = [];
|
|
29
|
+
/** Provenance: the callsite (captured in the public method) lands in meta.loc, outside the hash. */
|
|
30
|
+
pushNode(node, loc) {
|
|
31
|
+
this.nodes.push({
|
|
32
|
+
...node,
|
|
33
|
+
...loc !== void 0 ? { meta: { loc } } : {}
|
|
34
|
+
});
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
message(channel, tpl, props, loc, devices) {
|
|
38
|
+
return this.pushNode({
|
|
39
|
+
id: "",
|
|
40
|
+
type: "message",
|
|
41
|
+
channel,
|
|
42
|
+
template: tpl.key,
|
|
43
|
+
props: props ?? {},
|
|
44
|
+
...devices !== void 0 ? { devices } : {}
|
|
45
|
+
}, loc);
|
|
46
|
+
}
|
|
47
|
+
email(t, ...args) {
|
|
48
|
+
return this.message("email", t, args[0], captureLoc(this.email));
|
|
49
|
+
}
|
|
50
|
+
sms(t, ...args) {
|
|
51
|
+
return this.message("sms", t, args[0], captureLoc(this.sms));
|
|
52
|
+
}
|
|
53
|
+
push(t, ...args) {
|
|
54
|
+
const [props, options] = args;
|
|
55
|
+
const devices = options?.devices === "latest" ? "latest" : void 0;
|
|
56
|
+
return this.message("push", t, props, captureLoc(this.push), devices);
|
|
57
|
+
}
|
|
58
|
+
inApp(t, ...args) {
|
|
59
|
+
return this.message("in_app", t, args[0], captureLoc(this.inApp));
|
|
60
|
+
}
|
|
61
|
+
slack(t, ...args) {
|
|
62
|
+
return this.message("slack", t, args[0], captureLoc(this.slack));
|
|
63
|
+
}
|
|
64
|
+
discord(t, ...args) {
|
|
65
|
+
return this.message("discord", t, args[0], captureLoc(this.discord));
|
|
66
|
+
}
|
|
67
|
+
survey(t, ...args) {
|
|
68
|
+
return this.message("survey", t, args[0], captureLoc(this.survey));
|
|
69
|
+
}
|
|
70
|
+
delay(d) {
|
|
71
|
+
const loc = captureLoc(this.delay);
|
|
72
|
+
if (typeof d === "string") return this.pushNode({
|
|
73
|
+
id: "",
|
|
74
|
+
type: "delay",
|
|
75
|
+
duration: durationIR(d)
|
|
76
|
+
}, loc);
|
|
77
|
+
const min = durationIR(d.min);
|
|
78
|
+
const max = durationIR(d.max);
|
|
79
|
+
if (max.ms < min.ms) throw new Error(`delay(): 'max' must not be shorter than 'min', got { min: '${d.min}', max: '${d.max}' }`);
|
|
80
|
+
return this.pushNode({
|
|
81
|
+
id: "",
|
|
82
|
+
type: "random_delay",
|
|
83
|
+
min,
|
|
84
|
+
max
|
|
85
|
+
}, loc);
|
|
86
|
+
}
|
|
87
|
+
timeWindow(opts) {
|
|
88
|
+
const loc = captureLoc(this.timeWindow);
|
|
89
|
+
const start = timeOfDayMinutes(opts.between[0]);
|
|
90
|
+
if (timeOfDayMinutes(opts.between[1]) <= start) throw new Error(`timeWindow(): 'between' must open before it closes within one day, got [${opts.between[0]}, ${opts.between[1]}] (overnight windows are not supported yet)`);
|
|
91
|
+
return this.pushNode({
|
|
92
|
+
id: "",
|
|
93
|
+
type: "time_window",
|
|
94
|
+
days: [...opts.days ?? [
|
|
95
|
+
"mon",
|
|
96
|
+
"tue",
|
|
97
|
+
"wed",
|
|
98
|
+
"thu",
|
|
99
|
+
"fri",
|
|
100
|
+
"sat",
|
|
101
|
+
"sun"
|
|
102
|
+
]],
|
|
103
|
+
between: [opts.between[0], opts.between[1]],
|
|
104
|
+
tz: opts.tz ?? "user"
|
|
105
|
+
}, loc);
|
|
106
|
+
}
|
|
107
|
+
waitUntil(condition, opts) {
|
|
108
|
+
const loc = captureLoc(this.waitUntil);
|
|
109
|
+
const onTimeout = opts.onTimeout ?? "continue";
|
|
110
|
+
return this.pushNode({
|
|
111
|
+
id: "",
|
|
112
|
+
type: "wait_until",
|
|
113
|
+
condition: condIR(condition),
|
|
114
|
+
timeout: durationIR(opts.timeout),
|
|
115
|
+
onTimeout: onTimeout === "continue" || onTimeout === "exit" ? onTimeout : resolveSubFlow(onTimeout)
|
|
116
|
+
}, loc);
|
|
117
|
+
}
|
|
118
|
+
use(fragment) {
|
|
119
|
+
this.nodes.push(...resolveSubFlow(fragment));
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
branch(...args) {
|
|
123
|
+
const loc = captureLoc(this.branch);
|
|
124
|
+
const label = typeof args[0] === "string" ? args[0] : void 0;
|
|
125
|
+
const arms = label === void 0 ? args : args.slice(1);
|
|
126
|
+
const cases = [];
|
|
127
|
+
let otherwise;
|
|
128
|
+
arms.forEach((arm, i) => {
|
|
129
|
+
if (Array.isArray(arm)) {
|
|
130
|
+
if (otherwise !== void 0) throw new Error("branch(): default arm (bare sub-flow) must be the last argument");
|
|
131
|
+
const [condition, sub] = arm;
|
|
132
|
+
cases.push({
|
|
133
|
+
condition: condIR(condition),
|
|
134
|
+
flow: resolveSubFlow(sub)
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
if (otherwise !== void 0) throw new Error("branch(): only one default arm (bare sub-flow) is allowed");
|
|
138
|
+
if (i !== arms.length - 1) throw new Error("branch(): default arm (bare sub-flow) must be the last argument");
|
|
139
|
+
otherwise = resolveSubFlow(arm);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return this.pushNode({
|
|
143
|
+
id: "",
|
|
144
|
+
type: "branch",
|
|
145
|
+
...label !== void 0 ? { label } : {},
|
|
146
|
+
cases,
|
|
147
|
+
...otherwise !== void 0 ? { otherwise } : {}
|
|
148
|
+
}, loc);
|
|
149
|
+
}
|
|
150
|
+
filter(condition, opts) {
|
|
151
|
+
return this.pushNode({
|
|
152
|
+
id: "",
|
|
153
|
+
type: "filter",
|
|
154
|
+
condition: condIR(condition),
|
|
155
|
+
...opts?.reason !== void 0 ? { reason: opts.reason } : {}
|
|
156
|
+
}, captureLoc(this.filter));
|
|
157
|
+
}
|
|
158
|
+
cohort(arms, opts) {
|
|
159
|
+
const loc = captureLoc(this.cohort);
|
|
160
|
+
const entries = Object.entries(arms);
|
|
161
|
+
const total = entries.map(([name, a]) => {
|
|
162
|
+
if (!ARM_NAME.test(name)) throw new Error(`cohort(): arm name '${name}' must start with a letter or '_' and contain only letters, digits, '_' or '-' — arm names become node id segments, and integer-like names would silently reorder the arms`);
|
|
163
|
+
const bp = a.weight * 100;
|
|
164
|
+
if (Math.abs(bp - Math.round(bp)) > 1e-6) throw new Error(`cohort(): arm '${name}' weight ${a.weight} is finer than the 0.01% bucketing grid — use at most two decimal places`);
|
|
165
|
+
if (bp < 0) throw new Error(`cohort(): arm '${name}' weight ${a.weight} must not be negative`);
|
|
166
|
+
return Math.round(bp);
|
|
167
|
+
}).reduce((sum, bp) => sum + bp, 0);
|
|
168
|
+
if (total !== 1e4) throw new Error(`cohort(): weights must sum to 100, got ${total / 100}`);
|
|
169
|
+
return this.pushNode({
|
|
170
|
+
id: "",
|
|
171
|
+
type: "cohort",
|
|
172
|
+
...opts?.key !== void 0 ? { key: opts.key } : {},
|
|
173
|
+
arms: entries.map(([name, a]) => ({
|
|
174
|
+
name,
|
|
175
|
+
weight: a.weight,
|
|
176
|
+
flow: a.flow ? resolveSubFlow(a.flow) : []
|
|
177
|
+
}))
|
|
178
|
+
}, loc);
|
|
179
|
+
}
|
|
180
|
+
exit(reason) {
|
|
181
|
+
return this.pushNode({
|
|
182
|
+
id: "",
|
|
183
|
+
type: "exit",
|
|
184
|
+
...reason !== void 0 ? { reason } : {}
|
|
185
|
+
}, captureLoc(this.exit));
|
|
186
|
+
}
|
|
187
|
+
sendEvent(ev, ...payload) {
|
|
188
|
+
const values = payload[0] ?? {};
|
|
189
|
+
for (const [field, value] of Object.entries(values)) if (!(typeof value === "object" && value !== null && value.type === "user_property") && ![
|
|
190
|
+
"string",
|
|
191
|
+
"number",
|
|
192
|
+
"boolean"
|
|
193
|
+
].includes(typeof value)) throw new TypeError(`sendEvent('${ev.name}'): '${field}' is not a scalar or a u.xxx reference — an emitted payload carries scalar fields only`);
|
|
194
|
+
return this.pushNode({
|
|
195
|
+
id: "",
|
|
196
|
+
type: "send_event",
|
|
197
|
+
event: ev.name,
|
|
198
|
+
payload: values
|
|
199
|
+
}, captureLoc(this.sendEvent));
|
|
200
|
+
}
|
|
201
|
+
run(a, ...args) {
|
|
202
|
+
return this.pushNode({
|
|
203
|
+
id: "",
|
|
204
|
+
type: "action",
|
|
205
|
+
action: a.name,
|
|
206
|
+
args: args[0] ?? {},
|
|
207
|
+
codeHash: a.codeHash
|
|
208
|
+
}, captureLoc(this.run));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* A reusable flow fragment: a free function. Once personalization goes through
|
|
213
|
+
* u.xxx and events through e.xxx, the flow layer carries no schema generics.
|
|
214
|
+
*/
|
|
215
|
+
function flow(build) {
|
|
216
|
+
const builder = new FlowBuilderImpl();
|
|
217
|
+
build(builder);
|
|
218
|
+
return {
|
|
219
|
+
__flow: true,
|
|
220
|
+
nodes: builder.nodes
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
export { FlowBuilderImpl, flow };
|
|
225
|
+
|
|
226
|
+
//# sourceMappingURL=flow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.mjs","names":[],"sources":["../../src/dsl/flow.ts"],"sourcesContent":["import type { ChannelIR, ConditionIR, NodeIR, PropValueIR, SourceLocIR } from '../ir';\nimport { captureLoc } from '../provenance';\nimport type { ActionRef } from './action';\nimport { type Duration, type TimeOfDay, type Weekday, durationIR, timeOfDayMinutes } from './base';\nimport { type Condition, condIR } from './condition';\nimport type { EventRef, MessageArgs, PropInput } from './refs';\nimport type { Channel, TemplateRef } from './template';\n\n/**\n * The flow chain — FlowBuilder is the DSL's step surface (messages, delays,\n * flow control, data), and its implementation is the compiler front half: each\n * chained call executes no logic, it just collects one IR node (ids are\n * assigned later, in workflow.toIR()). Sub-flow callbacks run exactly once at\n * construction — builder in, builder out — so the output is always a static\n * tree.\n *\n * Every public method also captures its callsite (provenance): the loc lands\n * in the node's hash-excluded meta and is the anchor for future in-place\n * editing from the studio.\n */\n\ntype Scalar = string | number | boolean;\n\n/** An emitted field: a scalar (or a profile ref to one); a nested field cannot be sent. */\ntype EmitValue<T> = [NonNullable<T>] extends [Scalar] ? PropInput<T> : never;\n\n/** The payload `sendEvent` accepts for an event: its fields, scalar ones only. */\nexport type EmitPayload<P> = { [K in keyof P]: EmitValue<P[K]> };\n\n/** Payload may be omitted when the event declares no required field. */\nexport type EmitArgs<P> =\n Record<never, never> extends P ? [payload?: EmitPayload<P>] : [payload: EmitPayload<P>];\n\n/** Per-node push options. */\nexport interface PushOptions {\n /** Which devices get a copy: 'all' (the default) or only the most recently registered. */\n devices?: 'all' | 'latest';\n}\n\n/** A reusable flow fragment (what `flow(...)` returns), referenced directly by branch arms. */\nexport interface Flow {\n readonly __flow: true;\n}\n\ninterface FlowInternal extends Flow {\n readonly nodes: NodeIR[];\n}\n\n/** Sub-flow: a named fragment, or an inline callback (runs once at construction — builder in, builder out). */\nexport type SubFlow = Flow | ((w: FlowBuilder) => FlowBuilder);\n\n/** A branch arm: the [condition, sub-flow] tuple — an [if, then] ordering convention. */\nexport type BranchCase = readonly [condition: Condition, flow: SubFlow];\n\n/**\n * A branch argument: either a tuple arm, or a bare sub-flow meaning the default\n * arm. The bare form may appear once, and must come last (checked at runtime).\n */\nexport type BranchArm = BranchCase | SubFlow;\n\n/**\n * A cohort arm name has two jobs, and both constrain its spelling:\n * - it is interpolated into the node ids of the arm's flow ('{id}.{name}.{j}'),\n * and an id is a durable step name — a dot would fake a nesting level and can\n * collide with a real one, an empty name gives '{id}..{j}';\n * - it is an object key, and JavaScript lists integer-like keys first in\n * ascending numeric order however the author wrote them. The arms array is\n * documented (and interpreted) as authoring order, and the bucketing walk\n * accumulates weights along it, so an arm named '0' added to a live\n * experiment would prepend itself and re-bucket everyone already in it.\n */\nconst ARM_NAME = /^[A-Za-z_][A-Za-z0-9_-]*$/;\n\nfunction resolveSubFlow(sub: SubFlow): NodeIR[] {\n if (typeof sub === 'function') {\n const builder = new FlowBuilderImpl();\n const returned: unknown = sub(builder);\n // An async callback would add its nodes after construction is over — after ids were assigned\n if (typeof (returned as { then?: unknown } | undefined)?.then === 'function') {\n throw new TypeError(\n 'sub-flow callbacks must be synchronous: they run once, while the workflow is defined'\n );\n }\n return builder.nodes;\n }\n /*\n * A named fragment is a value, and the convention is to reuse it — two branch\n * arms may hold the same one. Handing out its own nodes aliases them into\n * both places, and assignIds writes ids *in place*: the second prefix\n * overwrites the first, so the two placements end up as one object under one\n * id — one durable step name, one message idempotency key, one bucket seed.\n * A copy per placement is what makes a fragment behave like a value.\n */\n return structuredClone((sub as FlowInternal).nodes);\n}\n\nexport interface FlowBuilder {\n /* ---- Messages: every channel is one message node; separate methods buy channel-level typing ---- */\n email<P extends object>(template: TemplateRef<'email', P>, ...props: MessageArgs<P>): this;\n sms<P extends object>(template: TemplateRef<'sms', P>, ...props: MessageArgs<P>): this;\n /**\n * Push to the user's devices — every device the host's directory lists, or\n * only the most recently registered with `{ devices: 'latest' }`. A user with\n * no device is skipped (branch on `reachable('push')` to fall back to email).\n */\n push<P extends object>(\n template: TemplateRef<'push', P>,\n ...args: [...props: MessageArgs<P>, options?: PushOptions]\n ): this;\n inApp<P extends object>(template: TemplateRef<'in_app', P>, ...props: MessageArgs<P>): this;\n slack<P extends object>(template: TemplateRef<'slack', P>, ...props: MessageArgs<P>): this;\n discord<P extends object>(template: TemplateRef<'discord', P>, ...props: MessageArgs<P>): this;\n survey<P extends object>(template: TemplateRef<'survey', P>, ...props: MessageArgs<P>): this;\n\n /* --------------------------------- Delays --------------------------------- */\n /** Time Delay; passing { min, max } makes it a Randomized Delay. */\n delay(duration: Duration): this;\n delay(range: { min: Duration; max: Duration }): this;\n\n /** Time Window: hold until inside the window (e.g. weekdays 09:00–17:00). tz: 'user' uses the user's timezone. */\n timeWindow(opts: {\n days?: readonly Weekday[];\n between: readonly [TimeOfDay, TimeOfDay];\n tz?: 'user' | (string & {});\n }): this;\n\n /**\n * Wait Until: continue on the main line once the condition holds, or take\n * onTimeout when it expires (default 'continue'). On the engine side this is\n * \"await event racing a timer\" — a native primitive of durable runtimes.\n */\n waitUntil(\n condition: Condition,\n opts: { timeout: Duration; onTimeout?: 'continue' | 'exit' | SubFlow }\n ): this;\n\n /**\n * Splice a fragment in place: a named `flow(...)` or a callback, expanded\n * once while the workflow is defined — a composition step before compiling,\n * not a node (the IR has no trace of it, and ids are assigned over the whole\n * workflow as if the steps were written inline). Each use gets its own copy,\n * so one fragment can be used in several places and workflows.\n *\n * const preferPush = (push, email, props) =>\n * flow((w) => w.branch([reachable('push'), (b) => b.push(push, props)], (b) => b.email(email, props)));\n * workflow({ id: 'onboarding', ... }).use(preferPush(tipPush, tipEmail, { name: u.name }))\n */\n use(fragment: SubFlow): this;\n\n /* ------------------------------ Flow Control ------------------------------ */\n /**\n * Conditional branch: ordered first-match (same semantics as Step Functions\n * Choice / Knock branch). This one primitive covers both the UI's True/False\n * Branch (two arms) and Multi-Split Branch (N arms). Arms are\n * [condition, sub-flow] tuples; a bare sub-flow in tail position is the\n * default arm. With no match and no default, execution simply continues.\n * Rejoin is structural: after the matching arm finishes, execution resumes\n * at the node following the branch — to opt out, call .exit() inside the arm.\n *\n * .branch([activeSubscriber, upgradeFlow], firstTimeFlow) // True/False\n * .branch([vip, vipFlow], [trial, trialFlow], defaultFlow) // Multi-Split\n * .branch([not(usedStaging), eduFlow]) // single arm: no match continues\n *\n * The optional first argument `label` becomes the node's name in IR (UI title\n * / observability handle). It is not a jump target — there is no goto here;\n * looping is a future re-entry-policy topic (see sendEvent). Arm labels in\n * the UI are derived from the condition.\n */\n branch(...arms: readonly BranchArm[]): this;\n branch(label: string, ...arms: readonly BranchArm[]): this;\n\n /**\n * Gate: exit unless the condition holds, otherwise continue. A first-class\n * node rather than sugar over branch — same semantics as Zapier's \"only\n * continue if\" / Iterable's Filter tile, and rendered on its own in the UI.\n * `reason` is the audit-log line — metadata, so rewording it is free\n * (excluded from contentHash, see hash.ts).\n */\n filter(condition: Condition, opts?: { reason?: string }): this;\n\n /**\n * Random Cohort Branch (A/B): weights must sum to 100 (checked at runtime).\n * `key` names the experiment: bucketing hashes `userId:key` instead of the\n * structural node id, so assignments survive node insertion/moves and the\n * experiment keeps one identity across workflow versions — set it for any\n * A/B whose results you intend to read.\n *\n * Arm names become node id segments and are read back in authoring order, so\n * they are restricted to letters, digits, '_' and '-', never starting with a\n * digit (checked at runtime).\n */\n cohort(arms: Record<string, { weight: number; flow?: SubFlow }>, opts?: { key?: string }): this;\n\n /**\n * Exit: end the whole workflow immediately (the UI's Exit node); `reason`\n * goes into the audit log and is metadata, so rewording it neither repins\n * in-flight journeys nor shows up in plan. Inside a branch arm this means\n * \"terminate, do not rejoin\" — it stops here instead of falling through,\n * while an arm without exit rejoins naturally.\n */\n exit(reason?: string): this;\n\n /* ---------------------------------- Data ---------------------------------- */\n /**\n * Emit a typed event (customer.io's Send Event). The event comes from an\n * e.xxx reference, so payload types flow in the same way trigger.event works.\n * This is how workflows compose: an event can trigger another workflow, and\n * the resulting call graph is statically analyzable. Payload values may\n * reference u.xxx. Only scalar fields can be sent (IR carries literals and\n * profile refs, not nested JSON): an event whose payload requires a nested\n * field cannot be emitted from a journey, and the types say so.\n *\n * Note on loops: a trailing self-triggering sendEvent will become the\n * official periodic-flow shape *once a re-entry policy exists* — today the\n * entry policy is once-per-user, so a self-trigger cannot re-enter and does\n * not loop.\n * TODO: the rest of the Data category — outbound webhook / profile update /\n * journey attributes.\n */\n sendEvent<P extends object>(event: EventRef<P>, ...payload: EmitArgs<P>): this;\n\n /**\n * Run a custom action (see dsl/action.ts for the model). The chain records\n * identity only — name, args, codeHash — never the code: the implementation\n * ships inside the deployed Worker bundle and is resolved by name from the\n * runtime registry. Args are typed by the ActionRef and may reference u.xxx,\n * resolved at run time exactly like message props. Executed inside a durable\n * step: retried on throw, checkpointed on success.\n */\n run<A extends object>(action: ActionRef<A>, ...args: MessageArgs<A>): this;\n}\n\n/* oxlint-disable typescript/unbound-method --\n * `captureLoc(this.xxx)` passes the method by identity as the stack-trace\n * boundary for Error.captureStackTrace; it is never invoked, so `this`\n * scoping cannot go wrong. */\n/** @internal extended by WorkflowBuilderImpl; not part of the public API */\nexport class FlowBuilderImpl implements FlowBuilder {\n /** Nodes as collected; ids are assigned in one pass inside toIR, so '' is a placeholder here. */\n readonly nodes: NodeIR[] = [];\n\n /** Provenance: the callsite (captured in the public method) lands in meta.loc, outside the hash. */\n private pushNode(node: NodeIR, loc: SourceLocIR | undefined): this {\n this.nodes.push({ ...node, ...(loc !== undefined ? { meta: { loc } } : {}) });\n return this;\n }\n\n private message(\n channel: ChannelIR,\n tpl: TemplateRef<Channel, object>,\n props: object | undefined,\n loc: SourceLocIR | undefined,\n devices?: 'latest'\n ): this {\n return this.pushNode(\n {\n id: '',\n type: 'message',\n channel,\n template: tpl.key,\n props: (props ?? {}) as Record<string, PropValueIR>,\n // Absent for 'all', so adding the option left every existing push's hash as it was\n ...(devices !== undefined ? { devices } : {}),\n },\n loc\n );\n }\n\n email<P extends object>(t: TemplateRef<'email', P>, ...args: MessageArgs<P>): this {\n return this.message('email', t, args[0], captureLoc(this.email));\n }\n sms<P extends object>(t: TemplateRef<'sms', P>, ...args: MessageArgs<P>): this {\n return this.message('sms', t, args[0], captureLoc(this.sms));\n }\n push<P extends object>(\n t: TemplateRef<'push', P>,\n ...args: [...props: MessageArgs<P>, options?: PushOptions]\n ): this {\n const [props, options] = args as unknown as [object | undefined, PushOptions | undefined];\n const devices = options?.devices === 'latest' ? 'latest' : undefined;\n return this.message('push', t, props, captureLoc(this.push), devices);\n }\n inApp<P extends object>(t: TemplateRef<'in_app', P>, ...args: MessageArgs<P>): this {\n return this.message('in_app', t, args[0], captureLoc(this.inApp));\n }\n slack<P extends object>(t: TemplateRef<'slack', P>, ...args: MessageArgs<P>): this {\n return this.message('slack', t, args[0], captureLoc(this.slack));\n }\n discord<P extends object>(t: TemplateRef<'discord', P>, ...args: MessageArgs<P>): this {\n return this.message('discord', t, args[0], captureLoc(this.discord));\n }\n survey<P extends object>(t: TemplateRef<'survey', P>, ...args: MessageArgs<P>): this {\n return this.message('survey', t, args[0], captureLoc(this.survey));\n }\n\n delay(duration: Duration): this;\n delay(range: { min: Duration; max: Duration }): this;\n delay(d: Duration | { min: Duration; max: Duration }): this {\n const loc = captureLoc(this.delay);\n if (typeof d === 'string') {\n return this.pushNode({ id: '', type: 'delay', duration: durationIR(d) }, loc);\n }\n const min = durationIR(d.min);\n const max = durationIR(d.max);\n /*\n * The interpreter draws `min + random(max - min)` with the span clamped at\n * zero, so a backwards range does not fail — it quietly collapses into a\n * fixed `min` sleep. Reject it here, where the author can still see it.\n */\n if (max.ms < min.ms) {\n throw new Error(\n `delay(): 'max' must not be shorter than 'min', got { min: '${d.min}', max: '${d.max}' }`\n );\n }\n return this.pushNode({ id: '', type: 'random_delay', min, max }, loc);\n }\n\n timeWindow(opts: {\n days?: readonly Weekday[];\n between: readonly [TimeOfDay, TimeOfDay];\n tz?: 'user' | (string & {});\n }): this {\n const loc = captureLoc(this.timeWindow);\n const start = timeOfDayMinutes(opts.between[0]);\n const end = timeOfDayMinutes(opts.between[1]);\n if (end <= start) {\n throw new Error(\n `timeWindow(): 'between' must open before it closes within one day, got [${opts.between[0]}, ${opts.between[1]}] (overnight windows are not supported yet)`\n );\n }\n return this.pushNode(\n {\n id: '',\n type: 'time_window',\n days: [...(opts.days ?? (['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] as const))],\n between: [opts.between[0], opts.between[1]],\n tz: opts.tz ?? 'user',\n },\n loc\n );\n }\n\n waitUntil(\n condition: Condition,\n opts: { timeout: Duration; onTimeout?: 'continue' | 'exit' | SubFlow }\n ): this {\n const loc = captureLoc(this.waitUntil);\n const onTimeout = opts.onTimeout ?? 'continue';\n return this.pushNode(\n {\n id: '',\n type: 'wait_until',\n condition: condIR(condition),\n timeout: durationIR(opts.timeout),\n onTimeout:\n onTimeout === 'continue' || onTimeout === 'exit' ? onTimeout : resolveSubFlow(onTimeout),\n },\n loc\n );\n }\n\n use(fragment: SubFlow): this {\n // The fragment's nodes carry their own provenance (where the fragment was written)\n this.nodes.push(...resolveSubFlow(fragment));\n return this;\n }\n\n branch(...arms: readonly BranchArm[]): this;\n branch(label: string, ...arms: readonly BranchArm[]): this;\n branch(...args: readonly (string | BranchArm)[]): this {\n const loc = captureLoc(this.branch);\n const label = typeof args[0] === 'string' ? args[0] : undefined;\n const arms = (label === undefined ? args : args.slice(1)) as readonly BranchArm[];\n\n const cases: { condition: ConditionIR; flow: NodeIR[] }[] = [];\n let otherwise: NodeIR[] | undefined;\n arms.forEach((arm, i) => {\n if (Array.isArray(arm)) {\n if (otherwise !== undefined) {\n throw new Error('branch(): default arm (bare sub-flow) must be the last argument');\n }\n const [condition, sub] = arm as BranchCase;\n cases.push({ condition: condIR(condition), flow: resolveSubFlow(sub) });\n } else {\n if (otherwise !== undefined) {\n throw new Error('branch(): only one default arm (bare sub-flow) is allowed');\n }\n if (i !== arms.length - 1) {\n throw new Error('branch(): default arm (bare sub-flow) must be the last argument');\n }\n otherwise = resolveSubFlow(arm as SubFlow);\n }\n });\n\n return this.pushNode(\n {\n id: '',\n type: 'branch',\n ...(label !== undefined ? { label } : {}),\n cases,\n ...(otherwise !== undefined ? { otherwise } : {}),\n },\n loc\n );\n }\n\n filter(condition: Condition, opts?: { reason?: string }): this {\n return this.pushNode(\n {\n id: '',\n type: 'filter',\n condition: condIR(condition),\n ...(opts?.reason !== undefined ? { reason: opts.reason } : {}),\n },\n captureLoc(this.filter)\n );\n }\n\n cohort(arms: Record<string, { weight: number; flow?: SubFlow }>, opts?: { key?: string }): this {\n const loc = captureLoc(this.cohort);\n const entries = Object.entries(arms);\n /*\n * Weights live on a 0.01% grid: the runtime buckets into 10,000 slots\n * (basis points), so anything finer would be silently quantized — reject\n * it here instead. Converting to integer basis points also makes the\n * sum check exact; no epsilon needed.\n */\n const basisPoints = entries.map(([name, a]) => {\n if (!ARM_NAME.test(name)) {\n throw new Error(\n `cohort(): arm name '${name}' must start with a letter or '_' and contain only letters, digits, '_' or '-' — arm names become node id segments, and integer-like names would silently reorder the arms`\n );\n }\n const bp = a.weight * 100;\n if (Math.abs(bp - Math.round(bp)) > 1e-6) {\n throw new Error(\n `cohort(): arm '${name}' weight ${a.weight} is finer than the 0.01% bucketing grid — use at most two decimal places`\n );\n }\n /*\n * The sum check alone accepts -50 / 150: the runtime walks the arms\n * accumulating basis points and takes the first whose cumulative total\n * clears the bucket, so a negative weight hands 100% of users to its\n * neighbour instead of splitting anything.\n */\n if (bp < 0) {\n throw new Error(`cohort(): arm '${name}' weight ${a.weight} must not be negative`);\n }\n return Math.round(bp);\n });\n const total = basisPoints.reduce((sum, bp) => sum + bp, 0);\n if (total !== 10_000) {\n throw new Error(`cohort(): weights must sum to 100, got ${total / 100}`);\n }\n return this.pushNode(\n {\n id: '',\n type: 'cohort',\n ...(opts?.key !== undefined ? { key: opts.key } : {}),\n arms: entries.map(([name, a]) => ({\n name,\n weight: a.weight,\n flow: a.flow ? resolveSubFlow(a.flow) : [],\n })),\n },\n loc\n );\n }\n\n exit(reason?: string): this {\n return this.pushNode(\n { id: '', type: 'exit', ...(reason !== undefined ? { reason } : {}) },\n captureLoc(this.exit)\n );\n }\n\n sendEvent<P extends object>(ev: EventRef<P>, ...payload: EmitArgs<P>): this {\n const values = (payload[0] ?? {}) as Record<string, unknown>;\n for (const [field, value] of Object.entries(values)) {\n const ref =\n typeof value === 'object' &&\n value !== null &&\n (value as { type?: unknown }).type === 'user_property';\n if (!ref && !['string', 'number', 'boolean'].includes(typeof value)) {\n throw new TypeError(\n `sendEvent('${ev.name}'): '${field}' is not a scalar or a u.xxx reference — an emitted payload carries scalar fields only`\n );\n }\n }\n return this.pushNode(\n {\n id: '',\n type: 'send_event',\n event: ev.name,\n payload: values as Record<string, PropValueIR>,\n },\n captureLoc(this.sendEvent)\n );\n }\n\n run<A extends object>(a: ActionRef<A>, ...args: MessageArgs<A>): this {\n return this.pushNode(\n {\n id: '',\n type: 'action',\n action: a.name,\n args: (args[0] ?? {}) as Record<string, PropValueIR>,\n codeHash: a.codeHash,\n },\n captureLoc(this.run)\n );\n }\n}\n/* oxlint-enable typescript/unbound-method */\n\n/**\n * A reusable flow fragment: a free function. Once personalization goes through\n * u.xxx and events through e.xxx, the flow layer carries no schema generics.\n */\nexport function flow(build: (w: FlowBuilder) => FlowBuilder): Flow {\n const builder = new FlowBuilderImpl();\n build(builder);\n const impl: FlowInternal = { __flow: true, nodes: builder.nodes };\n return impl;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_dsl_action = require("./action.cjs");
|
|
3
|
+
const require_dsl_refs = require("./refs.cjs");
|
|
4
|
+
const require_dsl_template = require("./template.cjs");
|
|
5
|
+
const require_dsl_condition = require("./condition.cjs");
|
|
6
|
+
const require_dsl_flow = require("./flow.cjs");
|
|
7
|
+
const require_dsl_trigger = require("./trigger.cjs");
|
|
8
|
+
const require_dsl_workflow = require("./workflow.cjs");
|
|
9
|
+
const require_dsl_bundle = require("./bundle.cjs");
|
|
10
|
+
exports.action = require_dsl_action.action;
|
|
11
|
+
exports.and = require_dsl_condition.and;
|
|
12
|
+
exports.between = require_dsl_condition.between;
|
|
13
|
+
exports.compileBundle = require_dsl_bundle.compileBundle;
|
|
14
|
+
exports.contains = require_dsl_condition.contains;
|
|
15
|
+
exports.eq = require_dsl_condition.eq;
|
|
16
|
+
exports.event = require_dsl_refs.event;
|
|
17
|
+
exports.exists = require_dsl_condition.exists;
|
|
18
|
+
exports.flow = require_dsl_flow.flow;
|
|
19
|
+
exports.gt = require_dsl_condition.gt;
|
|
20
|
+
exports.gte = require_dsl_condition.gte;
|
|
21
|
+
exports.inArray = require_dsl_condition.inArray;
|
|
22
|
+
exports.lt = require_dsl_condition.lt;
|
|
23
|
+
exports.lte = require_dsl_condition.lte;
|
|
24
|
+
exports.ne = require_dsl_condition.ne;
|
|
25
|
+
exports.not = require_dsl_condition.not;
|
|
26
|
+
exports.notBetween = require_dsl_condition.notBetween;
|
|
27
|
+
exports.notContains = require_dsl_condition.notContains;
|
|
28
|
+
exports.notExists = require_dsl_condition.notExists;
|
|
29
|
+
exports.notInArray = require_dsl_condition.notInArray;
|
|
30
|
+
exports.or = require_dsl_condition.or;
|
|
31
|
+
exports.performed = require_dsl_condition.performed;
|
|
32
|
+
exports.reachable = require_dsl_condition.reachable;
|
|
33
|
+
exports.segment = require_dsl_condition.segment;
|
|
34
|
+
exports.template = require_dsl_template.template;
|
|
35
|
+
exports.templates = require_dsl_template.templates;
|
|
36
|
+
exports.trigger = require_dsl_trigger.trigger;
|
|
37
|
+
exports.user = require_dsl_refs.user;
|
|
38
|
+
exports.workflow = require_dsl_workflow.workflow;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActionContext, ActionHandler, ActionRef, action } from "./action.cjs";
|
|
2
|
+
import { Duration, EventMap, TimeOfDay, UserPropertyBase, Weekday } from "./base.cjs";
|
|
3
|
+
import { EventRef, EventRefs, MessageArgs, PayloadRef, PayloadRefNode, PayloadRefs, PropInput, PropsInput, UserPropertyRef, UserRefs, event, user } from "./refs.cjs";
|
|
4
|
+
import { Channel, EmptyProps, PropsOf, TemplateFactory, TemplateRef, TemplateRefTable, TemplateRefs, TemplateRegistry, template, templates } from "./template.cjs";
|
|
5
|
+
import { Condition, PayloadWhere, PerformedOptions, SegmentDefinition, SegmentRef, and, between, contains, eq, exists, gt, gte, inArray, lt, lte, ne, not, notBetween, notContains, notExists, notInArray, or, performed, reachable, segment } from "./condition.cjs";
|
|
6
|
+
import { BranchArm, BranchCase, EmitArgs, EmitPayload, Flow, FlowBuilder, PushOptions, SubFlow, flow } from "./flow.cjs";
|
|
7
|
+
import { DateTime, EventTriggerOptions, TriggerFactory, TriggerRef, trigger } from "./trigger.cjs";
|
|
8
|
+
import { GoalOptions, WorkflowBuilder, WorkflowDefinition, workflow } from "./workflow.cjs";
|
|
9
|
+
import { compileBundle } from "./bundle.cjs";
|
|
10
|
+
export { type ActionContext, type ActionHandler, type ActionRef, type BranchArm, type BranchCase, type Channel, type Condition, type DateTime, type Duration, type EmitArgs, type EmitPayload, type EmptyProps, type EventMap, type EventRef, type EventRefs, type EventTriggerOptions, type Flow, type FlowBuilder, type GoalOptions, type MessageArgs, type PayloadRef, type PayloadRefNode, type PayloadRefs, type PayloadWhere, type PerformedOptions, type PropInput, type PropsInput, type PropsOf, type PushOptions, type SegmentDefinition, type SegmentRef, type SubFlow, type TemplateFactory, type TemplateRef, type TemplateRefTable, type TemplateRefs, type TemplateRegistry, type TimeOfDay, type TriggerFactory, type TriggerRef, type UserPropertyBase, type UserPropertyRef, type UserRefs, type Weekday, type WorkflowBuilder, type WorkflowDefinition, action, and, between, compileBundle, contains, eq, event, exists, flow, gt, gte, inArray, lt, lte, ne, not, notBetween, notContains, notExists, notInArray, or, performed, reachable, segment, template, templates, trigger, user, workflow };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActionContext, ActionHandler, ActionRef, action } from "./action.mjs";
|
|
2
|
+
import { Duration, EventMap, TimeOfDay, UserPropertyBase, Weekday } from "./base.mjs";
|
|
3
|
+
import { EventRef, EventRefs, MessageArgs, PayloadRef, PayloadRefNode, PayloadRefs, PropInput, PropsInput, UserPropertyRef, UserRefs, event, user } from "./refs.mjs";
|
|
4
|
+
import { Channel, EmptyProps, PropsOf, TemplateFactory, TemplateRef, TemplateRefTable, TemplateRefs, TemplateRegistry, template, templates } from "./template.mjs";
|
|
5
|
+
import { Condition, PayloadWhere, PerformedOptions, SegmentDefinition, SegmentRef, and, between, contains, eq, exists, gt, gte, inArray, lt, lte, ne, not, notBetween, notContains, notExists, notInArray, or, performed, reachable, segment } from "./condition.mjs";
|
|
6
|
+
import { BranchArm, BranchCase, EmitArgs, EmitPayload, Flow, FlowBuilder, PushOptions, SubFlow, flow } from "./flow.mjs";
|
|
7
|
+
import { DateTime, EventTriggerOptions, TriggerFactory, TriggerRef, trigger } from "./trigger.mjs";
|
|
8
|
+
import { GoalOptions, WorkflowBuilder, WorkflowDefinition, workflow } from "./workflow.mjs";
|
|
9
|
+
import { compileBundle } from "./bundle.mjs";
|
|
10
|
+
export { type ActionContext, type ActionHandler, type ActionRef, type BranchArm, type BranchCase, type Channel, type Condition, type DateTime, type Duration, type EmitArgs, type EmitPayload, type EmptyProps, type EventMap, type EventRef, type EventRefs, type EventTriggerOptions, type Flow, type FlowBuilder, type GoalOptions, type MessageArgs, type PayloadRef, type PayloadRefNode, type PayloadRefs, type PayloadWhere, type PerformedOptions, type PropInput, type PropsInput, type PropsOf, type PushOptions, type SegmentDefinition, type SegmentRef, type SubFlow, type TemplateFactory, type TemplateRef, type TemplateRefTable, type TemplateRefs, type TemplateRegistry, type TimeOfDay, type TriggerFactory, type TriggerRef, type UserPropertyBase, type UserPropertyRef, type UserRefs, type Weekday, type WorkflowBuilder, type WorkflowDefinition, action, and, between, compileBundle, contains, eq, event, exists, flow, gt, gte, inArray, lt, lte, ne, not, notBetween, notContains, notExists, notInArray, or, performed, reachable, segment, template, templates, trigger, user, workflow };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { action } from "./action.mjs";
|
|
2
|
+
import { event, user } from "./refs.mjs";
|
|
3
|
+
import { template, templates } from "./template.mjs";
|
|
4
|
+
import { and, between, contains, eq, exists, gt, gte, inArray, lt, lte, ne, not, notBetween, notContains, notExists, notInArray, or, performed, reachable, segment } from "./condition.mjs";
|
|
5
|
+
import { flow } from "./flow.mjs";
|
|
6
|
+
import { trigger } from "./trigger.mjs";
|
|
7
|
+
import { workflow } from "./workflow.mjs";
|
|
8
|
+
import { compileBundle } from "./bundle.mjs";
|
|
9
|
+
export { action, and, between, compileBundle, contains, eq, event, exists, flow, gt, gte, inArray, lt, lte, ne, not, notBetween, notContains, notExists, notInArray, or, performed, reachable, segment, template, templates, trigger, user, workflow };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/dsl/refs.ts
|
|
3
|
+
/**
|
|
4
|
+
* Build the reference tables: the app calls each once in its schema module and
|
|
5
|
+
* exports the result (implemented with a Proxy — property access *is* the reference).
|
|
6
|
+
*
|
|
7
|
+
* export const u = user<UserProperty>();
|
|
8
|
+
* export const e = event<Event>();
|
|
9
|
+
*
|
|
10
|
+
* From then on predicates and personalization are all property access:
|
|
11
|
+
* eq(u.subscription_status, 'active'), performed(e.purchase, { within: '30 days' }),
|
|
12
|
+
* { plan: u.subscription_plan }.
|
|
13
|
+
*
|
|
14
|
+
* Properties are deliberately single-level: the data source is a database
|
|
15
|
+
* table and is naturally flat, so nested paths are out of scope.
|
|
16
|
+
*/
|
|
17
|
+
function user() {
|
|
18
|
+
return new Proxy({}, { get: (_target, prop) => ({
|
|
19
|
+
type: "user_property",
|
|
20
|
+
path: String(prop)
|
|
21
|
+
}) });
|
|
22
|
+
}
|
|
23
|
+
function event() {
|
|
24
|
+
return new Proxy({}, { get: (_target, prop) => ({
|
|
25
|
+
type: "event_ref",
|
|
26
|
+
name: String(prop)
|
|
27
|
+
}) });
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Where a payload ref keeps its own state. A payload ref doubles as the table
|
|
31
|
+
* of its sub-fields, so every *string* key it answered for itself shadowed an
|
|
32
|
+
* author's field of that name: with a payload field called `path`,
|
|
33
|
+
* `performed(e.page_view, (p) => eq(p.path, '/pricing'))` type-checked, handed
|
|
34
|
+
* `prop()` the ref's own prefix instead of a sub-ref, and compiled to a
|
|
35
|
+
* *profile* predicate on a property named 'path' — a mistake that only
|
|
36
|
+
* surfaced later, as a zod error nowhere near the line that caused it. A symbol
|
|
37
|
+
* key cannot be reached by `p.<field>`, so no field name can collide with it.
|
|
38
|
+
*/
|
|
39
|
+
const PAYLOAD_PATH = Symbol("workflow.payloadPath");
|
|
40
|
+
/**
|
|
41
|
+
* Nested Proxy: every string key extends the dotted path, so an author's field
|
|
42
|
+
* may be named anything — including `path` or `type`. The ref's own path reads
|
|
43
|
+
* off PAYLOAD_PATH, the one key a field name cannot spell.
|
|
44
|
+
* @internal used by performed() and trigger.event() to hand `p` to a where callback
|
|
45
|
+
*/
|
|
46
|
+
function payloadRefs(prefix = "") {
|
|
47
|
+
return new Proxy({}, { get: (_target, prop) => {
|
|
48
|
+
if (prop === PAYLOAD_PATH) return prefix;
|
|
49
|
+
if (typeof prop === "symbol") return void 0;
|
|
50
|
+
return payloadRefs(prefix === "" ? prop : `${prefix}.${prop}`);
|
|
51
|
+
} });
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
exports.PAYLOAD_PATH = PAYLOAD_PATH;
|
|
55
|
+
exports.event = event;
|
|
56
|
+
exports.payloadRefs = payloadRefs;
|
|
57
|
+
exports.user = user;
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=refs.cjs.map
|