@hasna/microservices 0.0.16 → 0.0.18
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 +143 -23
- package/bin/index.js +784 -13987
- package/bin/mcp.js +298 -10973
- package/dist/index.js +251 -10056
- package/package.json +36 -26
- package/microservices/microservice-ads/package.json +0 -28
- package/microservices/microservice-ads/src/cli/index.ts +0 -605
- package/microservices/microservice-ads/src/db/campaigns.ts +0 -797
- package/microservices/microservice-ads/src/db/database.ts +0 -91
- package/microservices/microservice-ads/src/db/migrations.ts +0 -60
- package/microservices/microservice-ads/src/index.ts +0 -39
- package/microservices/microservice-ads/src/mcp/index.ts +0 -480
- package/microservices/microservice-analytics/package.json +0 -28
- package/microservices/microservice-analytics/src/cli/index.ts +0 -373
- package/microservices/microservice-analytics/src/db/analytics.ts +0 -564
- package/microservices/microservice-analytics/src/db/database.ts +0 -91
- package/microservices/microservice-analytics/src/db/migrations.ts +0 -50
- package/microservices/microservice-analytics/src/index.ts +0 -37
- package/microservices/microservice-analytics/src/mcp/index.ts +0 -334
- package/microservices/microservice-assets/package.json +0 -28
- package/microservices/microservice-assets/src/cli/index.ts +0 -375
- package/microservices/microservice-assets/src/db/assets.ts +0 -370
- package/microservices/microservice-assets/src/db/database.ts +0 -91
- package/microservices/microservice-assets/src/db/migrations.ts +0 -51
- package/microservices/microservice-assets/src/index.ts +0 -32
- package/microservices/microservice-assets/src/mcp/index.ts +0 -346
- package/microservices/microservice-bookkeeping/package.json +0 -28
- package/microservices/microservice-bookkeeping/src/cli/index.ts +0 -386
- package/microservices/microservice-bookkeeping/src/db/bookkeeping.ts +0 -591
- package/microservices/microservice-bookkeeping/src/db/database.ts +0 -91
- package/microservices/microservice-bookkeeping/src/db/migrations.ts +0 -52
- package/microservices/microservice-bookkeeping/src/index.ts +0 -32
- package/microservices/microservice-bookkeeping/src/mcp/index.ts +0 -284
- package/microservices/microservice-calendar/package.json +0 -28
- package/microservices/microservice-calendar/src/cli/index.ts +0 -287
- package/microservices/microservice-calendar/src/db/calendar.ts +0 -328
- package/microservices/microservice-calendar/src/db/database.ts +0 -91
- package/microservices/microservice-calendar/src/db/migrations.ts +0 -47
- package/microservices/microservice-calendar/src/index.ts +0 -24
- package/microservices/microservice-calendar/src/mcp/index.ts +0 -226
- package/microservices/microservice-company/package.json +0 -28
- package/microservices/microservice-company/src/cli/index.ts +0 -1126
- package/microservices/microservice-company/src/db/company.ts +0 -854
- package/microservices/microservice-company/src/db/database.ts +0 -91
- package/microservices/microservice-company/src/db/migrations.ts +0 -214
- package/microservices/microservice-company/src/db/workflow-migrations.ts +0 -44
- package/microservices/microservice-company/src/index.ts +0 -60
- package/microservices/microservice-company/src/lib/audit.ts +0 -168
- package/microservices/microservice-company/src/lib/finance.ts +0 -299
- package/microservices/microservice-company/src/lib/settings.ts +0 -85
- package/microservices/microservice-company/src/lib/workflows.ts +0 -698
- package/microservices/microservice-company/src/mcp/index.ts +0 -991
- package/microservices/microservice-compliance/package.json +0 -28
- package/microservices/microservice-compliance/src/cli/index.ts +0 -467
- package/microservices/microservice-compliance/src/db/compliance.ts +0 -633
- package/microservices/microservice-compliance/src/db/database.ts +0 -91
- package/microservices/microservice-compliance/src/db/migrations.ts +0 -63
- package/microservices/microservice-compliance/src/index.ts +0 -46
- package/microservices/microservice-compliance/src/mcp/index.ts +0 -438
- package/microservices/microservice-contacts/package.json +0 -28
- package/microservices/microservice-contacts/src/cli/index.ts +0 -393
- package/microservices/microservice-contacts/src/db/companies.ts +0 -167
- package/microservices/microservice-contacts/src/db/contacts.ts +0 -249
- package/microservices/microservice-contacts/src/db/database.ts +0 -91
- package/microservices/microservice-contacts/src/db/migrations.ts +0 -71
- package/microservices/microservice-contacts/src/db/relationships.ts +0 -53
- package/microservices/microservice-contacts/src/index.ts +0 -42
- package/microservices/microservice-contacts/src/mcp/index.ts +0 -303
- package/microservices/microservice-contracts/package.json +0 -28
- package/microservices/microservice-contracts/src/cli/index.ts +0 -770
- package/microservices/microservice-contracts/src/db/contracts.ts +0 -925
- package/microservices/microservice-contracts/src/db/database.ts +0 -91
- package/microservices/microservice-contracts/src/db/migrations.ts +0 -141
- package/microservices/microservice-contracts/src/index.ts +0 -43
- package/microservices/microservice-contracts/src/mcp/index.ts +0 -617
- package/microservices/microservice-crm/package.json +0 -28
- package/microservices/microservice-crm/src/cli/index.ts +0 -396
- package/microservices/microservice-crm/src/db/database.ts +0 -91
- package/microservices/microservice-crm/src/db/migrations.ts +0 -66
- package/microservices/microservice-crm/src/db/pipeline.ts +0 -397
- package/microservices/microservice-crm/src/index.ts +0 -34
- package/microservices/microservice-crm/src/mcp/index.ts +0 -294
- package/microservices/microservice-documents/package.json +0 -28
- package/microservices/microservice-documents/src/cli/index.ts +0 -246
- package/microservices/microservice-documents/src/db/database.ts +0 -91
- package/microservices/microservice-documents/src/db/documents.ts +0 -316
- package/microservices/microservice-documents/src/db/migrations.ts +0 -49
- package/microservices/microservice-documents/src/index.ts +0 -24
- package/microservices/microservice-documents/src/mcp/index.ts +0 -202
- package/microservices/microservice-domains/package.json +0 -28
- package/microservices/microservice-domains/src/cli/index.ts +0 -1111
- package/microservices/microservice-domains/src/db/database.ts +0 -91
- package/microservices/microservice-domains/src/db/domains.ts +0 -1164
- package/microservices/microservice-domains/src/db/migrations.ts +0 -60
- package/microservices/microservice-domains/src/index.ts +0 -65
- package/microservices/microservice-domains/src/lib/brandsight.ts +0 -350
- package/microservices/microservice-domains/src/lib/godaddy.ts +0 -338
- package/microservices/microservice-domains/src/lib/namecheap.ts +0 -262
- package/microservices/microservice-domains/src/lib/registrar.ts +0 -355
- package/microservices/microservice-domains/src/mcp/index.ts +0 -781
- package/microservices/microservice-expenses/package.json +0 -28
- package/microservices/microservice-expenses/src/cli/index.ts +0 -267
- package/microservices/microservice-expenses/src/db/database.ts +0 -91
- package/microservices/microservice-expenses/src/db/expenses.ts +0 -345
- package/microservices/microservice-expenses/src/db/migrations.ts +0 -45
- package/microservices/microservice-expenses/src/index.ts +0 -25
- package/microservices/microservice-expenses/src/mcp/index.ts +0 -196
- package/microservices/microservice-habits/package.json +0 -28
- package/microservices/microservice-habits/src/cli/index.ts +0 -315
- package/microservices/microservice-habits/src/db/database.ts +0 -91
- package/microservices/microservice-habits/src/db/habits.ts +0 -451
- package/microservices/microservice-habits/src/db/migrations.ts +0 -46
- package/microservices/microservice-habits/src/index.ts +0 -31
- package/microservices/microservice-habits/src/mcp/index.ts +0 -313
- package/microservices/microservice-health/package.json +0 -28
- package/microservices/microservice-health/src/cli/index.ts +0 -484
- package/microservices/microservice-health/src/db/database.ts +0 -91
- package/microservices/microservice-health/src/db/health.ts +0 -708
- package/microservices/microservice-health/src/db/migrations.ts +0 -70
- package/microservices/microservice-health/src/index.ts +0 -63
- package/microservices/microservice-health/src/mcp/index.ts +0 -437
- package/microservices/microservice-hiring/package.json +0 -28
- package/microservices/microservice-hiring/src/cli/index.ts +0 -741
- package/microservices/microservice-hiring/src/db/database.ts +0 -91
- package/microservices/microservice-hiring/src/db/hiring.ts +0 -1085
- package/microservices/microservice-hiring/src/db/migrations.ts +0 -89
- package/microservices/microservice-hiring/src/index.ts +0 -80
- package/microservices/microservice-hiring/src/lib/scoring.ts +0 -206
- package/microservices/microservice-hiring/src/mcp/index.ts +0 -709
- package/microservices/microservice-inventory/package.json +0 -28
- package/microservices/microservice-inventory/src/cli/index.ts +0 -365
- package/microservices/microservice-inventory/src/db/database.ts +0 -91
- package/microservices/microservice-inventory/src/db/inventory.ts +0 -393
- package/microservices/microservice-inventory/src/db/migrations.ts +0 -54
- package/microservices/microservice-inventory/src/index.ts +0 -28
- package/microservices/microservice-inventory/src/mcp/index.ts +0 -250
- package/microservices/microservice-invoices/dashboard/index.html +0 -12
- package/microservices/microservice-invoices/dashboard/package.json +0 -29
- package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
- package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
- package/microservices/microservice-invoices/package.json +0 -31
- package/microservices/microservice-invoices/src/cli/index.ts +0 -308
- package/microservices/microservice-invoices/src/db/business.ts +0 -241
- package/microservices/microservice-invoices/src/db/clients.ts +0 -127
- package/microservices/microservice-invoices/src/db/database.ts +0 -91
- package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
- package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
- package/microservices/microservice-invoices/src/index.ts +0 -56
- package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
- package/microservices/microservice-invoices/src/server/index.ts +0 -162
- package/microservices/microservice-leads/package.json +0 -28
- package/microservices/microservice-leads/src/cli/index.ts +0 -596
- package/microservices/microservice-leads/src/db/database.ts +0 -91
- package/microservices/microservice-leads/src/db/leads.ts +0 -520
- package/microservices/microservice-leads/src/db/lists.ts +0 -151
- package/microservices/microservice-leads/src/db/migrations.ts +0 -93
- package/microservices/microservice-leads/src/index.ts +0 -65
- package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
- package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
- package/microservices/microservice-leads/src/mcp/index.ts +0 -533
- package/microservices/microservice-notes/package.json +0 -28
- package/microservices/microservice-notes/src/cli/index.ts +0 -63
- package/microservices/microservice-notes/src/db/database.ts +0 -91
- package/microservices/microservice-notes/src/db/migrations.ts +0 -40
- package/microservices/microservice-notes/src/db/notes.ts +0 -114
- package/microservices/microservice-notes/src/index.ts +0 -2
- package/microservices/microservice-notes/src/mcp/index.ts +0 -37
- package/microservices/microservice-notifications/package.json +0 -28
- package/microservices/microservice-notifications/src/cli/index.ts +0 -349
- package/microservices/microservice-notifications/src/db/database.ts +0 -91
- package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
- package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
- package/microservices/microservice-notifications/src/index.ts +0 -41
- package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
- package/microservices/microservice-payments/package.json +0 -28
- package/microservices/microservice-payments/src/cli/index.ts +0 -609
- package/microservices/microservice-payments/src/db/database.ts +0 -91
- package/microservices/microservice-payments/src/db/migrations.ts +0 -81
- package/microservices/microservice-payments/src/db/payments.ts +0 -1204
- package/microservices/microservice-payments/src/index.ts +0 -51
- package/microservices/microservice-payments/src/mcp/index.ts +0 -683
- package/microservices/microservice-payroll/package.json +0 -28
- package/microservices/microservice-payroll/src/cli/index.ts +0 -643
- package/microservices/microservice-payroll/src/db/database.ts +0 -91
- package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
- package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
- package/microservices/microservice-payroll/src/index.ts +0 -48
- package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
- package/microservices/microservice-products/package.json +0 -28
- package/microservices/microservice-products/src/cli/index.ts +0 -416
- package/microservices/microservice-products/src/db/categories.ts +0 -154
- package/microservices/microservice-products/src/db/database.ts +0 -91
- package/microservices/microservice-products/src/db/migrations.ts +0 -58
- package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
- package/microservices/microservice-products/src/db/products.ts +0 -452
- package/microservices/microservice-products/src/index.ts +0 -53
- package/microservices/microservice-products/src/mcp/index.ts +0 -453
- package/microservices/microservice-projects/package.json +0 -28
- package/microservices/microservice-projects/src/cli/index.ts +0 -480
- package/microservices/microservice-projects/src/db/database.ts +0 -91
- package/microservices/microservice-projects/src/db/migrations.ts +0 -65
- package/microservices/microservice-projects/src/db/projects.ts +0 -715
- package/microservices/microservice-projects/src/index.ts +0 -57
- package/microservices/microservice-projects/src/mcp/index.ts +0 -501
- package/microservices/microservice-proposals/package.json +0 -28
- package/microservices/microservice-proposals/src/cli/index.ts +0 -400
- package/microservices/microservice-proposals/src/db/database.ts +0 -91
- package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
- package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
- package/microservices/microservice-proposals/src/index.ts +0 -37
- package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
- package/microservices/microservice-reading/package.json +0 -28
- package/microservices/microservice-reading/src/cli/index.ts +0 -464
- package/microservices/microservice-reading/src/db/database.ts +0 -91
- package/microservices/microservice-reading/src/db/migrations.ts +0 -59
- package/microservices/microservice-reading/src/db/reading.ts +0 -524
- package/microservices/microservice-reading/src/index.ts +0 -51
- package/microservices/microservice-reading/src/mcp/index.ts +0 -368
- package/microservices/microservice-shipping/package.json +0 -28
- package/microservices/microservice-shipping/src/cli/index.ts +0 -606
- package/microservices/microservice-shipping/src/db/database.ts +0 -91
- package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
- package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
- package/microservices/microservice-shipping/src/index.ts +0 -53
- package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
- package/microservices/microservice-social/package.json +0 -29
- package/microservices/microservice-social/src/cli/index.ts +0 -1583
- package/microservices/microservice-social/src/db/database.ts +0 -91
- package/microservices/microservice-social/src/db/migrations.ts +0 -160
- package/microservices/microservice-social/src/db/social.ts +0 -1076
- package/microservices/microservice-social/src/index.ts +0 -46
- package/microservices/microservice-social/src/lib/audience.ts +0 -353
- package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
- package/microservices/microservice-social/src/lib/media.ts +0 -311
- package/microservices/microservice-social/src/lib/mentions.ts +0 -434
- package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
- package/microservices/microservice-social/src/lib/publisher.ts +0 -377
- package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
- package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
- package/microservices/microservice-social/src/lib/threads.ts +0 -291
- package/microservices/microservice-social/src/mcp/index.ts +0 -1425
- package/microservices/microservice-social/src/server/index.ts +0 -441
- package/microservices/microservice-subscriptions/package.json +0 -28
- package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
- package/microservices/microservice-subscriptions/src/db/database.ts +0 -91
- package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
- package/microservices/microservice-subscriptions/src/index.ts +0 -41
- package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
- package/microservices/microservice-timesheets/package.json +0 -28
- package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
- package/microservices/microservice-timesheets/src/db/database.ts +0 -91
- package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
- package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
- package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
- package/microservices/microservice-timesheets/src/index.ts +0 -44
- package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
- package/microservices/microservice-transcriber/package.json +0 -29
- package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
- package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
- package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
- package/microservices/microservice-transcriber/src/db/database.ts +0 -91
- package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
- package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
- package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
- package/microservices/microservice-transcriber/src/index.ts +0 -43
- package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
- package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
- package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
- package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
- package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
- package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
- package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
- package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
- package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
- package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
- package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
- package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
- package/microservices/microservice-transcriber/src/server/index.ts +0 -199
- package/microservices/microservice-travel/package.json +0 -28
- package/microservices/microservice-travel/src/cli/index.ts +0 -505
- package/microservices/microservice-travel/src/db/database.ts +0 -91
- package/microservices/microservice-travel/src/db/migrations.ts +0 -77
- package/microservices/microservice-travel/src/db/travel.ts +0 -802
- package/microservices/microservice-travel/src/index.ts +0 -60
- package/microservices/microservice-travel/src/mcp/index.ts +0 -495
- package/microservices/microservice-wiki/package.json +0 -28
- package/microservices/microservice-wiki/src/cli/index.ts +0 -345
- package/microservices/microservice-wiki/src/db/database.ts +0 -91
- package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
- package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
- package/microservices/microservice-wiki/src/index.ts +0 -32
- package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
import {
|
|
5
|
-
createBook,
|
|
6
|
-
getBook,
|
|
7
|
-
listBooks,
|
|
8
|
-
updateBook,
|
|
9
|
-
deleteBook,
|
|
10
|
-
searchBooks,
|
|
11
|
-
startBook,
|
|
12
|
-
finishBook,
|
|
13
|
-
abandonBook,
|
|
14
|
-
getCurrentlyReading,
|
|
15
|
-
getBookProgress,
|
|
16
|
-
getReadingStats,
|
|
17
|
-
getReadingPace,
|
|
18
|
-
} from "../db/reading.js";
|
|
19
|
-
import {
|
|
20
|
-
createHighlight,
|
|
21
|
-
listHighlights,
|
|
22
|
-
searchHighlights,
|
|
23
|
-
} from "../db/reading.js";
|
|
24
|
-
import {
|
|
25
|
-
createReadingSession,
|
|
26
|
-
listReadingSessions,
|
|
27
|
-
} from "../db/reading.js";
|
|
28
|
-
|
|
29
|
-
const program = new Command();
|
|
30
|
-
|
|
31
|
-
program
|
|
32
|
-
.name("microservice-reading")
|
|
33
|
-
.description("Reading tracker microservice")
|
|
34
|
-
.version("0.0.1");
|
|
35
|
-
|
|
36
|
-
// --- Books ---
|
|
37
|
-
|
|
38
|
-
const bookCmd = program
|
|
39
|
-
.command("book")
|
|
40
|
-
.description("Book management");
|
|
41
|
-
|
|
42
|
-
bookCmd
|
|
43
|
-
.command("add")
|
|
44
|
-
.description("Add a new book")
|
|
45
|
-
.requiredOption("--title <title>", "Book title")
|
|
46
|
-
.option("--author <author>", "Author name")
|
|
47
|
-
.option("--isbn <isbn>", "ISBN")
|
|
48
|
-
.option("--category <category>", "Category/genre")
|
|
49
|
-
.option("--pages <pages>", "Total pages")
|
|
50
|
-
.option("--cover-url <url>", "Cover image URL")
|
|
51
|
-
.option("--json", "Output as JSON", false)
|
|
52
|
-
.action((opts) => {
|
|
53
|
-
const book = createBook({
|
|
54
|
-
title: opts.title,
|
|
55
|
-
author: opts.author,
|
|
56
|
-
isbn: opts.isbn,
|
|
57
|
-
category: opts.category,
|
|
58
|
-
pages: opts.pages ? parseInt(opts.pages) : undefined,
|
|
59
|
-
cover_url: opts.coverUrl,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (opts.json) {
|
|
63
|
-
console.log(JSON.stringify(book, null, 2));
|
|
64
|
-
} else {
|
|
65
|
-
console.log(`Added book: ${book.title}${book.author ? ` by ${book.author}` : ""} (${book.id})`);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
bookCmd
|
|
70
|
-
.command("list")
|
|
71
|
-
.description("List books")
|
|
72
|
-
.option("--status <status>", "Filter by status (to_read, reading, completed, abandoned)")
|
|
73
|
-
.option("--category <category>", "Filter by category")
|
|
74
|
-
.option("--author <author>", "Filter by author")
|
|
75
|
-
.option("--limit <n>", "Limit results")
|
|
76
|
-
.option("--json", "Output as JSON", false)
|
|
77
|
-
.action((opts) => {
|
|
78
|
-
const books = listBooks({
|
|
79
|
-
status: opts.status,
|
|
80
|
-
category: opts.category,
|
|
81
|
-
author: opts.author,
|
|
82
|
-
limit: opts.limit ? parseInt(opts.limit) : undefined,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
if (opts.json) {
|
|
86
|
-
console.log(JSON.stringify(books, null, 2));
|
|
87
|
-
} else {
|
|
88
|
-
if (books.length === 0) {
|
|
89
|
-
console.log("No books found.");
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
for (const b of books) {
|
|
93
|
-
const author = b.author ? ` by ${b.author}` : "";
|
|
94
|
-
const status = ` [${b.status}]`;
|
|
95
|
-
const progress = b.pages ? ` (${b.current_page}/${b.pages})` : "";
|
|
96
|
-
console.log(` ${b.title}${author}${status}${progress}`);
|
|
97
|
-
}
|
|
98
|
-
console.log(`\n${books.length} book(s)`);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
bookCmd
|
|
103
|
-
.command("get")
|
|
104
|
-
.description("Get a book by ID")
|
|
105
|
-
.argument("<id>", "Book ID")
|
|
106
|
-
.option("--json", "Output as JSON", false)
|
|
107
|
-
.action((id, opts) => {
|
|
108
|
-
const book = getBook(id);
|
|
109
|
-
if (!book) {
|
|
110
|
-
console.error(`Book '${id}' not found.`);
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (opts.json) {
|
|
115
|
-
console.log(JSON.stringify(book, null, 2));
|
|
116
|
-
} else {
|
|
117
|
-
console.log(`${book.title}`);
|
|
118
|
-
if (book.author) console.log(` Author: ${book.author}`);
|
|
119
|
-
if (book.isbn) console.log(` ISBN: ${book.isbn}`);
|
|
120
|
-
console.log(` Status: ${book.status}`);
|
|
121
|
-
if (book.pages) console.log(` Progress: ${book.current_page}/${book.pages} pages`);
|
|
122
|
-
if (book.rating) console.log(` Rating: ${book.rating}/5`);
|
|
123
|
-
if (book.category) console.log(` Category: ${book.category}`);
|
|
124
|
-
if (book.started_at) console.log(` Started: ${book.started_at}`);
|
|
125
|
-
if (book.finished_at) console.log(` Finished: ${book.finished_at}`);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
bookCmd
|
|
130
|
-
.command("update")
|
|
131
|
-
.description("Update a book")
|
|
132
|
-
.argument("<id>", "Book ID")
|
|
133
|
-
.option("--title <title>", "Title")
|
|
134
|
-
.option("--author <author>", "Author")
|
|
135
|
-
.option("--isbn <isbn>", "ISBN")
|
|
136
|
-
.option("--category <category>", "Category")
|
|
137
|
-
.option("--pages <pages>", "Total pages")
|
|
138
|
-
.option("--current-page <page>", "Current page")
|
|
139
|
-
.option("--rating <rating>", "Rating (1-5)")
|
|
140
|
-
.option("--cover-url <url>", "Cover URL")
|
|
141
|
-
.option("--json", "Output as JSON", false)
|
|
142
|
-
.action((id, opts) => {
|
|
143
|
-
const input: Record<string, unknown> = {};
|
|
144
|
-
if (opts.title !== undefined) input.title = opts.title;
|
|
145
|
-
if (opts.author !== undefined) input.author = opts.author;
|
|
146
|
-
if (opts.isbn !== undefined) input.isbn = opts.isbn;
|
|
147
|
-
if (opts.category !== undefined) input.category = opts.category;
|
|
148
|
-
if (opts.pages !== undefined) input.pages = parseInt(opts.pages);
|
|
149
|
-
if (opts.currentPage !== undefined) input.current_page = parseInt(opts.currentPage);
|
|
150
|
-
if (opts.rating !== undefined) input.rating = parseInt(opts.rating);
|
|
151
|
-
if (opts.coverUrl !== undefined) input.cover_url = opts.coverUrl;
|
|
152
|
-
|
|
153
|
-
const book = updateBook(id, input);
|
|
154
|
-
if (!book) {
|
|
155
|
-
console.error(`Book '${id}' not found.`);
|
|
156
|
-
process.exit(1);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (opts.json) {
|
|
160
|
-
console.log(JSON.stringify(book, null, 2));
|
|
161
|
-
} else {
|
|
162
|
-
console.log(`Updated: ${book.title}`);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
bookCmd
|
|
167
|
-
.command("delete")
|
|
168
|
-
.description("Delete a book")
|
|
169
|
-
.argument("<id>", "Book ID")
|
|
170
|
-
.action((id) => {
|
|
171
|
-
const deleted = deleteBook(id);
|
|
172
|
-
if (deleted) {
|
|
173
|
-
console.log(`Deleted book ${id}`);
|
|
174
|
-
} else {
|
|
175
|
-
console.error(`Book '${id}' not found.`);
|
|
176
|
-
process.exit(1);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
bookCmd
|
|
181
|
-
.command("search")
|
|
182
|
-
.description("Search books")
|
|
183
|
-
.argument("<query>", "Search term")
|
|
184
|
-
.option("--json", "Output as JSON", false)
|
|
185
|
-
.action((query, opts) => {
|
|
186
|
-
const results = searchBooks(query);
|
|
187
|
-
|
|
188
|
-
if (opts.json) {
|
|
189
|
-
console.log(JSON.stringify(results, null, 2));
|
|
190
|
-
} else {
|
|
191
|
-
if (results.length === 0) {
|
|
192
|
-
console.log(`No books matching "${query}".`);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
for (const b of results) {
|
|
196
|
-
console.log(` ${b.title}${b.author ? ` by ${b.author}` : ""} [${b.status}]`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
bookCmd
|
|
202
|
-
.command("start")
|
|
203
|
-
.description("Start reading a book")
|
|
204
|
-
.argument("<id>", "Book ID")
|
|
205
|
-
.option("--json", "Output as JSON", false)
|
|
206
|
-
.action((id, opts) => {
|
|
207
|
-
const book = startBook(id);
|
|
208
|
-
if (!book) {
|
|
209
|
-
console.error(`Book '${id}' not found.`);
|
|
210
|
-
process.exit(1);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (opts.json) {
|
|
214
|
-
console.log(JSON.stringify(book, null, 2));
|
|
215
|
-
} else {
|
|
216
|
-
console.log(`Started reading: ${book.title}`);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
bookCmd
|
|
221
|
-
.command("finish")
|
|
222
|
-
.description("Mark a book as finished")
|
|
223
|
-
.argument("<id>", "Book ID")
|
|
224
|
-
.option("--rating <rating>", "Rating (1-5)")
|
|
225
|
-
.option("--json", "Output as JSON", false)
|
|
226
|
-
.action((id, opts) => {
|
|
227
|
-
const rating = opts.rating ? parseInt(opts.rating) : undefined;
|
|
228
|
-
const book = finishBook(id, rating);
|
|
229
|
-
if (!book) {
|
|
230
|
-
console.error(`Book '${id}' not found.`);
|
|
231
|
-
process.exit(1);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (opts.json) {
|
|
235
|
-
console.log(JSON.stringify(book, null, 2));
|
|
236
|
-
} else {
|
|
237
|
-
console.log(`Finished: ${book.title}${rating ? ` (rated ${rating}/5)` : ""}`);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
bookCmd
|
|
242
|
-
.command("abandon")
|
|
243
|
-
.description("Abandon a book")
|
|
244
|
-
.argument("<id>", "Book ID")
|
|
245
|
-
.option("--json", "Output as JSON", false)
|
|
246
|
-
.action((id, opts) => {
|
|
247
|
-
const book = abandonBook(id);
|
|
248
|
-
if (!book) {
|
|
249
|
-
console.error(`Book '${id}' not found.`);
|
|
250
|
-
process.exit(1);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (opts.json) {
|
|
254
|
-
console.log(JSON.stringify(book, null, 2));
|
|
255
|
-
} else {
|
|
256
|
-
console.log(`Abandoned: ${book.title}`);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// --- Highlights ---
|
|
261
|
-
|
|
262
|
-
const highlightCmd = program
|
|
263
|
-
.command("highlight")
|
|
264
|
-
.description("Highlight management");
|
|
265
|
-
|
|
266
|
-
highlightCmd
|
|
267
|
-
.command("add")
|
|
268
|
-
.description("Add a highlight to a book")
|
|
269
|
-
.requiredOption("--book <id>", "Book ID")
|
|
270
|
-
.requiredOption("--text <text>", "Highlight text")
|
|
271
|
-
.option("--page <page>", "Page number")
|
|
272
|
-
.option("--chapter <chapter>", "Chapter name")
|
|
273
|
-
.option("--color <color>", "Highlight color", "yellow")
|
|
274
|
-
.option("--notes <notes>", "Notes about the highlight")
|
|
275
|
-
.option("--json", "Output as JSON", false)
|
|
276
|
-
.action((opts) => {
|
|
277
|
-
const highlight = createHighlight({
|
|
278
|
-
book_id: opts.book,
|
|
279
|
-
text: opts.text,
|
|
280
|
-
page: opts.page ? parseInt(opts.page) : undefined,
|
|
281
|
-
chapter: opts.chapter,
|
|
282
|
-
color: opts.color,
|
|
283
|
-
notes: opts.notes,
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
if (opts.json) {
|
|
287
|
-
console.log(JSON.stringify(highlight, null, 2));
|
|
288
|
-
} else {
|
|
289
|
-
console.log(`Added highlight (${highlight.id})`);
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
highlightCmd
|
|
294
|
-
.command("list")
|
|
295
|
-
.description("List highlights for a book")
|
|
296
|
-
.argument("<book-id>", "Book ID")
|
|
297
|
-
.option("--json", "Output as JSON", false)
|
|
298
|
-
.action((bookId, opts) => {
|
|
299
|
-
const highlights = listHighlights(bookId);
|
|
300
|
-
|
|
301
|
-
if (opts.json) {
|
|
302
|
-
console.log(JSON.stringify(highlights, null, 2));
|
|
303
|
-
} else {
|
|
304
|
-
if (highlights.length === 0) {
|
|
305
|
-
console.log("No highlights found.");
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
for (const h of highlights) {
|
|
309
|
-
const page = h.page ? ` (p.${h.page})` : "";
|
|
310
|
-
const chapter = h.chapter ? ` [${h.chapter}]` : "";
|
|
311
|
-
console.log(` "${h.text}"${page}${chapter}`);
|
|
312
|
-
if (h.notes) console.log(` Note: ${h.notes}`);
|
|
313
|
-
}
|
|
314
|
-
console.log(`\n${highlights.length} highlight(s)`);
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
highlightCmd
|
|
319
|
-
.command("search")
|
|
320
|
-
.description("Search all highlights")
|
|
321
|
-
.argument("<query>", "Search term")
|
|
322
|
-
.option("--json", "Output as JSON", false)
|
|
323
|
-
.action((query, opts) => {
|
|
324
|
-
const results = searchHighlights(query);
|
|
325
|
-
|
|
326
|
-
if (opts.json) {
|
|
327
|
-
console.log(JSON.stringify(results, null, 2));
|
|
328
|
-
} else {
|
|
329
|
-
if (results.length === 0) {
|
|
330
|
-
console.log(`No highlights matching "${query}".`);
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
for (const h of results) {
|
|
334
|
-
console.log(` "${h.text}" — ${h.book_title}`);
|
|
335
|
-
if (h.notes) console.log(` Note: ${h.notes}`);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
// --- Sessions ---
|
|
341
|
-
|
|
342
|
-
const sessionCmd = program
|
|
343
|
-
.command("session")
|
|
344
|
-
.description("Reading session management");
|
|
345
|
-
|
|
346
|
-
sessionCmd
|
|
347
|
-
.command("log")
|
|
348
|
-
.description("Log a reading session")
|
|
349
|
-
.requiredOption("--book <id>", "Book ID")
|
|
350
|
-
.option("--pages <pages>", "Pages read")
|
|
351
|
-
.option("--duration <minutes>", "Duration in minutes")
|
|
352
|
-
.option("--date <date>", "Date (ISO string)", new Date().toISOString())
|
|
353
|
-
.option("--json", "Output as JSON", false)
|
|
354
|
-
.action((opts) => {
|
|
355
|
-
const session = createReadingSession({
|
|
356
|
-
book_id: opts.book,
|
|
357
|
-
pages_read: opts.pages ? parseInt(opts.pages) : undefined,
|
|
358
|
-
duration_min: opts.duration ? parseInt(opts.duration) : undefined,
|
|
359
|
-
logged_at: opts.date,
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
if (opts.json) {
|
|
363
|
-
console.log(JSON.stringify(session, null, 2));
|
|
364
|
-
} else {
|
|
365
|
-
const pages = session.pages_read ? `${session.pages_read} pages` : "";
|
|
366
|
-
const duration = session.duration_min ? `${session.duration_min} min` : "";
|
|
367
|
-
const parts = [pages, duration].filter(Boolean).join(", ");
|
|
368
|
-
console.log(`Logged session: ${parts || "no details"} (${session.id})`);
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
sessionCmd
|
|
373
|
-
.command("list")
|
|
374
|
-
.description("List reading sessions for a book")
|
|
375
|
-
.argument("<book-id>", "Book ID")
|
|
376
|
-
.option("--json", "Output as JSON", false)
|
|
377
|
-
.action((bookId, opts) => {
|
|
378
|
-
const sessions = listReadingSessions(bookId);
|
|
379
|
-
|
|
380
|
-
if (opts.json) {
|
|
381
|
-
console.log(JSON.stringify(sessions, null, 2));
|
|
382
|
-
} else {
|
|
383
|
-
if (sessions.length === 0) {
|
|
384
|
-
console.log("No sessions found.");
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
for (const s of sessions) {
|
|
388
|
-
const pages = s.pages_read ? `${s.pages_read} pages` : "";
|
|
389
|
-
const duration = s.duration_min ? `${s.duration_min} min` : "";
|
|
390
|
-
const parts = [pages, duration].filter(Boolean).join(", ");
|
|
391
|
-
console.log(` ${s.logged_at}: ${parts || "no details"}`);
|
|
392
|
-
}
|
|
393
|
-
console.log(`\n${sessions.length} session(s)`);
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
// --- Top-level convenience commands ---
|
|
398
|
-
|
|
399
|
-
program
|
|
400
|
-
.command("stats")
|
|
401
|
-
.description("Show reading statistics")
|
|
402
|
-
.option("--year <year>", "Filter by year")
|
|
403
|
-
.option("--json", "Output as JSON", false)
|
|
404
|
-
.action((opts) => {
|
|
405
|
-
const year = opts.year ? parseInt(opts.year) : undefined;
|
|
406
|
-
const stats = getReadingStats(year);
|
|
407
|
-
|
|
408
|
-
if (opts.json) {
|
|
409
|
-
console.log(JSON.stringify(stats, null, 2));
|
|
410
|
-
} else {
|
|
411
|
-
console.log(`Reading Stats${year ? ` (${year})` : ""}:`);
|
|
412
|
-
console.log(` Books read: ${stats.books_read}`);
|
|
413
|
-
console.log(` Pages read: ${stats.pages_read}`);
|
|
414
|
-
console.log(` Total sessions: ${stats.total_sessions}`);
|
|
415
|
-
console.log(` Avg rating: ${stats.avg_rating ?? "N/A"}`);
|
|
416
|
-
if (Object.keys(stats.by_category).length > 0) {
|
|
417
|
-
console.log(" By category:");
|
|
418
|
-
for (const [cat, count] of Object.entries(stats.by_category)) {
|
|
419
|
-
console.log(` ${cat}: ${count}`);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
program
|
|
426
|
-
.command("currently-reading")
|
|
427
|
-
.description("Show books currently being read")
|
|
428
|
-
.option("--json", "Output as JSON", false)
|
|
429
|
-
.action((opts) => {
|
|
430
|
-
const books = getCurrentlyReading();
|
|
431
|
-
|
|
432
|
-
if (opts.json) {
|
|
433
|
-
console.log(JSON.stringify(books, null, 2));
|
|
434
|
-
} else {
|
|
435
|
-
if (books.length === 0) {
|
|
436
|
-
console.log("Not reading any books right now.");
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
for (const b of books) {
|
|
440
|
-
const progress = b.pages ? ` (${b.current_page}/${b.pages} pages)` : "";
|
|
441
|
-
console.log(` ${b.title}${b.author ? ` by ${b.author}` : ""}${progress}`);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
program
|
|
447
|
-
.command("pace")
|
|
448
|
-
.description("Show reading pace")
|
|
449
|
-
.option("--json", "Output as JSON", false)
|
|
450
|
-
.action((opts) => {
|
|
451
|
-
const pace = getReadingPace();
|
|
452
|
-
|
|
453
|
-
if (opts.json) {
|
|
454
|
-
console.log(JSON.stringify(pace, null, 2));
|
|
455
|
-
} else {
|
|
456
|
-
console.log("Reading Pace:");
|
|
457
|
-
console.log(` Pages/day: ${pace.pages_per_day}`);
|
|
458
|
-
console.log(` Books/month: ${pace.books_per_month}`);
|
|
459
|
-
console.log(` Avg pages/session: ${pace.avg_session_pages}`);
|
|
460
|
-
console.log(` Avg minutes/session: ${pace.avg_session_minutes ?? "N/A"}`);
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
program.parse(process.argv);
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database connection for microservice-reading
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
-
import type { Database } from "bun:sqlite";
|
|
7
|
-
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
8
|
-
import { dirname, join, resolve } from "node:path";
|
|
9
|
-
import { MIGRATIONS } from "./migrations.js";
|
|
10
|
-
|
|
11
|
-
let _db: Database | null = null;
|
|
12
|
-
|
|
13
|
-
function getDbPath(): string {
|
|
14
|
-
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
-
if (explicit) {
|
|
16
|
-
return join(explicit, "microservice-reading", "data.db");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let dir = resolve(process.cwd());
|
|
20
|
-
while (true) {
|
|
21
|
-
const msDir = join(dir, ".microservices");
|
|
22
|
-
if (existsSync(msDir)) return join(msDir, "microservice-reading", "data.db");
|
|
23
|
-
const parent = dirname(dir);
|
|
24
|
-
if (parent === dir) break;
|
|
25
|
-
dir = parent;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
29
|
-
const newDir = join(home, ".hasna", "microservices");
|
|
30
|
-
const oldDir = join(home, ".microservices");
|
|
31
|
-
if (!existsSync(newDir) && existsSync(oldDir)) {
|
|
32
|
-
mkdirSync(join(home, ".hasna"), { recursive: true });
|
|
33
|
-
cpSync(oldDir, newDir, { recursive: true });
|
|
34
|
-
}
|
|
35
|
-
return join(newDir, "microservice-reading", "data.db");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function getDatabase(): Database {
|
|
39
|
-
if (_db) return _db;
|
|
40
|
-
|
|
41
|
-
const dbPath = getDbPath();
|
|
42
|
-
const dir = dirname(resolve(dbPath));
|
|
43
|
-
if (!existsSync(dir)) {
|
|
44
|
-
mkdirSync(dir, { recursive: true });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
-
_db = adapter.raw;
|
|
49
|
-
// SqliteAdapter already sets WAL and foreign_keys
|
|
50
|
-
|
|
51
|
-
_db.exec(`
|
|
52
|
-
CREATE TABLE IF NOT EXISTS _migrations (
|
|
53
|
-
id INTEGER PRIMARY KEY,
|
|
54
|
-
name TEXT NOT NULL,
|
|
55
|
-
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
56
|
-
)
|
|
57
|
-
`);
|
|
58
|
-
|
|
59
|
-
const applied = _db
|
|
60
|
-
.query("SELECT id FROM _migrations ORDER BY id")
|
|
61
|
-
.all() as { id: number }[];
|
|
62
|
-
const appliedIds = new Set(applied.map((r) => r.id));
|
|
63
|
-
|
|
64
|
-
for (const migration of MIGRATIONS) {
|
|
65
|
-
if (appliedIds.has(migration.id)) continue;
|
|
66
|
-
|
|
67
|
-
_db.exec("BEGIN");
|
|
68
|
-
try {
|
|
69
|
-
_db.exec(migration.sql);
|
|
70
|
-
_db.prepare("INSERT INTO _migrations (id, name) VALUES (?, ?)").run(
|
|
71
|
-
migration.id,
|
|
72
|
-
migration.name
|
|
73
|
-
);
|
|
74
|
-
_db.exec("COMMIT");
|
|
75
|
-
} catch (error) {
|
|
76
|
-
_db.exec("ROLLBACK");
|
|
77
|
-
throw new Error(
|
|
78
|
-
`Migration ${migration.id} (${migration.name}) failed: ${error instanceof Error ? error.message : String(error)}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return _db;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function closeDatabase(): void {
|
|
87
|
-
if (_db) {
|
|
88
|
-
_db.close();
|
|
89
|
-
_db = null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export interface MigrationEntry {
|
|
2
|
-
id: number;
|
|
3
|
-
name: string;
|
|
4
|
-
sql: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const MIGRATIONS: MigrationEntry[] = [
|
|
8
|
-
{
|
|
9
|
-
id: 1,
|
|
10
|
-
name: "initial_schema",
|
|
11
|
-
sql: `
|
|
12
|
-
CREATE TABLE IF NOT EXISTS books (
|
|
13
|
-
id TEXT PRIMARY KEY,
|
|
14
|
-
title TEXT NOT NULL,
|
|
15
|
-
author TEXT,
|
|
16
|
-
isbn TEXT,
|
|
17
|
-
status TEXT NOT NULL DEFAULT 'to_read' CHECK(status IN ('to_read','reading','completed','abandoned')),
|
|
18
|
-
rating INTEGER,
|
|
19
|
-
category TEXT,
|
|
20
|
-
pages INTEGER,
|
|
21
|
-
current_page INTEGER NOT NULL DEFAULT 0,
|
|
22
|
-
started_at TEXT,
|
|
23
|
-
finished_at TEXT,
|
|
24
|
-
cover_url TEXT,
|
|
25
|
-
metadata TEXT NOT NULL DEFAULT '{}',
|
|
26
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
27
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
CREATE TABLE IF NOT EXISTS highlights (
|
|
31
|
-
id TEXT PRIMARY KEY,
|
|
32
|
-
book_id TEXT NOT NULL REFERENCES books(id) ON DELETE CASCADE,
|
|
33
|
-
text TEXT NOT NULL,
|
|
34
|
-
page INTEGER,
|
|
35
|
-
chapter TEXT,
|
|
36
|
-
color TEXT NOT NULL DEFAULT 'yellow',
|
|
37
|
-
notes TEXT,
|
|
38
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
CREATE TABLE IF NOT EXISTS reading_sessions (
|
|
42
|
-
id TEXT PRIMARY KEY,
|
|
43
|
-
book_id TEXT NOT NULL REFERENCES books(id) ON DELETE CASCADE,
|
|
44
|
-
pages_read INTEGER,
|
|
45
|
-
duration_min INTEGER,
|
|
46
|
-
logged_at TEXT NOT NULL,
|
|
47
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
CREATE INDEX IF NOT EXISTS idx_books_status ON books(status);
|
|
51
|
-
CREATE INDEX IF NOT EXISTS idx_books_author ON books(author);
|
|
52
|
-
CREATE INDEX IF NOT EXISTS idx_books_category ON books(category);
|
|
53
|
-
CREATE INDEX IF NOT EXISTS idx_books_isbn ON books(isbn);
|
|
54
|
-
CREATE INDEX IF NOT EXISTS idx_highlights_book ON highlights(book_id);
|
|
55
|
-
CREATE INDEX IF NOT EXISTS idx_reading_sessions_book ON reading_sessions(book_id);
|
|
56
|
-
CREATE INDEX IF NOT EXISTS idx_reading_sessions_logged ON reading_sessions(logged_at);
|
|
57
|
-
`,
|
|
58
|
-
},
|
|
59
|
-
];
|