@hasna/microservices 0.0.16 → 0.0.17
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 +711 -13998
- package/bin/mcp.js +228 -10987
- package/dist/index.js +166 -10056
- package/package.json +25 -25
- 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,370 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asset and Collection CRUD operations
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { getDatabase } from "./database.js";
|
|
6
|
-
|
|
7
|
-
// --- Asset types ---
|
|
8
|
-
|
|
9
|
-
export interface Asset {
|
|
10
|
-
id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
description: string | null;
|
|
13
|
-
type: string | null;
|
|
14
|
-
file_path: string | null;
|
|
15
|
-
file_size: number | null;
|
|
16
|
-
mime_type: string | null;
|
|
17
|
-
dimensions: string | null;
|
|
18
|
-
tags: string[];
|
|
19
|
-
category: string | null;
|
|
20
|
-
metadata: Record<string, unknown>;
|
|
21
|
-
uploaded_by: string | null;
|
|
22
|
-
created_at: string;
|
|
23
|
-
updated_at: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface AssetRow {
|
|
27
|
-
id: string;
|
|
28
|
-
name: string;
|
|
29
|
-
description: string | null;
|
|
30
|
-
type: string | null;
|
|
31
|
-
file_path: string | null;
|
|
32
|
-
file_size: number | null;
|
|
33
|
-
mime_type: string | null;
|
|
34
|
-
dimensions: string | null;
|
|
35
|
-
tags: string;
|
|
36
|
-
category: string | null;
|
|
37
|
-
metadata: string;
|
|
38
|
-
uploaded_by: string | null;
|
|
39
|
-
created_at: string;
|
|
40
|
-
updated_at: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function rowToAsset(row: AssetRow): Asset {
|
|
44
|
-
return {
|
|
45
|
-
...row,
|
|
46
|
-
tags: JSON.parse(row.tags || "[]"),
|
|
47
|
-
metadata: JSON.parse(row.metadata || "{}"),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface CreateAssetInput {
|
|
52
|
-
name: string;
|
|
53
|
-
description?: string;
|
|
54
|
-
type?: string;
|
|
55
|
-
file_path?: string;
|
|
56
|
-
file_size?: number;
|
|
57
|
-
mime_type?: string;
|
|
58
|
-
dimensions?: string;
|
|
59
|
-
tags?: string[];
|
|
60
|
-
category?: string;
|
|
61
|
-
metadata?: Record<string, unknown>;
|
|
62
|
-
uploaded_by?: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function createAsset(input: CreateAssetInput): Asset {
|
|
66
|
-
const db = getDatabase();
|
|
67
|
-
const id = crypto.randomUUID();
|
|
68
|
-
const tags = JSON.stringify(input.tags || []);
|
|
69
|
-
const metadata = JSON.stringify(input.metadata || {});
|
|
70
|
-
|
|
71
|
-
db.prepare(
|
|
72
|
-
`INSERT INTO assets (id, name, description, type, file_path, file_size, mime_type, dimensions, tags, category, metadata, uploaded_by)
|
|
73
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
74
|
-
).run(
|
|
75
|
-
id,
|
|
76
|
-
input.name,
|
|
77
|
-
input.description || null,
|
|
78
|
-
input.type || null,
|
|
79
|
-
input.file_path || null,
|
|
80
|
-
input.file_size ?? null,
|
|
81
|
-
input.mime_type || null,
|
|
82
|
-
input.dimensions || null,
|
|
83
|
-
tags,
|
|
84
|
-
input.category || null,
|
|
85
|
-
metadata,
|
|
86
|
-
input.uploaded_by || null
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
return getAsset(id)!;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function getAsset(id: string): Asset | null {
|
|
93
|
-
const db = getDatabase();
|
|
94
|
-
const row = db.prepare("SELECT * FROM assets WHERE id = ?").get(id) as AssetRow | null;
|
|
95
|
-
return row ? rowToAsset(row) : null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface ListAssetsOptions {
|
|
99
|
-
search?: string;
|
|
100
|
-
type?: string;
|
|
101
|
-
category?: string;
|
|
102
|
-
tag?: string;
|
|
103
|
-
uploaded_by?: string;
|
|
104
|
-
limit?: number;
|
|
105
|
-
offset?: number;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function listAssets(options: ListAssetsOptions = {}): Asset[] {
|
|
109
|
-
const db = getDatabase();
|
|
110
|
-
const conditions: string[] = [];
|
|
111
|
-
const params: unknown[] = [];
|
|
112
|
-
|
|
113
|
-
if (options.search) {
|
|
114
|
-
conditions.push("(name LIKE ? OR description LIKE ? OR tags LIKE ?)");
|
|
115
|
-
const q = `%${options.search}%`;
|
|
116
|
-
params.push(q, q, q);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (options.type) {
|
|
120
|
-
conditions.push("type = ?");
|
|
121
|
-
params.push(options.type);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (options.category) {
|
|
125
|
-
conditions.push("category = ?");
|
|
126
|
-
params.push(options.category);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (options.tag) {
|
|
130
|
-
conditions.push("tags LIKE ?");
|
|
131
|
-
params.push(`%${options.tag}%`);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (options.uploaded_by) {
|
|
135
|
-
conditions.push("uploaded_by = ?");
|
|
136
|
-
params.push(options.uploaded_by);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
let sql = "SELECT * FROM assets";
|
|
140
|
-
if (conditions.length > 0) {
|
|
141
|
-
sql += " WHERE " + conditions.join(" AND ");
|
|
142
|
-
}
|
|
143
|
-
sql += " ORDER BY created_at DESC";
|
|
144
|
-
|
|
145
|
-
if (options.limit) {
|
|
146
|
-
sql += " LIMIT ?";
|
|
147
|
-
params.push(options.limit);
|
|
148
|
-
}
|
|
149
|
-
if (options.offset) {
|
|
150
|
-
sql += " OFFSET ?";
|
|
151
|
-
params.push(options.offset);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const rows = db.prepare(sql).all(...params) as AssetRow[];
|
|
155
|
-
return rows.map(rowToAsset);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export interface UpdateAssetInput {
|
|
159
|
-
name?: string;
|
|
160
|
-
description?: string;
|
|
161
|
-
type?: string;
|
|
162
|
-
file_path?: string;
|
|
163
|
-
file_size?: number;
|
|
164
|
-
mime_type?: string;
|
|
165
|
-
dimensions?: string;
|
|
166
|
-
tags?: string[];
|
|
167
|
-
category?: string;
|
|
168
|
-
metadata?: Record<string, unknown>;
|
|
169
|
-
uploaded_by?: string;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function updateAsset(id: string, input: UpdateAssetInput): Asset | null {
|
|
173
|
-
const db = getDatabase();
|
|
174
|
-
const existing = getAsset(id);
|
|
175
|
-
if (!existing) return null;
|
|
176
|
-
|
|
177
|
-
const sets: string[] = [];
|
|
178
|
-
const params: unknown[] = [];
|
|
179
|
-
|
|
180
|
-
if (input.name !== undefined) {
|
|
181
|
-
sets.push("name = ?");
|
|
182
|
-
params.push(input.name);
|
|
183
|
-
}
|
|
184
|
-
if (input.description !== undefined) {
|
|
185
|
-
sets.push("description = ?");
|
|
186
|
-
params.push(input.description);
|
|
187
|
-
}
|
|
188
|
-
if (input.type !== undefined) {
|
|
189
|
-
sets.push("type = ?");
|
|
190
|
-
params.push(input.type);
|
|
191
|
-
}
|
|
192
|
-
if (input.file_path !== undefined) {
|
|
193
|
-
sets.push("file_path = ?");
|
|
194
|
-
params.push(input.file_path);
|
|
195
|
-
}
|
|
196
|
-
if (input.file_size !== undefined) {
|
|
197
|
-
sets.push("file_size = ?");
|
|
198
|
-
params.push(input.file_size);
|
|
199
|
-
}
|
|
200
|
-
if (input.mime_type !== undefined) {
|
|
201
|
-
sets.push("mime_type = ?");
|
|
202
|
-
params.push(input.mime_type);
|
|
203
|
-
}
|
|
204
|
-
if (input.dimensions !== undefined) {
|
|
205
|
-
sets.push("dimensions = ?");
|
|
206
|
-
params.push(input.dimensions);
|
|
207
|
-
}
|
|
208
|
-
if (input.tags !== undefined) {
|
|
209
|
-
sets.push("tags = ?");
|
|
210
|
-
params.push(JSON.stringify(input.tags));
|
|
211
|
-
}
|
|
212
|
-
if (input.category !== undefined) {
|
|
213
|
-
sets.push("category = ?");
|
|
214
|
-
params.push(input.category);
|
|
215
|
-
}
|
|
216
|
-
if (input.metadata !== undefined) {
|
|
217
|
-
sets.push("metadata = ?");
|
|
218
|
-
params.push(JSON.stringify(input.metadata));
|
|
219
|
-
}
|
|
220
|
-
if (input.uploaded_by !== undefined) {
|
|
221
|
-
sets.push("uploaded_by = ?");
|
|
222
|
-
params.push(input.uploaded_by);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (sets.length === 0) return existing;
|
|
226
|
-
|
|
227
|
-
sets.push("updated_at = datetime('now')");
|
|
228
|
-
params.push(id);
|
|
229
|
-
|
|
230
|
-
db.prepare(
|
|
231
|
-
`UPDATE assets SET ${sets.join(", ")} WHERE id = ?`
|
|
232
|
-
).run(...params);
|
|
233
|
-
|
|
234
|
-
return getAsset(id);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export function deleteAsset(id: string): boolean {
|
|
238
|
-
const db = getDatabase();
|
|
239
|
-
const result = db.prepare("DELETE FROM assets WHERE id = ?").run(id);
|
|
240
|
-
return result.changes > 0;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function searchAssets(query: string): Asset[] {
|
|
244
|
-
return listAssets({ search: query });
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export function listByType(type: string): Asset[] {
|
|
248
|
-
return listAssets({ type });
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export function listByTag(tag: string): Asset[] {
|
|
252
|
-
return listAssets({ tag });
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export function listByCategory(category: string): Asset[] {
|
|
256
|
-
return listAssets({ category });
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export interface AssetStats {
|
|
260
|
-
total_assets: number;
|
|
261
|
-
total_size: number;
|
|
262
|
-
by_type: Record<string, number>;
|
|
263
|
-
by_category: Record<string, number>;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export function getAssetStats(): AssetStats {
|
|
267
|
-
const db = getDatabase();
|
|
268
|
-
|
|
269
|
-
const totalRow = db.prepare("SELECT COUNT(*) as count FROM assets").get() as { count: number };
|
|
270
|
-
const sizeRow = db.prepare("SELECT COALESCE(SUM(file_size), 0) as total FROM assets").get() as { total: number };
|
|
271
|
-
|
|
272
|
-
const typeRows = db.prepare(
|
|
273
|
-
"SELECT type, COUNT(*) as count FROM assets WHERE type IS NOT NULL GROUP BY type"
|
|
274
|
-
).all() as { type: string; count: number }[];
|
|
275
|
-
|
|
276
|
-
const categoryRows = db.prepare(
|
|
277
|
-
"SELECT category, COUNT(*) as count FROM assets WHERE category IS NOT NULL GROUP BY category"
|
|
278
|
-
).all() as { category: string; count: number }[];
|
|
279
|
-
|
|
280
|
-
const by_type: Record<string, number> = {};
|
|
281
|
-
for (const row of typeRows) {
|
|
282
|
-
by_type[row.type] = row.count;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const by_category: Record<string, number> = {};
|
|
286
|
-
for (const row of categoryRows) {
|
|
287
|
-
by_category[row.category] = row.count;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return {
|
|
291
|
-
total_assets: totalRow.count,
|
|
292
|
-
total_size: sizeRow.total,
|
|
293
|
-
by_type,
|
|
294
|
-
by_category,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// --- Collection types ---
|
|
299
|
-
|
|
300
|
-
export interface Collection {
|
|
301
|
-
id: string;
|
|
302
|
-
name: string;
|
|
303
|
-
description: string | null;
|
|
304
|
-
created_at: string;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export interface CreateCollectionInput {
|
|
308
|
-
name: string;
|
|
309
|
-
description?: string;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export function createCollection(input: CreateCollectionInput): Collection {
|
|
313
|
-
const db = getDatabase();
|
|
314
|
-
const id = crypto.randomUUID();
|
|
315
|
-
|
|
316
|
-
db.prepare(
|
|
317
|
-
`INSERT INTO collections (id, name, description) VALUES (?, ?, ?)`
|
|
318
|
-
).run(id, input.name, input.description || null);
|
|
319
|
-
|
|
320
|
-
return getCollection(id)!;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export function getCollection(id: string): Collection | null {
|
|
324
|
-
const db = getDatabase();
|
|
325
|
-
return db.prepare("SELECT * FROM collections WHERE id = ?").get(id) as Collection | null;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
export function listCollections(): Collection[] {
|
|
329
|
-
const db = getDatabase();
|
|
330
|
-
return db.prepare("SELECT * FROM collections ORDER BY name").all() as Collection[];
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
export function deleteCollection(id: string): boolean {
|
|
334
|
-
const db = getDatabase();
|
|
335
|
-
const result = db.prepare("DELETE FROM collections WHERE id = ?").run(id);
|
|
336
|
-
return result.changes > 0;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// --- Collection-Asset operations ---
|
|
340
|
-
|
|
341
|
-
export function addToCollection(collectionId: string, assetId: string): boolean {
|
|
342
|
-
const db = getDatabase();
|
|
343
|
-
try {
|
|
344
|
-
db.prepare(
|
|
345
|
-
"INSERT OR IGNORE INTO collection_assets (collection_id, asset_id) VALUES (?, ?)"
|
|
346
|
-
).run(collectionId, assetId);
|
|
347
|
-
return true;
|
|
348
|
-
} catch {
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
export function removeFromCollection(collectionId: string, assetId: string): boolean {
|
|
354
|
-
const db = getDatabase();
|
|
355
|
-
const result = db.prepare(
|
|
356
|
-
"DELETE FROM collection_assets WHERE collection_id = ? AND asset_id = ?"
|
|
357
|
-
).run(collectionId, assetId);
|
|
358
|
-
return result.changes > 0;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
export function getCollectionAssets(collectionId: string): Asset[] {
|
|
362
|
-
const db = getDatabase();
|
|
363
|
-
const rows = db.prepare(
|
|
364
|
-
`SELECT a.* FROM assets a
|
|
365
|
-
INNER JOIN collection_assets ca ON ca.asset_id = a.id
|
|
366
|
-
WHERE ca.collection_id = ?
|
|
367
|
-
ORDER BY ca.added_at DESC`
|
|
368
|
-
).all(collectionId) as AssetRow[];
|
|
369
|
-
return rows.map(rowToAsset);
|
|
370
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database connection for microservice-assets
|
|
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-assets", "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-assets", "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-assets", "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,51 +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 assets (
|
|
13
|
-
id TEXT PRIMARY KEY,
|
|
14
|
-
name TEXT NOT NULL,
|
|
15
|
-
description TEXT,
|
|
16
|
-
type TEXT CHECK(type IN ('image','video','document','audio','template','logo','font','other')),
|
|
17
|
-
file_path TEXT,
|
|
18
|
-
file_size INTEGER,
|
|
19
|
-
mime_type TEXT,
|
|
20
|
-
dimensions TEXT,
|
|
21
|
-
tags TEXT DEFAULT '[]',
|
|
22
|
-
category TEXT,
|
|
23
|
-
metadata TEXT DEFAULT '{}',
|
|
24
|
-
uploaded_by TEXT,
|
|
25
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
26
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
CREATE TABLE IF NOT EXISTS collections (
|
|
30
|
-
id TEXT PRIMARY KEY,
|
|
31
|
-
name TEXT NOT NULL,
|
|
32
|
-
description TEXT,
|
|
33
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
CREATE TABLE IF NOT EXISTS collection_assets (
|
|
37
|
-
collection_id TEXT NOT NULL REFERENCES collections(id) ON DELETE CASCADE,
|
|
38
|
-
asset_id TEXT NOT NULL REFERENCES assets(id) ON DELETE CASCADE,
|
|
39
|
-
added_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
40
|
-
PRIMARY KEY (collection_id, asset_id)
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
CREATE INDEX IF NOT EXISTS idx_assets_name ON assets(name);
|
|
44
|
-
CREATE INDEX IF NOT EXISTS idx_assets_type ON assets(type);
|
|
45
|
-
CREATE INDEX IF NOT EXISTS idx_assets_category ON assets(category);
|
|
46
|
-
CREATE INDEX IF NOT EXISTS idx_assets_uploaded_by ON assets(uploaded_by);
|
|
47
|
-
CREATE INDEX IF NOT EXISTS idx_collections_name ON collections(name);
|
|
48
|
-
CREATE INDEX IF NOT EXISTS idx_collection_assets_asset ON collection_assets(asset_id);
|
|
49
|
-
`,
|
|
50
|
-
},
|
|
51
|
-
];
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* microservice-assets — Digital asset management microservice
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
createAsset,
|
|
7
|
-
getAsset,
|
|
8
|
-
listAssets,
|
|
9
|
-
updateAsset,
|
|
10
|
-
deleteAsset,
|
|
11
|
-
searchAssets,
|
|
12
|
-
listByType,
|
|
13
|
-
listByTag,
|
|
14
|
-
listByCategory,
|
|
15
|
-
getAssetStats,
|
|
16
|
-
createCollection,
|
|
17
|
-
getCollection,
|
|
18
|
-
listCollections,
|
|
19
|
-
deleteCollection,
|
|
20
|
-
addToCollection,
|
|
21
|
-
removeFromCollection,
|
|
22
|
-
getCollectionAssets,
|
|
23
|
-
type Asset,
|
|
24
|
-
type CreateAssetInput,
|
|
25
|
-
type UpdateAssetInput,
|
|
26
|
-
type ListAssetsOptions,
|
|
27
|
-
type AssetStats,
|
|
28
|
-
type Collection,
|
|
29
|
-
type CreateCollectionInput,
|
|
30
|
-
} from "./db/assets.js";
|
|
31
|
-
|
|
32
|
-
export { getDatabase, closeDatabase } from "./db/database.js";
|