better-supabase 0.54.0 → 0.56.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.
Files changed (445) hide show
  1. package/dist/{agents-DcZk8HBB.d.ts → agents-DJChYmXn.d.ts} +2 -2
  2. package/dist/{ai-schedules-b-uWaxba.d.ts → ai-schedules-5fxfEOWM.d.ts} +1 -1
  3. package/dist/ai-sdk/agents/index.d.ts +1 -1
  4. package/dist/ai-sdk/workflow/index.d.ts +1 -1
  5. package/dist/{app-tables-B2xNMyLA.d.ts → app-tables-CWnf7wpo.d.ts} +1 -1
  6. package/dist/{audit-actions-Dni5Y4wV.d.ts → audit-actions-DC-AtyWB.d.ts} +6 -0
  7. package/dist/{authorization-Bk6cLL5f.d.ts → authorization-Hh9xUm0r.d.ts} +1 -1
  8. package/dist/{automations-CjKWYzIu.js → automations-Cu1KdCvL.js} +3 -1
  9. package/dist/{bind-DWElQa6I.d.ts → bind-CC5-eBT-.d.ts} +4 -4
  10. package/dist/{block-env-CQQUMPYZ.d.ts → block-env-CzT1OAiI.d.ts} +4 -4
  11. package/dist/{block-subjects-9KU6Q6-3.js → block-subjects-B9hb1LLk.js} +4 -3
  12. package/dist/{block-tables-JC1dMLaA.d.ts → block-tables-DOGtmm0m.d.ts} +1 -1
  13. package/dist/blocks/access-requests/index.d.ts +1 -1
  14. package/dist/blocks/accounting/index.d.ts +1 -1
  15. package/dist/blocks/acknowledgements/index.d.ts +1 -1
  16. package/dist/blocks/activities/index.d.ts +2 -2
  17. package/dist/blocks/advisories/index.d.ts +1 -1
  18. package/dist/blocks/agent-checkout/index.d.ts +1 -1
  19. package/dist/blocks/agents/index.d.ts +1 -1
  20. package/dist/blocks/ai-cache/index.d.ts +1 -1
  21. package/dist/blocks/ai-chat/index.d.ts +1 -1
  22. package/dist/blocks/ai-evals/index.d.ts +1 -1
  23. package/dist/blocks/ai-files/index.d.ts +1 -1
  24. package/dist/blocks/ai-guardrails/index.d.ts +1 -1
  25. package/dist/blocks/ai-keys/index.d.ts +1 -1
  26. package/dist/blocks/ai-schedules/index.d.ts +2 -2
  27. package/dist/blocks/announcements/index.d.ts +4 -4
  28. package/dist/blocks/api-keys/index.d.ts +1 -1
  29. package/dist/blocks/appraisals/index.d.ts +1 -1
  30. package/dist/blocks/approvals/index.d.ts +1 -1
  31. package/dist/blocks/assets/index.d.ts +2 -2
  32. package/dist/blocks/assignment/index.d.ts +1 -1
  33. package/dist/blocks/attachments/index.d.ts +5 -5
  34. package/dist/blocks/audit/index.d.ts +2 -2
  35. package/dist/blocks/automations/index.d.ts +3 -3
  36. package/dist/blocks/banking/index.d.ts +1 -1
  37. package/dist/blocks/billable-time/index.d.ts +1 -1
  38. package/dist/blocks/billing/index.d.ts +2 -2
  39. package/dist/blocks/bookings/index.d.ts +2 -2
  40. package/dist/blocks/bulk/index.d.ts +1 -1
  41. package/dist/blocks/calendar/index.d.ts +3 -3
  42. package/dist/blocks/care/index.d.ts +27 -27
  43. package/dist/blocks/care-plans/index.d.ts +3 -3
  44. package/dist/blocks/cases/index.d.ts +3 -3
  45. package/dist/blocks/catalog/index.d.ts +2 -2
  46. package/dist/blocks/channels/index.d.ts +1 -1
  47. package/dist/blocks/clinical-decision-support/index.d.ts +1 -1
  48. package/dist/blocks/cms/index.d.ts +5 -5
  49. package/dist/blocks/collaboration/index.d.ts +6 -6
  50. package/dist/blocks/collections/index.d.ts +1 -1
  51. package/dist/blocks/comments/index.d.ts +2 -2
  52. package/dist/blocks/commerce/index.d.ts +5 -5
  53. package/dist/blocks/commerce/index.js +2 -2
  54. package/dist/blocks/commissions/index.d.ts +1 -1
  55. package/dist/blocks/compliance/index.d.ts +1 -1
  56. package/dist/blocks/connectors/index.d.ts +1 -1
  57. package/dist/blocks/consents/index.d.ts +2 -2
  58. package/dist/blocks/contacts/index.d.ts +2 -2
  59. package/dist/blocks/content/index.d.ts +2 -2
  60. package/dist/blocks/contracts/index.d.ts +1 -1
  61. package/dist/blocks/courses/index.d.ts +3 -3
  62. package/dist/blocks/created-by/index.d.ts +2 -2
  63. package/dist/blocks/crm/index.d.ts +16 -16
  64. package/dist/blocks/crm/index.js +2 -2
  65. package/dist/blocks/custom-fields/index.d.ts +1 -1
  66. package/dist/blocks/dam/index.d.ts +2 -2
  67. package/dist/blocks/data-lifecycle/index.d.ts +2 -2
  68. package/dist/blocks/deadlines/index.d.ts +249 -43
  69. package/dist/blocks/deadlines/index.js +862 -20
  70. package/dist/blocks/deals/index.d.ts +1 -1
  71. package/dist/blocks/dispatch/index.d.ts +2 -2
  72. package/dist/blocks/document-templates/index.d.ts +2 -2
  73. package/dist/blocks/documents/index.d.ts +1 -1
  74. package/dist/blocks/domains/index.d.ts +1 -1
  75. package/dist/blocks/donations/index.d.ts +1 -1
  76. package/dist/blocks/drive/index.d.ts +5 -5
  77. package/dist/blocks/e-prescribing/index.d.ts +1 -1
  78. package/dist/blocks/employees/index.d.ts +1 -1
  79. package/dist/blocks/enrichment/index.d.ts +1 -1
  80. package/dist/blocks/enrollments/index.d.ts +2 -2
  81. package/dist/blocks/entitlements/index.d.ts +3 -3
  82. package/dist/blocks/events/index.d.ts +3 -3
  83. package/dist/blocks/expenses/index.d.ts +1 -1
  84. package/dist/blocks/field-history/index.d.ts +1 -1
  85. package/dist/blocks/filespace/index.d.ts +8 -8
  86. package/dist/blocks/finance/index.d.ts +5 -5
  87. package/dist/blocks/finance/index.js +1 -1
  88. package/dist/blocks/flags/index.d.ts +1 -1
  89. package/dist/blocks/forecasts/index.d.ts +1 -1
  90. package/dist/blocks/forms/index.d.ts +3 -3
  91. package/dist/blocks/funding/index.d.ts +2 -2
  92. package/dist/blocks/goals/index.d.ts +1 -1
  93. package/dist/blocks/governance/index.d.ts +4 -4
  94. package/dist/blocks/guests/index.d.ts +1 -1
  95. package/dist/blocks/hiring/index.d.ts +1 -1
  96. package/dist/blocks/identities/index.d.ts +1 -1
  97. package/dist/blocks/imports/index.d.ts +2 -2
  98. package/dist/blocks/inbox/index.d.ts +6 -6
  99. package/dist/blocks/incidents/index.d.ts +1 -1
  100. package/dist/blocks/index.d.ts +4 -4
  101. package/dist/blocks/inspections/index.d.ts +2 -2
  102. package/dist/blocks/inventory/index.d.ts +1 -1
  103. package/dist/blocks/inventory/index.js +1 -1
  104. package/dist/blocks/invoices/index.d.ts +1 -1
  105. package/dist/blocks/invoices/index.js +1 -1
  106. package/dist/blocks/knowledge/index.d.ts +1 -1
  107. package/dist/blocks/lead-scoring/index.d.ts +2 -2
  108. package/dist/blocks/learning/index.d.ts +3 -3
  109. package/dist/blocks/leases/index.d.ts +1 -1
  110. package/dist/blocks/leave/index.d.ts +1 -1
  111. package/dist/blocks/ledger/index.d.ts +1 -1
  112. package/dist/blocks/legal-entities/index.d.ts +2 -2
  113. package/dist/blocks/lims/index.d.ts +2 -2
  114. package/dist/blocks/mail-sync/index.d.ts +3 -3
  115. package/dist/blocks/maintenance/index.d.ts +2 -2
  116. package/dist/blocks/manufacturing/index.d.ts +2 -2
  117. package/dist/blocks/medications/index.d.ts +1 -1
  118. package/dist/blocks/meetings/index.d.ts +3 -3
  119. package/dist/blocks/memberships/index.d.ts +2 -2
  120. package/dist/blocks/memory/index.d.ts +1 -1
  121. package/dist/blocks/messaging/index.d.ts +5 -5
  122. package/dist/blocks/metrics/index.d.ts +1 -1
  123. package/dist/blocks/mfa/index.d.ts +2 -2
  124. package/dist/blocks/moderation/index.d.ts +2 -2
  125. package/dist/blocks/notifications/index.d.ts +5 -5
  126. package/dist/blocks/numbering/index.d.ts +1 -1
  127. package/dist/blocks/oauth-server/index.d.ts +1 -1
  128. package/dist/blocks/observations/index.d.ts +2 -2
  129. package/dist/blocks/onboarding/index.d.ts +2 -2
  130. package/dist/blocks/option-sets/index.d.ts +2 -2
  131. package/dist/blocks/orders/index.d.ts +1 -1
  132. package/dist/blocks/orders/index.js +1 -1
  133. package/dist/blocks/organizations/index.d.ts +2 -2
  134. package/dist/blocks/outbox/index.d.ts +1 -1
  135. package/dist/blocks/passes/index.d.ts +2 -2
  136. package/dist/blocks/payroll-export/index.d.ts +2 -2
  137. package/dist/blocks/payroll-export/index.js +1 -1
  138. package/dist/blocks/people/index.d.ts +7 -7
  139. package/dist/blocks/people/index.js +1 -1
  140. package/dist/blocks/periods/index.d.ts +1 -1
  141. package/dist/blocks/permissions/index.d.ts +3 -3
  142. package/dist/blocks/pipelines/index.d.ts +1 -1
  143. package/dist/blocks/posts/index.d.ts +2 -2
  144. package/dist/blocks/procurement/index.d.ts +5 -5
  145. package/dist/blocks/procurement/index.js +2 -2
  146. package/dist/blocks/profiles/index.d.ts +1 -1
  147. package/dist/blocks/projects/index.d.ts +7 -7
  148. package/dist/blocks/projects/index.js +2 -2
  149. package/dist/blocks/promotions/index.d.ts +1 -1
  150. package/dist/blocks/prompts/index.d.ts +1 -1
  151. package/dist/blocks/push/index.d.ts +2 -2
  152. package/dist/blocks/qualifications/index.d.ts +2 -2
  153. package/dist/blocks/queue/index.d.ts +2 -2
  154. package/dist/blocks/quotes/index.d.ts +1 -1
  155. package/dist/blocks/quotes/index.js +2 -2
  156. package/dist/blocks/rank/index.d.ts +1 -1
  157. package/dist/blocks/reactions/index.d.ts +4 -4
  158. package/dist/blocks/recruiting/index.d.ts +4 -4
  159. package/dist/blocks/referrals/index.d.ts +1 -1
  160. package/dist/blocks/relations/index.d.ts +1 -1
  161. package/dist/blocks/reminders/index.d.ts +1 -1
  162. package/dist/blocks/reviews/index.d.ts +1 -1
  163. package/dist/blocks/rfqs/index.d.ts +2 -2
  164. package/dist/blocks/risks/index.d.ts +2 -2
  165. package/dist/blocks/saas/index.d.ts +12 -12
  166. package/dist/blocks/sales/index.d.ts +1 -1
  167. package/dist/blocks/sales/index.js +1 -1
  168. package/dist/blocks/saved-views/index.d.ts +2 -2
  169. package/dist/blocks/scheduling/index.d.ts +4 -4
  170. package/dist/blocks/scores/index.d.ts +2 -2
  171. package/dist/blocks/search/index.d.ts +3 -3
  172. package/dist/blocks/security-events/index.d.ts +1 -1
  173. package/dist/blocks/segments/index.d.ts +2 -2
  174. package/dist/blocks/sequences/index.d.ts +3 -3
  175. package/dist/blocks/service/index.d.ts +7 -7
  176. package/dist/blocks/service/index.js +1 -1
  177. package/dist/blocks/service-accounts/index.d.ts +1 -1
  178. package/dist/blocks/sessions/index.d.ts +2 -2
  179. package/dist/blocks/settings/index.d.ts +2 -2
  180. package/dist/blocks/share-links/index.d.ts +1 -1
  181. package/dist/blocks/shifts/index.d.ts +2 -2
  182. package/dist/blocks/shipments/index.d.ts +2 -2
  183. package/dist/blocks/signatures/index.d.ts +2 -2
  184. package/dist/blocks/signing-keys/index.d.ts +1 -1
  185. package/dist/blocks/sla/index.d.ts +1 -1
  186. package/dist/blocks/sso/index.d.ts +1 -1
  187. package/dist/blocks/state-machine/index.d.ts +1 -1
  188. package/dist/blocks/subjects/index.d.ts +2 -2
  189. package/dist/blocks/support/index.d.ts +5 -5
  190. package/dist/blocks/support/index.js +1 -1
  191. package/dist/blocks/tags/index.d.ts +2 -2
  192. package/dist/blocks/tasks/index.d.ts +2 -2
  193. package/dist/blocks/tasks/index.js +1 -1
  194. package/dist/blocks/tax/index.d.ts +2 -2
  195. package/dist/blocks/teams/index.d.ts +1 -1
  196. package/dist/blocks/templates/index.d.ts +11 -1
  197. package/dist/blocks/templates/index.js +6 -1
  198. package/dist/blocks/tills/index.d.ts +1 -1
  199. package/dist/blocks/time-tracking/index.d.ts +2 -2
  200. package/dist/blocks/timeline/index.d.ts +1 -1
  201. package/dist/blocks/trash/index.d.ts +1 -1
  202. package/dist/blocks/undo/index.d.ts +2 -2
  203. package/dist/blocks/updated-at/index.d.ts +2 -2
  204. package/dist/blocks/usage/index.d.ts +2 -2
  205. package/dist/blocks/vercel-marketplace/index.d.ts +1 -1
  206. package/dist/blocks/versions/index.d.ts +1 -1
  207. package/dist/blocks/waitlist/index.d.ts +1 -1
  208. package/dist/blocks/warehouse/index.d.ts +1 -1
  209. package/dist/blocks/webhooks/index.d.ts +1 -1
  210. package/dist/blocks/workflow-editor/index.d.ts +4 -4
  211. package/dist/blocks/workflows/index.d.ts +4 -4
  212. package/dist/{blocks-LZklPzC5.d.ts → blocks-DvWEz8mQ.d.ts} +56 -21
  213. package/dist/claims/index.d.ts +3 -3
  214. package/dist/cli/{add-BQZbFEAP.js → add--O_HFhs0.js} +2 -2
  215. package/dist/cli/add-CUAchifS.js +1 -0
  216. package/dist/cli/{add-DK38-F2F.js → add-DT2QsJB0.js} +12 -12
  217. package/dist/cli/{app-table-files-C5Sx2Qao.js → app-table-files-BjMDa_7_.js} +3 -3
  218. package/dist/cli/{app-tables-ChZE8Z_L.js → app-tables-D34g1ASz.js} +2 -2
  219. package/dist/cli/{backfill-COnv2tOL.js → backfill-DWD5chCd.js} +3 -3
  220. package/dist/cli/bin.js +1 -1
  221. package/dist/cli/{blocks-Dea_Z5Ps.js → blocks-BduQcXFb.js} +1 -1
  222. package/dist/cli/{blocks-Csu6lLqC.js → blocks-DKs7Qj8R.js} +1 -1
  223. package/dist/cli/{cache-C1nAFZNW.js → cache-EFwNdKib.js} +1 -1
  224. package/dist/cli/{codemod-DHULUpez.js → codemod-CuaWRwst.js} +1 -1
  225. package/dist/cli/{config-FN5Cp861.js → config-DdkxiGjH.js} +7 -0
  226. package/dist/cli/{config-U32Vo0h6.js → config-DmjFp8jY.js} +1 -1
  227. package/dist/cli/{content-mapper-QVJJto5U.js → content-mapper-BlOMmIM2.js} +2 -2
  228. package/dist/cli/{db-T8u160uM.js → db-B54TQ_iX.js} +2 -2
  229. package/dist/cli/{doctor-Du2zwLUG.js → doctor-JdxWuscJ.js} +17 -17
  230. package/dist/cli/{gen-CQ2ubqjB.js → gen-n6l6AMLo.js} +14 -14
  231. package/dist/cli/index.d.ts +1 -1
  232. package/dist/cli/index.js +7 -7
  233. package/dist/cli/{init-CTt0aQn1.js → init-BLMHN_2A.js} +10 -10
  234. package/dist/cli/{live-DMNuAml9.js → live-C4uCg3ME.js} +2 -2
  235. package/dist/cli/{mcp-C63ulwyU.js → mcp-CFLvzFKH.js} +2 -2
  236. package/dist/cli/{metadata-CylES-9Y.js → metadata-CRp8JQTE.js} +3 -3
  237. package/dist/cli/{migrate-BezKva56.js → migrate-BjDf0moD.js} +1 -1
  238. package/dist/cli/{migration-safety-DQtpMu-g.js → migration-safety-D-QnV2BW.js} +2 -2
  239. package/dist/cli/{migrations-DGJJ1rHt.js → migrations-8dDFF8SW.js} +2 -2
  240. package/dist/cli/{module-migration-CxbEDfSF.js → module-migration-DuwIX8MO.js} +2 -2
  241. package/dist/cli/powersync-ByqoHJwp.js +1 -0
  242. package/dist/cli/{powersync-FUYFuZSw.js → powersync-CHVlZIqs.js} +3 -3
  243. package/dist/cli/{print-DAwLAC-7.js → print-orgMiDzp.js} +2 -2
  244. package/dist/cli/{providers-hrxX3YKU.js → providers-DWZVnoDw.js} +1 -1
  245. package/dist/cli/{prune-workflows-DLhKu_UJ.js → prune-workflows-DelKs-zD.js} +3 -3
  246. package/dist/cli/{remove-DSC6Fvwo.js → remove-BH6Zwjhs.js} +6 -6
  247. package/dist/cli/{render-647qdnrX.js → render-DyWVslCM.js} +4 -4
  248. package/dist/cli/{run--qaDaqfL.js → run-BYX5n5rt.js} +9 -9
  249. package/dist/cli/{run-BcI6KXV3.js → run-GcSBgXCH.js} +35 -35
  250. package/dist/cli/seed-BxjjQ3OO.js +1 -0
  251. package/dist/cli/{seed-BgpovbwF.js → seed-kCLEYSOH.js} +2 -2
  252. package/dist/cli/{shared-D_DZ9MfG.js → shared-BoVOOrpJ.js} +1 -1
  253. package/dist/cli/{snapshot-B-1tPbV4.js → snapshot-BZGZ9pB-.js} +3 -3
  254. package/dist/cli/{source-BgFNrRcl.js → source-Buw7eODS.js} +1 -1
  255. package/dist/cli/{source-args-DC8snM7e.js → source-args-C3_mMci3.js} +1 -1
  256. package/dist/cli/{spec-CV0FdW18.js → spec-CUWMpL3f.js} +2 -2
  257. package/dist/cli/{spec-C88dtkj4.js → spec-CnRC9FcX.js} +1 -1
  258. package/dist/cli/{sql-layout-byUur5FC.js → sql-layout-BZ-NhhTI.js} +2 -2
  259. package/dist/cli/{sync-BtM7o-sI.js → sync-CFzA4xdr.js} +4 -4
  260. package/dist/cli/{upgrade-CKDeHkyy.js → upgrade-D1szGysi.js} +5 -5
  261. package/dist/cli/{upgrade-B_HEJvRX.js → upgrade-ukOP0GXf.js} +2 -2
  262. package/dist/cli/{version-DWDoiP5_.js → version-D1sJX6_6.js} +1 -1
  263. package/dist/client/index.d.ts +6 -6
  264. package/dist/client/native/index.d.ts +4 -4
  265. package/dist/config/index.d.ts +4 -4
  266. package/dist/config/index.js +4 -4
  267. package/dist/{config-LOwFAFpo.js → config-Bx3UYp8b.js} +3 -3
  268. package/dist/{config-ekflaCnS.js → config-CAjlOSQY.js} +1 -1
  269. package/dist/{context-iduX3Fsn.d.ts → context-BIBqUjVz.d.ts} +47 -4
  270. package/dist/contract/index.d.ts +3 -3
  271. package/dist/{contributions-DPjEWWpE.js → contributions-olp7tVYC.js} +11 -0
  272. package/dist/{controller-DFGNChQL.d.ts → controller-DBD6WWDa.d.ts} +1 -1
  273. package/dist/{conversion-DTBB0Zgt.d.ts → conversion-DLkof9_y.d.ts} +1 -1
  274. package/dist/create/index.d.ts +4 -4
  275. package/dist/create/index.js +3 -3
  276. package/dist/create/lite/index.d.ts +3 -3
  277. package/dist/create/lite/index.js +2 -2
  278. package/dist/{data-engine-BKO5EAzN.d.ts → data-engine-0uVsKWaB.d.ts} +7 -3
  279. package/dist/deadlines-values-vmaCCdGl.js +92 -0
  280. package/dist/{define-block-By-LUpM_.d.ts → define-block-zK3QnPyG.d.ts} +1 -1
  281. package/dist/{drive-CuNG4qB8.d.ts → drive-Keqe8dIg.d.ts} +1 -1
  282. package/dist/{entitlements-Go8BHqhr.d.ts → entitlements-QwMag409.d.ts} +1 -1
  283. package/dist/{extract-DQKHxiiq.d.ts → extract-CJWS6MMG.d.ts} +1 -1
  284. package/dist/{field-errors-B4SMTk2e.d.ts → field-errors-BlyD3if3.d.ts} +6 -6
  285. package/dist/{index-DQVQYEhP.d.ts → index-0AVn1Dcr.d.ts} +1 -1
  286. package/dist/{index-20EPlFXG.d.ts → index-9rajR8Ti.d.ts} +1 -1
  287. package/dist/{index-DlXgoerO.d.ts → index-B5rQ9MEl.d.ts} +1 -1
  288. package/dist/{index-DkNMN5uU.d.ts → index-B7_Mq8Qm.d.ts} +1 -1
  289. package/dist/{index-DkJtM-9e.d.ts → index-BGqvP9dE.d.ts} +9 -9
  290. package/dist/{index-szXZSILq.d.ts → index-BIClMq6S.d.ts} +7 -7
  291. package/dist/{index-YZ-_hzdR.d.ts → index-BOI3eLz0.d.ts} +1 -1
  292. package/dist/{index-B8axasMg.d.ts → index-BSdDLEA-.d.ts} +1 -1
  293. package/dist/{index-ROumUag2.d.ts → index-BTC40rxx.d.ts} +1 -1
  294. package/dist/{index-C1kImKZg.d.ts → index-BxdldeGx.d.ts} +1 -1
  295. package/dist/{index-DXoS8BnK.d.ts → index-C7tmYYB5.d.ts} +3 -3
  296. package/dist/{index-BoKvWo8t.d.ts → index-CJB2uCFk.d.ts} +1 -1
  297. package/dist/{index-DkNLdcX_.d.ts → index-COLMIEk0.d.ts} +1 -1
  298. package/dist/{index-BmKtYKwN.d.ts → index-CPRQdNHc.d.ts} +2 -2
  299. package/dist/{index-NqLuAXG3.d.ts → index-CSdjm0Kn.d.ts} +2 -2
  300. package/dist/{index-D4ke5U0m.d.ts → index-CT0OjCk1.d.ts} +1 -1
  301. package/dist/{index-D7FXhn2i.d.ts → index-CocISf2h.d.ts} +1 -1
  302. package/dist/{index-9zNFFq6E.d.ts → index-Cvd24Ybb.d.ts} +1 -1
  303. package/dist/{index-CTHuTJtf.d.ts → index-DASeimpy.d.ts} +1 -1
  304. package/dist/{index-Dg35ugqv.d.ts → index-DBqRH5cj.d.ts} +4 -4
  305. package/dist/{index-abVPYQE3.d.ts → index-DCeA3cFQ.d.ts} +1 -1
  306. package/dist/{index-bJVAgXxw.d.ts → index-DD3Ldome.d.ts} +2 -2
  307. package/dist/{index-DJyt9j86.d.ts → index-DEDIPDaW.d.ts} +2 -2
  308. package/dist/{index-D9Sb8Ju5.d.ts → index-DNitLhgU.d.ts} +3 -3
  309. package/dist/{index-BKWnyAWN.d.ts → index-D_OEwOaE.d.ts} +2 -2
  310. package/dist/{index-DzjugbCf.d.ts → index-D_g2loq-.d.ts} +2 -2
  311. package/dist/{index-DfJFbsVp.d.ts → index-DaTxv1aA.d.ts} +1 -1
  312. package/dist/{index-D337YzjX.d.ts → index-DcihkEQo.d.ts} +1 -1
  313. package/dist/{index-DeE-Xuv7.d.ts → index-Do6ZAvXT.d.ts} +1 -1
  314. package/dist/{index-DgRK-iM3.d.ts → index-DpwRuDBy.d.ts} +4 -4
  315. package/dist/{index-pRdO2XnG.d.ts → index-HANt6RDT.d.ts} +1 -1
  316. package/dist/{index-Bsd8P1iQ.d.ts → index-QpKsKUbn.d.ts} +2 -2
  317. package/dist/{index-DFdqVxv6.d.ts → index-WXVYfOHr.d.ts} +4 -4
  318. package/dist/{index-BkBNirhK.d.ts → index-XjhYgGhk.d.ts} +2 -2
  319. package/dist/{index-BvwlIGwY.d.ts → index-_rOaXPbx.d.ts} +1 -1
  320. package/dist/{index-BXRyr3ey.d.ts → index-n-7IwvYP.d.ts} +2 -2
  321. package/dist/{index-D-bMFoGs.d.ts → index-urOSlPMc.d.ts} +2 -2
  322. package/dist/{instances-DJxWRqXk.js → instances-z6DJn2Gr.js} +52 -8
  323. package/dist/{inventory-reads-BNDSYnuG.js → inventory-reads-DEw2Kbff.js} +2 -1
  324. package/dist/{manifest-DjAdsSs4.d.ts → manifest-B4SF4ieN.d.ts} +1 -1
  325. package/dist/{manifest-BeW5LlW1.d.ts → manifest-B9D-PHpo.d.ts} +1 -1
  326. package/dist/{manifest-H6lz9xQm.d.ts → manifest-BBIs-5xy.d.ts} +1 -1
  327. package/dist/{manifest-BfIYKrNe.d.ts → manifest-BE6JGlFP.d.ts} +1 -1
  328. package/dist/{manifest-BCOBkYvY.d.ts → manifest-BExilPWu.d.ts} +2 -2
  329. package/dist/{manifest-uL5fzXsx.d.ts → manifest-BNhdYakH.d.ts} +1 -1
  330. package/dist/{manifest-DZLr6Cbr.js → manifest-BV1YxozT.js} +1 -1
  331. package/dist/{manifest-DweZMH-F.d.ts → manifest-BVkjX2t-.d.ts} +1 -1
  332. package/dist/{manifest-RUmJ5H6p.d.ts → manifest-BVnfLMPU.d.ts} +2 -2
  333. package/dist/{manifest-BxuSAdYu.d.ts → manifest-BX7vyeYr.d.ts} +1 -1
  334. package/dist/{manifest-DBmuiJ91.d.ts → manifest-BYxKYFcH.d.ts} +1 -1
  335. package/dist/{manifest-BRFen7mE.js → manifest-Bb8S2tcs.js} +1 -1
  336. package/dist/{manifest-CfQ0nD_7.d.ts → manifest-Bcx4GSo0.d.ts} +1 -1
  337. package/dist/{manifest-fviCqeHj.d.ts → manifest-BeupHUUC.d.ts} +1 -1
  338. package/dist/{manifest-BAgvJODg.d.ts → manifest-BmI85ooO.d.ts} +1 -1
  339. package/dist/{manifest-Dh4AJeLl.d.ts → manifest-BoKnFQJK.d.ts} +1 -1
  340. package/dist/{manifest-DxPMUjhY.js → manifest-BvcIe5z_.js} +1 -1
  341. package/dist/{manifest-DWQaegX6.d.ts → manifest-BwwWlxof.d.ts} +1 -1
  342. package/dist/{manifest-BGD8cD6S.d.ts → manifest-Bx62hgMv.d.ts} +1 -1
  343. package/dist/{manifest-o-S9bj6i.d.ts → manifest-C1plIFth.d.ts} +1 -1
  344. package/dist/{manifest-upfKO7JJ.d.ts → manifest-C8-zVlM4.d.ts} +1 -1
  345. package/dist/{manifest-BCyCm0Z3.d.ts → manifest-CANbbLyM.d.ts} +1 -1
  346. package/dist/{manifest-DdxfAXvG.d.ts → manifest-CCQYjt7L.d.ts} +1 -1
  347. package/dist/{manifest-CAPSAozN.d.ts → manifest-CDIvE9Po.d.ts} +1 -1
  348. package/dist/{manifest-CDcaLpwB.d.ts → manifest-CJEzfFKP.d.ts} +1 -1
  349. package/dist/{manifest-BgVQ8xd3.d.ts → manifest-CLSlmLnn.d.ts} +1 -1
  350. package/dist/{manifest-KHudP5T5.d.ts → manifest-CV-9uzTU.d.ts} +1 -1
  351. package/dist/{manifest-Dc1eHEJV.d.ts → manifest-CYDtm5Yz.d.ts} +1 -1
  352. package/dist/{manifest-CcDqfRee.d.ts → manifest-Cb0BCYmS.d.ts} +1 -1
  353. package/dist/{manifest-BJs6pHI0.d.ts → manifest-Cc1r_IME.d.ts} +1 -1
  354. package/dist/{manifest-DGgFeLwd.d.ts → manifest-CeFiTTOx.d.ts} +1 -1
  355. package/dist/{manifest-CszjCxVJ.d.ts → manifest-Ch8G8wad.d.ts} +1 -1
  356. package/dist/{manifest-qs_U2rx3.d.ts → manifest-Ciu7htmT.d.ts} +1 -1
  357. package/dist/{manifest-H65OlXiB.js → manifest-CqJkmxrA.js} +1 -1
  358. package/dist/{manifest-xRlf8RQk.d.ts → manifest-CtvRTQoq.d.ts} +1 -1
  359. package/dist/{manifest-B24Ymu8p.d.ts → manifest-CxJtO760.d.ts} +1 -1
  360. package/dist/{manifest-BSkYvne3.d.ts → manifest-D2mvuqCe.d.ts} +1 -1
  361. package/dist/{manifest-B6EkxzC0.d.ts → manifest-D8o7ivPa.d.ts} +1 -1
  362. package/dist/{manifest-Cko_ySTe.d.ts → manifest-DAQAHnHf.d.ts} +1 -1
  363. package/dist/{manifest-2jLTjnVh.d.ts → manifest-DBUE3KbP.d.ts} +1 -1
  364. package/dist/{manifest-DCPKfwsh.d.ts → manifest-DElW3hfs.d.ts} +1 -1
  365. package/dist/{manifest-BrOXXz7k.d.ts → manifest-DFGW17h3.d.ts} +1 -1
  366. package/dist/{manifest-CL5QEu5B.d.ts → manifest-DGXOQgh3.d.ts} +1 -1
  367. package/dist/{manifest-BqBVKNjy.d.ts → manifest-DHV0zxVj.d.ts} +1 -1
  368. package/dist/{manifest-BHZEsuzC.d.ts → manifest-DKCc24tm.d.ts} +1 -1
  369. package/dist/{manifest-BxujRhsY.d.ts → manifest-DKk12W7u.d.ts} +1 -1
  370. package/dist/{manifest-BbC83cJB.d.ts → manifest-DOUGC7xP.d.ts} +1 -1
  371. package/dist/{manifest-BmLU5HtO.d.ts → manifest-DPQpIRCO.d.ts} +1 -1
  372. package/dist/{manifest-Csw2tVut.d.ts → manifest-DPXd-wZG.d.ts} +1 -1
  373. package/dist/{manifest-Ct6mHhg4.d.ts → manifest-D_tuEFvt.d.ts} +1 -1
  374. package/dist/{manifest-BtlEwVU4.d.ts → manifest-DbzB7NQP.d.ts} +1 -1
  375. package/dist/{manifest-Bg5Znp_u.d.ts → manifest-Dd0bmqd-.d.ts} +1 -1
  376. package/dist/{manifest-jSOZl7qT.d.ts → manifest-DebHyEiN.d.ts} +1 -1
  377. package/dist/{manifest-vG5iHhA5.d.ts → manifest-Doxj-elq.d.ts} +1 -1
  378. package/dist/{manifest-Oo7PegXK.d.ts → manifest-DujUV7Cu.d.ts} +1 -1
  379. package/dist/{manifest-DnGgZ9_F.d.ts → manifest-Duj_AN2H.d.ts} +1 -1
  380. package/dist/{manifest-CeoUoZDs.d.ts → manifest-DzN5YdbZ.d.ts} +1 -1
  381. package/dist/{manifest-Da1QZDY4.d.ts → manifest-P2Pzb1Jo.d.ts} +1 -1
  382. package/dist/{manifest-DPGJ2otk.d.ts → manifest-SEhx1LFs.d.ts} +1 -1
  383. package/dist/{manifest-DpF5bliV.d.ts → manifest-Se6qEw03.d.ts} +1 -1
  384. package/dist/{manifest-8JvRt8LB.d.ts → manifest-UHESrKBI.d.ts} +1 -1
  385. package/dist/{manifest-dXPq0ubY.d.ts → manifest-Ul7Uq35H.d.ts} +1 -1
  386. package/dist/{manifest-CH7g3uI3.d.ts → manifest-XpSrCsAV.d.ts} +1 -1
  387. package/dist/{manifest-2ZgzNTbP.d.ts → manifest-iRX3gQ3g.d.ts} +10 -1
  388. package/dist/{manifest-BUktyXMR.js → manifest-ok1ge1bM.js} +1 -1
  389. package/dist/{manifest-BHlKJbN2.d.ts → manifest-uRsVzPOJ.d.ts} +1 -1
  390. package/dist/{manifest-DevURQJj.js → manifest-vBvsSefP.js} +5 -1
  391. package/dist/{manifest-Bj5hfBA_.d.ts → manifest-x50nYF_4.d.ts} +1 -1
  392. package/dist/mapper/bin.js +6 -6
  393. package/dist/mcp/index.d.ts +1 -1
  394. package/dist/next/index.d.ts +7 -7
  395. package/dist/{operations-IzVAIMvs.d.ts → operations-Ce53BGJ0.d.ts} +1 -1
  396. package/dist/{options-CGQC7Wue.js → options-C1N8cOQU.js} +2 -1
  397. package/dist/{options-BTuDJ2RC.js → options-Cu6IqZ_n.js} +3 -1
  398. package/dist/{options-wBw_6uhd.js → options-Oo46IzNk.js} +2 -1
  399. package/dist/{orders-reads-Yo9GGjdv.js → orders-reads-2ozdZx1l.js} +108 -13
  400. package/dist/otel/index.js +4 -4
  401. package/dist/{payroll-export-T754eWz8.js → payroll-export-ChZY6W3w.js} +1 -1
  402. package/dist/{permissions-DxXor_NY.d.ts → permissions-Bi4WvjnM.d.ts} +1 -1
  403. package/dist/{ports-C5BEHQi6.d.ts → ports-TvLRuWgJ.d.ts} +1 -1
  404. package/dist/powersync/index.d.ts +3 -3
  405. package/dist/powersync/index.js +11 -3
  406. package/dist/preset/index.d.ts +4 -4
  407. package/dist/preset/index.js +3 -3
  408. package/dist/{preset-8Xh21Uyw.js → preset-CPUA9haY.js} +9 -3
  409. package/dist/{preview-B-mtB1ka.d.ts → preview-DvpfbcDY.d.ts} +2 -2
  410. package/dist/{project-C6JAWCnH.js → project-CkGGYXKd.js} +5 -5
  411. package/dist/{push-token-TWXWra8i.d.ts → push-token-GJUUE_6j.d.ts} +1 -1
  412. package/dist/query/index.d.ts +1 -1
  413. package/dist/react/index.d.ts +6 -6
  414. package/dist/react/native/index.d.ts +1 -1
  415. package/dist/react/server.d.ts +5 -5
  416. package/dist/realtime/index.d.ts +3 -3
  417. package/dist/{record-form-B9-7RhYz.d.ts → record-form-DhpdYw5e.d.ts} +1 -1
  418. package/dist/records/index.d.ts +7 -7
  419. package/dist/{sales-CLHrvNDm.js → sales-BhOckhix.js} +3 -3
  420. package/dist/server/index.d.ts +3 -3
  421. package/dist/solid/index.d.ts +5 -5
  422. package/dist/sql/index.d.ts +6 -6
  423. package/dist/sql/index.js +3 -3
  424. package/dist/{sql-Bam07JIf.js → sql-CFsIpR4t.js} +2515 -474
  425. package/dist/sqlite/index.d.ts +1 -1
  426. package/dist/ssr/index.d.ts +1 -1
  427. package/dist/svelte/index.d.ts +5 -5
  428. package/dist/tanstack-db/index.d.ts +1 -1
  429. package/dist/{tenant-BpJ2F2b_.d.ts → tenant-BTxVWIN6.d.ts} +1 -1
  430. package/dist/testing/index.d.ts +6 -6
  431. package/dist/testing/index.js +1 -1
  432. package/dist/{timeline-LHtdAJnM.d.ts → timeline-9r4mx0A2.d.ts} +2 -2
  433. package/dist/{topic-4KYLvvTB.d.ts → topic-_7QKu4b5.d.ts} +1 -1
  434. package/dist/{types-Dfa7b0KI.d.ts → types-C2qXUXjK.d.ts} +2 -2
  435. package/dist/vue/index.d.ts +5 -5
  436. package/dist/{watch-topic-C9DIO476.d.ts → watch-topic-Do0x41n3.d.ts} +1 -1
  437. package/dist/webmcp/index.d.ts +1 -1
  438. package/dist/yjs/index.d.ts +1 -1
  439. package/package.json +1 -1
  440. package/schemas/config-v1.json +64 -1
  441. package/skills/better-supabase-api/references/powersync.md +1 -0
  442. package/dist/cli/add-3L9NVEA3.js +0 -1
  443. package/dist/cli/powersync-COHj6FT8.js +0 -1
  444. package/dist/cli/seed-CRD1tYPA.js +0 -1
  445. package/dist/deadlines-values-B7ArpVJU.js +0 -127
@@ -2,20 +2,846 @@ import { B as textOf, C as optionalInstant, D as plainDateOf, K as rpcTransport,
2
2
  import { i as wrapTransport, n as extendBlock, r as withBlockHooks } from "../../block-hooks-Bd5bRM9B.js";
3
3
  import { t as requireTenant } from "../../block-tenant-DHvDBWgF.js";
4
4
  import { t as temporal } from "../../temporal-required-DK3ImZW6.js";
5
- import { c as validateDeadlineRules, n as DEADLINE_RESULTS, o as RULE_VERSION_STATUSES, r as DEADLINE_STATES, s as evaluateDeadlineRule } from "../../deadlines-values-B7ArpVJU.js";
5
+ import { _ as RULE_KEY, a as EXCEPTION_RESULTS, b as has, c as LAST_FURNISHING_FACT, d as OBSERVED_FALLS_ON, f as OBSERVED_MOVES, g as ROLL_DAYS, h as PART_STATUSES, i as DEADLINE_STATES, l as META_LIMIT, m as OFFSET_UNITS, n as DEADLINE_NAME, o as FIRST_FURNISHING_FACT, p as OFFSET_LIMIT, r as DEADLINE_RESULTS, s as ISO_DATE, t as DEADLINE_ADJUSTMENTS, u as NOTE_LIMIT, v as RULE_VERSION_STATUSES, x as isRecord, y as WEEKDAYS } from "../../deadlines-values-vmaCCdGl.js";
6
6
  import { n as defineBlock } from "../../define-block-D3uNVp2k.js";
7
7
  import { n as event, t as defineEvents } from "../../event-map-DLajpFiJ.js";
8
+ // src/sql/modules/deadlines-evaluate.ts
9
+ const DAY_MS = 864e5;
10
+ function fromParts(year, month, day) {
11
+ const date = /* @__PURE__ */ new Date(0);
12
+ date.setUTCFullYear(year, month - 1, day);
13
+ return Math.round(date.getTime() / DAY_MS);
14
+ }
15
+ function parts(days) {
16
+ const date = /* @__PURE__ */ new Date(days * DAY_MS);
17
+ return [
18
+ date.getUTCFullYear(),
19
+ date.getUTCMonth() + 1,
20
+ date.getUTCDate()
21
+ ];
22
+ }
23
+ /** Days since the epoch of an ISO date, or `undefined` when it isn't one. */
24
+ function parseDate(value) {
25
+ if (typeof value !== "string") return;
26
+ const match = ISO_DATE.exec(value);
27
+ if (match === null) return;
28
+ const year = Number(match[1]);
29
+ const month = Number(match[2]);
30
+ const day = Number(match[3]);
31
+ const days = fromParts(year, month, day);
32
+ const [y, m, d] = parts(days);
33
+ return year >= 1 && y === year && m === month && d === day ? days : void 0;
34
+ }
35
+ /** Whether a value is a valid ISO date string. */
36
+ function isIsoDate(value) {
37
+ return parseDate(value) !== void 0;
38
+ }
39
+ function format(days) {
40
+ return (/* @__PURE__ */ new Date(days * DAY_MS)).toISOString().slice(0, 10);
41
+ }
42
+ /** ISO day of the week: Monday 1 to Sunday 7. */
43
+ function isoDow(days) {
44
+ return ((days + 3) % 7 + 7) % 7 + 1;
45
+ }
46
+ function daysInMonth(year, month) {
47
+ return fromParts(year, month + 1, 1) - fromParts(year, month, 1);
48
+ }
49
+ function addMonths(days, months) {
50
+ const [year, month, day] = parts(days);
51
+ const total = year * 12 + month - 1 + months;
52
+ const y = Math.floor(total / 12);
53
+ const m = total - y * 12 + 1;
54
+ return fromParts(y, m, Math.min(day, daysInMonth(y, m)));
55
+ }
56
+ function monthStart(days) {
57
+ const [year, month] = parts(days);
58
+ return fromParts(year, month, 1);
59
+ }
60
+ function holidayListed(holiday, year) {
61
+ const { date } = holiday;
62
+ const last = daysInMonth(year, date.month);
63
+ if ("day" in date) return date.day > last ? void 0 : fromParts(year, date.month, date.day);
64
+ const wanted = WEEKDAYS.indexOf(date.weekday) + 1;
65
+ if (date.nth === "last") {
66
+ const end = fromParts(year, date.month, last);
67
+ return end - (isoDow(end) - wanted + 7) % 7;
68
+ }
69
+ const first = fromParts(year, date.month, 1);
70
+ const day = first + (wanted - isoDow(first) + 7) % 7 + (date.nth - 1) * 7;
71
+ return day - first < last ? day : void 0;
72
+ }
73
+ function fallsOn(days, on) {
74
+ switch (on) {
75
+ case "saturday": return isoDow(days) === 6;
76
+ case "sunday": return isoDow(days) === 7;
77
+ case "other_than_sunday": return isoDow(days) !== 7;
78
+ default: return on;
79
+ }
80
+ }
81
+ function observedDay(days, observe) {
82
+ const before = (weekday) => days - ((isoDow(days) - weekday + 6) % 7 + 1);
83
+ const after = (weekday) => days + ((weekday - isoDow(days) + 6) % 7 + 1);
84
+ switch (observe) {
85
+ case "preceding_friday": return before(5);
86
+ case "following_monday": return after(1);
87
+ case "preceding_sunday": return before(7);
88
+ case "following_sunday": return after(7);
89
+ default: return observe;
90
+ }
91
+ }
92
+ /** The days the holidays make holidays for the dates listed in a year. */
93
+ function holidaysOf(holidays, year) {
94
+ return holidays.flatMap((holiday) => {
95
+ const listed = holidayListed(holiday, year);
96
+ if (listed === void 0) return [];
97
+ const moved = (holiday.observed ?? []).filter((entry) => fallsOn(listed, entry.falls_on));
98
+ const observed = moved.map((entry) => observedDay(listed, entry.observe));
99
+ return moved.some((entry) => entry.replaces === true) ? observed : [listed, ...observed];
100
+ });
101
+ }
102
+ function isHoliday(counting, days) {
103
+ const holidays = counting?.holidays ?? [];
104
+ if (holidays.length === 0) return false;
105
+ const [year] = parts(days);
106
+ return [
107
+ year - 1,
108
+ year,
109
+ year + 1
110
+ ].some((y) => holidaysOf(holidays, y).includes(days));
111
+ }
112
+ function approved(counting) {
113
+ return counting !== void 0 && (counting.status ?? "approved") === "approved";
114
+ }
115
+ /** Not a weekend, and not a holiday of an approved counting block. */
116
+ function businessDay(counting, days) {
117
+ return isoDow(days) < 6 && !(approved(counting) && isHoliday(counting, days));
118
+ }
119
+ /** Moves a last day forward while it falls on a day the block rolls past. */
120
+ function roll(counting, days) {
121
+ if (counting === void 0 || !approved(counting)) return days;
122
+ const when = counting.roll_when;
123
+ let current = days;
124
+ while (when.includes("saturday") && isoDow(current) === 6 || when.includes("sunday") && isoDow(current) === 7 || when.includes("holiday") && isHoliday(counting, current)) current += 1;
125
+ return current;
126
+ }
127
+ function adjust(counting, days, how) {
128
+ if (how === "none") return days;
129
+ const step = how === "next_business_day" ? 1 : -1;
130
+ let current = days;
131
+ while (!businessDay(counting, current)) current += step;
132
+ return current;
133
+ }
134
+ function addCountDays(anchor, count, counting) {
135
+ const n = (count.n ?? 0) * (count.before === void 0 ? 1 : -1);
136
+ switch (count.unit) {
137
+ case void 0:
138
+ case "days": return anchor + n;
139
+ case "months": {
140
+ if (count.day_of_month === void 0) return addMonths(anchor, n);
141
+ const [year, month] = parts(addMonths(monthStart(anchor), n));
142
+ return fromParts(year, month, Math.min(count.day_of_month, daysInMonth(year, month)));
143
+ }
144
+ case "business_days": {
145
+ const step = n < 0 ? -1 : 1;
146
+ let current = anchor;
147
+ let left = Math.abs(n);
148
+ while (left > 0) {
149
+ current += step;
150
+ if (businessDay(counting, current)) left -= 1;
151
+ }
152
+ return current;
153
+ }
154
+ default: return count.unit;
155
+ }
156
+ }
157
+ function candidate(count, facts, counting) {
158
+ const fact = count.from ?? count.before ?? "";
159
+ if (!has(facts, fact)) return {
160
+ state: "unanswered",
161
+ asks: [fact]
162
+ };
163
+ if (facts[fact] === null) return { state: "skipped" };
164
+ const anchor = parseDate(facts[fact]);
165
+ return anchor === void 0 ? {
166
+ state: "unanswered",
167
+ asks: [fact]
168
+ } : {
169
+ state: "dated",
170
+ due: addCountDays(anchor, count, counting),
171
+ fact,
172
+ anchor
173
+ };
174
+ }
175
+ function countsOf(deadline) {
176
+ if (deadline === "none") return [];
177
+ if ("first_of" in deadline) return deadline.first_of;
178
+ if ("earlier_of" in deadline) return deadline.earlier_of;
179
+ if ("later_of" in deadline) return deadline.later_of;
180
+ return [deadline];
181
+ }
182
+ const asksOf = (candidates) => candidates.flatMap((c) => c.state === "unanswered" ? c.asks : []);
183
+ function skippedFrom(counts, candidates) {
184
+ return counts.flatMap((count, index) => count.from !== void 0 && candidates[index]?.state === "skipped" ? [count.from] : []);
185
+ }
186
+ function outcomeOf(deadline, facts, counting) {
187
+ if (deadline === void 0 || deadline === "none") return {
188
+ result: "undated",
189
+ due: null,
190
+ asks: [],
191
+ basis: null
192
+ };
193
+ const counts = countsOf(deadline);
194
+ const candidates = counts.map((count) => candidate(count, facts, counting));
195
+ const asks = asksOf(candidates);
196
+ const undated = {
197
+ result: asks.length > 0 ? "unknown" : "pending",
198
+ due: null,
199
+ asks,
200
+ basis: null
201
+ };
202
+ const dated = candidates.flatMap((c) => c.state === "dated" ? [c.due] : []);
203
+ if ("first_of" in deadline) {
204
+ const index = candidates.findIndex((c) => c.state === "dated");
205
+ const taken = candidates[index];
206
+ return taken?.state === "dated" ? {
207
+ result: "due",
208
+ due: taken.due,
209
+ asks: asksOf(candidates.slice(0, index)),
210
+ basis: {
211
+ anchor: {
212
+ fact: taken.fact,
213
+ date: format(taken.anchor)
214
+ },
215
+ without: skippedFrom(counts, candidates)
216
+ }
217
+ } : undated;
218
+ }
219
+ if ("earlier_of" in deadline) return dated.length === 0 ? undated : {
220
+ result: "due",
221
+ due: Math.min(...dated),
222
+ asks,
223
+ basis: {
224
+ anchor: null,
225
+ without: skippedFrom(counts, candidates)
226
+ }
227
+ };
228
+ if ("later_of" in deadline) return dated.length === 0 || asks.length > 0 ? undated : {
229
+ result: "due",
230
+ due: Math.max(...dated),
231
+ asks: [],
232
+ basis: {
233
+ anchor: null,
234
+ without: []
235
+ }
236
+ };
237
+ const [only] = candidates;
238
+ return only?.state === "dated" ? {
239
+ result: "due",
240
+ due: only.due,
241
+ asks: [],
242
+ basis: {
243
+ anchor: {
244
+ fact: only.fact,
245
+ date: format(only.anchor)
246
+ },
247
+ without: []
248
+ }
249
+ } : undated;
250
+ }
251
+ /** A deadline with a count before a fact never rolls. */
252
+ function rolls(deadline) {
253
+ return deadline !== void 0 && countsOf(deadline).every((count) => count.before === void 0);
254
+ }
255
+ function monthlyCount(deadline) {
256
+ return deadline !== void 0 && deadline !== "none" && !("first_of" in deadline) && !("earlier_of" in deadline) && !("later_of" in deadline) && deadline.each === "furnishing_month" ? deadline : void 0;
257
+ }
258
+ /**
259
+ * A monthly count's months as their first days, or what it waits for before it
260
+ * has any. The months run from the first furnishing through the last or, while
261
+ * furnishing goes on, through the month of `asOf` and one ahead.
262
+ */
263
+ function periodsOf(facts, asOf) {
264
+ if (facts["first_furnishing_date"] === null) return {
265
+ months: [],
266
+ asks: []
267
+ };
268
+ const first = parseDate(facts[FIRST_FURNISHING_FACT]);
269
+ if (first === void 0) return {
270
+ months: [],
271
+ asks: [FIRST_FURNISHING_FACT]
272
+ };
273
+ const last = parseDate(facts[LAST_FURNISHING_FACT]);
274
+ const ongoing = last === void 0 || last > asOf;
275
+ const end = monthStart(ongoing ? asOf : last);
276
+ const months = [];
277
+ let month = monthStart(first);
278
+ do {
279
+ months.push(month);
280
+ month = addMonths(month, 1);
281
+ } while (month <= end);
282
+ if (ongoing) months.push(month);
283
+ return {
284
+ months,
285
+ asks: []
286
+ };
287
+ }
288
+ /** A fact as an enum code: a string, or a number as its decimal text. */
289
+ function code(value) {
290
+ if (typeof value === "string") return value;
291
+ return typeof value === "number" ? String(value) : void 0;
292
+ }
293
+ function judgeEntry(facts, fact, expected) {
294
+ if (!has(facts, fact)) return "unknown";
295
+ const value = facts[fact];
296
+ if (expected === "present" || expected === "absent") return value !== null === (expected === "present");
297
+ if (value === null) return "unknown";
298
+ if (typeof expected === "boolean") return value === expected;
299
+ const text = code(value);
300
+ return typeof expected === "string" ? text === expected : text !== void 0 && expected.includes(text);
301
+ }
302
+ /** Three-valued AND over a condition's entries. */
303
+ function judge(condition, facts) {
304
+ const asks = [];
305
+ for (const [fact, expected] of Object.entries(condition ?? {})) {
306
+ const verdict = judgeEntry(facts, fact, expected);
307
+ if (verdict === false) return {
308
+ verdict: false,
309
+ asks: []
310
+ };
311
+ if (verdict === "unknown") asks.push(fact);
312
+ }
313
+ return {
314
+ verdict: asks.length > 0 ? "unknown" : true,
315
+ asks
316
+ };
317
+ }
318
+ function isRegime(value) {
319
+ return !(typeof value === "string" || typeof value === "boolean" || Array.isArray(value));
320
+ }
321
+ /**
322
+ * Whether a rule applies: its membership entries first, then its date regime. A
323
+ * regime whose date is unknown applies, and names the fact.
324
+ */
325
+ function applies(rule, facts) {
326
+ const membership = {};
327
+ let range;
328
+ for (const [fact, value] of Object.entries(rule.applies ?? {})) if (isRegime(value)) range = [fact, value];
329
+ else membership[fact] = value;
330
+ const judged = judge(membership, facts);
331
+ if (judged.verdict !== true || range === void 0) return {
332
+ ...judged,
333
+ regime: null
334
+ };
335
+ const [fact, { from, before }] = range;
336
+ const date = parseDate(facts[fact]);
337
+ if (date === void 0) return {
338
+ verdict: true,
339
+ asks: [],
340
+ regime: {
341
+ fact,
342
+ from: from ?? null
343
+ }
344
+ };
345
+ const value = format(date);
346
+ return {
347
+ verdict: (from === void 0 || value >= from) && (before === void 0 || value < before),
348
+ asks: [],
349
+ regime: null
350
+ };
351
+ }
352
+ /** The first rule of a group that applies, unless an earlier one is open. */
353
+ function selectRule(rules, facts) {
354
+ const asks = /* @__PURE__ */ new Set();
355
+ for (const rule of rules) {
356
+ const judged = applies(rule, facts);
357
+ if (judged.verdict === true && asks.size === 0) return {
358
+ kind: "rule",
359
+ rule,
360
+ regime: judged.regime
361
+ };
362
+ if (judged.verdict === "unknown") for (const fact of judged.asks) asks.add(fact);
363
+ }
364
+ return asks.size > 0 ? {
365
+ kind: "asks",
366
+ asks: [...asks]
367
+ } : { kind: "not_covered" };
368
+ }
369
+ const sorted = (names) => [...new Set(names)].toSorted();
370
+ function base(group) {
371
+ return {
372
+ group: group.key,
373
+ ruleKey: null,
374
+ period: null,
375
+ result: "not_covered",
376
+ dueOn: null,
377
+ provisional: false,
378
+ missing: [],
379
+ exception: null,
380
+ review: [],
381
+ basis: null,
382
+ deadline: null,
383
+ citation: group.citation
384
+ };
385
+ }
386
+ /**
387
+ * The exceptions of a rule in order: the first settled one whose `when` holds
388
+ * and whose `unless` doesn't decides. An unsettled one is carried for review,
389
+ * and an open one asks its facts.
390
+ */
391
+ function tripped(rule, facts) {
392
+ const asks = [];
393
+ const unsettled = [];
394
+ for (const exception of rule.exceptions ?? []) {
395
+ const when = judge(exception.when, facts);
396
+ const unless = exception.unless === void 0 ? {
397
+ verdict: false,
398
+ asks: []
399
+ } : judge(exception.unless, facts);
400
+ if (when.verdict === false || unless.verdict === true) continue;
401
+ if (when.verdict === true && unless.verdict === false) {
402
+ const { result } = exception;
403
+ if (result !== "review_required" && exception.status !== "review_required") return {
404
+ refused: { exception: {
405
+ ...exception,
406
+ result
407
+ } },
408
+ unsettled,
409
+ asks
410
+ };
411
+ unsettled.push({
412
+ kind: "exception",
413
+ name: exception.name,
414
+ citation: exception.citation,
415
+ ...exception.note === void 0 ? {} : { note: exception.note }
416
+ });
417
+ continue;
418
+ }
419
+ asks.push(...when.asks, ...unless.asks);
420
+ }
421
+ return {
422
+ refused: null,
423
+ unsettled,
424
+ asks
425
+ };
426
+ }
427
+ function evaluateGroup(content, group, facts, asOf) {
428
+ const empty = base(group);
429
+ const selection = selectRule(content.rules.filter((rule) => rule.group === group.key), facts);
430
+ if (selection.kind === "asks") return [{
431
+ ...empty,
432
+ result: "unknown",
433
+ missing: sorted(selection.asks)
434
+ }];
435
+ if (selection.kind === "not_covered") return [empty];
436
+ const { rule, regime } = selection;
437
+ const status = rule.status ?? "approved";
438
+ const regimeMarks = regime === null ? [] : [{
439
+ kind: "regime",
440
+ ...regime
441
+ }];
442
+ const ruleMarks = status === "approved" ? [] : [{
443
+ kind: "rule",
444
+ status
445
+ }];
446
+ const selected = {
447
+ ...empty,
448
+ ruleKey: rule.key,
449
+ deadline: rule.deadline ?? null,
450
+ citation: rule.citation
451
+ };
452
+ const finish = (result, asks, review) => {
453
+ const missing = sorted([...regime === null ? [] : [regime.fact], ...asks]);
454
+ return {
455
+ ...result,
456
+ missing,
457
+ provisional: result.result !== "unknown" && missing.length > 0,
458
+ review: [
459
+ ...regimeMarks,
460
+ ...review,
461
+ ...ruleMarks
462
+ ]
463
+ };
464
+ };
465
+ if (rule.required === false) return [finish({
466
+ ...selected,
467
+ result: "not_required",
468
+ citation: group.citation
469
+ }, [], [])];
470
+ const exceptions = tripped(rule, facts);
471
+ if (exceptions.refused !== null) {
472
+ const { exception } = exceptions.refused;
473
+ return [finish({
474
+ ...selected,
475
+ result: exception.result,
476
+ exception: {
477
+ name: exception.name,
478
+ citation: exception.citation,
479
+ ...exception.remedy === void 0 ? {} : { remedy: exception.remedy },
480
+ ...exception.note === void 0 ? {} : { note: exception.note }
481
+ }
482
+ }, exceptions.asks, [])];
483
+ }
484
+ const counting = content.counting ?? void 0;
485
+ const countingMarks = counting === void 0 || approved(counting) ? [] : [{
486
+ kind: "counting",
487
+ status: counting.status ?? "approved"
488
+ }];
489
+ const dated = (days) => format(adjust(counting, rolls(rule.deadline) ? roll(counting, days) : days, rule.adjust ?? "none"));
490
+ const monthly = monthlyCount(rule.deadline);
491
+ if (monthly !== void 0) {
492
+ const { months, asks } = periodsOf(facts, asOf);
493
+ if (months.length === 0) return [finish({
494
+ ...selected,
495
+ result: asks.length > 0 ? "unknown" : "pending"
496
+ }, [...exceptions.asks, ...asks], exceptions.unsettled)];
497
+ return months.map((start) => finish({
498
+ ...selected,
499
+ result: "due",
500
+ period: format(start).slice(0, 7),
501
+ dueOn: dated(addCountDays(start, monthly, counting)),
502
+ basis: {
503
+ anchor: {
504
+ fact: monthly.from ?? "",
505
+ date: format(start)
506
+ },
507
+ without: []
508
+ }
509
+ }, exceptions.asks, [...exceptions.unsettled, ...countingMarks]));
510
+ }
511
+ const outcome = outcomeOf(rule.deadline, facts, counting);
512
+ return [finish({
513
+ ...selected,
514
+ result: outcome.result,
515
+ dueOn: outcome.due === null ? null : dated(outcome.due),
516
+ basis: outcome.basis
517
+ }, [...exceptions.asks, ...outcome.asks], outcome.result === "due" ? [...exceptions.unsettled, ...countingMarks] : exceptions.unsettled)];
518
+ }
519
+ const OPEN_RESULTS = /* @__PURE__ */ new Set([
520
+ "due",
521
+ "unknown",
522
+ "pending",
523
+ "undated"
524
+ ]);
525
+ /**
526
+ * A group that requires a barred group is barred with it, to a fixed point.
527
+ * Only a group without a refusal of its own falls.
528
+ */
529
+ function cascade(results, groups) {
530
+ let changed = true;
531
+ while (changed) {
532
+ changed = false;
533
+ for (const group of groups) {
534
+ const [first] = results.get(group.key) ?? [];
535
+ if (first === void 0 || !OPEN_RESULTS.has(first.result)) continue;
536
+ const barring = (group.requires ?? []).map((key) => results.get(key)?.[0]).find((result) => result?.result === "barred");
537
+ if (barring?.exception === void 0 || barring.exception === null) continue;
538
+ results.set(group.key, [{
539
+ ...first,
540
+ period: null,
541
+ result: "barred",
542
+ dueOn: null,
543
+ provisional: false,
544
+ missing: [],
545
+ basis: null,
546
+ review: first.review.filter((mark) => mark.kind !== "exception" && mark.kind !== "counting"),
547
+ exception: {
548
+ name: barring.exception.name,
549
+ citation: barring.exception.citation,
550
+ note: `falls with ${barring.group}`
551
+ }
552
+ }]);
553
+ changed = true;
554
+ }
555
+ }
556
+ }
557
+ /** A group and every group it requires, transitively. */
558
+ function closure(groups, key) {
559
+ const keys = /* @__PURE__ */ new Set();
560
+ const queue = [key];
561
+ while (queue.length > 0) {
562
+ const next = queue.shift() ?? "";
563
+ if (!keys.has(next)) {
564
+ keys.add(next);
565
+ queue.push(...groups.find((g) => g.key === next)?.requires ?? []);
566
+ }
567
+ }
568
+ return keys;
569
+ }
570
+ function today() {
571
+ return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
572
+ }
573
+ /**
574
+ * Evaluates a rule set version for a subject's facts: one result per group in
575
+ * the version's order (one per month for a periodic rule), or only `group`'s.
576
+ * `asOf` (today by default) ends a periodic rule's months while furnishing goes
577
+ * on. The SQL function `evaluate_deadlines` returns the same results.
578
+ */
579
+ function evaluateVersion$1(content, facts, asOf = today(), group) {
580
+ const day = parseDate(asOf);
581
+ if (day === void 0) throw new RangeError(`asOf is not an ISO date: ${asOf}`);
582
+ const wanted = group === void 0 ? void 0 : closure(content.groups, group);
583
+ const evaluated = content.groups.filter((g) => wanted === void 0 || wanted.has(g.key));
584
+ const results = new Map(evaluated.map((g) => [g.key, evaluateGroup(content, g, facts, day)]));
585
+ cascade(results, evaluated);
586
+ return evaluated.filter((g) => group === void 0 || g.key === group).flatMap((g) => results.get(g.key) ?? []);
587
+ }
588
+ // src/sql/modules/deadlines-validate.ts
589
+ const list = (values) => values.join(", ");
590
+ /** Length in code points, as `char_length` counts it. */
591
+ const characters = (value) => value.length - (value.match(/[\u{10000}-\u{10FFFF}]/gu)?.length ?? 0);
592
+ const keysOf = (value) => Object.keys(value).toSorted();
593
+ /** Bytes of a value's jsonb text: JSON with a space after each `:` and `,`. */
594
+ function jsonbBytes(value) {
595
+ let separators = 0;
596
+ const walk = (node) => {
597
+ const children = Array.isArray(node) ? node : isRecord(node) ? Object.values(node) : [];
598
+ separators += Math.max(children.length - 1, 0) + (isRecord(node) ? children.length : 0);
599
+ for (const child of children) walk(child);
600
+ };
601
+ walk(value);
602
+ return new TextEncoder().encode(JSON.stringify(value)).length + separators;
603
+ }
604
+ function badMeta(value) {
605
+ return !isRecord(value) || jsonbBytes(value) > 32768;
606
+ }
607
+ function isText(value, max) {
608
+ return typeof value === "string" && characters(value) <= max;
609
+ }
610
+ function isName(value) {
611
+ return typeof value === "string" && DEADLINE_NAME.test(value);
612
+ }
613
+ function isWhole(value, min, max) {
614
+ return typeof value === "number" && Number.isInteger(value) && value >= min && value <= max;
615
+ }
616
+ function oneOf(values, value) {
617
+ return values.some((entry) => entry === value);
618
+ }
619
+ function badCitation(value) {
620
+ return !isRecord(value) || typeof value["reference"] !== "string" || value["reference"].trim() === "";
621
+ }
622
+ function isDate(value) {
623
+ return isIsoDate(value);
624
+ }
625
+ function codes(value) {
626
+ return Array.isArray(value) && value.length > 0 && value.every((entry) => typeof entry === "string" && entry !== "") && new Set(value).size === value.length;
627
+ }
628
+ function badCondition(value, nonEmpty) {
629
+ if (!isRecord(value)) return true;
630
+ const entries = Object.entries(value);
631
+ return nonEmpty && entries.length === 0 || entries.some(([fact, expected]) => !isName(fact) || !(typeof expected === "boolean" || typeof expected === "string" && expected !== "" || codes(expected)));
632
+ }
633
+ function countsBefore(node) {
634
+ if (Array.isArray(node)) return node.some(countsBefore);
635
+ return isRecord(node) && ("before" in node || Object.values(node).some(countsBefore));
636
+ }
637
+ function countIssues(count, at, inside) {
638
+ if (!isRecord(count)) return [`${at} must be a count`];
639
+ const issues = [];
640
+ const { from, before, n, unit } = count;
641
+ if (from === void 0 === (before === void 0) || from !== void 0 && !isName(from) || before !== void 0 && !isName(before)) issues.push(`${at} counts from or before one fact`);
642
+ if (n !== void 0 && !isWhole(n, 0, 3650)) issues.push(`${at} n is a whole number from 0 to ${OFFSET_LIMIT}`);
643
+ if (unit !== void 0 && !oneOf(OFFSET_UNITS, unit)) issues.push(`${at} unit is ${list(OFFSET_UNITS)}`);
644
+ if (n !== void 0 && unit === void 0) issues.push(`${at} n needs a unit`);
645
+ if (from !== void 0 && n === void 0) issues.push(`${at} from needs n`);
646
+ if (count["day_of_month"] !== void 0 && (!isWhole(count["day_of_month"], 1, 28) || unit !== "months")) issues.push(`${at} day_of_month is 1 to 28 with unit months`);
647
+ if (count["each"] !== void 0) {
648
+ if (inside) issues.push(`${at} each is not allowed inside a combinator`);
649
+ else if (count["each"] !== "furnishing_month" || from === void 0 || n === void 0) issues.push(`${at} each is furnishing_month on a count from a fact`);
650
+ }
651
+ return issues;
652
+ }
653
+ const COMBINATORS = [
654
+ "first_of",
655
+ "earlier_of",
656
+ "later_of"
657
+ ];
658
+ function deadlineIssues(deadline, at) {
659
+ if (deadline === "none") return [];
660
+ const notADeadline = `${at} deadline is none, a count, or ${list(COMBINATORS)} with at least two counts`;
661
+ if (!isRecord(deadline)) return [notADeadline];
662
+ const combinator = COMBINATORS.find((key) => has(deadline, key));
663
+ if (combinator === void 0) return countIssues(deadline, `${at} deadline`, false);
664
+ const counts = deadline[combinator];
665
+ if (Object.keys(deadline).length !== 1 || !Array.isArray(counts) || counts.length < 2) return [notADeadline];
666
+ return counts.flatMap((count, index) => countIssues(count, `${at} deadline ${combinator} ${index + 1}`, true));
667
+ }
668
+ function appliesIssues(value, at) {
669
+ if (!isRecord(value)) return [`${at} applies must be an object`];
670
+ const issues = [];
671
+ let regimes = 0;
672
+ for (const fact of keysOf(value)) {
673
+ const entry = value[fact];
674
+ if (!DEADLINE_NAME.test(fact)) issues.push(`${at} applies ${fact} is not a fact name`);
675
+ else if (isRecord(entry)) {
676
+ regimes += 1;
677
+ const { from, before } = entry;
678
+ if (keysOf(entry).some((key) => key !== "from" && key !== "before") || from === void 0 && before === void 0 || from !== void 0 && !isDate(from) || before !== void 0 && !isDate(before) || isDate(from) && isDate(before) && from >= before) issues.push(`${at} applies ${fact} is a date range from before before`);
679
+ } else if (!(entry === "present" || entry === "absent" || codes(entry))) issues.push(`${at} applies ${fact} is a list of codes, present or absent`);
680
+ }
681
+ if (regimes > 1) issues.push(`${at} selects by one date at most`);
682
+ return issues;
683
+ }
684
+ function exceptionIssues(exceptions, at) {
685
+ if (!Array.isArray(exceptions)) return [`${at} exceptions must be a list`];
686
+ const issues = [];
687
+ const names = /* @__PURE__ */ new Set();
688
+ for (const [index, exception] of exceptions.entries()) {
689
+ const here = `${at} exception ${index + 1}`;
690
+ if (!isRecord(exception)) {
691
+ issues.push(`${here} must be an object`);
692
+ continue;
693
+ }
694
+ const { name } = exception;
695
+ if (!isName(name)) issues.push(`${here} needs a name in lower case letters, digits and _`);
696
+ else if (names.has(name)) issues.push(`${here} repeats the name ${name}`);
697
+ else names.add(name);
698
+ if (badCondition(exception["when"], true)) issues.push(`${here} when is a non-empty condition`);
699
+ if (exception["unless"] !== void 0 && badCondition(exception["unless"], false)) issues.push(`${here} unless is a condition`);
700
+ if (!oneOf(EXCEPTION_RESULTS, exception["result"])) issues.push(`${here} result is ${list(EXCEPTION_RESULTS)}`);
701
+ if (exception["remedy"] !== void 0 && !isText(exception["remedy"], 500)) issues.push(`${here} remedy is text of at most 500 characters`);
702
+ if (exception["note"] !== void 0 && !isText(exception["note"], 2e3)) issues.push(`${here} note is text of at most ${NOTE_LIMIT} characters`);
703
+ if (exception["status"] !== void 0 && !oneOf(PART_STATUSES, exception["status"])) issues.push(`${here} status is ${list(PART_STATUSES)}`);
704
+ if (badCitation(exception["citation"])) issues.push(`${here} needs a citation with a reference`);
705
+ }
706
+ return issues;
707
+ }
708
+ function requiresCycle(requires, start) {
709
+ return (requires.get(start) ?? []).find((next) => {
710
+ const seen = /* @__PURE__ */ new Set();
711
+ const queue = [next];
712
+ while (queue.length > 0) {
713
+ const key = queue.shift() ?? "";
714
+ if (key === start) return true;
715
+ if (!seen.has(key)) {
716
+ seen.add(key);
717
+ queue.push(...requires.get(key) ?? []);
718
+ }
719
+ }
720
+ return false;
721
+ });
722
+ }
723
+ function groupIssues(groups) {
724
+ const issues = [];
725
+ const keys = /* @__PURE__ */ new Set();
726
+ for (const [index, group] of groups.entries()) {
727
+ const at = `group ${index + 1}`;
728
+ if (!isRecord(group)) {
729
+ issues.push(`${at} must be an object`);
730
+ continue;
731
+ }
732
+ const { key } = group;
733
+ if (!isName(key)) issues.push(`${at} needs a key in lower case letters, digits and _`);
734
+ else if (keys.has(key)) issues.push(`${at} repeats the key ${key}`);
735
+ else keys.add(key);
736
+ if (group["title"] !== void 0 && !isText(group["title"], 200)) issues.push(`${at} title is text of at most 200 characters`);
737
+ if (badCitation(group["citation"])) issues.push(`${at} needs a citation with a reference`);
738
+ if (group["meta"] !== void 0 && badMeta(group["meta"])) issues.push(`${at} meta must be an object of at most ${META_LIMIT} bytes`);
739
+ }
740
+ const requires = /* @__PURE__ */ new Map();
741
+ for (const [index, group] of groups.entries()) {
742
+ if (!isRecord(group) || group["requires"] === void 0) continue;
743
+ const named = group["requires"];
744
+ const valid = [];
745
+ if (Array.isArray(named) && named.every((key) => {
746
+ const ok = typeof key === "string" && keys.has(key) && key !== group["key"];
747
+ if (ok) valid.push(key);
748
+ return ok;
749
+ })) {
750
+ if (typeof group["key"] === "string") requires.set(group["key"], valid);
751
+ } else issues.push(`group ${index + 1} requires is a list of other group keys`);
752
+ }
753
+ for (const [index, group] of groups.entries()) {
754
+ const start = isRecord(group) ? group["key"] : void 0;
755
+ const through = typeof start === "string" ? requiresCycle(requires, start) : void 0;
756
+ if (through !== void 0) issues.push(`group ${index + 1} requires itself through ${through}`);
757
+ }
758
+ return issues;
759
+ }
760
+ function ruleIssues(rules, groups) {
761
+ const issues = [];
762
+ const keys = /* @__PURE__ */ new Set();
763
+ const known = new Set(groups.flatMap((group) => isRecord(group) && typeof group["key"] === "string" ? [group["key"]] : []));
764
+ for (const [index, rule] of rules.entries()) {
765
+ const at = `rule ${index + 1}`;
766
+ if (!isRecord(rule)) {
767
+ issues.push(`${at} must be an object`);
768
+ continue;
769
+ }
770
+ const { key } = rule;
771
+ if (typeof key !== "string" || !RULE_KEY.test(key)) issues.push(`${at} needs a key in lower case letters, digits and _`);
772
+ else if (keys.has(key)) issues.push(`${at} repeats the key ${key}`);
773
+ else keys.add(key);
774
+ if (typeof rule["group"] !== "string" || !known.has(rule["group"])) issues.push(`${at} needs a group that the version lists`);
775
+ if (rule["title"] !== void 0 && !isText(rule["title"], 200)) issues.push(`${at} title is text of at most 200 characters`);
776
+ if (rule["status"] !== void 0 && !oneOf(PART_STATUSES, rule["status"])) issues.push(`${at} status is ${list(PART_STATUSES)}`);
777
+ if (rule["adjust"] !== void 0 && !oneOf(DEADLINE_ADJUSTMENTS, rule["adjust"])) issues.push(`${at} adjust is ${list(DEADLINE_ADJUSTMENTS)}`);
778
+ if (rule["adjust"] === "next_business_day" && countsBefore(rule["deadline"])) issues.push(`${at} adjust next_business_day never follows a before count`);
779
+ if (rule["required"] !== void 0 && typeof rule["required"] !== "boolean") issues.push(`${at} required is true or false`);
780
+ if (badCitation(rule["citation"])) issues.push(`${at} needs a citation with a reference`);
781
+ if (rule["applies"] !== void 0) issues.push(...appliesIssues(rule["applies"], at));
782
+ if (rule["deadline"] !== void 0) issues.push(...deadlineIssues(rule["deadline"], at));
783
+ if (rule["exceptions"] !== void 0) issues.push(...exceptionIssues(rule["exceptions"], at));
784
+ if (rule["meta"] !== void 0 && badMeta(rule["meta"])) issues.push(`${at} meta must be an object of at most ${META_LIMIT} bytes`);
785
+ }
786
+ return issues;
787
+ }
788
+ function holidayIssues(holiday, at) {
789
+ if (!isRecord(holiday)) return [`${at} must be an object`];
790
+ const issues = [];
791
+ const { name, date, observed } = holiday;
792
+ if (typeof name !== "string" || name === "" || !isText(name, 200)) issues.push(`${at} needs a name of at most 200 characters`);
793
+ const fixed = isRecord(date) && keysOf(date).join(",") === "day,month" && isWhole(date["month"], 1, 12) && isWhole(date["day"], 1, 31);
794
+ const nth = isRecord(date) && keysOf(date).join(",") === "month,nth,weekday" && isWhole(date["month"], 1, 12) && oneOf(WEEKDAYS, date["weekday"]) && (date["nth"] === "last" || isWhole(date["nth"], 1, 5));
795
+ if (!fixed && !nth) issues.push(`${at} date is a month and day, or a month, weekday and nth`);
796
+ if (badCitation(holiday["citation"])) issues.push(`${at} needs a citation with a reference`);
797
+ if (observed === void 0) return issues;
798
+ if (!Array.isArray(observed)) return [...issues, `${at} observed must be a list`];
799
+ for (const [index, entry] of observed.entries()) if (!isRecord(entry) || !oneOf(OBSERVED_FALLS_ON, entry["falls_on"]) || !oneOf(OBSERVED_MOVES, entry["observe"]) || entry["replaces"] !== void 0 && typeof entry["replaces"] !== "boolean" || badCitation(entry["citation"])) issues.push(`${at} observed ${index + 1} needs falls_on, observe and a citation`);
800
+ return issues;
801
+ }
802
+ function countingIssues(counting) {
803
+ const issues = [];
804
+ if (counting["roll_to"] !== "next_business_day") issues.push("counting roll_to is next_business_day");
805
+ const when = counting["roll_when"];
806
+ if (!Array.isArray(when) || when.length === 0 || !when.every((day) => oneOf(ROLL_DAYS, day)) || new Set(when).size !== when.length) issues.push(`counting roll_when is a non-empty list of ${list(ROLL_DAYS)}`);
807
+ const holidays = counting["holidays"];
808
+ if (Array.isArray(holidays)) for (const [index, holiday] of holidays.entries()) issues.push(...holidayIssues(holiday, `counting holiday ${index + 1}`));
809
+ else if (holidays !== void 0) issues.push("counting holidays must be a list");
810
+ if (counting["citation"] !== void 0 && badCitation(counting["citation"])) issues.push("counting citation needs a reference");
811
+ if (counting["status"] !== void 0 && !oneOf(PART_STATUSES, counting["status"])) issues.push(`counting status is ${list(PART_STATUSES)}`);
812
+ return issues;
813
+ }
814
+ /**
815
+ * The problems of a rule set version's content, empty when it can be saved. The
816
+ * SQL function `validate_deadline_rules` finds the same ones, in the same
817
+ * order.
818
+ */
819
+ function validateRuleVersion$1(content) {
820
+ if (!isRecord(content)) return ["a rule set version is an object with rules and groups"];
821
+ const { rules, groups, counting, meta } = content;
822
+ const empty = [];
823
+ if (!Array.isArray(rules) || rules.length === 0) empty.push("a rule set version needs a non-empty list of rules");
824
+ if (!Array.isArray(groups) || groups.length === 0) empty.push("a rule set version needs a non-empty list of groups");
825
+ if (!Array.isArray(rules) || !Array.isArray(groups) || empty.length > 0) return empty;
826
+ const issues = [...groupIssues(groups), ...ruleIssues(rules, groups)];
827
+ if (isRecord(counting)) issues.push(...countingIssues(counting));
828
+ else if (counting !== void 0 && counting !== null) issues.push("counting must be an object");
829
+ if (meta !== void 0 && meta !== null && badMeta(meta)) issues.push(`meta must be an object of at most ${META_LIMIT} bytes`);
830
+ return issues;
831
+ }
8
832
  // src/blocks/deadlines/deadlines.ts
9
833
  /**
10
- * Evaluates one rule against facts in TypeScript, with the same result as the
11
- * database. Use it to preview a draft or to show a date without a round trip.
834
+ * Evaluates a rule set version against facts in TypeScript, with the same
835
+ * results as the database: one per group (one per month for a periodic rule),
836
+ * or only `group`'s. Use it to preview a draft or to show dates without a round
837
+ * trip. `asOf` is an ISO date, today by default.
12
838
  */
13
- function evaluateRule(rule, facts) {
14
- return evaluateDeadlineRule(rule, facts);
839
+ function evaluateVersion(content, facts, asOf, group) {
840
+ return evaluateVersion$1(content, facts, asOf === void 0 ? void 0 : asOf.toString(), group);
15
841
  }
16
- /** The problems of a rule list, or an empty array when it can be saved. */
17
- function validateRules(rules) {
18
- return validateDeadlineRules(rules);
842
+ /** The problems of a version's content, or an empty array when it can be saved. */
843
+ function validateRuleVersion(content) {
844
+ return validateRuleVersion$1(content);
19
845
  }
20
846
  function objectOf(value) {
21
847
  return typeof value === "object" && value !== null && !Array.isArray(value) ? Object.fromEntries(Object.entries(value)) : {};
@@ -23,9 +849,12 @@ function objectOf(value) {
23
849
  function optionalText(value) {
24
850
  return typeof value === "string" ? value : void 0;
25
851
  }
26
- function isRule(value) {
852
+ function isKeyed(value) {
27
853
  return typeof value === "object" && value !== null && "key" in value;
28
854
  }
855
+ function isObject(value) {
856
+ return typeof value === "object" && value !== null && !Array.isArray(value);
857
+ }
29
858
  function versionOf(value, fn) {
30
859
  const row = recordOf(value, fn);
31
860
  const effectiveFrom = row["effectiveFrom"];
@@ -38,8 +867,11 @@ function versionOf(value, fn) {
38
867
  kind: textOf(row["kind"]),
39
868
  version: Number(row["version"]),
40
869
  status: enumOrThrow(row["status"], RULE_VERSION_STATUSES, "rule status"),
41
- rules: Array.isArray(row["rules"]) ? row["rules"].filter(isRule) : [],
870
+ rules: Array.isArray(row["rules"]) ? row["rules"].filter((rule) => isKeyed(rule)) : [],
871
+ groups: Array.isArray(row["groups"]) ? row["groups"].filter((group) => isKeyed(group)) : [],
42
872
  createdAt: temporal().Instant.from(textOf(row["createdAt"])),
873
+ ...isObject(row["counting"]) ? { counting: row["counting"] } : {},
874
+ ...isObject(row["meta"]) ? { meta: row["meta"] } : {},
43
875
  ...contentHash === void 0 ? {} : { contentHash },
44
876
  ...typeof effectiveFrom === "string" ? { effectiveFrom: plainDateOf(effectiveFrom, "effectiveFrom") } : {},
45
877
  ...approvedBy === void 0 ? {} : { approvedBy },
@@ -52,6 +884,8 @@ function deadlineOf(value, fn) {
52
884
  const satisfiedAt = optionalInstant(row["satisfiedAt"]);
53
885
  const satisfiedBy = optionalText(row["satisfiedBy"]);
54
886
  const satisfiedAction = optionalText(row["satisfiedAction"]);
887
+ const ruleKey = optionalText(row["ruleKey"]);
888
+ const period = optionalText(row["period"]);
55
889
  const citation = objectOf(row["citation"]);
56
890
  const url = optionalText(citation["url"]);
57
891
  const text = optionalText(citation["text"]);
@@ -62,11 +896,19 @@ function deadlineOf(value, fn) {
62
896
  subjectId: textOf(row["subjectId"]),
63
897
  jurisdiction: textOf(row["jurisdiction"]),
64
898
  kind: textOf(row["kind"]),
65
- ruleKey: textOf(row["ruleKey"]),
899
+ groupKey: textOf(row["groupKey"]),
66
900
  ruleVersionId: textOf(row["ruleVersionId"]),
67
901
  facts: objectOf(row["facts"]),
68
902
  result: enumOrThrow(row["result"], DEADLINE_RESULTS, "deadline result"),
903
+ provisional: row["provisional"] === true,
69
904
  missing: Array.isArray(row["missing"]) ? row["missing"].map((item) => textOf(item)) : [],
905
+ review: Array.isArray(row["review"]) ? row["review"].filter((mark) => isObject(mark)) : [],
906
+ asOf: plainDateOf(textOf(row["asOf"]), "asOf"),
907
+ ...ruleKey === void 0 ? {} : { ruleKey },
908
+ ...period === void 0 ? {} : { period },
909
+ ...isObject(row["exception"]) ? { exception: row["exception"] } : {},
910
+ ...isObject(row["basis"]) ? { basis: row["basis"] } : {},
911
+ ...row["deadline"] === "none" || isObject(row["deadline"]) ? { deadline: row["deadline"] } : {},
70
912
  citation: {
71
913
  reference: textOf(citation["reference"]),
72
914
  ...url === void 0 ? {} : { url },
@@ -84,8 +926,8 @@ function deadlineOf(value, fn) {
84
926
  }
85
927
  /**
86
928
  * Deadlines: rule sets owned by the platform, versioned and approved once, and
87
- * the deadlines computed from a subject's facts. A rule whose facts are not all
88
- * known yields `unknown` with the facts it waits for, never a guess.
929
+ * the deadlines computed from a subject's facts. A deadline whose facts are not
930
+ * all known is `unknown` with the facts it waits for, never a guess.
89
931
  */
90
932
  function createDeadlines(options) {
91
933
  applyTemporal(options);
@@ -95,7 +937,7 @@ function createDeadlines(options) {
95
937
  saveRules: (input) => call("save_rule_version", {
96
938
  jurisdiction: input.jurisdiction,
97
939
  kind: input.kind,
98
- rules: input.rules,
940
+ content: input.content,
99
941
  ...input.effectiveFrom === void 0 ? {} : { effective_from: input.effectiveFrom.toString() },
100
942
  ...input.title === void 0 ? {} : { title: input.title }
101
943
  }, (value) => versionOf(value, "save_rule_version")),
@@ -109,16 +951,16 @@ function createDeadlines(options) {
109
951
  kind,
110
952
  ...date === void 0 ? {} : { on_date: date.toString() }
111
953
  }, (value) => value === null || value === void 0 ? void 0 : versionOf(value, "rule_version_at")),
112
- compute: (input) => tenant().andThen((organizationId) => call("compute_deadline", {
954
+ compute: (input) => tenant().andThen((organizationId) => call("compute_deadlines", {
113
955
  tenant: organizationId,
114
956
  subject_type: input.subjectType,
115
957
  subject_id: input.subjectId,
116
958
  jurisdiction: input.jurisdiction,
117
959
  kind: input.kind,
118
- rule_key: input.ruleKey,
119
960
  facts: input.facts,
120
- ...input.asOf === void 0 ? {} : { as_of: input.asOf.toString() }
121
- }, (value) => deadlineOf(value, "compute_deadline"))),
961
+ ...input.asOf === void 0 ? {} : { as_of: input.asOf.toString() },
962
+ ...input.group === void 0 ? {} : { group_key: input.group }
963
+ }, (value) => recordsOf(value, "compute_deadlines").map((row) => deadlineOf(row, "compute_deadlines")))),
122
964
  recompute: (input) => tenant().andThen((organizationId) => call("recompute_deadlines", {
123
965
  tenant: organizationId,
124
966
  subject_type: input.subjectType,
@@ -154,6 +996,6 @@ const deadlinesBlock = /* @__PURE__ */ defineBlock({
154
996
  create: createDeadlines,
155
997
  recipes: [],
156
998
  category: "work",
157
- description: "Platform-owned rule sets per jurisdiction and kind, versioned and approved once with a content hash and a citation per rule, and the deadlines computed from a subject's facts: due on a date or unknown with the facts still missing."
999
+ description: "Platform-owned rule sets per jurisdiction and kind, versioned and approved once with a content hash: groups of cited rules with conditions, exceptions and counts, and the deadlines computed from a subject's facts per group: due on a date, unknown with the facts still missing, or the reason there is none."
158
1000
  });
159
- export { createDeadlines, dbTransport, deadlinesBlock, deadlinesEvents, evaluateRule, extendBlock, rpcTransport, sqlTransport, validateRules, withBlockHooks, wrapTransport };
1001
+ export { createDeadlines, dbTransport, deadlinesBlock, deadlinesEvents, evaluateVersion, extendBlock, rpcTransport, sqlTransport, validateRuleVersion, withBlockHooks, wrapTransport };