sendwend 0.0.0-stage → 12.7.3

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.
Files changed (680) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2082 -2
  3. package/dist/_virtual/_rolldown/runtime.cjs +22 -0
  4. package/dist/apns-relay.cjs +91 -0
  5. package/dist/apns-relay.cjs.map +1 -0
  6. package/dist/apns-relay.d.cts +26 -0
  7. package/dist/apns-relay.d.cts.map +1 -0
  8. package/dist/apns-relay.d.mts +26 -0
  9. package/dist/apns-relay.d.mts.map +1 -0
  10. package/dist/apns-relay.mjs +90 -0
  11. package/dist/apns-relay.mjs.map +1 -0
  12. package/dist/apns.cjs +215 -0
  13. package/dist/apns.cjs.map +1 -0
  14. package/dist/apns.d.cts +110 -0
  15. package/dist/apns.d.cts.map +1 -0
  16. package/dist/apns.d.mts +110 -0
  17. package/dist/apns.d.mts.map +1 -0
  18. package/dist/apns.mjs +207 -0
  19. package/dist/apns.mjs.map +1 -0
  20. package/dist/aws/engine-step.cjs +105 -0
  21. package/dist/aws/engine-step.cjs.map +1 -0
  22. package/dist/aws/engine-step.d.cts +42 -0
  23. package/dist/aws/engine-step.d.cts.map +1 -0
  24. package/dist/aws/engine-step.d.mts +42 -0
  25. package/dist/aws/engine-step.d.mts.map +1 -0
  26. package/dist/aws/engine-step.mjs +103 -0
  27. package/dist/aws/engine-step.mjs.map +1 -0
  28. package/dist/aws/function-url.cjs +53 -0
  29. package/dist/aws/function-url.cjs.map +1 -0
  30. package/dist/aws/function-url.d.cts +36 -0
  31. package/dist/aws/function-url.d.cts.map +1 -0
  32. package/dist/aws/function-url.d.mts +36 -0
  33. package/dist/aws/function-url.d.mts.map +1 -0
  34. package/dist/aws/function-url.mjs +50 -0
  35. package/dist/aws/function-url.mjs.map +1 -0
  36. package/dist/aws/index.cjs +232 -0
  37. package/dist/aws/index.cjs.map +1 -0
  38. package/dist/aws/index.d.cts +73 -0
  39. package/dist/aws/index.d.cts.map +1 -0
  40. package/dist/aws/index.d.mts +73 -0
  41. package/dist/aws/index.d.mts.map +1 -0
  42. package/dist/aws/index.mjs +218 -0
  43. package/dist/aws/index.mjs.map +1 -0
  44. package/dist/aws/instances.cjs +218 -0
  45. package/dist/aws/instances.cjs.map +1 -0
  46. package/dist/aws/instances.d.cts +102 -0
  47. package/dist/aws/instances.d.cts.map +1 -0
  48. package/dist/aws/instances.d.mts +102 -0
  49. package/dist/aws/instances.d.mts.map +1 -0
  50. package/dist/aws/instances.mjs +214 -0
  51. package/dist/aws/instances.mjs.map +1 -0
  52. package/dist/aws/lambda-api.cjs +86 -0
  53. package/dist/aws/lambda-api.cjs.map +1 -0
  54. package/dist/aws/lambda-api.d.cts +41 -0
  55. package/dist/aws/lambda-api.d.cts.map +1 -0
  56. package/dist/aws/lambda-api.d.mts +41 -0
  57. package/dist/aws/lambda-api.d.mts.map +1 -0
  58. package/dist/aws/lambda-api.mjs +85 -0
  59. package/dist/aws/lambda-api.mjs.map +1 -0
  60. package/dist/client.cjs +216 -0
  61. package/dist/client.cjs.map +1 -0
  62. package/dist/client.d.cts +193 -0
  63. package/dist/client.d.cts.map +1 -0
  64. package/dist/client.d.mts +193 -0
  65. package/dist/client.d.mts.map +1 -0
  66. package/dist/client.mjs +212 -0
  67. package/dist/client.mjs.map +1 -0
  68. package/dist/cloudflare/bindings.cjs +49 -0
  69. package/dist/cloudflare/bindings.cjs.map +1 -0
  70. package/dist/cloudflare/bindings.d.cts +31 -0
  71. package/dist/cloudflare/bindings.d.cts.map +1 -0
  72. package/dist/cloudflare/bindings.d.mts +31 -0
  73. package/dist/cloudflare/bindings.d.mts.map +1 -0
  74. package/dist/cloudflare/bindings.mjs +46 -0
  75. package/dist/cloudflare/bindings.mjs.map +1 -0
  76. package/dist/cloudflare/index.cjs +73 -0
  77. package/dist/cloudflare/index.d.cts +25 -0
  78. package/dist/cloudflare/index.d.mts +25 -0
  79. package/dist/cloudflare/index.mjs +20 -0
  80. package/dist/cloudflare/runner.cjs +200 -0
  81. package/dist/cloudflare/runner.cjs.map +1 -0
  82. package/dist/cloudflare/runner.d.cts +83 -0
  83. package/dist/cloudflare/runner.d.cts.map +1 -0
  84. package/dist/cloudflare/runner.d.mts +83 -0
  85. package/dist/cloudflare/runner.d.mts.map +1 -0
  86. package/dist/cloudflare/runner.mjs +199 -0
  87. package/dist/cloudflare/runner.mjs.map +1 -0
  88. package/dist/cloudflare/worker.cjs +106 -0
  89. package/dist/cloudflare/worker.cjs.map +1 -0
  90. package/dist/cloudflare/worker.d.cts +52 -0
  91. package/dist/cloudflare/worker.d.cts.map +1 -0
  92. package/dist/cloudflare/worker.d.mts +52 -0
  93. package/dist/cloudflare/worker.d.mts.map +1 -0
  94. package/dist/cloudflare/worker.mjs +104 -0
  95. package/dist/cloudflare/worker.mjs.map +1 -0
  96. package/dist/cloudflare/workers.d.cjs +0 -0
  97. package/dist/cloudflare/workers.d.cts +42 -0
  98. package/dist/cloudflare/workers.d.cts.map +1 -0
  99. package/dist/cloudflare/workers.d.mts +42 -0
  100. package/dist/cloudflare/workers.d.mts.map +1 -0
  101. package/dist/config.cjs +257 -0
  102. package/dist/config.cjs.map +1 -0
  103. package/dist/config.d.cts +184 -0
  104. package/dist/config.d.cts.map +1 -0
  105. package/dist/config.d.mts +184 -0
  106. package/dist/config.d.mts.map +1 -0
  107. package/dist/config.mjs +246 -0
  108. package/dist/config.mjs.map +1 -0
  109. package/dist/contract.cjs +222 -0
  110. package/dist/contract.cjs.map +1 -0
  111. package/dist/contract.d.cts +110 -0
  112. package/dist/contract.d.cts.map +1 -0
  113. package/dist/contract.d.mts +110 -0
  114. package/dist/contract.d.mts.map +1 -0
  115. package/dist/contract.mjs +216 -0
  116. package/dist/contract.mjs.map +1 -0
  117. package/dist/date-time.cjs +22 -0
  118. package/dist/date-time.cjs.map +1 -0
  119. package/dist/date-time.d.cts +10 -0
  120. package/dist/date-time.d.cts.map +1 -0
  121. package/dist/date-time.d.mts +10 -0
  122. package/dist/date-time.d.mts.map +1 -0
  123. package/dist/date-time.mjs +21 -0
  124. package/dist/date-time.mjs.map +1 -0
  125. package/dist/dsl/action.cjs +25 -0
  126. package/dist/dsl/action.cjs.map +1 -0
  127. package/dist/dsl/action.d.cts +63 -0
  128. package/dist/dsl/action.d.cts.map +1 -0
  129. package/dist/dsl/action.d.mts +63 -0
  130. package/dist/dsl/action.d.mts.map +1 -0
  131. package/dist/dsl/action.mjs +24 -0
  132. package/dist/dsl/action.mjs.map +1 -0
  133. package/dist/dsl/base.cjs +33 -0
  134. package/dist/dsl/base.cjs.map +1 -0
  135. package/dist/dsl/base.d.cts +43 -0
  136. package/dist/dsl/base.d.cts.map +1 -0
  137. package/dist/dsl/base.d.mts +43 -0
  138. package/dist/dsl/base.d.mts.map +1 -0
  139. package/dist/dsl/base.mjs +29 -0
  140. package/dist/dsl/base.mjs.map +1 -0
  141. package/dist/dsl/bundle.cjs +287 -0
  142. package/dist/dsl/bundle.cjs.map +1 -0
  143. package/dist/dsl/bundle.d.cts +33 -0
  144. package/dist/dsl/bundle.d.cts.map +1 -0
  145. package/dist/dsl/bundle.d.mts +33 -0
  146. package/dist/dsl/bundle.d.mts.map +1 -0
  147. package/dist/dsl/bundle.mjs +284 -0
  148. package/dist/dsl/bundle.mjs.map +1 -0
  149. package/dist/dsl/condition.cjs +200 -0
  150. package/dist/dsl/condition.cjs.map +1 -0
  151. package/dist/dsl/condition.d.cts +151 -0
  152. package/dist/dsl/condition.d.cts.map +1 -0
  153. package/dist/dsl/condition.d.mts +151 -0
  154. package/dist/dsl/condition.d.mts.map +1 -0
  155. package/dist/dsl/condition.mjs +178 -0
  156. package/dist/dsl/condition.mjs.map +1 -0
  157. package/dist/dsl/flow.cjs +335 -0
  158. package/dist/dsl/flow.cjs.map +1 -0
  159. package/dist/dsl/flow.d.cts +278 -0
  160. package/dist/dsl/flow.d.cts.map +1 -0
  161. package/dist/dsl/flow.d.mts +278 -0
  162. package/dist/dsl/flow.d.mts.map +1 -0
  163. package/dist/dsl/flow.mjs +331 -0
  164. package/dist/dsl/flow.mjs.map +1 -0
  165. package/dist/dsl/index.cjs +37 -0
  166. package/dist/dsl/index.d.cts +34 -0
  167. package/dist/dsl/index.d.mts +34 -0
  168. package/dist/dsl/index.mjs +9 -0
  169. package/dist/dsl/refs.cjs +101 -0
  170. package/dist/dsl/refs.cjs.map +1 -0
  171. package/dist/dsl/refs.d.cts +127 -0
  172. package/dist/dsl/refs.d.cts.map +1 -0
  173. package/dist/dsl/refs.d.mts +127 -0
  174. package/dist/dsl/refs.d.mts.map +1 -0
  175. package/dist/dsl/refs.mjs +93 -0
  176. package/dist/dsl/refs.mjs.map +1 -0
  177. package/dist/dsl/template.cjs +19 -0
  178. package/dist/dsl/template.cjs.map +1 -0
  179. package/dist/dsl/template.d.cts +30 -0
  180. package/dist/dsl/template.d.cts.map +1 -0
  181. package/dist/dsl/template.d.mts +30 -0
  182. package/dist/dsl/template.d.mts.map +1 -0
  183. package/dist/dsl/template.mjs +18 -0
  184. package/dist/dsl/template.mjs.map +1 -0
  185. package/dist/dsl/trigger.cjs +53 -0
  186. package/dist/dsl/trigger.cjs.map +1 -0
  187. package/dist/dsl/trigger.d.cts +112 -0
  188. package/dist/dsl/trigger.d.cts.map +1 -0
  189. package/dist/dsl/trigger.d.mts +112 -0
  190. package/dist/dsl/trigger.d.mts.map +1 -0
  191. package/dist/dsl/trigger.mjs +52 -0
  192. package/dist/dsl/trigger.mjs.map +1 -0
  193. package/dist/dsl/workflow.cjs +143 -0
  194. package/dist/dsl/workflow.cjs.map +1 -0
  195. package/dist/dsl/workflow.d.cts +88 -0
  196. package/dist/dsl/workflow.d.cts.map +1 -0
  197. package/dist/dsl/workflow.d.mts +88 -0
  198. package/dist/dsl/workflow.d.mts.map +1 -0
  199. package/dist/dsl/workflow.mjs +142 -0
  200. package/dist/dsl/workflow.mjs.map +1 -0
  201. package/dist/email-context.cjs +28 -0
  202. package/dist/email-context.cjs.map +1 -0
  203. package/dist/email-context.d.cts +9 -0
  204. package/dist/email-context.d.cts.map +1 -0
  205. package/dist/email-context.d.mts +9 -0
  206. package/dist/email-context.d.mts.map +1 -0
  207. package/dist/email-context.mjs +26 -0
  208. package/dist/email-context.mjs.map +1 -0
  209. package/dist/email-sender.cjs +93 -0
  210. package/dist/email-sender.cjs.map +1 -0
  211. package/dist/email-sender.d.cts +88 -0
  212. package/dist/email-sender.d.cts.map +1 -0
  213. package/dist/email-sender.d.mts +88 -0
  214. package/dist/email-sender.d.mts.map +1 -0
  215. package/dist/email-sender.mjs +90 -0
  216. package/dist/email-sender.mjs.map +1 -0
  217. package/dist/email.cjs +73 -0
  218. package/dist/email.cjs.map +1 -0
  219. package/dist/email.d.cts +59 -0
  220. package/dist/email.d.cts.map +1 -0
  221. package/dist/email.d.mts +59 -0
  222. package/dist/email.d.mts.map +1 -0
  223. package/dist/email.mjs +68 -0
  224. package/dist/email.mjs.map +1 -0
  225. package/dist/engine/actions.cjs +19 -0
  226. package/dist/engine/actions.cjs.map +1 -0
  227. package/dist/engine/actions.d.cts +27 -0
  228. package/dist/engine/actions.d.cts.map +1 -0
  229. package/dist/engine/actions.d.mts +27 -0
  230. package/dist/engine/actions.d.mts.map +1 -0
  231. package/dist/engine/actions.mjs +18 -0
  232. package/dist/engine/actions.mjs.map +1 -0
  233. package/dist/engine/bucket.cjs +71 -0
  234. package/dist/engine/bucket.cjs.map +1 -0
  235. package/dist/engine/bucket.d.cts +30 -0
  236. package/dist/engine/bucket.d.cts.map +1 -0
  237. package/dist/engine/bucket.d.mts +30 -0
  238. package/dist/engine/bucket.d.mts.map +1 -0
  239. package/dist/engine/bucket.mjs +68 -0
  240. package/dist/engine/bucket.mjs.map +1 -0
  241. package/dist/engine/condition.cjs +199 -0
  242. package/dist/engine/condition.cjs.map +1 -0
  243. package/dist/engine/condition.d.cts +76 -0
  244. package/dist/engine/condition.d.cts.map +1 -0
  245. package/dist/engine/condition.d.mts +76 -0
  246. package/dist/engine/condition.d.mts.map +1 -0
  247. package/dist/engine/condition.mjs +192 -0
  248. package/dist/engine/condition.mjs.map +1 -0
  249. package/dist/engine/duration.cjs +33 -0
  250. package/dist/engine/duration.cjs.map +1 -0
  251. package/dist/engine/duration.d.cts +3 -0
  252. package/dist/engine/duration.d.cts.map +1 -0
  253. package/dist/engine/duration.d.mts +3 -0
  254. package/dist/engine/duration.d.mts.map +1 -0
  255. package/dist/engine/duration.mjs +32 -0
  256. package/dist/engine/duration.mjs.map +1 -0
  257. package/dist/engine/index.cjs +33 -0
  258. package/dist/engine/index.d.cts +10 -0
  259. package/dist/engine/index.d.mts +10 -0
  260. package/dist/engine/index.mjs +9 -0
  261. package/dist/engine/interpreter.cjs +613 -0
  262. package/dist/engine/interpreter.cjs.map +1 -0
  263. package/dist/engine/interpreter.d.cts +4 -0
  264. package/dist/engine/interpreter.d.cts.map +1 -0
  265. package/dist/engine/interpreter.d.mts +4 -0
  266. package/dist/engine/interpreter.d.mts.map +1 -0
  267. package/dist/engine/interpreter.mjs +612 -0
  268. package/dist/engine/interpreter.mjs.map +1 -0
  269. package/dist/engine/ports.cjs +0 -0
  270. package/dist/engine/ports.d.cts +373 -0
  271. package/dist/engine/ports.d.cts.map +1 -0
  272. package/dist/engine/ports.d.mts +373 -0
  273. package/dist/engine/ports.d.mts.map +1 -0
  274. package/dist/engine/ports.mjs +1 -0
  275. package/dist/engine/recipient.cjs +22 -0
  276. package/dist/engine/recipient.cjs.map +1 -0
  277. package/dist/engine/recipient.d.cts +11 -0
  278. package/dist/engine/recipient.d.cts.map +1 -0
  279. package/dist/engine/recipient.d.mts +11 -0
  280. package/dist/engine/recipient.d.mts.map +1 -0
  281. package/dist/engine/recipient.mjs +21 -0
  282. package/dist/engine/recipient.mjs.map +1 -0
  283. package/dist/engine/retry.cjs +106 -0
  284. package/dist/engine/retry.cjs.map +1 -0
  285. package/dist/engine/retry.d.cts +73 -0
  286. package/dist/engine/retry.d.cts.map +1 -0
  287. package/dist/engine/retry.d.mts +73 -0
  288. package/dist/engine/retry.d.mts.map +1 -0
  289. package/dist/engine/retry.mjs +98 -0
  290. package/dist/engine/retry.mjs.map +1 -0
  291. package/dist/engine/time-scale.cjs +153 -0
  292. package/dist/engine/time-scale.cjs.map +1 -0
  293. package/dist/engine/time-scale.d.cts +41 -0
  294. package/dist/engine/time-scale.d.cts.map +1 -0
  295. package/dist/engine/time-scale.d.mts +41 -0
  296. package/dist/engine/time-scale.d.mts.map +1 -0
  297. package/dist/engine/time-scale.mjs +150 -0
  298. package/dist/engine/time-scale.mjs.map +1 -0
  299. package/dist/engine/time-window.cjs +148 -0
  300. package/dist/engine/time-window.cjs.map +1 -0
  301. package/dist/engine/time-window.d.cts +20 -0
  302. package/dist/engine/time-window.d.cts.map +1 -0
  303. package/dist/engine/time-window.d.mts +20 -0
  304. package/dist/engine/time-window.d.mts.map +1 -0
  305. package/dist/engine/time-window.mjs +146 -0
  306. package/dist/engine/time-window.mjs.map +1 -0
  307. package/dist/fcm.cjs +208 -0
  308. package/dist/fcm.cjs.map +1 -0
  309. package/dist/fcm.d.cts +89 -0
  310. package/dist/fcm.d.cts.map +1 -0
  311. package/dist/fcm.d.mts +89 -0
  312. package/dist/fcm.d.mts.map +1 -0
  313. package/dist/fcm.mjs +202 -0
  314. package/dist/fcm.mjs.map +1 -0
  315. package/dist/hash.cjs +244 -0
  316. package/dist/hash.cjs.map +1 -0
  317. package/dist/hash.d.cts +28 -0
  318. package/dist/hash.d.cts.map +1 -0
  319. package/dist/hash.d.mts +28 -0
  320. package/dist/hash.d.mts.map +1 -0
  321. package/dist/hash.mjs +238 -0
  322. package/dist/hash.mjs.map +1 -0
  323. package/dist/host/auth.cjs +48 -0
  324. package/dist/host/auth.cjs.map +1 -0
  325. package/dist/host/auth.d.cts +33 -0
  326. package/dist/host/auth.d.cts.map +1 -0
  327. package/dist/host/auth.d.mts +33 -0
  328. package/dist/host/auth.d.mts.map +1 -0
  329. package/dist/host/auth.mjs +45 -0
  330. package/dist/host/auth.mjs.map +1 -0
  331. package/dist/host/batch.cjs +178 -0
  332. package/dist/host/batch.cjs.map +1 -0
  333. package/dist/host/batch.d.cts +92 -0
  334. package/dist/host/batch.d.cts.map +1 -0
  335. package/dist/host/batch.d.mts +92 -0
  336. package/dist/host/batch.d.mts.map +1 -0
  337. package/dist/host/batch.mjs +169 -0
  338. package/dist/host/batch.mjs.map +1 -0
  339. package/dist/host/channels.cjs +256 -0
  340. package/dist/host/channels.cjs.map +1 -0
  341. package/dist/host/channels.d.cts +66 -0
  342. package/dist/host/channels.d.cts.map +1 -0
  343. package/dist/host/channels.d.mts +66 -0
  344. package/dist/host/channels.d.mts.map +1 -0
  345. package/dist/host/channels.mjs +252 -0
  346. package/dist/host/channels.mjs.map +1 -0
  347. package/dist/host/execute.cjs +102 -0
  348. package/dist/host/execute.cjs.map +1 -0
  349. package/dist/host/execute.d.cts +38 -0
  350. package/dist/host/execute.d.cts.map +1 -0
  351. package/dist/host/execute.d.mts +38 -0
  352. package/dist/host/execute.d.mts.map +1 -0
  353. package/dist/host/execute.mjs +101 -0
  354. package/dist/host/execute.mjs.map +1 -0
  355. package/dist/host/fresh-read.cjs +29 -0
  356. package/dist/host/fresh-read.cjs.map +1 -0
  357. package/dist/host/fresh-read.d.cts +16 -0
  358. package/dist/host/fresh-read.d.cts.map +1 -0
  359. package/dist/host/fresh-read.d.mts +16 -0
  360. package/dist/host/fresh-read.d.mts.map +1 -0
  361. package/dist/host/fresh-read.mjs +28 -0
  362. package/dist/host/fresh-read.mjs.map +1 -0
  363. package/dist/host/http.cjs +393 -0
  364. package/dist/host/http.cjs.map +1 -0
  365. package/dist/host/http.d.cts +61 -0
  366. package/dist/host/http.d.cts.map +1 -0
  367. package/dist/host/http.d.mts +61 -0
  368. package/dist/host/http.d.mts.map +1 -0
  369. package/dist/host/http.mjs +389 -0
  370. package/dist/host/http.mjs.map +1 -0
  371. package/dist/host/ingest.cjs +1210 -0
  372. package/dist/host/ingest.cjs.map +1 -0
  373. package/dist/host/ingest.d.cts +497 -0
  374. package/dist/host/ingest.d.cts.map +1 -0
  375. package/dist/host/ingest.d.mts +497 -0
  376. package/dist/host/ingest.d.mts.map +1 -0
  377. package/dist/host/ingest.mjs +1172 -0
  378. package/dist/host/ingest.mjs.map +1 -0
  379. package/dist/host/journey-host.cjs +223 -0
  380. package/dist/host/journey-host.cjs.map +1 -0
  381. package/dist/host/journey-host.d.cts +118 -0
  382. package/dist/host/journey-host.d.cts.map +1 -0
  383. package/dist/host/journey-host.d.mts +118 -0
  384. package/dist/host/journey-host.d.mts.map +1 -0
  385. package/dist/host/journey-host.mjs +219 -0
  386. package/dist/host/journey-host.mjs.map +1 -0
  387. package/dist/host/platform.cjs +20 -0
  388. package/dist/host/platform.cjs.map +1 -0
  389. package/dist/host/platform.d.cts +120 -0
  390. package/dist/host/platform.d.cts.map +1 -0
  391. package/dist/host/platform.d.mts +120 -0
  392. package/dist/host/platform.d.mts.map +1 -0
  393. package/dist/host/platform.mjs +18 -0
  394. package/dist/host/platform.mjs.map +1 -0
  395. package/dist/host/senders.cjs +71 -0
  396. package/dist/host/senders.cjs.map +1 -0
  397. package/dist/host/senders.d.cts +34 -0
  398. package/dist/host/senders.d.cts.map +1 -0
  399. package/dist/host/senders.d.mts +34 -0
  400. package/dist/host/senders.d.mts.map +1 -0
  401. package/dist/host/senders.mjs +67 -0
  402. package/dist/host/senders.mjs.map +1 -0
  403. package/dist/host/workflow-cache.cjs +47 -0
  404. package/dist/host/workflow-cache.cjs.map +1 -0
  405. package/dist/host/workflow-cache.d.cts +21 -0
  406. package/dist/host/workflow-cache.d.cts.map +1 -0
  407. package/dist/host/workflow-cache.d.mts +21 -0
  408. package/dist/host/workflow-cache.d.mts.map +1 -0
  409. package/dist/host/workflow-cache.mjs +46 -0
  410. package/dist/host/workflow-cache.mjs.map +1 -0
  411. package/dist/http2-client.cjs +89 -0
  412. package/dist/http2-client.cjs.map +1 -0
  413. package/dist/http2-client.d.cts +45 -0
  414. package/dist/http2-client.d.cts.map +1 -0
  415. package/dist/http2-client.d.mts +45 -0
  416. package/dist/http2-client.d.mts.map +1 -0
  417. package/dist/http2-client.mjs +87 -0
  418. package/dist/http2-client.mjs.map +1 -0
  419. package/dist/index.cjs +130 -0
  420. package/dist/index.d.cts +21 -0
  421. package/dist/index.d.mts +21 -0
  422. package/dist/index.mjs +20 -0
  423. package/dist/inflight.cjs +116 -0
  424. package/dist/inflight.cjs.map +1 -0
  425. package/dist/inflight.d.cts +49 -0
  426. package/dist/inflight.d.cts.map +1 -0
  427. package/dist/inflight.d.mts +49 -0
  428. package/dist/inflight.d.mts.map +1 -0
  429. package/dist/inflight.mjs +113 -0
  430. package/dist/inflight.mjs.map +1 -0
  431. package/dist/ir.cjs +429 -0
  432. package/dist/ir.cjs.map +1 -0
  433. package/dist/ir.d.cts +593 -0
  434. package/dist/ir.d.cts.map +1 -0
  435. package/dist/ir.d.mts +593 -0
  436. package/dist/ir.d.mts.map +1 -0
  437. package/dist/ir.mjs +404 -0
  438. package/dist/ir.mjs.map +1 -0
  439. package/dist/jwt.cjs +17 -0
  440. package/dist/jwt.cjs.map +1 -0
  441. package/dist/jwt.d.cts +7 -0
  442. package/dist/jwt.d.cts.map +1 -0
  443. package/dist/jwt.d.mts +7 -0
  444. package/dist/jwt.d.mts.map +1 -0
  445. package/dist/jwt.mjs +15 -0
  446. package/dist/jwt.mjs.map +1 -0
  447. package/dist/node/index.cjs +231 -0
  448. package/dist/node/index.cjs.map +1 -0
  449. package/dist/node/index.d.cts +59 -0
  450. package/dist/node/index.d.cts.map +1 -0
  451. package/dist/node/index.d.mts +59 -0
  452. package/dist/node/index.d.mts.map +1 -0
  453. package/dist/node/index.mjs +225 -0
  454. package/dist/node/index.mjs.map +1 -0
  455. package/dist/node/runs.cjs +222 -0
  456. package/dist/node/runs.cjs.map +1 -0
  457. package/dist/node/runs.d.cts +93 -0
  458. package/dist/node/runs.d.cts.map +1 -0
  459. package/dist/node/runs.d.mts +93 -0
  460. package/dist/node/runs.d.mts.map +1 -0
  461. package/dist/node/runs.mjs +221 -0
  462. package/dist/node/runs.mjs.map +1 -0
  463. package/dist/node/runtime.cjs +351 -0
  464. package/dist/node/runtime.cjs.map +1 -0
  465. package/dist/node/runtime.d.cts +96 -0
  466. package/dist/node/runtime.d.cts.map +1 -0
  467. package/dist/node/runtime.d.mts +96 -0
  468. package/dist/node/runtime.d.mts.map +1 -0
  469. package/dist/node/runtime.mjs +348 -0
  470. package/dist/node/runtime.mjs.map +1 -0
  471. package/dist/plan.cjs +221 -0
  472. package/dist/plan.cjs.map +1 -0
  473. package/dist/plan.d.cts +68 -0
  474. package/dist/plan.d.cts.map +1 -0
  475. package/dist/plan.d.mts +68 -0
  476. package/dist/plan.d.mts.map +1 -0
  477. package/dist/plan.mjs +218 -0
  478. package/dist/plan.mjs.map +1 -0
  479. package/dist/postgres-js.cjs +51 -0
  480. package/dist/postgres-js.cjs.map +1 -0
  481. package/dist/postgres-js.d.cts +32 -0
  482. package/dist/postgres-js.d.cts.map +1 -0
  483. package/dist/postgres-js.d.mts +32 -0
  484. package/dist/postgres-js.d.mts.map +1 -0
  485. package/dist/postgres-js.mjs +46 -0
  486. package/dist/postgres-js.mjs.map +1 -0
  487. package/dist/provenance.cjs +66 -0
  488. package/dist/provenance.cjs.map +1 -0
  489. package/dist/provenance.d.cts +40 -0
  490. package/dist/provenance.d.cts.map +1 -0
  491. package/dist/provenance.d.mts +40 -0
  492. package/dist/provenance.d.mts.map +1 -0
  493. package/dist/provenance.mjs +64 -0
  494. package/dist/provenance.mjs.map +1 -0
  495. package/dist/push.cjs +11 -0
  496. package/dist/push.cjs.map +1 -0
  497. package/dist/push.d.cts +14 -0
  498. package/dist/push.d.cts.map +1 -0
  499. package/dist/push.d.mts +14 -0
  500. package/dist/push.d.mts.map +1 -0
  501. package/dist/push.mjs +10 -0
  502. package/dist/push.mjs.map +1 -0
  503. package/dist/react-email.cjs +56 -0
  504. package/dist/react-email.cjs.map +1 -0
  505. package/dist/react-email.d.cts +5 -0
  506. package/dist/react-email.d.cts.map +1 -0
  507. package/dist/react-email.d.mts +5 -0
  508. package/dist/react-email.d.mts.map +1 -0
  509. package/dist/react-email.mjs +55 -0
  510. package/dist/react-email.mjs.map +1 -0
  511. package/dist/reporting/classify.cjs +46 -0
  512. package/dist/reporting/classify.cjs.map +1 -0
  513. package/dist/reporting/classify.d.cts +65 -0
  514. package/dist/reporting/classify.d.cts.map +1 -0
  515. package/dist/reporting/classify.d.mts +65 -0
  516. package/dist/reporting/classify.d.mts.map +1 -0
  517. package/dist/reporting/classify.mjs +42 -0
  518. package/dist/reporting/classify.mjs.map +1 -0
  519. package/dist/reporting/observer.cjs +137 -0
  520. package/dist/reporting/observer.cjs.map +1 -0
  521. package/dist/reporting/observer.d.cts +31 -0
  522. package/dist/reporting/observer.d.cts.map +1 -0
  523. package/dist/reporting/observer.d.mts +31 -0
  524. package/dist/reporting/observer.d.mts.map +1 -0
  525. package/dist/reporting/observer.mjs +134 -0
  526. package/dist/reporting/observer.mjs.map +1 -0
  527. package/dist/reporting/tracking.cjs +185 -0
  528. package/dist/reporting/tracking.cjs.map +1 -0
  529. package/dist/reporting/tracking.d.cts +63 -0
  530. package/dist/reporting/tracking.d.cts.map +1 -0
  531. package/dist/reporting/tracking.d.mts +63 -0
  532. package/dist/reporting/tracking.d.mts.map +1 -0
  533. package/dist/reporting/tracking.mjs +182 -0
  534. package/dist/reporting/tracking.mjs.map +1 -0
  535. package/dist/runtime.cjs +18 -0
  536. package/dist/runtime.cjs.map +1 -0
  537. package/dist/runtime.d.cts +44 -0
  538. package/dist/runtime.d.cts.map +1 -0
  539. package/dist/runtime.d.mts +44 -0
  540. package/dist/runtime.d.mts.map +1 -0
  541. package/dist/runtime.mjs +17 -0
  542. package/dist/runtime.mjs.map +1 -0
  543. package/dist/store/condition-sql.cjs +145 -0
  544. package/dist/store/condition-sql.cjs.map +1 -0
  545. package/dist/store/condition-sql.d.cts +38 -0
  546. package/dist/store/condition-sql.d.cts.map +1 -0
  547. package/dist/store/condition-sql.d.mts +38 -0
  548. package/dist/store/condition-sql.d.mts.map +1 -0
  549. package/dist/store/condition-sql.mjs +144 -0
  550. package/dist/store/condition-sql.mjs.map +1 -0
  551. package/dist/store/erasure.cjs +21 -0
  552. package/dist/store/erasure.cjs.map +1 -0
  553. package/dist/store/erasure.d.cts +16 -0
  554. package/dist/store/erasure.d.cts.map +1 -0
  555. package/dist/store/erasure.d.mts +16 -0
  556. package/dist/store/erasure.d.mts.map +1 -0
  557. package/dist/store/erasure.mjs +20 -0
  558. package/dist/store/erasure.mjs.map +1 -0
  559. package/dist/store/facts.cjs +79 -0
  560. package/dist/store/facts.cjs.map +1 -0
  561. package/dist/store/facts.d.cts +41 -0
  562. package/dist/store/facts.d.cts.map +1 -0
  563. package/dist/store/facts.d.mts +41 -0
  564. package/dist/store/facts.d.mts.map +1 -0
  565. package/dist/store/facts.mjs +77 -0
  566. package/dist/store/facts.mjs.map +1 -0
  567. package/dist/store/identity.cjs +34 -0
  568. package/dist/store/identity.cjs.map +1 -0
  569. package/dist/store/identity.d.cts +13 -0
  570. package/dist/store/identity.d.cts.map +1 -0
  571. package/dist/store/identity.d.mts +13 -0
  572. package/dist/store/identity.d.mts.map +1 -0
  573. package/dist/store/identity.mjs +30 -0
  574. package/dist/store/identity.mjs.map +1 -0
  575. package/dist/store/index.cjs +35 -0
  576. package/dist/store/index.cjs.map +1 -0
  577. package/dist/store/index.d.cts +766 -0
  578. package/dist/store/index.d.cts.map +1 -0
  579. package/dist/store/index.d.mts +766 -0
  580. package/dist/store/index.d.mts.map +1 -0
  581. package/dist/store/index.mjs +22 -0
  582. package/dist/store/index.mjs.map +1 -0
  583. package/dist/store/postgres-reporting.cjs +327 -0
  584. package/dist/store/postgres-reporting.cjs.map +1 -0
  585. package/dist/store/postgres-reporting.d.cts +95 -0
  586. package/dist/store/postgres-reporting.d.cts.map +1 -0
  587. package/dist/store/postgres-reporting.d.mts +95 -0
  588. package/dist/store/postgres-reporting.d.mts.map +1 -0
  589. package/dist/store/postgres-reporting.mjs +326 -0
  590. package/dist/store/postgres-reporting.mjs.map +1 -0
  591. package/dist/store/postgres.cjs +1173 -0
  592. package/dist/store/postgres.cjs.map +1 -0
  593. package/dist/store/postgres.d.cts +199 -0
  594. package/dist/store/postgres.d.cts.map +1 -0
  595. package/dist/store/postgres.d.mts +199 -0
  596. package/dist/store/postgres.d.mts.map +1 -0
  597. package/dist/store/postgres.mjs +1170 -0
  598. package/dist/store/postgres.mjs.map +1 -0
  599. package/dist/store/sql.cjs +24 -0
  600. package/dist/store/sql.cjs.map +1 -0
  601. package/dist/store/sql.d.cts +26 -0
  602. package/dist/store/sql.d.cts.map +1 -0
  603. package/dist/store/sql.d.mts +26 -0
  604. package/dist/store/sql.d.mts.map +1 -0
  605. package/dist/store/sql.mjs +23 -0
  606. package/dist/store/sql.mjs.map +1 -0
  607. package/dist/store/tables.cjs +660 -0
  608. package/dist/store/tables.cjs.map +1 -0
  609. package/dist/store/tables.d.cts +103 -0
  610. package/dist/store/tables.d.cts.map +1 -0
  611. package/dist/store/tables.d.mts +103 -0
  612. package/dist/store/tables.d.mts.map +1 -0
  613. package/dist/store/tables.mjs +653 -0
  614. package/dist/store/tables.mjs.map +1 -0
  615. package/dist/store/user-lock.cjs +42 -0
  616. package/dist/store/user-lock.cjs.map +1 -0
  617. package/dist/store/user-lock.d.cts +30 -0
  618. package/dist/store/user-lock.d.cts.map +1 -0
  619. package/dist/store/user-lock.d.mts +30 -0
  620. package/dist/store/user-lock.d.mts.map +1 -0
  621. package/dist/store/user-lock.mjs +39 -0
  622. package/dist/store/user-lock.mjs.map +1 -0
  623. package/dist/template-rules.cjs +94 -0
  624. package/dist/template-rules.cjs.map +1 -0
  625. package/dist/template-rules.d.cts +80 -0
  626. package/dist/template-rules.d.cts.map +1 -0
  627. package/dist/template-rules.d.mts +80 -0
  628. package/dist/template-rules.d.mts.map +1 -0
  629. package/dist/template-rules.mjs +86 -0
  630. package/dist/template-rules.mjs.map +1 -0
  631. package/dist/templates.cjs +375 -0
  632. package/dist/templates.cjs.map +1 -0
  633. package/dist/templates.d.cts +358 -0
  634. package/dist/templates.d.cts.map +1 -0
  635. package/dist/templates.d.mts +358 -0
  636. package/dist/templates.d.mts.map +1 -0
  637. package/dist/templates.mjs +353 -0
  638. package/dist/templates.mjs.map +1 -0
  639. package/dist/transports/cloudflare-email.cjs +69 -0
  640. package/dist/transports/cloudflare-email.cjs.map +1 -0
  641. package/dist/transports/cloudflare-email.d.cts +63 -0
  642. package/dist/transports/cloudflare-email.d.cts.map +1 -0
  643. package/dist/transports/cloudflare-email.d.mts +63 -0
  644. package/dist/transports/cloudflare-email.d.mts.map +1 -0
  645. package/dist/transports/cloudflare-email.mjs +67 -0
  646. package/dist/transports/cloudflare-email.mjs.map +1 -0
  647. package/dist/transports/ses.cjs +142 -0
  648. package/dist/transports/ses.cjs.map +1 -0
  649. package/dist/transports/ses.d.cts +49 -0
  650. package/dist/transports/ses.d.cts.map +1 -0
  651. package/dist/transports/ses.d.mts +49 -0
  652. package/dist/transports/ses.d.mts.map +1 -0
  653. package/dist/transports/ses.mjs +139 -0
  654. package/dist/transports/ses.mjs.map +1 -0
  655. package/dist/transports/sigv4.cjs +86 -0
  656. package/dist/transports/sigv4.cjs.map +1 -0
  657. package/dist/transports/sigv4.d.cts +25 -0
  658. package/dist/transports/sigv4.d.cts.map +1 -0
  659. package/dist/transports/sigv4.d.mts +25 -0
  660. package/dist/transports/sigv4.d.mts.map +1 -0
  661. package/dist/transports/sigv4.mjs +85 -0
  662. package/dist/transports/sigv4.mjs.map +1 -0
  663. package/dist/webhooks.cjs +97 -0
  664. package/dist/webhooks.cjs.map +1 -0
  665. package/dist/webhooks.d.cts +23 -0
  666. package/dist/webhooks.d.cts.map +1 -0
  667. package/dist/webhooks.d.mts +23 -0
  668. package/dist/webhooks.d.mts.map +1 -0
  669. package/dist/webhooks.mjs +95 -0
  670. package/dist/webhooks.mjs.map +1 -0
  671. package/dist/webpush.cjs +361 -0
  672. package/dist/webpush.cjs.map +1 -0
  673. package/dist/webpush.d.cts +135 -0
  674. package/dist/webpush.d.cts.map +1 -0
  675. package/dist/webpush.d.mts +135 -0
  676. package/dist/webpush.d.mts.map +1 -0
  677. package/dist/webpush.mjs +350 -0
  678. package/dist/webpush.mjs.map +1 -0
  679. package/package.json +279 -3
  680. package/src/cloudflare/workers.d.ts +44 -0
@@ -0,0 +1,38 @@
1
+ import { ConditionIR } from "../ir.mjs";
2
+ /**
3
+ * A condition as one SQL boolean over a whole set of users, for the segment sweep: where
4
+ * `engine/condition.ts` asks about one user in several round trips, this asks about all of them
5
+ * in one statement.
6
+ *
7
+ * `engine/condition.ts` stays the authority, and this only narrows down who it has to look at.
8
+ * So the result is three-valued: TRUE and FALSE state what the evaluator would answer, and NULL
9
+ * means "ask the evaluator". SQL's AND, OR and NOT carry a NULL exactly as far as it can affect
10
+ * the outcome, so a leaf that cannot match JavaScript's semantics returns NULL and nothing above
11
+ * it has to know. That covers what SQL has no clean form for: a comparison across types (`'5' > 3`
12
+ * coerces in JavaScript), a segment that is unknown or reaches itself (the evaluator throws, and
13
+ * its error is the one to report), hand-built IR.
14
+ *
15
+ * Injection: nothing from the condition is ever written into the statement. Every name, path and
16
+ * value goes through `bind`, as does the clock; the only other text is this file's own SQL, the
17
+ * store's table names and a count checked to be an integer. Keep it that way: a segment id or a
18
+ * property path is data, however trusted the bundle that carries it.
19
+ */
20
+ export interface ConditionSqlContext {
21
+ /** The qualified tables the condition reads. */
22
+ tables: {
23
+ event: string;
24
+ suppression: string;
25
+ device: string;
26
+ };
27
+ /** The column holding the user id. */
28
+ user: string;
29
+ /** The column holding the user's profile props, NULL when there is no profile. */
30
+ props: string;
31
+ nowMs: number;
32
+ /** Every deployed segment, for `segment(...)` references. */
33
+ segments: ReadonlyMap<string, ConditionIR>;
34
+ /** Registers a parameter and returns its placeholder (`$3`). */
35
+ bind(value: unknown): string;
36
+ }
37
+ export declare function conditionToSql(condition: ConditionIR, context: ConditionSqlContext): string;
38
+ //# sourceMappingURL=condition-sql.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"condition-sql.d.mts","names":[],"sources":["../../src/store/condition-sql.ts"],"mappings":";;;;;;;;;;;;;;;;;;;iBAuBiB;;EAEf;IAAU;IAAe;IAAqB;;;EAE9C;;EAEA;EACA;;EAEA,UAAU,oBAAoB;;EAE9B,KAAK;;wBAQS,eAAe,WAAW,aAAa,SAAS"}
@@ -0,0 +1,144 @@
1
+ import { RECIPIENT_PROPERTY } from "../engine/recipient.mjs";
2
+ import "./facts.mjs";
3
+ // src/store/condition-sql.ts
4
+ const UNKNOWN = "NULL::boolean";
5
+ /** `to_timestamp`, as every other read of `ts` in the store writes it. */
6
+ const timestamp = (param) => `to_timestamp(${param}::double precision / 1000)`;
7
+ function conditionToSql(condition, context) {
8
+ if (JSON.stringify(condition).includes("\\u0000")) return UNKNOWN;
9
+ return compile(condition, context, []);
10
+ }
11
+ function compile(condition, context, enclosing) {
12
+ switch (condition.type) {
13
+ case "and": return join(condition.conditions.map((child) => compile(child, context, enclosing)), "AND", "TRUE");
14
+ case "or": return join(condition.conditions.map((child) => compile(child, context, enclosing)), "OR", "FALSE");
15
+ case "not": return `(NOT ${compile(condition.condition, context, enclosing)})`;
16
+ case "segment": {
17
+ const definition = context.segments.get(condition.segment);
18
+ if (definition === void 0 || enclosing.includes(condition.segment)) return UNKNOWN;
19
+ return compile(definition, context, [...enclosing, condition.segment]);
20
+ }
21
+ case "performed": return performed(condition, context);
22
+ case "property": return compare(condition, once(() => profileScalar(condition.path, context)), context);
23
+ case "reachable": return reachable(condition.channel, context);
24
+ case "payload":
25
+ case "trigger_payload": return UNKNOWN;
26
+ }
27
+ }
28
+ function once(make) {
29
+ let made;
30
+ return () => made ??= make();
31
+ }
32
+ function join(parts, operator, empty) {
33
+ return parts.length === 0 ? empty : `(${parts.join(` ${operator} `)})`;
34
+ }
35
+ /** Mirrors `JourneyFactSource.countEvents`: the window's bounds are inclusive at both ends. */
36
+ function performed(condition, context) {
37
+ const atLeast = Math.ceil(condition.count ?? 1);
38
+ if (!Number.isSafeInteger(atLeast)) return UNKNOWN;
39
+ if (atLeast <= 0) return "TRUE";
40
+ const since = condition.within === void 0 ? void 0 : context.nowMs - condition.within.ms;
41
+ if (since !== void 0 && !Number.isFinite(since)) return UNKNOWN;
42
+ let events = `SELECT 1 FROM ${context.tables.event} ev WHERE ev.user_id = ${context.user} AND ev.name = ${context.bind(condition.event)}::text`;
43
+ if (since !== void 0) events += ` AND ev.ts >= ${timestamp(context.bind(since))}`;
44
+ if (condition.where === void 0) return reaches(events, atLeast);
45
+ const where = whereToSql(condition.where, context);
46
+ return `(CASE WHEN ${reaches(`${events} AND (${where}) IS TRUE`, atLeast)} THEN TRUE WHEN ${reaches(`${events} AND (${where}) IS NOT FALSE`, atLeast)} THEN ${UNKNOWN} ELSE FALSE END)`;
47
+ }
48
+ /** Whether a query yields `atLeast` rows, stopping there: the (user_id, name, ts) index serves it. */
49
+ function reaches(query, atLeast) {
50
+ return atLeast === 1 ? `EXISTS (${query})` : `((SELECT count(*) FROM (${query} LIMIT ${String(atLeast)}) capped) >= ${String(atLeast)})`;
51
+ }
52
+ /** Mirrors `matchesWhere`, over the event row `ev`. */
53
+ function whereToSql(where, context) {
54
+ switch (where.type) {
55
+ case "and": return join(where.conditions.map((child) => whereToSql(child, context)), "AND", "TRUE");
56
+ case "or": return join(where.conditions.map((child) => whereToSql(child, context)), "OR", "FALSE");
57
+ case "not": return `(NOT ${whereToSql(where.condition, context)})`;
58
+ case "payload": {
59
+ const keys = where.path.split(".");
60
+ if (!keys.every(isPlainKey)) return UNKNOWN;
61
+ const raw = once(() => keys.reduce((json, key) => `${json} -> ${context.bind(key)}::text`, "ev.payload"));
62
+ const present = () => `(jsonb_typeof(${raw()}) IS DISTINCT FROM 'null' AND ${raw()} IS NOT NULL)`;
63
+ if (where.op === "exists") return present();
64
+ if (where.op === "not_exists") return `(NOT ${present()})`;
65
+ return compare(where, once(() => scalarOf(raw())), context);
66
+ }
67
+ default: return UNKNOWN;
68
+ }
69
+ }
70
+ /**
71
+ * A key `valueAtPath` finds in plain JSON objects only. It indexes with `current[key]`, so a
72
+ * number reaches into an array, `length` reads an array's size and `toString` finds the prototype,
73
+ * none of which `->` does.
74
+ */
75
+ function isPlainKey(key) {
76
+ return !/^\d+$/.test(key) && key !== "length" && !(key in Object.prototype);
77
+ }
78
+ /** The value if it is a JSON scalar, SQL NULL otherwise: a non-scalar reads as absent. */
79
+ function scalarOf(json) {
80
+ return `(CASE WHEN jsonb_typeof(${json}) IN ('string', 'number', 'boolean') THEN ${json} END)`;
81
+ }
82
+ /** Mirrors `JourneyFactSource.getProperty`. */
83
+ function profileScalar(path, context) {
84
+ if (path === "userId") return `to_jsonb(${context.user})`;
85
+ return scalarOf(`${context.props} -> ${context.bind(path)}::text`);
86
+ }
87
+ function reachable(channel, context) {
88
+ const suppressed = `EXISTS (SELECT 1 FROM ${context.tables.suppression} s WHERE s.user_id = ${context.user} AND s.channel = ${context.bind(channel)}::text AND s.topic IS NULL)`;
89
+ let address;
90
+ if (channel === "push") address = `EXISTS (SELECT 1 FROM ${context.tables.device} d WHERE d.user_id = ${context.user})`;
91
+ else {
92
+ const path = RECIPIENT_PROPERTY[channel];
93
+ address = path === void 0 ? "TRUE" : `${profileScalar(path, context)} IS NOT NULL`;
94
+ }
95
+ return `(NOT ${suppressed} AND ${address})`;
96
+ }
97
+ /**
98
+ * Mirrors `compareProperty`. `actual` yields a jsonb scalar, or SQL NULL for "undefined". It is
99
+ * asked for only by a branch that uses it: Postgres cannot type a parameter no statement mentions,
100
+ * so an operator that needs no value (`between` without a range) must not bind one.
101
+ */
102
+ function compare(condition, actual, context) {
103
+ const { value, values } = condition;
104
+ const json = (scalar) => `${context.bind(JSON.stringify(scalar))}::text::jsonb`;
105
+ const isIn = () => (values ?? []).length === 0 ? "FALSE" : `COALESCE(${actual()} IN (${(values ?? []).map(json).join(", ")}), FALSE)`;
106
+ const isBetween = () => {
107
+ if (values === void 0 || values.length < 2) return "FALSE";
108
+ const [min, max] = values;
109
+ return `(${order(actual, ">=", min, context)} AND ${order(actual, "<=", max, context)})`;
110
+ };
111
+ const contains = () => typeof value === "string" ? `COALESCE(jsonb_typeof(${actual()}) = 'string' AND strpos(${actual()} #>> '{}', ${context.bind(value)}::text) > 0, FALSE)` : "FALSE";
112
+ switch (condition.op) {
113
+ case "exists": return `(${actual()} IS NOT NULL)`;
114
+ case "not_exists": return `(${actual()} IS NULL)`;
115
+ case "eq": return value === void 0 ? `(${actual()} IS NULL)` : `COALESCE(${actual()} = ${json(value)}, FALSE)`;
116
+ case "ne": return value === void 0 ? `(${actual()} IS NOT NULL)` : `(${actual()} IS DISTINCT FROM ${json(value)})`;
117
+ case "gt": return order(actual, ">", value, context);
118
+ case "gte": return order(actual, ">=", value, context);
119
+ case "lt": return order(actual, "<", value, context);
120
+ case "lte": return order(actual, "<=", value, context);
121
+ case "between": return isBetween();
122
+ case "not_between": return `(NOT ${isBetween()})`;
123
+ case "in_array": return isIn();
124
+ case "not_in_array": return `(NOT ${isIn()})`;
125
+ case "contains": return contains();
126
+ case "not_contains": return `(NOT ${contains()})`;
127
+ }
128
+ }
129
+ /**
130
+ * An ordering of two values of one type; across types JavaScript coerces, so that is the
131
+ * evaluator's to answer. Strings compare by code point, what `COLLATE "C"` does on UTF-8: JavaScript
132
+ * compares UTF-16 units, which differs only between an astral character and U+E000 to U+FFFF.
133
+ */
134
+ function order(scalar, operator, value, context) {
135
+ if (value === void 0) return "FALSE";
136
+ const actual = scalar();
137
+ let same = UNKNOWN;
138
+ if (typeof value === "number" && Number.isFinite(value)) same = `(CASE WHEN jsonb_typeof(${actual}) = 'number' THEN (${actual})::numeric ${operator} ${`${context.bind(String(value))}::text::numeric`} END)`;
139
+ else if (typeof value === "string") same = `(CASE WHEN jsonb_typeof(${actual}) = 'string' THEN (${actual} #>> '{}') COLLATE "C" ${operator} ${`${context.bind(value)}::text`} END)`;
140
+ return `(CASE WHEN ${actual} IS NULL THEN FALSE ELSE ${same} END)`;
141
+ }
142
+ export { conditionToSql };
143
+
144
+ //# sourceMappingURL=condition-sql.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"condition-sql.mjs","names":[],"sources":["../../src/store/condition-sql.ts"],"sourcesContent":["import { RECIPIENT_PROPERTY } from '../engine/recipient';\nimport type { ConditionIR, PropertyOperatorIR, ScalarIR } from '../ir';\nimport { USER_ID_PROPERTY } from './facts';\n\n/**\n * A condition as one SQL boolean over a whole set of users, for the segment sweep: where\n * `engine/condition.ts` asks about one user in several round trips, this asks about all of them\n * in one statement.\n *\n * `engine/condition.ts` stays the authority, and this only narrows down who it has to look at.\n * So the result is three-valued: TRUE and FALSE state what the evaluator would answer, and NULL\n * means \"ask the evaluator\". SQL's AND, OR and NOT carry a NULL exactly as far as it can affect\n * the outcome, so a leaf that cannot match JavaScript's semantics returns NULL and nothing above\n * it has to know. That covers what SQL has no clean form for: a comparison across types (`'5' > 3`\n * coerces in JavaScript), a segment that is unknown or reaches itself (the evaluator throws, and\n * its error is the one to report), hand-built IR.\n *\n * Injection: nothing from the condition is ever written into the statement. Every name, path and\n * value goes through `bind`, as does the clock; the only other text is this file's own SQL, the\n * store's table names and a count checked to be an integer. Keep it that way: a segment id or a\n * property path is data, however trusted the bundle that carries it.\n */\n\nexport interface ConditionSqlContext {\n /** The qualified tables the condition reads. */\n tables: { event: string; suppression: string; device: string };\n /** The column holding the user id. */\n user: string;\n /** The column holding the user's profile props, NULL when there is no profile. */\n props: string;\n nowMs: number;\n /** Every deployed segment, for `segment(...)` references. */\n segments: ReadonlyMap<string, ConditionIR>;\n /** Registers a parameter and returns its placeholder (`$3`). */\n bind(value: unknown): string;\n}\n\nconst UNKNOWN = 'NULL::boolean';\n\n/** `to_timestamp`, as every other read of `ts` in the store writes it. */\nconst timestamp = (param: string) => `to_timestamp(${param}::double precision / 1000)`;\n\nexport function conditionToSql(condition: ConditionIR, context: ConditionSqlContext): string {\n // Postgres refuses NUL in text and jsonb, and one bad parameter would fail the statement for\n // every segment on the page. JSON escapes it, so this sees it wherever the tree holds it.\n if (JSON.stringify(condition).includes('\\\\u0000')) return UNKNOWN;\n return compile(condition, context, []);\n}\n\nfunction compile(\n condition: ConditionIR,\n context: ConditionSqlContext,\n enclosing: readonly string[]\n): string {\n switch (condition.type) {\n case 'and':\n return join(\n condition.conditions.map((child) => compile(child, context, enclosing)),\n 'AND',\n 'TRUE'\n );\n case 'or':\n return join(\n condition.conditions.map((child) => compile(child, context, enclosing)),\n 'OR',\n 'FALSE'\n );\n case 'not':\n return `(NOT ${compile(condition.condition, context, enclosing)})`;\n case 'segment': {\n const definition = context.segments.get(condition.segment);\n if (definition === undefined || enclosing.includes(condition.segment)) return UNKNOWN;\n return compile(definition, context, [...enclosing, condition.segment]);\n }\n case 'performed':\n return performed(condition, context);\n case 'property':\n return compare(\n condition,\n once(() => profileScalar(condition.path, context)),\n context\n );\n case 'reachable':\n return reachable(condition.channel, context);\n case 'payload':\n case 'trigger_payload':\n // The evaluator rejects both here: a payload condition outside a where clause, and a\n // trigger payload condition where there is no journey\n return UNKNOWN;\n }\n}\n\nfunction once(make: () => string): () => string {\n let made: string | undefined;\n return () => (made ??= make());\n}\n\nfunction join(parts: string[], operator: 'AND' | 'OR', empty: string): string {\n return parts.length === 0 ? empty : `(${parts.join(` ${operator} `)})`;\n}\n\n/** Mirrors `JourneyFactSource.countEvents`: the window's bounds are inclusive at both ends. */\nfunction performed(\n condition: Extract<ConditionIR, { type: 'performed' }>,\n context: ConditionSqlContext\n): string {\n const atLeast = Math.ceil(condition.count ?? 1);\n if (!Number.isSafeInteger(atLeast)) return UNKNOWN;\n if (atLeast <= 0) return 'TRUE'; // Every count is at least zero\n const since = condition.within === undefined ? undefined : context.nowMs - condition.within.ms;\n // Before anything is bound: to_timestamp would fail the whole statement on it\n if (since !== undefined && !Number.isFinite(since)) return UNKNOWN;\n let events =\n `SELECT 1 FROM ${context.tables.event} ev ` +\n `WHERE ev.user_id = ${context.user} AND ev.name = ${context.bind(condition.event)}::text`;\n if (since !== undefined) events += ` AND ev.ts >= ${timestamp(context.bind(since))}`;\n if (condition.where === undefined) return reaches(events, atLeast);\n const where = whereToSql(condition.where, context);\n // An event the where clause cannot decide may or may not count\n const certain = reaches(`${events} AND (${where}) IS TRUE`, atLeast);\n const possible = reaches(`${events} AND (${where}) IS NOT FALSE`, atLeast);\n return `(CASE WHEN ${certain} THEN TRUE WHEN ${possible} THEN ${UNKNOWN} ELSE FALSE END)`;\n}\n\n/** Whether a query yields `atLeast` rows, stopping there: the (user_id, name, ts) index serves it. */\nfunction reaches(query: string, atLeast: number): string {\n return atLeast === 1\n ? `EXISTS (${query})`\n : `((SELECT count(*) FROM (${query} LIMIT ${String(atLeast)}) capped) >= ${String(atLeast)})`;\n}\n\n/** Mirrors `matchesWhere`, over the event row `ev`. */\nfunction whereToSql(where: ConditionIR, context: ConditionSqlContext): string {\n switch (where.type) {\n case 'and':\n return join(\n where.conditions.map((child) => whereToSql(child, context)),\n 'AND',\n 'TRUE'\n );\n case 'or':\n return join(\n where.conditions.map((child) => whereToSql(child, context)),\n 'OR',\n 'FALSE'\n );\n case 'not':\n return `(NOT ${whereToSql(where.condition, context)})`;\n case 'payload': {\n const keys = where.path.split('.');\n if (!keys.every(isPlainKey)) return UNKNOWN;\n const raw = once(() =>\n keys.reduce((json, key) => `${json} -> ${context.bind(key)}::text`, 'ev.payload')\n );\n // Unlike a comparison, exists sees objects and arrays too; only JSON null reads as missing\n const present = () =>\n `(jsonb_typeof(${raw()}) IS DISTINCT FROM 'null' AND ${raw()} IS NOT NULL)`;\n if (where.op === 'exists') return present();\n if (where.op === 'not_exists') return `(NOT ${present()})`;\n return compare(\n where,\n once(() => scalarOf(raw())),\n context\n );\n }\n default:\n // Compile rejects these, and the evaluator throws on hand-built IR\n return UNKNOWN;\n }\n}\n\n/**\n * A key `valueAtPath` finds in plain JSON objects only. It indexes with `current[key]`, so a\n * number reaches into an array, `length` reads an array's size and `toString` finds the prototype,\n * none of which `->` does.\n */\nfunction isPlainKey(key: string): boolean {\n return !/^\\d+$/.test(key) && key !== 'length' && !(key in Object.prototype);\n}\n\n/** The value if it is a JSON scalar, SQL NULL otherwise: a non-scalar reads as absent. */\nfunction scalarOf(json: string): string {\n return `(CASE WHEN jsonb_typeof(${json}) IN ('string', 'number', 'boolean') THEN ${json} END)`;\n}\n\n/** Mirrors `JourneyFactSource.getProperty`. */\nfunction profileScalar(path: string, context: ConditionSqlContext): string {\n if (path === USER_ID_PROPERTY) return `to_jsonb(${context.user})`;\n return scalarOf(`${context.props} -> ${context.bind(path)}::text`);\n}\n\nfunction reachable(\n channel: Extract<ConditionIR, { type: 'reachable' }>['channel'],\n context: ConditionSqlContext\n): string {\n // The channel-wide opt-out only, as in the evaluator: its row has no topic\n const suppressed =\n `EXISTS (SELECT 1 FROM ${context.tables.suppression} s ` +\n `WHERE s.user_id = ${context.user} AND s.channel = ${context.bind(channel)}::text AND s.topic IS NULL)`;\n let address: string;\n if (channel === 'push') {\n address = `EXISTS (SELECT 1 FROM ${context.tables.device} d WHERE d.user_id = ${context.user})`;\n } else {\n const path = RECIPIENT_PROPERTY[channel];\n address = path === undefined ? 'TRUE' : `${profileScalar(path, context)} IS NOT NULL`;\n }\n return `(NOT ${suppressed} AND ${address})`;\n}\n\n/**\n * Mirrors `compareProperty`. `actual` yields a jsonb scalar, or SQL NULL for \"undefined\". It is\n * asked for only by a branch that uses it: Postgres cannot type a parameter no statement mentions,\n * so an operator that needs no value (`between` without a range) must not bind one.\n */\nfunction compare(\n condition: {\n op: PropertyOperatorIR;\n value?: ScalarIR | undefined;\n values?: ScalarIR[] | undefined;\n },\n actual: () => string,\n context: ConditionSqlContext\n): string {\n const { value, values } = condition;\n const json = (scalar: ScalarIR) => `${context.bind(JSON.stringify(scalar))}::text::jsonb`;\n const isIn = () =>\n (values ?? []).length === 0\n ? 'FALSE'\n : `COALESCE(${actual()} IN (${(values ?? []).map(json).join(', ')}), FALSE)`;\n const isBetween = () => {\n if (values === undefined || values.length < 2) return 'FALSE';\n const [min, max] = values as [ScalarIR, ScalarIR, ...ScalarIR[]];\n return `(${order(actual, '>=', min, context)} AND ${order(actual, '<=', max, context)})`;\n };\n const contains = () =>\n typeof value === 'string'\n ? `COALESCE(jsonb_typeof(${actual()}) = 'string' AND strpos(${actual()} #>> '{}', ${context.bind(value)}::text) > 0, FALSE)`\n : 'FALSE';\n switch (condition.op) {\n case 'exists':\n return `(${actual()} IS NOT NULL)`;\n case 'not_exists':\n return `(${actual()} IS NULL)`;\n case 'eq':\n return value === undefined\n ? `(${actual()} IS NULL)`\n : `COALESCE(${actual()} = ${json(value)}, FALSE)`;\n case 'ne':\n return value === undefined\n ? `(${actual()} IS NOT NULL)`\n : `(${actual()} IS DISTINCT FROM ${json(value)})`;\n case 'gt':\n return order(actual, '>', value, context);\n case 'gte':\n return order(actual, '>=', value, context);\n case 'lt':\n return order(actual, '<', value, context);\n case 'lte':\n return order(actual, '<=', value, context);\n case 'between':\n return isBetween();\n case 'not_between':\n return `(NOT ${isBetween()})`;\n case 'in_array':\n return isIn();\n case 'not_in_array':\n return `(NOT ${isIn()})`;\n case 'contains':\n return contains();\n case 'not_contains':\n return `(NOT ${contains()})`;\n }\n}\n\n/**\n * An ordering of two values of one type; across types JavaScript coerces, so that is the\n * evaluator's to answer. Strings compare by code point, what `COLLATE \"C\"` does on UTF-8: JavaScript\n * compares UTF-16 units, which differs only between an astral character and U+E000 to U+FFFF.\n */\nfunction order(\n scalar: () => string,\n operator: '>' | '>=' | '<' | '<=',\n value: ScalarIR | undefined,\n context: ConditionSqlContext\n): string {\n if (value === undefined) return 'FALSE';\n const actual = scalar();\n let same = UNKNOWN;\n if (typeof value === 'number' && Number.isFinite(value)) {\n const bound = `${context.bind(String(value))}::text::numeric`;\n same = `(CASE WHEN jsonb_typeof(${actual}) = 'number' THEN (${actual})::numeric ${operator} ${bound} END)`;\n } else if (typeof value === 'string') {\n const bound = `${context.bind(value)}::text`;\n same = `(CASE WHEN jsonb_typeof(${actual}) = 'string' THEN (${actual} #>> '{}') COLLATE \"C\" ${operator} ${bound} END)`;\n }\n return `(CASE WHEN ${actual} IS NULL THEN FALSE ELSE ${same} END)`;\n}\n"],"mappings":"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"}
@@ -0,0 +1,21 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ // src/store/erasure.ts
3
+ /**
4
+ * The user has an erasure tombstone — requested and under way, or carried out — so nothing may
5
+ * be written about them: a write that got through would come back after the erase, or bring an
6
+ * erased user back. Thrown by the store from the conditional write itself (the gate), and by the
7
+ * entry points that check first for a fast answer; the HTTP surface answers 410.
8
+ */
9
+ var UserErasedError = class extends Error {
10
+ userId;
11
+ name = "UserErasedError";
12
+ /** The tombstone is permanent: a retry meets it again. */
13
+ retryable = false;
14
+ constructor(userId) {
15
+ super(`user ${userId} is erased`);
16
+ this.userId = userId;
17
+ }
18
+ };
19
+ exports.UserErasedError = UserErasedError;
20
+
21
+ //# sourceMappingURL=erasure.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erasure.cjs","names":[],"sources":["../../src/store/erasure.ts"],"sourcesContent":["/** Where a user stands with erasure: see `JourneyStore.erasureState`. */\nexport type ErasureState = 'none' | 'erasing' | 'erased';\n\n/**\n * The user has an erasure tombstone — requested and under way, or carried out — so nothing may\n * be written about them: a write that got through would come back after the erase, or bring an\n * erased user back. Thrown by the store from the conditional write itself (the gate), and by the\n * entry points that check first for a fast answer; the HTTP surface answers 410.\n */\nexport class UserErasedError extends Error {\n override readonly name = 'UserErasedError';\n /** The tombstone is permanent: a retry meets it again. */\n readonly retryable = false;\n constructor(readonly userId: string) {\n super(`user ${userId} is erased`);\n }\n}\n"],"mappings":";;;;;;;;AASA,IAAa,kBAAb,cAAqC,MAAM;CAIpB;CAHH,OAAO;;CAEhB,YAAY;CACrB,YAAqB,QAAgB;EACnC,MAAM,QAAQ,OAAO,WAAW;EADb,KAAA,SAAA;CAErB;AACF"}
@@ -0,0 +1,16 @@
1
+ /** Where a user stands with erasure: see `JourneyStore.erasureState`. */
2
+ export type ErasureState = 'none' | 'erasing' | 'erased';
3
+ /**
4
+ * The user has an erasure tombstone — requested and under way, or carried out — so nothing may
5
+ * be written about them: a write that got through would come back after the erase, or bring an
6
+ * erased user back. Thrown by the store from the conditional write itself (the gate), and by the
7
+ * entry points that check first for a fast answer; the HTTP surface answers 410.
8
+ */
9
+ export declare class UserErasedError extends Error {
10
+ readonly userId: string;
11
+ readonly name = "UserErasedError";
12
+ /** The tombstone is permanent: a retry meets it again. */
13
+ readonly retryable = false;
14
+ constructor(userId: string);
15
+ }
16
+ //# sourceMappingURL=erasure.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erasure.d.cts","names":[],"sources":["../../src/store/erasure.ts"],"mappings":";YACY;;;;;;;qBAQC,wBAAwB;WAId;WAHH;;WAET;EACT,YAAqB"}
@@ -0,0 +1,16 @@
1
+ /** Where a user stands with erasure: see `JourneyStore.erasureState`. */
2
+ export type ErasureState = 'none' | 'erasing' | 'erased';
3
+ /**
4
+ * The user has an erasure tombstone — requested and under way, or carried out — so nothing may
5
+ * be written about them: a write that got through would come back after the erase, or bring an
6
+ * erased user back. Thrown by the store from the conditional write itself (the gate), and by the
7
+ * entry points that check first for a fast answer; the HTTP surface answers 410.
8
+ */
9
+ export declare class UserErasedError extends Error {
10
+ readonly userId: string;
11
+ readonly name = "UserErasedError";
12
+ /** The tombstone is permanent: a retry meets it again. */
13
+ readonly retryable = false;
14
+ constructor(userId: string);
15
+ }
16
+ //# sourceMappingURL=erasure.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erasure.d.mts","names":[],"sources":["../../src/store/erasure.ts"],"mappings":";YACY;;;;;;;qBAQC,wBAAwB;WAId;WAHH;;WAET;EACT,YAAqB"}
@@ -0,0 +1,20 @@
1
+ // src/store/erasure.ts
2
+ /**
3
+ * The user has an erasure tombstone — requested and under way, or carried out — so nothing may
4
+ * be written about them: a write that got through would come back after the erase, or bring an
5
+ * erased user back. Thrown by the store from the conditional write itself (the gate), and by the
6
+ * entry points that check first for a fast answer; the HTTP surface answers 410.
7
+ */
8
+ var UserErasedError = class extends Error {
9
+ userId;
10
+ name = "UserErasedError";
11
+ /** The tombstone is permanent: a retry meets it again. */
12
+ retryable = false;
13
+ constructor(userId) {
14
+ super(`user ${userId} is erased`);
15
+ this.userId = userId;
16
+ }
17
+ };
18
+ export { UserErasedError };
19
+
20
+ //# sourceMappingURL=erasure.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erasure.mjs","names":[],"sources":["../../src/store/erasure.ts"],"sourcesContent":["/** Where a user stands with erasure: see `JourneyStore.erasureState`. */\nexport type ErasureState = 'none' | 'erasing' | 'erased';\n\n/**\n * The user has an erasure tombstone — requested and under way, or carried out — so nothing may\n * be written about them: a write that got through would come back after the erase, or bring an\n * erased user back. Thrown by the store from the conditional write itself (the gate), and by the\n * entry points that check first for a fast answer; the HTTP surface answers 410.\n */\nexport class UserErasedError extends Error {\n override readonly name = 'UserErasedError';\n /** The tombstone is permanent: a retry meets it again. */\n readonly retryable = false;\n constructor(readonly userId: string) {\n super(`user ${userId} is erased`);\n }\n}\n"],"mappings":";;;;;;;AASA,IAAa,kBAAb,cAAqC,MAAM;CAIpB;CAHH,OAAO;;CAEhB,YAAY;CACrB,YAAqB,QAAgB;EACnC,MAAM,QAAQ,OAAO,WAAW;EADb,KAAA,SAAA;CAErB;AACF"}
@@ -0,0 +1,79 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_engine_condition = require("../engine/condition.cjs");
3
+ // src/store/facts.ts
4
+ /** The profile path that reads the user's own id (`u.userId`). */
5
+ const USER_ID_PROPERTY = "userId";
6
+ /** Payloads per round trip when a `where` filters events in JS. */
7
+ const PAYLOAD_PAGE = 500;
8
+ /** Single-user fact source over a JourneyStore: evaluation lives in engine/condition.ts, this only reads. */
9
+ var JourneyFactSource = class {
10
+ store;
11
+ userId;
12
+ owner;
13
+ constructor(store, userId, owner = () => Promise.resolve(userId)) {
14
+ this.store = store;
15
+ this.userId = userId;
16
+ this.owner = owner;
17
+ }
18
+ async countEvents(event, opts) {
19
+ const window = {
20
+ ...opts?.sinceMs === void 0 ? {} : { sinceMs: opts.sinceMs },
21
+ ...opts?.untilMs === void 0 ? {} : { untilMs: opts.untilMs }
22
+ };
23
+ const atLeast = opts?.atLeast;
24
+ const userId = await this.owner();
25
+ if (opts?.where === void 0) return this.store.countEvents(userId, event, window, atLeast);
26
+ const where = opts.where;
27
+ let matched = 0;
28
+ let after;
29
+ for (;;) {
30
+ const page = await this.store.pageEventPayloads(userId, event, window, {
31
+ limit: PAYLOAD_PAGE,
32
+ after
33
+ });
34
+ for (const payload of page.payloads) {
35
+ if (require_engine_condition.matchesWhere(payload, where)) matched += 1;
36
+ if (atLeast !== void 0 && matched >= atLeast) return matched;
37
+ }
38
+ if (page.next === void 0) return matched;
39
+ after = page.next;
40
+ }
41
+ }
42
+ /**
43
+ * The scalar boundary. Everything downstream — comparisons, subject
44
+ * placeholders, resolved message props — is typed ScalarIR, but nothing so
45
+ * far has checked that the stored JSON is one: /ingest validates only that
46
+ * `props` is a plain object, and the merge stores whatever nesting it is
47
+ * handed. Left unchecked, `gt(score, 3)` on `['5']` coerces its way to true
48
+ * while `eq(score, 5)` is false, and `String(recipient)` on an object
49
+ * addresses an email to `[object Object]`.
50
+ *
51
+ * So a non-scalar value reads as absent, matching how matchesWhere treats a
52
+ * non-scalar payload leaf. The port cannot say "present but not a scalar",
53
+ * and guessing at a coercion is what produced the wrong branch in the first
54
+ * place.
55
+ */
56
+ async getProperty(path) {
57
+ const userId = await this.owner();
58
+ if (path === "userId") return userId;
59
+ const props = await this.store.getProfile(userId);
60
+ if (props === void 0) return void 0;
61
+ if (!Object.hasOwn(props, path)) return void 0;
62
+ const value = props[path];
63
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
64
+ }
65
+ getSegmentCondition(name) {
66
+ return this.store.getSegmentCondition(name);
67
+ }
68
+ /** The user's opt-outs: the channel's, or with a topic that topic's as well. */
69
+ async isSuppressed(channel, topic) {
70
+ return this.store.isSuppressed(await this.owner(), channel, topic);
71
+ }
72
+ async listDevices() {
73
+ return this.store.listDevices(await this.owner());
74
+ }
75
+ };
76
+ exports.JourneyFactSource = JourneyFactSource;
77
+ exports.USER_ID_PROPERTY = USER_ID_PROPERTY;
78
+
79
+ //# sourceMappingURL=facts.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts.cjs","names":["matchesWhere"],"sources":["../../src/store/facts.ts"],"sourcesContent":["import { matchesWhere } from '../engine/condition';\nimport type { FactSource, PushDevice } from '../engine/ports';\nimport type { ConditionIR, ScalarIR } from '../ir';\nimport type { EventCursor, JourneyStore } from './index';\n\n/** The profile path that reads the user's own id (`u.userId`). */\nexport const USER_ID_PROPERTY = 'userId';\n\n/** Payloads per round trip when a `where` filters events in JS. */\nconst PAYLOAD_PAGE = 500;\n\n/** Single-user fact source over a JourneyStore: evaluation lives in engine/condition.ts, this only reads. */\nexport class JourneyFactSource implements FactSource {\n constructor(\n private readonly store: JourneyStore,\n private readonly userId: string,\n /** Who the facts are about now, for a journey that can change hands; `userId` otherwise. */\n private readonly owner: () => Promise<string> = () => Promise.resolve(userId)\n ) {}\n\n async countEvents(\n event: string,\n opts?: { sinceMs?: number; untilMs?: number; where?: ConditionIR; atLeast?: number }\n ): Promise<number> {\n const window = {\n ...(opts?.sinceMs === undefined ? {} : { sinceMs: opts.sinceMs }),\n ...(opts?.untilMs === undefined ? {} : { untilMs: opts.untilMs }),\n };\n const atLeast = opts?.atLeast;\n const userId = await this.owner();\n if (opts?.where === undefined) {\n return this.store.countEvents(userId, event, window, atLeast);\n }\n // Payload filtering stays in JS through the shared evaluator — one set of where semantics\n // with the in-memory FactSource — but a page at a time, stopping as soon as enough events\n // match. A heavy user's history is no longer loaded whole on every evaluation; only a user\n // with no match left to find is read to the end, and then in bounded pages.\n const where = opts.where;\n let matched = 0;\n let after: EventCursor | undefined;\n for (;;) {\n const page = await this.store.pageEventPayloads(userId, event, window, {\n limit: PAYLOAD_PAGE,\n after,\n });\n for (const payload of page.payloads) {\n if (matchesWhere(payload, where)) matched += 1;\n if (atLeast !== undefined && matched >= atLeast) return matched;\n }\n if (page.next === undefined) return matched;\n after = page.next;\n }\n }\n\n /**\n * The scalar boundary. Everything downstream — comparisons, subject\n * placeholders, resolved message props — is typed ScalarIR, but nothing so\n * far has checked that the stored JSON is one: /ingest validates only that\n * `props` is a plain object, and the merge stores whatever nesting it is\n * handed. Left unchecked, `gt(score, 3)` on `['5']` coerces its way to true\n * while `eq(score, 5)` is false, and `String(recipient)` on an object\n * addresses an email to `[object Object]`.\n *\n * So a non-scalar value reads as absent, matching how matchesWhere treats a\n * non-scalar payload leaf. The port cannot say \"present but not a scalar\",\n * and guessing at a coercion is what produced the wrong branch in the first\n * place.\n */\n async getProperty(path: string): Promise<ScalarIR | undefined> {\n // The system field: the request's identity, never stored in the profile (contract.user.userId)\n const userId = await this.owner();\n if (path === USER_ID_PROPERTY) return userId;\n const props: Record<string, unknown> | undefined = await this.store.getProfile(userId);\n if (props === undefined) return undefined;\n // Own keys only: `props[path]` would otherwise find Object.prototype, so\n // `exists(u.toString)` held for every user with a profile row and a subject\n // placeholder rendered native-code text into the email.\n if (!Object.hasOwn(props, path)) return undefined;\n const value = props[path];\n // An explicit null means \"unset\" and behaves as not_exists. /ingest\n // itself clears a property by removing the key (the merge drops nulls), so\n // this covers profiles written by other means — a direct SQL fixup, a\n // migration, an import.\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return value;\n }\n return undefined;\n }\n\n getSegmentCondition(name: string): Promise<ConditionIR | undefined> {\n return this.store.getSegmentCondition(name);\n }\n\n /** The user's opt-outs: the channel's, or with a topic that topic's as well. */\n async isSuppressed(channel: string, topic?: string): Promise<boolean> {\n return this.store.isSuppressed(await this.owner(), channel, topic);\n }\n\n async listDevices(): Promise<PushDevice[]> {\n return this.store.listDevices(await this.owner());\n }\n}\n"],"mappings":";;;;AAMA,MAAa,mBAAmB;;AAGhC,MAAM,eAAe;;AAGrB,IAAa,oBAAb,MAAqD;CAEhC;CACA;CAEA;CAJnB,YACmB,OACA,QAEA,cAAqC,QAAQ,QAAQ,MAAM,GAC5E;EAJiB,KAAA,QAAA;EACA,KAAA,SAAA;EAEA,KAAA,QAAA;CAChB;CAEH,MAAM,YACJ,OACA,MACiB;EACjB,MAAM,SAAS;GACb,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,KAAK,QAAQ;GAC/D,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,KAAK,QAAQ;EACjE;EACA,MAAM,UAAU,MAAM;EACtB,MAAM,SAAS,MAAM,KAAK,MAAM;EAChC,IAAI,MAAM,UAAU,KAAA,GAClB,OAAO,KAAK,MAAM,YAAY,QAAQ,OAAO,QAAQ,OAAO;EAM9D,MAAM,QAAQ,KAAK;EACnB,IAAI,UAAU;EACd,IAAI;EACJ,SAAS;GACP,MAAM,OAAO,MAAM,KAAK,MAAM,kBAAkB,QAAQ,OAAO,QAAQ;IACrE,OAAO;IACP;GACF,CAAC;GACD,KAAK,MAAM,WAAW,KAAK,UAAU;IACnC,IAAIA,yBAAAA,aAAa,SAAS,KAAK,GAAG,WAAW;IAC7C,IAAI,YAAY,KAAA,KAAa,WAAW,SAAS,OAAO;GAC1D;GACA,IAAI,KAAK,SAAS,KAAA,GAAW,OAAO;GACpC,QAAQ,KAAK;EACf;CACF;;;;;;;;;;;;;;;CAgBA,MAAM,YAAY,MAA6C;EAE7D,MAAM,SAAS,MAAM,KAAK,MAAM;EAChC,IAAI,SAAA,UAA2B,OAAO;EACtC,MAAM,QAA6C,MAAM,KAAK,MAAM,WAAW,MAAM;EACrF,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;EAIhC,IAAI,CAAC,OAAO,OAAO,OAAO,IAAI,GAAG,OAAO,KAAA;EACxC,MAAM,QAAQ,MAAM;EAKpB,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,WAC7E,OAAO;CAGX;CAEA,oBAAoB,MAAgD;EAClE,OAAO,KAAK,MAAM,oBAAoB,IAAI;CAC5C;;CAGA,MAAM,aAAa,SAAiB,OAAkC;EACpE,OAAO,KAAK,MAAM,aAAa,MAAM,KAAK,MAAM,GAAG,SAAS,KAAK;CACnE;CAEA,MAAM,cAAqC;EACzC,OAAO,KAAK,MAAM,YAAY,MAAM,KAAK,MAAM,CAAC;CAClD;AACF"}
@@ -0,0 +1,41 @@
1
+ import { FactSource, PushDevice } from "../engine/ports.cjs";
2
+ import { ConditionIR, ScalarIR } from "../ir.cjs";
3
+ import { JourneyStore } from "./index.cjs";
4
+ /** The profile path that reads the user's own id (`u.userId`). */
5
+ export declare const USER_ID_PROPERTY = "userId";
6
+ /** Single-user fact source over a JourneyStore: evaluation lives in engine/condition.ts, this only reads. */
7
+ export declare class JourneyFactSource implements FactSource {
8
+ private readonly store;
9
+ private readonly userId;
10
+ /** Who the facts are about now, for a journey that can change hands; `userId` otherwise. */
11
+ private readonly owner;
12
+ constructor(store: JourneyStore, userId: string,
13
+ /** Who the facts are about now, for a journey that can change hands; `userId` otherwise. */
14
+ owner?: () => Promise<string>);
15
+ countEvents(event: string, opts?: {
16
+ sinceMs?: number;
17
+ untilMs?: number;
18
+ where?: ConditionIR;
19
+ atLeast?: number;
20
+ }): Promise<number>;
21
+ /**
22
+ * The scalar boundary. Everything downstream — comparisons, subject
23
+ * placeholders, resolved message props — is typed ScalarIR, but nothing so
24
+ * far has checked that the stored JSON is one: /ingest validates only that
25
+ * `props` is a plain object, and the merge stores whatever nesting it is
26
+ * handed. Left unchecked, `gt(score, 3)` on `['5']` coerces its way to true
27
+ * while `eq(score, 5)` is false, and `String(recipient)` on an object
28
+ * addresses an email to `[object Object]`.
29
+ *
30
+ * So a non-scalar value reads as absent, matching how matchesWhere treats a
31
+ * non-scalar payload leaf. The port cannot say "present but not a scalar",
32
+ * and guessing at a coercion is what produced the wrong branch in the first
33
+ * place.
34
+ */
35
+ getProperty(path: string): Promise<ScalarIR | undefined>;
36
+ getSegmentCondition(name: string): Promise<ConditionIR | undefined>;
37
+ /** The user's opt-outs: the channel's, or with a topic that topic's as well. */
38
+ isSuppressed(channel: string, topic?: string): Promise<boolean>;
39
+ listDevices(): Promise<PushDevice[]>;
40
+ }
41
+ //# sourceMappingURL=facts.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts.d.cts","names":[],"sources":["../../src/store/facts.ts"],"mappings":";;;;qBAMa;;qBAMA,6BAA6B;mBAErB;mBACA;;mBAEA;EAJnB,YACmB,OAAO,cACP;;EAEA,cAAa;EAG1B,YACJ,eACA;IAAS;IAAkB;IAAkB,QAAQ;IAAa;MACjE;;;;;;;;;;;;;;;EA6CG,YAAY,eAAe,QAAQ;EAqBzC,oBAAoB,eAAe,QAAQ;;EAKrC,aAAa,iBAAiB,iBAAiB;EAI/C,eAAe,QAAQ"}
@@ -0,0 +1,41 @@
1
+ import { FactSource, PushDevice } from "../engine/ports.mjs";
2
+ import { ConditionIR, ScalarIR } from "../ir.mjs";
3
+ import { JourneyStore } from "./index.mjs";
4
+ /** The profile path that reads the user's own id (`u.userId`). */
5
+ export declare const USER_ID_PROPERTY = "userId";
6
+ /** Single-user fact source over a JourneyStore: evaluation lives in engine/condition.ts, this only reads. */
7
+ export declare class JourneyFactSource implements FactSource {
8
+ private readonly store;
9
+ private readonly userId;
10
+ /** Who the facts are about now, for a journey that can change hands; `userId` otherwise. */
11
+ private readonly owner;
12
+ constructor(store: JourneyStore, userId: string,
13
+ /** Who the facts are about now, for a journey that can change hands; `userId` otherwise. */
14
+ owner?: () => Promise<string>);
15
+ countEvents(event: string, opts?: {
16
+ sinceMs?: number;
17
+ untilMs?: number;
18
+ where?: ConditionIR;
19
+ atLeast?: number;
20
+ }): Promise<number>;
21
+ /**
22
+ * The scalar boundary. Everything downstream — comparisons, subject
23
+ * placeholders, resolved message props — is typed ScalarIR, but nothing so
24
+ * far has checked that the stored JSON is one: /ingest validates only that
25
+ * `props` is a plain object, and the merge stores whatever nesting it is
26
+ * handed. Left unchecked, `gt(score, 3)` on `['5']` coerces its way to true
27
+ * while `eq(score, 5)` is false, and `String(recipient)` on an object
28
+ * addresses an email to `[object Object]`.
29
+ *
30
+ * So a non-scalar value reads as absent, matching how matchesWhere treats a
31
+ * non-scalar payload leaf. The port cannot say "present but not a scalar",
32
+ * and guessing at a coercion is what produced the wrong branch in the first
33
+ * place.
34
+ */
35
+ getProperty(path: string): Promise<ScalarIR | undefined>;
36
+ getSegmentCondition(name: string): Promise<ConditionIR | undefined>;
37
+ /** The user's opt-outs: the channel's, or with a topic that topic's as well. */
38
+ isSuppressed(channel: string, topic?: string): Promise<boolean>;
39
+ listDevices(): Promise<PushDevice[]>;
40
+ }
41
+ //# sourceMappingURL=facts.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts.d.mts","names":[],"sources":["../../src/store/facts.ts"],"mappings":";;;;qBAMa;;qBAMA,6BAA6B;mBAErB;mBACA;;mBAEA;EAJnB,YACmB,OAAO,cACP;;EAEA,cAAa;EAG1B,YACJ,eACA;IAAS;IAAkB;IAAkB,QAAQ;IAAa;MACjE;;;;;;;;;;;;;;;EA6CG,YAAY,eAAe,QAAQ;EAqBzC,oBAAoB,eAAe,QAAQ;;EAKrC,aAAa,iBAAiB,iBAAiB;EAI/C,eAAe,QAAQ"}
@@ -0,0 +1,77 @@
1
+ import { matchesWhere } from "../engine/condition.mjs";
2
+ // src/store/facts.ts
3
+ /** The profile path that reads the user's own id (`u.userId`). */
4
+ const USER_ID_PROPERTY = "userId";
5
+ /** Payloads per round trip when a `where` filters events in JS. */
6
+ const PAYLOAD_PAGE = 500;
7
+ /** Single-user fact source over a JourneyStore: evaluation lives in engine/condition.ts, this only reads. */
8
+ var JourneyFactSource = class {
9
+ store;
10
+ userId;
11
+ owner;
12
+ constructor(store, userId, owner = () => Promise.resolve(userId)) {
13
+ this.store = store;
14
+ this.userId = userId;
15
+ this.owner = owner;
16
+ }
17
+ async countEvents(event, opts) {
18
+ const window = {
19
+ ...opts?.sinceMs === void 0 ? {} : { sinceMs: opts.sinceMs },
20
+ ...opts?.untilMs === void 0 ? {} : { untilMs: opts.untilMs }
21
+ };
22
+ const atLeast = opts?.atLeast;
23
+ const userId = await this.owner();
24
+ if (opts?.where === void 0) return this.store.countEvents(userId, event, window, atLeast);
25
+ const where = opts.where;
26
+ let matched = 0;
27
+ let after;
28
+ for (;;) {
29
+ const page = await this.store.pageEventPayloads(userId, event, window, {
30
+ limit: PAYLOAD_PAGE,
31
+ after
32
+ });
33
+ for (const payload of page.payloads) {
34
+ if (matchesWhere(payload, where)) matched += 1;
35
+ if (atLeast !== void 0 && matched >= atLeast) return matched;
36
+ }
37
+ if (page.next === void 0) return matched;
38
+ after = page.next;
39
+ }
40
+ }
41
+ /**
42
+ * The scalar boundary. Everything downstream — comparisons, subject
43
+ * placeholders, resolved message props — is typed ScalarIR, but nothing so
44
+ * far has checked that the stored JSON is one: /ingest validates only that
45
+ * `props` is a plain object, and the merge stores whatever nesting it is
46
+ * handed. Left unchecked, `gt(score, 3)` on `['5']` coerces its way to true
47
+ * while `eq(score, 5)` is false, and `String(recipient)` on an object
48
+ * addresses an email to `[object Object]`.
49
+ *
50
+ * So a non-scalar value reads as absent, matching how matchesWhere treats a
51
+ * non-scalar payload leaf. The port cannot say "present but not a scalar",
52
+ * and guessing at a coercion is what produced the wrong branch in the first
53
+ * place.
54
+ */
55
+ async getProperty(path) {
56
+ const userId = await this.owner();
57
+ if (path === "userId") return userId;
58
+ const props = await this.store.getProfile(userId);
59
+ if (props === void 0) return void 0;
60
+ if (!Object.hasOwn(props, path)) return void 0;
61
+ const value = props[path];
62
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
63
+ }
64
+ getSegmentCondition(name) {
65
+ return this.store.getSegmentCondition(name);
66
+ }
67
+ /** The user's opt-outs: the channel's, or with a topic that topic's as well. */
68
+ async isSuppressed(channel, topic) {
69
+ return this.store.isSuppressed(await this.owner(), channel, topic);
70
+ }
71
+ async listDevices() {
72
+ return this.store.listDevices(await this.owner());
73
+ }
74
+ };
75
+ export { JourneyFactSource, USER_ID_PROPERTY };
76
+
77
+ //# sourceMappingURL=facts.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts.mjs","names":[],"sources":["../../src/store/facts.ts"],"sourcesContent":["import { matchesWhere } from '../engine/condition';\nimport type { FactSource, PushDevice } from '../engine/ports';\nimport type { ConditionIR, ScalarIR } from '../ir';\nimport type { EventCursor, JourneyStore } from './index';\n\n/** The profile path that reads the user's own id (`u.userId`). */\nexport const USER_ID_PROPERTY = 'userId';\n\n/** Payloads per round trip when a `where` filters events in JS. */\nconst PAYLOAD_PAGE = 500;\n\n/** Single-user fact source over a JourneyStore: evaluation lives in engine/condition.ts, this only reads. */\nexport class JourneyFactSource implements FactSource {\n constructor(\n private readonly store: JourneyStore,\n private readonly userId: string,\n /** Who the facts are about now, for a journey that can change hands; `userId` otherwise. */\n private readonly owner: () => Promise<string> = () => Promise.resolve(userId)\n ) {}\n\n async countEvents(\n event: string,\n opts?: { sinceMs?: number; untilMs?: number; where?: ConditionIR; atLeast?: number }\n ): Promise<number> {\n const window = {\n ...(opts?.sinceMs === undefined ? {} : { sinceMs: opts.sinceMs }),\n ...(opts?.untilMs === undefined ? {} : { untilMs: opts.untilMs }),\n };\n const atLeast = opts?.atLeast;\n const userId = await this.owner();\n if (opts?.where === undefined) {\n return this.store.countEvents(userId, event, window, atLeast);\n }\n // Payload filtering stays in JS through the shared evaluator — one set of where semantics\n // with the in-memory FactSource — but a page at a time, stopping as soon as enough events\n // match. A heavy user's history is no longer loaded whole on every evaluation; only a user\n // with no match left to find is read to the end, and then in bounded pages.\n const where = opts.where;\n let matched = 0;\n let after: EventCursor | undefined;\n for (;;) {\n const page = await this.store.pageEventPayloads(userId, event, window, {\n limit: PAYLOAD_PAGE,\n after,\n });\n for (const payload of page.payloads) {\n if (matchesWhere(payload, where)) matched += 1;\n if (atLeast !== undefined && matched >= atLeast) return matched;\n }\n if (page.next === undefined) return matched;\n after = page.next;\n }\n }\n\n /**\n * The scalar boundary. Everything downstream — comparisons, subject\n * placeholders, resolved message props — is typed ScalarIR, but nothing so\n * far has checked that the stored JSON is one: /ingest validates only that\n * `props` is a plain object, and the merge stores whatever nesting it is\n * handed. Left unchecked, `gt(score, 3)` on `['5']` coerces its way to true\n * while `eq(score, 5)` is false, and `String(recipient)` on an object\n * addresses an email to `[object Object]`.\n *\n * So a non-scalar value reads as absent, matching how matchesWhere treats a\n * non-scalar payload leaf. The port cannot say \"present but not a scalar\",\n * and guessing at a coercion is what produced the wrong branch in the first\n * place.\n */\n async getProperty(path: string): Promise<ScalarIR | undefined> {\n // The system field: the request's identity, never stored in the profile (contract.user.userId)\n const userId = await this.owner();\n if (path === USER_ID_PROPERTY) return userId;\n const props: Record<string, unknown> | undefined = await this.store.getProfile(userId);\n if (props === undefined) return undefined;\n // Own keys only: `props[path]` would otherwise find Object.prototype, so\n // `exists(u.toString)` held for every user with a profile row and a subject\n // placeholder rendered native-code text into the email.\n if (!Object.hasOwn(props, path)) return undefined;\n const value = props[path];\n // An explicit null means \"unset\" and behaves as not_exists. /ingest\n // itself clears a property by removing the key (the merge drops nulls), so\n // this covers profiles written by other means — a direct SQL fixup, a\n // migration, an import.\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return value;\n }\n return undefined;\n }\n\n getSegmentCondition(name: string): Promise<ConditionIR | undefined> {\n return this.store.getSegmentCondition(name);\n }\n\n /** The user's opt-outs: the channel's, or with a topic that topic's as well. */\n async isSuppressed(channel: string, topic?: string): Promise<boolean> {\n return this.store.isSuppressed(await this.owner(), channel, topic);\n }\n\n async listDevices(): Promise<PushDevice[]> {\n return this.store.listDevices(await this.owner());\n }\n}\n"],"mappings":";;;AAMA,MAAa,mBAAmB;;AAGhC,MAAM,eAAe;;AAGrB,IAAa,oBAAb,MAAqD;CAEhC;CACA;CAEA;CAJnB,YACmB,OACA,QAEA,cAAqC,QAAQ,QAAQ,MAAM,GAC5E;EAJiB,KAAA,QAAA;EACA,KAAA,SAAA;EAEA,KAAA,QAAA;CAChB;CAEH,MAAM,YACJ,OACA,MACiB;EACjB,MAAM,SAAS;GACb,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,KAAK,QAAQ;GAC/D,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,KAAK,QAAQ;EACjE;EACA,MAAM,UAAU,MAAM;EACtB,MAAM,SAAS,MAAM,KAAK,MAAM;EAChC,IAAI,MAAM,UAAU,KAAA,GAClB,OAAO,KAAK,MAAM,YAAY,QAAQ,OAAO,QAAQ,OAAO;EAM9D,MAAM,QAAQ,KAAK;EACnB,IAAI,UAAU;EACd,IAAI;EACJ,SAAS;GACP,MAAM,OAAO,MAAM,KAAK,MAAM,kBAAkB,QAAQ,OAAO,QAAQ;IACrE,OAAO;IACP;GACF,CAAC;GACD,KAAK,MAAM,WAAW,KAAK,UAAU;IACnC,IAAI,aAAa,SAAS,KAAK,GAAG,WAAW;IAC7C,IAAI,YAAY,KAAA,KAAa,WAAW,SAAS,OAAO;GAC1D;GACA,IAAI,KAAK,SAAS,KAAA,GAAW,OAAO;GACpC,QAAQ,KAAK;EACf;CACF;;;;;;;;;;;;;;;CAgBA,MAAM,YAAY,MAA6C;EAE7D,MAAM,SAAS,MAAM,KAAK,MAAM;EAChC,IAAI,SAAA,UAA2B,OAAO;EACtC,MAAM,QAA6C,MAAM,KAAK,MAAM,WAAW,MAAM;EACrF,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;EAIhC,IAAI,CAAC,OAAO,OAAO,OAAO,IAAI,GAAG,OAAO,KAAA;EACxC,MAAM,QAAQ,MAAM;EAKpB,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,WAC7E,OAAO;CAGX;CAEA,oBAAoB,MAAgD;EAClE,OAAO,KAAK,MAAM,oBAAoB,IAAI;CAC5C;;CAGA,MAAM,aAAa,SAAiB,OAAkC;EACpE,OAAO,KAAK,MAAM,aAAa,MAAM,KAAK,MAAM,GAAG,SAAS,KAAK;CACnE;CAEA,MAAM,cAAqC;EACzC,OAAO,KAAK,MAAM,YAAY,MAAM,KAAK,MAAM,CAAC;CAClD;AACF"}