ekwo-os 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/README.md +873 -0
  2. package/dist/args.d.ts +57 -0
  3. package/dist/args.d.ts.map +1 -0
  4. package/dist/args.js +134 -0
  5. package/dist/args.js.map +1 -0
  6. package/dist/assets/expected-objects.json +9432 -0
  7. package/dist/assets/migrations/20260911120000_core_companies.sql +260 -0
  8. package/dist/assets/migrations/20260911120100_accounts_journals.sql +211 -0
  9. package/dist/assets/migrations/20260911120200_contacts.sql +90 -0
  10. package/dist/assets/migrations/20260911120300_taxes.sql +146 -0
  11. package/dist/assets/migrations/20260911120400_entries.sql +338 -0
  12. package/dist/assets/migrations/20260911120500_documents.sql +279 -0
  13. package/dist/assets/migrations/20260911120600_payments_reconciliation.sql +251 -0
  14. package/dist/assets/migrations/20260911120700_bank.sql +178 -0
  15. package/dist/assets/migrations/20260911120800_analytics_attachments.sql +128 -0
  16. package/dist/assets/migrations/20260911120900_post_document.sql +279 -0
  17. package/dist/assets/migrations/20260911121000_reporting.sql +235 -0
  18. package/dist/assets/migrations/20260911121100_country_templates.sql +226 -0
  19. package/dist/assets/migrations/20260911121200_fec.sql +71 -0
  20. package/dist/assets/migrations/20260911130000_instance.sql +77 -0
  21. package/dist/assets/migrations/20260911130100_instance_members.sql +224 -0
  22. package/dist/assets/migrations/20260911140000_instance_admins.sql +112 -0
  23. package/dist/assets/migrations/20260911160000_tax_posting_templates_unique.sql +17 -0
  24. package/dist/assets/migrations/20260911170000_document_amount_paid.sql +82 -0
  25. package/dist/assets/migrations/20260911173000_post_payment.sql +122 -0
  26. package/dist/assets/migrations/20260911173100_sequence_counters_under_rls.sql +84 -0
  27. package/dist/assets/migrations/20260911183000_country_journal_defaults.sql +143 -0
  28. package/dist/assets/migrations/20260911193853_line_account_defaults.sql +274 -0
  29. package/dist/assets/migrations/20260911195054_products.sql +221 -0
  30. package/dist/assets/migrations/20260911210131_anon_surface.sql +85 -0
  31. package/dist/assets/migrations/20260912074712_country_packs.sql +318 -0
  32. package/dist/assets/migrations/20260912080311_report_code_and_region.sql +198 -0
  33. package/dist/assets/migrations/20260912081014_pack_certification_maintained.sql +31 -0
  34. package/dist/assets/migrations/20260912081015_pack_certification_backfill.sql +16 -0
  35. package/dist/assets/migrations/20260912090407_tax_report_boxes.sql +329 -0
  36. package/dist/assets/migrations/20260912091917_tax_on_base_value.sql +25 -0
  37. package/dist/assets/migrations/20260912091918_tax_engine_columns.sql +776 -0
  38. package/dist/assets/migrations/20260912094412_opening_and_closing.sql +759 -0
  39. package/dist/assets/migrations/20260912095825_charts_of_accounts.sql +326 -0
  40. package/dist/assets/migrations/20260912100412_financial_statements.sql +632 -0
  41. package/dist/assets/migrations/20260912104719_one_formula_evaluator.sql +209 -0
  42. package/dist/assets/migrations/20260912105720_entry_kind_appropriation.sql +26 -0
  43. package/dist/assets/migrations/20260912105721_appropriation_entry_kind.sql +444 -0
  44. package/dist/assets/migrations/20260912111751_document_rules.sql +274 -0
  45. package/dist/assets/migrations/20260912112132_cash_basis_vat_and_fx.sql +1189 -0
  46. package/dist/assets/migrations/20260913074512_modules.sql +493 -0
  47. package/dist/assets/migrations/20260913075903_asset_disposal_roles.sql +47 -0
  48. package/dist/assets/migrations/20260913083216_capabilities.sql +637 -0
  49. package/dist/assets/migrations/20260913083901_company_invitations.sql +262 -0
  50. package/dist/assets/migrations/20260913084402_user_preferences.sql +376 -0
  51. package/dist/assets/migrations/20260913084847_company_profile.sql +261 -0
  52. package/dist/assets/migrations/20260913085436_numbering_reads_the_pack.sql +235 -0
  53. package/dist/assets/migrations/20260913085932_api_keys.sql +303 -0
  54. package/dist/assets/migrations/20260913090216_fiscal_year_bounds.sql +159 -0
  55. package/dist/assets/migrations/20260913092527_entries_import.sql +219 -0
  56. package/dist/assets/migrations/20260913101536_null_safe_guards.sql +188 -0
  57. package/dist/assets/migrations/20260913102115_installer_is_named.sql +462 -0
  58. package/dist/assets/migrations/20260913102758_no_currency_default.sql +138 -0
  59. package/dist/assets/migrations/20260913103355_cash_basis_needs_a_box.sql +453 -0
  60. package/dist/assets/migrations/20260913104014_aged_balance_named_group.sql +79 -0
  61. package/dist/assets/migrations/20260913104232_foreign_key_indexes.sql +144 -0
  62. package/dist/assets/migrations/20260913105120_declared_no_reader.sql +41 -0
  63. package/dist/assets/migrations/20260913111407_pack_languages.sql +223 -0
  64. package/dist/assets/migrations/20260913112233_schema_comments_for_a_reader.sql +27 -0
  65. package/dist/assets/migrations/20260913114535_fec_opening_balances.sql +307 -0
  66. package/dist/assets/migrations/20260914103412_audit_log.sql +509 -0
  67. package/dist/assets/migrations/20260914111907_pack_upgrade.sql +428 -0
  68. package/dist/assets/migrations/20260914120500_rounding_reads_the_currency.sql +206 -0
  69. package/dist/assets/migrations/20260914121200_amounts_round_at_the_currency.sql +2403 -0
  70. package/dist/assets/migrations/20260914134325_schema_version_0_2_0.sql +36 -0
  71. package/dist/assets/migrations/20260914143915_accounts_in_use.sql +428 -0
  72. package/dist/assets/migrations/20260914144731_account_code_frozen.sql +99 -0
  73. package/dist/assets/migrations/20260914151207_schema_grants_its_own_rights.sql +284 -0
  74. package/dist/assets/migrations/20260914152840_pack_upgrade_records_its_own_line.sql +237 -0
  75. package/dist/assets/migrations/20260914163943_declaration_periodicity.sql +349 -0
  76. package/dist/assets/migrations/20260915094000_foreign_services_received.sql +37 -0
  77. package/dist/assets/migrations/20260915094500_mentions_read_a_foreign_service.sql +72 -0
  78. package/dist/assets/migrations/20260915153000_document_shares.sql +568 -0
  79. package/dist/assets/migrations/20260915160000_ec_sales_list.sql +181 -0
  80. package/dist/assets/migrations/20260915161842_pack_sources.sql +56 -0
  81. package/dist/assets/migrations/20260915170500_schema_version_0_3_0.sql +45 -0
  82. package/dist/assets/migrations/20260915174500_a_vat_category_is_a_code.sql +177 -0
  83. package/dist/assets/migrations/20260915180000_document_rule_references.sql +85 -0
  84. package/dist/assets/migrations/20260915181000_territories.sql +342 -0
  85. package/dist/assets/migrations/20260915181500_ec_sales_list_reads_the_territories.sql +222 -0
  86. package/dist/assets/migrations/20260915182000_intracom_triangular.sql +53 -0
  87. package/dist/assets/migrations/20260915182500_a_triangular_supply_says_reverse_charge.sql +99 -0
  88. package/dist/assets/migrations/20260915191200_a_document_knows_its_language.sql +633 -0
  89. package/dist/assets/migrations/20260915195000_a_price_that_holds_its_tax.sql +649 -0
  90. package/dist/assets/migrations/20260915200000_a_posting_names_its_boxes.sql +1004 -0
  91. package/dist/assets/migrations/20260916094500_a_company_files_more_than_one_declaration.sql +795 -0
  92. package/dist/assets/migrations/20260916103000_a_ledger_line_names_its_posting.sql +902 -0
  93. package/dist/assets/migrations/20260916123000_a_vocabulary_for_a_tax_that_is_not_a_vat.sql +144 -0
  94. package/dist/assets/migrations/20260916124000_a_box_can_be_a_rate_of_a_box.sql +525 -0
  95. package/dist/assets/migrations/20260916125000_a_tax_follows_the_territory.sql +1318 -0
  96. package/dist/assets/migrations/20260916126000_a_tax_point_and_its_exception.sql +1211 -0
  97. package/dist/assets/migrations/20260917090000_a_counterparty_that_learns.sql +561 -0
  98. package/dist/assets/migrations/20260917120000_what_the_money_pays.sql +545 -0
  99. package/dist/assets/migrations/20260917150000_a_filing_is_a_row.sql +488 -0
  100. package/dist/assets/migrations/20260917170000_when_it_is_due.sql +194 -0
  101. package/dist/assets/migrations/20260917180000_a_box_is_a_number_and_a_kind.sql +213 -0
  102. package/dist/assets/migrations/20260917190000_what_a_declaration_owes.sql +486 -0
  103. package/dist/assets/migrations/20260917200000_what_moved_after_it_went.sql +227 -0
  104. package/dist/assets/migrations/20260918090000_a_form_names_its_file.sql +27 -0
  105. package/dist/assets/migrations/20260918110000_a_deposit_and_what_came_back.sql +286 -0
  106. package/dist/assets/migrations/20260918113741_a_fourth_preset_is_named.sql +9 -0
  107. package/dist/assets/migrations/20260918113807_a_client_reads_and_hands_over.sql +96 -0
  108. package/dist/assets/migrations/20260918114322_two_definer_functions_check_their_caller.sql +75 -0
  109. package/dist/assets/migrations/20260918130000_every_company_somebody_keeps.sql +177 -0
  110. package/dist/assets/migrations/20260918140000_a_session_nobody_prepared.sql +40 -0
  111. package/dist/assets/migrations/20260918141107_a_line_keeps_the_tax_it_was_posted_with.sql +256 -0
  112. package/dist/assets/migrations/20260918141342_a_company_has_an_electronic_address.sql +66 -0
  113. package/dist/assets/migrations/20260918141605_an_invoice_reads_whole_from_the_views.sql +313 -0
  114. package/dist/assets/migrations/20260918141627_a_policy_asks_once.sql +132 -0
  115. package/dist/assets/migrations/20260918143352_a_suggestion_reads_the_words_once.sql +204 -0
  116. package/dist/assets/migrations/20260918143417_a_reference_of_the_caller_and_a_rehearsal.sql +115 -0
  117. package/dist/assets/migrations/20260918150712_a_company_leaves_with_its_books.sql +1119 -0
  118. package/dist/assets/migrations/20260918150931_a_statement_is_imported_once.sql +654 -0
  119. package/dist/assets/migrations/20260918161204_a_posted_document_does_not_move.sql +437 -0
  120. package/dist/assets/migrations/20260918161538_a_posted_entry_does_not_move.sql +252 -0
  121. package/dist/assets/migrations/20260918171946_an_entry_is_posted_by_post_entry.sql +289 -0
  122. package/dist/assets/migrations/20260918174312_schema_version_0_4_0.sql +53 -0
  123. package/dist/assets/modules/assets/module.json +13 -0
  124. package/dist/assets/modules/assets/supabase/migrations/20260913081447_assets.sql +1190 -0
  125. package/dist/assets/modules/assets/supabase/migrations/20260913104234_foreign_key_indexes.sql +47 -0
  126. package/dist/assets/modules/assets/supabase/migrations/20260913104500_assets_capabilities.sql +145 -0
  127. package/dist/assets/modules/assets/supabase/migrations/20260914122100_assets_round_at_the_currency.sql +564 -0
  128. package/dist/assets/modules/assets/supabase/migrations/20260914145012_assets_accounts_in_use.sql +37 -0
  129. package/dist/assets/modules/assets/supabase/migrations/20260914151530_assets_grants_its_own_rights.sql +63 -0
  130. package/dist/assets/modules/assets/supabase/migrations/20260918113912_assets_client_reads.sql +20 -0
  131. package/dist/assets/modules/assets/supabase/migrations/20260918150801_assets_leave_with_the_company.sql +41 -0
  132. package/dist/assets/modules/budgets/module.json +12 -0
  133. package/dist/assets/modules/budgets/supabase/migrations/20260913083012_budgets.sql +210 -0
  134. package/dist/assets/modules/budgets/supabase/migrations/20260913104233_foreign_key_indexes.sql +37 -0
  135. package/dist/assets/modules/budgets/supabase/migrations/20260913104501_budgets_capabilities.sql +72 -0
  136. package/dist/assets/modules/budgets/supabase/migrations/20260914122400_budgets_round_at_the_currency.sql +68 -0
  137. package/dist/assets/modules/budgets/supabase/migrations/20260914145048_budgets_accounts_in_use.sql +30 -0
  138. package/dist/assets/modules/budgets/supabase/migrations/20260914151812_budgets_grants_its_own_rights.sql +31 -0
  139. package/dist/assets/modules/budgets/supabase/migrations/20260918113954_budgets_client_reads.sql +20 -0
  140. package/dist/assets/modules/budgets/supabase/migrations/20260918150823_budgets_leave_with_the_company.sql +37 -0
  141. package/dist/assets/modules/schema/module.1.json +69 -0
  142. package/dist/assets/seed/00_currencies.sql +15 -0
  143. package/dist/assets/seed/00_territories.sql +280 -0
  144. package/dist/assets/seed/05_framework_generic.sql +110 -0
  145. package/dist/assets/seed/10_pack_be.sql +1284 -0
  146. package/dist/assets/seed/11_pack_fr.sql +1112 -0
  147. package/dist/assets/seed/12_pack_lu.sql +2484 -0
  148. package/dist/assets/seed/13_pack_ee.sql +733 -0
  149. package/dist/assets/seed/14_pack_gb.sql +796 -0
  150. package/dist/assets/seed/15_pack_us.sql +751 -0
  151. package/dist/assets/seed/90_demo_company.sql +368 -0
  152. package/dist/assets/seed/modules/assets/10_pack_be.sql +58 -0
  153. package/dist/assets/seed/modules/assets/11_pack_fr.sql +57 -0
  154. package/dist/assets/seed/modules/assets/14_pack_gb.sql +58 -0
  155. package/dist/assets/seed/modules/assets/15_pack_us.sql +60 -0
  156. package/dist/auth.d.ts +59 -0
  157. package/dist/auth.d.ts.map +1 -0
  158. package/dist/auth.js +134 -0
  159. package/dist/auth.js.map +1 -0
  160. package/dist/bin.d.ts +6 -0
  161. package/dist/bin.d.ts.map +1 -0
  162. package/dist/bin.js +8 -0
  163. package/dist/bin.js.map +1 -0
  164. package/dist/books.d.ts +60 -0
  165. package/dist/books.d.ts.map +1 -0
  166. package/dist/books.js +168 -0
  167. package/dist/books.js.map +1 -0
  168. package/dist/bootstrap.d.ts +236 -0
  169. package/dist/bootstrap.d.ts.map +1 -0
  170. package/dist/bootstrap.js +459 -0
  171. package/dist/bootstrap.js.map +1 -0
  172. package/dist/bundle.d.ts +27 -0
  173. package/dist/bundle.d.ts.map +1 -0
  174. package/dist/bundle.js +47 -0
  175. package/dist/bundle.js.map +1 -0
  176. package/dist/checklist.d.ts +35 -0
  177. package/dist/checklist.d.ts.map +1 -0
  178. package/dist/checklist.js +64 -0
  179. package/dist/checklist.js.map +1 -0
  180. package/dist/cli.d.ts +14 -0
  181. package/dist/cli.d.ts.map +1 -0
  182. package/dist/cli.js +318 -0
  183. package/dist/cli.js.map +1 -0
  184. package/dist/commands/company.d.ts +59 -0
  185. package/dist/commands/company.d.ts.map +1 -0
  186. package/dist/commands/company.js +287 -0
  187. package/dist/commands/company.js.map +1 -0
  188. package/dist/commands/contact.d.ts +9 -0
  189. package/dist/commands/contact.d.ts.map +1 -0
  190. package/dist/commands/contact.js +82 -0
  191. package/dist/commands/contact.js.map +1 -0
  192. package/dist/commands/demo.d.ts +19 -0
  193. package/dist/commands/demo.d.ts.map +1 -0
  194. package/dist/commands/demo.js +72 -0
  195. package/dist/commands/demo.js.map +1 -0
  196. package/dist/commands/doctor.d.ts +12 -0
  197. package/dist/commands/doctor.d.ts.map +1 -0
  198. package/dist/commands/doctor.js +68 -0
  199. package/dist/commands/doctor.js.map +1 -0
  200. package/dist/commands/document.d.ts +17 -0
  201. package/dist/commands/document.d.ts.map +1 -0
  202. package/dist/commands/document.js +217 -0
  203. package/dist/commands/document.js.map +1 -0
  204. package/dist/commands/init.d.ts +31 -0
  205. package/dist/commands/init.d.ts.map +1 -0
  206. package/dist/commands/init.js +535 -0
  207. package/dist/commands/init.js.map +1 -0
  208. package/dist/commands/login.d.ts +24 -0
  209. package/dist/commands/login.d.ts.map +1 -0
  210. package/dist/commands/login.js +128 -0
  211. package/dist/commands/login.js.map +1 -0
  212. package/dist/commands/migrate.d.ts +30 -0
  213. package/dist/commands/migrate.d.ts.map +1 -0
  214. package/dist/commands/migrate.js +115 -0
  215. package/dist/commands/migrate.js.map +1 -0
  216. package/dist/commands/module.d.ts +32 -0
  217. package/dist/commands/module.d.ts.map +1 -0
  218. package/dist/commands/module.js +285 -0
  219. package/dist/commands/module.js.map +1 -0
  220. package/dist/commands/pack.d.ts +22 -0
  221. package/dist/commands/pack.d.ts.map +1 -0
  222. package/dist/commands/pack.js +481 -0
  223. package/dist/commands/pack.js.map +1 -0
  224. package/dist/commands/payment.d.ts +15 -0
  225. package/dist/commands/payment.d.ts.map +1 -0
  226. package/dist/commands/payment.js +97 -0
  227. package/dist/commands/payment.js.map +1 -0
  228. package/dist/commands/register.d.ts +20 -0
  229. package/dist/commands/register.d.ts.map +1 -0
  230. package/dist/commands/register.js +134 -0
  231. package/dist/commands/register.js.map +1 -0
  232. package/dist/commands/status.d.ts +8 -0
  233. package/dist/commands/status.d.ts.map +1 -0
  234. package/dist/commands/status.js +134 -0
  235. package/dist/commands/status.js.map +1 -0
  236. package/dist/commands/whoami.d.ts +21 -0
  237. package/dist/commands/whoami.d.ts.map +1 -0
  238. package/dist/commands/whoami.js +133 -0
  239. package/dist/commands/whoami.js.map +1 -0
  240. package/dist/company.d.ts +16 -0
  241. package/dist/company.d.ts.map +1 -0
  242. package/dist/company.js +26 -0
  243. package/dist/company.js.map +1 -0
  244. package/dist/config.d.ts +24 -0
  245. package/dist/config.d.ts.map +1 -0
  246. package/dist/config.js +50 -0
  247. package/dist/config.js.map +1 -0
  248. package/dist/connection.d.ts +79 -0
  249. package/dist/connection.d.ts.map +1 -0
  250. package/dist/connection.js +116 -0
  251. package/dist/connection.js.map +1 -0
  252. package/dist/context.d.ts +47 -0
  253. package/dist/context.d.ts.map +1 -0
  254. package/dist/context.js +93 -0
  255. package/dist/context.js.map +1 -0
  256. package/dist/doctor.d.ts +45 -0
  257. package/dist/doctor.d.ts.map +1 -0
  258. package/dist/doctor.js +448 -0
  259. package/dist/doctor.js.map +1 -0
  260. package/dist/grants.d.ts +88 -0
  261. package/dist/grants.d.ts.map +1 -0
  262. package/dist/grants.js +174 -0
  263. package/dist/grants.js.map +1 -0
  264. package/dist/identity.d.ts +54 -0
  265. package/dist/identity.d.ts.map +1 -0
  266. package/dist/identity.js +132 -0
  267. package/dist/identity.js.map +1 -0
  268. package/dist/index.d.ts +44 -0
  269. package/dist/index.d.ts.map +1 -0
  270. package/dist/index.js +43 -0
  271. package/dist/index.js.map +1 -0
  272. package/dist/inventory.d.ts +155 -0
  273. package/dist/inventory.d.ts.map +1 -0
  274. package/dist/inventory.js +303 -0
  275. package/dist/inventory.js.map +1 -0
  276. package/dist/migrations.d.ts +76 -0
  277. package/dist/migrations.d.ts.map +1 -0
  278. package/dist/migrations.js +226 -0
  279. package/dist/migrations.js.map +1 -0
  280. package/dist/module/read.d.ts +91 -0
  281. package/dist/module/read.d.ts.map +1 -0
  282. package/dist/module/read.js +172 -0
  283. package/dist/module/read.js.map +1 -0
  284. package/dist/output.d.ts +110 -0
  285. package/dist/output.d.ts.map +1 -0
  286. package/dist/output.js +173 -0
  287. package/dist/output.js.map +1 -0
  288. package/dist/pack/certification.d.ts +27 -0
  289. package/dist/pack/certification.d.ts.map +1 -0
  290. package/dist/pack/certification.js +38 -0
  291. package/dist/pack/certification.js.map +1 -0
  292. package/dist/pack/compile.d.ts +75 -0
  293. package/dist/pack/compile.d.ts.map +1 -0
  294. package/dist/pack/compile.js +801 -0
  295. package/dist/pack/compile.js.map +1 -0
  296. package/dist/pack/filing.d.ts +48 -0
  297. package/dist/pack/filing.d.ts.map +1 -0
  298. package/dist/pack/filing.js +56 -0
  299. package/dist/pack/filing.js.map +1 -0
  300. package/dist/pack/read.d.ts +766 -0
  301. package/dist/pack/read.d.ts.map +1 -0
  302. package/dist/pack/read.js +2336 -0
  303. package/dist/pack/read.js.map +1 -0
  304. package/dist/pack/schema.d.ts +26 -0
  305. package/dist/pack/schema.d.ts.map +1 -0
  306. package/dist/pack/schema.js +181 -0
  307. package/dist/pack/schema.js.map +1 -0
  308. package/dist/pack/territories.d.ts +98 -0
  309. package/dist/pack/territories.d.ts.map +1 -0
  310. package/dist/pack/territories.js +0 -0
  311. package/dist/pack/territories.js.map +1 -0
  312. package/dist/pack/upgrade.d.ts +86 -0
  313. package/dist/pack/upgrade.d.ts.map +1 -0
  314. package/dist/pack/upgrade.js +76 -0
  315. package/dist/pack/upgrade.js.map +1 -0
  316. package/dist/pack/vat-codes.d.ts +273 -0
  317. package/dist/pack/vat-codes.d.ts.map +1 -0
  318. package/dist/pack/vat-codes.js +513 -0
  319. package/dist/pack/vat-codes.js.map +1 -0
  320. package/dist/profiles.d.ts +67 -0
  321. package/dist/profiles.d.ts.map +1 -0
  322. package/dist/profiles.js +187 -0
  323. package/dist/profiles.js.map +1 -0
  324. package/dist/prompt.d.ts +40 -0
  325. package/dist/prompt.d.ts.map +1 -0
  326. package/dist/prompt.js +120 -0
  327. package/dist/prompt.js.map +1 -0
  328. package/dist/registry.d.ts +84 -0
  329. package/dist/registry.d.ts.map +1 -0
  330. package/dist/registry.js +104 -0
  331. package/dist/registry.js.map +1 -0
  332. package/dist/rest.d.ts +81 -0
  333. package/dist/rest.d.ts.map +1 -0
  334. package/dist/rest.js +245 -0
  335. package/dist/rest.js.map +1 -0
  336. package/dist/schema.d.ts +15 -0
  337. package/dist/schema.d.ts.map +1 -0
  338. package/dist/schema.js +15 -0
  339. package/dist/schema.js.map +1 -0
  340. package/dist/seeds.d.ts +27 -0
  341. package/dist/seeds.d.ts.map +1 -0
  342. package/dist/seeds.js +47 -0
  343. package/dist/seeds.js.map +1 -0
  344. package/dist/session.d.ts +39 -0
  345. package/dist/session.d.ts.map +1 -0
  346. package/dist/session.js +92 -0
  347. package/dist/session.js.map +1 -0
  348. package/dist/sql.d.ts +48 -0
  349. package/dist/sql.d.ts.map +1 -0
  350. package/dist/sql.js +112 -0
  351. package/dist/sql.js.map +1 -0
  352. package/dist/status.d.ts +94 -0
  353. package/dist/status.d.ts.map +1 -0
  354. package/dist/status.js +120 -0
  355. package/dist/status.js.map +1 -0
  356. package/dist/ui.d.ts +55 -0
  357. package/dist/ui.d.ts.map +1 -0
  358. package/dist/ui.js +114 -0
  359. package/dist/ui.js.map +1 -0
  360. package/package.json +29 -0
  361. package/schema/output.1.json +613 -0
@@ -0,0 +1,155 @@
1
+ /**
2
+ * What this release defines, and what a database actually holds.
3
+ *
4
+ * `packages/cli/assets/expected-objects.json` is generated from the migrations
5
+ * by `scripts/generate-expected-objects.mjs` and travels inside the published
6
+ * package. It is an inventory, not a list kept by hand: a doctor whose
7
+ * expectations are typed out by a human drifts from the schema the first time
8
+ * somebody adds a table and forgets the list, and then it lies in both
9
+ * directions at once.
10
+ *
11
+ * Comparing it to a live catalogue answers two different questions. Something
12
+ * **missing** means the installation is behind or has been damaged — a
13
+ * migration that did not land, an object dropped by hand. Something **extra**
14
+ * means an operator added it: their table, their function, their business, and
15
+ * this reports it as information rather than as a fault.
16
+ *
17
+ * A policy is the exception. Row level security is the whole security model
18
+ * here, so a policy that is gone and a policy that was added to a table of
19
+ * this schema are both faults: the first opens nothing and closes everything,
20
+ * the second is a grant nobody reviewed.
21
+ */
22
+ import { type GrantsSection } from './grants.js';
23
+ import type { SqlClient } from './sql.js';
24
+ export interface ExpectedColumn {
25
+ name: string;
26
+ type: string;
27
+ }
28
+ export interface ExpectedTable {
29
+ name: string;
30
+ columns: ExpectedColumn[];
31
+ }
32
+ export interface ExpectedFunction {
33
+ name: string;
34
+ /** `pg_get_function_identity_arguments`, so an overload is its own entry. */
35
+ arguments: string;
36
+ }
37
+ export interface ExpectedPolicy {
38
+ table: string;
39
+ name: string;
40
+ command: string;
41
+ }
42
+ export interface ExpectedTrigger {
43
+ table: string;
44
+ name: string;
45
+ }
46
+ export interface ExpectedType {
47
+ name: string;
48
+ kind: string;
49
+ labels?: string[];
50
+ }
51
+ export interface ExpectedSchema {
52
+ schema: string;
53
+ tables: ExpectedTable[];
54
+ views: string[];
55
+ functions: ExpectedFunction[];
56
+ policies: ExpectedPolicy[];
57
+ triggers: ExpectedTrigger[];
58
+ types: ExpectedType[];
59
+ /**
60
+ * Which of `anon`, `authenticated` and `service_role` may reach each of
61
+ * those objects, and with which verbs.
62
+ *
63
+ * Part of the inventory rather than a file of its own, because a privilege
64
+ * and the object it is on ship in the same migration: since
65
+ * `20260914151207` the schema grants its own rights by name instead of
66
+ * taking whatever a Supabase project's default privileges hand out, and a
67
+ * table added without its grants is exactly as broken as a table added
68
+ * without its policy.
69
+ *
70
+ * `doctor.ts` compares it separately from the categories above, because the
71
+ * rule is not the same: a missing grant is a fault, an extra one to `anon`
72
+ * is a fault, and an extra one to a signed-in user is worth saying out loud
73
+ * without failing a build.
74
+ */
75
+ grants: GrantsSection;
76
+ }
77
+ export interface ExpectedModule extends ExpectedSchema {
78
+ code: string;
79
+ version: string;
80
+ }
81
+ export interface ExpectedObjects {
82
+ /** The schema version this inventory describes. */
83
+ schemaVersion: string | null;
84
+ /** The last migration it was generated from. */
85
+ migration: string | null;
86
+ socle: ExpectedSchema;
87
+ modules: ExpectedModule[];
88
+ }
89
+ /** One category, compared. Every entry is a printable key. */
90
+ export interface CategoryDiff {
91
+ missing: string[];
92
+ extra: string[];
93
+ /** Present on both sides and not the same: a column whose type moved. */
94
+ changed: string[];
95
+ }
96
+ export interface SectionComparison {
97
+ /** `socle`, or the module's code. */
98
+ code: string;
99
+ schema: string;
100
+ /**
101
+ * Whether this database carries the section at all. A module the operator
102
+ * never installed is not a fault, and nothing of it is required.
103
+ */
104
+ installed: boolean;
105
+ tables: CategoryDiff;
106
+ columns: CategoryDiff;
107
+ views: CategoryDiff;
108
+ functions: CategoryDiff;
109
+ policies: CategoryDiff;
110
+ triggers: CategoryDiff;
111
+ types: CategoryDiff;
112
+ }
113
+ export interface CatalogueComparison {
114
+ /** Version the inventory describes. */
115
+ expectedVersion: string | null;
116
+ /** Version the database reports, which may be older or newer. */
117
+ databaseVersion: string | null;
118
+ sections: SectionComparison[];
119
+ missing: number;
120
+ extra: number;
121
+ changed: number;
122
+ /** Missing or extra policies on a table of this schema. Always a fault. */
123
+ policyFaults: number;
124
+ }
125
+ export declare class InventoryError extends Error {
126
+ }
127
+ /**
128
+ * Where the inventory is.
129
+ *
130
+ * Published package: `dist/assets/expected-objects.json`, put there at build
131
+ * time by `scripts/copy-assets.mjs`. Checkout: `packages/cli/assets/`, which
132
+ * is the file the generator writes and the repository commits. The two
133
+ * candidates mirror `resolveBundleDir()`.
134
+ */
135
+ export declare function resolveInventoryPath(): string | undefined;
136
+ /** The inventory this CLI ships, or `undefined` if it ships none. */
137
+ export declare function readExpectedObjects(path?: string | undefined): Promise<ExpectedObjects | undefined>;
138
+ /** The live grants of one schema, for the doctor's own check. */
139
+ export declare function readGrants(db: SqlClient, schema: string): Promise<GrantsSection>;
140
+ /** The schemas of an inventory this database actually carries. */
141
+ export declare function installedSections(db: SqlClient, expected: ExpectedObjects): Promise<ExpectedSchema[]>;
142
+ /**
143
+ * The inventory against the live catalogue.
144
+ *
145
+ * The database's own schema version is read and reported but never gates the
146
+ * comparison: an installation older than the CLI is exactly when this is worth
147
+ * running, and refusing to look would be refusing the case.
148
+ */
149
+ export declare function compareCatalogue(db: SqlClient, expected: ExpectedObjects): Promise<CatalogueComparison>;
150
+ /** Every difference of one section, as printable lines. */
151
+ export declare function describeDifferences(section: SectionComparison): {
152
+ faults: string[];
153
+ information: string[];
154
+ };
155
+ //# sourceMappingURL=inventory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../src/inventory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,OAAO,EAAkB,KAAK,aAAa,EAAE,MA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AAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAEtF;AAED,kEAAkE;AAClE,wBAAsB,iBAAiB,CACrC,EAAE,EAAE,SAAS,EACb,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,cAAc,EAAE,CAAC,CAG3B;AAmID;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,SAAS,EACb,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,mBAAmB,CAAC,CAqC9B;AAED,2DAA2D;AAC3D,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG;IAC/D,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB,CAgBA"}
@@ -0,0 +1,303 @@
1
+ /**
2
+ * What this release defines, and what a database actually holds.
3
+ *
4
+ * `packages/cli/assets/expected-objects.json` is generated from the migrations
5
+ * by `scripts/generate-expected-objects.mjs` and travels inside the published
6
+ * package. It is an inventory, not a list kept by hand: a doctor whose
7
+ * expectations are typed out by a human drifts from the schema the first time
8
+ * somebody adds a table and forgets the list, and then it lies in both
9
+ * directions at once.
10
+ *
11
+ * Comparing it to a live catalogue answers two different questions. Something
12
+ * **missing** means the installation is behind or has been damaged — a
13
+ * migration that did not land, an object dropped by hand. Something **extra**
14
+ * means an operator added it: their table, their function, their business, and
15
+ * this reports it as information rather than as a fault.
16
+ *
17
+ * A policy is the exception. Row level security is the whole security model
18
+ * here, so a policy that is gone and a policy that was added to a table of
19
+ * this schema are both faults: the first opens nothing and closes everything,
20
+ * the second is a grant nobody reviewed.
21
+ */
22
+ import { existsSync } from 'node:fs';
23
+ import { readFile } from 'node:fs/promises';
24
+ import { fileURLToPath } from 'node:url';
25
+ import { describeGrants } from './grants.js';
26
+ import { scalar } from './sql.js';
27
+ export class InventoryError extends Error {
28
+ }
29
+ const CATEGORIES = ['tables', 'columns', 'views', 'functions', 'policies', 'triggers', 'types'];
30
+ /**
31
+ * Where the inventory is.
32
+ *
33
+ * Published package: `dist/assets/expected-objects.json`, put there at build
34
+ * time by `scripts/copy-assets.mjs`. Checkout: `packages/cli/assets/`, which
35
+ * is the file the generator writes and the repository commits. The two
36
+ * candidates mirror `resolveBundleDir()`.
37
+ */
38
+ export function resolveInventoryPath() {
39
+ const candidates = [
40
+ new URL('./assets/expected-objects.json', import.meta.url),
41
+ new URL('../assets/expected-objects.json', import.meta.url),
42
+ ];
43
+ for (const candidate of candidates) {
44
+ const path = fileURLToPath(candidate);
45
+ if (existsSync(path))
46
+ return path;
47
+ }
48
+ return undefined;
49
+ }
50
+ /** The inventory this CLI ships, or `undefined` if it ships none. */
51
+ export async function readExpectedObjects(path = resolveInventoryPath()) {
52
+ if (path === undefined)
53
+ return undefined;
54
+ const raw = await readFile(path, 'utf8');
55
+ let parsed;
56
+ try {
57
+ parsed = JSON.parse(raw);
58
+ }
59
+ catch (error) {
60
+ throw new InventoryError(`inventory_invalid: ${path} — ${error.message}`);
61
+ }
62
+ if (parsed.socle === undefined || !Array.isArray(parsed.modules)) {
63
+ throw new InventoryError(`inventory_invalid: ${path} — no socle or no modules`);
64
+ }
65
+ return parsed;
66
+ }
67
+ // ------------------------------------------------------------------ reading
68
+ /** The same categories, read from a live catalogue. */
69
+ async function readSchema(db, schema) {
70
+ const tables = await db.query(`select c.relname as name
71
+ from pg_class c join pg_namespace n on n.oid = c.relnamespace
72
+ where n.nspname = $1 and c.relkind in ('r', 'p')
73
+ order by c.relname`, [schema]);
74
+ const columns = await db.query(`select c.relname as table_name, a.attname as name,
75
+ format_type(a.atttypid, a.atttypmod) as type
76
+ from pg_attribute a
77
+ join pg_class c on c.oid = a.attrelid
78
+ join pg_namespace n on n.oid = c.relnamespace
79
+ where n.nspname = $1 and c.relkind in ('r', 'p')
80
+ and a.attnum > 0 and not a.attisdropped
81
+ order by c.relname, a.attname`, [schema]);
82
+ const views = await db.query(`select c.relname as name
83
+ from pg_class c join pg_namespace n on n.oid = c.relnamespace
84
+ where n.nspname = $1 and c.relkind in ('v', 'm')
85
+ order by c.relname`, [schema]);
86
+ const functions = await db.query(`select p.proname as name, pg_get_function_identity_arguments(p.oid) as arguments
87
+ from pg_proc p join pg_namespace n on n.oid = p.pronamespace
88
+ where n.nspname = $1
89
+ order by p.proname, pg_get_function_identity_arguments(p.oid)`, [schema]);
90
+ const policies = await db.query(`select c.relname as table_name, p.polname as name,
91
+ case p.polcmd when 'r' then 'select' when 'a' then 'insert'
92
+ when 'w' then 'update' when 'd' then 'delete'
93
+ else 'all' end as command
94
+ from pg_policy p
95
+ join pg_class c on c.oid = p.polrelid
96
+ join pg_namespace n on n.oid = c.relnamespace
97
+ where n.nspname = $1
98
+ order by c.relname, p.polname`, [schema]);
99
+ const triggers = await db.query(`select c.relname as table_name, t.tgname as name
100
+ from pg_trigger t
101
+ join pg_class c on c.oid = t.tgrelid
102
+ join pg_namespace n on n.oid = c.relnamespace
103
+ where n.nspname = $1 and not t.tgisinternal
104
+ order by c.relname, t.tgname`, [schema]);
105
+ const types = await db.query(`select t.typname as name,
106
+ case t.typtype when 'e' then 'enum' when 'd' then 'domain' else 'composite' end as kind,
107
+ case when t.typtype = 'e' then (
108
+ select array_agg(e.enumlabel order by e.enumsortorder)
109
+ from pg_enum e where e.enumtypid = t.oid
110
+ ) end as labels
111
+ from pg_type t join pg_namespace n on n.oid = t.typnamespace
112
+ where n.nspname = $1 and t.typtype in ('e', 'd', 'c')
113
+ and (t.typtype <> 'c'
114
+ or exists (select 1 from pg_class c where c.oid = t.typrelid and c.relkind = 'c'))
115
+ order by t.typname`, [schema]);
116
+ const grants = await describeGrants((sql, params) => db.query(sql, params), schema);
117
+ return {
118
+ schema,
119
+ tables: tables.map((t) => ({
120
+ name: t.name,
121
+ columns: columns
122
+ .filter((c) => c.table_name === t.name)
123
+ .map((c) => ({ name: c.name, type: c.type })),
124
+ })),
125
+ views: views.map((v) => v.name),
126
+ functions: functions.map((f) => ({ name: f.name, arguments: f.arguments })),
127
+ policies: policies.map((p) => ({ table: p.table_name, name: p.name, command: p.command })),
128
+ triggers: triggers.map((t) => ({ table: t.table_name, name: t.name })),
129
+ types: types.map((t) => ({
130
+ name: t.name,
131
+ kind: t.kind,
132
+ ...(t.labels === null ? {} : { labels: t.labels }),
133
+ })),
134
+ grants,
135
+ };
136
+ }
137
+ /** The live grants of one schema, for the doctor's own check. */
138
+ export async function readGrants(db, schema) {
139
+ return describeGrants((sql, params) => db.query(sql, params), schema);
140
+ }
141
+ /** The schemas of an inventory this database actually carries. */
142
+ export async function installedSections(db, expected) {
143
+ const carried = await installedModules(db);
144
+ return [expected.socle, ...expected.modules.filter((m) => carried.has(m.code))];
145
+ }
146
+ // ---------------------------------------------------------------- comparing
147
+ function emptyDiff() {
148
+ return { missing: [], extra: [], changed: [] };
149
+ }
150
+ /**
151
+ * Two keyed sets, compared.
152
+ *
153
+ * `key` is what identifies the object — a name, or a name and a signature —
154
+ * and `same` says whether two objects that share a key are still the same
155
+ * thing. Both sides are already sorted, and the keys are what is printed.
156
+ */
157
+ function diff(expected, actual, key, same = () => undefined) {
158
+ const out = emptyDiff();
159
+ const here = new Map(actual.map((item) => [key(item), item]));
160
+ const there = new Set(expected.map(key));
161
+ for (const item of expected) {
162
+ const found = here.get(key(item));
163
+ if (found === undefined) {
164
+ out.missing.push(key(item));
165
+ continue;
166
+ }
167
+ const difference = same(item, found);
168
+ if (difference !== undefined)
169
+ out.changed.push(difference);
170
+ }
171
+ for (const item of actual) {
172
+ if (!there.has(key(item)))
173
+ out.extra.push(key(item));
174
+ }
175
+ return out;
176
+ }
177
+ const functionKey = (f) => `${f.name}(${f.arguments})`;
178
+ const policyKey = (p) => `${p.table}.${p.name}`;
179
+ const triggerKey = (t) => `${t.table}.${t.name}`;
180
+ /** One section of the inventory against one schema of the database. */
181
+ function compareSchema(code, expected, actual) {
182
+ const tables = diff(expected.tables, actual.tables, (t) => t.name);
183
+ // Columns, triggers and policies are compared on the tables this schema
184
+ // defines. On a table the operator added, they are the operator's business,
185
+ // and the table itself is already reported as extra.
186
+ const known = new Set(expected.tables.map((t) => t.name));
187
+ const expectedColumns = expected.tables.flatMap((t) => t.columns.map((c) => ({ key: `${t.name}.${c.name}`, type: c.type })));
188
+ const actualColumns = actual.tables
189
+ .filter((t) => known.has(t.name))
190
+ .flatMap((t) => t.columns.map((c) => ({ key: `${t.name}.${c.name}`, type: c.type })));
191
+ const columns = diff(expectedColumns, actualColumns, (c) => c.key, (a, b) => (a.type === b.type ? undefined : `${a.key} is ${b.type}, expected ${a.type}`));
192
+ // A column missing because its whole table is missing is already said once.
193
+ columns.missing = columns.missing.filter((c) => !tables.missing.includes(c.split('.')[0] ?? ''));
194
+ const policies = diff(expected.policies, actual.policies.filter((p) => known.has(p.table)), policyKey, (a, b) => (a.command === b.command ? undefined : `${policyKey(a)} is ${b.command}, expected ${a.command}`));
195
+ policies.missing = policies.missing.filter((p) => !tables.missing.includes(p.split('.')[0] ?? ''));
196
+ const triggers = diff(expected.triggers, actual.triggers.filter((t) => known.has(t.table)), triggerKey);
197
+ triggers.missing = triggers.missing.filter((t) => !tables.missing.includes(t.split('.')[0] ?? ''));
198
+ return {
199
+ code,
200
+ schema: expected.schema,
201
+ installed: true,
202
+ tables,
203
+ columns,
204
+ views: diff(expected.views, actual.views, (v) => v),
205
+ functions: diff(expected.functions, actual.functions, functionKey),
206
+ policies,
207
+ triggers,
208
+ types: diff(expected.types, actual.types, (t) => t.name, (a, b) => {
209
+ if (a.kind !== b.kind)
210
+ return `${a.name} is a ${b.kind}, expected a ${a.kind}`;
211
+ const expectedLabels = (a.labels ?? []).join(', ');
212
+ const actualLabels = (b.labels ?? []).join(', ');
213
+ if (expectedLabels === actualLabels)
214
+ return undefined;
215
+ return `${a.name} holds (${actualLabels}), expected (${expectedLabels})`;
216
+ }),
217
+ };
218
+ }
219
+ /** A section this database does not carry: nothing of it is required. */
220
+ function notInstalled(code, schema) {
221
+ return {
222
+ code,
223
+ schema,
224
+ installed: false,
225
+ tables: emptyDiff(),
226
+ columns: emptyDiff(),
227
+ views: emptyDiff(),
228
+ functions: emptyDiff(),
229
+ policies: emptyDiff(),
230
+ triggers: emptyDiff(),
231
+ types: emptyDiff(),
232
+ };
233
+ }
234
+ /** The module codes this database carries, whatever this CLI ships. */
235
+ async function installedModules(db) {
236
+ const present = await scalar(db, `select to_regclass('public.modules') is not null`);
237
+ if (present !== true)
238
+ return new Set();
239
+ const rows = await db.query('select code from modules');
240
+ return new Set(rows.map((r) => r.code));
241
+ }
242
+ /**
243
+ * The inventory against the live catalogue.
244
+ *
245
+ * The database's own schema version is read and reported but never gates the
246
+ * comparison: an installation older than the CLI is exactly when this is worth
247
+ * running, and refusing to look would be refusing the case.
248
+ */
249
+ export async function compareCatalogue(db, expected) {
250
+ // Asked in two steps on purpose: naming the function in a `case` still
251
+ // resolves it, so a database that does not have it would raise rather than
252
+ // answer, and that database is one this is meant to report on.
253
+ const hasVersion = await scalar(db, `select to_regprocedure('public.ekwo_schema_version()') is not null`);
254
+ const databaseVersion = hasVersion === true ? ((await scalar(db, 'select ekwo_schema_version()')) ?? null) : null;
255
+ const sections = [compareSchema('socle', expected.socle, await readSchema(db, 'public'))];
256
+ const carried = await installedModules(db);
257
+ for (const module of expected.modules) {
258
+ if (!carried.has(module.code)) {
259
+ sections.push(notInstalled(module.code, module.schema));
260
+ continue;
261
+ }
262
+ sections.push(compareSchema(module.code, module, await readSchema(db, module.schema)));
263
+ }
264
+ let missing = 0;
265
+ let extra = 0;
266
+ let changed = 0;
267
+ let policyFaults = 0;
268
+ for (const section of sections) {
269
+ for (const category of CATEGORIES) {
270
+ missing += section[category].missing.length;
271
+ extra += section[category].extra.length;
272
+ changed += section[category].changed.length;
273
+ }
274
+ policyFaults +=
275
+ section.policies.missing.length + section.policies.extra.length + section.policies.changed.length;
276
+ }
277
+ return { expectedVersion: expected.schemaVersion, databaseVersion, sections, missing, extra, changed, policyFaults };
278
+ }
279
+ /** Every difference of one section, as printable lines. */
280
+ export function describeDifferences(section) {
281
+ const faults = [];
282
+ const information = [];
283
+ const where = section.code === 'socle' ? '' : `${section.code}: `;
284
+ for (const category of CATEGORIES) {
285
+ const { missing, extra, changed } = section[category];
286
+ for (const item of missing)
287
+ faults.push(`${where}missing ${singular(category)} ${item}`);
288
+ for (const item of changed)
289
+ faults.push(`${where}${item}`);
290
+ for (const item of extra) {
291
+ const line = `${where}extra ${singular(category)} ${item}`;
292
+ if (category === 'policies')
293
+ faults.push(line);
294
+ else
295
+ information.push(line);
296
+ }
297
+ }
298
+ return { faults, information };
299
+ }
300
+ function singular(category) {
301
+ return category === 'policies' ? 'policy' : category.replace(/s$/, '');
302
+ }
303
+ //# sourceMappingURL=inventory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inventory.js","sourceRoot":"","sources":["../src/inventory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,cAAc,EAAsB,MAAM,aAAa,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAmHlC,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,CAAU,CAAC;AAEzG;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,UAAU,GAAG;QACjB,IAAI,GAAG,CAAC,gCAAgC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QAC1D,IAAI,GAAG,CAAC,iCAAiC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;KAC5D,CAAC;IACF,KAAK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CAAC;QACzF,KAAK,MAAM,IAAI,IAAI,OAAO;YAAE,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,IAAI,EAAE,CAAC,CAAC;QAC3D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,GAAG,KAAK,SAAS,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;YAC3D,IAAI,QAAQ,KAAK,UAAU;gBAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;gBAC1C,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,QAAQ,CAAC,QAAqC;IACrD,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The migration runner.
3
+ *
4
+ * It applies `supabase/migrations/*.sql` in filename order and records what
5
+ * it did in `supabase_migrations.schema_migrations`, **in the format the
6
+ * Supabase CLI uses** — same schema, same table, same three columns, version
7
+ * being the timestamp prefix of the filename. That is the whole point: an
8
+ * installation set up with `ekwo init` can later be pushed to with
9
+ * `supabase db push`, and one set up with `supabase db push` can be brought
10
+ * forward with `ekwo migrate`. The two are interchangeable because they read
11
+ * and write the same history.
12
+ *
13
+ * Each file is applied inside one transaction together with its history row,
14
+ * so a migration that fails halfway leaves neither half-applied schema nor a
15
+ * history row that lies. Re-running resumes at the file that failed.
16
+ */
17
+ import type { SqlClient } from './sql.js';
18
+ export interface Migration {
19
+ /** `20260911120000` — the timestamp prefix, and the primary key of the history. */
20
+ version: string;
21
+ /** `core_companies` — what the Supabase CLI stores as `name`. */
22
+ name: string;
23
+ /** `20260911120000_core_companies.sql` */
24
+ file: string;
25
+ /** Absolute path on disk. */
26
+ path: string;
27
+ }
28
+ /** Parses a migration filename, or returns `undefined` if it is not one. */
29
+ export declare function parseMigrationFile(file: string): Omit<Migration, 'path'> | undefined;
30
+ /** Every migration in `dir`, in the order they must be applied. */
31
+ export declare function listMigrations(dir: string): Promise<Migration[]>;
32
+ /**
33
+ * The history table, created exactly as the Supabase CLI creates it.
34
+ *
35
+ * The columns are added one by one with `if not exists`, so this is safe on a
36
+ * project the Supabase CLI has already touched, whichever version of it.
37
+ */
38
+ export declare function ensureHistory(db: SqlClient): Promise<void>;
39
+ /** Versions already recorded, oldest first. */
40
+ export declare function appliedVersions(db: SqlClient): Promise<string[]>;
41
+ export interface Gap {
42
+ applied: string[];
43
+ pending: Migration[];
44
+ /** Versions in the database that this release does not ship — a newer installation. */
45
+ unknown: string[];
46
+ }
47
+ /** What separates the database from the migrations this CLI carries. */
48
+ export declare function migrationGap(db: SqlClient, all: Migration[]): Promise<Gap>;
49
+ /**
50
+ * Applies one migration and records it, atomically.
51
+ *
52
+ * The file is sent as a single command string, so Postgres runs it as one
53
+ * unit inside the transaction we opened. No file in this repository opens a
54
+ * transaction of its own, and none may: the runner owns that.
55
+ */
56
+ export declare function applyMigration(db: SqlClient, migration: Migration): Promise<void>;
57
+ export interface ApplyResult {
58
+ applied: Migration[];
59
+ alreadyApplied: number;
60
+ }
61
+ /** Applies every pending migration, in order, reporting each one as it lands. */
62
+ export declare function applyMigrations(db: SqlClient, all: Migration[], onApplied?: (migration: Migration) => void): Promise<ApplyResult>;
63
+ /**
64
+ * Splits a SQL file into statements, for the `statements` column only.
65
+ *
66
+ * Execution never goes through this: the file is handed to Postgres whole.
67
+ * The column is what `supabase migration repair` and `supabase db diff` read
68
+ * back, so it should hold statements rather than one blob — but a mistake
69
+ * here can only make that column less pretty, never break an installation.
70
+ *
71
+ * Handles line and block comments, single- and double-quoted literals,
72
+ * `E''` backslash escapes and dollar quoting with tags, which is what the
73
+ * function bodies in this schema are made of.
74
+ */
75
+ export declare function splitStatements(sql: string): string[];
76
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,WAAW,SAAS;IACxB,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAID,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,SAAS,CAMpF;AAED,mEAAmE;AACnE,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAWtE;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhE;AAED,+CAA+C;AAC/C,wBAAsB,eAAe,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAKtE;AAED,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,uFAAuF;IACvF,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wEAAwE;AACxE,wBAAsB,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAUhF;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS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