better-supabase 0.55.0 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agents-CBXJce8J.d.ts → agents-BXjBzFlb.d.ts} +2 -2
- package/dist/{ai-schedules-CtwkMJDZ.d.ts → ai-schedules-F9MS-bie.d.ts} +1 -1
- package/dist/ai-sdk/agents/index.d.ts +1 -1
- package/dist/ai-sdk/workflow/index.d.ts +1 -1
- package/dist/{app-tables-BsDmauWB.d.ts → app-tables-DypEnAID.d.ts} +1 -1
- package/dist/{authorization-DK7YSiFV.d.ts → authorization-CRKL2OFQ.d.ts} +1 -1
- package/dist/{bind-DiGmjHzz.d.ts → bind-DEPqZLwv.d.ts} +3 -3
- package/dist/{block-env-BTKZBCL4.d.ts → block-env-CAdE4Q5v.d.ts} +4 -4
- package/dist/{block-subjects-BoJrJAgR.js → block-subjects-B9hb1LLk.js} +2 -2
- package/dist/{block-tables-B6Jt0mWg.d.ts → block-tables-BATer_QF.d.ts} +1 -1
- package/dist/blocks/access-requests/index.d.ts +1 -1
- package/dist/blocks/accounting/index.d.ts +1 -1
- package/dist/blocks/acknowledgements/index.d.ts +1 -1
- package/dist/blocks/activities/index.d.ts +2 -2
- package/dist/blocks/advisories/index.d.ts +1 -1
- package/dist/blocks/agent-checkout/index.d.ts +1 -1
- package/dist/blocks/agents/index.d.ts +1 -1
- package/dist/blocks/ai-cache/index.d.ts +1 -1
- package/dist/blocks/ai-chat/index.d.ts +1 -1
- package/dist/blocks/ai-evals/index.d.ts +1 -1
- package/dist/blocks/ai-files/index.d.ts +1 -1
- package/dist/blocks/ai-guardrails/index.d.ts +1 -1
- package/dist/blocks/ai-keys/index.d.ts +1 -1
- package/dist/blocks/ai-schedules/index.d.ts +2 -2
- package/dist/blocks/announcements/index.d.ts +4 -4
- package/dist/blocks/api-keys/index.d.ts +1 -1
- package/dist/blocks/appraisals/index.d.ts +1 -1
- package/dist/blocks/approvals/index.d.ts +1 -1
- package/dist/blocks/assets/index.d.ts +2 -2
- package/dist/blocks/assignment/index.d.ts +1 -1
- package/dist/blocks/attachments/index.d.ts +5 -5
- package/dist/blocks/audit/index.d.ts +2 -2
- package/dist/blocks/automations/index.d.ts +3 -3
- package/dist/blocks/banking/index.d.ts +1 -1
- package/dist/blocks/billable-time/index.d.ts +1 -1
- package/dist/blocks/billing/index.d.ts +2 -2
- package/dist/blocks/bookings/index.d.ts +2 -2
- package/dist/blocks/bulk/index.d.ts +1 -1
- package/dist/blocks/calendar/index.d.ts +3 -3
- package/dist/blocks/care/index.d.ts +27 -27
- package/dist/blocks/care-plans/index.d.ts +3 -3
- package/dist/blocks/cases/index.d.ts +3 -3
- package/dist/blocks/catalog/index.d.ts +2 -2
- package/dist/blocks/channels/index.d.ts +1 -1
- package/dist/blocks/clinical-decision-support/index.d.ts +1 -1
- package/dist/blocks/cms/index.d.ts +5 -5
- package/dist/blocks/collaboration/index.d.ts +6 -6
- package/dist/blocks/collections/index.d.ts +1 -1
- package/dist/blocks/comments/index.d.ts +2 -2
- package/dist/blocks/commerce/index.d.ts +5 -5
- package/dist/blocks/commissions/index.d.ts +1 -1
- package/dist/blocks/compliance/index.d.ts +1 -1
- package/dist/blocks/connectors/index.d.ts +1 -1
- package/dist/blocks/consents/index.d.ts +2 -2
- package/dist/blocks/contacts/index.d.ts +2 -2
- package/dist/blocks/content/index.d.ts +2 -2
- package/dist/blocks/contracts/index.d.ts +1 -1
- package/dist/blocks/courses/index.d.ts +3 -3
- package/dist/blocks/created-by/index.d.ts +2 -2
- package/dist/blocks/crm/index.d.ts +16 -16
- package/dist/blocks/custom-fields/index.d.ts +1 -1
- package/dist/blocks/dam/index.d.ts +2 -2
- package/dist/blocks/data-lifecycle/index.d.ts +2 -2
- package/dist/blocks/deadlines/index.d.ts +249 -43
- package/dist/blocks/deadlines/index.js +862 -20
- package/dist/blocks/deals/index.d.ts +1 -1
- package/dist/blocks/dispatch/index.d.ts +2 -2
- package/dist/blocks/document-templates/index.d.ts +2 -2
- package/dist/blocks/documents/index.d.ts +1 -1
- package/dist/blocks/domains/index.d.ts +1 -1
- package/dist/blocks/donations/index.d.ts +1 -1
- package/dist/blocks/drive/index.d.ts +5 -5
- package/dist/blocks/e-prescribing/index.d.ts +1 -1
- package/dist/blocks/employees/index.d.ts +1 -1
- package/dist/blocks/enrichment/index.d.ts +1 -1
- package/dist/blocks/enrollments/index.d.ts +2 -2
- package/dist/blocks/entitlements/index.d.ts +3 -3
- package/dist/blocks/events/index.d.ts +3 -3
- package/dist/blocks/expenses/index.d.ts +1 -1
- package/dist/blocks/field-history/index.d.ts +1 -1
- package/dist/blocks/filespace/index.d.ts +8 -8
- package/dist/blocks/finance/index.d.ts +5 -5
- package/dist/blocks/flags/index.d.ts +1 -1
- package/dist/blocks/forecasts/index.d.ts +1 -1
- package/dist/blocks/forms/index.d.ts +3 -3
- package/dist/blocks/funding/index.d.ts +2 -2
- package/dist/blocks/goals/index.d.ts +1 -1
- package/dist/blocks/governance/index.d.ts +4 -4
- package/dist/blocks/guests/index.d.ts +1 -1
- package/dist/blocks/hiring/index.d.ts +1 -1
- package/dist/blocks/identities/index.d.ts +1 -1
- package/dist/blocks/imports/index.d.ts +2 -2
- package/dist/blocks/inbox/index.d.ts +6 -6
- package/dist/blocks/incidents/index.d.ts +1 -1
- package/dist/blocks/index.d.ts +3 -3
- package/dist/blocks/inspections/index.d.ts +2 -2
- package/dist/blocks/inventory/index.d.ts +1 -1
- package/dist/blocks/invoices/index.d.ts +1 -1
- package/dist/blocks/knowledge/index.d.ts +1 -1
- package/dist/blocks/lead-scoring/index.d.ts +2 -2
- package/dist/blocks/learning/index.d.ts +3 -3
- package/dist/blocks/leases/index.d.ts +1 -1
- package/dist/blocks/leave/index.d.ts +1 -1
- package/dist/blocks/ledger/index.d.ts +1 -1
- package/dist/blocks/legal-entities/index.d.ts +2 -2
- package/dist/blocks/lims/index.d.ts +2 -2
- package/dist/blocks/mail-sync/index.d.ts +3 -3
- package/dist/blocks/maintenance/index.d.ts +2 -2
- package/dist/blocks/manufacturing/index.d.ts +2 -2
- package/dist/blocks/medications/index.d.ts +1 -1
- package/dist/blocks/meetings/index.d.ts +3 -3
- package/dist/blocks/memberships/index.d.ts +2 -2
- package/dist/blocks/memory/index.d.ts +1 -1
- package/dist/blocks/messaging/index.d.ts +5 -5
- package/dist/blocks/metrics/index.d.ts +1 -1
- package/dist/blocks/mfa/index.d.ts +2 -2
- package/dist/blocks/moderation/index.d.ts +2 -2
- package/dist/blocks/notifications/index.d.ts +5 -5
- package/dist/blocks/numbering/index.d.ts +1 -1
- package/dist/blocks/oauth-server/index.d.ts +1 -1
- package/dist/blocks/observations/index.d.ts +2 -2
- package/dist/blocks/onboarding/index.d.ts +2 -2
- package/dist/blocks/option-sets/index.d.ts +2 -2
- package/dist/blocks/orders/index.d.ts +1 -1
- package/dist/blocks/organizations/index.d.ts +2 -2
- package/dist/blocks/outbox/index.d.ts +1 -1
- package/dist/blocks/passes/index.d.ts +2 -2
- package/dist/blocks/payroll-export/index.d.ts +2 -2
- package/dist/blocks/people/index.d.ts +7 -7
- package/dist/blocks/periods/index.d.ts +1 -1
- package/dist/blocks/permissions/index.d.ts +3 -3
- package/dist/blocks/pipelines/index.d.ts +1 -1
- package/dist/blocks/posts/index.d.ts +2 -2
- package/dist/blocks/procurement/index.d.ts +5 -5
- package/dist/blocks/profiles/index.d.ts +1 -1
- package/dist/blocks/projects/index.d.ts +7 -7
- package/dist/blocks/promotions/index.d.ts +1 -1
- package/dist/blocks/prompts/index.d.ts +1 -1
- package/dist/blocks/push/index.d.ts +2 -2
- package/dist/blocks/qualifications/index.d.ts +2 -2
- package/dist/blocks/queue/index.d.ts +2 -2
- package/dist/blocks/quotes/index.d.ts +1 -1
- package/dist/blocks/rank/index.d.ts +1 -1
- package/dist/blocks/reactions/index.d.ts +4 -4
- package/dist/blocks/recruiting/index.d.ts +4 -4
- package/dist/blocks/referrals/index.d.ts +1 -1
- package/dist/blocks/relations/index.d.ts +1 -1
- package/dist/blocks/reminders/index.d.ts +1 -1
- package/dist/blocks/reviews/index.d.ts +1 -1
- package/dist/blocks/rfqs/index.d.ts +2 -2
- package/dist/blocks/risks/index.d.ts +2 -2
- package/dist/blocks/saas/index.d.ts +12 -12
- package/dist/blocks/sales/index.d.ts +1 -1
- package/dist/blocks/saved-views/index.d.ts +2 -2
- package/dist/blocks/scheduling/index.d.ts +4 -4
- package/dist/blocks/scores/index.d.ts +2 -2
- package/dist/blocks/search/index.d.ts +3 -3
- package/dist/blocks/security-events/index.d.ts +1 -1
- package/dist/blocks/segments/index.d.ts +2 -2
- package/dist/blocks/sequences/index.d.ts +3 -3
- package/dist/blocks/service/index.d.ts +7 -7
- package/dist/blocks/service-accounts/index.d.ts +1 -1
- package/dist/blocks/sessions/index.d.ts +2 -2
- package/dist/blocks/settings/index.d.ts +2 -2
- package/dist/blocks/share-links/index.d.ts +1 -1
- package/dist/blocks/shifts/index.d.ts +2 -2
- package/dist/blocks/shipments/index.d.ts +2 -2
- package/dist/blocks/signatures/index.d.ts +2 -2
- package/dist/blocks/signing-keys/index.d.ts +1 -1
- package/dist/blocks/sla/index.d.ts +1 -1
- package/dist/blocks/sso/index.d.ts +1 -1
- package/dist/blocks/state-machine/index.d.ts +1 -1
- package/dist/blocks/subjects/index.d.ts +2 -2
- package/dist/blocks/support/index.d.ts +5 -5
- package/dist/blocks/tags/index.d.ts +2 -2
- package/dist/blocks/tasks/index.d.ts +2 -2
- package/dist/blocks/tax/index.d.ts +2 -2
- package/dist/blocks/teams/index.d.ts +1 -1
- package/dist/blocks/templates/index.d.ts +1 -1
- package/dist/blocks/tills/index.d.ts +1 -1
- package/dist/blocks/time-tracking/index.d.ts +2 -2
- package/dist/blocks/timeline/index.d.ts +1 -1
- package/dist/blocks/trash/index.d.ts +1 -1
- package/dist/blocks/undo/index.d.ts +2 -2
- package/dist/blocks/updated-at/index.d.ts +2 -2
- package/dist/blocks/usage/index.d.ts +2 -2
- package/dist/blocks/vercel-marketplace/index.d.ts +1 -1
- package/dist/blocks/versions/index.d.ts +1 -1
- package/dist/blocks/waitlist/index.d.ts +1 -1
- package/dist/blocks/warehouse/index.d.ts +1 -1
- package/dist/blocks/webhooks/index.d.ts +1 -1
- package/dist/blocks/workflow-editor/index.d.ts +4 -4
- package/dist/blocks/workflows/index.d.ts +4 -4
- package/dist/{blocks-2HFgUcqG.d.ts → blocks-Cf2U_jmO.d.ts} +4 -4
- package/dist/claims/index.d.ts +3 -3
- package/dist/cli/{add-LvxZ-JNB.js → add-CB2nU8nW.js} +2 -2
- package/dist/cli/{add-BnYh-Kpy.js → add-DQXg3MLt.js} +10 -10
- package/dist/cli/add-DWUCeKIl.js +1 -0
- package/dist/cli/{app-table-files-7M0I9LaE.js → app-table-files-Ch3GTFjg.js} +2 -2
- package/dist/cli/{app-tables-BfWPWiOJ.js → app-tables-CwSpV4yV.js} +2 -2
- package/dist/cli/{backfill-i0Tx24Sa.js → backfill-Cngd3Ax2.js} +1 -1
- package/dist/cli/bin.js +1 -1
- package/dist/cli/{blocks-C_7ioBdJ.js → blocks--hf8elE7.js} +1 -1
- package/dist/cli/{blocks-X_eD_t_f.js → blocks-BGHYZGoh.js} +1 -1
- package/dist/cli/{cache-D98rjB1C.js → cache-DMqncCOE.js} +1 -1
- package/dist/cli/{codemod-j1nCkgA5.js → codemod-BrNMM9qN.js} +1 -1
- package/dist/cli/{content-mapper-UsLt4y0J.js → content-mapper-CBBnca0p.js} +2 -2
- package/dist/cli/{doctor-BYJM72wi.js → doctor-BHsw2SGl.js} +15 -15
- package/dist/cli/{gen-D47t5jj3.js → gen-BbLeZxhv.js} +11 -11
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +6 -6
- package/dist/cli/{init-CAWeLXCs.js → init-DH0LI0hx.js} +9 -9
- package/dist/cli/{live-DNd8MMNk.js → live-DFlCT5Uk.js} +2 -2
- package/dist/cli/{mcp-BUs7M6fq.js → mcp-B9ZwlZrA.js} +2 -2
- package/dist/cli/{metadata-UwEYCntC.js → metadata-DmXQDGq9.js} +3 -3
- package/dist/cli/{migrate-D-GzXR4D.js → migrate-DG4_cemN.js} +1 -1
- package/dist/cli/{migration-safety-Cg9jf2s-.js → migration-safety-CMvBM2Vi.js} +1 -1
- package/dist/cli/{migrations-Bhcf7MHM.js → migrations-B88uNBtB.js} +2 -2
- package/dist/cli/{module-migration-BJaOdOWy.js → module-migration-CrVdvTsm.js} +2 -2
- package/dist/cli/{powersync-DQKdjG_K.js → powersync-CiWMuRwt.js} +3 -3
- package/dist/cli/powersync-TFSmK9XH.js +1 -0
- package/dist/cli/{print-B1onZWRG.js → print-DJtwCt5U.js} +2 -2
- package/dist/cli/{providers-M7s8btf1.js → providers-CN8w11Yf.js} +1 -1
- package/dist/cli/{prune-workflows-BiRF1YBZ.js → prune-workflows-Bwzd1_z4.js} +1 -1
- package/dist/cli/{remove-BHyzqWNm.js → remove-D4fXl2zz.js} +6 -6
- package/dist/cli/{render-DDCy_0V_.js → render-Fafpgh5a.js} +3 -3
- package/dist/cli/{run-DDUBMkbN.js → run-BM4C0L-r.js} +9 -9
- package/dist/cli/{run-Csm1-Uto.js → run-du7PclzJ.js} +31 -31
- package/dist/cli/{shared-Cv22MEAO.js → shared-l0oG47Rc.js} +1 -1
- package/dist/cli/{snapshot-9xnSt525.js → snapshot-DAVFBIVQ.js} +2 -2
- package/dist/cli/{source-B_miugrh.js → source-CfPOobxZ.js} +1 -1
- package/dist/cli/{spec-dYLJbr9J.js → spec-DCSih_mA.js} +2 -2
- package/dist/cli/{spec-BeAgQ-of.js → spec-Dlbmh0EH.js} +1 -1
- package/dist/cli/{sql-layout-3YU4941N.js → sql-layout-DpCFWUnX.js} +2 -2
- package/dist/cli/{sync-Bfwk4Ldc.js → sync-3LMoCI1x.js} +4 -4
- package/dist/cli/{upgrade-BMrkzAcD.js → upgrade-4A6oQN-6.js} +5 -5
- package/dist/cli/{upgrade-DRvMFW2T.js → upgrade-DyE_4LAn.js} +2 -2
- package/dist/cli/{version-BXjNETWS.js → version-DaV4RlVP.js} +1 -1
- package/dist/client/index.d.ts +5 -5
- package/dist/client/native/index.d.ts +4 -4
- package/dist/config/index.d.ts +4 -4
- package/dist/config/index.js +4 -4
- package/dist/{config-CsX2THwJ.js → config-Bx3UYp8b.js} +3 -3
- package/dist/{config-Dgl6AxKE.js → config-CAjlOSQY.js} +1 -1
- package/dist/{context-DSJpfeVv.d.ts → context-C3-QkbC2.d.ts} +3 -3
- package/dist/contract/index.d.ts +3 -3
- package/dist/{controller-BVee4yX8.d.ts → controller-6_Uo4WEe.d.ts} +1 -1
- package/dist/{conversion-BPkWkVoa.d.ts → conversion-kJKGDyKY.d.ts} +1 -1
- package/dist/create/index.d.ts +4 -4
- package/dist/create/index.js +3 -3
- package/dist/create/lite/index.d.ts +3 -3
- package/dist/create/lite/index.js +2 -2
- package/dist/deadlines-values-vmaCCdGl.js +92 -0
- package/dist/{define-block-Cu67KCN1.d.ts → define-block-Dle1hNrI.d.ts} +1 -1
- package/dist/{drive-D008IDpI.d.ts → drive-C2EYvBxH.d.ts} +1 -1
- package/dist/{entitlements-CRBZg5y2.d.ts → entitlements-Bb-dOARS.d.ts} +1 -1
- package/dist/{extract-BU5w3k5s.d.ts → extract-BwhGjyWJ.d.ts} +1 -1
- package/dist/{field-errors-CjEgbjO9.d.ts → field-errors-CjEfOrH1.d.ts} +5 -5
- package/dist/{index-voglIa16.d.ts → index-2gyZE8Rf.d.ts} +3 -3
- package/dist/{index-CDEzb5bl.d.ts → index-B5Qh7kMt.d.ts} +1 -1
- package/dist/{index-DhS8Qkgj.d.ts → index-BE4JTKF9.d.ts} +2 -2
- package/dist/{index-DYzQ_PPW.d.ts → index-BEmlle8t.d.ts} +1 -1
- package/dist/{index-BDn4Mqq0.d.ts → index-BEtCBklB.d.ts} +1 -1
- package/dist/{index-AmPcMT_X.d.ts → index-BY1YQVSU.d.ts} +1 -1
- package/dist/{index-Dyq6B4gZ.d.ts → index-BYV1G4-b.d.ts} +2 -2
- package/dist/{index-DZRsTCds.d.ts → index-BjIGMnQ0.d.ts} +1 -1
- package/dist/{index-CKdNndE3.d.ts → index-BqD3Iu_J.d.ts} +2 -2
- package/dist/{index-BTl5A8Aj.d.ts → index-BqJum_h9.d.ts} +1 -1
- package/dist/{index-DtMdKIJU.d.ts → index-Buxrux0m.d.ts} +2 -2
- package/dist/{index-DR4P3Lf9.d.ts → index-BzrihVGI.d.ts} +2 -2
- package/dist/{index-BeU2DRAI.d.ts → index-C8S7_Q8r.d.ts} +1 -1
- package/dist/{index-r3QZBY7z.d.ts → index-CC34bHDQ.d.ts} +1 -1
- package/dist/{index-_RnZChF8.d.ts → index-CN3C6JkR.d.ts} +1 -1
- package/dist/{index-CaW37FHZ.d.ts → index-CNuolr9n.d.ts} +1 -1
- package/dist/{index-DJ1Uk4ff.d.ts → index-COIhSgY7.d.ts} +4 -4
- package/dist/{index-BOZ6AsMs.d.ts → index-Cg7SR_qX.d.ts} +1 -1
- package/dist/{index-BvPirjfD.d.ts → index-Cm8MeW9i.d.ts} +4 -4
- package/dist/{index-ChaJiMkI.d.ts → index-CwPttFTz.d.ts} +2 -2
- package/dist/{index-u8EXkOzJ.d.ts → index-D1O-RJWe.d.ts} +1 -1
- package/dist/{index-BleHtlJ6.d.ts → index-D9nVD78s.d.ts} +1 -1
- package/dist/{index-dMGEJLxl.d.ts → index-DBFr7a8o.d.ts} +1 -1
- package/dist/{index-BVJsz3pS.d.ts → index-DOfmW2AH.d.ts} +2 -2
- package/dist/{index-D5nY5k-2.d.ts → index-DSAikYZQ.d.ts} +7 -7
- package/dist/{index-D-3fZP5z.d.ts → index-DbCYIGAY.d.ts} +1 -1
- package/dist/{index--7HXH_H_.d.ts → index-DdMcDiIK.d.ts} +2 -2
- package/dist/{index-DsA7MQwZ.d.ts → index-Ddo11etS.d.ts} +1 -1
- package/dist/{index-BR8ZkijS.d.ts → index-DugPUkCG.d.ts} +2 -2
- package/dist/{index-BoCyVsCr.d.ts → index-DwDtMCDt.d.ts} +1 -1
- package/dist/{index-_wr8wCe9.d.ts → index-Dx6jNpfl.d.ts} +1 -1
- package/dist/{index-D7zwaGAP.d.ts → index-Dxza7aew.d.ts} +1 -1
- package/dist/{index-ilxdL8pz.d.ts → index-NzTBsdNG.d.ts} +1 -1
- package/dist/{index-DDDHYXtr.d.ts → index-U2_mkKvZ.d.ts} +8 -8
- package/dist/{index-JzAR_Y7n.d.ts → index-bTW0dRZY.d.ts} +3 -3
- package/dist/{index-E_Q5L9PV.d.ts → index-hctpn1Mt.d.ts} +1 -1
- package/dist/{index-slG4UpF_.d.ts → index-yL19hBMN.d.ts} +2 -2
- package/dist/{instances-BMjIO6Xu.js → instances-z6DJn2Gr.js} +20 -1
- package/dist/{manifest-CbKgs5qA.d.ts → manifest-2z4m-cwI.d.ts} +1 -1
- package/dist/{manifest-CoFpa0dN.d.ts → manifest-64Zd4QzL.d.ts} +1 -1
- package/dist/{manifest-DhpmWh55.d.ts → manifest-9tZFwb_N.d.ts} +1 -1
- package/dist/{manifest-BZL2TAB1.d.ts → manifest-B0-5rKJ_.d.ts} +1 -1
- package/dist/{manifest-CELTce26.d.ts → manifest-B0ByrOJ2.d.ts} +1 -1
- package/dist/{manifest-CGZQ9lU3.d.ts → manifest-B4yf2Fir.d.ts} +1 -1
- package/dist/{manifest-D2Z_2z9-.d.ts → manifest-BBETqrI-.d.ts} +1 -1
- package/dist/{manifest-CMnLDDS3.d.ts → manifest-BEFiuvqo.d.ts} +1 -1
- package/dist/{manifest-BE7UwezO.d.ts → manifest-BG6K9qvU.d.ts} +1 -1
- package/dist/{manifest-6PhMgCFi.d.ts → manifest-BOkGzZcG.d.ts} +1 -1
- package/dist/{manifest-BzsuqiQx.d.ts → manifest-BReV7Ehb.d.ts} +1 -1
- package/dist/{manifest-CdD44xlg.d.ts → manifest-BSmnJW4X.d.ts} +1 -1
- package/dist/{manifest-DYPVnKW_.d.ts → manifest-BV8_wZab.d.ts} +1 -1
- package/dist/{manifest-xikzppm9.d.ts → manifest-BXvY6i0C.d.ts} +1 -1
- package/dist/{manifest-lzwWCAYV.d.ts → manifest-BbUa_z3D.d.ts} +1 -1
- package/dist/{manifest-Eazz96as.d.ts → manifest-BcurR7jz.d.ts} +1 -1
- package/dist/{manifest-BknZ4yQ-.d.ts → manifest-BfWK-zw_.d.ts} +1 -1
- package/dist/{manifest-Dk_7prKx.d.ts → manifest-Bl4kFo6c.d.ts} +1 -1
- package/dist/{manifest-CSHNTEJZ.d.ts → manifest-Bsr9SSG5.d.ts} +1 -1
- package/dist/{manifest-DxPLHyKY.d.ts → manifest-BtI5HhXk.d.ts} +1 -1
- package/dist/{manifest-BMNwdO5D.d.ts → manifest-BxY9kn1w.d.ts} +1 -1
- package/dist/{manifest-BSvxbZH5.d.ts → manifest-C2QmAn2x.d.ts} +1 -1
- package/dist/{manifest-DhXoSaUC.d.ts → manifest-C5CZYXC2.d.ts} +1 -1
- package/dist/{manifest-Bz0EjE76.d.ts → manifest-C9PoeugH.d.ts} +1 -1
- package/dist/{manifest-DwCorUVJ.d.ts → manifest-C9x5lxeF.d.ts} +1 -1
- package/dist/{manifest-CaA-2HPK.d.ts → manifest-CKAtEVtk.d.ts} +1 -1
- package/dist/{manifest-C_dVunWg.d.ts → manifest-CVQ3q-JJ.d.ts} +1 -1
- package/dist/{manifest-BYbt4y_O.d.ts → manifest-CWKtnWcS.d.ts} +1 -1
- package/dist/{manifest-Dl_bw4IU.d.ts → manifest-CchgUbRg.d.ts} +1 -1
- package/dist/{manifest-auanzyjB.d.ts → manifest-Cjt5fW9U.d.ts} +1 -1
- package/dist/{manifest-Bp0oZ3-W.d.ts → manifest-CuuE9u0c.d.ts} +1 -1
- package/dist/{manifest-D7mliM-d.d.ts → manifest-D23v7_Fg.d.ts} +1 -1
- package/dist/{manifest-CGcGylmw.d.ts → manifest-D9fWfK2i.d.ts} +1 -1
- package/dist/{manifest-DMvx2rWH.d.ts → manifest-DGHeP3gy.d.ts} +1 -1
- package/dist/{manifest-DGiswyG5.d.ts → manifest-DGePKO35.d.ts} +1 -1
- package/dist/{manifest-gGFtQDJz.d.ts → manifest-DHAShiq8.d.ts} +1 -1
- package/dist/{manifest-DPqKZgWn.d.ts → manifest-DPSgN4LB.d.ts} +1 -1
- package/dist/{manifest-D2d1wS7g.d.ts → manifest-DPeSW0P5.d.ts} +1 -1
- package/dist/{manifest-CBwrN4Nf.d.ts → manifest-DT4l91L_.d.ts} +1 -1
- package/dist/{manifest-Pl5us_yz.d.ts → manifest-DUA64Tnn.d.ts} +1 -1
- package/dist/{manifest-DUlZ8qck.d.ts → manifest-DVBfzRly.d.ts} +1 -1
- package/dist/{manifest-uIIb_YLI.d.ts → manifest-DXuOYu6Q.d.ts} +1 -1
- package/dist/{manifest-Df1QDhiQ.d.ts → manifest-D_AT0kqo.d.ts} +1 -1
- package/dist/{manifest-B4CEdcH_.d.ts → manifest-D_aJ09Il.d.ts} +1 -1
- package/dist/{manifest-D_VmA0aC.d.ts → manifest-D_kxP0yH.d.ts} +1 -1
- package/dist/{manifest-X4analSK.d.ts → manifest-DgtO2rew.d.ts} +1 -1
- package/dist/{manifest-DG0oDOmq.d.ts → manifest-DiKKpytg.d.ts} +1 -1
- package/dist/{manifest-BVjhJ3Mj.d.ts → manifest-DlWg4mC8.d.ts} +1 -1
- package/dist/{manifest-DAXz8rxB.d.ts → manifest-DlyGRc_x.d.ts} +1 -1
- package/dist/{manifest-BB3GjGa3.d.ts → manifest-DreoW4xj.d.ts} +1 -1
- package/dist/{manifest-Dc8pNExY.d.ts → manifest-Gwsis09w.d.ts} +1 -1
- package/dist/{manifest-CWj5SFuw.d.ts → manifest-K1yCH7Ai.d.ts} +1 -1
- package/dist/{manifest-DtEcJBdE.d.ts → manifest-TSUBAvih.d.ts} +1 -1
- package/dist/{manifest-DsuoLp-Y.d.ts → manifest-WuPrNtWh.d.ts} +1 -1
- package/dist/{manifest-yKx0faak.d.ts → manifest-b1ei2NBj.d.ts} +1 -1
- package/dist/{manifest-BXxSqnLS.d.ts → manifest-byZwzlAG.d.ts} +1 -1
- package/dist/{manifest-D9P9Yhe3.d.ts → manifest-fUQWT0ft.d.ts} +1 -1
- package/dist/{manifest-DGLrMEdB.d.ts → manifest-hrX9Hsgd.d.ts} +1 -1
- package/dist/{manifest-D0FjVeay.d.ts → manifest-iRyMyb7t.d.ts} +1 -1
- package/dist/{manifest-B17Sra5h.d.ts → manifest-r5iVaZrT.d.ts} +1 -1
- package/dist/{manifest-DIZ6chpf.d.ts → manifest-xVl_34TT.d.ts} +1 -1
- package/dist/{manifest-CMNPpmWS.d.ts → manifest-yUJGXgsd.d.ts} +2 -2
- package/dist/mapper/bin.js +5 -5
- package/dist/mcp/index.d.ts +1 -1
- package/dist/next/index.d.ts +7 -7
- package/dist/{operations-DKfYeS5z.d.ts → operations-DvIB3N20.d.ts} +1 -1
- package/dist/otel/index.js +4 -4
- package/dist/{permissions-C5h1cU25.d.ts → permissions-CtS73Ot8.d.ts} +1 -1
- package/dist/{ports-DvaVv_3b.d.ts → ports-D_z0B0OU.d.ts} +1 -1
- package/dist/powersync/index.d.ts +2 -2
- package/dist/preset/index.d.ts +4 -4
- package/dist/preset/index.js +3 -3
- package/dist/{preset-Cl3Q5ASC.js → preset-CPUA9haY.js} +3 -3
- package/dist/{preview-Bwg7r1Lf.d.ts → preview-B0MvbKqQ.d.ts} +2 -2
- package/dist/{project-At5wBJSS.js → project-CMRUh_6Z.js} +5 -5
- package/dist/{push-token-C6ZGE1g0.d.ts → push-token--jdbVbWv.d.ts} +1 -1
- package/dist/query/index.d.ts +1 -1
- package/dist/react/index.d.ts +5 -5
- package/dist/react/native/index.d.ts +1 -1
- package/dist/react/server.d.ts +5 -5
- package/dist/realtime/index.d.ts +3 -3
- package/dist/{record-form-DTncyqVH.d.ts → record-form-Bb3mf114.d.ts} +1 -1
- package/dist/records/index.d.ts +7 -7
- package/dist/server/index.d.ts +3 -3
- package/dist/solid/index.d.ts +5 -5
- package/dist/sql/index.d.ts +5 -5
- package/dist/sql/index.js +2 -2
- package/dist/{sql-CdZdPqjA.js → sql-DXME28Gr.js} +1560 -264
- package/dist/ssr/index.d.ts +1 -1
- package/dist/svelte/index.d.ts +5 -5
- package/dist/{tenant-BTnwa5oZ.d.ts → tenant-sm9d_APF.d.ts} +1 -1
- package/dist/testing/index.d.ts +6 -6
- package/dist/testing/index.js +1 -1
- package/dist/{timeline-B7kBQ1gh.d.ts → timeline-BR-oKhI4.d.ts} +2 -2
- package/dist/{topic-hu0RP7CG.d.ts → topic-CBTgUy6t.d.ts} +1 -1
- package/dist/{types-DvglaQ_D.d.ts → types-DRNzKqdm.d.ts} +2 -2
- package/dist/vue/index.d.ts +5 -5
- package/dist/{watch-topic-C_rGHxIA.d.ts → watch-topic-DYDnWH_a.d.ts} +1 -1
- package/dist/webmcp/index.d.ts +1 -1
- package/dist/yjs/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cli/add-D0TUMxXn.js +0 -1
- package/dist/cli/powersync-Bn-u0TGP.js +0 -1
- 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
|
|
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
|
|
11
|
-
*
|
|
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
|
|
14
|
-
return
|
|
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
|
|
17
|
-
function
|
|
18
|
-
return
|
|
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
|
|
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(
|
|
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
|
-
|
|
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
|
|
88
|
-
* known
|
|
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
|
-
|
|
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("
|
|
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
|
-
|
|
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
|
|
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,
|
|
1001
|
+
export { createDeadlines, dbTransport, deadlinesBlock, deadlinesEvents, evaluateVersion, extendBlock, rpcTransport, sqlTransport, validateRuleVersion, withBlockHooks, wrapTransport };
|