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.
- package/README.md +873 -0
- package/dist/args.d.ts +57 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +134 -0
- package/dist/args.js.map +1 -0
- package/dist/assets/expected-objects.json +9432 -0
- package/dist/assets/migrations/20260911120000_core_companies.sql +260 -0
- package/dist/assets/migrations/20260911120100_accounts_journals.sql +211 -0
- package/dist/assets/migrations/20260911120200_contacts.sql +90 -0
- package/dist/assets/migrations/20260911120300_taxes.sql +146 -0
- package/dist/assets/migrations/20260911120400_entries.sql +338 -0
- package/dist/assets/migrations/20260911120500_documents.sql +279 -0
- package/dist/assets/migrations/20260911120600_payments_reconciliation.sql +251 -0
- package/dist/assets/migrations/20260911120700_bank.sql +178 -0
- package/dist/assets/migrations/20260911120800_analytics_attachments.sql +128 -0
- package/dist/assets/migrations/20260911120900_post_document.sql +279 -0
- package/dist/assets/migrations/20260911121000_reporting.sql +235 -0
- package/dist/assets/migrations/20260911121100_country_templates.sql +226 -0
- package/dist/assets/migrations/20260911121200_fec.sql +71 -0
- package/dist/assets/migrations/20260911130000_instance.sql +77 -0
- package/dist/assets/migrations/20260911130100_instance_members.sql +224 -0
- package/dist/assets/migrations/20260911140000_instance_admins.sql +112 -0
- package/dist/assets/migrations/20260911160000_tax_posting_templates_unique.sql +17 -0
- package/dist/assets/migrations/20260911170000_document_amount_paid.sql +82 -0
- package/dist/assets/migrations/20260911173000_post_payment.sql +122 -0
- package/dist/assets/migrations/20260911173100_sequence_counters_under_rls.sql +84 -0
- package/dist/assets/migrations/20260911183000_country_journal_defaults.sql +143 -0
- package/dist/assets/migrations/20260911193853_line_account_defaults.sql +274 -0
- package/dist/assets/migrations/20260911195054_products.sql +221 -0
- package/dist/assets/migrations/20260911210131_anon_surface.sql +85 -0
- package/dist/assets/migrations/20260912074712_country_packs.sql +318 -0
- package/dist/assets/migrations/20260912080311_report_code_and_region.sql +198 -0
- package/dist/assets/migrations/20260912081014_pack_certification_maintained.sql +31 -0
- package/dist/assets/migrations/20260912081015_pack_certification_backfill.sql +16 -0
- package/dist/assets/migrations/20260912090407_tax_report_boxes.sql +329 -0
- package/dist/assets/migrations/20260912091917_tax_on_base_value.sql +25 -0
- package/dist/assets/migrations/20260912091918_tax_engine_columns.sql +776 -0
- package/dist/assets/migrations/20260912094412_opening_and_closing.sql +759 -0
- package/dist/assets/migrations/20260912095825_charts_of_accounts.sql +326 -0
- package/dist/assets/migrations/20260912100412_financial_statements.sql +632 -0
- package/dist/assets/migrations/20260912104719_one_formula_evaluator.sql +209 -0
- package/dist/assets/migrations/20260912105720_entry_kind_appropriation.sql +26 -0
- package/dist/assets/migrations/20260912105721_appropriation_entry_kind.sql +444 -0
- package/dist/assets/migrations/20260912111751_document_rules.sql +274 -0
- package/dist/assets/migrations/20260912112132_cash_basis_vat_and_fx.sql +1189 -0
- package/dist/assets/migrations/20260913074512_modules.sql +493 -0
- package/dist/assets/migrations/20260913075903_asset_disposal_roles.sql +47 -0
- package/dist/assets/migrations/20260913083216_capabilities.sql +637 -0
- package/dist/assets/migrations/20260913083901_company_invitations.sql +262 -0
- package/dist/assets/migrations/20260913084402_user_preferences.sql +376 -0
- package/dist/assets/migrations/20260913084847_company_profile.sql +261 -0
- package/dist/assets/migrations/20260913085436_numbering_reads_the_pack.sql +235 -0
- package/dist/assets/migrations/20260913085932_api_keys.sql +303 -0
- package/dist/assets/migrations/20260913090216_fiscal_year_bounds.sql +159 -0
- package/dist/assets/migrations/20260913092527_entries_import.sql +219 -0
- package/dist/assets/migrations/20260913101536_null_safe_guards.sql +188 -0
- package/dist/assets/migrations/20260913102115_installer_is_named.sql +462 -0
- package/dist/assets/migrations/20260913102758_no_currency_default.sql +138 -0
- package/dist/assets/migrations/20260913103355_cash_basis_needs_a_box.sql +453 -0
- package/dist/assets/migrations/20260913104014_aged_balance_named_group.sql +79 -0
- package/dist/assets/migrations/20260913104232_foreign_key_indexes.sql +144 -0
- package/dist/assets/migrations/20260913105120_declared_no_reader.sql +41 -0
- package/dist/assets/migrations/20260913111407_pack_languages.sql +223 -0
- package/dist/assets/migrations/20260913112233_schema_comments_for_a_reader.sql +27 -0
- package/dist/assets/migrations/20260913114535_fec_opening_balances.sql +307 -0
- package/dist/assets/migrations/20260914103412_audit_log.sql +509 -0
- package/dist/assets/migrations/20260914111907_pack_upgrade.sql +428 -0
- package/dist/assets/migrations/20260914120500_rounding_reads_the_currency.sql +206 -0
- package/dist/assets/migrations/20260914121200_amounts_round_at_the_currency.sql +2403 -0
- package/dist/assets/migrations/20260914134325_schema_version_0_2_0.sql +36 -0
- package/dist/assets/migrations/20260914143915_accounts_in_use.sql +428 -0
- package/dist/assets/migrations/20260914144731_account_code_frozen.sql +99 -0
- package/dist/assets/migrations/20260914151207_schema_grants_its_own_rights.sql +284 -0
- package/dist/assets/migrations/20260914152840_pack_upgrade_records_its_own_line.sql +237 -0
- package/dist/assets/migrations/20260914163943_declaration_periodicity.sql +349 -0
- package/dist/assets/migrations/20260915094000_foreign_services_received.sql +37 -0
- package/dist/assets/migrations/20260915094500_mentions_read_a_foreign_service.sql +72 -0
- package/dist/assets/migrations/20260915153000_document_shares.sql +568 -0
- package/dist/assets/migrations/20260915160000_ec_sales_list.sql +181 -0
- package/dist/assets/migrations/20260915161842_pack_sources.sql +56 -0
- package/dist/assets/migrations/20260915170500_schema_version_0_3_0.sql +45 -0
- package/dist/assets/migrations/20260915174500_a_vat_category_is_a_code.sql +177 -0
- package/dist/assets/migrations/20260915180000_document_rule_references.sql +85 -0
- package/dist/assets/migrations/20260915181000_territories.sql +342 -0
- package/dist/assets/migrations/20260915181500_ec_sales_list_reads_the_territories.sql +222 -0
- package/dist/assets/migrations/20260915182000_intracom_triangular.sql +53 -0
- package/dist/assets/migrations/20260915182500_a_triangular_supply_says_reverse_charge.sql +99 -0
- package/dist/assets/migrations/20260915191200_a_document_knows_its_language.sql +633 -0
- package/dist/assets/migrations/20260915195000_a_price_that_holds_its_tax.sql +649 -0
- package/dist/assets/migrations/20260915200000_a_posting_names_its_boxes.sql +1004 -0
- package/dist/assets/migrations/20260916094500_a_company_files_more_than_one_declaration.sql +795 -0
- package/dist/assets/migrations/20260916103000_a_ledger_line_names_its_posting.sql +902 -0
- package/dist/assets/migrations/20260916123000_a_vocabulary_for_a_tax_that_is_not_a_vat.sql +144 -0
- package/dist/assets/migrations/20260916124000_a_box_can_be_a_rate_of_a_box.sql +525 -0
- package/dist/assets/migrations/20260916125000_a_tax_follows_the_territory.sql +1318 -0
- package/dist/assets/migrations/20260916126000_a_tax_point_and_its_exception.sql +1211 -0
- package/dist/assets/migrations/20260917090000_a_counterparty_that_learns.sql +561 -0
- package/dist/assets/migrations/20260917120000_what_the_money_pays.sql +545 -0
- package/dist/assets/migrations/20260917150000_a_filing_is_a_row.sql +488 -0
- package/dist/assets/migrations/20260917170000_when_it_is_due.sql +194 -0
- package/dist/assets/migrations/20260917180000_a_box_is_a_number_and_a_kind.sql +213 -0
- package/dist/assets/migrations/20260917190000_what_a_declaration_owes.sql +486 -0
- package/dist/assets/migrations/20260917200000_what_moved_after_it_went.sql +227 -0
- package/dist/assets/migrations/20260918090000_a_form_names_its_file.sql +27 -0
- package/dist/assets/migrations/20260918110000_a_deposit_and_what_came_back.sql +286 -0
- package/dist/assets/migrations/20260918113741_a_fourth_preset_is_named.sql +9 -0
- package/dist/assets/migrations/20260918113807_a_client_reads_and_hands_over.sql +96 -0
- package/dist/assets/migrations/20260918114322_two_definer_functions_check_their_caller.sql +75 -0
- package/dist/assets/migrations/20260918130000_every_company_somebody_keeps.sql +177 -0
- package/dist/assets/migrations/20260918140000_a_session_nobody_prepared.sql +40 -0
- package/dist/assets/migrations/20260918141107_a_line_keeps_the_tax_it_was_posted_with.sql +256 -0
- package/dist/assets/migrations/20260918141342_a_company_has_an_electronic_address.sql +66 -0
- package/dist/assets/migrations/20260918141605_an_invoice_reads_whole_from_the_views.sql +313 -0
- package/dist/assets/migrations/20260918141627_a_policy_asks_once.sql +132 -0
- package/dist/assets/migrations/20260918143352_a_suggestion_reads_the_words_once.sql +204 -0
- package/dist/assets/migrations/20260918143417_a_reference_of_the_caller_and_a_rehearsal.sql +115 -0
- package/dist/assets/migrations/20260918150712_a_company_leaves_with_its_books.sql +1119 -0
- package/dist/assets/migrations/20260918150931_a_statement_is_imported_once.sql +654 -0
- package/dist/assets/migrations/20260918161204_a_posted_document_does_not_move.sql +437 -0
- package/dist/assets/migrations/20260918161538_a_posted_entry_does_not_move.sql +252 -0
- package/dist/assets/migrations/20260918171946_an_entry_is_posted_by_post_entry.sql +289 -0
- package/dist/assets/migrations/20260918174312_schema_version_0_4_0.sql +53 -0
- package/dist/assets/modules/assets/module.json +13 -0
- package/dist/assets/modules/assets/supabase/migrations/20260913081447_assets.sql +1190 -0
- package/dist/assets/modules/assets/supabase/migrations/20260913104234_foreign_key_indexes.sql +47 -0
- package/dist/assets/modules/assets/supabase/migrations/20260913104500_assets_capabilities.sql +145 -0
- package/dist/assets/modules/assets/supabase/migrations/20260914122100_assets_round_at_the_currency.sql +564 -0
- package/dist/assets/modules/assets/supabase/migrations/20260914145012_assets_accounts_in_use.sql +37 -0
- package/dist/assets/modules/assets/supabase/migrations/20260914151530_assets_grants_its_own_rights.sql +63 -0
- package/dist/assets/modules/assets/supabase/migrations/20260918113912_assets_client_reads.sql +20 -0
- package/dist/assets/modules/assets/supabase/migrations/20260918150801_assets_leave_with_the_company.sql +41 -0
- package/dist/assets/modules/budgets/module.json +12 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260913083012_budgets.sql +210 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260913104233_foreign_key_indexes.sql +37 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260913104501_budgets_capabilities.sql +72 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260914122400_budgets_round_at_the_currency.sql +68 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260914145048_budgets_accounts_in_use.sql +30 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260914151812_budgets_grants_its_own_rights.sql +31 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260918113954_budgets_client_reads.sql +20 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260918150823_budgets_leave_with_the_company.sql +37 -0
- package/dist/assets/modules/schema/module.1.json +69 -0
- package/dist/assets/seed/00_currencies.sql +15 -0
- package/dist/assets/seed/00_territories.sql +280 -0
- package/dist/assets/seed/05_framework_generic.sql +110 -0
- package/dist/assets/seed/10_pack_be.sql +1284 -0
- package/dist/assets/seed/11_pack_fr.sql +1112 -0
- package/dist/assets/seed/12_pack_lu.sql +2484 -0
- package/dist/assets/seed/13_pack_ee.sql +733 -0
- package/dist/assets/seed/14_pack_gb.sql +796 -0
- package/dist/assets/seed/15_pack_us.sql +751 -0
- package/dist/assets/seed/90_demo_company.sql +368 -0
- package/dist/assets/seed/modules/assets/10_pack_be.sql +58 -0
- package/dist/assets/seed/modules/assets/11_pack_fr.sql +57 -0
- package/dist/assets/seed/modules/assets/14_pack_gb.sql +58 -0
- package/dist/assets/seed/modules/assets/15_pack_us.sql +60 -0
- package/dist/auth.d.ts +59 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +134 -0
- package/dist/auth.js.map +1 -0
- package/dist/bin.d.ts +6 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +8 -0
- package/dist/bin.js.map +1 -0
- package/dist/books.d.ts +60 -0
- package/dist/books.d.ts.map +1 -0
- package/dist/books.js +168 -0
- package/dist/books.js.map +1 -0
- package/dist/bootstrap.d.ts +236 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +459 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/bundle.d.ts +27 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +47 -0
- package/dist/bundle.js.map +1 -0
- package/dist/checklist.d.ts +35 -0
- package/dist/checklist.d.ts.map +1 -0
- package/dist/checklist.js +64 -0
- package/dist/checklist.js.map +1 -0
- package/dist/cli.d.ts +14 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +318 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/company.d.ts +59 -0
- package/dist/commands/company.d.ts.map +1 -0
- package/dist/commands/company.js +287 -0
- package/dist/commands/company.js.map +1 -0
- package/dist/commands/contact.d.ts +9 -0
- package/dist/commands/contact.d.ts.map +1 -0
- package/dist/commands/contact.js +82 -0
- package/dist/commands/contact.js.map +1 -0
- package/dist/commands/demo.d.ts +19 -0
- package/dist/commands/demo.d.ts.map +1 -0
- package/dist/commands/demo.js +72 -0
- package/dist/commands/demo.js.map +1 -0
- package/dist/commands/doctor.d.ts +12 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +68 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/document.d.ts +17 -0
- package/dist/commands/document.d.ts.map +1 -0
- package/dist/commands/document.js +217 -0
- package/dist/commands/document.js.map +1 -0
- package/dist/commands/init.d.ts +31 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +535 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/login.d.ts +24 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +128 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/migrate.d.ts +30 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +115 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/module.d.ts +32 -0
- package/dist/commands/module.d.ts.map +1 -0
- package/dist/commands/module.js +285 -0
- package/dist/commands/module.js.map +1 -0
- package/dist/commands/pack.d.ts +22 -0
- package/dist/commands/pack.d.ts.map +1 -0
- package/dist/commands/pack.js +481 -0
- package/dist/commands/pack.js.map +1 -0
- package/dist/commands/payment.d.ts +15 -0
- package/dist/commands/payment.d.ts.map +1 -0
- package/dist/commands/payment.js +97 -0
- package/dist/commands/payment.js.map +1 -0
- package/dist/commands/register.d.ts +20 -0
- package/dist/commands/register.d.ts.map +1 -0
- package/dist/commands/register.js +134 -0
- package/dist/commands/register.js.map +1 -0
- package/dist/commands/status.d.ts +8 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +134 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/whoami.d.ts +21 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +133 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/company.d.ts +16 -0
- package/dist/company.d.ts.map +1 -0
- package/dist/company.js +26 -0
- package/dist/company.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +50 -0
- package/dist/config.js.map +1 -0
- package/dist/connection.d.ts +79 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +116 -0
- package/dist/connection.js.map +1 -0
- package/dist/context.d.ts +47 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +93 -0
- package/dist/context.js.map +1 -0
- package/dist/doctor.d.ts +45 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +448 -0
- package/dist/doctor.js.map +1 -0
- package/dist/grants.d.ts +88 -0
- package/dist/grants.d.ts.map +1 -0
- package/dist/grants.js +174 -0
- package/dist/grants.js.map +1 -0
- package/dist/identity.d.ts +54 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +132 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/inventory.d.ts +155 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +303 -0
- package/dist/inventory.js.map +1 -0
- package/dist/migrations.d.ts +76 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +226 -0
- package/dist/migrations.js.map +1 -0
- package/dist/module/read.d.ts +91 -0
- package/dist/module/read.d.ts.map +1 -0
- package/dist/module/read.js +172 -0
- package/dist/module/read.js.map +1 -0
- package/dist/output.d.ts +110 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +173 -0
- package/dist/output.js.map +1 -0
- package/dist/pack/certification.d.ts +27 -0
- package/dist/pack/certification.d.ts.map +1 -0
- package/dist/pack/certification.js +38 -0
- package/dist/pack/certification.js.map +1 -0
- package/dist/pack/compile.d.ts +75 -0
- package/dist/pack/compile.d.ts.map +1 -0
- package/dist/pack/compile.js +801 -0
- package/dist/pack/compile.js.map +1 -0
- package/dist/pack/filing.d.ts +48 -0
- package/dist/pack/filing.d.ts.map +1 -0
- package/dist/pack/filing.js +56 -0
- package/dist/pack/filing.js.map +1 -0
- package/dist/pack/read.d.ts +766 -0
- package/dist/pack/read.d.ts.map +1 -0
- package/dist/pack/read.js +2336 -0
- package/dist/pack/read.js.map +1 -0
- package/dist/pack/schema.d.ts +26 -0
- package/dist/pack/schema.d.ts.map +1 -0
- package/dist/pack/schema.js +181 -0
- package/dist/pack/schema.js.map +1 -0
- package/dist/pack/territories.d.ts +98 -0
- package/dist/pack/territories.d.ts.map +1 -0
- package/dist/pack/territories.js +0 -0
- package/dist/pack/territories.js.map +1 -0
- package/dist/pack/upgrade.d.ts +86 -0
- package/dist/pack/upgrade.d.ts.map +1 -0
- package/dist/pack/upgrade.js +76 -0
- package/dist/pack/upgrade.js.map +1 -0
- package/dist/pack/vat-codes.d.ts +273 -0
- package/dist/pack/vat-codes.d.ts.map +1 -0
- package/dist/pack/vat-codes.js +513 -0
- package/dist/pack/vat-codes.js.map +1 -0
- package/dist/profiles.d.ts +67 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/profiles.js +187 -0
- package/dist/profiles.js.map +1 -0
- package/dist/prompt.d.ts +40 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +120 -0
- package/dist/prompt.js.map +1 -0
- package/dist/registry.d.ts +84 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +104 -0
- package/dist/registry.js.map +1 -0
- package/dist/rest.d.ts +81 -0
- package/dist/rest.d.ts.map +1 -0
- package/dist/rest.js +245 -0
- package/dist/rest.js.map +1 -0
- package/dist/schema.d.ts +15 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +15 -0
- package/dist/schema.js.map +1 -0
- package/dist/seeds.d.ts +27 -0
- package/dist/seeds.d.ts.map +1 -0
- package/dist/seeds.js +47 -0
- package/dist/seeds.js.map +1 -0
- package/dist/session.d.ts +39 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +92 -0
- package/dist/session.js.map +1 -0
- package/dist/sql.d.ts +48 -0
- package/dist/sql.d.ts.map +1 -0
- package/dist/sql.js +112 -0
- package/dist/sql.js.map +1 -0
- package/dist/status.d.ts +94 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +120 -0
- package/dist/status.js.map +1 -0
- package/dist/ui.d.ts +55 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +114 -0
- package/dist/ui.js.map +1 -0
- package/package.json +29 -0
- package/schema/output.1.json +613 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
-- Ekwo OS — United States: how this country depreciates and derecognises a fixed asset.
|
|
2
|
+
--
|
|
3
|
+
-- Generated from packs/us/assets.json at version 0.5.0, do not edit.
|
|
4
|
+
-- Change the pack and run `ekwo pack build us`; `ekwo pack check --all`
|
|
5
|
+
-- refuses a seed that is not the exact output of its pack, and the CI runs it.
|
|
6
|
+
--
|
|
7
|
+
-- Applied by the module migration runner — `ekwo migrate`, or `ekwo module
|
|
8
|
+
-- migrate` — and never by the socle seed step: these tables exist only on an
|
|
9
|
+
-- installation that carries the `assets` module.
|
|
10
|
+
--
|
|
11
|
+
-- The accounts a disposal lands on are not here. They are roles of the chart,
|
|
12
|
+
-- in `country_defaults`, written by the pack seed beside every other role.
|
|
13
|
+
|
|
14
|
+
insert into assets.country_rules
|
|
15
|
+
(country, prorata_straight_line, prorata_declining, day_count,
|
|
16
|
+
declining_cap_percent, declining_switch_to_linear, disposal_style, legal_reference)
|
|
17
|
+
values
|
|
18
|
+
('US', 'months', 'months', 'actual', null, true, 'net_result', 'FASB Accounting Standards Codification topic 360 — depreciation begins when an asset is ready for its intended use, so the charge runs from the month the asset is placed in service and not for the whole of the first year. The Codification prescribes no method and names the straight line, the units of production and the declining balance among those an entity may select, so nothing here caps a declining rate. What this section is **not** is the Modified Accelerated Cost Recovery System: the Internal Revenue Service''s conventions — the half-year convention, the mid-quarter convention, the mid-month convention for real property — belong to a tax return and never to the books. A company that keeps both keeps two sets of figures for one asset, and the module carries one; the gap is written up in docs/international.md.')
|
|
19
|
+
on conflict (country) do update set
|
|
20
|
+
prorata_straight_line = excluded.prorata_straight_line,
|
|
21
|
+
prorata_declining = excluded.prorata_declining,
|
|
22
|
+
day_count = excluded.day_count,
|
|
23
|
+
declining_cap_percent = excluded.declining_cap_percent,
|
|
24
|
+
declining_switch_to_linear = excluded.declining_switch_to_linear,
|
|
25
|
+
disposal_style = excluded.disposal_style,
|
|
26
|
+
legal_reference = excluded.legal_reference;
|
|
27
|
+
|
|
28
|
+
insert into assets.category_templates
|
|
29
|
+
(country, code, name, name_i18n, method, duration_months, coefficient,
|
|
30
|
+
prorata, account_type, sequence, legal_reference)
|
|
31
|
+
select v.country::char(2), v.code, v.name, v.name_i18n::jsonb,
|
|
32
|
+
v.method::assets.depreciation_method, v.duration_months::integer,
|
|
33
|
+
v.coefficient::numeric, v.prorata::assets.prorata_rule,
|
|
34
|
+
v.account_type::account_type, v.sequence::integer, v.legal_reference
|
|
35
|
+
from (values
|
|
36
|
+
('US', 'goodwill', 'Goodwill', '{}'::jsonb, 'straight_line', 120, null, null, 'asset_fixed', 10, 'A public business entity does not amortise goodwill at all under the Codification: it tests it for impairment. A private company that has elected the accounting alternative of topic 350 amortises it over ten years or less, and this category is that election. There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
37
|
+
('US', 'intangibles', 'Other intangible assets, patents and licences', '{}'::jsonb, 'straight_line', 60, null, null, 'asset_fixed', 20, 'An intangible asset with a finite useful life is amortised over that life under topic 350; one with an indefinite life is not amortised and is tested for impairment instead, and no category of this section can express that. There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
38
|
+
('US', 'buildings', 'Buildings', '{}'::jsonb, 'straight_line', 468, null, null, 'asset_fixed', 30, 'Land is not depreciated and the building on it is, so a property is split before this category reaches the part that has a life. Thirty-nine years is the figure American practice reaches for most commercial buildings, and it is worth saying out loud that it is also the recovery period MACRS gives to non-residential real property: the two agree by habit and not by rule, and nothing makes the accounting life follow the tax one. There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
39
|
+
('US', 'building-improvements', 'Building improvements', '{}'::jsonb, 'straight_line', 180, null, null, 'asset_fixed', 40, 'There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
40
|
+
('US', 'leasehold-improvements', 'Leasehold improvements', '{}'::jsonb, 'straight_line', 120, null, null, 'asset_fixed', 50, 'Practice amortises a leasehold improvement over the shorter of its own life and the remaining term of the lease, which is a fact about the lease and not about the category. There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
41
|
+
('US', 'machinery-and-equipment', 'Machinery and equipment', '{}'::jsonb, 'straight_line', 120, null, null, 'asset_fixed', 60, 'There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
42
|
+
('US', 'furniture-and-fixtures', 'Furniture and fixtures', '{}'::jsonb, 'straight_line', 84, null, null, 'asset_fixed', 70, 'There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
43
|
+
('US', 'computer-equipment', 'Computer equipment', '{}'::jsonb, 'straight_line', 36, null, null, 'asset_fixed', 80, 'There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
44
|
+
('US', 'computer-software', 'Computer software', '{}'::jsonb, 'straight_line', 36, null, null, 'asset_fixed', 90, 'There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
45
|
+
('US', 'vehicles', 'Vehicles, straight line', '{}'::jsonb, 'straight_line', 60, null, null, 'asset_fixed', 100, 'There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
46
|
+
('US', 'vehicles-declining', 'Vehicles, declining balance at 40 per cent', '{}'::jsonb, 'declining_balance', 60, 2, null, 'asset_fixed', 110, 'Twice the straight-line rate of a five-year life is forty per cent a year, which is the double-declining balance American practice applies to a vehicle most often, with a switch to the straight line when that gives the larger charge. There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.'),
|
|
47
|
+
('US', 'right-of-use-assets', 'Right-of-use assets', '{}'::jsonb, 'straight_line', 120, null, null, 'asset_fixed', 120, 'A right-of-use asset arising from a lease is amortised over the lease term under topic 842, and the term is a fact about the contract rather than about a class of asset. There is no legal or fiscal table of useful lives in the United States. FASB Accounting Standards Codification topic 360, Property, Plant, and Equipment, requires the depreciable amount of a long-lived asset to be allocated over its useful life on a systematic and rational basis, and leaves that life to the entity to estimate and to review. What the Internal Revenue Service publishes — the Modified Accelerated Cost Recovery System of Publication 946, with its three, five, seven, ten, fifteen, twenty, twenty-seven-and-a-half and thirty-nine year recovery periods, its half-year and mid-quarter conventions and its two declining-balance rates — is a tax computation and is never the accounting charge. **This category is not MACRS.** The duration below is common American practice, and an asset that depreciates differently says so in its own columns.')
|
|
48
|
+
) as v (country, code, name, name_i18n, method, duration_months, coefficient,
|
|
49
|
+
prorata, account_type, sequence, legal_reference)
|
|
50
|
+
on conflict (country, code) do update set
|
|
51
|
+
name = excluded.name,
|
|
52
|
+
name_i18n = excluded.name_i18n,
|
|
53
|
+
method = excluded.method,
|
|
54
|
+
duration_months = excluded.duration_months,
|
|
55
|
+
coefficient = excluded.coefficient,
|
|
56
|
+
prorata = excluded.prorata,
|
|
57
|
+
account_type = excluded.account_type,
|
|
58
|
+
sequence = excluded.sequence,
|
|
59
|
+
legal_reference = excluded.legal_reference;
|
|
60
|
+
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first administrator, created through Supabase Auth.
|
|
3
|
+
*
|
|
4
|
+
* Why the CLI cannot do this in SQL. Every policy in the schema compares
|
|
5
|
+
* `auth.uid()` against a row, and `auth.uid()` reads the JWT of the request.
|
|
6
|
+
* The CLI holds a Postgres connection, not a session: it runs as the database
|
|
7
|
+
* owner, `auth.uid()` is NULL, and row level security is bypassed rather than
|
|
8
|
+
* satisfied. So it cannot *be* the first user; it can only create one and then
|
|
9
|
+
* write the rows that user will later be recognised by.
|
|
10
|
+
*
|
|
11
|
+
* Creating the user is also not something SQL can do honestly. `auth.users`
|
|
12
|
+
* belongs to GoTrue — the password hash, the confirmation state, the identity
|
|
13
|
+
* row. Writing it by hand produces an account that looks right and cannot sign
|
|
14
|
+
* in. The admin API is the supported way, and it needs the service_role key.
|
|
15
|
+
*
|
|
16
|
+
* Order, therefore: create the user through GoTrue, take its id, then insert
|
|
17
|
+
* `instance_admins` and the rest over the Postgres connection.
|
|
18
|
+
*
|
|
19
|
+
* `fetch` is a parameter so the tests can drive every branch — created,
|
|
20
|
+
* already exists, invite link, network down — without a Supabase project.
|
|
21
|
+
*/
|
|
22
|
+
export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
23
|
+
export interface AuthUser {
|
|
24
|
+
id: string;
|
|
25
|
+
email: string;
|
|
26
|
+
/** Set when the user was created without a password: send them this link. */
|
|
27
|
+
actionLink?: string;
|
|
28
|
+
/** False when the account was already there and we simply looked it up. */
|
|
29
|
+
created: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface CreateAuthUserOptions {
|
|
32
|
+
supabaseUrl: string;
|
|
33
|
+
serviceRoleKey: string;
|
|
34
|
+
email: string;
|
|
35
|
+
/** Omitted: an invite link is generated instead of a password being set. */
|
|
36
|
+
password?: string | undefined;
|
|
37
|
+
fetchImpl?: FetchLike;
|
|
38
|
+
}
|
|
39
|
+
/** How the bootstrap gets a user id. Injected, so tests never hit the network. */
|
|
40
|
+
export type CreateAuthUser = (options: CreateAuthUserOptions) => Promise<AuthUser>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates the first administrator in the customer's own Supabase Auth.
|
|
43
|
+
*
|
|
44
|
+
* With a password: the account is created confirmed, so they can sign in at
|
|
45
|
+
* once. Without: GoTrue generates an invite link, the account exists with no
|
|
46
|
+
* password, and the link is what the CLI prints.
|
|
47
|
+
*
|
|
48
|
+
* An address that already has an account is not an error. The CLI looks the
|
|
49
|
+
* user up and carries on, which is what makes `ekwo init` safe to re-run.
|
|
50
|
+
*/
|
|
51
|
+
export declare const createAuthUser: CreateAuthUser;
|
|
52
|
+
/** Looks an account up by address through the admin API. */
|
|
53
|
+
export declare function findAuthUserByEmail({ supabaseUrl, serviceRoleKey, email, fetchImpl, }: {
|
|
54
|
+
supabaseUrl: string;
|
|
55
|
+
serviceRoleKey: string;
|
|
56
|
+
email: string;
|
|
57
|
+
fetchImpl?: FetchLike;
|
|
58
|
+
}): Promise<AuthUser | undefined>;
|
|
59
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEjF,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,kFAAkF;AAClF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AA6BnF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,EAAE,cAwE5B,CAAC;AAEF,4DAA4D;AAC5D,wBAAsB,mBAAmB,CAAC,EACxC,WAAW,EACX,cAAc,EACd,KAAK,EACL,SAA4B,GAC7B,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAiBhC"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first administrator, created through Supabase Auth.
|
|
3
|
+
*
|
|
4
|
+
* Why the CLI cannot do this in SQL. Every policy in the schema compares
|
|
5
|
+
* `auth.uid()` against a row, and `auth.uid()` reads the JWT of the request.
|
|
6
|
+
* The CLI holds a Postgres connection, not a session: it runs as the database
|
|
7
|
+
* owner, `auth.uid()` is NULL, and row level security is bypassed rather than
|
|
8
|
+
* satisfied. So it cannot *be* the first user; it can only create one and then
|
|
9
|
+
* write the rows that user will later be recognised by.
|
|
10
|
+
*
|
|
11
|
+
* Creating the user is also not something SQL can do honestly. `auth.users`
|
|
12
|
+
* belongs to GoTrue — the password hash, the confirmation state, the identity
|
|
13
|
+
* row. Writing it by hand produces an account that looks right and cannot sign
|
|
14
|
+
* in. The admin API is the supported way, and it needs the service_role key.
|
|
15
|
+
*
|
|
16
|
+
* Order, therefore: create the user through GoTrue, take its id, then insert
|
|
17
|
+
* `instance_admins` and the rest over the Postgres connection.
|
|
18
|
+
*
|
|
19
|
+
* `fetch` is a parameter so the tests can drive every branch — created,
|
|
20
|
+
* already exists, invite link, network down — without a Supabase project.
|
|
21
|
+
*/
|
|
22
|
+
function authBase(supabaseUrl) {
|
|
23
|
+
return `${supabaseUrl.replace(/\/+$/, '')}/auth/v1`;
|
|
24
|
+
}
|
|
25
|
+
function headers(serviceRoleKey) {
|
|
26
|
+
return {
|
|
27
|
+
apikey: serviceRoleKey,
|
|
28
|
+
Authorization: `Bearer ${serviceRoleKey}`,
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async function readBody(response) {
|
|
33
|
+
const text = await response.text();
|
|
34
|
+
if (text.trim().length === 0)
|
|
35
|
+
return {};
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(text);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return { message: text };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function describe(body, status) {
|
|
44
|
+
const message = body['msg'] ?? body['message'] ?? body['error_description'] ?? body['error'];
|
|
45
|
+
return typeof message === 'string' ? message : `HTTP ${status}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates the first administrator in the customer's own Supabase Auth.
|
|
49
|
+
*
|
|
50
|
+
* With a password: the account is created confirmed, so they can sign in at
|
|
51
|
+
* once. Without: GoTrue generates an invite link, the account exists with no
|
|
52
|
+
* password, and the link is what the CLI prints.
|
|
53
|
+
*
|
|
54
|
+
* An address that already has an account is not an error. The CLI looks the
|
|
55
|
+
* user up and carries on, which is what makes `ekwo init` safe to re-run.
|
|
56
|
+
*/
|
|
57
|
+
export const createAuthUser = async ({ supabaseUrl, serviceRoleKey, email, password, fetchImpl = globalThis.fetch, }) => {
|
|
58
|
+
const base = authBase(supabaseUrl);
|
|
59
|
+
if (password === undefined || password.length === 0) {
|
|
60
|
+
const response = await fetchImpl(`${base}/admin/generate_link`, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: headers(serviceRoleKey),
|
|
63
|
+
body: JSON.stringify({ type: 'invite', email }),
|
|
64
|
+
});
|
|
65
|
+
const body = await readBody(response);
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(`auth_invite_failed: ${describe(body, response.status)}`);
|
|
68
|
+
}
|
|
69
|
+
const id = body['user_id'] ?? body['user']?.['id'];
|
|
70
|
+
if (typeof id !== 'string') {
|
|
71
|
+
throw new Error('auth_invite_failed: Supabase Auth returned no user id');
|
|
72
|
+
}
|
|
73
|
+
const link = body['action_link'];
|
|
74
|
+
return {
|
|
75
|
+
id,
|
|
76
|
+
email,
|
|
77
|
+
created: true,
|
|
78
|
+
...(typeof link === 'string' ? { actionLink: link } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const response = await fetchImpl(`${base}/admin/users`, {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
headers: headers(serviceRoleKey),
|
|
84
|
+
body: JSON.stringify({ email, password, email_confirm: true }),
|
|
85
|
+
});
|
|
86
|
+
const body = await readBody(response);
|
|
87
|
+
if (response.ok) {
|
|
88
|
+
const id = body['id'];
|
|
89
|
+
if (typeof id !== 'string') {
|
|
90
|
+
throw new Error('auth_create_failed: Supabase Auth returned no user id');
|
|
91
|
+
}
|
|
92
|
+
return { id, email, created: true };
|
|
93
|
+
}
|
|
94
|
+
// 422 email_exists, or a 400 from an older GoTrue saying the same thing.
|
|
95
|
+
const message = describe(body, response.status).toLowerCase();
|
|
96
|
+
const alreadyThere = body['error_code'] === 'email_exists' ||
|
|
97
|
+
message.includes('already been registered') ||
|
|
98
|
+
message.includes('already registered') ||
|
|
99
|
+
message.includes('already exists');
|
|
100
|
+
if (!alreadyThere) {
|
|
101
|
+
throw new Error(`auth_create_failed: ${describe(body, response.status)}`);
|
|
102
|
+
}
|
|
103
|
+
const existing = await findAuthUserByEmail({
|
|
104
|
+
supabaseUrl,
|
|
105
|
+
serviceRoleKey,
|
|
106
|
+
email,
|
|
107
|
+
fetchImpl,
|
|
108
|
+
});
|
|
109
|
+
if (existing === undefined) {
|
|
110
|
+
throw new Error(`auth_create_failed: ${email} already has an account but it could not be read back. ` +
|
|
111
|
+
'Pass --admin-user-id with its id from the Supabase dashboard.');
|
|
112
|
+
}
|
|
113
|
+
return { ...existing, created: false };
|
|
114
|
+
};
|
|
115
|
+
/** Looks an account up by address through the admin API. */
|
|
116
|
+
export async function findAuthUserByEmail({ supabaseUrl, serviceRoleKey, email, fetchImpl = globalThis.fetch, }) {
|
|
117
|
+
const url = `${authBase(supabaseUrl)}/admin/users?page=1&per_page=200&filter=${encodeURIComponent(email)}`;
|
|
118
|
+
const response = await fetchImpl(url, { headers: headers(serviceRoleKey) });
|
|
119
|
+
if (!response.ok)
|
|
120
|
+
return undefined;
|
|
121
|
+
const body = await readBody(response);
|
|
122
|
+
const users = body['users'];
|
|
123
|
+
if (!Array.isArray(users))
|
|
124
|
+
return undefined;
|
|
125
|
+
for (const candidate of users) {
|
|
126
|
+
if (typeof candidate['email'] === 'string' &&
|
|
127
|
+
candidate['email'].toLowerCase() === email.toLowerCase() &&
|
|
128
|
+
typeof candidate['id'] === 'string') {
|
|
129
|
+
return { id: candidate['id'], email: candidate['email'], created: false };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAyBH,SAAS,QAAQ,CAAC,WAAmB;IACnC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC;AACtD,CAAC;AAED,SAAS,OAAO,CAAC,cAAsB;IACrC,OAAO;QACL,MAAM,EAAE,cAAc;QACtB,aAAa,EAAE,UAAU,cAAc,EAAE;QACzC,cAAc,EAAE,kBAAkB;KACnC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,QAAkB;IACxC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAA4B,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,IAA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C,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE;YACxD,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,QAAQ,EACnC,CAAC;YACD,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC5E,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;GAEG"}
|
package/dist/bin.js
ADDED
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC"}
|
package/dist/books.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every bookkeeping verb starts with, and nothing about bookkeeping.
|
|
3
|
+
*
|
|
4
|
+
* A verb of this CLI is one function of `@ekwo-ai/core` — the function the MCP
|
|
5
|
+
* server calls for the tool of the same meaning — handed a `Backend` that
|
|
6
|
+
* speaks PostgREST as the person signed in. This file opens that backend,
|
|
7
|
+
* settles which company the verb runs on, and reads what the caller typed:
|
|
8
|
+
* flags, or one JSON document on the standard input. It passes values on as
|
|
9
|
+
* text. No amount is parsed, added or rounded on this side of the database,
|
|
10
|
+
* and `tests/cli/no-rules.test.ts` reads the commands to keep it that way.
|
|
11
|
+
*/
|
|
12
|
+
import type { Backend } from '@ekwo-ai/core';
|
|
13
|
+
import { type ParsedArgs } from './args.js';
|
|
14
|
+
import { type UserDeps } from './identity.js';
|
|
15
|
+
import type { CompanyRef } from './profiles.js';
|
|
16
|
+
/** The flags every bookkeeping verb accepts. */
|
|
17
|
+
export declare const BOOKS_FLAGS: readonly ["profile", "company", "supabase-url", "anon-key"];
|
|
18
|
+
/** And those of a verb that creates something. */
|
|
19
|
+
export declare const CREATE_FLAGS: readonly ["profile", "company", "supabase-url", "anon-key", "ref", "stdin"];
|
|
20
|
+
export interface BooksDeps extends UserDeps {
|
|
21
|
+
/** The standard input, when a test stands in for it. */
|
|
22
|
+
stdin?: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface Books {
|
|
25
|
+
backend: Backend;
|
|
26
|
+
company: CompanyRef;
|
|
27
|
+
}
|
|
28
|
+
/** Signs in as the person, settles the company, and says so in the document. */
|
|
29
|
+
export declare function openBooks(args: ParsedArgs, deps: BooksDeps): Promise<Books>;
|
|
30
|
+
/** An argument that has to be an id, refused here rather than by a cast in the database. */
|
|
31
|
+
export declare function uuidArg(value: string | undefined, what: string): string;
|
|
32
|
+
export declare function required(value: string | undefined, what: string, flag: string): string;
|
|
33
|
+
/** Today, as the machine running the command calls it. Printed wherever it is used. */
|
|
34
|
+
export declare function today(): string;
|
|
35
|
+
/**
|
|
36
|
+
* The JSON document on the standard input, under `--stdin`.
|
|
37
|
+
*
|
|
38
|
+
* The way in for a program: the fields are the ones the MCP tool of the same
|
|
39
|
+
* meaning takes, so an agent composes one object and escapes nothing. A field
|
|
40
|
+
* nobody defined is refused rather than dropped — `unit_prise` silently doing
|
|
41
|
+
* nothing is an invoice at the catalogue price. Flags given beside it win.
|
|
42
|
+
*/
|
|
43
|
+
export declare function stdinDocument(args: ParsedArgs, deps: BooksDeps, known: readonly string[]): Promise<Record<string, unknown>>;
|
|
44
|
+
export declare const LINE_FIELDS: readonly ["name", "description", "quantity", "unit_code", "unit_price", "discount_percent", "product_id", "product_code", "account_id", "account_code", "tax_id", "tax_code"];
|
|
45
|
+
/**
|
|
46
|
+
* `--line "name=Audit,price=1500.00,tax=<code>"` — named fields, never positions.
|
|
47
|
+
*
|
|
48
|
+
* The card offered `"Audit 1 500 EUR@21"` and asked for an arbitration. It is
|
|
49
|
+
* not shipped: "1 500" is one number or two, `@21` names a rate where the
|
|
50
|
+
* books need a tax — several taxes share a rate — and a currency belongs to
|
|
51
|
+
* the document, not to a line. Named fields cost a few characters and cannot
|
|
52
|
+
* be misread; a comma inside a value is written `\,`. Anything richer goes
|
|
53
|
+
* through `--stdin`, which is the form that is authoritative.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseLine(text: string): Record<string, string>;
|
|
56
|
+
/** Refuses a line from `--stdin` that carries a field nobody defined. */
|
|
57
|
+
export declare function checkedLines(value: unknown): Record<string, unknown>[];
|
|
58
|
+
/** Drops what was not given, so the core sees an absent field and not an undefined one. */
|
|
59
|
+
export declare function given<T extends Record<string, unknown>>(fields: T): T;
|
|
60
|
+
//# sourceMappingURL=books.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"books.d.ts","sourceRoot":"","sources":["../src/books.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAoC,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAiC,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,gDAAgD;AAChD,eAAO,MAAM,WAAW,6DAA8D,CAAC;AACvF,kDAAkD;AAClD,eAAO,MAAM,YAAY,6EAA4C,CAAC;AAEtE,MAAM,WAAW,SAAU,SAAQ,QAAQ;IACzC,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,KAAK;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,UAAU,CAAC;CACrB;AAED,gFAAgF;AAChF,wBAAsB,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAwBjF;AAID,4FAA4F;AAC5F,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIvE;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGtF;AAED,uFAAuF;AACvF,wBAAgB,KAAK,IAAI,MAAM,CAI9B;AAQD;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,SAAS,MAAM,EAAE,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAoBlC;AAED,eAAO,MAAM,WAAW,+KAad,CAAC;AAeX;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc9D;AAED,yEAAyE;AACzE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAYtE;AAED,2FAA2F;AAC3F,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAErE"}
|
package/dist/books.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every bookkeeping verb starts with, and nothing about bookkeeping.
|
|
3
|
+
*
|
|
4
|
+
* A verb of this CLI is one function of `@ekwo-ai/core` — the function the MCP
|
|
5
|
+
* server calls for the tool of the same meaning — handed a `Backend` that
|
|
6
|
+
* speaks PostgREST as the person signed in. This file opens that backend,
|
|
7
|
+
* settles which company the verb runs on, and reads what the caller typed:
|
|
8
|
+
* flags, or one JSON document on the standard input. It passes values on as
|
|
9
|
+
* text. No amount is parsed, added or rounded on this side of the database,
|
|
10
|
+
* and `tests/cli/no-rules.test.ts` reads the commands to keep it that way.
|
|
11
|
+
*/
|
|
12
|
+
import { UsageError, boolFlag, stringFlag } from './args.js';
|
|
13
|
+
import { matchCompany } from './company.js';
|
|
14
|
+
import { actAsUser, refuseInstallerKey } from './identity.js';
|
|
15
|
+
import { setContext } from './output.js';
|
|
16
|
+
/** The flags every bookkeeping verb accepts. */
|
|
17
|
+
export const BOOKS_FLAGS = ['profile', 'company', 'supabase-url', 'anon-key'];
|
|
18
|
+
/** And those of a verb that creates something. */
|
|
19
|
+
export const CREATE_FLAGS = [...BOOKS_FLAGS, 'ref', 'stdin'];
|
|
20
|
+
/** Signs in as the person, settles the company, and says so in the document. */
|
|
21
|
+
export async function openBooks(args, deps) {
|
|
22
|
+
refuseInstallerKey(args);
|
|
23
|
+
const acting = await actAsUser(args, deps);
|
|
24
|
+
const backend = acting.client.backend(undefined);
|
|
25
|
+
const instance = acting.client.instance.supabaseUrl;
|
|
26
|
+
const asked = stringFlag(args, 'company');
|
|
27
|
+
let company = acting.storedCompany;
|
|
28
|
+
if (asked !== undefined) {
|
|
29
|
+
const visible = await backend.select({
|
|
30
|
+
table: 'companies',
|
|
31
|
+
columns: ['id', 'name'],
|
|
32
|
+
order: [{ column: 'name' }],
|
|
33
|
+
});
|
|
34
|
+
const match = matchCompany(visible, asked);
|
|
35
|
+
company = { id: match.id, name: match.name };
|
|
36
|
+
}
|
|
37
|
+
setContext({ profile: acting.profile ?? null, instance, company: company ?? null });
|
|
38
|
+
if (company === undefined) {
|
|
39
|
+
throw new UsageError('no_company: no company is in use. Run `ekwo use <company>`, or pass --company. None is ever picked for you, not even the only one.');
|
|
40
|
+
}
|
|
41
|
+
return { backend, company };
|
|
42
|
+
}
|
|
43
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
44
|
+
/** An argument that has to be an id, refused here rather than by a cast in the database. */
|
|
45
|
+
export function uuidArg(value, what) {
|
|
46
|
+
if (value === undefined)
|
|
47
|
+
throw new UsageError(`missing_argument: ${what} was not given.`);
|
|
48
|
+
if (!UUID.test(value))
|
|
49
|
+
throw new UsageError(`bad_id: ${what} must be a uuid, got "${value}".`);
|
|
50
|
+
return value.toLowerCase();
|
|
51
|
+
}
|
|
52
|
+
export function required(value, what, flag) {
|
|
53
|
+
if (value === undefined)
|
|
54
|
+
throw new UsageError(`missing_argument: ${what} was not given. Pass ${flag}.`);
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
/** Today, as the machine running the command calls it. Printed wherever it is used. */
|
|
58
|
+
export function today() {
|
|
59
|
+
const now = new Date();
|
|
60
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
61
|
+
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
62
|
+
}
|
|
63
|
+
async function readAll() {
|
|
64
|
+
const chunks = [];
|
|
65
|
+
for await (const chunk of process.stdin)
|
|
66
|
+
chunks.push(Buffer.from(chunk));
|
|
67
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The JSON document on the standard input, under `--stdin`.
|
|
71
|
+
*
|
|
72
|
+
* The way in for a program: the fields are the ones the MCP tool of the same
|
|
73
|
+
* meaning takes, so an agent composes one object and escapes nothing. A field
|
|
74
|
+
* nobody defined is refused rather than dropped — `unit_prise` silently doing
|
|
75
|
+
* nothing is an invoice at the catalogue price. Flags given beside it win.
|
|
76
|
+
*/
|
|
77
|
+
export async function stdinDocument(args, deps, known) {
|
|
78
|
+
if (!boolFlag(args, 'stdin'))
|
|
79
|
+
return {};
|
|
80
|
+
if (deps.stdin === undefined && process.stdin.isTTY === true) {
|
|
81
|
+
throw new UsageError('missing_input: --stdin reads a JSON document from the standard input, and this is a terminal. Pipe one in.');
|
|
82
|
+
}
|
|
83
|
+
const text = deps.stdin ?? (await readAll());
|
|
84
|
+
let parsed;
|
|
85
|
+
try {
|
|
86
|
+
parsed = JSON.parse(text);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw new UsageError(`bad_json: the standard input is not JSON: ${error.message}`);
|
|
90
|
+
}
|
|
91
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
92
|
+
throw new UsageError('bad_json: the standard input must be one JSON object.');
|
|
93
|
+
}
|
|
94
|
+
const unknown = Object.keys(parsed).filter((key) => !known.includes(key));
|
|
95
|
+
if (unknown.length > 0) {
|
|
96
|
+
throw new UsageError(`unknown_field: ${unknown.join(', ')}. This command reads: ${known.join(', ')}.`);
|
|
97
|
+
}
|
|
98
|
+
return parsed;
|
|
99
|
+
}
|
|
100
|
+
export const LINE_FIELDS = [
|
|
101
|
+
'name',
|
|
102
|
+
'description',
|
|
103
|
+
'quantity',
|
|
104
|
+
'unit_code',
|
|
105
|
+
'unit_price',
|
|
106
|
+
'discount_percent',
|
|
107
|
+
'product_id',
|
|
108
|
+
'product_code',
|
|
109
|
+
'account_id',
|
|
110
|
+
'account_code',
|
|
111
|
+
'tax_id',
|
|
112
|
+
'tax_code',
|
|
113
|
+
];
|
|
114
|
+
/** The short keys `--line` accepts, and the field each one is. */
|
|
115
|
+
const LINE_KEYS = {
|
|
116
|
+
name: 'name',
|
|
117
|
+
description: 'description',
|
|
118
|
+
qty: 'quantity',
|
|
119
|
+
unit: 'unit_code',
|
|
120
|
+
price: 'unit_price',
|
|
121
|
+
discount: 'discount_percent',
|
|
122
|
+
product: 'product_code',
|
|
123
|
+
account: 'account_code',
|
|
124
|
+
tax: 'tax_code',
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* `--line "name=Audit,price=1500.00,tax=<code>"` — named fields, never positions.
|
|
128
|
+
*
|
|
129
|
+
* The card offered `"Audit 1 500 EUR@21"` and asked for an arbitration. It is
|
|
130
|
+
* not shipped: "1 500" is one number or two, `@21` names a rate where the
|
|
131
|
+
* books need a tax — several taxes share a rate — and a currency belongs to
|
|
132
|
+
* the document, not to a line. Named fields cost a few characters and cannot
|
|
133
|
+
* be misread; a comma inside a value is written `\,`. Anything richer goes
|
|
134
|
+
* through `--stdin`, which is the form that is authoritative.
|
|
135
|
+
*/
|
|
136
|
+
export function parseLine(text) {
|
|
137
|
+
const line = {};
|
|
138
|
+
for (const part of text.split(/(?<!\\),/)) {
|
|
139
|
+
const equals = part.indexOf('=');
|
|
140
|
+
const key = (equals === -1 ? part : part.slice(0, equals)).trim();
|
|
141
|
+
const field = LINE_KEYS[key];
|
|
142
|
+
if (equals === -1 || field === undefined) {
|
|
143
|
+
throw new UsageError(`bad_line: "${part.trim()}" is not key=value with a key among ${Object.keys(LINE_KEYS).join(', ')}. Example: --line "name=Audit,price=1500.00,tax=<tax code>".`);
|
|
144
|
+
}
|
|
145
|
+
line[field] = part.slice(equals + 1).trim().replace(/\\,/g, ',');
|
|
146
|
+
}
|
|
147
|
+
return line;
|
|
148
|
+
}
|
|
149
|
+
/** Refuses a line from `--stdin` that carries a field nobody defined. */
|
|
150
|
+
export function checkedLines(value) {
|
|
151
|
+
if (!Array.isArray(value))
|
|
152
|
+
throw new UsageError('bad_json: `lines` must be a list.');
|
|
153
|
+
return value.map((line, index) => {
|
|
154
|
+
if (typeof line !== 'object' || line === null || Array.isArray(line)) {
|
|
155
|
+
throw new UsageError(`bad_json: line ${index + 1} must be an object.`);
|
|
156
|
+
}
|
|
157
|
+
const unknown = Object.keys(line).filter((key) => !LINE_FIELDS.includes(key));
|
|
158
|
+
if (unknown.length > 0) {
|
|
159
|
+
throw new UsageError(`unknown_field: ${unknown.join(', ')} on line ${index + 1}. A line reads: ${LINE_FIELDS.join(', ')}.`);
|
|
160
|
+
}
|
|
161
|
+
return line;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/** Drops what was not given, so the core sees an absent field and not an undefined one. */
|
|
165
|
+
export function given(fields) {
|
|
166
|
+
return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined));
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=books.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"books.js","sourceRoot":"","sources":["../src/books.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAmB,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAiB,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,gDAAgD;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,CAAU,CAAC;AACvF,kDAAkD;AAClD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAG,WAAW,EAAE,KAAK,EAAE,OAAO,CAAU,CAAC;AAYtE,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAgB,EAAE,IAAe;IAC/D,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;IAEpD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,E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