better-supabase 0.54.0 → 0.55.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-DcZk8HBB.d.ts → agents-CBXJce8J.d.ts} +2 -2
- package/dist/{ai-schedules-b-uWaxba.d.ts → ai-schedules-CtwkMJDZ.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-B2xNMyLA.d.ts → app-tables-BsDmauWB.d.ts} +1 -1
- package/dist/{audit-actions-Dni5Y4wV.d.ts → audit-actions-DC-AtyWB.d.ts} +6 -0
- package/dist/{authorization-Bk6cLL5f.d.ts → authorization-DK7YSiFV.d.ts} +1 -1
- package/dist/{automations-CjKWYzIu.js → automations-Cu1KdCvL.js} +3 -1
- package/dist/{bind-DWElQa6I.d.ts → bind-DiGmjHzz.d.ts} +4 -4
- package/dist/{block-env-CQQUMPYZ.d.ts → block-env-BTKZBCL4.d.ts} +4 -4
- package/dist/{block-subjects-9KU6Q6-3.js → block-subjects-BoJrJAgR.js} +3 -2
- package/dist/{block-tables-JC1dMLaA.d.ts → block-tables-B6Jt0mWg.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/commerce/index.js +2 -2
- 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/crm/index.js +2 -2
- 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 +1 -1
- 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/finance/index.js +1 -1
- 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 +4 -4
- package/dist/blocks/inspections/index.d.ts +2 -2
- package/dist/blocks/inventory/index.d.ts +1 -1
- package/dist/blocks/inventory/index.js +1 -1
- package/dist/blocks/invoices/index.d.ts +1 -1
- package/dist/blocks/invoices/index.js +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/orders/index.js +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/payroll-export/index.js +1 -1
- package/dist/blocks/people/index.d.ts +7 -7
- package/dist/blocks/people/index.js +1 -1
- 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/procurement/index.js +2 -2
- package/dist/blocks/profiles/index.d.ts +1 -1
- package/dist/blocks/projects/index.d.ts +7 -7
- package/dist/blocks/projects/index.js +2 -2
- 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/quotes/index.js +2 -2
- 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/sales/index.js +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/index.js +1 -1
- 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/support/index.js +1 -1
- package/dist/blocks/tags/index.d.ts +2 -2
- package/dist/blocks/tasks/index.d.ts +2 -2
- package/dist/blocks/tasks/index.js +1 -1
- 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 +11 -1
- package/dist/blocks/templates/index.js +6 -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-LZklPzC5.d.ts → blocks-2HFgUcqG.d.ts} +52 -17
- package/dist/claims/index.d.ts +3 -3
- package/dist/cli/{add-DK38-F2F.js → add-BnYh-Kpy.js} +12 -12
- package/dist/cli/add-D0TUMxXn.js +1 -0
- package/dist/cli/{add-BQZbFEAP.js → add-LvxZ-JNB.js} +2 -2
- package/dist/cli/{app-table-files-C5Sx2Qao.js → app-table-files-7M0I9LaE.js} +3 -3
- package/dist/cli/{app-tables-ChZE8Z_L.js → app-tables-BfWPWiOJ.js} +2 -2
- package/dist/cli/{backfill-COnv2tOL.js → backfill-i0Tx24Sa.js} +3 -3
- package/dist/cli/bin.js +1 -1
- package/dist/cli/{blocks-Dea_Z5Ps.js → blocks-C_7ioBdJ.js} +1 -1
- package/dist/cli/{blocks-Csu6lLqC.js → blocks-X_eD_t_f.js} +1 -1
- package/dist/cli/{cache-C1nAFZNW.js → cache-D98rjB1C.js} +1 -1
- package/dist/cli/{codemod-DHULUpez.js → codemod-j1nCkgA5.js} +1 -1
- package/dist/cli/{config-FN5Cp861.js → config-DdkxiGjH.js} +7 -0
- package/dist/cli/{config-U32Vo0h6.js → config-DmjFp8jY.js} +1 -1
- package/dist/cli/{content-mapper-QVJJto5U.js → content-mapper-UsLt4y0J.js} +2 -2
- package/dist/cli/{db-T8u160uM.js → db-B54TQ_iX.js} +2 -2
- package/dist/cli/{doctor-Du2zwLUG.js → doctor-BYJM72wi.js} +17 -17
- package/dist/cli/{gen-CQ2ubqjB.js → gen-D47t5jj3.js} +14 -14
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +7 -7
- package/dist/cli/{init-CTt0aQn1.js → init-CAWeLXCs.js} +10 -10
- package/dist/cli/{live-DMNuAml9.js → live-DNd8MMNk.js} +2 -2
- package/dist/cli/{mcp-C63ulwyU.js → mcp-BUs7M6fq.js} +2 -2
- package/dist/cli/{metadata-CylES-9Y.js → metadata-UwEYCntC.js} +3 -3
- package/dist/cli/{migrate-BezKva56.js → migrate-D-GzXR4D.js} +1 -1
- package/dist/cli/{migration-safety-DQtpMu-g.js → migration-safety-Cg9jf2s-.js} +2 -2
- package/dist/cli/{migrations-DGJJ1rHt.js → migrations-Bhcf7MHM.js} +2 -2
- package/dist/cli/{module-migration-CxbEDfSF.js → module-migration-BJaOdOWy.js} +2 -2
- package/dist/cli/powersync-Bn-u0TGP.js +1 -0
- package/dist/cli/{powersync-FUYFuZSw.js → powersync-DQKdjG_K.js} +3 -3
- package/dist/cli/{print-DAwLAC-7.js → print-B1onZWRG.js} +2 -2
- package/dist/cli/{providers-hrxX3YKU.js → providers-M7s8btf1.js} +1 -1
- package/dist/cli/{prune-workflows-DLhKu_UJ.js → prune-workflows-BiRF1YBZ.js} +3 -3
- package/dist/cli/{remove-DSC6Fvwo.js → remove-BHyzqWNm.js} +6 -6
- package/dist/cli/{render-647qdnrX.js → render-DDCy_0V_.js} +4 -4
- package/dist/cli/{run-BcI6KXV3.js → run-Csm1-Uto.js} +35 -35
- package/dist/cli/{run--qaDaqfL.js → run-DDUBMkbN.js} +9 -9
- package/dist/cli/seed-BxjjQ3OO.js +1 -0
- package/dist/cli/{seed-BgpovbwF.js → seed-kCLEYSOH.js} +2 -2
- package/dist/cli/{shared-D_DZ9MfG.js → shared-Cv22MEAO.js} +1 -1
- package/dist/cli/{snapshot-B-1tPbV4.js → snapshot-9xnSt525.js} +3 -3
- package/dist/cli/{source-BgFNrRcl.js → source-B_miugrh.js} +1 -1
- package/dist/cli/{source-args-DC8snM7e.js → source-args-C3_mMci3.js} +1 -1
- package/dist/cli/{spec-C88dtkj4.js → spec-BeAgQ-of.js} +1 -1
- package/dist/cli/{spec-CV0FdW18.js → spec-dYLJbr9J.js} +2 -2
- package/dist/cli/{sql-layout-byUur5FC.js → sql-layout-3YU4941N.js} +2 -2
- package/dist/cli/{sync-BtM7o-sI.js → sync-Bfwk4Ldc.js} +4 -4
- package/dist/cli/{upgrade-CKDeHkyy.js → upgrade-BMrkzAcD.js} +5 -5
- package/dist/cli/{upgrade-B_HEJvRX.js → upgrade-DRvMFW2T.js} +2 -2
- package/dist/cli/{version-DWDoiP5_.js → version-BXjNETWS.js} +1 -1
- package/dist/client/index.d.ts +6 -6
- 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-LOwFAFpo.js → config-CsX2THwJ.js} +3 -3
- package/dist/{config-ekflaCnS.js → config-Dgl6AxKE.js} +1 -1
- package/dist/{context-iduX3Fsn.d.ts → context-DSJpfeVv.d.ts} +47 -4
- package/dist/contract/index.d.ts +3 -3
- package/dist/{contributions-DPjEWWpE.js → contributions-olp7tVYC.js} +11 -0
- package/dist/{controller-DFGNChQL.d.ts → controller-BVee4yX8.d.ts} +1 -1
- package/dist/{conversion-DTBB0Zgt.d.ts → conversion-BPkWkVoa.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/{data-engine-BKO5EAzN.d.ts → data-engine-0uVsKWaB.d.ts} +7 -3
- package/dist/{define-block-By-LUpM_.d.ts → define-block-Cu67KCN1.d.ts} +1 -1
- package/dist/{drive-CuNG4qB8.d.ts → drive-D008IDpI.d.ts} +1 -1
- package/dist/{entitlements-Go8BHqhr.d.ts → entitlements-CRBZg5y2.d.ts} +1 -1
- package/dist/{extract-DQKHxiiq.d.ts → extract-BU5w3k5s.d.ts} +1 -1
- package/dist/{field-errors-B4SMTk2e.d.ts → field-errors-CjEgbjO9.d.ts} +6 -6
- package/dist/{index-NqLuAXG3.d.ts → index--7HXH_H_.d.ts} +2 -2
- package/dist/{index-BvwlIGwY.d.ts → index-AmPcMT_X.d.ts} +1 -1
- package/dist/{index-DfJFbsVp.d.ts → index-BDn4Mqq0.d.ts} +1 -1
- package/dist/{index-DeE-Xuv7.d.ts → index-BOZ6AsMs.d.ts} +1 -1
- package/dist/{index-BkBNirhK.d.ts → index-BR8ZkijS.d.ts} +2 -2
- package/dist/{index-DzjugbCf.d.ts → index-BTl5A8Aj.d.ts} +2 -2
- package/dist/{index-BmKtYKwN.d.ts → index-BVJsz3pS.d.ts} +2 -2
- package/dist/{index-CTHuTJtf.d.ts → index-BeU2DRAI.d.ts} +1 -1
- package/dist/{index-DkNMN5uU.d.ts → index-BleHtlJ6.d.ts} +1 -1
- package/dist/{index-ROumUag2.d.ts → index-BoCyVsCr.d.ts} +1 -1
- package/dist/{index-DgRK-iM3.d.ts → index-BvPirjfD.d.ts} +4 -4
- package/dist/{index-pRdO2XnG.d.ts → index-CDEzb5bl.d.ts} +1 -1
- package/dist/{index-D-bMFoGs.d.ts → index-CKdNndE3.d.ts} +2 -2
- package/dist/{index-B8axasMg.d.ts → index-CaW37FHZ.d.ts} +1 -1
- package/dist/{index-DJyt9j86.d.ts → index-ChaJiMkI.d.ts} +2 -2
- package/dist/{index-9zNFFq6E.d.ts → index-D-3fZP5z.d.ts} +1 -1
- package/dist/{index-szXZSILq.d.ts → index-D5nY5k-2.d.ts} +7 -7
- package/dist/{index-D7FXhn2i.d.ts → index-D7zwaGAP.d.ts} +1 -1
- package/dist/{index-DkJtM-9e.d.ts → index-DDDHYXtr.d.ts} +9 -9
- package/dist/{index-DFdqVxv6.d.ts → index-DJ1Uk4ff.d.ts} +4 -4
- package/dist/{index-BKWnyAWN.d.ts → index-DR4P3Lf9.d.ts} +2 -2
- package/dist/{index-BoKvWo8t.d.ts → index-DYzQ_PPW.d.ts} +1 -1
- package/dist/{index-abVPYQE3.d.ts → index-DZRsTCds.d.ts} +1 -1
- package/dist/{index-D9Sb8Ju5.d.ts → index-DhS8Qkgj.d.ts} +3 -3
- package/dist/{index-YZ-_hzdR.d.ts → index-DsA7MQwZ.d.ts} +1 -1
- package/dist/{index-bJVAgXxw.d.ts → index-DtMdKIJU.d.ts} +2 -2
- package/dist/{index-BXRyr3ey.d.ts → index-Dyq6B4gZ.d.ts} +2 -2
- package/dist/{index-D337YzjX.d.ts → index-E_Q5L9PV.d.ts} +1 -1
- package/dist/{index-DXoS8BnK.d.ts → index-JzAR_Y7n.d.ts} +3 -3
- package/dist/{index-D4ke5U0m.d.ts → index-_RnZChF8.d.ts} +1 -1
- package/dist/{index-DkNLdcX_.d.ts → index-_wr8wCe9.d.ts} +1 -1
- package/dist/{index-20EPlFXG.d.ts → index-dMGEJLxl.d.ts} +1 -1
- package/dist/{index-DQVQYEhP.d.ts → index-ilxdL8pz.d.ts} +1 -1
- package/dist/{index-DlXgoerO.d.ts → index-r3QZBY7z.d.ts} +1 -1
- package/dist/{index-Bsd8P1iQ.d.ts → index-slG4UpF_.d.ts} +2 -2
- package/dist/{index-C1kImKZg.d.ts → index-u8EXkOzJ.d.ts} +1 -1
- package/dist/{index-Dg35ugqv.d.ts → index-voglIa16.d.ts} +4 -4
- package/dist/{instances-DJxWRqXk.js → instances-BMjIO6Xu.js} +32 -7
- package/dist/{inventory-reads-BNDSYnuG.js → inventory-reads-DEw2Kbff.js} +2 -1
- package/dist/{manifest-8JvRt8LB.d.ts → manifest-6PhMgCFi.d.ts} +1 -1
- package/dist/{manifest-B6EkxzC0.d.ts → manifest-B17Sra5h.d.ts} +1 -1
- package/dist/{manifest-DCPKfwsh.d.ts → manifest-B4CEdcH_.d.ts} +1 -1
- package/dist/{manifest-BCyCm0Z3.d.ts → manifest-BB3GjGa3.d.ts} +1 -1
- package/dist/{manifest-H6lz9xQm.d.ts → manifest-BE7UwezO.d.ts} +1 -1
- package/dist/{manifest-DGgFeLwd.d.ts → manifest-BMNwdO5D.d.ts} +1 -1
- package/dist/{manifest-BrOXXz7k.d.ts → manifest-BSvxbZH5.d.ts} +1 -1
- package/dist/{manifest-DZLr6Cbr.js → manifest-BV1YxozT.js} +1 -1
- package/dist/{manifest-BJs6pHI0.d.ts → manifest-BVjhJ3Mj.d.ts} +1 -1
- package/dist/{manifest-Dh4AJeLl.d.ts → manifest-BXxSqnLS.d.ts} +1 -1
- package/dist/{manifest-CcDqfRee.d.ts → manifest-BYbt4y_O.d.ts} +1 -1
- package/dist/{manifest-KHudP5T5.d.ts → manifest-BZL2TAB1.d.ts} +1 -1
- package/dist/{manifest-BRFen7mE.js → manifest-Bb8S2tcs.js} +1 -1
- package/dist/{manifest-fviCqeHj.d.ts → manifest-BknZ4yQ-.d.ts} +1 -1
- package/dist/{manifest-B24Ymu8p.d.ts → manifest-Bp0oZ3-W.d.ts} +1 -1
- package/dist/{manifest-DxPMUjhY.js → manifest-BvcIe5z_.js} +1 -1
- package/dist/{manifest-DWQaegX6.d.ts → manifest-Bz0EjE76.d.ts} +1 -1
- package/dist/{manifest-BbC83cJB.d.ts → manifest-BzsuqiQx.d.ts} +1 -1
- package/dist/{manifest-Dc1eHEJV.d.ts → manifest-CBwrN4Nf.d.ts} +1 -1
- package/dist/{manifest-BqBVKNjy.d.ts → manifest-CELTce26.d.ts} +1 -1
- package/dist/{manifest-jSOZl7qT.d.ts → manifest-CGZQ9lU3.d.ts} +1 -1
- package/dist/{manifest-DpF5bliV.d.ts → manifest-CGcGylmw.d.ts} +1 -1
- package/dist/{manifest-RUmJ5H6p.d.ts → manifest-CMNPpmWS.d.ts} +2 -2
- package/dist/{manifest-vG5iHhA5.d.ts → manifest-CMnLDDS3.d.ts} +1 -1
- package/dist/{manifest-CszjCxVJ.d.ts → manifest-CSHNTEJZ.d.ts} +1 -1
- package/dist/{manifest-qs_U2rx3.d.ts → manifest-CWj5SFuw.d.ts} +1 -1
- package/dist/{manifest-Cko_ySTe.d.ts → manifest-C_dVunWg.d.ts} +1 -1
- package/dist/{manifest-uL5fzXsx.d.ts → manifest-CaA-2HPK.d.ts} +1 -1
- package/dist/{manifest-DPGJ2otk.d.ts → manifest-CbKgs5qA.d.ts} +1 -1
- package/dist/{manifest-BfIYKrNe.d.ts → manifest-CdD44xlg.d.ts} +1 -1
- package/dist/{manifest-BGD8cD6S.d.ts → manifest-CoFpa0dN.d.ts} +1 -1
- package/dist/{manifest-H65OlXiB.js → manifest-CqJkmxrA.js} +1 -1
- package/dist/{manifest-BHlKJbN2.d.ts → manifest-D0FjVeay.d.ts} +1 -1
- package/dist/{manifest-Bj5hfBA_.d.ts → manifest-D2Z_2z9-.d.ts} +1 -1
- package/dist/{manifest-o-S9bj6i.d.ts → manifest-D2d1wS7g.d.ts} +1 -1
- package/dist/{manifest-CL5QEu5B.d.ts → manifest-D7mliM-d.d.ts} +1 -1
- package/dist/{manifest-DBmuiJ91.d.ts → manifest-D9P9Yhe3.d.ts} +1 -1
- package/dist/{manifest-Bg5Znp_u.d.ts → manifest-DAXz8rxB.d.ts} +1 -1
- package/dist/{manifest-BgVQ8xd3.d.ts → manifest-DG0oDOmq.d.ts} +1 -1
- package/dist/{manifest-Csw2tVut.d.ts → manifest-DGLrMEdB.d.ts} +1 -1
- package/dist/{manifest-BxujRhsY.d.ts → manifest-DGiswyG5.d.ts} +1 -1
- package/dist/{manifest-Da1QZDY4.d.ts → manifest-DIZ6chpf.d.ts} +1 -1
- package/dist/{manifest-xRlf8RQk.d.ts → manifest-DMvx2rWH.d.ts} +1 -1
- package/dist/{manifest-BtlEwVU4.d.ts → manifest-DPqKZgWn.d.ts} +1 -1
- package/dist/{manifest-BmLU5HtO.d.ts → manifest-DUlZ8qck.d.ts} +1 -1
- package/dist/{manifest-DjAdsSs4.d.ts → manifest-DYPVnKW_.d.ts} +1 -1
- package/dist/{manifest-Oo7PegXK.d.ts → manifest-D_VmA0aC.d.ts} +1 -1
- package/dist/{manifest-CAPSAozN.d.ts → manifest-Dc8pNExY.d.ts} +1 -1
- package/dist/{manifest-dXPq0ubY.d.ts → manifest-Df1QDhiQ.d.ts} +1 -1
- package/dist/{manifest-BAgvJODg.d.ts → manifest-DhXoSaUC.d.ts} +1 -1
- package/dist/{manifest-DweZMH-F.d.ts → manifest-DhpmWh55.d.ts} +1 -1
- package/dist/{manifest-BxuSAdYu.d.ts → manifest-Dk_7prKx.d.ts} +1 -1
- package/dist/{manifest-DnGgZ9_F.d.ts → manifest-Dl_bw4IU.d.ts} +1 -1
- package/dist/{manifest-BeW5LlW1.d.ts → manifest-DsuoLp-Y.d.ts} +1 -1
- package/dist/{manifest-2ZgzNTbP.d.ts → manifest-DtEcJBdE.d.ts} +10 -1
- package/dist/{manifest-DdxfAXvG.d.ts → manifest-DwCorUVJ.d.ts} +1 -1
- package/dist/{manifest-CfQ0nD_7.d.ts → manifest-DxPLHyKY.d.ts} +1 -1
- package/dist/{manifest-BSkYvne3.d.ts → manifest-Eazz96as.d.ts} +1 -1
- package/dist/{manifest-CH7g3uI3.d.ts → manifest-Pl5us_yz.d.ts} +1 -1
- package/dist/{manifest-upfKO7JJ.d.ts → manifest-X4analSK.d.ts} +1 -1
- package/dist/{manifest-2jLTjnVh.d.ts → manifest-auanzyjB.d.ts} +1 -1
- package/dist/{manifest-CeoUoZDs.d.ts → manifest-gGFtQDJz.d.ts} +1 -1
- package/dist/{manifest-BCOBkYvY.d.ts → manifest-lzwWCAYV.d.ts} +2 -2
- package/dist/{manifest-BUktyXMR.js → manifest-ok1ge1bM.js} +1 -1
- package/dist/{manifest-Ct6mHhg4.d.ts → manifest-uIIb_YLI.d.ts} +1 -1
- package/dist/{manifest-DevURQJj.js → manifest-vBvsSefP.js} +5 -1
- package/dist/{manifest-CDcaLpwB.d.ts → manifest-xikzppm9.d.ts} +1 -1
- package/dist/{manifest-BHZEsuzC.d.ts → manifest-yKx0faak.d.ts} +1 -1
- package/dist/mapper/bin.js +6 -6
- package/dist/mcp/index.d.ts +1 -1
- package/dist/next/index.d.ts +7 -7
- package/dist/{operations-IzVAIMvs.d.ts → operations-DKfYeS5z.d.ts} +1 -1
- package/dist/{options-CGQC7Wue.js → options-C1N8cOQU.js} +2 -1
- package/dist/{options-BTuDJ2RC.js → options-Cu6IqZ_n.js} +3 -1
- package/dist/{options-wBw_6uhd.js → options-Oo46IzNk.js} +2 -1
- package/dist/{orders-reads-Yo9GGjdv.js → orders-reads-2ozdZx1l.js} +108 -13
- package/dist/otel/index.js +4 -4
- package/dist/{payroll-export-T754eWz8.js → payroll-export-ChZY6W3w.js} +1 -1
- package/dist/{permissions-DxXor_NY.d.ts → permissions-C5h1cU25.d.ts} +1 -1
- package/dist/{ports-C5BEHQi6.d.ts → ports-DvaVv_3b.d.ts} +1 -1
- package/dist/powersync/index.d.ts +3 -3
- package/dist/powersync/index.js +11 -3
- package/dist/preset/index.d.ts +4 -4
- package/dist/preset/index.js +3 -3
- package/dist/{preset-8Xh21Uyw.js → preset-Cl3Q5ASC.js} +8 -2
- package/dist/{preview-B-mtB1ka.d.ts → preview-Bwg7r1Lf.d.ts} +2 -2
- package/dist/{project-C6JAWCnH.js → project-At5wBJSS.js} +5 -5
- package/dist/{push-token-TWXWra8i.d.ts → push-token-C6ZGE1g0.d.ts} +1 -1
- package/dist/query/index.d.ts +1 -1
- package/dist/react/index.d.ts +6 -6
- 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-B9-7RhYz.d.ts → record-form-DTncyqVH.d.ts} +1 -1
- package/dist/records/index.d.ts +7 -7
- package/dist/{sales-CLHrvNDm.js → sales-BhOckhix.js} +3 -3
- package/dist/server/index.d.ts +3 -3
- package/dist/solid/index.d.ts +5 -5
- package/dist/sql/index.d.ts +6 -6
- package/dist/sql/index.js +3 -3
- package/dist/{sql-Bam07JIf.js → sql-CdZdPqjA.js} +1010 -219
- package/dist/sqlite/index.d.ts +1 -1
- package/dist/ssr/index.d.ts +1 -1
- package/dist/svelte/index.d.ts +5 -5
- package/dist/tanstack-db/index.d.ts +1 -1
- package/dist/{tenant-BpJ2F2b_.d.ts → tenant-BTnwa5oZ.d.ts} +1 -1
- package/dist/testing/index.d.ts +6 -6
- package/dist/testing/index.js +1 -1
- package/dist/{timeline-LHtdAJnM.d.ts → timeline-B7kBQ1gh.d.ts} +2 -2
- package/dist/{topic-4KYLvvTB.d.ts → topic-hu0RP7CG.d.ts} +1 -1
- package/dist/{types-Dfa7b0KI.d.ts → types-DvglaQ_D.d.ts} +2 -2
- package/dist/vue/index.d.ts +5 -5
- package/dist/{watch-topic-C9DIO476.d.ts → watch-topic-C_rGHxIA.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/schemas/config-v1.json +64 -1
- package/skills/better-supabase-api/references/powersync.md +1 -0
- package/dist/cli/add-3L9NVEA3.js +0 -1
- package/dist/cli/powersync-COHj6FT8.js +0 -1
- package/dist/cli/seed-CRD1tYPA.js +0 -1
|
@@ -6,10 +6,10 @@ import { a as hasPlaceholder, l as splitPlaceholders, r as containsPlaceholder,
|
|
|
6
6
|
import { r as isFunctionSpec } from "./spec-BSc8n34a.js";
|
|
7
7
|
import { a as OPERATION_RENAMES, c as PROGRAM_EVENT_MOVES, f as configuredAction, g as isOldPermissionKey, i as EVENT_TYPE_SPLITS, m as currentPermissionKeys, o as PERMISSION_KEY_RENAMES, p as currentEventTypes, r as EVENT_TYPE_RENAMES, s as PERMISSION_KEY_SPLITS, t as ENTITY_KEY_RENAMES, u as SUBJECT_TYPE_RENAMES } from "./renames-PnqMkqit.js";
|
|
8
8
|
import { t as SPEC_PINS } from "./spec-pins-Dlz8OVqi.js";
|
|
9
|
-
import { _ as resolveJsonSchema, a as blockFormerSubjectTypes, d as freesTableName, f as tableBase, g as clientFunctions, h as resolveNames, l as blockColumnName, m as entityType, p as tableMoves, s as installedBlockSubjects, u as columnRenamer, v as CONFIG_DEFAULTS } from "./block-subjects-
|
|
9
|
+
import { _ as resolveJsonSchema, a as blockFormerSubjectTypes, d as freesTableName, f as tableBase, g as clientFunctions, h as resolveNames, l as blockColumnName, m as entityType, p as tableMoves, s as installedBlockSubjects, u as columnRenamer, v as CONFIG_DEFAULTS } from "./block-subjects-BoJrJAgR.js";
|
|
10
10
|
import { t as DEFAULT_CLAIMS } from "./claims-CqTr_N1n.js";
|
|
11
11
|
import { o as tenantNames, r as composeNames } from "./entity-naming-BES3pkQI.js";
|
|
12
|
-
import { B as resolveBlock, C as columnsWithAccess, E as hiddenColumns, I as PRESET_CATALOG, L as BLOCK_SCOPES, N as createdFromLink, P as link, S as hasComputed, T as hasColumnAccess, V as tenantNameOf, a as isRenamedInstance, g as appTableVersions, i as instancePrefix, l as APP_RANK_COLUMN, m as appTableEventKinds, s as APP_DELETED_AT_COLUMN, w as encryptedColumns, y as lookupColumn } from "./instances-
|
|
12
|
+
import { B as resolveBlock, C as columnsWithAccess, E as hiddenColumns, I as PRESET_CATALOG, L as BLOCK_SCOPES, N as createdFromLink, P as link, S as hasComputed, T as hasColumnAccess, V as tenantNameOf, a as isRenamedInstance, g as appTableVersions, i as instancePrefix, l as APP_RANK_COLUMN, m as appTableEventKinds, s as APP_DELETED_AT_COLUMN, w as encryptedColumns, y as lookupColumn } from "./instances-BMjIO6Xu.js";
|
|
13
13
|
import { i as FIELD_FORMATS, n as CUSTOM_FIELD_FORM_TYPES, o as FIELD_FORMAT_VALIDATORS, r as CUSTOM_FIELD_TYPES, s as RATING_BOUNDS, t as CUSTOM_FIELD_CHECKED_FORMATS } from "./field-formats-sLYMh1ZK.js";
|
|
14
14
|
import { t as isSqlType } from "./sql-type-XWMeZRAl.js";
|
|
15
15
|
import { a as sqlString, i as sqlIdent$1 } from "./template-1e2akYYK.js";
|
|
@@ -17,7 +17,7 @@ import { i as fillTemplate, u as templatePlaceholders } from "./access-sql-DH2Lb
|
|
|
17
17
|
import { a as readGrants, c as renderPolicy, i as policy$1, n as closingParen$1, o as readPolicies, r as maskSql, s as readPolicy$6, t as catalogPolicy } from "./policy-B9UWDXMF.js";
|
|
18
18
|
import { t as MAX_BATCH$1 } from "./batch-limit-DqQ3d6op.js";
|
|
19
19
|
import { $ as updateExtraColumns, A as membershipDisabledAt, B as registerPartitions, C as extraFieldsJson, D as jwtClaim, E as jsonSchemaChecks, F as pageSize, G as serviceGrant, H as replaceColumnCheck, I as quotedTable, J as shortHash, K as serviceOnly$1, L as raise$1, M as notNullCheckName, N as organizationMissing, O as lockTable, P as ownRowPolicies, Q as triggerGrant, R as readLine, S as extraFieldsArg, T as insertExtraColumns, U as revokeTable, V as renameSql, W as schemaPreamble, X as transitionActorSql, Y as splitTable$1, Z as transitionReasonSql, _ as defaultPartitionName, a as SCHEMA$6, b as dropExpiredPartitions, c as activeMembership, d as addForeignKey, et as updatedAt, f as addNotNullCheck, g as defaultPartition, h as columnsObject, i as PARTITION_VARIABLES, j as membershipSuspended, k as memberAddedRecord, l as addCheck, m as columnRef, n as MONTHLY_PARTITIONS, nt as withExtraFields, o as SERVICE_CALLER$1, p as batchFunction, q as sha256HexSql, r as NOTHING, rt as writeExtraColumns, s as accessDefinesDisabledHelpers, t as EQUIVALENT_TRIGGERS, tt as userGrant, u as addExtraColumns, v as disabledHelpers, w as fail, x as ensureCheck, y as disabledHelpersNeedLaterTables, z as recordTrigger } from "./shared-DwShIqeQ.js";
|
|
20
|
-
import { $ as qualifiedTable$2, A as editableContracts, B as entryEnded, C as leaveOwner, D as recordOwner, E as ownerIsEmployee, F as splitName, G as boundSubjectMatch, H as lockedColumns, I as feedOptions, J as liveShareLink, K as boundSubjects$1, L as feedWindow, M as majorSalary, N as overlappingContracts, O as FLAT_DETAILS, P as reportsMoveUp, Q as onSettings, R as byEmployee, S as leaveConfidentialReader, T as leavePartsMapped, U as timeOwner, V as entrySubjects, W as boundRowSubject, X as touchShareLink, Y as shareLinkRow, Z as andSubjectAction, _ as leaveBalancesTable, a as leaveEndPart, at as subjectTableBindings, b as leaveConfidentialFilter, c as leavePartial, ct as payrollExportSqlOptions, d as leaveTeamFeedSubject, dt as withColumnTypeFunction, et as subjectAccess, f as leaveTypeKey, g as leaveAutoApproveMapped, h as leaveAutoApprove, it as subjectReadable, j as flatDetails, k as denyOverlaps, l as leaveRequestUser, lt as asColumnType, m as halfDays, nt as subjectCascades, o as leaveFeed, ot as subjectTypeGuard, p as dropSignatures, q as SHARE_LINKS, rt as subjectIdMatches, s as leaveFeedSubject, st as subjectsOption, t as PAYROLL_EXPORT, tt as subjectActionCheck, u as leaveStartPart, ut as tryColumnType, v as leaveByEmployee, w as leaveParts, x as leaveConfidentialKey, y as leaveConfidential, z as durationEntries } from "./payroll-export-
|
|
20
|
+
import { $ as qualifiedTable$2, A as editableContracts, B as entryEnded, C as leaveOwner, D as recordOwner, E as ownerIsEmployee, F as splitName, G as boundSubjectMatch, H as lockedColumns, I as feedOptions, J as liveShareLink, K as boundSubjects$1, L as feedWindow, M as majorSalary, N as overlappingContracts, O as FLAT_DETAILS, P as reportsMoveUp, Q as onSettings, R as byEmployee, S as leaveConfidentialReader, T as leavePartsMapped, U as timeOwner, V as entrySubjects, W as boundRowSubject, X as touchShareLink, Y as shareLinkRow, Z as andSubjectAction, _ as leaveBalancesTable, a as leaveEndPart, at as subjectTableBindings, b as leaveConfidentialFilter, c as leavePartial, ct as payrollExportSqlOptions, d as leaveTeamFeedSubject, dt as withColumnTypeFunction, et as subjectAccess, f as leaveTypeKey, g as leaveAutoApproveMapped, h as leaveAutoApprove, it as subjectReadable, j as flatDetails, k as denyOverlaps, l as leaveRequestUser, lt as asColumnType, m as halfDays, nt as subjectCascades, o as leaveFeed, ot as subjectTypeGuard, p as dropSignatures, q as SHARE_LINKS, rt as subjectIdMatches, s as leaveFeedSubject, st as subjectsOption, t as PAYROLL_EXPORT, tt as subjectActionCheck, u as leaveStartPart, ut as tryColumnType, v as leaveByEmployee, w as leaveParts, x as leaveConfidentialKey, y as leaveConfidential, z as durationEntries } from "./payroll-export-ChZY6W3w.js";
|
|
21
21
|
import { n as blockOptions, r as option, t as NO_OPTIONS } from "./options-Z-bd_H1E.js";
|
|
22
22
|
import { t as accessRequestsSqlOptions } from "./options-Cl7lLI30.js";
|
|
23
23
|
import { t as accountingSqlOptions } from "./options-C3FFnaE-.js";
|
|
@@ -79,8 +79,8 @@ import { t as importsSqlOptions } from "./options-CQmxsjZK.js";
|
|
|
79
79
|
import { r as inboxSqlOptions, t as CONVERSATION_TO_TASK } from "./automations-CkwKi84L.js";
|
|
80
80
|
import { t as incidentsSqlOptions } from "./options-BmFSI07A.js";
|
|
81
81
|
import { a as INSPECTION_PROGRAM_STATUSES, i as INSPECTION_MEMBER_ROLES, n as DEFAULT_INSPECTION_FINDING_TYPES, o as INSPECTION_STATUSES, r as DEFAULT_INSPECTION_KINDS, s as inspectionsSqlOptions, t as DEFAULT_INSPECTION_CASE_FINDING_TYPES } from "./inspections-values-Djv5fqaw.js";
|
|
82
|
-
import { i as inventorySqlOptions, n as INVENTORY_READS, r as inventoryReads } from "./inventory-reads-
|
|
83
|
-
import { t as invoicesSqlOptions } from "./options-
|
|
82
|
+
import { i as inventorySqlOptions, n as INVENTORY_READS, r as inventoryReads } from "./inventory-reads-DEw2Kbff.js";
|
|
83
|
+
import { t as invoicesSqlOptions } from "./options-Cu6IqZ_n.js";
|
|
84
84
|
import { t as knowledgeSqlOptions } from "./options-BNtLQZrG.js";
|
|
85
85
|
import { t as leadScoringSqlOptions } from "./options-COfEYic3.js";
|
|
86
86
|
import { t as leasesSqlOptions } from "./options-KcNfi9A3.js";
|
|
@@ -102,7 +102,7 @@ import { t as oauthServerSqlOptions } from "./options-ax_ssX_m.js";
|
|
|
102
102
|
import { t as observationsSqlOptions } from "./options-DIS8K_PS.js";
|
|
103
103
|
import { t as onboardingSqlOptions } from "./options-DP7NwQPZ.js";
|
|
104
104
|
import { t as optionSetsSqlOptions } from "./options-DtDvpZu7.js";
|
|
105
|
-
import { A as
|
|
105
|
+
import { A as assignWhen, B as templateColumnSql, C as storefrontOption, D as uniqueViolationOn, E as columnDefaults, F as sequenceEntry, G as rankAfter, H as templateRowsOf, I as sequences, K as rankBackfill, L as excludeTemplates, M as scopeSql, N as sequenceFormatOf, O as withColumnDefault, P as withFixedNumber, R as liveRowsIndex, S as productSettingTypes, T as catalogRank, U as templateTriggerReturn, V as templateGuardSql, W as RANK_KEY_PATTERN, _ as categoryExtras, a as asService, b as productExtras, c as guard$12, d as orderTemplatesOn, f as paymentWindow, g as amountOf, h as SLUG$7, i as amountOf$1, j as hasLegalEntityColumn, k as assignNumberSql, l as orderFields, m as transitionFunction, o as assignNumber$1, p as serviceOnlyGuard, q as ordersSqlOptions, r as orderReads, s as columns, t as ORDER_READS, u as orderPayload, v as guard$11, w as variantExtras, x as productFunctions$1, y as optionFunctions, z as sourceTemplateColumnSql } from "./orders-reads-2ozdZx1l.js";
|
|
106
106
|
import { a as organizationsSqlOptions, i as invitationsSqlOptions, n as ORGANIZATION_READS, r as organizationOverview } from "./organizations-overview-CSpcd2FE.js";
|
|
107
107
|
import { t as outboxSqlOptions } from "./options-CptvcSmF.js";
|
|
108
108
|
import { t as passesSqlOptions } from "./options-CkhQoLJy.js";
|
|
@@ -115,7 +115,7 @@ import { t as promptsSqlOptions } from "./options-qsL6D-7s.js";
|
|
|
115
115
|
import { t as pushSqlOptions } from "./options-jg0FMHA5.js";
|
|
116
116
|
import { t as qualificationsSqlOptions } from "./options-BZ5TzeFN.js";
|
|
117
117
|
import { n as rateLimitSqlOptions, r as webhookInboxSqlOptions, t as queueSqlOptions } from "./options-BTRH26MJ.js";
|
|
118
|
-
import { i as quotesSqlOptions, r as QUOTE_TO_ORDER } from "./automations-
|
|
118
|
+
import { i as quotesSqlOptions, r as QUOTE_TO_ORDER } from "./automations-Cu1KdCvL.js";
|
|
119
119
|
import { t as reactionsSqlOptions } from "./options-BcBdiPSZ.js";
|
|
120
120
|
import { n as referralsSqlOptions, t as REFERRAL_STATUSES } from "./referrals-values-EXlMZA7X.js";
|
|
121
121
|
import { t as relationsSqlOptions } from "./options-Lg76d-cV.js";
|
|
@@ -141,9 +141,9 @@ import { t as ssoSqlOptions } from "./options-CzWjw2HY.js";
|
|
|
141
141
|
import { t as stateMachineSqlOptions } from "./options-Oki2W_c3.js";
|
|
142
142
|
import { n as subjectsSqlOptions, t as DEFAULT_RECORD_TEAM_ROLES } from "./options-DtxrIk8Q.js";
|
|
143
143
|
import { t as tagsSqlOptions } from "./options-CyDOOWlk.js";
|
|
144
|
-
import { t as tasksSqlOptions } from "./options-
|
|
144
|
+
import { t as tasksSqlOptions } from "./options-Oo46IzNk.js";
|
|
145
145
|
import { t as teamsSqlOptions } from "./options-B8c2_hIB.js";
|
|
146
|
-
import { t as templatesSqlOptions } from "./options-
|
|
146
|
+
import { t as templatesSqlOptions } from "./options-C1N8cOQU.js";
|
|
147
147
|
import { t as timeTrackingSqlOptions } from "./options-DjdxZgHi.js";
|
|
148
148
|
import { t as trashSqlOptions } from "./options-B3xH2JvJ.js";
|
|
149
149
|
import { t as updatedAtSqlOptions } from "./options-1iHDmlZ5.js";
|
|
@@ -154,7 +154,7 @@ import { t as waitlistSqlOptions } from "./options-DFgHHwzD.js";
|
|
|
154
154
|
import { n as webhooksOutSqlOptions, t as webhooksInSqlOptions } from "./options-BfY4pyQE.js";
|
|
155
155
|
import { t as workflowEditorSqlOptions } from "./options-SlC_jZ7y.js";
|
|
156
156
|
import { t as workflowsSqlOptions } from "./options-BxOFSs-u.js";
|
|
157
|
-
import { a as registeredIdMatches, c as teamActions, d as subjectPermissionKey, f as subjectPermissionOf, i as logsSubjectReads, l as tenantColumnOf, n as auditedSubjects, o as registeredSubjects, r as checkCall, t as uniqueContributions, u as urlExpression } from "./contributions-
|
|
157
|
+
import { a as registeredIdMatches, c as teamActions, d as subjectPermissionKey, f as subjectPermissionOf, i as logsSubjectReads, l as tenantColumnOf, n as auditedSubjects, o as registeredSubjects, r as checkCall, t as uniqueContributions, u as urlExpression } from "./contributions-olp7tVYC.js";
|
|
158
158
|
import { n as SUBJECT_TYPE_SQL_PATTERN, r as subjectTypeIdent } from "./subject-type-BarjdHZV.js";
|
|
159
159
|
import { a as moduleOperations, c as roleNames, d as tenantScope, i as isOperationModule$1, l as roleScopeIs, n as OPERATIONS, o as modulePermission, r as accessModel, s as modulePermissionKey, u as rolesOf } from "./permissions-model-Dh9-Zzfy.js";
|
|
160
160
|
import { i as CHECKOUT_SESSION_STATUSES, n as AGENT_MANDATE_TYPES, r as CHECKOUT_PROTOCOLS, t as AGENT_MANDATE_STATUSES } from "./agent-checkout-values-Cn6rZgn4.js";
|
|
@@ -371,7 +371,7 @@ const TYPE_STARTS = /* @__PURE__ */ new Set([
|
|
|
371
371
|
"bit",
|
|
372
372
|
"interval"
|
|
373
373
|
]);
|
|
374
|
-
const normalize = (type) => type.replaceAll(/\s+/g, " ").replaceAll("\"", "").trim().toLowerCase();
|
|
374
|
+
const normalize$1 = (type) => type.replaceAll(/\s+/g, " ").replaceAll("\"", "").trim().toLowerCase();
|
|
375
375
|
/** Splits on commas outside parentheses and quotes. */
|
|
376
376
|
function splitTopLevel$1(text) {
|
|
377
377
|
const parts = [];
|
|
@@ -454,7 +454,7 @@ function sourceDrops(sql, schema) {
|
|
|
454
454
|
const drop = new RegExp(`drop\\s+function\\s+if\\s+exists\\s+${ident}\\.(?:"([^"]+)"|([a-z_][a-z0-9_]*))\\s*\\(([^)]*)\\)\\s*;`, "gi");
|
|
455
455
|
return [...sql.matchAll(drop)].map((match) => ({
|
|
456
456
|
name: match[1] ?? match[2],
|
|
457
|
-
types: splitTopLevel$1(match[3]).map(normalize).join(", ")
|
|
457
|
+
types: splitTopLevel$1(match[3]).map(normalize$1).join(", ")
|
|
458
458
|
}));
|
|
459
459
|
}
|
|
460
460
|
function apiGrants(sql, schema) {
|
|
@@ -465,7 +465,7 @@ function apiGrants(sql, schema) {
|
|
|
465
465
|
if (roles.length === 0) return [];
|
|
466
466
|
return [{
|
|
467
467
|
name: match[1] ?? match[2],
|
|
468
|
-
types: splitTopLevel$1(match[3]).map(normalize),
|
|
468
|
+
types: splitTopLevel$1(match[3]).map(normalize$1),
|
|
469
469
|
roles
|
|
470
470
|
}];
|
|
471
471
|
});
|
|
@@ -516,7 +516,7 @@ function apiWrappers(sql, source, api, module, internal = [], client = []) {
|
|
|
516
516
|
const replaced = [...new Set(sourceDrops(sql, source).filter((entry) => wrapped.has(entry.name)).map((entry) => `drop function if exists ${schema}.${sqlIdent$1(entry.name)}(${entry.types});`))];
|
|
517
517
|
if (grants.length === 0 && dropped.length === 0) return "";
|
|
518
518
|
const statements = grants.map((grant) => {
|
|
519
|
-
const signature = defined.find((entry) => entry.name === grant.name && inputs(entry).length === grant.types.length && inputs(entry).every((arg, index) => normalize(arg.type) === grant.types[index]));
|
|
519
|
+
const signature = defined.find((entry) => entry.name === grant.name && inputs(entry).length === grant.types.length && inputs(entry).every((arg, index) => normalize$1(arg.type) === grant.types[index]));
|
|
520
520
|
if (!signature) throw new TypeError(`blocks.${module}.api: found no definition of ${grant.name}(${grant.types.join(", ")}) to wrap`);
|
|
521
521
|
return wrapper(signature, source, api.schema, grant);
|
|
522
522
|
});
|
|
@@ -660,7 +660,7 @@ function registration(args) {
|
|
|
660
660
|
redact
|
|
661
661
|
};
|
|
662
662
|
}
|
|
663
|
-
const CALL$
|
|
663
|
+
const CALL$2 = /\bbetter_supabase\s*\.\s*(un)?audit\s*\(/gi;
|
|
664
664
|
const IDENT$13 = String.raw`(?:"(?:[^"]|"")+"|[A-Za-z_][\w$]*)`;
|
|
665
665
|
const TRIGGER$3 = /* @__PURE__ */ new RegExp(String.raw`\bcreate\s+(?:or\s+replace\s+)?trigger\s+"?bsb?_audit"?\s+after\s+[\s\S]*?\bon\s+(${IDENT$13}(?:\s*\.\s*${IDENT$13})?)\s+for\s+each\s+row\s+execute\s+(?:function|procedure)\s+better_supabase\s*\.\s*audit_row_change\s*\(`, "gi");
|
|
666
666
|
const TABLE_NAME$5 = String.raw`${IDENT$13}(?:\s*\.\s*${IDENT$13})?`;
|
|
@@ -694,7 +694,7 @@ function auditRegistrations(files) {
|
|
|
694
694
|
for (const file of files) {
|
|
695
695
|
const text = withoutComments(file.text);
|
|
696
696
|
const found = [
|
|
697
|
-
...[...text.matchAll(CALL$
|
|
697
|
+
...[...text.matchAll(CALL$2)].map((match) => ({
|
|
698
698
|
match,
|
|
699
699
|
kind: "call"
|
|
700
700
|
})),
|
|
@@ -754,7 +754,7 @@ function qualified$10(target) {
|
|
|
754
754
|
const parts = (target.match(new RegExp(NAME$10, "g")) ?? []).map(unquote$6);
|
|
755
755
|
return parts.length === 1 ? `public.${parts[0]}` : parts.join(".");
|
|
756
756
|
}
|
|
757
|
-
const TABLE$
|
|
757
|
+
const TABLE$3 = /* @__PURE__ */ new RegExp(String.raw`\bcreate\s+(?:unlogged\s+)?table\s+(?:if\s+not\s+exists\s+)?(${NAME$10}(?:\s*\.\s*${NAME$10})?)\s*\(`, "gi");
|
|
758
758
|
/** `*` in a `schema.table` glob matches any run of characters. */
|
|
759
759
|
function tableGlobs(globs) {
|
|
760
760
|
return globs.map((glob) => new RegExp(`^${glob.split("*").map((part) => part.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*")}$`, "i"));
|
|
@@ -767,7 +767,7 @@ function declaredTables(files, schemas) {
|
|
|
767
767
|
const found = /* @__PURE__ */ new Set();
|
|
768
768
|
for (const file of files) {
|
|
769
769
|
const text = withoutComments(file.text);
|
|
770
|
-
inOrder([[...text.matchAll(TABLE$
|
|
770
|
+
inOrder([[...text.matchAll(TABLE$3)].map((match) => ({
|
|
771
771
|
index: match.index,
|
|
772
772
|
apply: () => {
|
|
773
773
|
const table = qualified$10(match[1]);
|
|
@@ -931,7 +931,7 @@ function declaredColumnTypes(files, schemas) {
|
|
|
931
931
|
const found = /* @__PURE__ */ new Map();
|
|
932
932
|
for (const file of files) {
|
|
933
933
|
const text = withoutComments(file.text);
|
|
934
|
-
for (const match of text.matchAll(TABLE$
|
|
934
|
+
for (const match of text.matchAll(TABLE$3)) {
|
|
935
935
|
const table = qualified$10(match[1]);
|
|
936
936
|
if (!schemas.includes(table.slice(0, table.indexOf(".")))) continue;
|
|
937
937
|
const open = match.index + match[0].length - 1;
|
|
@@ -1169,7 +1169,7 @@ function declaredIndexes(files, schemas) {
|
|
|
1169
1169
|
for (const file of files) {
|
|
1170
1170
|
const text = withoutComments(file.text);
|
|
1171
1171
|
for (const index of indexStatements(text)) if (!index.partial && index.method === "btree") add(index.table, index.columns, index.name);
|
|
1172
|
-
for (const match of text.matchAll(TABLE$
|
|
1172
|
+
for (const match of text.matchAll(TABLE$3)) {
|
|
1173
1173
|
const table = qualified$10(match[1]);
|
|
1174
1174
|
const open = match.index + match[0].length - 1;
|
|
1175
1175
|
const close = closingParen(text, open);
|
|
@@ -1350,7 +1350,7 @@ function overAppTables(sql, appTables, appColumns = {}) {
|
|
|
1350
1350
|
const masked = maskComments(sql);
|
|
1351
1351
|
let out = "";
|
|
1352
1352
|
let at = 0;
|
|
1353
|
-
for (const match of masked.matchAll(TABLE$
|
|
1353
|
+
for (const match of masked.matchAll(TABLE$3)) {
|
|
1354
1354
|
const table = qualified$10(match[1]);
|
|
1355
1355
|
if (!appTables.has(table) || match.index < at) continue;
|
|
1356
1356
|
const open = match.index + match[0].length - 1;
|
|
@@ -1910,6 +1910,30 @@ const BLOCK_OPTION_SCHEMAS = {
|
|
|
1910
1910
|
function optionSchemaOf(module) {
|
|
1911
1911
|
return Object.entries(BLOCK_OPTION_SCHEMAS).find(([name]) => name === module)?.[1];
|
|
1912
1912
|
}
|
|
1913
|
+
// src/sql/audit-actions.ts
|
|
1914
|
+
/**
|
|
1915
|
+
* The outbox statement, written only when `live` is true. An empty event or no
|
|
1916
|
+
* guard is returned unchanged.
|
|
1917
|
+
*/
|
|
1918
|
+
function liveStatement(event, live) {
|
|
1919
|
+
if (event === "" || live === void 0) return event;
|
|
1920
|
+
return `if ${live} then\n ${event.replaceAll("\n", "\n ")}\n end if;`;
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* The categories module actions are audited under. An adopted log with its own
|
|
1924
|
+
* names maps them through `blocks.audit.options.values.category`.
|
|
1925
|
+
*/
|
|
1926
|
+
const AUDIT_CATEGORIES = [
|
|
1927
|
+
"membership",
|
|
1928
|
+
"access",
|
|
1929
|
+
"security",
|
|
1930
|
+
"configuration",
|
|
1931
|
+
"billing",
|
|
1932
|
+
"data",
|
|
1933
|
+
"ai",
|
|
1934
|
+
"integration",
|
|
1935
|
+
"read"
|
|
1936
|
+
];
|
|
1913
1937
|
// src/sql/default-rule-row.ts
|
|
1914
1938
|
const UPDATED = [
|
|
1915
1939
|
"subjectType",
|
|
@@ -2600,7 +2624,7 @@ function createModuleContext(module, namesOf, source = {}) {
|
|
|
2600
2624
|
hookTarget,
|
|
2601
2625
|
emit: outbox,
|
|
2602
2626
|
record(action) {
|
|
2603
|
-
const parts = [outbox(action), auditEntry(action)].filter((part) => part !== "");
|
|
2627
|
+
const parts = [liveStatement(outbox(action), action.live), auditEntry(action)].filter((part) => part !== "");
|
|
2604
2628
|
return parts.length === 0 ? NOTHING : parts.join("\n ");
|
|
2605
2629
|
},
|
|
2606
2630
|
audit(action) {
|
|
@@ -10985,7 +11009,7 @@ const ACCOUNTING = {
|
|
|
10985
11009
|
}
|
|
10986
11010
|
};
|
|
10987
11011
|
// src/sql/modules/acknowledgements-functions.ts
|
|
10988
|
-
const COLUMN$
|
|
11012
|
+
const COLUMN$14 = /^[a-z_][a-z0-9_]*$/;
|
|
10989
11013
|
/**
|
|
10990
11014
|
* The record types whose current version is a column on the record
|
|
10991
11015
|
* (`on.<type>.versionColumn`, or a block's `acknowledgements` contribution),
|
|
@@ -10996,7 +11020,7 @@ function versionColumns(ctx, subjects) {
|
|
|
10996
11020
|
const own = subjects.flatMap(([type, subject]) => {
|
|
10997
11021
|
const column = subject.extra["versionColumn"];
|
|
10998
11022
|
if (column === void 0) return [];
|
|
10999
|
-
if (typeof column !== "string" || !COLUMN$
|
|
11023
|
+
if (typeof column !== "string" || !COLUMN$14.test(column)) throw new TypeError(`blocks.${ctx.instance}.on.${type}.versionColumn must be a column name`);
|
|
11000
11024
|
return [[
|
|
11001
11025
|
type,
|
|
11002
11026
|
subject,
|
|
@@ -12713,7 +12737,7 @@ function recordingsContract() {
|
|
|
12713
12737
|
];
|
|
12714
12738
|
}
|
|
12715
12739
|
// src/sql/modules/activities-data.ts
|
|
12716
|
-
const COLUMN$
|
|
12740
|
+
const COLUMN$13 = "action_items";
|
|
12717
12741
|
/**
|
|
12718
12742
|
* Copies each note's `action_items` into tasks through the tasks block's
|
|
12719
12743
|
* `create_task` and links them in the note actions table. A note whose activity
|
|
@@ -12741,10 +12765,10 @@ begin
|
|
|
12741
12765
|
raise exception 'the activities upgrade copies action_items into tasks as the service role or the migration role';
|
|
12742
12766
|
end if;
|
|
12743
12767
|
for v_note in
|
|
12744
|
-
select x.${n("engagement")} as id, x.${n("tenant")} as tenant, x.${COLUMN$
|
|
12768
|
+
select x.${n("engagement")} as id, x.${n("tenant")} as tenant, x.${COLUMN$13} as items
|
|
12745
12769
|
from ${notes} x
|
|
12746
|
-
where jsonb_typeof(x.${COLUMN$
|
|
12747
|
-
and jsonb_array_length(x.${COLUMN$
|
|
12770
|
+
where jsonb_typeof(x.${COLUMN$13}) = 'array'
|
|
12771
|
+
and jsonb_array_length(x.${COLUMN$13}) > 0
|
|
12748
12772
|
and not exists (select 1 from ${actions} y where y.${a("engagement")} = x.${n("engagement")})
|
|
12749
12773
|
order by x.${n("engagement")}
|
|
12750
12774
|
loop
|
|
@@ -12794,8 +12818,8 @@ const NOTE_ACTION_ITEMS_TO_TASKS = {
|
|
|
12794
12818
|
const table = ctx.table("notes");
|
|
12795
12819
|
const withTasks = ctx.installed("tasks") && ctx.of("tasks").mode !== "custom";
|
|
12796
12820
|
const regclass = `to_regclass(${sqlString(table)})`;
|
|
12797
|
-
const exists = `exists (select 1 from pg_attribute where attrelid = ${regclass} and attname = ${sqlString(COLUMN$
|
|
12798
|
-
const holds = `exists (select 1 from ${table} x where jsonb_typeof(x.${COLUMN$
|
|
12821
|
+
const exists = `exists (select 1 from pg_attribute where attrelid = ${regclass} and attname = ${sqlString(COLUMN$13)} and not attisdropped)`;
|
|
12822
|
+
const holds = `exists (select 1 from ${table} x where jsonb_typeof(x.${COLUMN$13}) = 'array' and jsonb_array_length(x.${COLUMN$13}) > 0)`;
|
|
12799
12823
|
const tasks = withTasks ? ctx.of("tasks") : void 0;
|
|
12800
12824
|
const a = (column) => ctx.col("actions", column);
|
|
12801
12825
|
const link = tasks === void 0 ? "" : `create table if not exists ${ctx.table("actions")} (
|
|
@@ -12818,7 +12842,7 @@ ${tasks === void 0 ? ` if ${holds} then
|
|
|
12818
12842
|
${link}
|
|
12819
12843
|
execute ${sqlString(copyActionItems$1(ctx))};
|
|
12820
12844
|
end if;`}
|
|
12821
|
-
alter table ${table} drop column ${COLUMN$
|
|
12845
|
+
alter table ${table} drop column ${COLUMN$13};
|
|
12822
12846
|
end if;
|
|
12823
12847
|
end;
|
|
12824
12848
|
$upgrade$;`;
|
|
@@ -13331,7 +13355,7 @@ const NAMES$151 = {
|
|
|
13331
13355
|
...RECORDING_TABLES
|
|
13332
13356
|
}
|
|
13333
13357
|
};
|
|
13334
|
-
const TYPE$
|
|
13358
|
+
const TYPE$6 = /^[a-z][a-z0-9_]{0,62}$/;
|
|
13335
13359
|
/**
|
|
13336
13360
|
* Row `alias` of logical table `table` as JSON keyed by the module's column
|
|
13337
13361
|
* names. Over the app's table it lists the module's columns only, with null for
|
|
@@ -13343,7 +13367,7 @@ function rowJson$5(ctx, table, alias) {
|
|
|
13343
13367
|
}
|
|
13344
13368
|
function types(ctx) {
|
|
13345
13369
|
const list = ctx.list("types", ACTIVITY_TYPES);
|
|
13346
|
-
if (list.length === 0 || list.some((item) => !TYPE$
|
|
13370
|
+
if (list.length === 0 || list.some((item) => !TYPE$6.test(item))) throw new TypeError("blocks.activities.options.types must be a non-empty list of lowercase names");
|
|
13347
13371
|
return list;
|
|
13348
13372
|
}
|
|
13349
13373
|
function build$154(ctx) {
|
|
@@ -13866,7 +13890,7 @@ const ADVISORY_SEVERITIES = [
|
|
|
13866
13890
|
"high",
|
|
13867
13891
|
"critical"
|
|
13868
13892
|
];
|
|
13869
|
-
const quoted$
|
|
13893
|
+
const quoted$6 = (values) => values.map((value) => sqlString(value)).join(", ");
|
|
13870
13894
|
function advisoriesSql(ctx) {
|
|
13871
13895
|
const p = (column) => ctx.col("products", column);
|
|
13872
13896
|
const v = (column) => ctx.col("versions", column);
|
|
@@ -14433,13 +14457,13 @@ begin
|
|
|
14433
14457
|
if not ${q.allowed("save_vex_statement.tenant", q.write)} then
|
|
14434
14458
|
${q.forbidden("not allowed to change advisories")}
|
|
14435
14459
|
end if;
|
|
14436
|
-
if coalesce(save_vex_statement.status, '') not in (${quoted$
|
|
14460
|
+
if coalesce(save_vex_statement.status, '') not in (${quoted$6(ADVISORY_VEX_STATUSES)}) then
|
|
14437
14461
|
${q.invalid(`status must be one of ${ADVISORY_VEX_STATUSES.join(", ")}`)}
|
|
14438
14462
|
end if;
|
|
14439
14463
|
if save_vex_statement.status = 'not_affected' and (save_vex_statement.justification is null and nullif(trim(save_vex_statement.impact_statement), '') is null) then
|
|
14440
14464
|
${q.invalid("not_affected needs a justification or an impact statement")}
|
|
14441
14465
|
end if;
|
|
14442
|
-
if save_vex_statement.justification is not null and (save_vex_statement.status <> 'not_affected' or save_vex_statement.justification not in (${quoted$
|
|
14466
|
+
if save_vex_statement.justification is not null and (save_vex_statement.status <> 'not_affected' or save_vex_statement.justification not in (${quoted$6(ADVISORY_VEX_JUSTIFICATIONS)})) then
|
|
14443
14467
|
${q.invalid("a justification applies to not_affected and is one of the OpenVEX justifications")}
|
|
14444
14468
|
end if;
|
|
14445
14469
|
if length(save_vex_statement.impact_statement) > 5000 or length(save_vex_statement.action_statement) > 5000 then
|
|
@@ -14556,7 +14580,7 @@ begin
|
|
|
14556
14580
|
if coalesce(length(trim(save_advisory.title)), 0) not between 1 and 300 or length(save_advisory.summary) > 10000 then
|
|
14557
14581
|
${q.invalid("title must be 1 to 300 characters and summary at most 10000")}
|
|
14558
14582
|
end if;
|
|
14559
|
-
if save_advisory.severity is not null and save_advisory.severity not in (${quoted$
|
|
14583
|
+
if save_advisory.severity is not null and save_advisory.severity not in (${quoted$6(ADVISORY_SEVERITIES)}) then
|
|
14560
14584
|
${q.invalid(`severity must be one of ${ADVISORY_SEVERITIES.join(", ")}`)}
|
|
14561
14585
|
end if;
|
|
14562
14586
|
if cardinality(v_ids) > 500 then
|
|
@@ -15133,7 +15157,7 @@ create table if not exists ${q.vulnerabilities} (
|
|
|
15133
15157
|
${x("cvssVector")} text check (${x("cvssVector")} is null or length(${x("cvssVector")}) <= 300),
|
|
15134
15158
|
${x("cvssVersion")} text check (${x("cvssVersion")} is null or ${x("cvssVersion")} in ('3.0', '3.1', '4.0')),
|
|
15135
15159
|
${x("cvssScore")} numeric(3, 1) check (${x("cvssScore")} is null or ${x("cvssScore")} between 0 and 10),
|
|
15136
|
-
${x("severity")} text check (${x("severity")} is null or ${x("severity")} in (${quoted$
|
|
15160
|
+
${x("severity")} text check (${x("severity")} is null or ${x("severity")} in (${quoted$6(ADVISORY_SEVERITIES)})),
|
|
15137
15161
|
${x("epssScore")} numeric(6, 5) check (${x("epssScore")} is null or ${x("epssScore")} between 0 and 1),
|
|
15138
15162
|
${x("epssPercentile")} numeric(6, 5) check (${x("epssPercentile")} is null or ${x("epssPercentile")} between 0 and 1),
|
|
15139
15163
|
${x("epssDate")} date,
|
|
@@ -15162,8 +15186,8 @@ create table if not exists ${q.vex} (
|
|
|
15162
15186
|
-- Null: the statement covers every version of the product.
|
|
15163
15187
|
${s("version")} uuid,
|
|
15164
15188
|
${s("vulnerability")} uuid not null,
|
|
15165
|
-
${s("status")} text not null check (${s("status")} in (${quoted$
|
|
15166
|
-
${s("justification")} text check (${s("justification")} is null or ${s("justification")} in (${quoted$
|
|
15189
|
+
${s("status")} text not null check (${s("status")} in (${quoted$6(ADVISORY_VEX_STATUSES)})),
|
|
15190
|
+
${s("justification")} text check (${s("justification")} is null or ${s("justification")} in (${quoted$6(ADVISORY_VEX_JUSTIFICATIONS)})),
|
|
15167
15191
|
${s("impactStatement")} text check (${s("impactStatement")} is null or length(${s("impactStatement")}) <= 5000),
|
|
15168
15192
|
${s("actionStatement")} text check (${s("actionStatement")} is null or length(${s("actionStatement")}) <= 5000),
|
|
15169
15193
|
${s("createdBy")} uuid,
|
|
@@ -15181,8 +15205,8 @@ create table if not exists ${q.advisories} (
|
|
|
15181
15205
|
${a("title")} text not null check (length(${a("title")}) between 1 and 300),
|
|
15182
15206
|
${a("summary")} text check (${a("summary")} is null or length(${a("summary")}) <= 10000),
|
|
15183
15207
|
${a("product")} uuid not null,
|
|
15184
|
-
${a("severity")} text check (${a("severity")} is null or ${a("severity")} in (${quoted$
|
|
15185
|
-
${a("status")} text not null default 'draft' check (${a("status")} in (${quoted$
|
|
15208
|
+
${a("severity")} text check (${a("severity")} is null or ${a("severity")} in (${quoted$6(ADVISORY_SEVERITIES)})),
|
|
15209
|
+
${a("status")} text not null default 'draft' check (${a("status")} in (${quoted$6(ADVISORY_SQL_STATUSES)})),
|
|
15186
15210
|
-- The CSAF document version: 0 for a draft, then one more per publication.
|
|
15187
15211
|
${a("revision")} integer not null default 0 check (${a("revision")} >= 0),
|
|
15188
15212
|
${a("initialReleaseAt")} timestamptz,
|
|
@@ -19947,8 +19971,8 @@ const NAMES$145 = {
|
|
|
19947
19971
|
}
|
|
19948
19972
|
} }
|
|
19949
19973
|
};
|
|
19950
|
-
const COLUMN$
|
|
19951
|
-
const isColumn = (value) => typeof value === "string" && COLUMN$
|
|
19974
|
+
const COLUMN$12 = /^[a-z_][a-z0-9_]*$/;
|
|
19975
|
+
const isColumn = (value) => typeof value === "string" && COLUMN$12.test(value);
|
|
19952
19976
|
const isColumnList$1 = (value) => Array.isArray(value) && value.every(isColumn);
|
|
19953
19977
|
const isChildInput = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19954
19978
|
function childrenOf(value, where) {
|
|
@@ -21991,8 +22015,7 @@ ${userGrant(`${fn("has_subject_role")}(text, text, text[])`)}
|
|
|
21991
22015
|
}
|
|
21992
22016
|
/** The row `s` of `subject` is `id` and, with `deletedAt`, not deleted. */
|
|
21993
22017
|
function live$1(subject, id) {
|
|
21994
|
-
|
|
21995
|
-
return subject.config.deletedAt === void 0 ? match : `${match} and s.${sqlIdent$1(subject.config.deletedAt)} is null`;
|
|
22018
|
+
return `${registeredIdMatches(subject, id)}${subject.config.deletedAt === void 0 ? "" : ` and s.${sqlIdent$1(subject.config.deletedAt)} is null`}${excludeTemplates(subject.config, "s")}`;
|
|
21996
22019
|
}
|
|
21997
22020
|
/**
|
|
21998
22021
|
* The record team's policy and functions, after `can_subject`: the read policy
|
|
@@ -22458,7 +22481,7 @@ function readLoggedSubjects(ctx, subjects) {
|
|
|
22458
22481
|
function tenantLookup(audited, fnName) {
|
|
22459
22482
|
return ` case ${fnName}.subject_type
|
|
22460
22483
|
${audited.map((subject) => {
|
|
22461
|
-
const live = subject.config.deletedAt === void 0 ? "" : ` and s.${sqlIdent$1(subject.config.deletedAt)} is null`;
|
|
22484
|
+
const live = `${subject.config.deletedAt === void 0 ? "" : ` and s.${sqlIdent$1(subject.config.deletedAt)} is null`}${excludeTemplates(subject.config, "s")}`;
|
|
22462
22485
|
return ` when ${sqlString(subject.type)} then
|
|
22463
22486
|
select s.${subject.tenant} into v_tenant from ${subject.qualified} s
|
|
22464
22487
|
where ${registeredIdMatches(subject, `${fnName}.subject_id`)}${live};`;
|
|
@@ -22769,8 +22792,7 @@ function actionsOf(subject) {
|
|
|
22769
22792
|
}
|
|
22770
22793
|
/** The row `s` is `id` and, with `deletedAt`, not soft-deleted. */
|
|
22771
22794
|
function rowMatches(subject, id) {
|
|
22772
|
-
|
|
22773
|
-
return subject.config.deletedAt === void 0 ? match : `${match} and s.${sqlIdent$1(subject.config.deletedAt)} is null`;
|
|
22795
|
+
return `${registeredIdMatches(subject, id)}${subject.config.deletedAt === void 0 ? "" : ` and s.${sqlIdent$1(subject.config.deletedAt)} is null`}${excludeTemplates(subject.config, "s")}`;
|
|
22774
22796
|
}
|
|
22775
22797
|
function cases$1(subjects, former, branch) {
|
|
22776
22798
|
const registered = new Set(subjects.map((subject) => subject.type));
|
|
@@ -22789,7 +22811,7 @@ function titlesBranch(subject) {
|
|
|
22789
22811
|
const ids = `select r ->> 'id' from jsonb_array_elements(subject_titles.refs) r where r ->> 'type' = ${sqlString(subject.type)}`;
|
|
22790
22812
|
const idType = subject.config.idType;
|
|
22791
22813
|
const match = idType === void 0 ? `s.${subject.id}::text = any(array(${ids}))` : `s.${subject.id} = any(array(${ids})::${idType}[])`;
|
|
22792
|
-
const live = subject.config.deletedAt === void 0 ? "" : ` and s.${sqlIdent$1(subject.config.deletedAt)} is null`;
|
|
22814
|
+
const live = `${subject.config.deletedAt === void 0 ? "" : ` and s.${sqlIdent$1(subject.config.deletedAt)} is null`}${excludeTemplates(subject.config, "s")}`;
|
|
22793
22815
|
const title = subject.config.title === void 0 ? "null::text" : `s.${sqlIdent$1(subject.config.title)}::text`;
|
|
22794
22816
|
const url = subject.config.url === void 0 ? "null::text" : urlExpression(subject.config.url);
|
|
22795
22817
|
return ` found := found || coalesce((
|
|
@@ -29327,7 +29349,7 @@ const NAMES$139 = {
|
|
|
29327
29349
|
}
|
|
29328
29350
|
} }
|
|
29329
29351
|
};
|
|
29330
|
-
const COLUMN$
|
|
29352
|
+
const COLUMN$11 = /^[a-z_][a-z0-9_]*$/;
|
|
29331
29353
|
const FUNCTION$4 = /^[a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)?$/;
|
|
29332
29354
|
const RESTORING = "better_supabase.restoring_version";
|
|
29333
29355
|
function versioned(ctx) {
|
|
@@ -29359,7 +29381,7 @@ function versioned(ctx) {
|
|
|
29359
29381
|
};
|
|
29360
29382
|
});
|
|
29361
29383
|
}
|
|
29362
|
-
const isColumnList = (value) => Array.isArray(value) && value.every((column) => typeof column === "string" && COLUMN$
|
|
29384
|
+
const isColumnList = (value) => Array.isArray(value) && value.every((column) => typeof column === "string" && COLUMN$11.test(column));
|
|
29363
29385
|
const isFreezeValues = (value) => Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string" && item.length > 0 && !item.includes(","));
|
|
29364
29386
|
const isFreezeInput = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29365
29387
|
function freezeOf(value, where) {
|
|
@@ -29367,7 +29389,7 @@ function freezeOf(value, where) {
|
|
|
29367
29389
|
const expected = `${where} must be { column, values }`;
|
|
29368
29390
|
if (!isFreezeInput(value)) throw new TypeError(expected);
|
|
29369
29391
|
const { column, values } = value;
|
|
29370
|
-
if (typeof column !== "string" || !COLUMN$
|
|
29392
|
+
if (typeof column !== "string" || !COLUMN$11.test(column)) throw new TypeError(expected);
|
|
29371
29393
|
if (!isFreezeValues(values)) throw new TypeError(`${where}.values must be a list of values without commas`);
|
|
29372
29394
|
return {
|
|
29373
29395
|
column,
|
|
@@ -42111,7 +42133,7 @@ function rowPairs(ctx, snapshots, expr, context) {
|
|
|
42111
42133
|
}
|
|
42112
42134
|
// src/sql/modules/audit-subjects.ts
|
|
42113
42135
|
const HEADER = /^[a-z0-9-]+$/;
|
|
42114
|
-
const COLUMN$
|
|
42136
|
+
const COLUMN$10 = /^[a-z_][a-z0-9_]*$/;
|
|
42115
42137
|
const CLAIM$1 = /^[a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)*$/i;
|
|
42116
42138
|
const UUID$8 = "'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'";
|
|
42117
42139
|
/**
|
|
@@ -42183,7 +42205,7 @@ function subjectColumns$1(ctx, taken) {
|
|
|
42183
42205
|
if (raw === void 0) return [];
|
|
42184
42206
|
if (!isRecord$1(raw)) throw new TypeError(`${where} must map column names to { type, from }`);
|
|
42185
42207
|
return Object.entries(raw).map(([name, entry]) => {
|
|
42186
|
-
if (!COLUMN$
|
|
42208
|
+
if (!COLUMN$10.test(name) || name.length > 46) throw new TypeError(`${where}: "${name}" is not a valid column name`);
|
|
42187
42209
|
if (taken.includes(name)) throw new TypeError(`${where}: "${name}" is already a column of the audit log`);
|
|
42188
42210
|
const type = isRecord$1(entry) ? entry["type"] : void 0;
|
|
42189
42211
|
const from = isRecord$1(entry) ? entry["from"] ?? name : void 0;
|
|
@@ -47505,7 +47527,8 @@ function workItemFunctions(ctx, n) {
|
|
|
47505
47527
|
payload: `jsonb_build_object('organizationId', ${alias}.${w("tenant")}, 'workItemId', ${alias}.${w("id")}, 'subjectType', ${item}, 'subjectId', ${alias}.${w("id")}::text, 'title', ${alias}.${w("title")}${extra})`,
|
|
47506
47528
|
subject: `'work-items/' || ${alias}.${w("id")}::text`,
|
|
47507
47529
|
tenant: `${alias}.${w("tenant")}::text`,
|
|
47508
|
-
audit: false
|
|
47530
|
+
audit: false,
|
|
47531
|
+
...n.templates ? { live: `${alias}.${w("template")} is null` } : {}
|
|
47509
47532
|
});
|
|
47510
47533
|
const writes = [
|
|
47511
47534
|
...fields$2(ctx, w, e).map((field) => has(field.column) ? ` when ${sqlString(field.field)} then
|
|
@@ -47722,7 +47745,7 @@ begin
|
|
|
47722
47745
|
seq: w("number"),
|
|
47723
47746
|
tenant: w("tenant"),
|
|
47724
47747
|
prefix: n.prefix
|
|
47725
|
-
})}
|
|
47748
|
+
}, "now()", n.templates ? { when: "nullif(create_task.attrs ->> 'templateId', '') is null" } : {})}
|
|
47726
47749
|
begin
|
|
47727
47750
|
insert into ${t("items")} (${lines(" ", [
|
|
47728
47751
|
w("tenant"),
|
|
@@ -47744,7 +47767,7 @@ begin
|
|
|
47744
47767
|
w("pipeline"),
|
|
47745
47768
|
w("stage"),
|
|
47746
47769
|
column("createdBy")
|
|
47747
|
-
])}${extrasInsert.columns})
|
|
47770
|
+
])}${extrasInsert.columns}${n.templates ? `, ${w("template")}${ctx.has("items", "sourceTemplate") ? `, ${w("sourceTemplate")}` : ""}` : ""})
|
|
47748
47771
|
values (${lines(" ", [
|
|
47749
47772
|
"create_task.tenant",
|
|
47750
47773
|
"v_seq",
|
|
@@ -47763,7 +47786,7 @@ begin
|
|
|
47763
47786
|
"(create_task.attrs ->> 'pipelineId')::uuid",
|
|
47764
47787
|
"(create_task.attrs ->> 'stageId')::uuid",
|
|
47765
47788
|
present("items", "createdBy", "auth.uid()")
|
|
47766
|
-
])}${extrasInsert.values})
|
|
47789
|
+
])}${extrasInsert.values}${n.templates ? `, nullif(create_task.attrs ->> 'templateId', '')::uuid${ctx.has("items", "sourceTemplate") ? ", nullif(create_task.attrs ->> 'sourceTemplateId', '')::uuid" : ""}` : ""})
|
|
47767
47790
|
returning ${w("id")} into v_id;
|
|
47768
47791
|
exception when check_violation or invalid_text_representation or datetime_field_overflow or numeric_value_out_of_range or foreign_key_violation then
|
|
47769
47792
|
${fail("TASK_ATTRS_INVALID", "a work item field has an invalid value", "22023")}
|
|
@@ -48035,7 +48058,7 @@ as $$
|
|
|
48035
48058
|
from (
|
|
48036
48059
|
select ${row("x")} as value, x.${w("number")} as number
|
|
48037
48060
|
from ${t("items")} x
|
|
48038
|
-
where x.${w("tenant")} = list_tasks.tenant and x.${w("archivedAt")} is null
|
|
48061
|
+
where x.${w("tenant")} = list_tasks.tenant and x.${w("archivedAt")} is null${n.templates ? `\n and (case coalesce(list_tasks.filter ->> 'templates', 'exclude') when 'include' then true when 'only' then x.${w("template")} is not null else x.${w("template")} is null end)` : ""}
|
|
48039
48062
|
and (list_tasks.filter ->> 'teamId' is null or x.${w("team")} = (list_tasks.filter ->> 'teamId')::uuid)
|
|
48040
48063
|
and (list_tasks.filter ->> ${sqlString(e("projectId"))} is null or ${has("project") ? `x.${w("project")} = (list_tasks.filter ->> ${sqlString(e("projectId"))})::uuid` : "false"})
|
|
48041
48064
|
and (list_tasks.filter ->> ${sqlString(e("iterationId"))} is null or ${has("iteration") ? `x.${w("iteration")} = (list_tasks.filter ->> ${sqlString(e("iterationId"))})::uuid` : "false"})
|
|
@@ -48050,7 +48073,71 @@ as $$
|
|
|
48050
48073
|
) p
|
|
48051
48074
|
$$;
|
|
48052
48075
|
${userGrant(`${fn("list_tasks")}(${ctx.idType}, jsonb, text, uuid, integer)`)}
|
|
48053
|
-
${workItemExtraFunctions(ctx, n, row, record)}${projects}${iterations}`;
|
|
48076
|
+
${cloneTask(ctx, n, fn, t, w, a, row)}${workItemExtraFunctions(ctx, n, row, record)}${projects}${iterations}`;
|
|
48077
|
+
}
|
|
48078
|
+
/**
|
|
48079
|
+
* Copies a task and its assignees, checklist and child tasks. A template copy
|
|
48080
|
+
* is a live task (numbered, with events) unless overrides.templateId is set.
|
|
48081
|
+
*/
|
|
48082
|
+
function cloneTask(ctx, n, fn, t, w, a, row) {
|
|
48083
|
+
const template = n.templates ? `case when coalesce(clone_task.overrides, '{}'::jsonb) ? 'templateId' then clone_task.overrides ->> 'templateId' else null end` : "null";
|
|
48084
|
+
const source = n.templates ? `case when v_src.${w("template")} is not null then v_src.${w("template")}::text else v_src.${ctx.has("items", "sourceTemplate") ? w("sourceTemplate") : "id"}::text end` : "null";
|
|
48085
|
+
const tags = ctx.installed("tags") ? `
|
|
48086
|
+
insert into ${ctx.of("tags").table("taggings")} (${ctx.of("tags").col("taggings", "tenant")}, ${ctx.of("tags").col("taggings", "tag")}, ${ctx.of("tags").col("taggings", "subjectType")}, ${ctx.of("tags").col("taggings", "subjectId")})
|
|
48087
|
+
select g.${ctx.of("tags").col("taggings", "tenant")}, g.${ctx.of("tags").col("taggings", "tag")}, g.${ctx.of("tags").col("taggings", "subjectType")}, v_id::text
|
|
48088
|
+
from ${ctx.of("tags").table("taggings")} g
|
|
48089
|
+
where g.${ctx.of("tags").col("taggings", "subjectType")} = ${sqlString(n.type)} and g.${ctx.of("tags").col("taggings", "subjectId")} = clone_task.source::text;` : "";
|
|
48090
|
+
const checklist = ctx.hasTable("checklist") ? `
|
|
48091
|
+
insert into ${t("checklist")} (${ctx.col("checklist", "tenant")}, ${ctx.col("checklist", "item")}, ${ctx.col("checklist", "title")}, ${ctx.col("checklist", "done")}, ${ctx.col("checklist", "rank")})
|
|
48092
|
+
select c.${ctx.col("checklist", "tenant")}, v_id, c.${ctx.col("checklist", "title")}, false, c.${ctx.col("checklist", "rank")}
|
|
48093
|
+
from ${t("checklist")} c where c.${ctx.col("checklist", "item")} = clone_task.source;` : "";
|
|
48094
|
+
return `
|
|
48095
|
+
-- Copies source into a new task. overrides replaces the fields the caller
|
|
48096
|
+
-- edited. A template becomes a live task unless overrides.templateId is set.
|
|
48097
|
+
create or replace function ${fn("clone_task")}(source uuid, overrides jsonb default null)
|
|
48098
|
+
returns jsonb
|
|
48099
|
+
language plpgsql
|
|
48100
|
+
security definer
|
|
48101
|
+
set search_path = ''
|
|
48102
|
+
as $$
|
|
48103
|
+
declare
|
|
48104
|
+
v_src ${t("items")}%rowtype;
|
|
48105
|
+
v_id uuid;
|
|
48106
|
+
v_created jsonb;
|
|
48107
|
+
v_child uuid;
|
|
48108
|
+
v_copy jsonb;
|
|
48109
|
+
v_users uuid[];
|
|
48110
|
+
begin
|
|
48111
|
+
select * into v_src from ${t("items")} x where x.${w("id")} = clone_task.source;
|
|
48112
|
+
if not found then
|
|
48113
|
+
${fail("TASK_NOT_FOUND", "no such work item", "P0002")}
|
|
48114
|
+
end if;
|
|
48115
|
+
if not (${n.service} or ${ctx.scope.can(`v_src.${w("tenant")}`, n.create)}) then
|
|
48116
|
+
${fail("TASK_FORBIDDEN", "not allowed to change work items")}
|
|
48117
|
+
end if;
|
|
48118
|
+
${ctx.hook("before_task_clone", [["uuid", "clone_task.source"], ["jsonb", "clone_task.overrides"]])}
|
|
48119
|
+
select coalesce(array_agg(ra.${a("user")}), '{}') into v_users from ${t("assignees")} ra where ra.${a("item")} = v_src.${w("id")};
|
|
48120
|
+
v_created := ${fn("create_task")}(v_src.${w("tenant")}, jsonb_strip_nulls(jsonb_build_object(
|
|
48121
|
+
'title', v_src.${w("title")},
|
|
48122
|
+
'body', ${ctx.has("items", "body") ? `v_src.${w("body")}` : "null"},
|
|
48123
|
+
'parentId', v_src.${w("parent")},
|
|
48124
|
+
'teamId', v_src.${w("team")},
|
|
48125
|
+
'dueAt', v_src.${w("dueAt")},
|
|
48126
|
+
'priority', v_src.${w("priority")},
|
|
48127
|
+
'templateId', ${template},
|
|
48128
|
+
'sourceTemplateId', ${source}
|
|
48129
|
+
)) || (coalesce(clone_task.overrides, '{}'::jsonb) - 'templateId') || jsonb_strip_nulls(jsonb_build_object('templateId', ${template}, 'sourceTemplateId', ${source})), v_users);
|
|
48130
|
+
v_id := (v_created ->> 'id')::uuid;${checklist}${tags}
|
|
48131
|
+
for v_child in select c.${w("id")} from ${t("items")} c where c.${w("parent")} = clone_task.source loop
|
|
48132
|
+
v_copy := ${fn("clone_task")}(v_child, coalesce(clone_task.overrides, '{}'::jsonb) - 'templateId' - 'parentId');
|
|
48133
|
+
update ${t("items")} x set ${w("parent")} = v_id where x.${w("id")} = (v_copy ->> 'id')::uuid;
|
|
48134
|
+
end loop;
|
|
48135
|
+
${ctx.hook("after_task_clone", [["uuid", "v_id"]])}
|
|
48136
|
+
return (select ${row("x")} from ${t("items")} x where x.${w("id")} = v_id);
|
|
48137
|
+
end;
|
|
48138
|
+
$$;
|
|
48139
|
+
${userGrant(`${fn("clone_task")}(uuid, jsonb)`)}
|
|
48140
|
+
`;
|
|
48054
48141
|
}
|
|
48055
48142
|
// src/sql/modules/tasks.ts
|
|
48056
48143
|
/** The subject type of a project, after `blocks.tasks.entities`. */
|
|
@@ -48156,7 +48243,8 @@ const NAMES$124 = {
|
|
|
48156
48243
|
body: ["identifier", "body"]
|
|
48157
48244
|
},
|
|
48158
48245
|
realtime: true,
|
|
48159
|
-
history: ["title", "body"]
|
|
48246
|
+
history: ["title", "body"],
|
|
48247
|
+
template: "template"
|
|
48160
48248
|
}
|
|
48161
48249
|
},
|
|
48162
48250
|
project: {
|
|
@@ -48176,7 +48264,9 @@ const NAMES$124 = {
|
|
|
48176
48264
|
"before_task_create",
|
|
48177
48265
|
"after_task_create",
|
|
48178
48266
|
"before_task_update",
|
|
48179
|
-
"after_task_update"
|
|
48267
|
+
"after_task_update",
|
|
48268
|
+
"before_task_clone",
|
|
48269
|
+
"after_task_clone"
|
|
48180
48270
|
],
|
|
48181
48271
|
options: [
|
|
48182
48272
|
"prefix",
|
|
@@ -48185,7 +48275,8 @@ const NAMES$124 = {
|
|
|
48185
48275
|
"authorCanDelete",
|
|
48186
48276
|
"notify",
|
|
48187
48277
|
"actionPath",
|
|
48188
|
-
"searchColumn"
|
|
48278
|
+
"searchColumn",
|
|
48279
|
+
"templates"
|
|
48189
48280
|
],
|
|
48190
48281
|
tables: {
|
|
48191
48282
|
items: {
|
|
@@ -48222,6 +48313,8 @@ const NAMES$124 = {
|
|
|
48222
48313
|
locked: "locked",
|
|
48223
48314
|
rank: "rank",
|
|
48224
48315
|
archivedAt: "archived_at",
|
|
48316
|
+
template: "template_id",
|
|
48317
|
+
sourceTemplate: "source_template_id",
|
|
48225
48318
|
recursFrom: "recurs_from",
|
|
48226
48319
|
createdBy: "created_by",
|
|
48227
48320
|
createdAt: "created_at",
|
|
@@ -48236,7 +48329,9 @@ const NAMES$124 = {
|
|
|
48236
48329
|
"startAt",
|
|
48237
48330
|
"endAt",
|
|
48238
48331
|
"recursFrom",
|
|
48239
|
-
"createdBy"
|
|
48332
|
+
"createdBy",
|
|
48333
|
+
"template",
|
|
48334
|
+
"sourceTemplate"
|
|
48240
48335
|
],
|
|
48241
48336
|
typed: ["state", "closeReason"],
|
|
48242
48337
|
mappable: ["priority"]
|
|
@@ -48339,6 +48434,31 @@ const NAMES$124 = {
|
|
|
48339
48434
|
}
|
|
48340
48435
|
}
|
|
48341
48436
|
};
|
|
48437
|
+
/** Template rows are on: the option, the column, and the templates block. */
|
|
48438
|
+
function templatesOn(ctx) {
|
|
48439
|
+
if (!ctx.flag("templates", false)) return false;
|
|
48440
|
+
if (!ctx.installed("templates")) throw new TypeError("blocks.tasks.options.templates needs the templates block");
|
|
48441
|
+
return ctx.has("items", "template");
|
|
48442
|
+
}
|
|
48443
|
+
function templateColumns(ctx) {
|
|
48444
|
+
if (!templatesOn(ctx)) return "";
|
|
48445
|
+
const templates = ctx.of("templates").table("templates");
|
|
48446
|
+
return `
|
|
48447
|
+
${templateColumnSql(ctx.colName("items", "template"), templates, true)},
|
|
48448
|
+
${ctx.has("items", "sourceTemplate") ? `${sourceTemplateColumnSql(ctx.colName("items", "sourceTemplate"), templates)},` : ""}`;
|
|
48449
|
+
}
|
|
48450
|
+
function templateGuard(ctx, t) {
|
|
48451
|
+
if (!templatesOn(ctx)) return "";
|
|
48452
|
+
return `
|
|
48453
|
+
${templateGuardSql({
|
|
48454
|
+
fn: ctx.fn("task_template_guard"),
|
|
48455
|
+
trigger: ctx.trigger("task_template"),
|
|
48456
|
+
table: t("items"),
|
|
48457
|
+
column: ctx.colName("items", "template"),
|
|
48458
|
+
hint: "TASK_TEMPLATE_IMMUTABLE"
|
|
48459
|
+
})}
|
|
48460
|
+
${triggerGrant(`${ctx.fn("task_template_guard")}()`)}`;
|
|
48461
|
+
}
|
|
48342
48462
|
function tables$55(ctx, n) {
|
|
48343
48463
|
if (!ctx.manages) return "";
|
|
48344
48464
|
const { t, c } = n;
|
|
@@ -48392,9 +48512,9 @@ ${read("iterations")}
|
|
|
48392
48512
|
` : ""}
|
|
48393
48513
|
create table if not exists ${t("items")} (
|
|
48394
48514
|
${w("id")} uuid primary key default gen_random_uuid(),
|
|
48395
|
-
${w("tenant")} ${ctx.idType} not null
|
|
48396
|
-
${w("number")} bigint not null,
|
|
48397
|
-
${w("identifier")} text not null,
|
|
48515
|
+
${w("tenant")} ${ctx.idType} not null,${templateColumns(ctx)}
|
|
48516
|
+
${w("number")} bigint${templatesOn(ctx) ? "" : " not null"},
|
|
48517
|
+
${w("identifier")} text${templatesOn(ctx) ? "" : " not null"},
|
|
48398
48518
|
${w("title")} text not null check (length(${w("title")}) between 1 and 500),${column("items", "body", (name) => `${name} text`)}
|
|
48399
48519
|
${w("parent")} uuid references ${t("items")} (${w("id")}) on delete cascade,
|
|
48400
48520
|
${w("team")} uuid,${column("items", "project", (name) => `${name} uuid${ctx.hasTable("projects") ? ` references ${t("projects")} (${p("id")}) on delete set null` : ""}`)}${column("items", "iteration", (name) => `${name} uuid${ctx.hasTable("iterations") ? ` references ${t("iterations")} (${i("id")}) on delete set null` : ""}`)}
|
|
@@ -48415,7 +48535,7 @@ create table if not exists ${t("items")} (
|
|
|
48415
48535
|
);${appUniqueIndex(ctx, "items", ["tenant", "number"])}
|
|
48416
48536
|
create index if not exists ${sqlIdent$1(`${ctx.tableName("items").name}_board_idx`)} on ${t("items")} (${w("pipeline")}, ${w("stage")}, ${w("rank")});
|
|
48417
48537
|
create index if not exists ${sqlIdent$1(`${ctx.tableName("items").name}_parent_idx`)} on ${t("items")} (${w("parent")});${ctx.has("items", "project") ? `\ncreate index if not exists ${sqlIdent$1(`${ctx.tableName("items").name}_${ctx.naming.rename("project_idx")}`)} on ${t("items")} (${w("project")});` : ""}${ctx.has("items", "iteration") ? `\ncreate index if not exists ${sqlIdent$1(`${ctx.tableName("items").name}_${ctx.naming.rename("iteration_idx")}`)} on ${t("items")} (${w("iteration")});` : ""}
|
|
48418
|
-
create index if not exists ${sqlIdent$1(`${ctx.tableName("items").name}_due_idx`)} on ${t("items")} (${w("tenant")}, ${w("dueAt")}) where ${w("closedAt")} is null;${addExtraColumns(t("items"), ctx.extraColumns("items", ["fields"]))}${searchColumnSql(ctx, "items", [
|
|
48538
|
+
create index if not exists ${sqlIdent$1(`${ctx.tableName("items").name}_due_idx`)} on ${t("items")} (${w("tenant")}, ${w("dueAt")}) where ${w("closedAt")} is null;${templatesOn(ctx) ? `\n${liveRowsIndex(`${ctx.tableName("items").name}_live_idx`, t("items"), `${w("tenant")}, ${w("number")} desc`, ctx.colName("items", "template"))}` : ""}${templateGuard(ctx, t)}${addExtraColumns(t("items"), ctx.extraColumns("items", ["fields"]))}${searchColumnSql(ctx, "items", [
|
|
48419
48539
|
"identifier",
|
|
48420
48540
|
"title",
|
|
48421
48541
|
"body"
|
|
@@ -48500,7 +48620,8 @@ ${ctx.has("items", "progress") ? ` if ${state(`new.${w("state")}`, ["comple
|
|
|
48500
48620
|
payload: payload(`, 'state', new.${w("state")}, 'closeReason', new.${w("closeReason")}`),
|
|
48501
48621
|
subject,
|
|
48502
48622
|
tenant,
|
|
48503
|
-
audit: false
|
|
48623
|
+
audit: false,
|
|
48624
|
+
...templatesOn(ctx) ? { live: `new.${w("template")} is null` } : {}
|
|
48504
48625
|
})}
|
|
48505
48626
|
elsif not (${closed}) and ${state(`old.${w("state")}`, ["completed", "canceled"])} then
|
|
48506
48627
|
new.${w("closedAt")} := null;
|
|
@@ -48510,7 +48631,8 @@ ${ctx.has("items", "progress") ? ` if ${state(`new.${w("state")}`, ["comple
|
|
|
48510
48631
|
payload: payload(""),
|
|
48511
48632
|
subject,
|
|
48512
48633
|
tenant,
|
|
48513
|
-
audit: false
|
|
48634
|
+
audit: false,
|
|
48635
|
+
...templatesOn(ctx) ? { live: `new.${w("template")} is null` } : {}
|
|
48514
48636
|
})}
|
|
48515
48637
|
end if;
|
|
48516
48638
|
end if;
|
|
@@ -48546,7 +48668,8 @@ function build$128(ctx) {
|
|
|
48546
48668
|
service: "(auth.role() = 'service_role')",
|
|
48547
48669
|
extras: ctx.extraColumns("items", ["fields"]),
|
|
48548
48670
|
e: (name) => ctx.resolved.entityNaming.rename(name),
|
|
48549
|
-
type: taskType(ctx)
|
|
48671
|
+
type: taskType(ctx),
|
|
48672
|
+
templates: templatesOn(ctx)
|
|
48550
48673
|
};
|
|
48551
48674
|
return `${schemaPreamble(ctx)}
|
|
48552
48675
|
-- Work items on pipelines: issues and tasks with an identifier, a parent,
|
|
@@ -48564,6 +48687,11 @@ function contract$115(ctx) {
|
|
|
48564
48687
|
],
|
|
48565
48688
|
returns: "jsonb"
|
|
48566
48689
|
},
|
|
48690
|
+
{
|
|
48691
|
+
name: "clone_task",
|
|
48692
|
+
args: ["uuid", "jsonb"],
|
|
48693
|
+
returns: "jsonb"
|
|
48694
|
+
},
|
|
48567
48695
|
{
|
|
48568
48696
|
name: "update_tasks",
|
|
48569
48697
|
args: ["jsonb", "boolean"],
|
|
@@ -48741,6 +48869,26 @@ const WORK_ITEMS = {
|
|
|
48741
48869
|
items: PRIORITY_ITEMS
|
|
48742
48870
|
} }
|
|
48743
48871
|
}],
|
|
48872
|
+
templates: (own) => {
|
|
48873
|
+
if (!own.flag("templates", false) || !own.has("items", "template")) return [];
|
|
48874
|
+
const { schema, name } = own.tableName("items");
|
|
48875
|
+
return [{
|
|
48876
|
+
type: taskType(own),
|
|
48877
|
+
storage: "rows",
|
|
48878
|
+
subject: taskType(own),
|
|
48879
|
+
clone: own.fn("clone_task"),
|
|
48880
|
+
table: `${schema}.${name}`,
|
|
48881
|
+
templateColumn: own.colName("items", "template"),
|
|
48882
|
+
idColumn: own.colName("items", "id"),
|
|
48883
|
+
children: [{
|
|
48884
|
+
table: `${schema}.${own.tableName("assignees").name}`,
|
|
48885
|
+
parent: own.colName("assignees", "item")
|
|
48886
|
+
}, ...own.hasTable("checklist") ? [{
|
|
48887
|
+
table: `${schema}.${own.tableName("checklist").name}`,
|
|
48888
|
+
parent: own.colName("checklist", "item")
|
|
48889
|
+
}] : []]
|
|
48890
|
+
}];
|
|
48891
|
+
},
|
|
48744
48892
|
pipelines: (own) => {
|
|
48745
48893
|
const { schema, name } = own.tableName("items");
|
|
48746
48894
|
return [{
|
|
@@ -48759,7 +48907,7 @@ const WORK_ITEMS = {
|
|
|
48759
48907
|
where a.${own.col("assignees", "user")} = v_me
|
|
48760
48908
|
and ${own.is("items", "state", w("state"), ["completed", "canceled"], true)}
|
|
48761
48909
|
and ${w("archivedAt")} is null
|
|
48762
|
-
and ${myWorkTenant(w("tenant"))}` }];
|
|
48910
|
+
and ${myWorkTenant(w("tenant"))}${own.flag("templates", false) && own.has("items", "template") ? `\n and ${w("template")} is null` : ""}` }];
|
|
48763
48911
|
}
|
|
48764
48912
|
},
|
|
48765
48913
|
name: "tasks",
|
|
@@ -48779,7 +48927,10 @@ const WORK_ITEMS = {
|
|
|
48779
48927
|
"numbering",
|
|
48780
48928
|
"attachments",
|
|
48781
48929
|
"reminders",
|
|
48782
|
-
"accounting"
|
|
48930
|
+
"accounting",
|
|
48931
|
+
"option-sets",
|
|
48932
|
+
"templates",
|
|
48933
|
+
"tags"
|
|
48783
48934
|
],
|
|
48784
48935
|
target: "schema",
|
|
48785
48936
|
modes: ["managed", "custom"],
|
|
@@ -53353,7 +53504,7 @@ function appFunction(ctx, value, key) {
|
|
|
53353
53504
|
const fn = value.split(".").map(sqlIdent$1).join(".");
|
|
53354
53505
|
return (calendar, user) => `${fn}(${calendar}, ${user})`;
|
|
53355
53506
|
}
|
|
53356
|
-
const COLUMN$
|
|
53507
|
+
const COLUMN$9 = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
53357
53508
|
function ruleDialect(ctx) {
|
|
53358
53509
|
const raw = ctx.option("ruleDialect");
|
|
53359
53510
|
const at = "blocks.calendar.options.ruleDialect";
|
|
@@ -53368,7 +53519,7 @@ function ruleDialect(ctx) {
|
|
|
53368
53519
|
lower: weekdays === "lower",
|
|
53369
53520
|
scalarMonthDay: monthDay === "scalar"
|
|
53370
53521
|
};
|
|
53371
|
-
if (!isRecord$1(ordinal) || typeof ordinal["weekday"] !== "string" || typeof ordinal["position"] !== "string" || !COLUMN$
|
|
53522
|
+
if (!isRecord$1(ordinal) || typeof ordinal["weekday"] !== "string" || typeof ordinal["position"] !== "string" || !COLUMN$9.test(ordinal["weekday"]) || !COLUMN$9.test(ordinal["position"])) throw new TypeError(`${at}.ordinal takes { weekday, position }, two column names of the rules table`);
|
|
53372
53523
|
return {
|
|
53373
53524
|
lower: weekdays === "lower",
|
|
53374
53525
|
scalarMonthDay: monthDay === "scalar",
|
|
@@ -59063,7 +59214,7 @@ ${userGrant(`${fn("drive_set_download_blocked")}(text, uuid, boolean)`)}
|
|
|
59063
59214
|
`}`;
|
|
59064
59215
|
}
|
|
59065
59216
|
// src/sql/modules/drive-documents.ts
|
|
59066
|
-
const TYPE$
|
|
59217
|
+
const TYPE$5 = /^[a-z][a-z0-9_-]{0,62}$/u;
|
|
59067
59218
|
const DEFAULT_REVIEW_MONTHS = 12;
|
|
59068
59219
|
/** The blocks `options.control` builds on. */
|
|
59069
59220
|
const NEEDS = [
|
|
@@ -59086,7 +59237,7 @@ function driveControl(ctx, files) {
|
|
|
59086
59237
|
if (!isRecord$1(raw)) throw new TypeError(`${where} must be { types, reviewMonths, releaseRole }`);
|
|
59087
59238
|
const entries = raw["types"];
|
|
59088
59239
|
const typeNames = Array.isArray(entries) ? entries.map((entry) => isRecord$1(entry) ? entry["name"] : entry) : [];
|
|
59089
|
-
if (!Array.isArray(entries) || entries.length === 0 || !typeNames.every((type) => typeof type === "string" && TYPE$
|
|
59240
|
+
if (!Array.isArray(entries) || entries.length === 0 || !typeNames.every((type) => typeof type === "string" && TYPE$5.test(type)) || new Set(typeNames).size !== typeNames.length) throw new TypeError(`${where}.types must list distinct document types in lowercase, such as sop, or { name, numberFormat }`);
|
|
59090
59241
|
const types = typeNames.map(String);
|
|
59091
59242
|
const numberFormats = {};
|
|
59092
59243
|
for (const entry of entries) {
|
|
@@ -68452,7 +68603,7 @@ const NAMES$115 = {
|
|
|
68452
68603
|
}
|
|
68453
68604
|
}
|
|
68454
68605
|
};
|
|
68455
|
-
const quoted$
|
|
68606
|
+
const quoted$5 = (values) => values.map((value) => `'${value}'`).join(", ");
|
|
68456
68607
|
function tables$49(ctx) {
|
|
68457
68608
|
const sql = decisionSupportSql(ctx);
|
|
68458
68609
|
const { r, a } = sql;
|
|
@@ -68476,12 +68627,12 @@ function tables$49(ctx) {
|
|
|
68476
68627
|
create table if not exists ${sql.rules} (
|
|
68477
68628
|
${r("id")} uuid primary key default gen_random_uuid(),
|
|
68478
68629
|
${r("tenant")} ${ctx.idType} not null,
|
|
68479
|
-
${r("kind")} text not null check (${r("kind")} in (${quoted$
|
|
68630
|
+
${r("kind")} text not null check (${r("kind")} in (${quoted$5(CARE_RULE_KINDS)})),
|
|
68480
68631
|
${r("medicationIds")} uuid[] not null default '{}',
|
|
68481
68632
|
${r("minDose")} numeric check (${r("minDose")} is null or ${r("minDose")} >= 0),
|
|
68482
68633
|
${r("maxDose")} numeric check (${r("maxDose")} is null or ${r("maxDose")} > 0),
|
|
68483
68634
|
${r("maxPerDay")} numeric check (${r("maxPerDay")} is null or ${r("maxPerDay")} > 0),
|
|
68484
|
-
${r("severity")} text not null default 'warning' check (${r("severity")} in (${quoted$
|
|
68635
|
+
${r("severity")} text not null default 'warning' check (${r("severity")} in (${quoted$5(CARE_ALERT_SEVERITIES)})),
|
|
68485
68636
|
${r("message")} text check (${r("message")} is null or length(${r("message")}) <= 1000),
|
|
68486
68637
|
${r("active")} boolean not null default true,
|
|
68487
68638
|
${r("createdAt")} timestamptz not null default now(),
|
|
@@ -68505,15 +68656,15 @@ create table if not exists ${sql.alerts} (
|
|
|
68505
68656
|
${a("tenant")} ${ctx.idType} not null,
|
|
68506
68657
|
${a("subjectType")} text not null,
|
|
68507
68658
|
${a("subjectId")} text not null,
|
|
68508
|
-
${a("kind")} text not null check (${a("kind")} in (${quoted$
|
|
68509
|
-
${a("severity")} text not null check (${a("severity")} in (${quoted$
|
|
68659
|
+
${a("kind")} text not null check (${a("kind")} in (${quoted$5(CARE_ALERT_KINDS)})),
|
|
68660
|
+
${a("severity")} text not null check (${a("severity")} in (${quoted$5(CARE_ALERT_SEVERITIES)})),
|
|
68510
68661
|
${a("source")} text not null check (length(${a("source")}) between 1 and 100),
|
|
68511
68662
|
${a("rule")} uuid,
|
|
68512
68663
|
${a("orderIds")} uuid[] not null default '{}',
|
|
68513
68664
|
${a("message")} text not null check (length(${a("message")}) between 1 and 1000),
|
|
68514
68665
|
${a("details")} jsonb,
|
|
68515
68666
|
${a("fingerprint")} text not null check (length(${a("fingerprint")}) between 1 and 200),
|
|
68516
|
-
${a("status")} text not null default 'open' check (${a("status")} in (${quoted$
|
|
68667
|
+
${a("status")} text not null default 'open' check (${a("status")} in (${quoted$5(CARE_ALERT_STATUSES)})),
|
|
68517
68668
|
${a("decidedBy")} uuid,
|
|
68518
68669
|
${a("decidedAt")} timestamptz,
|
|
68519
68670
|
${a("decisionReason")} text check (${a("decisionReason")} is null or length(${a("decisionReason")}) <= 1000),
|
|
@@ -75998,7 +76149,7 @@ const NAMES$109 = {
|
|
|
75998
76149
|
}
|
|
75999
76150
|
}
|
|
76000
76151
|
};
|
|
76001
|
-
const quoted$
|
|
76152
|
+
const quoted$4 = (values) => values.map((value) => `'${value}'`).join(", ");
|
|
76002
76153
|
function tables$46(ctx) {
|
|
76003
76154
|
const q = consentsSql(ctx);
|
|
76004
76155
|
const { p, c, has, purposes, consents } = q;
|
|
@@ -76011,7 +76162,7 @@ function tables$46(ctx) {
|
|
|
76011
76162
|
${p("tenant")} ${ctx.idType},
|
|
76012
76163
|
${p("key")} text not null check (${p("key")} ~ '^[a-z][a-z0-9_.-]{0,62}$'),
|
|
76013
76164
|
${p("title")} text not null check (length(${p("title")}) between 1 and 200),
|
|
76014
|
-
${optional("purposes", "description", (x) => `${x} text check (${x} is null or length(${x}) <= 4000)`)} ${p("legalBasis")} text not null default 'consent' check (${p("legalBasis")} in (${quoted$
|
|
76165
|
+
${optional("purposes", "description", (x) => `${x} text check (${x} is null or length(${x}) <= 4000)`)} ${p("legalBasis")} text not null default 'consent' check (${p("legalBasis")} in (${quoted$4(LEGAL_BASES)})),
|
|
76015
76166
|
${p("version")} text not null default '1' check (length(${p("version")}) between 1 and 40),
|
|
76016
76167
|
${p("requiresSignature")} boolean not null default false,
|
|
76017
76168
|
${p("validMonths")} integer check (${p("validMonths")} is null or ${p("validMonths")} between 1 and 1200),
|
|
@@ -76036,11 +76187,11 @@ create table if not exists ${consents} (
|
|
|
76036
76187
|
${c("purpose")} uuid not null references ${purposes} (${p("id")}) on delete restrict,
|
|
76037
76188
|
${c("subjectType")} text not null,
|
|
76038
76189
|
${c("subjectId")} text not null,
|
|
76039
|
-
${c("givenBy")} text not null default 'self' check (${c("givenBy")} in (${quoted$
|
|
76190
|
+
${c("givenBy")} text not null default 'self' check (${c("givenBy")} in (${quoted$4(GIVEN_BY)})),
|
|
76040
76191
|
-- The contact person who decided for the record, when a representative did.
|
|
76041
76192
|
${c("givenByContact")} uuid,
|
|
76042
76193
|
${c("givenByUser")} uuid,
|
|
76043
|
-
${c("status")} text not null check (${c("status")} in (${quoted$
|
|
76194
|
+
${c("status")} text not null check (${c("status")} in (${quoted$4(CONSENT_STATUSES)})),
|
|
76044
76195
|
${optional("consents", "scope", (x) => `${x} jsonb not null default '{}'::jsonb check (jsonb_typeof(${x}) = 'object')`)} -- When the decision was made, for a refusal too.
|
|
76045
76196
|
${c("grantedAt")} timestamptz not null default now(),
|
|
76046
76197
|
${c("validUntil")} timestamptz,
|
|
@@ -78420,7 +78571,7 @@ const PARTIES = {
|
|
|
78420
78571
|
};
|
|
78421
78572
|
// src/sql/modules/content-sql.ts
|
|
78422
78573
|
const WHERE$18 = "blocks.content.options";
|
|
78423
|
-
const TYPE$
|
|
78574
|
+
const TYPE$4 = /^[a-z][a-z0-9_-]{0,62}$/;
|
|
78424
78575
|
const LOCALE = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
78425
78576
|
/** The statuses an entry moves through. */
|
|
78426
78577
|
const CONTENT_STATUSES = [
|
|
@@ -78441,7 +78592,7 @@ function keysOf$1(ctx, name, fallback, pattern, what) {
|
|
|
78441
78592
|
return values;
|
|
78442
78593
|
}
|
|
78443
78594
|
/** `options.types`: the entry types, such as `page` and `post`. */
|
|
78444
|
-
const contentTypes = (ctx) => keysOf$1(ctx, "types", ["page", "post"], TYPE$
|
|
78595
|
+
const contentTypes = (ctx) => keysOf$1(ctx, "types", ["page", "post"], TYPE$4, "type");
|
|
78445
78596
|
/** `options.locales`; the first is the default. */
|
|
78446
78597
|
const contentLocales = (ctx) => keysOf$1(ctx, "locales", ["en"], LOCALE, "locale");
|
|
78447
78598
|
/** Whether publishing goes through approvals; throws when it can't. */
|
|
@@ -84381,7 +84532,7 @@ function valueSql(at, value) {
|
|
|
84381
84532
|
if (isRecord$1(value) && typeof value["sql"] === "string") return `(${value["sql"].replaceAll("{row}", "r")})`;
|
|
84382
84533
|
throw new TypeError(`${at} must be a string, number, boolean, null or { sql: "<expression>" }`);
|
|
84383
84534
|
}
|
|
84384
|
-
function rulesOf(ctx) {
|
|
84535
|
+
function rulesOf$1(ctx) {
|
|
84385
84536
|
const where = "blocks.data-lifecycle.options.anonymize";
|
|
84386
84537
|
const value = ctx.option("anonymize");
|
|
84387
84538
|
if (value === void 0) return [];
|
|
@@ -84416,7 +84567,7 @@ function rulesOf(ctx) {
|
|
|
84416
84567
|
*/
|
|
84417
84568
|
function anonymizeSql(ctx) {
|
|
84418
84569
|
const fn = ctx.fn("anonymize_due");
|
|
84419
|
-
const rules = rulesOf(ctx);
|
|
84570
|
+
const rules = rulesOf$1(ctx);
|
|
84420
84571
|
const blocks = rules.map((rule) => `
|
|
84421
84572
|
with due as (
|
|
84422
84573
|
select r.ctid from ${rule.table} r
|
|
@@ -87281,7 +87432,7 @@ const NAMES$100 = {
|
|
|
87281
87432
|
}
|
|
87282
87433
|
}
|
|
87283
87434
|
};
|
|
87284
|
-
const quoted$
|
|
87435
|
+
const quoted$3 = (values) => values.map((value) => `'${value}'`).join(", ");
|
|
87285
87436
|
function build$102(ctx) {
|
|
87286
87437
|
if (ctx.mode === "custom") return "";
|
|
87287
87438
|
const idType = ctx.idType;
|
|
@@ -87373,7 +87524,7 @@ create table if not exists ${versions} (
|
|
|
87373
87524
|
${v("id")} uuid primary key default gen_random_uuid(),
|
|
87374
87525
|
${v("ruleSet")} uuid not null references ${sets} (${s("id")}) on delete cascade,
|
|
87375
87526
|
${v("version")} integer not null check (${v("version")} >= 1),
|
|
87376
|
-
${v("status")} text not null default 'draft' check (${v("status")} in (${quoted$
|
|
87527
|
+
${v("status")} text not null default 'draft' check (${v("status")} in (${quoted$3(RULE_VERSION_STATUSES)})),
|
|
87377
87528
|
${v("rules")} jsonb not null,
|
|
87378
87529
|
${v("contentHash")} text,
|
|
87379
87530
|
${v("effectiveFrom")} date,
|
|
@@ -87420,11 +87571,11 @@ create table if not exists ${deadlines} (
|
|
|
87420
87571
|
${d("ruleKey")} text not null,
|
|
87421
87572
|
${d("ruleVersion")} uuid not null references ${versions} (${v("id")}) on delete restrict,
|
|
87422
87573
|
${d("facts")} jsonb not null default '{}'::jsonb,
|
|
87423
|
-
${d("result")} text not null check (${d("result")} in (${quoted$
|
|
87574
|
+
${d("result")} text not null check (${d("result")} in (${quoted$3(DEADLINE_RESULTS)})),
|
|
87424
87575
|
${d("dueOn")} date,
|
|
87425
87576
|
${d("missing")} text[] not null default '{}',
|
|
87426
87577
|
${d("citation")} jsonb not null,
|
|
87427
|
-
${d("state")} text not null default 'pending' check (${d("state")} in (${quoted$
|
|
87578
|
+
${d("state")} text not null default 'pending' check (${d("state")} in (${quoted$3(DEADLINE_STATES)})),
|
|
87428
87579
|
${d("satisfiedAt")} timestamptz,
|
|
87429
87580
|
${d("satisfiedBy")} uuid,
|
|
87430
87581
|
${d("satisfiedAction")} text check (${d("satisfiedAction")} is null or length(${d("satisfiedAction")}) <= 200),
|
|
@@ -96202,7 +96353,7 @@ begin
|
|
|
96202
96353
|
end if;
|
|
96203
96354
|
return new;
|
|
96204
96355
|
end if;
|
|
96205
|
-
if not (${item
|
|
96356
|
+
if not (${assignWhen(ctx, item)}) then
|
|
96206
96357
|
return new;
|
|
96207
96358
|
end if;
|
|
96208
96359
|
v_n := ${ctx.fn("next_number")}(new.${sqlIdent$1(item.tenantColumn)}, ${sqlString(item.name)}, v_at, ${scope});
|
|
@@ -101282,7 +101433,7 @@ const NAMES$93 = {
|
|
|
101282
101433
|
}
|
|
101283
101434
|
} }
|
|
101284
101435
|
};
|
|
101285
|
-
const quoted$
|
|
101436
|
+
const quoted$2 = (values) => values.map((value) => `'${value}'`).join(", ");
|
|
101286
101437
|
function tables$38(ctx) {
|
|
101287
101438
|
const sql = prescribingSql(ctx);
|
|
101288
101439
|
const { p } = sql;
|
|
@@ -101313,7 +101464,7 @@ create table if not exists ${sql.prescriptions} (
|
|
|
101313
101464
|
${p("subjectId")} text not null,
|
|
101314
101465
|
${p("prescriber")} uuid not null,
|
|
101315
101466
|
${p("prescriberName")} text check (${p("prescriberName")} is null or length(${p("prescriberName")}) <= 300),
|
|
101316
|
-
${p("status")} text not null default 'draft' check (${p("status")} in (${quoted$
|
|
101467
|
+
${p("status")} text not null default 'draft' check (${p("status")} in (${quoted$2(PRESCRIPTION_STATUSES)})),
|
|
101317
101468
|
${p("snapshot")} jsonb,
|
|
101318
101469
|
${p("signedBy")} uuid,
|
|
101319
101470
|
${p("signedAt")} timestamptz,
|
|
@@ -103735,7 +103886,7 @@ ${userGrant(`${fn("open_enrollment_steps")}(${idType}, text, uuid, timestamptz,
|
|
|
103735
103886
|
}
|
|
103736
103887
|
// src/sql/modules/enrollments-functions.ts
|
|
103737
103888
|
const STEP_ID = "^[a-z][a-z0-9_.-]{0,63}$";
|
|
103738
|
-
const TYPE$
|
|
103889
|
+
const TYPE$3 = "^[a-z][a-z0-9_-]{0,62}$";
|
|
103739
103890
|
function maxStepsOf(ctx) {
|
|
103740
103891
|
const value = ctx.number("maxSteps", 100);
|
|
103741
103892
|
if (!Number.isInteger(value) || value < 1 || value > 1e3) throw new TypeError("blocks.enrollments.options.maxSteps must be a whole number from 1 to 1000");
|
|
@@ -104131,7 +104282,7 @@ begin
|
|
|
104131
104282
|
then save_enrollment_program.program -> 'steps' else coalesce(v_old.${p("steps")}, '[]'::jsonb) end;
|
|
104132
104283
|
v_enabled := case when save_enrollment_program.program ? 'enabled'
|
|
104133
104284
|
then (save_enrollment_program.program ->> 'enabled')::boolean else coalesce(v_old.${p("enabled")}, true) end;
|
|
104134
|
-
if v_key is null or v_key !~ '${TYPE$
|
|
104285
|
+
if v_key is null or v_key !~ '${TYPE$3}' then
|
|
104135
104286
|
${invalid("key: use lowercase letters, digits, \"_\" or \"-\", starting with a letter")}
|
|
104136
104287
|
end if;
|
|
104137
104288
|
if v_old.${p("id")} is not null and v_key <> v_old.${p("key")} then
|
|
@@ -104143,7 +104294,7 @@ begin
|
|
|
104143
104294
|
if length(v_description) > 2000 then
|
|
104144
104295
|
${invalid("description must be at most 2000 characters")}
|
|
104145
104296
|
end if;
|
|
104146
|
-
if exists (select 1 from unnest(v_types) as t(value) where t.value is null or t.value !~ '${TYPE$
|
|
104297
|
+
if exists (select 1 from unnest(v_types) as t(value) where t.value is null or t.value !~ '${TYPE$3}') then
|
|
104147
104298
|
${invalid("subjectTypes must be lower-case subject types")}
|
|
104148
104299
|
end if;
|
|
104149
104300
|
if jsonb_typeof(v_steps) <> 'array' or jsonb_array_length(v_steps) = 0 then
|
|
@@ -104265,7 +104416,7 @@ begin
|
|
|
104265
104416
|
if not v_program.${p("enabled")} then
|
|
104266
104417
|
${invalid("this program is turned off")}
|
|
104267
104418
|
end if;
|
|
104268
|
-
if enroll.subject_type is null or enroll.subject_type !~ '${TYPE$
|
|
104419
|
+
if enroll.subject_type is null or enroll.subject_type !~ '${TYPE$3}' or enroll.subject_id is null or length(enroll.subject_id) not between 1 and 200 then
|
|
104269
104420
|
${invalid("an enrollment needs a subject type and id")}
|
|
104270
104421
|
end if;
|
|
104271
104422
|
if cardinality(v_program.${p("subjectTypes")}) > 0 and not (enroll.subject_type = any(v_program.${p("subjectTypes")})) then
|
|
@@ -107188,7 +107339,7 @@ const NAMES$88 = {
|
|
|
107188
107339
|
optional: ["changedBy", "changedAt"]
|
|
107189
107340
|
} }
|
|
107190
107341
|
};
|
|
107191
|
-
const COLUMN$
|
|
107342
|
+
const COLUMN$8 = /^[a-z_][a-z0-9_]{0,62}$/u;
|
|
107192
107343
|
/**
|
|
107193
107344
|
* `blocks.field-history.on`, record type to `{ fields }`, checked against
|
|
107194
107345
|
* `config.subjects`.
|
|
@@ -107204,7 +107355,7 @@ function historyBindings(ctx) {
|
|
|
107204
107355
|
const subject = registry.find((item) => item.type === type);
|
|
107205
107356
|
if (subject?.tenant === void 0) throw new TypeError(`${where}: register "${type}" with a tenant column in config.subjects first`);
|
|
107206
107357
|
const fields = isRecord$1(settings) ? settings["fields"] : void 0;
|
|
107207
|
-
if (!Array.isArray(fields) || fields.length === 0 || fields.some((field) => typeof field !== "string" || !COLUMN$
|
|
107358
|
+
if (!Array.isArray(fields) || fields.length === 0 || fields.some((field) => typeof field !== "string" || !COLUMN$8.test(field))) throw new TypeError(`${where}.fields must be a non-empty list of column names`);
|
|
107208
107359
|
return {
|
|
107209
107360
|
subject,
|
|
107210
107361
|
fields: [...new Set(fields.map(String))]
|
|
@@ -111368,7 +111519,7 @@ ${userGrant(`${fn("invoice_funding_claim")}(uuid, jsonb)`)}
|
|
|
111368
111519
|
}
|
|
111369
111520
|
// src/sql/modules/time-tracking-status.ts
|
|
111370
111521
|
const WHERE$15 = "blocks.time-tracking.options.userTimeZone";
|
|
111371
|
-
const COLUMN$
|
|
111522
|
+
const COLUMN$7 = /^[a-z_][a-z0-9_]{0,62}$/u;
|
|
111372
111523
|
/**
|
|
111373
111524
|
* `options.userTimeZone` (`{ column: "schema.table.column", key? }`), or
|
|
111374
111525
|
* `undefined` when weeks start in `options.timeZone` for everyone.
|
|
@@ -111381,8 +111532,8 @@ function userTimeZoneOf(ctx) {
|
|
|
111381
111532
|
const column = entry["column"];
|
|
111382
111533
|
const key = entry["key"] ?? "id";
|
|
111383
111534
|
const parts = typeof column === "string" ? column.split(".") : [];
|
|
111384
|
-
if (parts.length !== 3 || !parts.every((part) => COLUMN$
|
|
111385
|
-
if (typeof key !== "string" || !COLUMN$
|
|
111535
|
+
if (parts.length !== 3 || !parts.every((part) => COLUMN$7.test(part))) throw new TypeError(`${WHERE$15}.column must be "schema.table.column"`);
|
|
111536
|
+
if (typeof key !== "string" || !COLUMN$7.test(key)) throw new TypeError(`${WHERE$15}.key must be the column holding the user id`);
|
|
111386
111537
|
return {
|
|
111387
111538
|
table: `${sqlIdent$1(parts[0])}.${sqlIdent$1(parts[1])}`,
|
|
111388
111539
|
column: sqlIdent$1(parts[2]),
|
|
@@ -114869,14 +115020,14 @@ function shippedAutomation(ctx, spec, target) {
|
|
|
114869
115020
|
});
|
|
114870
115021
|
}
|
|
114871
115022
|
// src/sql/modules/hiring-stages.ts
|
|
114872
|
-
const COLUMN$
|
|
115023
|
+
const COLUMN$6 = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
114873
115024
|
const OUTCOMES = [
|
|
114874
115025
|
"hired",
|
|
114875
115026
|
"rejected",
|
|
114876
115027
|
"withdrawn"
|
|
114877
115028
|
];
|
|
114878
115029
|
function columnOf$3(where, value) {
|
|
114879
|
-
if (typeof value !== "string" || !COLUMN$
|
|
115030
|
+
if (typeof value !== "string" || !COLUMN$6.test(value)) throw new TypeError(`${where} must be a column name`);
|
|
114880
115031
|
return sqlIdent$1(value);
|
|
114881
115032
|
}
|
|
114882
115033
|
function markerOf(where, value) {
|
|
@@ -121559,7 +121710,7 @@ const INBOX = {
|
|
|
121559
121710
|
seeds: inboxSeeds
|
|
121560
121711
|
};
|
|
121561
121712
|
// src/sql/modules/incidents-data.ts
|
|
121562
|
-
const COLUMN$
|
|
121713
|
+
const COLUMN$5 = "action_items";
|
|
121563
121714
|
/**
|
|
121564
121715
|
* Copies each postmortem's `action_items` into tasks through
|
|
121565
121716
|
* `add_incident_postmortem_action`. A postmortem that already has linked
|
|
@@ -121587,10 +121738,10 @@ begin
|
|
|
121587
121738
|
raise exception 'the incidents upgrade copies action_items into tasks as the service role or the migration role';
|
|
121588
121739
|
end if;
|
|
121589
121740
|
for v_post in
|
|
121590
|
-
select x.${pm("id")} as id, x.${COLUMN$
|
|
121741
|
+
select x.${pm("id")} as id, x.${COLUMN$5} as items
|
|
121591
121742
|
from ${postmortems} x
|
|
121592
|
-
where jsonb_typeof(x.${COLUMN$
|
|
121593
|
-
and jsonb_array_length(x.${COLUMN$
|
|
121743
|
+
where jsonb_typeof(x.${COLUMN$5}) = 'array'
|
|
121744
|
+
and jsonb_array_length(x.${COLUMN$5}) > 0
|
|
121594
121745
|
and not exists (select 1 from ${actions} y where y.${a("postmortem")} = x.${pm("id")})
|
|
121595
121746
|
order by x.${pm("id")}
|
|
121596
121747
|
loop
|
|
@@ -121648,8 +121799,8 @@ const ACTION_ITEMS_TO_TASKS = {
|
|
|
121648
121799
|
const table = ctx.table("postmortems");
|
|
121649
121800
|
const withTasks = ctx.installed("tasks") && ctx.hasTable("actions");
|
|
121650
121801
|
const regclass = `to_regclass(${sqlString(table)})`;
|
|
121651
|
-
const exists = `exists (select 1 from pg_attribute where attrelid = ${regclass} and attname = ${sqlString(COLUMN$
|
|
121652
|
-
const holds = `exists (select 1 from ${table} x where jsonb_typeof(x.${COLUMN$
|
|
121802
|
+
const exists = `exists (select 1 from pg_attribute where attrelid = ${regclass} and attname = ${sqlString(COLUMN$5)} and not attisdropped)`;
|
|
121803
|
+
const holds = `exists (select 1 from ${table} x where jsonb_typeof(x.${COLUMN$5}) = 'array' and jsonb_array_length(x.${COLUMN$5}) > 0)`;
|
|
121653
121804
|
const ready = `to_regprocedure(${sqlString(`${ctx.fn("add_incident_postmortem_action")}(uuid, text, uuid, timestamptz)`)}) is not null`;
|
|
121654
121805
|
return `-- Postmortem action items are tasks now (ADR 0149): copy what is left and drop the column.
|
|
121655
121806
|
do $upgrade$
|
|
@@ -121663,7 +121814,7 @@ ${withTasks ? ` if ${holds} then
|
|
|
121663
121814
|
end if;` : ` if ${holds} then
|
|
121664
121815
|
raise exception 'incident_postmortems.action_items still holds action items and the tasks block is not installed: install tasks to keep them as tasks, or clear the column, then run upgrade again';
|
|
121665
121816
|
end if;`}
|
|
121666
|
-
alter table ${table} drop column ${COLUMN$
|
|
121817
|
+
alter table ${table} drop column ${COLUMN$5};
|
|
121667
121818
|
end if;
|
|
121668
121819
|
end;
|
|
121669
121820
|
$upgrade$;`;
|
|
@@ -128594,7 +128745,11 @@ const NAMES$73 = {
|
|
|
128594
128745
|
...PROCUREMENT_ENTITIES
|
|
128595
128746
|
},
|
|
128596
128747
|
events: EVENTS$16,
|
|
128597
|
-
options: [
|
|
128748
|
+
options: [
|
|
128749
|
+
"extraColumns",
|
|
128750
|
+
"receiptInspection",
|
|
128751
|
+
"templates"
|
|
128752
|
+
],
|
|
128598
128753
|
hooks: [
|
|
128599
128754
|
"before_stock_adjust",
|
|
128600
128755
|
"after_stock_adjust",
|
|
@@ -128707,12 +128862,16 @@ const NAMES$73 = {
|
|
|
128707
128862
|
placedAt: "placed_at",
|
|
128708
128863
|
shipTo: "ship_to",
|
|
128709
128864
|
originType: "origin_type",
|
|
128710
|
-
originId: "origin_id"
|
|
128865
|
+
originId: "origin_id",
|
|
128866
|
+
template: "template_id",
|
|
128867
|
+
sourceTemplate: "source_template_id"
|
|
128711
128868
|
},
|
|
128712
128869
|
optional: [
|
|
128713
128870
|
"shipTo",
|
|
128714
128871
|
"originType",
|
|
128715
|
-
"originId"
|
|
128872
|
+
"originId",
|
|
128873
|
+
"template",
|
|
128874
|
+
"sourceTemplate"
|
|
128716
128875
|
],
|
|
128717
128876
|
typed: ["status"]
|
|
128718
128877
|
},
|
|
@@ -128857,7 +129016,7 @@ ${read("transferLines")}
|
|
|
128857
129016
|
` : ""}${orders ? `
|
|
128858
129017
|
create table if not exists ${t("purchaseOrders")} (
|
|
128859
129018
|
${po("id")} uuid primary key default gen_random_uuid(),
|
|
128860
|
-
${po("tenant")} ${ctx.idType} not null,
|
|
129019
|
+
${po("tenant")} ${ctx.idType} not null,${purchaseTemplates(ctx) ? `\n ${templateColumnSql(ctx.colName("purchaseOrders", "template"), ctx.of("templates").table("templates"), true)},${ctx.has("purchaseOrders", "sourceTemplate") ? `\n ${sourceTemplateColumnSql(ctx.colName("purchaseOrders", "sourceTemplate"), ctx.of("templates").table("templates"))},` : ""}` : ""}
|
|
128861
129020
|
${po("location")} uuid not null references ${location},
|
|
128862
129021
|
${po("supplierType")} text,
|
|
128863
129022
|
${po("supplierId")} text,
|
|
@@ -129223,6 +129382,11 @@ const REQUIRES$3 = [
|
|
|
129223
129382
|
"catalog",
|
|
129224
129383
|
"ledger"
|
|
129225
129384
|
];
|
|
129385
|
+
function purchaseTemplates(ctx) {
|
|
129386
|
+
if (!ctx.flag("templates", false) || !ctx.hasTable("purchaseOrders")) return false;
|
|
129387
|
+
if (!ctx.installed("templates")) throw new TypeError("blocks.inventory.options.templates needs the templates block");
|
|
129388
|
+
return ctx.has("purchaseOrders", "template");
|
|
129389
|
+
}
|
|
129226
129390
|
const INVENTORY = {
|
|
129227
129391
|
name: "inventory",
|
|
129228
129392
|
scopes: ["tenant"],
|
|
@@ -129236,7 +129400,8 @@ const INVENTORY = {
|
|
|
129236
129400
|
"accounting",
|
|
129237
129401
|
"contacts",
|
|
129238
129402
|
"approvals",
|
|
129239
|
-
"inspections"
|
|
129403
|
+
"inspections",
|
|
129404
|
+
"templates"
|
|
129240
129405
|
],
|
|
129241
129406
|
target: "schema",
|
|
129242
129407
|
modes: ["managed", "custom"],
|
|
@@ -133464,6 +133629,12 @@ function quoteOrigin(ctx) {
|
|
|
133464
133629
|
* `blocks.quotes.options.versionLines`: each published version keeps its lines
|
|
133465
133630
|
* as rows with their own ids in `quote_version_lines`.
|
|
133466
133631
|
*/
|
|
133632
|
+
/** Template rows are on for quotes (ADR 0244). */
|
|
133633
|
+
function quoteTemplatesOn(ctx) {
|
|
133634
|
+
if (!ctx.flag("templates", false)) return false;
|
|
133635
|
+
if (!ctx.installed("templates")) throw new TypeError("blocks.quotes.options.templates needs the templates block");
|
|
133636
|
+
return ctx.has("quotes", "template");
|
|
133637
|
+
}
|
|
133467
133638
|
function versionLinesOn(ctx) {
|
|
133468
133639
|
return ctx.flag("versionLines", false) && ctx.hasTable("versionLines");
|
|
133469
133640
|
}
|
|
@@ -133514,7 +133685,8 @@ function quoteKit(ctx, n) {
|
|
|
133514
133685
|
payload: `jsonb_build_object('organizationId', ${alias}.${q("tenant")}, 'quoteId', ${alias}.${q("id")}, 'subjectType', 'quote', 'subjectId', ${alias}.${q("id")}::text, 'identifier', ${alias}.${q("identifier")}${extra})`,
|
|
133515
133686
|
subject: `'quotes/' || ${alias}.${q("id")}::text`,
|
|
133516
133687
|
tenant: `${alias}.${q("tenant")}::text`,
|
|
133517
|
-
audit: false
|
|
133688
|
+
audit: false,
|
|
133689
|
+
...quoteTemplatesOn(ctx) ? { live: `${alias}.${q("template")} is null` } : {}
|
|
133518
133690
|
});
|
|
133519
133691
|
const markViewed = () => viewed || has("viewedAt") ? ` if ${st(`v_row.${q("status")}`, ["sent"])}${viewed ? "" : ` and v_row.${q("viewedAt")} is null`} then
|
|
133520
133692
|
update ${t("quotes")} x set ${viewed ? `${q("status")} = ${sv("viewed")}${has("viewedAt") ? ", " : ""}` : ""}${has("viewedAt") ? `${q("viewedAt")} = now()` : ""} where x.${q("id")} = v_row.${q("id")}
|
|
@@ -135937,6 +136109,52 @@ $$;
|
|
|
135937
136109
|
${userGrant(`${fn("purchase_bill_match")}(uuid)`)}
|
|
135938
136110
|
`;
|
|
135939
136111
|
}
|
|
136112
|
+
// src/sql/modules/invoices-templates.ts
|
|
136113
|
+
/** Template rows are on for invoices (ADR 0244). */
|
|
136114
|
+
function invoiceTemplatesOn(ctx) {
|
|
136115
|
+
if (!ctx.flag("templates", false)) return false;
|
|
136116
|
+
if (!ctx.installed("templates")) throw new TypeError("blocks.invoices.options.templates needs the templates block");
|
|
136117
|
+
return ctx.has("invoices", "template");
|
|
136118
|
+
}
|
|
136119
|
+
/** `clone_invoice`: a new invoice from an invoice or a template, with its lines. */
|
|
136120
|
+
function cloneInvoice(ctx, n, fn, t, i, row) {
|
|
136121
|
+
const on = invoiceTemplatesOn(ctx);
|
|
136122
|
+
const template = on ? "case when coalesce(clone_invoice.overrides, '{}'::jsonb) ? 'templateId' then clone_invoice.overrides ->> 'templateId' else null end" : "null";
|
|
136123
|
+
const copied = ctx.has("invoices", "sourceTemplate") ? `v_src.${i("sourceTemplate")}::text` : "null";
|
|
136124
|
+
const source = on ? `case when v_src.${i("template")} is not null then v_src.${i("template")}::text else ${copied} end` : "null";
|
|
136125
|
+
const parentKey = sqlString(ctx.colName("lines", "parent"));
|
|
136126
|
+
return [
|
|
136127
|
+
`create or replace function ${fn("clone_invoice")}(source uuid, overrides jsonb default null)`,
|
|
136128
|
+
"returns jsonb",
|
|
136129
|
+
"language plpgsql",
|
|
136130
|
+
"security definer",
|
|
136131
|
+
"set search_path = ''",
|
|
136132
|
+
"as $$",
|
|
136133
|
+
"declare",
|
|
136134
|
+
` v_src ${t("invoices")};`,
|
|
136135
|
+
" v_created jsonb;",
|
|
136136
|
+
" v_id uuid;",
|
|
136137
|
+
"begin",
|
|
136138
|
+
` select * into v_src from ${t("invoices")} x where x.${i("id")} = clone_invoice.source;`,
|
|
136139
|
+
" if not found then",
|
|
136140
|
+
` ${fail("INVOICE_NOT_FOUND", "no such invoice", "P0002")}`,
|
|
136141
|
+
" end if;",
|
|
136142
|
+
` if not (${n.service} or ${ctx.scope.can(`v_src.${i("tenant")}`, n.write)}) then`,
|
|
136143
|
+
` ${fail("INVOICE_FORBIDDEN", "not allowed to change invoices")}`,
|
|
136144
|
+
" end if;",
|
|
136145
|
+
` ${ctx.hook("before_invoice_clone", [["uuid", "clone_invoice.source"], ["jsonb", "clone_invoice.overrides"]])}`,
|
|
136146
|
+
` v_created := ${fn("create_invoice")}(v_src.${i("tenant")}, jsonb_strip_nulls(jsonb_build_object('title', v_src.${i("title")}, 'currency', v_src.${i("currency")}, 'templateId', ${template}, 'sourceTemplateId', ${source})) || (coalesce(clone_invoice.overrides, '{}'::jsonb) - 'templateId') || jsonb_strip_nulls(jsonb_build_object('templateId', ${template}, 'sourceTemplateId', ${source})), null);`,
|
|
136147
|
+
" v_id := (v_created ->> 'id')::uuid;",
|
|
136148
|
+
` insert into ${t("lines")}`,
|
|
136149
|
+
` select (jsonb_populate_record(null::${t("lines")}, to_jsonb(l) || jsonb_build_object('id', gen_random_uuid(), ${parentKey}, v_id))).*`,
|
|
136150
|
+
` from ${t("lines")} l where l.${ctx.col("lines", "parent")} = clone_invoice.source;`,
|
|
136151
|
+
` ${ctx.hook("after_invoice_clone", [["uuid", "v_id"]])}`,
|
|
136152
|
+
` return (select ${row("x")} from ${t("invoices")} x where x.${i("id")} = v_id);`,
|
|
136153
|
+
"end;",
|
|
136154
|
+
"$$;",
|
|
136155
|
+
userGrant(`${fn("clone_invoice")}(uuid, jsonb)`)
|
|
136156
|
+
].join("\n");
|
|
136157
|
+
}
|
|
135940
136158
|
// src/sql/modules/invoices-terms.ts
|
|
135941
136159
|
/**
|
|
135942
136160
|
* The invoice columns payment terms add: the terms an invoice copied from its
|
|
@@ -136148,6 +136366,7 @@ function invoiceFunctions(ctx, n) {
|
|
|
136148
136366
|
payload: `jsonb_build_object('organizationId', ${alias}.${i("tenant")}, 'invoiceId', ${alias}.${i("id")}, 'subjectType', 'invoice', 'subjectId', ${alias}.${i("id")}::text, 'identifier', ${alias}.${i("identifier")}${extra})`,
|
|
136149
136367
|
subject: `'invoices/' || ${alias}.${i("id")}::text`,
|
|
136150
136368
|
tenant: `${alias}.${i("tenant")}::text`,
|
|
136369
|
+
...invoiceTemplatesOn(ctx) ? { live: `${alias}.${i("template")} is null` } : {},
|
|
136151
136370
|
audit: audit ? {
|
|
136152
136371
|
category: "billing",
|
|
136153
136372
|
targetType: "invoice",
|
|
@@ -136440,7 +136659,7 @@ begin
|
|
|
136440
136659
|
end if;` : ""}${refuse(has("depositBps"), "create_invoice.attrs ->> 'depositBps'", "DEPOSIT", "deposit column")}${refuse(has("pricesIncludeTax"), "nullif(create_invoice.attrs ->> 'pricesIncludeTax', 'false')", "PRICING", "prices_include_tax column")}${headerRefusals("create_invoice.attrs")}${terms.lookup}
|
|
136441
136660
|
begin
|
|
136442
136661
|
insert into ${t("invoices")} (${i("tenant")}, ${i("title")}${also("companyType")}${also("companyId")}${also("contactType")}${also("contactId")}, ${i("currency")},
|
|
136443
|
-
${i("termsDays")}${also("note")}${also("originType")}${also("originId")}${also("depositBps")}${also("depositAmount")}${also("discountBps")}${also("discountAmount")}${also("pricesIncludeTax")}${also("direction")}${also("supplierReference")}${also("purchaseOrder")}${also("dimensions")}${terms.column}${also("createdBy")}${insertExtraColumns(t("invoices"), n.extras, "create_invoice.attrs").columns})
|
|
136662
|
+
${i("termsDays")}${also("note")}${also("originType")}${also("originId")}${also("depositBps")}${also("depositAmount")}${also("discountBps")}${also("discountAmount")}${also("pricesIncludeTax")}${also("direction")}${also("supplierReference")}${also("purchaseOrder")}${also("dimensions")}${terms.column}${also("createdBy")}${invoiceTemplatesOn(ctx) ? `, ${i("template")}${ctx.has("invoices", "sourceTemplate") ? `, ${i("sourceTemplate")}` : ""}` : ""}${insertExtraColumns(t("invoices"), n.extras, "create_invoice.attrs").columns})
|
|
136444
136663
|
values (${valueLines(" ", ["create_invoice.tenant", "trim(create_invoice.attrs ->> 'title')"], [present("companyType", "case when v_company_id is null then null else v_company_type end"), company === void 0 ? void 0 : partyId("company", "v_company_id")], [present("contactType", "case when v_contact_id is null then null else v_contact_type end"), contact === void 0 ? void 0 : partyId("contact", "v_contact_id")], ["upper(coalesce(create_invoice.attrs ->> 'currency', 'EUR'))", `case when create_invoice.attrs ? 'termsDays' then (create_invoice.attrs ->> 'termsDays')::integer else ${terms.days(String(n.termsDays))} end`], [
|
|
136445
136664
|
present("note", "create_invoice.attrs ->> 'note'"),
|
|
136446
136665
|
present("originType", "create_invoice.attrs -> 'origin' ->> 'type'"),
|
|
@@ -136454,7 +136673,7 @@ begin
|
|
|
136454
136673
|
...PURCHASE_VALUES.map(([key, value]) => present(key, value)),
|
|
136455
136674
|
terms.value,
|
|
136456
136675
|
present("createdBy", "auth.uid()")
|
|
136457
|
-
])}${insertExtraColumns(t("invoices"), n.extras, "create_invoice.attrs").values})
|
|
136676
|
+
])}${invoiceTemplatesOn(ctx) ? `, nullif(create_invoice.attrs ->> 'templateId', '')::uuid${ctx.has("invoices", "sourceTemplate") ? ", nullif(create_invoice.attrs ->> 'sourceTemplateId', '')::uuid" : ""}` : ""}${insertExtraColumns(t("invoices"), n.extras, "create_invoice.attrs").values})
|
|
136458
136677
|
returning * into v_row;
|
|
136459
136678
|
exception when check_violation or invalid_text_representation${discounts || has("depositAmount") ? " or numeric_value_out_of_range" : ""} then
|
|
136460
136679
|
${fail("INVOICE_ATTRS_INVALID", "an invoice field has an invalid value", "22023")}
|
|
@@ -136519,6 +136738,7 @@ begin
|
|
|
136519
136738
|
if v_row.${i("id")} is null then
|
|
136520
136739
|
${fail("INVOICE_NOT_FOUND", "no such invoice you can edit", "P0002")}
|
|
136521
136740
|
end if;
|
|
136741
|
+
${invoiceTemplatesOn(ctx) ? `if v_row.${i("template")} is not null then\n ${fail("INVOICE_TEMPLATE", "a template invoice cannot be issued", "22023")}\n end if;` : ""}
|
|
136522
136742
|
if ${st(`v_row.${i("status")}`, ["draft"], true)} then
|
|
136523
136743
|
${fail("INVOICE_NOT_DRAFT", "the invoice was already issued", "55000")}
|
|
136524
136744
|
end if;
|
|
@@ -136850,7 +137070,7 @@ ${addCharge}${p.aging}${fromQuote}${p.functions}${invoiceCollectionsAndOpenItems
|
|
|
136850
137070
|
settle,
|
|
136851
137071
|
ledger,
|
|
136852
137072
|
charges
|
|
136853
|
-
})}`;
|
|
137073
|
+
})}${cloneInvoice(ctx, n, fn, t, i, row)}`;
|
|
136854
137074
|
}
|
|
136855
137075
|
// src/sql/modules/invoices-accounting.ts
|
|
136856
137076
|
/**
|
|
@@ -137814,7 +138034,8 @@ const NAMES$71 = {
|
|
|
137814
138034
|
permissions: {
|
|
137815
138035
|
read: "read",
|
|
137816
138036
|
write: "write"
|
|
137817
|
-
}
|
|
138037
|
+
},
|
|
138038
|
+
template: "template"
|
|
137818
138039
|
}
|
|
137819
138040
|
} },
|
|
137820
138041
|
events: EVENTS$15,
|
|
@@ -137822,7 +138043,9 @@ const NAMES$71 = {
|
|
|
137822
138043
|
"before_invoice_issue",
|
|
137823
138044
|
"after_invoice_issue",
|
|
137824
138045
|
"before_invoice_payment",
|
|
137825
|
-
"after_invoice_payment"
|
|
138046
|
+
"after_invoice_payment",
|
|
138047
|
+
"before_invoice_clone",
|
|
138048
|
+
"after_invoice_clone"
|
|
137826
138049
|
],
|
|
137827
138050
|
options: [
|
|
137828
138051
|
"company",
|
|
@@ -137847,7 +138070,9 @@ const NAMES$71 = {
|
|
|
137847
138070
|
"purchasePrefix",
|
|
137848
138071
|
"purchaseCreditPrefix",
|
|
137849
138072
|
"matchTolerance",
|
|
137850
|
-
"correctionEvents"
|
|
138073
|
+
"correctionEvents",
|
|
138074
|
+
"templates",
|
|
138075
|
+
"requireParty"
|
|
137851
138076
|
],
|
|
137852
138077
|
tables: {
|
|
137853
138078
|
invoices: {
|
|
@@ -137911,6 +138136,8 @@ const NAMES$71 = {
|
|
|
137911
138136
|
collectionStatus: "collection_status",
|
|
137912
138137
|
collectionAgencyId: "collection_agency_id",
|
|
137913
138138
|
collectionHandedAt: "collection_handed_at",
|
|
138139
|
+
template: "template_id",
|
|
138140
|
+
sourceTemplate: "source_template_id",
|
|
137914
138141
|
createdBy: "created_by",
|
|
137915
138142
|
createdAt: "created_at",
|
|
137916
138143
|
updatedAt: "updated_at",
|
|
@@ -137932,6 +138159,8 @@ const NAMES$71 = {
|
|
|
137932
138159
|
"discountAmount",
|
|
137933
138160
|
"pricesIncludeTax",
|
|
137934
138161
|
"archivedAt",
|
|
138162
|
+
"template",
|
|
138163
|
+
"sourceTemplate",
|
|
137935
138164
|
...PURCHASE_COLUMNS,
|
|
137936
138165
|
...COLLECTION_COLUMNS,
|
|
137937
138166
|
"buyer",
|
|
@@ -138050,7 +138279,7 @@ ${renderPolicy(policy$1({
|
|
|
138050
138279
|
return `
|
|
138051
138280
|
create table if not exists ${t("invoices")} (
|
|
138052
138281
|
${i("id")} uuid primary key default gen_random_uuid(),
|
|
138053
|
-
${i("tenant")} ${ctx.idType} not null,
|
|
138282
|
+
${i("tenant")} ${ctx.idType} not null,${invoiceTemplatesOn(ctx) ? `\n ${templateColumnSql(ctx.colName("invoices", "template"), ctx.of("templates").table("templates"), true)},${ctx.has("invoices", "sourceTemplate") ? `\n ${sourceTemplateColumnSql(ctx.colName("invoices", "sourceTemplate"), ctx.of("templates").table("templates"))},` : ""}` : ""}
|
|
138054
138283
|
${i("kind")} text not null default 'invoice' check (${i("kind")} in ('invoice', 'credit_note')),
|
|
138055
138284
|
${i("number")} bigint,
|
|
138056
138285
|
${i("identifier")} text,
|
|
@@ -138070,7 +138299,7 @@ create table if not exists ${t("invoices")} (
|
|
|
138070
138299
|
${totalColumnsSql(ctx, "invoices")},
|
|
138071
138300
|
${uniqueNumber === false ? "" : ` unique (${numberKey.map(i).join(", ")}),\n`} check ((${i("kind")} = 'credit_note') = (${i("original")} is not null)),
|
|
138072
138301
|
check (${i("status")} <> 'draft' or ${i("number")} is null),
|
|
138073
|
-
check (${i("status")} in ('draft', 'void') or ${i("number")} is not null)${company === "pair" ? `,\n check ((${i("companyType")} is null) = (${i("companyId")} is null))` : ""}
|
|
138302
|
+
check (${invoiceTemplatesOn(ctx) ? `${i("template")} is not null or ` : ""}${i("status")} in ('draft', 'void') or ${i("number")} is not null)${company === "pair" ? `,\n check ((${i("companyType")} is null) = (${i("companyId")} is null))` : ""}${invoiceTemplatesOn(ctx) && ctx.flag("requireParty", false) && ctx.has("invoices", "companyId") ? `,\n check (${i("template")} is not null or ${i("companyId")} is not null)` : ""}
|
|
138074
138303
|
);
|
|
138075
138304
|
${added === "" ? "" : `${added.slice(1)}\n`}create index if not exists ${ctx.naming.rename("invoices_tenant_status_idx")} on ${t("invoices")} (${i("tenant")}, ${i("status")}, ${i("dueOn")});${origin === void 0 ? "" : index("invoices_origin_idx", origin === "pair" ? ["originType", "originId"] : ["originId"])}${index("invoices_original_idx", ["original"])}${company === void 0 ? "" : index("invoices_company_idx", company === "pair" ? ["companyType", "companyId"] : ["companyId"])}${addExtraColumns(t("invoices"), n.extras)}${searchColumnSql(ctx, "invoices", [
|
|
138076
138305
|
"identifier",
|
|
@@ -138078,7 +138307,13 @@ ${added === "" ? "" : `${added.slice(1)}\n`}create index if not exists ${ctx.nam
|
|
|
138078
138307
|
"note",
|
|
138079
138308
|
"supplierReference"
|
|
138080
138309
|
])}${ctx.has("invoices", "purchaseOrder") ? index("invoices_purchase_order_idx", ["purchaseOrder"]) : ""}${uniqueNumber === false ? "" : appUniqueIndex(ctx, "invoices", numberKey)}
|
|
138081
|
-
${lockModuleTable(ctx, "invoices", { read: true })}
|
|
138310
|
+
${lockModuleTable(ctx, "invoices", { read: true })}${invoiceTemplatesOn(ctx) ? `\n${templateGuardSql({
|
|
138311
|
+
fn: ctx.fn("invoice_template_guard"),
|
|
138312
|
+
trigger: ctx.trigger("invoice_template"),
|
|
138313
|
+
table: t("invoices"),
|
|
138314
|
+
column: ctx.colName("invoices", "template"),
|
|
138315
|
+
hint: "INVOICE_TEMPLATE_IMMUTABLE"
|
|
138316
|
+
})}\n${triggerGrant(`${ctx.fn("invoice_template_guard")}()`)}` : ""}
|
|
138082
138317
|
${renderPolicy(policy$1({
|
|
138083
138318
|
table: t("invoices"),
|
|
138084
138319
|
name: ctx.naming.rename("invoices_read"),
|
|
@@ -138218,6 +138453,11 @@ function contract$62(ctx) {
|
|
|
138218
138453
|
],
|
|
138219
138454
|
returns: "jsonb"
|
|
138220
138455
|
},
|
|
138456
|
+
{
|
|
138457
|
+
name: "clone_invoice",
|
|
138458
|
+
args: ["uuid", "jsonb"],
|
|
138459
|
+
returns: "jsonb"
|
|
138460
|
+
},
|
|
138221
138461
|
{
|
|
138222
138462
|
name: "update_invoice",
|
|
138223
138463
|
args: ["uuid", "jsonb"],
|
|
@@ -138389,7 +138629,8 @@ const INVOICES = {
|
|
|
138389
138629
|
"contacts",
|
|
138390
138630
|
"orders",
|
|
138391
138631
|
"shipments",
|
|
138392
|
-
"billable-time"
|
|
138632
|
+
"billable-time",
|
|
138633
|
+
"templates"
|
|
138393
138634
|
],
|
|
138394
138635
|
target: "schema",
|
|
138395
138636
|
modes: ["managed", "custom"],
|
|
@@ -138402,7 +138643,24 @@ const INVOICES = {
|
|
|
138402
138643
|
names: NAMES$71,
|
|
138403
138644
|
contributes: {
|
|
138404
138645
|
accounting: (own) => accountingContributions(own, invoiceAccountingSources(own)),
|
|
138405
|
-
imports: invoiceImportTargets
|
|
138646
|
+
imports: invoiceImportTargets,
|
|
138647
|
+
templates: (own) => {
|
|
138648
|
+
if (!invoiceTemplatesOn(own)) return [];
|
|
138649
|
+
const { schema, name } = own.tableName("invoices");
|
|
138650
|
+
return [{
|
|
138651
|
+
type: "invoice",
|
|
138652
|
+
storage: "rows",
|
|
138653
|
+
subject: "invoice",
|
|
138654
|
+
clone: own.fn("clone_invoice"),
|
|
138655
|
+
table: `${schema}.${name}`,
|
|
138656
|
+
templateColumn: own.colName("invoices", "template"),
|
|
138657
|
+
idColumn: own.colName("invoices", "id"),
|
|
138658
|
+
children: [{
|
|
138659
|
+
table: `${schema}.${own.tableName("lines").name}`,
|
|
138660
|
+
parent: own.colName("lines", "parent")
|
|
138661
|
+
}]
|
|
138662
|
+
}];
|
|
138663
|
+
}
|
|
138406
138664
|
},
|
|
138407
138665
|
contract: contract$62,
|
|
138408
138666
|
build: build$72
|
|
@@ -145949,11 +146207,11 @@ const NAMES$65 = {
|
|
|
145949
146207
|
}
|
|
145950
146208
|
}
|
|
145951
146209
|
};
|
|
145952
|
-
const TYPE$
|
|
146210
|
+
const TYPE$2 = /^[a-z][a-z0-9_]{0,62}$/;
|
|
145953
146211
|
function names$3(ctx) {
|
|
145954
146212
|
const keys = moduleOperations("mail-sync");
|
|
145955
146213
|
const engagementType = ctx.text("engagementType", "email");
|
|
145956
|
-
if (!TYPE$
|
|
146214
|
+
if (!TYPE$2.test(engagementType)) throw new TypeError("blocks.mail-sync.options.engagementType must be a lowercase engagement type");
|
|
145957
146215
|
const json = (table, alias) => {
|
|
145958
146216
|
if (ctx.owns(table)) return `to_jsonb(${alias})`;
|
|
145959
146217
|
return `jsonb_build_object(${Object.entries(NAMES$65.tables[table]?.columns ?? {}).map(([logical, name]) => `${sqlString(name)}, ${ctx.has(table, logical) ? `${alias}.${ctx.col(table, logical)}` : "null"}`).join(", ")})`;
|
|
@@ -150967,7 +151225,7 @@ function meetingsSql(ctx) {
|
|
|
150967
151225
|
}
|
|
150968
151226
|
// src/sql/modules/meetings-functions.ts
|
|
150969
151227
|
const UUID$3 = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$";
|
|
150970
|
-
const quoted = (values) => values.map((value) => `'${value}'`).join(", ");
|
|
151228
|
+
const quoted$1 = (values) => values.map((value) => `'${value}'`).join(", ");
|
|
150971
151229
|
/** Loads `v_row` by `func.<arg>` for the callers who may see it. */
|
|
150972
151230
|
function load$1(q, func, arg) {
|
|
150973
151231
|
const { m, meetings } = q;
|
|
@@ -151000,8 +151258,8 @@ begin
|
|
|
151000
151258
|
if exists (
|
|
151001
151259
|
select 1 from jsonb_array_elements(v_team) e
|
|
151002
151260
|
where jsonb_typeof(e) <> 'object' or coalesce(e ->> 'userId', '') !~ '${UUID$3}'
|
|
151003
|
-
or coalesce(e ->> 'role', 'attendee') not in (${quoted(MEETING_ATTENDEE_ROLES)})
|
|
151004
|
-
or coalesce(e ->> 'attendance', 'invited') not in (${quoted(MEETING_ATTENDANCE)})
|
|
151261
|
+
or coalesce(e ->> 'role', 'attendee') not in (${quoted$1(MEETING_ATTENDEE_ROLES)})
|
|
151262
|
+
or coalesce(e ->> 'attendance', 'invited') not in (${quoted$1(MEETING_ATTENDANCE)})
|
|
151005
151263
|
) then
|
|
151006
151264
|
${q.invalid("each attendee needs a userId, a role of chair, secretary, attendee or guest, and an attendance of invited, present, absent or excused")}
|
|
151007
151265
|
end if;
|
|
@@ -151308,8 +151566,8 @@ begin
|
|
|
151308
151566
|
if v_row.${m("status")} = 'cancelled' then
|
|
151309
151567
|
${q.invalid("a cancelled meeting takes no changes")}
|
|
151310
151568
|
end if;
|
|
151311
|
-
if set_meeting_attendee.role not in (${quoted(MEETING_ATTENDEE_ROLES)})
|
|
151312
|
-
or set_meeting_attendee.attendance not in (${quoted(MEETING_ATTENDANCE)}) then
|
|
151569
|
+
if set_meeting_attendee.role not in (${quoted$1(MEETING_ATTENDEE_ROLES)})
|
|
151570
|
+
or set_meeting_attendee.attendance not in (${quoted$1(MEETING_ATTENDANCE)}) then
|
|
151313
151571
|
${q.invalid("role or attendance is not one of the allowed values")}
|
|
151314
151572
|
end if;
|
|
151315
151573
|
if not exists (
|
|
@@ -151404,7 +151662,7 @@ begin
|
|
|
151404
151662
|
${q.invalid("id is a uuid and ordinal an integer")}
|
|
151405
151663
|
end;
|
|
151406
151664
|
v_status := save_meeting_agenda_item.item ->> 'status';
|
|
151407
|
-
if v_status is not null and v_status not in (${quoted(MEETING_AGENDA_STATUSES)}) then
|
|
151665
|
+
if v_status is not null and v_status not in (${quoted$1(MEETING_AGENDA_STATUSES)}) then
|
|
151408
151666
|
${q.invalid("status is open, covered or skipped")}
|
|
151409
151667
|
end if;
|
|
151410
151668
|
if v_ordinal is not null and v_ordinal < 1 then
|
|
@@ -151533,7 +151791,7 @@ begin
|
|
|
151533
151791
|
${q.invalid("a decision needs a title of 1 to 300 characters")}
|
|
151534
151792
|
end if;
|
|
151535
151793
|
v_status := coalesce(record_meeting_decision.input ->> 'status', 'proposed');
|
|
151536
|
-
if v_status not in (${quoted(MEETING_DECISION_STATUSES)}) then
|
|
151794
|
+
if v_status not in (${quoted$1(MEETING_DECISION_STATUSES)}) then
|
|
151537
151795
|
${q.invalid("status is proposed, passed, rejected or deferred")}
|
|
151538
151796
|
end if;${hasBody ? `
|
|
151539
151797
|
if length(record_meeting_decision.input ->> 'body') > 10000 then
|
|
@@ -155353,16 +155611,25 @@ const qualified$6 = (table) => table.includes(".") ? table : `public.${table}`;
|
|
|
155353
155611
|
*/
|
|
155354
155612
|
function declaredMetrics(ctx) {
|
|
155355
155613
|
return metricsOf(ctx.option("metrics")).map((metric) => {
|
|
155356
|
-
|
|
155357
|
-
const column =
|
|
155358
|
-
|
|
155359
|
-
|
|
155360
|
-
|
|
155614
|
+
const subject = Object.values(ctx.subjects).find((entry) => qualified$6(entry.table) === qualified$6(metric.table));
|
|
155615
|
+
const column = subject?.deletedAt;
|
|
155616
|
+
const template = subject === void 0 ? void 0 : templateRowsOf(subject)?.column;
|
|
155617
|
+
let next = metric;
|
|
155618
|
+
if (metric.includeDeleted !== true && column !== void 0 && !Object.hasOwn(next.where ?? {}, column)) next = {
|
|
155619
|
+
...next,
|
|
155361
155620
|
where: {
|
|
155362
|
-
...
|
|
155621
|
+
...next.where,
|
|
155363
155622
|
[column]: null
|
|
155364
155623
|
}
|
|
155365
155624
|
};
|
|
155625
|
+
if (template !== void 0 && !Object.hasOwn(next.where ?? {}, template)) next = {
|
|
155626
|
+
...next,
|
|
155627
|
+
where: {
|
|
155628
|
+
...next.where,
|
|
155629
|
+
[template]: null
|
|
155630
|
+
}
|
|
155631
|
+
};
|
|
155632
|
+
return next;
|
|
155366
155633
|
});
|
|
155367
155634
|
}
|
|
155368
155635
|
/**
|
|
@@ -163585,11 +163852,11 @@ function brandSourceOf(ctx, where) {
|
|
|
163585
163852
|
// src/sql/modules/option-sets-bindings.ts
|
|
163586
163853
|
const KEY$1 = /^[a-z][a-z0-9_-]{0,62}$/;
|
|
163587
163854
|
const FIELD$1 = /^[a-z][a-z0-9_]{0,62}$/;
|
|
163588
|
-
const COLUMN$
|
|
163855
|
+
const COLUMN$4 = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
163589
163856
|
const BRAND$1 = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,99}$/;
|
|
163590
163857
|
function columnOf$2(where, value, fallback) {
|
|
163591
163858
|
const column = value ?? fallback;
|
|
163592
|
-
if (typeof column !== "string" || !COLUMN$
|
|
163859
|
+
if (typeof column !== "string" || !COLUMN$4.test(column)) throw new TypeError(`${where} must be a column name`);
|
|
163593
163860
|
return column;
|
|
163594
163861
|
}
|
|
163595
163862
|
function levelOf(where, value, min, max) {
|
|
@@ -164460,7 +164727,8 @@ function documentFunctions(ctx, names) {
|
|
|
164460
164727
|
]),
|
|
164461
164728
|
subject: "'orders/' || v_order.id::text",
|
|
164462
164729
|
tenant: "v_order.tenant",
|
|
164463
|
-
audit: false
|
|
164730
|
+
audit: false,
|
|
164731
|
+
...orderTemplatesOn(ctx) ? { live: `v_order.${ctx.colName("orders", "template")} is null` } : {}
|
|
164464
164732
|
});
|
|
164465
164733
|
const fromQuote = ctx.installed("quotes") ? quoteFunction(ctx, names) : noQuoteFunction(names);
|
|
164466
164734
|
return `
|
|
@@ -164497,14 +164765,14 @@ begin
|
|
|
164497
164765
|
${assignNumber$1(ctx, "order", "p_tenant", {
|
|
164498
164766
|
seq: "v_seq",
|
|
164499
164767
|
number: "v_number"
|
|
164500
|
-
})}
|
|
164768
|
+
}, orderTemplatesOn(ctx) ? "nullif(p_attrs ->> 'templateId', '') is null" : void 0)}
|
|
164501
164769
|
insert into ${orders} (${o("tenant")}, ${o("number")}, ${o("sequence")}, ${o("customer")}, ${email ? `${o("email")}, ` : ""}${o("status")}, ${o("currency")},
|
|
164502
164770
|
${o("subtotal")}, ${o("discountTotal")}, ${o("shippingTotal")}, ${o("taxTotal")}, ${o("total")}, ${o("taxInclusive")},
|
|
164503
|
-
${o("shippingAddress")}${billing ? `, ${o("billingAddress")}` : ""}${origin ? `, ${o("originType")}, ${o("originId")}` : ""})
|
|
164771
|
+
${o("shippingAddress")}${billing ? `, ${o("billingAddress")}` : ""}${origin ? `, ${o("originType")}, ${o("originId")}` : ""}${orderTemplatesOn(ctx) ? `, ${o("template")}${ctx.has("orders", "sourceTemplate") ? `, ${o("sourceTemplate")}` : ""}` : ""})
|
|
164504
164772
|
values (p_tenant, v_number, v_seq, nullif(p_attrs ->> 'customerId', '')::uuid, ${email ? "p_attrs ->> 'email', " : ""}${ctx.value("orders", "status", "confirmed")}, p_attrs ->> 'currency',
|
|
164505
164773
|
(p_attrs ->> 'subtotal')::bigint, (p_attrs ->> 'discountTotal')::bigint, (p_attrs ->> 'shippingTotal')::bigint,
|
|
164506
164774
|
(p_attrs ->> 'taxTotal')::bigint, (p_attrs ->> 'total')::bigint, coalesce((p_attrs ->> 'taxInclusive')::boolean, false),
|
|
164507
|
-
p_attrs -> 'shippingAddress'${billing ? ", p_attrs -> 'billingAddress'" : ""}${origin ? ", p_attrs #>> '{origin,type}', p_attrs #>> '{origin,id}'" : ""})
|
|
164775
|
+
p_attrs -> 'shippingAddress'${billing ? ", p_attrs -> 'billingAddress'" : ""}${origin ? ", p_attrs #>> '{origin,type}', p_attrs #>> '{origin,id}'" : ""}${orderTemplatesOn(ctx) ? `, nullif(p_attrs ->> 'templateId', '')::uuid${ctx.has("orders", "sourceTemplate") ? ", nullif(p_attrs ->> 'sourceTemplateId', '')::uuid" : ""}` : ""})
|
|
164508
164776
|
returning ${o("id")} into v_id;
|
|
164509
164777
|
insert into ${ctx.table("orderLines")} (${ol("tenant")}, ${ol("order")}, ${ol("position")}, ${ol("variant")}, ${ol("product")}, ${ol("sku")}, ${ol("title")},
|
|
164510
164778
|
${ol("quantity")}, ${ol("unitAmount")}, ${ol("subtotal")}, ${ol("discount")}, ${ol("tax")}, ${ol("total")}, ${ol("requiresShipping")})
|
|
@@ -164512,7 +164780,7 @@ begin
|
|
|
164512
164780
|
(e.l ->> 'quantity')::integer, (e.l ->> 'unitAmount')::bigint, (e.l ->> 'subtotal')::bigint, (e.l ->> 'discount')::bigint,
|
|
164513
164781
|
(e.l ->> 'tax')::bigint, (e.l ->> 'total')::bigint, (e.l ->> 'requiresShipping')::boolean
|
|
164514
164782
|
from jsonb_array_elements(p_lines) with ordinality as e(l, n);
|
|
164515
|
-
select ${orderFields(ctx, "x")} into v_order from ${orders} x where x.${o("id")} = v_id;${allocateLines(ctx, "p_location")}
|
|
164783
|
+
select ${orderFields(ctx, "x")} into v_order from ${orders} x where x.${o("id")} = v_id;${orderTemplatesOn(ctx) ? `\n if nullif(p_attrs ->> 'templateId', '') is null then\n ${allocateLines(ctx, "p_location")}\n end if;` : allocateLines(ctx, "p_location")}
|
|
164516
164784
|
${placed}
|
|
164517
164785
|
return ${fn("order_json")}(v_id) || jsonb_build_object('created', true);
|
|
164518
164786
|
end;
|
|
@@ -167396,7 +167664,8 @@ const NAMES$52 = {
|
|
|
167396
167664
|
permissions: {
|
|
167397
167665
|
read: "read",
|
|
167398
167666
|
write: "manage"
|
|
167399
|
-
}
|
|
167667
|
+
},
|
|
167668
|
+
template: "template"
|
|
167400
167669
|
}
|
|
167401
167670
|
},
|
|
167402
167671
|
cart: {
|
|
@@ -167417,7 +167686,8 @@ const NAMES$52 = {
|
|
|
167417
167686
|
"paymentWindowMinutes",
|
|
167418
167687
|
"extraColumns",
|
|
167419
167688
|
"kitchen",
|
|
167420
|
-
"discountMatrix"
|
|
167689
|
+
"discountMatrix",
|
|
167690
|
+
"templates"
|
|
167421
167691
|
],
|
|
167422
167692
|
tables: {
|
|
167423
167693
|
carts: {
|
|
@@ -167491,6 +167761,8 @@ const NAMES$52 = {
|
|
|
167491
167761
|
tenant: "tenant_id",
|
|
167492
167762
|
number: "number",
|
|
167493
167763
|
sequence: "sequence",
|
|
167764
|
+
template: "template_id",
|
|
167765
|
+
sourceTemplate: "source_template_id",
|
|
167494
167766
|
cart: "cart_id",
|
|
167495
167767
|
customer: "customer_id",
|
|
167496
167768
|
email: "email",
|
|
@@ -167537,7 +167809,9 @@ const NAMES$52 = {
|
|
|
167537
167809
|
"buyer",
|
|
167538
167810
|
"variantOf",
|
|
167539
167811
|
"variantLabel",
|
|
167540
|
-
"isSelected"
|
|
167812
|
+
"isSelected",
|
|
167813
|
+
"template",
|
|
167814
|
+
"sourceTemplate"
|
|
167541
167815
|
],
|
|
167542
167816
|
typed: ["status"]
|
|
167543
167817
|
},
|
|
@@ -167780,8 +168054,8 @@ ${policy("cartLines", `${tenantRead("cartLines")} or exists (select 1 from ${t("
|
|
|
167780
168054
|
create table if not exists ${t("orders")} (
|
|
167781
168055
|
${o("id")} uuid primary key default gen_random_uuid(),
|
|
167782
168056
|
${o("tenant")} ${ctx.idType} not null,
|
|
167783
|
-
${o("number")} text not null,
|
|
167784
|
-
${o("sequence")} bigint not null,
|
|
168057
|
+
${o("number")} text${orderTemplatesOn(ctx) ? "" : " not null"},
|
|
168058
|
+
${o("sequence")} bigint${orderTemplatesOn(ctx) ? "" : " not null"},${orderTemplatesOn(ctx) ? `\n ${templateColumnSql(ctx.colName("orders", "template"), ctx.of("templates").table("templates"), true)},${ctx.has("orders", "sourceTemplate") ? `\n ${sourceTemplateColumnSql(ctx.colName("orders", "sourceTemplate"), ctx.of("templates").table("templates"))},` : ""}` : ""}
|
|
167785
168059
|
${o("cart")} uuid unique references ${t("carts")} (${c("id")}) on delete set null,
|
|
167786
168060
|
${o("customer")} uuid references auth.users (id) on delete set null,${optionalColumn("orders", "email", (name) => `${name} text`)}
|
|
167787
168061
|
${o("status")} text not null default 'pending_payment',
|
|
@@ -168192,7 +168466,8 @@ const ORDERS = {
|
|
|
168192
168466
|
"state-machine",
|
|
168193
168467
|
"invoices",
|
|
168194
168468
|
"quotes",
|
|
168195
|
-
"contacts"
|
|
168469
|
+
"contacts",
|
|
168470
|
+
"templates"
|
|
168196
168471
|
],
|
|
168197
168472
|
target: "schema",
|
|
168198
168473
|
modes: ["managed", "custom"],
|
|
@@ -171956,11 +172231,11 @@ const PIPELINE_OUTCOMES = [
|
|
|
171956
172231
|
];
|
|
171957
172232
|
const NAME$2 = /^[a-z][a-z0-9_]{0,62}$/;
|
|
171958
172233
|
const VARIANT = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
171959
|
-
const COLUMN$
|
|
172234
|
+
const COLUMN$3 = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
171960
172235
|
const BRAND = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,99}$/;
|
|
171961
172236
|
function columnOf$1(where, value, fallback) {
|
|
171962
172237
|
if (value === void 0) return fallback;
|
|
171963
|
-
if (typeof value !== "string" || !COLUMN$
|
|
172238
|
+
if (typeof value !== "string" || !COLUMN$3.test(value)) throw new TypeError(`${where} must be a column name`);
|
|
171964
172239
|
return value;
|
|
171965
172240
|
}
|
|
171966
172241
|
function categoriesOf(where, value) {
|
|
@@ -172408,7 +172683,7 @@ declare
|
|
|
172408
172683
|
v_stage_name text;
|
|
172409
172684
|
v_claims text;
|
|
172410
172685
|
begin
|
|
172411
|
-
if tg_op = 'UPDATE' and new.${stage} is not distinct from old.${stage} and new.${pipeline} is not distinct from old.${pipeline} then${follow}
|
|
172686
|
+
${templateTriggerReturn(templateRowsOf(binding.subject.config)?.column, "new")} if tg_op = 'UPDATE' and new.${stage} is not distinct from old.${stage} and new.${pipeline} is not distinct from old.${pipeline} then${follow}
|
|
172412
172687
|
return new;
|
|
172413
172688
|
end if;
|
|
172414
172689
|
if new.${pipeline} is null then
|
|
@@ -172498,7 +172773,7 @@ as $$
|
|
|
172498
172773
|
declare
|
|
172499
172774
|
v_status text;
|
|
172500
172775
|
begin
|
|
172501
|
-
select case s.${c("stages", "category")} ${mapping} end into v_status
|
|
172776
|
+
${templateTriggerReturn(templateRowsOf(binding.subject.config)?.column, "null")} select case s.${c("stages", "category")} ${mapping} end into v_status
|
|
172502
172777
|
from ${t("stages")} s where s.${c("stages", "id")} = new.${stage};
|
|
172503
172778
|
if v_status is not null and v_status is distinct from new.${status}::text then
|
|
172504
172779
|
update ${subject.qualified} r set ${status} = (jsonb_populate_record(null::${subject.qualified}, jsonb_build_object(${sqlString(binding.status.column)}, v_status))).${status}
|
|
@@ -172539,7 +172814,7 @@ declare
|
|
|
172539
172814
|
v_current text;
|
|
172540
172815
|
v_stage ${t("stages")}.${c("stages", "id")}%type;
|
|
172541
172816
|
begin
|
|
172542
|
-
if new.${status} is not distinct from old.${status} or new.${pipeline} is null then
|
|
172817
|
+
${templateTriggerReturn(templateRowsOf(binding.subject.config)?.column, "null")} if new.${status} is not distinct from old.${status} or new.${pipeline} is null then
|
|
172543
172818
|
return null;
|
|
172544
172819
|
end if;
|
|
172545
172820
|
select case s.${c("stages", "category")} ${mapping} end into v_current
|
|
@@ -172906,7 +173181,7 @@ function readFunctions$1(idType, names, bindings) {
|
|
|
172906
173181
|
const board = byType("pipeline_board.subject_type", bindings, (binding) => {
|
|
172907
173182
|
const r = (column) => `r.${sqlIdent$1(column)}`;
|
|
172908
173183
|
const deleted = binding.subject.config.deletedAt;
|
|
172909
|
-
const live = deleted === void 0 ? "" : ` and ${r(deleted)} is null`;
|
|
173184
|
+
const live = `${deleted === void 0 ? "" : ` and ${r(deleted)} is null`}${excludeTemplates(binding.subject.config, "r")}`;
|
|
172910
173185
|
const owner = binding.owner === void 0 ? "" : ` and (pipeline_board.owner is null or ${r(binding.owner)} = pipeline_board.owner)`;
|
|
172911
173186
|
const money = binding.amount === void 0 || binding.currency === void 0 ? "null::text as currency, null::bigint as amount, null::numeric as weighted" : `${r(binding.currency)}::text as currency, ${r(binding.amount)}::bigint as amount,
|
|
172912
173187
|
${r(binding.amount)} * coalesce(${binding.probability === void 0 ? "null" : r(binding.probability)}, ${stage("probability")}, 0) / 100.0 as weighted`;
|
|
@@ -178760,6 +179035,50 @@ const JOBS = {
|
|
|
178760
179035
|
],
|
|
178761
179036
|
build: jobsSql
|
|
178762
179037
|
};
|
|
179038
|
+
// src/sql/modules/quotes-clone.ts
|
|
179039
|
+
/** `clone_quote`: a new quote from a quote or a template, with its lines. */
|
|
179040
|
+
function cloneQuoteSql(ctx, n) {
|
|
179041
|
+
const fn = n.fn;
|
|
179042
|
+
const t = n.t;
|
|
179043
|
+
const q = (column) => n.c("quotes", column);
|
|
179044
|
+
const lines = ctx.table("lines");
|
|
179045
|
+
const parent = ctx.col("lines", "parent");
|
|
179046
|
+
const parentKey = sqlString(ctx.colName("lines", "parent"));
|
|
179047
|
+
const on = quoteTemplatesOn(ctx);
|
|
179048
|
+
const templateExpr = on ? "case when coalesce(clone_quote.overrides, '{}'::jsonb) ? 'templateId' then clone_quote.overrides ->> 'templateId' else null end" : "null";
|
|
179049
|
+
const sourceExpr = on ? `case when v_src.${q("template")} is not null then v_src.${q("template")}::text else ${ctx.has("quotes", "sourceTemplate") ? `v_src.${q("sourceTemplate")}::text` : "null"} end` : "null";
|
|
179050
|
+
return [
|
|
179051
|
+
`create or replace function ${fn("clone_quote")}(source uuid, overrides jsonb default null)`,
|
|
179052
|
+
"returns jsonb",
|
|
179053
|
+
"language plpgsql",
|
|
179054
|
+
"security definer",
|
|
179055
|
+
"set search_path = ''",
|
|
179056
|
+
"as $$",
|
|
179057
|
+
"declare",
|
|
179058
|
+
` v_src ${t("quotes")};`,
|
|
179059
|
+
" v_created jsonb;",
|
|
179060
|
+
" v_id uuid;",
|
|
179061
|
+
"begin",
|
|
179062
|
+
` select * into v_src from ${t("quotes")} x where x.${q("id")} = clone_quote.source;`,
|
|
179063
|
+
" if not found then",
|
|
179064
|
+
` ${fail("QUOTE_NOT_FOUND", "no such quote", "P0002")}`,
|
|
179065
|
+
" end if;",
|
|
179066
|
+
` if not (${n.service} or ${ctx.scope.can(`v_src.${q("tenant")}`, n.write)}) then`,
|
|
179067
|
+
` ${fail("QUOTE_FORBIDDEN", "not allowed to change quotes")}`,
|
|
179068
|
+
" end if;",
|
|
179069
|
+
` ${ctx.hook("before_quote_clone", [["uuid", "clone_quote.source"], ["jsonb", "clone_quote.overrides"]])}`,
|
|
179070
|
+
` v_created := ${fn("create_quote")}(v_src.${q("tenant")}, jsonb_strip_nulls(jsonb_build_object('title', v_src.${q("title")}, 'currency', v_src.${q("currency")}, 'templateId', ${templateExpr}, 'sourceTemplateId', ${sourceExpr})) || (coalesce(clone_quote.overrides, '{}'::jsonb) - 'templateId') || jsonb_strip_nulls(jsonb_build_object('templateId', ${templateExpr}, 'sourceTemplateId', ${sourceExpr})), null);`,
|
|
179071
|
+
" v_id := (v_created ->> 'id')::uuid;",
|
|
179072
|
+
` insert into ${lines}`,
|
|
179073
|
+
` select (jsonb_populate_record(null::${lines}, to_jsonb(l) || jsonb_build_object('id', gen_random_uuid(), ${parentKey}, v_id))).*`,
|
|
179074
|
+
` from ${lines} l where l.${parent} = clone_quote.source;`,
|
|
179075
|
+
` ${ctx.hook("after_quote_clone", [["uuid", "v_id"]])}`,
|
|
179076
|
+
" return v_created;",
|
|
179077
|
+
"end;",
|
|
179078
|
+
"$$;",
|
|
179079
|
+
userGrant(`${fn("clone_quote")}(uuid, jsonb)`)
|
|
179080
|
+
].join("\n");
|
|
179081
|
+
}
|
|
178763
179082
|
// src/sql/modules/quotes-decisions.ts
|
|
178764
179083
|
/** The quote columns a customer sees of a published version. */
|
|
178765
179084
|
const PUBLISHED = [
|
|
@@ -178945,7 +179264,8 @@ begin
|
|
|
178945
179264
|
select * into v_row from ${t("quotes")} x where x.${q("id")} = decide_quote.quote and ${decideKey} for update;
|
|
178946
179265
|
if v_row.${q("id")} is null then
|
|
178947
179266
|
${fail("QUOTE_NOT_FOUND", "no such quote you can edit", "P0002")}
|
|
178948
|
-
end if
|
|
179267
|
+
end if;
|
|
179268
|
+
${quoteTemplatesOn(ctx) ? `if v_row.${q("template")} is not null then\n ${fail("QUOTE_TEMPLATE", "a template quote cannot be decided", "22023")}\n end if;` : ""}${answer({
|
|
178949
179269
|
name: "decide_quote",
|
|
178950
179270
|
by: "coalesce(nullif(trim(decide_quote.by), ''), nullif(trim(decide_quote.actor ->> 'name'), ''), decide_quote.actor ->> 'email')",
|
|
178951
179271
|
customer: false,
|
|
@@ -179248,6 +179568,8 @@ function quoteFunctions(ctx, n) {
|
|
|
179248
179568
|
"decidedIp",
|
|
179249
179569
|
"decidedUserAgent"
|
|
179250
179570
|
].filter(has).map((column) => `${q(column)} = null, `).join("");
|
|
179571
|
+
const templateColumns = quoteTemplatesOn(ctx) ? `, ${q("template")}${ctx.has("quotes", "sourceTemplate") ? `, ${q("sourceTemplate")}` : ""}` : "";
|
|
179572
|
+
const templateValues = quoteTemplatesOn(ctx) ? `, nullif(create_quote.attrs ->> 'templateId', '')::uuid${ctx.has("quotes", "sourceTemplate") ? ", nullif(create_quote.attrs ->> 'sourceTemplateId', '')::uuid" : ""}` : "";
|
|
179251
179573
|
const pricing = (attrs) => [
|
|
179252
179574
|
refuse(has("pricesIncludeTax"), `nullif(${attrs} ->> 'pricesIncludeTax', 'false')`, "PRICING", "prices_include_tax column"),
|
|
179253
179575
|
refuse(has("discountBps"), `nullif(${attrs} ->> 'discountBps', '0')`, "DISCOUNT", "discount column"),
|
|
@@ -179385,10 +179707,10 @@ begin
|
|
|
179385
179707
|
seq: q("number"),
|
|
179386
179708
|
tenant: q("tenant"),
|
|
179387
179709
|
prefix: n.prefix
|
|
179388
|
-
})}
|
|
179710
|
+
}, "now()", quoteTemplatesOn(ctx) ? { when: "nullif(create_quote.attrs ->> 'templateId', '') is null" } : {})}
|
|
179389
179711
|
begin
|
|
179390
179712
|
insert into ${t("quotes")} (${q("tenant")}, ${q("number")}, ${q("identifier")}, ${q("title")}${[...k.partyFields("company"), ...k.partyFields("contact")].map((field) => `, ${q(field)}`).join("")},
|
|
179391
|
-
${q("owner")}, ${q("currency")}, ${q("validUntil")}${also("terms")}${also("note")}${also("originType")}${also("originId")}${also("pricesIncludeTax")}${also("discountBps")}${also("discountAmount")}${also("depositBps")}${also("depositAmount")}${also("depositRequired")}${also("createdBy")}${insertExtraColumns(t("quotes"), n.extras, "coalesce(create_quote.attrs -> 'fields', '{}'::jsonb)").columns})
|
|
179713
|
+
${q("owner")}, ${q("currency")}, ${q("validUntil")}${also("terms")}${also("note")}${also("originType")}${also("originId")}${also("pricesIncludeTax")}${also("discountBps")}${also("discountAmount")}${also("depositBps")}${also("depositAmount")}${also("depositRequired")}${also("createdBy")}${templateColumns}${insertExtraColumns(t("quotes"), n.extras, "coalesce(create_quote.attrs -> 'fields', '{}'::jsonb)").columns})
|
|
179392
179714
|
values (${valueLines(" ", [
|
|
179393
179715
|
"create_quote.tenant",
|
|
179394
179716
|
"v_seq",
|
|
@@ -179402,7 +179724,7 @@ begin
|
|
|
179402
179724
|
present("depositAmount", "(create_quote.attrs ->> 'depositAmount')::bigint"),
|
|
179403
179725
|
present("depositRequired", "coalesce((create_quote.attrs ->> 'depositRequired')::boolean, false)"),
|
|
179404
179726
|
present("createdBy", "auth.uid()")
|
|
179405
|
-
])}${insertExtraColumns(t("quotes"), n.extras, "coalesce(create_quote.attrs -> 'fields', '{}'::jsonb)").values})
|
|
179727
|
+
])}${templateValues}${insertExtraColumns(t("quotes"), n.extras, "coalesce(create_quote.attrs -> 'fields', '{}'::jsonb)").values})
|
|
179406
179728
|
returning * into v_row;
|
|
179407
179729
|
exception when check_violation or invalid_text_representation or datetime_field_overflow or numeric_value_out_of_range then
|
|
179408
179730
|
${fail("QUOTE_ATTRS_INVALID", "a quote field has an invalid value", "22023")}
|
|
@@ -179505,6 +179827,7 @@ declare
|
|
|
179505
179827
|
v_version uuid;${k.workingCopy ? "\n v_linked boolean;" : ""}${holdsDeclare(ctx)}
|
|
179506
179828
|
begin
|
|
179507
179829
|
select * into v_row from ${t("quotes")} x where x.${q("id")} = send_quote.quote and ${editable("x", n.send)} for update;
|
|
179830
|
+
${quoteTemplatesOn(ctx) ? `if v_row.${q("template")} is not null then\n ${fail("QUOTE_TEMPLATE", "a template quote cannot be sent", "22023")}\n end if;` : ""}
|
|
179508
179831
|
if v_row.${q("id")} is null then
|
|
179509
179832
|
${fail("QUOTE_NOT_FOUND", "no such quote you can edit", "P0002")}
|
|
179510
179833
|
end if;
|
|
@@ -179617,7 +179940,7 @@ begin
|
|
|
179617
179940
|
perform set_config('better_supabase.transition_actor', '', true);
|
|
179618
179941
|
for v_row in
|
|
179619
179942
|
update ${t("quotes")} x set ${q("status")} = ${sv("expired")}, ${q("updatedAt")} = now()
|
|
179620
|
-
where ${st(`x.${q("status")}`, ["sent", "viewed"])} and x.${q("validUntil")} < current_date
|
|
179943
|
+
where ${st(`x.${q("status")}`, ["sent", "viewed"])} and x.${q("validUntil")} < current_date${quoteTemplatesOn(ctx) ? ` and x.${q("template")} is null` : ""}
|
|
179621
179944
|
returning *
|
|
179622
179945
|
loop
|
|
179623
179946
|
${record("quote.expired", "v_row")}
|
|
@@ -179627,7 +179950,7 @@ begin
|
|
|
179627
179950
|
end;
|
|
179628
179951
|
$$;
|
|
179629
179952
|
${serviceGrant(`${fn("expire_quotes")}()`)}
|
|
179630
|
-
${holdsSql(ctx, n)}${appTotalsGuard(ctx, n, k)}${fromDeal}`;
|
|
179953
|
+
${holdsSql(ctx, n)}${appTotalsGuard(ctx, n, k)}${fromDeal}${cloneQuoteSql(ctx, n)}`;
|
|
179631
179954
|
}
|
|
179632
179955
|
/**
|
|
179633
179956
|
* With `options.totals: "app"`, a trigger on the quotes table that refuses a
|
|
@@ -179889,7 +180212,8 @@ const NAMES$40 = {
|
|
|
179889
180212
|
permissions: {
|
|
179890
180213
|
read: "read",
|
|
179891
180214
|
write: "write"
|
|
179892
|
-
}
|
|
180215
|
+
},
|
|
180216
|
+
template: "template"
|
|
179893
180217
|
}
|
|
179894
180218
|
} },
|
|
179895
180219
|
events: EVENTS$8,
|
|
@@ -179897,7 +180221,9 @@ const NAMES$40 = {
|
|
|
179897
180221
|
"before_quote_send",
|
|
179898
180222
|
"after_quote_send",
|
|
179899
180223
|
"before_quote_accept",
|
|
179900
|
-
"after_quote_accept"
|
|
180224
|
+
"after_quote_accept",
|
|
180225
|
+
"before_quote_clone",
|
|
180226
|
+
"after_quote_clone"
|
|
179901
180227
|
],
|
|
179902
180228
|
options: [
|
|
179903
180229
|
"company",
|
|
@@ -179914,7 +180240,9 @@ const NAMES$40 = {
|
|
|
179914
180240
|
"resend",
|
|
179915
180241
|
"notifications",
|
|
179916
180242
|
"holds",
|
|
179917
|
-
"discountMatrix"
|
|
180243
|
+
"discountMatrix",
|
|
180244
|
+
"templates",
|
|
180245
|
+
"requireParty"
|
|
179918
180246
|
],
|
|
179919
180247
|
tables: {
|
|
179920
180248
|
quotes: {
|
|
@@ -179965,6 +180293,8 @@ const NAMES$40 = {
|
|
|
179965
180293
|
variantOf: "variant_of",
|
|
179966
180294
|
variantLabel: "variant_label",
|
|
179967
180295
|
isSelected: "is_selected",
|
|
180296
|
+
template: "template_id",
|
|
180297
|
+
sourceTemplate: "source_template_id",
|
|
179968
180298
|
createdBy: "created_by",
|
|
179969
180299
|
createdAt: "created_at",
|
|
179970
180300
|
updatedAt: "updated_at",
|
|
@@ -179997,6 +180327,8 @@ const NAMES$40 = {
|
|
|
179997
180327
|
"variantLabel",
|
|
179998
180328
|
"isSelected",
|
|
179999
180329
|
"createdBy",
|
|
180330
|
+
"template",
|
|
180331
|
+
"sourceTemplate",
|
|
180000
180332
|
"listTotal",
|
|
180001
180333
|
"discountTotal"
|
|
180002
180334
|
],
|
|
@@ -180108,14 +180440,15 @@ function tables$9(ctx, n) {
|
|
|
180108
180440
|
const constraints = [
|
|
180109
180441
|
`unique (${q("tenant")}, ${q("number")}, ${q("revision")})`,
|
|
180110
180442
|
...company === "pair" ? [`check ((${q("companyType")} is null) = (${q("companyId")} is null))`] : [],
|
|
180111
|
-
...origin ? [`check ((${q("originType")} is null) = (${q("originId")} is null))`] : []
|
|
180443
|
+
...origin ? [`check ((${q("originType")} is null) = (${q("originId")} is null))`] : [],
|
|
180444
|
+
...quoteTemplatesOn(ctx) && ctx.flag("requireParty", false) && ctx.has("quotes", "companyId") ? [`check (${q("template")} is not null or ${q("companyId")} is not null)`] : []
|
|
180112
180445
|
];
|
|
180113
180446
|
return `
|
|
180114
180447
|
create table if not exists ${t("quotes")} (
|
|
180115
180448
|
${q("id")} uuid primary key default gen_random_uuid(),
|
|
180116
|
-
${q("tenant")} ${ctx.idType} not null,
|
|
180117
|
-
${q("number")} bigint not null,
|
|
180118
|
-
${q("identifier")} text not null,
|
|
180449
|
+
${q("tenant")} ${ctx.idType} not null,${quoteTemplatesOn(ctx) ? `\n ${templateColumnSql(ctx.colName("quotes", "template"), ctx.of("templates").table("templates"), true)},${ctx.has("quotes", "sourceTemplate") ? `\n ${sourceTemplateColumnSql(ctx.colName("quotes", "sourceTemplate"), ctx.of("templates").table("templates"))},` : ""}` : ""}
|
|
180450
|
+
${q("number")} bigint${quoteTemplatesOn(ctx) ? "" : " not null"},
|
|
180451
|
+
${q("identifier")} text${quoteTemplatesOn(ctx) ? "" : " not null"},
|
|
180119
180452
|
${q("revision")} integer not null default 1,
|
|
180120
180453
|
${q("title")} text not null check (length(${q("title")}) between 1 and 300),${column("companyType", "text")}${column("companyId", "text")}${column("contactType", "text")}${column("contactId", "text")}
|
|
180121
180454
|
${q("owner")} uuid,
|
|
@@ -180133,7 +180466,13 @@ create table if not exists ${t("quotes")} (
|
|
|
180133
180466
|
);
|
|
180134
180467
|
${added}create index if not exists ${ctx.naming.rename("quotes_tenant_status_idx")} on ${t("quotes")} (${q("tenant")}, ${q("status")}, ${q("createdAt")} desc);${ctx.has("quotes", "variantOf") ? `\ncreate index if not exists ${ctx.naming.rename("quotes_variant_idx")} on ${t("quotes")} (${q("variantOf")}) where ${q("variantOf")} is not null;` : ""}${origin ? `\ncreate index if not exists ${ctx.naming.rename("quotes_origin_idx")} on ${t("quotes")} (${q("originType")}, ${q("originId")});` : ""}
|
|
180135
180468
|
${addExtraColumns(t("quotes"), n.extras)}${appUniqueIndex(ctx, "quotes", ["tokenHash"])}
|
|
180136
|
-
${lockModuleTable(ctx, "quotes", { read: true })}
|
|
180469
|
+
${lockModuleTable(ctx, "quotes", { read: true })}${quoteTemplatesOn(ctx) ? `\n${templateGuardSql({
|
|
180470
|
+
fn: ctx.fn("quote_template_guard"),
|
|
180471
|
+
trigger: ctx.trigger("quote_template"),
|
|
180472
|
+
table: t("quotes"),
|
|
180473
|
+
column: ctx.colName("quotes", "template"),
|
|
180474
|
+
hint: "QUOTE_TEMPLATE_IMMUTABLE"
|
|
180475
|
+
})}\n${triggerGrant(`${ctx.fn("quote_template_guard")}()`)}` : ""}
|
|
180137
180476
|
${renderPolicy(policy$1({
|
|
180138
180477
|
table: t("quotes"),
|
|
180139
180478
|
name: ctx.naming.rename("quotes_read"),
|
|
@@ -180301,6 +180640,11 @@ function contract$36(ctx) {
|
|
|
180301
180640
|
],
|
|
180302
180641
|
returns: "jsonb"
|
|
180303
180642
|
},
|
|
180643
|
+
{
|
|
180644
|
+
name: "clone_quote",
|
|
180645
|
+
args: ["uuid", "jsonb"],
|
|
180646
|
+
returns: "jsonb"
|
|
180647
|
+
},
|
|
180304
180648
|
{
|
|
180305
180649
|
name: "update_quote",
|
|
180306
180650
|
args: ["uuid", "jsonb"],
|
|
@@ -180448,7 +180792,8 @@ const QUOTES = {
|
|
|
180448
180792
|
"automations",
|
|
180449
180793
|
"orders",
|
|
180450
180794
|
"invoices",
|
|
180451
|
-
"inventory"
|
|
180795
|
+
"inventory",
|
|
180796
|
+
"templates"
|
|
180452
180797
|
],
|
|
180453
180798
|
target: "schema",
|
|
180454
180799
|
modes: ["managed", "custom"],
|
|
@@ -180465,7 +180810,26 @@ const QUOTES = {
|
|
|
180465
180810
|
names: NAMES$40,
|
|
180466
180811
|
contract: contract$36,
|
|
180467
180812
|
build: build$41,
|
|
180468
|
-
contributes: {
|
|
180813
|
+
contributes: {
|
|
180814
|
+
imports: quoteImportTargets,
|
|
180815
|
+
templates: (own) => {
|
|
180816
|
+
if (!quoteTemplatesOn(own)) return [];
|
|
180817
|
+
const { schema, name } = own.tableName("quotes");
|
|
180818
|
+
return [{
|
|
180819
|
+
type: "quote",
|
|
180820
|
+
storage: "rows",
|
|
180821
|
+
subject: "quote",
|
|
180822
|
+
clone: own.fn("clone_quote"),
|
|
180823
|
+
table: `${schema}.${name}`,
|
|
180824
|
+
templateColumn: own.colName("quotes", "template"),
|
|
180825
|
+
idColumn: own.colName("quotes", "id"),
|
|
180826
|
+
children: [{
|
|
180827
|
+
table: `${schema}.${own.tableName("lines").name}`,
|
|
180828
|
+
parent: own.colName("lines", "parent")
|
|
180829
|
+
}]
|
|
180830
|
+
}];
|
|
180831
|
+
}
|
|
180832
|
+
},
|
|
180469
180833
|
data: (ctx) => shippedAutomation(ctx, QUOTE_TO_ORDER, {
|
|
180470
180834
|
module: "orders",
|
|
180471
180835
|
entity: "order"
|
|
@@ -184000,7 +184364,7 @@ const NAMES$34 = {
|
|
|
184000
184364
|
};
|
|
184001
184365
|
/** `options.extraColumns`, added to a managed reminders table. */
|
|
184002
184366
|
const extrasOf$2 = (ctx) => ctx.extraColumns("reminders");
|
|
184003
|
-
const COLUMN$
|
|
184367
|
+
const COLUMN$2 = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
184004
184368
|
/**
|
|
184005
184369
|
* `blocks.reminders.on`, every registered subject when unset. `at` names the
|
|
184006
184370
|
* subject's timestamp column that a reminder without a rule counts back from.
|
|
@@ -184009,7 +184373,7 @@ function subjectsOf(ctx) {
|
|
|
184009
184373
|
const subjects = subjectsOption(ctx, ["at"]);
|
|
184010
184374
|
for (const [type, subject] of subjects) {
|
|
184011
184375
|
const at = subject.extra["at"];
|
|
184012
|
-
if (at !== void 0 && (typeof at !== "string" || !COLUMN$
|
|
184376
|
+
if (at !== void 0 && (typeof at !== "string" || !COLUMN$2.test(at))) throw new TypeError(`blocks.${ctx.instance}.on.${type}.at must be a column name, such as due_at`);
|
|
184013
184377
|
}
|
|
184014
184378
|
return subjects;
|
|
184015
184379
|
}
|
|
@@ -189433,6 +189797,7 @@ function watchedColumns(subject) {
|
|
|
189433
189797
|
own ? config.search?.description : void 0,
|
|
189434
189798
|
own ? config.search?.exclude : void 0,
|
|
189435
189799
|
config.deletedAt,
|
|
189800
|
+
typeof config.template === "string" ? config.template : config.template?.column,
|
|
189436
189801
|
...[...(config.url ?? "").matchAll(/\{([^}]*)\}/g)].map((m) => m[1])
|
|
189437
189802
|
];
|
|
189438
189803
|
return [...new Set(names.filter((name) => name !== void 0))];
|
|
@@ -189446,6 +189811,8 @@ function refreshBranch(subject, described) {
|
|
|
189446
189811
|
const bodySql = body.length === 0 ? "null" : `nullif(concat_ws(E'\\n', ${body.map((name) => `${source}.${sqlIdent$1(name)}::text`).join(", ")}), '')`;
|
|
189447
189812
|
const url = config.url === void 0 ? "null" : urlExpression(config.url, "s");
|
|
189448
189813
|
const deleted = config.deletedAt === void 0 ? "" : `\n and s.${sqlIdent$1(config.deletedAt)} is null`;
|
|
189814
|
+
const template = typeof config.template === "string" ? config.template : config.template?.column;
|
|
189815
|
+
const templated = template === void 0 ? "" : `\n and s.${sqlIdent$1(template)} is null`;
|
|
189449
189816
|
const exclude = config.search?.exclude;
|
|
189450
189817
|
const excluded = exclude === void 0 ? "" : `\n and (${source}.${sqlIdent$1(exclude)} is null or ${source}.${sqlIdent$1(exclude)}::text = 'false')`;
|
|
189451
189818
|
const description = config.search?.description;
|
|
@@ -189454,7 +189821,7 @@ function refreshBranch(subject, described) {
|
|
|
189454
189821
|
select s.${subject.tenant ?? sqlIdent$1("organization_id")}, ${source}.${sqlIdent$1(title)}::text, ${bodySql}, ${url}${described ? `, ${description === void 0 ? "null" : `${source}.${sqlIdent$1(description)}::text`}` : ""}
|
|
189455
189822
|
into v_tenant, v_title, v_body, v_url${described ? ", v_description" : ""}
|
|
189456
189823
|
from ${subject.qualified} s${join}
|
|
189457
|
-
where ${registeredIdMatches(subject, "search_refresh.subject_id")}${deleted}${excluded};
|
|
189824
|
+
where ${registeredIdMatches(subject, "search_refresh.subject_id")}${deleted}${templated}${excluded};
|
|
189458
189825
|
v_found := found;`;
|
|
189459
189826
|
}
|
|
189460
189827
|
/**
|
|
@@ -190964,7 +191331,7 @@ function matchingIds(ctx, n) {
|
|
|
190964
191331
|
const matches = ctx.of("automations").fn("rule_matches");
|
|
190965
191332
|
const branch = (subject) => {
|
|
190966
191333
|
const deletedAt = subject.config.deletedAt;
|
|
190967
|
-
const live = deletedAt === void 0 ? "" : ` and s.${sqlIdent$1(deletedAt)} is null`;
|
|
191334
|
+
const live = `${deletedAt === void 0 ? "" : ` and s.${sqlIdent$1(deletedAt)} is null`}${excludeTemplates(subject.config, "s")}`;
|
|
190968
191335
|
return `if v_row.${n.s("subjectType")} = ${sqlString(subject.type)} then
|
|
190969
191336
|
select coalesce(array_agg(x.id order by x.id), '{}') into v_ids from (
|
|
190970
191337
|
select s.${subject.id}::text as id from ${subject.qualified} s
|
|
@@ -198731,7 +199098,7 @@ const NAMES$17 = {
|
|
|
198731
199098
|
}
|
|
198732
199099
|
};
|
|
198733
199100
|
const TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
198734
|
-
const COLUMN = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
199101
|
+
const COLUMN$1 = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
198735
199102
|
function businessHours(ctx) {
|
|
198736
199103
|
const raw = ctx.option("businessHours") ?? {};
|
|
198737
199104
|
const where = "blocks.sla.options.businessHours";
|
|
@@ -198765,10 +199132,10 @@ function bindings(ctx) {
|
|
|
198765
199132
|
if (!isRecord$1(entry)) throw new TypeError(`${where} must be an object`);
|
|
198766
199133
|
const status = entry["status"];
|
|
198767
199134
|
const priority = entry["priority"];
|
|
198768
|
-
if (typeof status !== "string" || !COLUMN.test(status)) throw new TypeError(`${where}.status must be a column name`);
|
|
198769
|
-
if (priority !== void 0 && (typeof priority !== "string" || !COLUMN.test(priority))) throw new TypeError(`${where}.priority must be a column name`);
|
|
199135
|
+
if (typeof status !== "string" || !COLUMN$1.test(status)) throw new TypeError(`${where}.status must be a column name`);
|
|
199136
|
+
if (priority !== void 0 && (typeof priority !== "string" || !COLUMN$1.test(priority))) throw new TypeError(`${where}.priority must be a column name`);
|
|
198770
199137
|
const owner = entry["owner"];
|
|
198771
|
-
if (owner !== void 0 && (typeof owner !== "string" || !COLUMN.test(owner))) throw new TypeError(`${where}.owner must be a column name`);
|
|
199138
|
+
if (owner !== void 0 && (typeof owner !== "string" || !COLUMN$1.test(owner))) throw new TypeError(`${where}.owner must be a column name`);
|
|
198772
199139
|
const list = (key) => {
|
|
198773
199140
|
const value = entry[key] ?? [];
|
|
198774
199141
|
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) throw new TypeError(`${where}.${key} must be a list of statuses`);
|
|
@@ -201199,9 +201566,21 @@ function machine(name, entry, registry, naming) {
|
|
|
201199
201566
|
order,
|
|
201200
201567
|
flags,
|
|
201201
201568
|
...workflow === void 0 ? {} : { workflow },
|
|
201202
|
-
...history === void 0 ? {} : { history }
|
|
201569
|
+
...history === void 0 ? {} : { history },
|
|
201570
|
+
...templateOf(table, registry)
|
|
201203
201571
|
};
|
|
201204
201572
|
}
|
|
201573
|
+
/** The template column of the subject whose table this machine numbers. */
|
|
201574
|
+
function templateOf(table, registry) {
|
|
201575
|
+
const bare = table.includes(".") ? table.slice(table.lastIndexOf(".") + 1) : table;
|
|
201576
|
+
for (const entry of Object.values(registry)) {
|
|
201577
|
+
const entryBare = entry.table.includes(".") ? entry.table.slice(entry.table.lastIndexOf(".") + 1) : entry.table;
|
|
201578
|
+
if (entry.table !== table && entryBare !== bare) continue;
|
|
201579
|
+
const column = templateRowsOf(entry)?.column;
|
|
201580
|
+
if (column !== void 0) return { template: column };
|
|
201581
|
+
}
|
|
201582
|
+
return {};
|
|
201583
|
+
}
|
|
201205
201584
|
function edgesOf(value, where) {
|
|
201206
201585
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${where} must be an object of status to statuses`);
|
|
201207
201586
|
const edges = {};
|
|
@@ -201619,7 +201998,10 @@ security definer
|
|
|
201619
201998
|
set search_path = ''
|
|
201620
201999
|
as $$
|
|
201621
202000
|
${declare}begin
|
|
201622
|
-
if
|
|
202001
|
+
${item.template === void 0 ? "" : `if new.${sqlIdent$1(item.template)} is not null then
|
|
202002
|
+
return new;
|
|
202003
|
+
end if;
|
|
202004
|
+
`}if tg_op = 'INSERT' then
|
|
201623
202005
|
${insert}
|
|
201624
202006
|
return new;
|
|
201625
202007
|
end if;
|
|
@@ -205824,7 +206206,11 @@ const NAMES$10 = {
|
|
|
205824
206206
|
"before_template_apply",
|
|
205825
206207
|
"after_template_apply"
|
|
205826
206208
|
],
|
|
205827
|
-
options: [
|
|
206209
|
+
options: [
|
|
206210
|
+
"extraColumns",
|
|
206211
|
+
"brand",
|
|
206212
|
+
"types"
|
|
206213
|
+
],
|
|
205828
206214
|
tables: {
|
|
205829
206215
|
templates: {
|
|
205830
206216
|
name: "templates",
|
|
@@ -206347,6 +206733,378 @@ $$;
|
|
|
206347
206733
|
${serviceGrant(`${fn("finish_template_occurrence")}(uuid, timestamptz, uuid)`)}
|
|
206348
206734
|
`;
|
|
206349
206735
|
}
|
|
206736
|
+
// src/sql/modules/templates-types.ts
|
|
206737
|
+
const TYPE$1 = /^[a-z][a-z0-9_.-]{0,63}$/;
|
|
206738
|
+
const COLUMN = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
206739
|
+
const TABLE$2 = /^[a-z_][a-z0-9_]{0,62}(\.[a-z_][a-z0-9_]{0,62})?$/;
|
|
206740
|
+
const CALL$1 = /^[a-z_"][a-z0-9_".]*(\.[a-z_"][a-z0-9_"]*)+$/;
|
|
206741
|
+
/**
|
|
206742
|
+
* The template types in force: the app's `options.types`, then contributions
|
|
206743
|
+
* for types the app did not name. An empty registry keeps today's free-form
|
|
206744
|
+
* types.
|
|
206745
|
+
*/
|
|
206746
|
+
function templateTypes(ctx) {
|
|
206747
|
+
const configured = configuredTypes(ctx);
|
|
206748
|
+
const named = new Set(configured.map((item) => item.type));
|
|
206749
|
+
const contributed = uniqueContributions("templates", ctx.contributions("templates"), (item) => item.type).filter((item) => !named.has(item.type)).map((item) => normalize("contributes.templates", item));
|
|
206750
|
+
return [...configured, ...contributed];
|
|
206751
|
+
}
|
|
206752
|
+
function configuredTypes(ctx) {
|
|
206753
|
+
const raw = ctx.option("types");
|
|
206754
|
+
if (raw === void 0) return [];
|
|
206755
|
+
if (!isRecord$1(raw)) throw new TypeError("blocks.templates.options.types must be an object");
|
|
206756
|
+
return Object.entries(raw).map(([type, entry]) => {
|
|
206757
|
+
if (!isRecord$1(entry)) throw new TypeError(`blocks.templates.options.types.${type} must be an object`);
|
|
206758
|
+
return normalize(`blocks.templates.options.types.${type}`, {
|
|
206759
|
+
type,
|
|
206760
|
+
...entry
|
|
206761
|
+
});
|
|
206762
|
+
});
|
|
206763
|
+
}
|
|
206764
|
+
function normalize(where, entry) {
|
|
206765
|
+
if (!TYPE$1.test(entry.type)) throw new TypeError(`${where}: "${entry.type}" is not a template type`);
|
|
206766
|
+
if (entry.storage !== "body" && entry.storage !== "rows") throw new TypeError(`${where}.storage must be "body" or "rows"`);
|
|
206767
|
+
if (entry.storage === "rows") {
|
|
206768
|
+
if (entry.table === void 0 || !TABLE$2.test(entry.table)) throw new TypeError(`${where}.table must be "schema.table"`);
|
|
206769
|
+
if (entry.templateColumn === void 0 || !COLUMN.test(entry.templateColumn)) throw new TypeError(`${where}.templateColumn must be a column name`);
|
|
206770
|
+
if (entry.clone === void 0 || !CALL$1.test(entry.clone)) throw new TypeError(`${where}.clone must be a schema-qualified function`);
|
|
206771
|
+
}
|
|
206772
|
+
const idColumn = entry.idColumn ?? "id";
|
|
206773
|
+
if (!COLUMN.test(idColumn)) throw new TypeError(`${where}.idColumn must be a column name`);
|
|
206774
|
+
if (entry.extension !== void 0 && !TABLE$2.test(entry.extension)) throw new TypeError(`${where}.extension must be "schema.table"`);
|
|
206775
|
+
return {
|
|
206776
|
+
...entry,
|
|
206777
|
+
type: entry.type,
|
|
206778
|
+
storage: entry.storage,
|
|
206779
|
+
idColumn,
|
|
206780
|
+
...entry.children === void 0 ? {} : { children: entry.children.map((child, index) => childOf(where, index, child)) },
|
|
206781
|
+
...entry.rules === void 0 ? {} : { rules: rulesOf(where, entry.rules) }
|
|
206782
|
+
};
|
|
206783
|
+
}
|
|
206784
|
+
function childOf(where, index, child) {
|
|
206785
|
+
const at = `${where}.children[${String(index)}]`;
|
|
206786
|
+
if (!TABLE$2.test(child.table) || !COLUMN.test(child.parent)) throw new TypeError(`${at} must be { table: "schema.table", parent }`);
|
|
206787
|
+
return child;
|
|
206788
|
+
}
|
|
206789
|
+
function rulesOf(where, rules) {
|
|
206790
|
+
for (const [index, date] of (rules.dates ?? []).entries()) if (!COLUMN.test(date.column) || !COLUMN.test(date.days) || date.from !== "now" && !COLUMN.test(date.from)) throw new TypeError(`${where}.rules.dates[${String(index)}] must name a column, "now" or a column, and a settings key`);
|
|
206791
|
+
for (const name of rules.variables ?? []) if (!COLUMN.test(name)) throw new TypeError(`${where}.rules.variables must be column names`);
|
|
206792
|
+
return rules;
|
|
206793
|
+
}
|
|
206794
|
+
// src/sql/modules/templates-rows.ts
|
|
206795
|
+
/**
|
|
206796
|
+
* The rows-template functions: a type check for `save_template`, and
|
|
206797
|
+
* `instantiate_template`, `pack_template`, `unpack_template`, `clone_row` and
|
|
206798
|
+
* `template_table`. Empty when no type is registered and nothing else asks,
|
|
206799
|
+
* except `clone_row` and `template_table`, which the `@bsb template` tag
|
|
206800
|
+
* calls.
|
|
206801
|
+
*/
|
|
206802
|
+
function templateRowsSql(ctx) {
|
|
206803
|
+
const types = templateTypes(ctx);
|
|
206804
|
+
const fn = (name) => ctx.fn(name);
|
|
206805
|
+
return `${cloneRowSql(fn)}${templateTableSql(ctx, fn)}${types.length === 0 ? "" : typedSql(ctx, types, fn)}`;
|
|
206806
|
+
}
|
|
206807
|
+
/** The statement `save_template` runs to refuse an unregistered type. */
|
|
206808
|
+
function templateTypeCheck(ctx) {
|
|
206809
|
+
const types = templateTypes(ctx);
|
|
206810
|
+
if (types.length === 0) return "";
|
|
206811
|
+
const known = types.map((item) => sqlString(item.type)).join(", ");
|
|
206812
|
+
const settings = settingsCheck(ctx, types);
|
|
206813
|
+
return `
|
|
206814
|
+
if save_template.template_id is null and save_template.type not in (${known}) then
|
|
206815
|
+
${fail("TEMPLATE_TYPE_UNKNOWN", "That template type is not registered", "22023")}
|
|
206816
|
+
end if;${settings}`;
|
|
206817
|
+
}
|
|
206818
|
+
function settingsCheck(ctx, types) {
|
|
206819
|
+
const checked = types.filter((item) => item.settings !== void 0);
|
|
206820
|
+
if (checked.length === 0 || !ctx.installed("jsonb-schemas")) return "";
|
|
206821
|
+
const branches = checked.map((item) => `when ${sqlString(item.type)} then ${sqlString(JSON.stringify(item.settings))}::json`).join(" ");
|
|
206822
|
+
return `
|
|
206823
|
+
if save_template.settings is not null then
|
|
206824
|
+
declare
|
|
206825
|
+
v_schema json := case coalesce(save_template.type, v_row.${ctx.col("templates", "type")}) ${branches} else null end;
|
|
206826
|
+
v_errors jsonb;
|
|
206827
|
+
begin
|
|
206828
|
+
if v_schema is not null then
|
|
206829
|
+
v_errors := extensions.jsonschema_validation_errors(v_schema, save_template.settings::json);
|
|
206830
|
+
if v_errors <> '[]'::jsonb then
|
|
206831
|
+
${fail("TEMPLATE_SETTINGS_INVALID", "settings does not match this template type", "23514")}
|
|
206832
|
+
end if;
|
|
206833
|
+
end if;
|
|
206834
|
+
end;
|
|
206835
|
+
end if;`;
|
|
206836
|
+
}
|
|
206837
|
+
function typedSql(ctx, types, fn) {
|
|
206838
|
+
const id = ctx.idType;
|
|
206839
|
+
const rows = types.filter((item) => item.storage === "rows");
|
|
206840
|
+
return `${instantiateSql(ctx, types, fn, id)}${packSql(ctx, rows, fn)}${unpackSql(ctx, rows, fn, id)}`;
|
|
206841
|
+
}
|
|
206842
|
+
function instantiateSql(ctx, types, fn, id) {
|
|
206843
|
+
const branches = types.map((item) => item.storage === "body" ? `when ${sqlString(item.type)} then
|
|
206844
|
+
return ${fn("template_apply_target")}(instantiate_template.template, instantiate_template.tenant);` : `when ${sqlString(item.type)} then
|
|
206845
|
+
${rowsBranch(ctx, item)}`).join("\n ");
|
|
206846
|
+
return `
|
|
206847
|
+
-- Creates a record from a template: a body template returns its published
|
|
206848
|
+
-- version, a rows template clones its root row into a live record. Writes
|
|
206849
|
+
-- template_applications either way. templates.apply in tenant.
|
|
206850
|
+
create or replace function ${fn("instantiate_template")}(template uuid, tenant ${id}, overrides jsonb default null)
|
|
206851
|
+
returns jsonb
|
|
206852
|
+
language plpgsql
|
|
206853
|
+
security definer
|
|
206854
|
+
set search_path = ''
|
|
206855
|
+
as $$
|
|
206856
|
+
declare
|
|
206857
|
+
v_tpl record;
|
|
206858
|
+
v_version record;
|
|
206859
|
+
v_source uuid;
|
|
206860
|
+
v_overrides jsonb;
|
|
206861
|
+
v_created jsonb;
|
|
206862
|
+
v_type text;
|
|
206863
|
+
v_subject text;
|
|
206864
|
+
v_id text;
|
|
206865
|
+
v_key text;
|
|
206866
|
+
v_value text;
|
|
206867
|
+
begin
|
|
206868
|
+
if instantiate_template.tenant is null then
|
|
206869
|
+
${fail("TEMPLATE_INVALID", "Applying a template needs a tenant", "22023")}
|
|
206870
|
+
end if;
|
|
206871
|
+
select * into v_tpl from ${ctx.table("templates")} x where x.${ctx.col("templates", "id")} = instantiate_template.template;
|
|
206872
|
+
if not found then
|
|
206873
|
+
${fail("TEMPLATE_NOT_FOUND", "No such template", "P0002")}
|
|
206874
|
+
end if;
|
|
206875
|
+
v_type := v_tpl.${ctx.col("templates", "type")};
|
|
206876
|
+
select * into v_version from ${ctx.table("versions")} y
|
|
206877
|
+
where y.${ctx.col("versions", "template")} = v_tpl.${ctx.col("templates", "id")} and y.${ctx.col("versions", "publishedAt")} is not null
|
|
206878
|
+
order by y.${ctx.col("versions", "version")} desc limit 1;
|
|
206879
|
+
if not found then
|
|
206880
|
+
${fail("TEMPLATE_NOT_PUBLISHED", "This template has no published version", "P0002")}
|
|
206881
|
+
end if;
|
|
206882
|
+
v_overrides := coalesce(instantiate_template.overrides, '{}'::jsonb);
|
|
206883
|
+
${applyRules(ctx, types)}
|
|
206884
|
+
case v_type
|
|
206885
|
+
${branches}
|
|
206886
|
+
else
|
|
206887
|
+
${fail("TEMPLATE_TYPE_UNKNOWN", "That template type is not registered", "22023")}
|
|
206888
|
+
end case;
|
|
206889
|
+
return ${fn("record_template_application")}(v_tpl.${ctx.col("templates", "id")}, v_version.${ctx.col("versions", "id")}, instantiate_template.tenant, v_subject, v_id);
|
|
206890
|
+
end;
|
|
206891
|
+
$$;
|
|
206892
|
+
${userGrant(`${fn("instantiate_template")}(uuid, ${id}, jsonb)`)}
|
|
206893
|
+
`;
|
|
206894
|
+
}
|
|
206895
|
+
function rowsBranch(ctx, item) {
|
|
206896
|
+
const table = quoted(item.table ?? "");
|
|
206897
|
+
return `select ${sqlIdent$1(item.idColumn)} into v_source from ${table} r where r.${sqlIdent$1(item.templateColumn ?? "template_id")} = ${`v_tpl.${ctx.col("templates", "id")}`};
|
|
206898
|
+
if not found then
|
|
206899
|
+
${fail("TEMPLATE_EMPTY", "This template has no record to copy", "P0002")}
|
|
206900
|
+
end if;
|
|
206901
|
+
v_created := ${item.clone}(v_source, v_overrides);
|
|
206902
|
+
v_subject := ${sqlString(item.subject ?? item.type)};
|
|
206903
|
+
v_id := v_created ->> 'id';`;
|
|
206904
|
+
}
|
|
206905
|
+
/** Relative dates and `{{name}}` substitution, from the type's rules. */
|
|
206906
|
+
function applyRules(ctx, types) {
|
|
206907
|
+
const settings = ctx.has("templates", "settings") ? `v_tpl.${ctx.col("templates", "settings")}` : "'{}'::jsonb";
|
|
206908
|
+
return types.flatMap((item) => {
|
|
206909
|
+
const dates = item.rules?.dates ?? [];
|
|
206910
|
+
const variables = item.rules?.variables ?? [];
|
|
206911
|
+
if (dates.length === 0 && variables.length === 0) return [];
|
|
206912
|
+
const dated = dates.map((date) => {
|
|
206913
|
+
const base = date.from === "now" ? "now()" : `coalesce((v_overrides ->> ${sqlString(date.from)})::timestamptz, now())`;
|
|
206914
|
+
return `v_overrides := v_overrides || jsonb_build_object(${sqlString(date.column)}, to_char(${base} + make_interval(days => coalesce((${settings} ->> ${sqlString(date.days)})::integer, 0)), 'YYYY-MM-DD"T"HH24:MI:SSOF'));`;
|
|
206915
|
+
}).join("\n ");
|
|
206916
|
+
const substituted = variables.map((column) => `for v_key, v_value in select * from jsonb_each_text(coalesce(v_overrides -> 'variables', '{}'::jsonb)) loop
|
|
206917
|
+
v_overrides := jsonb_set(v_overrides, array[${sqlString(column)}], to_jsonb(replace(coalesce(v_overrides ->> ${sqlString(column)}, ''), '{{' || v_key || '}}', v_value)));
|
|
206918
|
+
end loop;`.replace("for v_key, v_value in select * from jsonb_each_text", "for v_key, v_value in select key, value from jsonb_each_text")).join("\n ");
|
|
206919
|
+
return `if v_type = ${sqlString(item.type)} then
|
|
206920
|
+
${dated}
|
|
206921
|
+
${substituted}
|
|
206922
|
+
end if;`;
|
|
206923
|
+
}).join("\n ");
|
|
206924
|
+
}
|
|
206925
|
+
function packSql(ctx, rows, fn) {
|
|
206926
|
+
if (rows.length === 0) return "";
|
|
206927
|
+
const branches = rows.map((item) => `when ${sqlString(item.type)} then\n ${packBranch(ctx, item)}`).join("\n ");
|
|
206928
|
+
return `
|
|
206929
|
+
-- Snapshots a rows template (its root row, children and extension) into the
|
|
206930
|
+
-- template's draft version, which publish_template_version then publishes.
|
|
206931
|
+
create or replace function ${fn("pack_template")}(template uuid)
|
|
206932
|
+
returns jsonb
|
|
206933
|
+
language plpgsql
|
|
206934
|
+
security definer
|
|
206935
|
+
set search_path = ''
|
|
206936
|
+
as $$
|
|
206937
|
+
declare
|
|
206938
|
+
v_tpl record;
|
|
206939
|
+
v_root record;
|
|
206940
|
+
v_body jsonb;
|
|
206941
|
+
begin
|
|
206942
|
+
select * into v_tpl from ${ctx.table("templates")} x where x.${ctx.col("templates", "id")} = pack_template.template;
|
|
206943
|
+
if not found then
|
|
206944
|
+
${fail("TEMPLATE_NOT_FOUND", "No such template", "P0002")}
|
|
206945
|
+
end if;
|
|
206946
|
+
case v_tpl.${ctx.col("templates", "type")}
|
|
206947
|
+
${branches}
|
|
206948
|
+
else
|
|
206949
|
+
${fail("TEMPLATE_TYPE_UNKNOWN", "That template type is not packed from rows", "22023")}
|
|
206950
|
+
end case;
|
|
206951
|
+
return ${fn("save_template_draft")}(v_tpl.${ctx.col("templates", "id")}, v_body);
|
|
206952
|
+
end;
|
|
206953
|
+
$$;
|
|
206954
|
+
${userGrant(`${fn("pack_template")}(uuid)`)}
|
|
206955
|
+
`;
|
|
206956
|
+
}
|
|
206957
|
+
function packBranch(ctx, item) {
|
|
206958
|
+
const table = quoted(item.table ?? "");
|
|
206959
|
+
const id = sqlIdent$1(item.idColumn);
|
|
206960
|
+
const template = sqlIdent$1(item.templateColumn ?? "");
|
|
206961
|
+
const templateId = `v_tpl.${ctx.col("templates", "id")}`;
|
|
206962
|
+
const children = (item.children ?? []).map((child) => `coalesce((select jsonb_agg(to_jsonb(c)) from ${quoted(child.table)} c where c.${sqlIdent$1(child.parent)} = v_root.${id}), '[]'::jsonb)`).join(", ");
|
|
206963
|
+
const extension = item.extension === void 0 ? "null" : `coalesce((select to_jsonb(e) from ${quoted(item.extension)} e where e.template_id = ${templateId}), 'null'::jsonb)`;
|
|
206964
|
+
return `select * into v_root from ${table} r where r.${template} = ${templateId};
|
|
206965
|
+
if not found then
|
|
206966
|
+
${fail("TEMPLATE_EMPTY", "This template has no record to pack", "P0002")}
|
|
206967
|
+
end if;
|
|
206968
|
+
v_body := jsonb_build_object('table', ${sqlString(item.table ?? "")}, 'row', to_jsonb(v_root), 'children', jsonb_build_array(${children === "" ? "" : children}), 'extension', ${extension});`;
|
|
206969
|
+
}
|
|
206970
|
+
function unpackSql(ctx, rows, fn, id) {
|
|
206971
|
+
if (rows.length === 0) return "";
|
|
206972
|
+
const branches = rows.map((item) => `when ${sqlString(item.type)} then
|
|
206973
|
+
perform ${fn("clone_row")}(${sqlString(item.table ?? "")}::regclass, (v_body -> 'row' ->> 'id')::uuid, jsonb_build_object('template_id', unpack_template.template));`).join("\n ");
|
|
206974
|
+
return `
|
|
206975
|
+
-- Materializes a packed body back into tenant rows owned by template.
|
|
206976
|
+
create or replace function ${fn("unpack_template")}(template uuid, version uuid, tenant ${id})
|
|
206977
|
+
returns uuid
|
|
206978
|
+
language plpgsql
|
|
206979
|
+
security definer
|
|
206980
|
+
set search_path = ''
|
|
206981
|
+
as $$
|
|
206982
|
+
declare
|
|
206983
|
+
v_tpl record;
|
|
206984
|
+
v_body jsonb;
|
|
206985
|
+
begin
|
|
206986
|
+
select * into v_tpl from ${ctx.table("templates")} x where x.${ctx.col("templates", "id")} = unpack_template.template;
|
|
206987
|
+
if not found then
|
|
206988
|
+
${fail("TEMPLATE_NOT_FOUND", "No such template", "P0002")}
|
|
206989
|
+
end if;
|
|
206990
|
+
select y.${ctx.col("versions", "body")} into v_body from ${ctx.table("versions")} y
|
|
206991
|
+
where y.${ctx.col("versions", "id")} = unpack_template.version and y.${ctx.col("versions", "template")} = v_tpl.${ctx.col("templates", "id")};
|
|
206992
|
+
if v_body is null or v_body -> 'row' is null then
|
|
206993
|
+
${fail("TEMPLATE_NOT_PUBLISHED", "That version has no packed rows", "P0002")}
|
|
206994
|
+
end if;
|
|
206995
|
+
case v_tpl.${ctx.col("templates", "type")}
|
|
206996
|
+
${branches}
|
|
206997
|
+
else
|
|
206998
|
+
${fail("TEMPLATE_TYPE_UNKNOWN", "That template type is not unpacked into rows", "22023")}
|
|
206999
|
+
end case;
|
|
207000
|
+
return unpack_template.template;
|
|
207001
|
+
end;
|
|
207002
|
+
$$;
|
|
207003
|
+
${userGrant(`${fn("unpack_template")}(uuid, uuid, ${id})`)}
|
|
207004
|
+
`;
|
|
207005
|
+
}
|
|
207006
|
+
/**
|
|
207007
|
+
* Copies one row and the rows that reference it, clearing `template_id` unless
|
|
207008
|
+
* overrides sets it, and recording `source_template_id` when the source is a
|
|
207009
|
+
* template. Used by app tables tagged `@bsb template`.
|
|
207010
|
+
*/
|
|
207011
|
+
function cloneRowSql(fn) {
|
|
207012
|
+
return `
|
|
207013
|
+
create or replace function ${fn("clone_row")}(target regclass, source uuid, overrides jsonb default null)
|
|
207014
|
+
returns uuid
|
|
207015
|
+
language plpgsql
|
|
207016
|
+
security definer
|
|
207017
|
+
set search_path = ''
|
|
207018
|
+
as $$
|
|
207019
|
+
declare
|
|
207020
|
+
v_row jsonb;
|
|
207021
|
+
v_new uuid := gen_random_uuid();
|
|
207022
|
+
v_template uuid;
|
|
207023
|
+
v_cols text;
|
|
207024
|
+
v_vals text;
|
|
207025
|
+
v_child record;
|
|
207026
|
+
begin
|
|
207027
|
+
execute format('select to_jsonb(t) from %s t where t.id = $1', target) into v_row using source;
|
|
207028
|
+
if v_row is null then
|
|
207029
|
+
${fail("TEMPLATE_NOT_FOUND", "No such row", "P0002")}
|
|
207030
|
+
end if;
|
|
207031
|
+
v_template := nullif(v_row ->> 'template_id', '')::uuid;
|
|
207032
|
+
v_row := v_row || coalesce(overrides, '{}'::jsonb) || jsonb_build_object('id', v_new);
|
|
207033
|
+
if not (coalesce(overrides, '{}'::jsonb) ? 'template_id') then
|
|
207034
|
+
v_row := v_row || jsonb_build_object('template_id', null);
|
|
207035
|
+
end if;
|
|
207036
|
+
if v_template is not null and not (coalesce(overrides, '{}'::jsonb) ? 'source_template_id') then
|
|
207037
|
+
v_row := v_row || jsonb_build_object('source_template_id', v_template);
|
|
207038
|
+
end if;
|
|
207039
|
+
select string_agg(format('%I', key), ', '), string_agg(format('%L', value), ', ')
|
|
207040
|
+
into v_cols, v_vals
|
|
207041
|
+
from jsonb_each_text(v_row);
|
|
207042
|
+
execute format('insert into %s (%s) values (%s)', target, v_cols, v_vals);
|
|
207043
|
+
for v_child in
|
|
207044
|
+
select c.conrelid::regclass as child, a.attname as parent
|
|
207045
|
+
from pg_catalog.pg_constraint c
|
|
207046
|
+
join pg_catalog.pg_attribute a on a.attrelid = c.conrelid and a.attnum = c.conkey[1]
|
|
207047
|
+
where c.confrelid = target and c.contype = 'f' and c.conrelid <> target
|
|
207048
|
+
loop
|
|
207049
|
+
execute format(
|
|
207050
|
+
'insert into %s select (jsonb_populate_record(null::%s, to_jsonb(x) || jsonb_build_object(%L, $1, ''id'', gen_random_uuid()))).* from %s x where x.%I = $2',
|
|
207051
|
+
v_child.child, v_child.child, v_child.parent, v_child.child, v_child.parent
|
|
207052
|
+
) using v_new, source;
|
|
207053
|
+
end loop;
|
|
207054
|
+
return v_new;
|
|
207055
|
+
end;
|
|
207056
|
+
$$;
|
|
207057
|
+
${serviceGrant(`${fn("clone_row")}(regclass, uuid, jsonb)`)}
|
|
207058
|
+
`;
|
|
207059
|
+
}
|
|
207060
|
+
/** Adds the template columns and the immutability trigger to an app table. */
|
|
207061
|
+
function templateTableSql(ctx, fn) {
|
|
207062
|
+
const templates = ctx.table("templates");
|
|
207063
|
+
return `
|
|
207064
|
+
create or replace function ${fn("template_table")}(target regclass)
|
|
207065
|
+
returns void
|
|
207066
|
+
language plpgsql
|
|
207067
|
+
security definer
|
|
207068
|
+
set search_path = ''
|
|
207069
|
+
as $$
|
|
207070
|
+
begin
|
|
207071
|
+
execute format('alter table %s add column if not exists template_id uuid unique references ${templates} (id) on delete cascade', target);
|
|
207072
|
+
execute format('alter table %s add column if not exists source_template_id uuid references ${templates} (id) on delete set null', target);
|
|
207073
|
+
execute format('drop trigger if exists bsb_template_row on %s', target);
|
|
207074
|
+
execute format('create trigger bsb_template_row before update of template_id on %s for each row execute function ${fn("template_row_guard")}()', target);
|
|
207075
|
+
end;
|
|
207076
|
+
$$;
|
|
207077
|
+
${serviceGrant(`${fn("template_table")}(regclass)`)}
|
|
207078
|
+
|
|
207079
|
+
create or replace function ${fn("template_row_guard")}()
|
|
207080
|
+
returns trigger
|
|
207081
|
+
language plpgsql
|
|
207082
|
+
set search_path = ''
|
|
207083
|
+
as $$
|
|
207084
|
+
begin
|
|
207085
|
+
if new.template_id is distinct from old.template_id then
|
|
207086
|
+
${fail("TEMPLATE_IMMUTABLE", "A row cannot change between a template and a live record", "23514")}
|
|
207087
|
+
end if;
|
|
207088
|
+
return new;
|
|
207089
|
+
end;
|
|
207090
|
+
$$;
|
|
207091
|
+
${triggerGrant(`${fn("template_row_guard")}()`)}
|
|
207092
|
+
`;
|
|
207093
|
+
}
|
|
207094
|
+
/** After a fork, materialize a rows template's packed body into tenant rows. */
|
|
207095
|
+
function forkUnpackSql(ctx) {
|
|
207096
|
+
const rows = templateTypes(ctx).filter((item) => item.storage === "rows");
|
|
207097
|
+
if (rows.length === 0) return "";
|
|
207098
|
+
const known = rows.map((item) => sqlString(item.type)).join(", ");
|
|
207099
|
+
return `
|
|
207100
|
+
if v_row.${ctx.col("templates", "type")} in (${known}) then
|
|
207101
|
+
perform ${ctx.fn("unpack_template")}(v_row.${ctx.col("templates", "id")}, (select y.${ctx.col("versions", "id")} from ${ctx.table("versions")} y where y.${ctx.col("versions", "template")} = v_row.${ctx.col("templates", "id")} and y.${ctx.col("versions", "version")} = 1), fork_template.tenant);
|
|
207102
|
+
end if;`;
|
|
207103
|
+
}
|
|
207104
|
+
function quoted(table) {
|
|
207105
|
+
const [schema, name] = table.includes(".") ? table.split(".") : ["public", table];
|
|
207106
|
+
return `${sqlIdent$1(schema ?? "public")}.${sqlIdent$1(name ?? table)}`;
|
|
207107
|
+
}
|
|
206350
207108
|
// src/sql/modules/templates-workflows.ts
|
|
206351
207109
|
/**
|
|
206352
207110
|
* The workflows a template starts on the record it creates, with the
|
|
@@ -206821,7 +207579,7 @@ begin
|
|
|
206821
207579
|
end if;
|
|
206822
207580
|
if save_template.template_id is null and (save_template.type is null or save_template.type !~ ${TYPE_PATTERN}) then
|
|
206823
207581
|
${fail("TEMPLATE_INVALID", "type must be lower-case letters, digits, dots, dashes or underscores", "22023")}
|
|
206824
|
-
end if
|
|
207582
|
+
end if;${templateTypeCheck(ctx)}
|
|
206825
207583
|
if save_template.template_id is null and save_template.name is null then
|
|
206826
207584
|
${fail("TEMPLATE_INVALID", "A template needs a name", "22023")}
|
|
206827
207585
|
end if;
|
|
@@ -207080,7 +207838,7 @@ begin
|
|
|
207080
207838
|
returning * into v_row;
|
|
207081
207839
|
insert into ${ver} (${cv("template")}, ${cv("version")}, ${cv("body")}, ${cv("hash")}, ${cv("publishedAt")}${also("versions", "createdBy", () => `, ${cv("createdBy")}`)})
|
|
207082
207840
|
values (v_row.${ct("id")}, 1, v_version.${cv("body")}, v_version.${cv("hash")}, now()${also("versions", "createdBy", () => ", (select auth.uid())")});
|
|
207083
|
-
${workflows?.forkCopy ?? ""}
|
|
207841
|
+
${workflows?.forkCopy ?? ""}${forkUnpackSql(ctx)}
|
|
207084
207842
|
return ${templateJson("v_row")};
|
|
207085
207843
|
end;
|
|
207086
207844
|
$$;
|
|
@@ -207235,7 +207993,7 @@ ${workflows?.functions ?? ""}${recurringParts(ctx, {
|
|
|
207235
207993
|
mayManage,
|
|
207236
207994
|
visible: brands.visible,
|
|
207237
207995
|
system
|
|
207238
|
-
})}`;
|
|
207996
|
+
})}${templateRowsSql(ctx)}`;
|
|
207239
207997
|
}
|
|
207240
207998
|
function contract$9(ctx) {
|
|
207241
207999
|
return [
|
|
@@ -207349,7 +208107,54 @@ function contract$9(ctx) {
|
|
|
207349
208107
|
returns: "jsonb"
|
|
207350
208108
|
}
|
|
207351
208109
|
] : [],
|
|
207352
|
-
...recurringContract(ctx)
|
|
208110
|
+
...recurringContract(ctx),
|
|
208111
|
+
...templateTypes(ctx).some((item) => item.storage === "rows") ? [
|
|
208112
|
+
{
|
|
208113
|
+
name: "instantiate_template",
|
|
208114
|
+
args: [
|
|
208115
|
+
"uuid",
|
|
208116
|
+
"{id}",
|
|
208117
|
+
"jsonb"
|
|
208118
|
+
],
|
|
208119
|
+
returns: "jsonb"
|
|
208120
|
+
},
|
|
208121
|
+
{
|
|
208122
|
+
name: "pack_template",
|
|
208123
|
+
args: ["uuid"],
|
|
208124
|
+
returns: "jsonb"
|
|
208125
|
+
},
|
|
208126
|
+
{
|
|
208127
|
+
name: "unpack_template",
|
|
208128
|
+
args: [
|
|
208129
|
+
"uuid",
|
|
208130
|
+
"uuid",
|
|
208131
|
+
"{id}"
|
|
208132
|
+
],
|
|
208133
|
+
returns: "uuid"
|
|
208134
|
+
}
|
|
208135
|
+
] : templateTypes(ctx).length === 0 ? [] : [{
|
|
208136
|
+
name: "instantiate_template",
|
|
208137
|
+
args: [
|
|
208138
|
+
"uuid",
|
|
208139
|
+
"{id}",
|
|
208140
|
+
"jsonb"
|
|
208141
|
+
],
|
|
208142
|
+
returns: "jsonb"
|
|
208143
|
+
}],
|
|
208144
|
+
{
|
|
208145
|
+
name: "clone_row",
|
|
208146
|
+
args: [
|
|
208147
|
+
"regclass",
|
|
208148
|
+
"uuid",
|
|
208149
|
+
"jsonb"
|
|
208150
|
+
],
|
|
208151
|
+
returns: "uuid"
|
|
208152
|
+
},
|
|
208153
|
+
{
|
|
208154
|
+
name: "template_table",
|
|
208155
|
+
args: ["regclass"],
|
|
208156
|
+
returns: "void"
|
|
208157
|
+
}
|
|
207353
208158
|
];
|
|
207354
208159
|
}
|
|
207355
208160
|
const TEMPLATES = {
|
|
@@ -226352,7 +227157,7 @@ function declaredForeignKeys(files, schemas) {
|
|
|
226352
227157
|
for (const file of files) {
|
|
226353
227158
|
const text = withoutComments(file.text);
|
|
226354
227159
|
const found = [];
|
|
226355
|
-
for (const match of text.matchAll(TABLE$
|
|
227160
|
+
for (const match of text.matchAll(TABLE$3)) {
|
|
226356
227161
|
const table = qualified$10(match[1]);
|
|
226357
227162
|
const open = match.index + match[0].length - 1;
|
|
226358
227163
|
const close = closingParen(text, open);
|
|
@@ -226547,7 +227352,7 @@ function declaredCheckValues(files, schemas) {
|
|
|
226547
227352
|
const found = [];
|
|
226548
227353
|
for (const file of files) {
|
|
226549
227354
|
const text = withoutComments(file.text);
|
|
226550
|
-
for (const match of text.matchAll(TABLE$
|
|
227355
|
+
for (const match of text.matchAll(TABLE$3)) {
|
|
226551
227356
|
const table = qualified$10(match[1]);
|
|
226552
227357
|
if (schemas !== void 0 && !schemas.includes(table.slice(0, table.indexOf(".")))) continue;
|
|
226553
227358
|
const open = match.index + match[0].length - 1;
|
|
@@ -226757,22 +227562,6 @@ function writtenValues(sql, table, column) {
|
|
|
226757
227562
|
triggerWrites(text, target, column, found);
|
|
226758
227563
|
return found;
|
|
226759
227564
|
}
|
|
226760
|
-
// src/sql/audit-actions.ts
|
|
226761
|
-
/**
|
|
226762
|
-
* The categories module actions are audited under. An adopted log with its own
|
|
226763
|
-
* names maps them through `blocks.audit.options.values.category`.
|
|
226764
|
-
*/
|
|
226765
|
-
const AUDIT_CATEGORIES = [
|
|
226766
|
-
"membership",
|
|
226767
|
-
"access",
|
|
226768
|
-
"security",
|
|
226769
|
-
"configuration",
|
|
226770
|
-
"billing",
|
|
226771
|
-
"data",
|
|
226772
|
-
"ai",
|
|
226773
|
-
"integration",
|
|
226774
|
-
"read"
|
|
226775
|
-
];
|
|
226776
227565
|
// src/sql/shared-roles.ts
|
|
226777
227566
|
/**
|
|
226778
227567
|
* Why a roles table that holds both tenant and platform roles (the tenant
|
|
@@ -227320,7 +228109,8 @@ const TABLE_FEATURES = [
|
|
|
227320
228109
|
"lifecycle",
|
|
227321
228110
|
"append-only",
|
|
227322
228111
|
"function-writes",
|
|
227323
|
-
"chain"
|
|
228112
|
+
"chain",
|
|
228113
|
+
"template"
|
|
227324
228114
|
];
|
|
227325
228115
|
function isTableFeature(value) {
|
|
227326
228116
|
return TABLE_FEATURES.some((feature) => feature === value);
|
|
@@ -227390,6 +228180,7 @@ function featureStatement(feature, schema, table) {
|
|
|
227390
228180
|
if (feature === "append-only") return `select better_supabase.append_only('${schema}.${table}');`;
|
|
227391
228181
|
if (feature === "function-writes") return `select better_supabase.function_writes('${schema}.${table}');`;
|
|
227392
228182
|
if (feature === "chain") return `select better_supabase.chain('${schema}.${table}');`;
|
|
228183
|
+
if (feature === "template") return `select better_supabase.template_table('${schema}.${table}'::regclass);`;
|
|
227393
228184
|
if (feature === "events") return `select better_supabase.track_events('${schema}.${table}');`;
|
|
227394
228185
|
if (feature === "audit-reads") return `create or replace function ${schema}.read_${table}(p_id text, p_purpose text default null)
|
|
227395
228186
|
returns setof ${schema}.${table}
|
|
@@ -227416,4 +228207,4 @@ function setFeatureStatement(sql, schema, table, feature, enabled) {
|
|
|
227416
228207
|
if (enabled) return present ? sql : `${sql.replace(/\n*$/u, "")}\n\n${statement}\n`;
|
|
227417
228208
|
return present ? sql.replace(`\n${statement}`, "").replace(statement, "") : sql;
|
|
227418
228209
|
}
|
|
227419
|
-
export {
|
|
228210
|
+
export { scopePolicyName as $, adoptedColumnProblems as A, appValues as At, moduleBody as B, declaredViews as Bt, writtenValues as C, currentBlockName as Ct, tenantsQuery as D, isBlockSqlIdType as Dt, blockReadRoles as E, MODULE_ID_TYPES as Et, blockTables as F, declaredColumnTypes as Ft, appTablePolicyNotes as G, renderBlocks as H, policyGrants as Ht, seedDefaultsFunctions as I, declaredIndexes as It, moduleDataDir as J, declaredPolicies as K, moduleLayout as L, declaredTableColumns as Lt, adoptedViews as M, AUDIT_CATEGORIES as Mt, moduleWritesText as N, BLOCK_OPTION_SCHEMAS as Nt, expiredFlagsQuery as O, moduleIdType as Ot, instanceFunctions as P, addedColumnTypes as Pt, appTablesFiles as Q, entityRenamePlan as R, declaredTables as Rt, sharedRolesProblems as S, BLOCK_RENAMES as St, declaredCheckValues as T, renamedBlock as Tt, moduleDeprecations as U, rlsTables as Ut, moduleTopics as V, extensionSchema as Vt, upgradePlan as W, auditRegistrations as Wt, APP_TABLES_MARKER as X, moduleFilePaths as Y, APP_TABLES_MODULE as Z, renderRule as _, SECRET_COLUMNS as _t, setTableFeature as a, sameBlockFile as at, compileReadSet as b, sameTenantTrigger as bt, commentOnTableSql as c, modulePermissionKeys as ct, setBsbTag as d, moduleSource as dt, renderAutoEmbedding as et, POLICY_FUNCTIONS as f, resolveBlocks as ft, readRulePolicies as g, resolveExposeColumns as gt, policyFunctionsSql as h, excludedColumns as ht, setFeatureStatement as i, moduleFileVersion as it, adoptedTables as j, checkedValueMaps as jt, sameTenantLayout as k, contractSignature as kt, formatBsbComment as l, moduleSchemaExtensions as lt, isRule as m, TENANT_SCOPE_POLICY as mt, createsTable as n, blockFileState as nt, tableFeatures as o, moduleEventTriggers as ot, disallowedPolicyCalls as p, TENANT_SCOPE_NAMES as pt, widenedCommands as q, isTableFeature as r, isModuleDataFile as rt, tableTagComments as s, moduleHidingColumns as st, TABLE_FEATURES as t, blockSqlVersion as tt, parseBsbComment as u, SQL_MODULES as ut, renderRulePolicy as v, dataExportPlan as vt, checkValues as w, formerBlockName as wt, compileReadSets as x, migrationOptionUses as xt, rulePolicy as y, sameTenantColumn as yt, customContracts as z, declaredUpdatedAtTriggers as zt };
|