@hasna/microservices 0.0.15 → 0.0.16
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 +25 -163
- package/bin/index.js +4451 -3189
- package/bin/mcp.js +5312 -4029
- package/dist/index.js +3806 -3153
- package/microservices/microservice-ads/package.json +1 -0
- package/microservices/microservice-ads/src/db/database.ts +20 -22
- package/microservices/microservice-analytics/package.json +1 -0
- package/microservices/microservice-analytics/src/db/database.ts +20 -22
- package/microservices/microservice-assets/package.json +1 -0
- package/microservices/microservice-assets/src/db/database.ts +20 -22
- package/microservices/microservice-bookkeeping/package.json +1 -0
- package/microservices/microservice-bookkeeping/src/db/database.ts +20 -22
- package/microservices/microservice-calendar/package.json +1 -0
- package/microservices/microservice-calendar/src/db/database.ts +20 -11
- package/microservices/microservice-company/package.json +1 -0
- package/microservices/microservice-company/src/db/database.ts +20 -22
- package/microservices/microservice-compliance/package.json +1 -0
- package/microservices/microservice-compliance/src/db/database.ts +20 -22
- package/microservices/microservice-contacts/package.json +1 -0
- package/microservices/microservice-contacts/src/db/database.ts +20 -22
- package/microservices/microservice-contracts/package.json +1 -0
- package/microservices/microservice-contracts/src/db/database.ts +20 -22
- package/microservices/microservice-crm/package.json +1 -0
- package/microservices/microservice-crm/src/db/database.ts +20 -11
- package/microservices/microservice-documents/package.json +1 -0
- package/microservices/microservice-documents/src/db/database.ts +20 -11
- package/microservices/microservice-domains/package.json +1 -0
- package/microservices/microservice-domains/src/db/database.ts +20 -22
- package/microservices/microservice-expenses/package.json +1 -0
- package/microservices/microservice-expenses/src/db/database.ts +20 -11
- package/microservices/microservice-habits/package.json +1 -0
- package/microservices/microservice-habits/src/db/database.ts +20 -22
- package/microservices/microservice-health/package.json +1 -0
- package/microservices/microservice-health/src/db/database.ts +20 -22
- package/microservices/microservice-hiring/package.json +1 -0
- package/microservices/microservice-hiring/src/db/database.ts +20 -22
- package/microservices/microservice-inventory/package.json +1 -0
- package/microservices/microservice-inventory/src/db/database.ts +20 -11
- package/microservices/microservice-invoices/package.json +1 -0
- package/microservices/microservice-invoices/src/db/database.ts +20 -11
- package/microservices/microservice-leads/package.json +1 -0
- package/microservices/microservice-leads/src/db/database.ts +20 -22
- package/microservices/microservice-notes/package.json +1 -0
- package/microservices/microservice-notes/src/db/database.ts +20 -22
- package/microservices/microservice-notifications/package.json +1 -0
- package/microservices/microservice-notifications/src/db/database.ts +20 -22
- package/microservices/microservice-payments/package.json +1 -0
- package/microservices/microservice-payments/src/db/database.ts +20 -22
- package/microservices/microservice-payroll/package.json +1 -0
- package/microservices/microservice-payroll/src/db/database.ts +20 -22
- package/microservices/microservice-products/package.json +1 -0
- package/microservices/microservice-products/src/db/database.ts +20 -22
- package/microservices/microservice-projects/package.json +1 -0
- package/microservices/microservice-projects/src/db/database.ts +20 -22
- package/microservices/microservice-proposals/package.json +1 -0
- package/microservices/microservice-proposals/src/db/database.ts +20 -22
- package/microservices/microservice-reading/package.json +1 -0
- package/microservices/microservice-reading/src/db/database.ts +20 -22
- package/microservices/microservice-shipping/package.json +1 -0
- package/microservices/microservice-shipping/src/db/database.ts +20 -22
- package/microservices/microservice-social/package.json +1 -0
- package/microservices/microservice-social/src/db/database.ts +20 -22
- package/microservices/microservice-subscriptions/package.json +1 -0
- package/microservices/microservice-subscriptions/src/db/database.ts +20 -22
- package/microservices/microservice-timesheets/package.json +1 -0
- package/microservices/microservice-timesheets/src/db/database.ts +20 -11
- package/microservices/microservice-transcriber/package.json +1 -0
- package/microservices/microservice-transcriber/src/db/database.ts +20 -11
- package/microservices/microservice-travel/package.json +1 -0
- package/microservices/microservice-travel/src/db/database.ts +20 -22
- package/microservices/microservice-wiki/package.json +1 -0
- package/microservices/microservice-wiki/src/db/database.ts +20 -22
- package/package.json +2 -2
- package/microservices/microservice-invoices/dashboard/dist/assets/index-Bngq7FNM.css +0 -1
- package/microservices/microservice-invoices/dashboard/dist/assets/index-aHW4ARZR.js +0 -124
- package/microservices/microservice-invoices/dashboard/dist/index.html +0 -13
|
@@ -2,53 +2,52 @@
|
|
|
2
2
|
* Database connection for microservice-health
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
+
import type { Database } from "bun:sqlite";
|
|
7
|
+
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
7
8
|
import { dirname, join, resolve } from "node:path";
|
|
8
9
|
import { MIGRATIONS } from "./migrations.js";
|
|
9
10
|
|
|
10
11
|
let _db: Database | null = null;
|
|
11
12
|
|
|
12
13
|
function getDbPath(): string {
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
return join(
|
|
14
|
+
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
+
if (explicit) {
|
|
16
|
+
return join(explicit, "microservice-health", "data.db");
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
// Check for .microservices in current or parent directories
|
|
19
19
|
let dir = resolve(process.cwd());
|
|
20
20
|
while (true) {
|
|
21
|
-
const candidate = join(dir, ".microservices", "microservice-health", "data.db");
|
|
22
21
|
const msDir = join(dir, ".microservices");
|
|
23
|
-
if (existsSync(msDir)) return
|
|
22
|
+
if (existsSync(msDir)) return join(msDir, "microservice-health", "data.db");
|
|
24
23
|
const parent = dirname(dir);
|
|
25
24
|
if (parent === dir) break;
|
|
26
25
|
dir = parent;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
// Global fallback
|
|
30
28
|
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!existsSync(dir)) {
|
|
37
|
-
mkdirSync(dir, { recursive: true });
|
|
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 });
|
|
38
34
|
}
|
|
35
|
+
return join(newDir, "microservice-health", "data.db");
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
export function getDatabase(): Database {
|
|
42
39
|
if (_db) return _db;
|
|
43
40
|
|
|
44
41
|
const dbPath = getDbPath();
|
|
45
|
-
|
|
42
|
+
const dir = dirname(resolve(dbPath));
|
|
43
|
+
if (!existsSync(dir)) {
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
_db
|
|
49
|
-
|
|
47
|
+
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
+
_db = adapter.raw;
|
|
49
|
+
// SqliteAdapter already sets WAL and foreign_keys
|
|
50
50
|
|
|
51
|
-
// Create migrations table
|
|
52
51
|
_db.exec(`
|
|
53
52
|
CREATE TABLE IF NOT EXISTS _migrations (
|
|
54
53
|
id INTEGER PRIMARY KEY,
|
|
@@ -57,7 +56,6 @@ export function getDatabase(): Database {
|
|
|
57
56
|
)
|
|
58
57
|
`);
|
|
59
58
|
|
|
60
|
-
// Apply pending migrations
|
|
61
59
|
const applied = _db
|
|
62
60
|
.query("SELECT id FROM _migrations ORDER BY id")
|
|
63
61
|
.all() as { id: number }[];
|
|
@@ -2,53 +2,52 @@
|
|
|
2
2
|
* Database connection for microservice-hiring
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
+
import type { Database } from "bun:sqlite";
|
|
7
|
+
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
7
8
|
import { dirname, join, resolve } from "node:path";
|
|
8
9
|
import { MIGRATIONS } from "./migrations.js";
|
|
9
10
|
|
|
10
11
|
let _db: Database | null = null;
|
|
11
12
|
|
|
12
13
|
function getDbPath(): string {
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
return join(
|
|
14
|
+
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
+
if (explicit) {
|
|
16
|
+
return join(explicit, "microservice-hiring", "data.db");
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
// Check for .microservices in current or parent directories
|
|
19
19
|
let dir = resolve(process.cwd());
|
|
20
20
|
while (true) {
|
|
21
|
-
const candidate = join(dir, ".microservices", "microservice-hiring", "data.db");
|
|
22
21
|
const msDir = join(dir, ".microservices");
|
|
23
|
-
if (existsSync(msDir)) return
|
|
22
|
+
if (existsSync(msDir)) return join(msDir, "microservice-hiring", "data.db");
|
|
24
23
|
const parent = dirname(dir);
|
|
25
24
|
if (parent === dir) break;
|
|
26
25
|
dir = parent;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
// Global fallback
|
|
30
28
|
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!existsSync(dir)) {
|
|
37
|
-
mkdirSync(dir, { recursive: true });
|
|
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 });
|
|
38
34
|
}
|
|
35
|
+
return join(newDir, "microservice-hiring", "data.db");
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
export function getDatabase(): Database {
|
|
42
39
|
if (_db) return _db;
|
|
43
40
|
|
|
44
41
|
const dbPath = getDbPath();
|
|
45
|
-
|
|
42
|
+
const dir = dirname(resolve(dbPath));
|
|
43
|
+
if (!existsSync(dir)) {
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
_db
|
|
49
|
-
|
|
47
|
+
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
+
_db = adapter.raw;
|
|
49
|
+
// SqliteAdapter already sets WAL and foreign_keys
|
|
50
50
|
|
|
51
|
-
// Create migrations table
|
|
52
51
|
_db.exec(`
|
|
53
52
|
CREATE TABLE IF NOT EXISTS _migrations (
|
|
54
53
|
id INTEGER PRIMARY KEY,
|
|
@@ -57,7 +56,6 @@ export function getDatabase(): Database {
|
|
|
57
56
|
)
|
|
58
57
|
`);
|
|
59
58
|
|
|
60
|
-
// Apply pending migrations
|
|
61
59
|
const applied = _db
|
|
62
60
|
.query("SELECT id FROM _migrations ORDER BY id")
|
|
63
61
|
.all() as { id: number }[];
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
* Database connection for microservice-inventory
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
+
import type { Database } from "bun:sqlite";
|
|
7
|
+
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
7
8
|
import { dirname, join, resolve } from "node:path";
|
|
8
9
|
import { MIGRATIONS } from "./migrations.js";
|
|
9
10
|
|
|
10
11
|
let _db: Database | null = null;
|
|
11
12
|
|
|
12
13
|
function getDbPath(): string {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
+
if (explicit) {
|
|
16
|
+
return join(explicit, "microservice-inventory", "data.db");
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
let dir = resolve(process.cwd());
|
|
@@ -24,21 +26,27 @@ function getDbPath(): string {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
27
|
-
|
|
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-inventory", "data.db");
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
export function getDatabase(): Database {
|
|
31
39
|
if (_db) return _db;
|
|
32
40
|
|
|
33
41
|
const dbPath = getDbPath();
|
|
34
|
-
const
|
|
35
|
-
if (!existsSync(
|
|
36
|
-
mkdirSync(
|
|
42
|
+
const dir = dirname(resolve(dbPath));
|
|
43
|
+
if (!existsSync(dir)) {
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
_db
|
|
41
|
-
|
|
47
|
+
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
+
_db = adapter.raw;
|
|
49
|
+
// SqliteAdapter already sets WAL and foreign_keys
|
|
42
50
|
|
|
43
51
|
_db.exec(`
|
|
44
52
|
CREATE TABLE IF NOT EXISTS _migrations (
|
|
@@ -55,6 +63,7 @@ export function getDatabase(): Database {
|
|
|
55
63
|
|
|
56
64
|
for (const migration of MIGRATIONS) {
|
|
57
65
|
if (appliedIds.has(migration.id)) continue;
|
|
66
|
+
|
|
58
67
|
_db.exec("BEGIN");
|
|
59
68
|
try {
|
|
60
69
|
_db.exec(migration.sql);
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
* Database connection for microservice-invoices
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
+
import type { Database } from "bun:sqlite";
|
|
7
|
+
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
7
8
|
import { dirname, join, resolve } from "node:path";
|
|
8
9
|
import { MIGRATIONS } from "./migrations.js";
|
|
9
10
|
|
|
10
11
|
let _db: Database | null = null;
|
|
11
12
|
|
|
12
13
|
function getDbPath(): string {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
+
if (explicit) {
|
|
16
|
+
return join(explicit, "microservice-invoices", "data.db");
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
let dir = resolve(process.cwd());
|
|
@@ -24,21 +26,27 @@ function getDbPath(): string {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
27
|
-
|
|
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-invoices", "data.db");
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
export function getDatabase(): Database {
|
|
31
39
|
if (_db) return _db;
|
|
32
40
|
|
|
33
41
|
const dbPath = getDbPath();
|
|
34
|
-
const
|
|
35
|
-
if (!existsSync(
|
|
36
|
-
mkdirSync(
|
|
42
|
+
const dir = dirname(resolve(dbPath));
|
|
43
|
+
if (!existsSync(dir)) {
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
_db
|
|
41
|
-
|
|
47
|
+
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
+
_db = adapter.raw;
|
|
49
|
+
// SqliteAdapter already sets WAL and foreign_keys
|
|
42
50
|
|
|
43
51
|
_db.exec(`
|
|
44
52
|
CREATE TABLE IF NOT EXISTS _migrations (
|
|
@@ -55,6 +63,7 @@ export function getDatabase(): Database {
|
|
|
55
63
|
|
|
56
64
|
for (const migration of MIGRATIONS) {
|
|
57
65
|
if (appliedIds.has(migration.id)) continue;
|
|
66
|
+
|
|
58
67
|
_db.exec("BEGIN");
|
|
59
68
|
try {
|
|
60
69
|
_db.exec(migration.sql);
|
|
@@ -2,53 +2,52 @@
|
|
|
2
2
|
* Database connection for microservice-leads
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
+
import type { Database } from "bun:sqlite";
|
|
7
|
+
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
7
8
|
import { dirname, join, resolve } from "node:path";
|
|
8
9
|
import { MIGRATIONS } from "./migrations.js";
|
|
9
10
|
|
|
10
11
|
let _db: Database | null = null;
|
|
11
12
|
|
|
12
13
|
function getDbPath(): string {
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
return join(
|
|
14
|
+
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
+
if (explicit) {
|
|
16
|
+
return join(explicit, "microservice-leads", "data.db");
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
// Check for .microservices in current or parent directories
|
|
19
19
|
let dir = resolve(process.cwd());
|
|
20
20
|
while (true) {
|
|
21
|
-
const candidate = join(dir, ".microservices", "microservice-leads", "data.db");
|
|
22
21
|
const msDir = join(dir, ".microservices");
|
|
23
|
-
if (existsSync(msDir)) return
|
|
22
|
+
if (existsSync(msDir)) return join(msDir, "microservice-leads", "data.db");
|
|
24
23
|
const parent = dirname(dir);
|
|
25
24
|
if (parent === dir) break;
|
|
26
25
|
dir = parent;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
// Global fallback
|
|
30
28
|
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!existsSync(dir)) {
|
|
37
|
-
mkdirSync(dir, { recursive: true });
|
|
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 });
|
|
38
34
|
}
|
|
35
|
+
return join(newDir, "microservice-leads", "data.db");
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
export function getDatabase(): Database {
|
|
42
39
|
if (_db) return _db;
|
|
43
40
|
|
|
44
41
|
const dbPath = getDbPath();
|
|
45
|
-
|
|
42
|
+
const dir = dirname(resolve(dbPath));
|
|
43
|
+
if (!existsSync(dir)) {
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
_db
|
|
49
|
-
|
|
47
|
+
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
+
_db = adapter.raw;
|
|
49
|
+
// SqliteAdapter already sets WAL and foreign_keys
|
|
50
50
|
|
|
51
|
-
// Create migrations table
|
|
52
51
|
_db.exec(`
|
|
53
52
|
CREATE TABLE IF NOT EXISTS _migrations (
|
|
54
53
|
id INTEGER PRIMARY KEY,
|
|
@@ -57,7 +56,6 @@ export function getDatabase(): Database {
|
|
|
57
56
|
)
|
|
58
57
|
`);
|
|
59
58
|
|
|
60
|
-
// Apply pending migrations
|
|
61
59
|
const applied = _db
|
|
62
60
|
.query("SELECT id FROM _migrations ORDER BY id")
|
|
63
61
|
.all() as { id: number }[];
|
|
@@ -2,53 +2,52 @@
|
|
|
2
2
|
* Database connection for microservice-notes
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
+
import type { Database } from "bun:sqlite";
|
|
7
|
+
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
7
8
|
import { dirname, join, resolve } from "node:path";
|
|
8
9
|
import { MIGRATIONS } from "./migrations.js";
|
|
9
10
|
|
|
10
11
|
let _db: Database | null = null;
|
|
11
12
|
|
|
12
13
|
function getDbPath(): string {
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
return join(
|
|
14
|
+
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
+
if (explicit) {
|
|
16
|
+
return join(explicit, "microservice-notes", "data.db");
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
// Check for .microservices in current or parent directories
|
|
19
19
|
let dir = resolve(process.cwd());
|
|
20
20
|
while (true) {
|
|
21
|
-
const candidate = join(dir, ".microservices", "microservice-notes", "data.db");
|
|
22
21
|
const msDir = join(dir, ".microservices");
|
|
23
|
-
if (existsSync(msDir)) return
|
|
22
|
+
if (existsSync(msDir)) return join(msDir, "microservice-notes", "data.db");
|
|
24
23
|
const parent = dirname(dir);
|
|
25
24
|
if (parent === dir) break;
|
|
26
25
|
dir = parent;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
// Global fallback
|
|
30
28
|
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!existsSync(dir)) {
|
|
37
|
-
mkdirSync(dir, { recursive: true });
|
|
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 });
|
|
38
34
|
}
|
|
35
|
+
return join(newDir, "microservice-notes", "data.db");
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
export function getDatabase(): Database {
|
|
42
39
|
if (_db) return _db;
|
|
43
40
|
|
|
44
41
|
const dbPath = getDbPath();
|
|
45
|
-
|
|
42
|
+
const dir = dirname(resolve(dbPath));
|
|
43
|
+
if (!existsSync(dir)) {
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
_db
|
|
49
|
-
|
|
47
|
+
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
+
_db = adapter.raw;
|
|
49
|
+
// SqliteAdapter already sets WAL and foreign_keys
|
|
50
50
|
|
|
51
|
-
// Create migrations table
|
|
52
51
|
_db.exec(`
|
|
53
52
|
CREATE TABLE IF NOT EXISTS _migrations (
|
|
54
53
|
id INTEGER PRIMARY KEY,
|
|
@@ -57,7 +56,6 @@ export function getDatabase(): Database {
|
|
|
57
56
|
)
|
|
58
57
|
`);
|
|
59
58
|
|
|
60
|
-
// Apply pending migrations
|
|
61
59
|
const applied = _db
|
|
62
60
|
.query("SELECT id FROM _migrations ORDER BY id")
|
|
63
61
|
.all() as { id: number }[];
|
|
@@ -2,53 +2,52 @@
|
|
|
2
2
|
* Database connection for microservice-notifications
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
+
import type { Database } from "bun:sqlite";
|
|
7
|
+
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
7
8
|
import { dirname, join, resolve } from "node:path";
|
|
8
9
|
import { MIGRATIONS } from "./migrations.js";
|
|
9
10
|
|
|
10
11
|
let _db: Database | null = null;
|
|
11
12
|
|
|
12
13
|
function getDbPath(): string {
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
return join(
|
|
14
|
+
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
+
if (explicit) {
|
|
16
|
+
return join(explicit, "microservice-notifications", "data.db");
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
// Check for .microservices in current or parent directories
|
|
19
19
|
let dir = resolve(process.cwd());
|
|
20
20
|
while (true) {
|
|
21
|
-
const candidate = join(dir, ".microservices", "microservice-notifications", "data.db");
|
|
22
21
|
const msDir = join(dir, ".microservices");
|
|
23
|
-
if (existsSync(msDir)) return
|
|
22
|
+
if (existsSync(msDir)) return join(msDir, "microservice-notifications", "data.db");
|
|
24
23
|
const parent = dirname(dir);
|
|
25
24
|
if (parent === dir) break;
|
|
26
25
|
dir = parent;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
// Global fallback
|
|
30
28
|
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!existsSync(dir)) {
|
|
37
|
-
mkdirSync(dir, { recursive: true });
|
|
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 });
|
|
38
34
|
}
|
|
35
|
+
return join(newDir, "microservice-notifications", "data.db");
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
export function getDatabase(): Database {
|
|
42
39
|
if (_db) return _db;
|
|
43
40
|
|
|
44
41
|
const dbPath = getDbPath();
|
|
45
|
-
|
|
42
|
+
const dir = dirname(resolve(dbPath));
|
|
43
|
+
if (!existsSync(dir)) {
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
_db
|
|
49
|
-
|
|
47
|
+
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
+
_db = adapter.raw;
|
|
49
|
+
// SqliteAdapter already sets WAL and foreign_keys
|
|
50
50
|
|
|
51
|
-
// Create migrations table
|
|
52
51
|
_db.exec(`
|
|
53
52
|
CREATE TABLE IF NOT EXISTS _migrations (
|
|
54
53
|
id INTEGER PRIMARY KEY,
|
|
@@ -57,7 +56,6 @@ export function getDatabase(): Database {
|
|
|
57
56
|
)
|
|
58
57
|
`);
|
|
59
58
|
|
|
60
|
-
// Apply pending migrations
|
|
61
59
|
const applied = _db
|
|
62
60
|
.query("SELECT id FROM _migrations ORDER BY id")
|
|
63
61
|
.all() as { id: number }[];
|