@hasna/economy 0.3.9 → 0.3.10
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/CHANGELOG.md +12 -0
- package/dist/cli/brains.d.ts +3 -0
- package/dist/cli/brains.d.ts.map +1 -0
- package/dist/cli/commands/brief.d.ts +11 -0
- package/dist/cli/commands/brief.d.ts.map +1 -0
- package/dist/cli/commands/completion.d.ts +2 -0
- package/dist/cli/commands/completion.d.ts.map +1 -0
- package/dist/cli/commands/extras.d.ts +4 -0
- package/dist/cli/commands/extras.d.ts.map +1 -0
- package/dist/cli/commands/menubar.d.ts +7 -0
- package/dist/cli/commands/menubar.d.ts.map +1 -0
- package/dist/cli/commands/notification.d.ts +8 -0
- package/dist/cli/commands/notification.d.ts.map +1 -0
- package/dist/cli/commands/todos.d.ts +29 -0
- package/dist/cli/commands/todos.d.ts.map +1 -0
- package/dist/cli/commands/tui.d.ts +26 -0
- package/dist/cli/commands/tui.d.ts.map +1 -0
- package/dist/cli/commands/watch.d.ts +10 -0
- package/dist/cli/commands/watch.d.ts.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +12493 -0
- package/dist/db/cloud.d.ts +47 -0
- package/dist/db/cloud.d.ts.map +1 -0
- package/dist/db/database.d.ts +157 -0
- package/dist/db/database.d.ts.map +1 -0
- package/dist/db/dialect.d.ts +13 -0
- package/dist/db/dialect.d.ts.map +1 -0
- package/dist/db/pg-migrate.d.ts +30 -0
- package/dist/db/pg-migrate.d.ts.map +1 -0
- package/dist/db/pg-migrations.d.ts +7 -0
- package/dist/db/pg-migrations.d.ts.map +1 -0
- package/dist/db/pg-sync-worker.d.ts +2 -0
- package/dist/db/pg-sync-worker.d.ts.map +1 -0
- package/dist/db/sqlite-adapter.d.ts +36 -0
- package/dist/db/sqlite-adapter.d.ts.map +1 -0
- package/dist/db/sync-pg.d.ts +43 -0
- package/dist/db/sync-pg.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3833 -0
- package/dist/ingest/billing.d.ts +27 -0
- package/dist/ingest/billing.d.ts.map +1 -0
- package/dist/ingest/claude-quota.d.ts +5 -0
- package/dist/ingest/claude-quota.d.ts.map +1 -0
- package/dist/ingest/claude.d.ts +18 -0
- package/dist/ingest/claude.d.ts.map +1 -0
- package/dist/ingest/codex-quota.d.ts +5 -0
- package/dist/ingest/codex-quota.d.ts.map +1 -0
- package/dist/ingest/codex.d.ts +8 -0
- package/dist/ingest/codex.d.ts.map +1 -0
- package/dist/ingest/cursor.d.ts +6 -0
- package/dist/ingest/cursor.d.ts.map +1 -0
- package/dist/ingest/gemini.d.ts +6 -0
- package/dist/ingest/gemini.d.ts.map +1 -0
- package/dist/ingest/hermes.d.ts +6 -0
- package/dist/ingest/hermes.d.ts.map +1 -0
- package/dist/ingest/loops.d.ts +6 -0
- package/dist/ingest/loops.d.ts.map +1 -0
- package/dist/ingest/opencode.d.ts +7 -0
- package/dist/ingest/opencode.d.ts.map +1 -0
- package/dist/ingest/otel.d.ts +33 -0
- package/dist/ingest/otel.d.ts.map +1 -0
- package/dist/ingest/pi.d.ts +7 -0
- package/dist/ingest/pi.d.ts.map +1 -0
- package/dist/ingest/plugin.d.ts +17 -0
- package/dist/ingest/plugin.d.ts.map +1 -0
- package/dist/lib/accounts.d.ts +11 -0
- package/dist/lib/accounts.d.ts.map +1 -0
- package/dist/lib/agents.d.ts +11 -0
- package/dist/lib/agents.d.ts.map +1 -0
- package/dist/lib/analytics.d.ts +68 -0
- package/dist/lib/analytics.d.ts.map +1 -0
- package/dist/lib/billing-diff.d.ts +61 -0
- package/dist/lib/billing-diff.d.ts.map +1 -0
- package/dist/lib/brief.d.ts +72 -0
- package/dist/lib/brief.d.ts.map +1 -0
- package/dist/lib/cloud-storage.d.ts +48 -0
- package/dist/lib/cloud-storage.d.ts.map +1 -0
- package/dist/lib/config.d.ts +13 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/contracts-client/index.d.ts +3 -0
- package/dist/lib/contracts-client/index.d.ts.map +1 -0
- package/dist/lib/contracts-client/mode.d.ts +20 -0
- package/dist/lib/contracts-client/mode.d.ts.map +1 -0
- package/dist/lib/contracts-client/storage.d.ts +83 -0
- package/dist/lib/contracts-client/storage.d.ts.map +1 -0
- package/dist/lib/contracts-client/transport.d.ts +148 -0
- package/dist/lib/contracts-client/transport.d.ts.map +1 -0
- package/dist/lib/gatherer.d.ts +21 -0
- package/dist/lib/gatherer.d.ts.map +1 -0
- package/dist/lib/model-config.d.ts +8 -0
- package/dist/lib/model-config.d.ts.map +1 -0
- package/dist/lib/open-projects.d.ts +27 -0
- package/dist/lib/open-projects.d.ts.map +1 -0
- package/dist/lib/package-metadata.d.ts +8 -0
- package/dist/lib/package-metadata.d.ts.map +1 -0
- package/dist/lib/paths.d.ts +20 -0
- package/dist/lib/paths.d.ts.map +1 -0
- package/dist/lib/periods.d.ts +6 -0
- package/dist/lib/periods.d.ts.map +1 -0
- package/dist/lib/pricing.d.ts +13 -0
- package/dist/lib/pricing.d.ts.map +1 -0
- package/dist/lib/savings.d.ts +17 -0
- package/dist/lib/savings.d.ts.map +1 -0
- package/dist/lib/serve-auth.d.ts +4 -0
- package/dist/lib/serve-auth.d.ts.map +1 -0
- package/dist/lib/spikes.d.ts +18 -0
- package/dist/lib/spikes.d.ts.map +1 -0
- package/dist/lib/store/index.d.ts +303 -0
- package/dist/lib/store/index.d.ts.map +1 -0
- package/dist/lib/sync-all.d.ts +28 -0
- package/dist/lib/sync-all.d.ts.map +1 -0
- package/dist/lib/watch-paths.d.ts +3 -0
- package/dist/lib/watch-paths.d.ts.map +1 -0
- package/dist/lib/webhooks.d.ts +3 -0
- package/dist/lib/webhooks.d.ts.map +1 -0
- package/dist/mcp/http.d.ts +14 -0
- package/dist/mcp/http.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +6274 -0
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/openapi.d.ts +3 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/otel/index.d.ts +3 -0
- package/dist/otel/index.d.ts.map +1 -0
- package/dist/otel/index.js +1464 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +8327 -0
- package/dist/server/pg-sync-worker.js +31 -0
- package/dist/server/serve.d.ts +42 -0
- package/dist/server/serve.d.ts.map +1 -0
- package/dist/types/index.d.ts +238 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AuthQueryClient } from '@hasna/contracts/auth';
|
|
2
|
+
import type { ServerDataBackend } from '@hasna/contracts/schemas';
|
|
3
|
+
import pg from 'pg';
|
|
4
|
+
import type { DbAdapter, SqliteAdapter as Database } from './sqlite-adapter.js';
|
|
5
|
+
/** The environment shape the backend resolver reads. */
|
|
6
|
+
type Env = Record<string, string | undefined>;
|
|
7
|
+
/** Resolve the Postgres DSN from the standard env aliases. */
|
|
8
|
+
export declare function getCloudDatabaseUrl(env?: Env): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the server data backend from database configuration ALONE.
|
|
11
|
+
*
|
|
12
|
+
* `@hasna/contracts` 0.9.0 removed the deployment-mode axis: the only switch is
|
|
13
|
+
* the server's data backend, `sqlite | postgresql`, and a present database URL
|
|
14
|
+
* is what selects `postgresql`. Retired `STORAGE_MODE` / `MODE` variables are
|
|
15
|
+
* rejected with a migration hint rather than normalized or silently mapped
|
|
16
|
+
* (CONTRACT.md section 2), so a half-migrated deployment fails loudly at startup
|
|
17
|
+
* instead of quietly serving the wrong store.
|
|
18
|
+
*
|
|
19
|
+
* The rejection is delegated to the contract package so the migration hint stays
|
|
20
|
+
* identical to the one the `server_backend_configuration` conformance gate emits.
|
|
21
|
+
* DSN resolution stays local because economy also honours the bare `DATABASE_URL`
|
|
22
|
+
* alias, which the contract's own resolver does not read — deferring to it
|
|
23
|
+
* wholesale would silently downgrade such a deployment to sqlite.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveEconomyServerBackend(env?: Env): ServerDataBackend;
|
|
26
|
+
/** True when the serve reads and writes PostgreSQL directly. */
|
|
27
|
+
export declare function isPostgresBackend(env?: Env): boolean;
|
|
28
|
+
/** HMAC signing secret for API-key verification (server-held, never in a token). */
|
|
29
|
+
export declare function resolveSigningSecret(): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Open a pooled Postgres connection to the shared RDS. Returns a value typed as
|
|
32
|
+
* the SQLite `Database` the query layer expects — safe because `SyncPgAdapter`
|
|
33
|
+
* implements the identical `DbAdapter` surface those functions rely on.
|
|
34
|
+
*/
|
|
35
|
+
export declare function openCloudDatabase(dsn?: string | undefined): Database;
|
|
36
|
+
/** A raw pg Pool for auxiliary async work (API-key store, migrations). */
|
|
37
|
+
export declare function createCloudPool(dsn?: string | undefined): pg.Pool;
|
|
38
|
+
/**
|
|
39
|
+
* Adapt a pg Pool to the `@hasna/contracts/auth` `AuthQueryClient` surface
|
|
40
|
+
* (many/get/execute). This backs the `ApiKeyStore` without pulling in the
|
|
41
|
+
* generic vendored kit — economy's storage is this pg pool.
|
|
42
|
+
*/
|
|
43
|
+
export declare function authClientFromPool(pool: pg.Pool): AuthQueryClient;
|
|
44
|
+
/** Ordered PG migrations applied by the migration runner (index = version). */
|
|
45
|
+
export declare function cloudMigrations(): string[];
|
|
46
|
+
export type { DbAdapter };
|
|
47
|
+
//# sourceMappingURL=cloud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../src/db/cloud.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,IAAI,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAK/E,wDAAwD;AACxD,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAE7C,8DAA8D;AAC9D,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,GAAiB,GAAG,MAAM,GAAG,SAAS,CAO9E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,GAAE,GAAiB,GAAG,iBAAiB,CAGrF;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,GAAiB,GAAG,OAAO,CAEjE;AAED,oFAAoF;AACpF,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAOzD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,qBAAwB,GAAG,QAAQ,CASvE;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,GAAG,qBAAwB,GAAG,EAAE,CAAC,IAAI,CAWpE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,eAAe,CAcjE;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,IAAI,MAAM,EAAE,CAE1C;AAED,YAAY,EAAE,SAAS,EAAE,CAAA"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { SqliteAdapter as Database } from './sqlite-adapter.js';
|
|
2
|
+
import type { EconomyRequest, EconomySession, EconomyProject, CostCenter, CostCenterBreakdown, CostCenterKind, Budget, BudgetStatus, CostSummary, ZeroCostModelBreakdown, ModelBreakdown, ProjectBreakdown, AgentBreakdown, AccountBreakdown, Period, Agent, SessionFilter } from '../types/index.js';
|
|
3
|
+
export declare function getMachineId(): string;
|
|
4
|
+
export declare function getDataDir(): string;
|
|
5
|
+
export declare function getDbPath(): string;
|
|
6
|
+
export declare function openDatabase(dbPath?: string, skipSeed?: boolean): Database;
|
|
7
|
+
export declare function upsertCostCenter(db: Database, center: CostCenter): void;
|
|
8
|
+
export declare function getCostCenter(db: Database, id: string): CostCenter | null;
|
|
9
|
+
export declare function upsertRequest(db: Database, req: EconomyRequest): void;
|
|
10
|
+
export declare function upsertSession(db: Database, session: EconomySession): void;
|
|
11
|
+
export declare function rollupSession(db: Database, sessionId: string): void;
|
|
12
|
+
export declare function querySessions(db: Database, filter?: SessionFilter): EconomySession[];
|
|
13
|
+
export declare function queryTopSessions(db: Database, n?: number, agent?: string, since?: string): EconomySession[];
|
|
14
|
+
export declare function querySummary(db: Database, period: Period, machine?: string, allMachines?: boolean, agent?: Agent): CostSummary;
|
|
15
|
+
export declare function queryZeroCostTokenizedModels(db: Database, limit?: number): ZeroCostModelBreakdown[];
|
|
16
|
+
export declare function queryModelBreakdown(db: Database): ModelBreakdown[];
|
|
17
|
+
export declare function queryAgentBreakdown(db: Database, period?: Period, machine?: string): AgentBreakdown[];
|
|
18
|
+
export declare function queryProjectBreakdown(db: Database, period?: Period, machine?: string): ProjectBreakdown[];
|
|
19
|
+
export declare function queryAccountBreakdown(db: Database, period?: Period, machine?: string): AccountBreakdown[];
|
|
20
|
+
export declare function queryCostCenterBreakdown(db: Database, period?: Period, filter?: {
|
|
21
|
+
kind?: CostCenterKind;
|
|
22
|
+
machine?: string;
|
|
23
|
+
since?: string;
|
|
24
|
+
}): CostCenterBreakdown[];
|
|
25
|
+
export declare function queryProjectBreakdownSince(db: Database, since: string, machine?: string): ProjectBreakdown[];
|
|
26
|
+
export declare function queryAgentBreakdownSince(db: Database, since: string): AgentBreakdown[];
|
|
27
|
+
export declare function queryModelBreakdownSince(db: Database, since: string): ModelBreakdown[];
|
|
28
|
+
export declare function queryAccountBreakdownSince(db: Database, since: string): AccountBreakdown[];
|
|
29
|
+
export declare function queryDailyBreakdown(db: Database, days?: number, machine?: string): Array<{
|
|
30
|
+
date: string;
|
|
31
|
+
cost_usd: number;
|
|
32
|
+
agent: string;
|
|
33
|
+
}>;
|
|
34
|
+
export declare function queryHourlyBreakdown(db: Database, machine?: string, hours?: number): Array<{
|
|
35
|
+
hour: string;
|
|
36
|
+
cost_usd: number;
|
|
37
|
+
agent: string;
|
|
38
|
+
}>;
|
|
39
|
+
export declare function upsertProject(db: Database, project: EconomyProject): void;
|
|
40
|
+
export declare function getProject(db: Database, path: string): EconomyProject | null;
|
|
41
|
+
export declare function listProjects(db: Database): EconomyProject[];
|
|
42
|
+
export declare function deleteProject(db: Database, path: string): void;
|
|
43
|
+
export declare function upsertBudget(db: Database, budget: Budget): void;
|
|
44
|
+
export declare function listBudgets(db: Database): Budget[];
|
|
45
|
+
export declare function deleteBudget(db: Database, id: string): void;
|
|
46
|
+
export declare function getBudgetStatuses(db: Database): BudgetStatus[];
|
|
47
|
+
export interface Goal {
|
|
48
|
+
id: string;
|
|
49
|
+
period: 'day' | 'week' | 'month' | 'year';
|
|
50
|
+
project_path: string | null;
|
|
51
|
+
agent: string | null;
|
|
52
|
+
limit_usd: number;
|
|
53
|
+
created_at: string;
|
|
54
|
+
updated_at: string;
|
|
55
|
+
}
|
|
56
|
+
export interface GoalStatus extends Goal {
|
|
57
|
+
current_spend_usd: number;
|
|
58
|
+
percent_used: number;
|
|
59
|
+
is_on_track: boolean;
|
|
60
|
+
is_at_risk: boolean;
|
|
61
|
+
is_over: boolean;
|
|
62
|
+
}
|
|
63
|
+
export declare function upsertGoal(db: Database, goal: Goal): void;
|
|
64
|
+
export declare function deleteGoal(db: Database, id: string): void;
|
|
65
|
+
export declare function listGoals(db: Database): Goal[];
|
|
66
|
+
export declare function getGoalStatuses(db: Database): GoalStatus[];
|
|
67
|
+
export declare function getIngestState(db: Database, source: string, key: string): string | null;
|
|
68
|
+
export declare function setIngestState(db: Database, source: string, key: string, value: string): void;
|
|
69
|
+
export declare function queryRequestsSince(db: Database, since: string): EconomyRequest[];
|
|
70
|
+
export interface FeedbackRecord {
|
|
71
|
+
message: string;
|
|
72
|
+
email?: string | null;
|
|
73
|
+
category?: string | null;
|
|
74
|
+
version?: string | null;
|
|
75
|
+
machine_id?: string | null;
|
|
76
|
+
}
|
|
77
|
+
/** Persist a feedback row. Used by both the LocalStore and the serve endpoint. */
|
|
78
|
+
export declare function insertFeedback(db: Database, record: FeedbackRecord): void;
|
|
79
|
+
export interface BillingDaily {
|
|
80
|
+
date: string;
|
|
81
|
+
provider: 'anthropic' | 'openai' | string;
|
|
82
|
+
description: string;
|
|
83
|
+
cost_usd: number;
|
|
84
|
+
updated_at: string;
|
|
85
|
+
}
|
|
86
|
+
export declare function upsertBillingDaily(db: Database, row: BillingDaily): void;
|
|
87
|
+
export declare function clearBillingRange(db: Database, provider: string, fromDate: string, toDate: string): void;
|
|
88
|
+
export declare function queryBillingSummary(db: Database, period: Period): {
|
|
89
|
+
total_usd: number;
|
|
90
|
+
by_provider: Record<string, number>;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* How many provider billing rows exist for a period. A $0.00 actual total is
|
|
94
|
+
* ambiguous on its own — it is produced both by "billing agrees with telemetry
|
|
95
|
+
* at zero" and by "billing was never imported" — and only this count separates
|
|
96
|
+
* them.
|
|
97
|
+
*/
|
|
98
|
+
export declare function countBillingRecords(db: Database, period: Period): number;
|
|
99
|
+
export interface SessionDetail {
|
|
100
|
+
session: Record<string, unknown>;
|
|
101
|
+
requests: Array<Record<string, unknown>>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Fetch a single session (by exact id or id-prefix) plus its per-request rows,
|
|
105
|
+
* ordered oldest-first. Returns null when no session matches. Backs the CLI
|
|
106
|
+
* `session <id>` command and the MCP `get_session_detail` tool via the Store.
|
|
107
|
+
*/
|
|
108
|
+
export declare function getSessionDetail(db: Database, id: string): SessionDetail | null;
|
|
109
|
+
export interface MachineInfo {
|
|
110
|
+
machine_id: string;
|
|
111
|
+
sessions: number;
|
|
112
|
+
requests: number;
|
|
113
|
+
total_cost_usd: number;
|
|
114
|
+
last_active: string;
|
|
115
|
+
}
|
|
116
|
+
export declare function listMachines(db: Database, period?: Period): MachineInfo[];
|
|
117
|
+
export interface DbModelPricing {
|
|
118
|
+
model: string;
|
|
119
|
+
input_per_1m: number;
|
|
120
|
+
output_per_1m: number;
|
|
121
|
+
cache_read_per_1m: number;
|
|
122
|
+
cache_write_per_1m: number;
|
|
123
|
+
cache_write_1h_per_1m?: number;
|
|
124
|
+
cache_storage_per_1m_hour?: number;
|
|
125
|
+
updated_at: string;
|
|
126
|
+
}
|
|
127
|
+
export declare function upsertModelPricing(db: Database, p: DbModelPricing): void;
|
|
128
|
+
export declare function getModelPricing(db: Database, model: string): DbModelPricing | null;
|
|
129
|
+
export declare function listModelPricing(db: Database): DbModelPricing[];
|
|
130
|
+
export declare function deleteModelPricing(db: Database, model: string): void;
|
|
131
|
+
export declare function seedModelPricing(db: Database, defaults: Record<string, {
|
|
132
|
+
inputPer1M: number;
|
|
133
|
+
outputPer1M: number;
|
|
134
|
+
cacheReadPer1M: number;
|
|
135
|
+
cacheWritePer1M: number;
|
|
136
|
+
cacheWrite1hPer1M?: number;
|
|
137
|
+
cacheStoragePer1MHour?: number;
|
|
138
|
+
}>): void;
|
|
139
|
+
export declare function upsertSubscription(db: Database, sub: import('../types/index.js').Subscription): void;
|
|
140
|
+
export declare function listSubscriptions(db: Database): import('../types/index.js').Subscription[];
|
|
141
|
+
export declare function deleteSubscription(db: Database, id: string): void;
|
|
142
|
+
export declare function upsertUsageSnapshot(db: Database, snap: Omit<import('../types/index.js').UsageSnapshot, 'id' | 'updated_at'> & {
|
|
143
|
+
id?: string;
|
|
144
|
+
updated_at?: string;
|
|
145
|
+
}): void;
|
|
146
|
+
export declare function queryUsageSnapshots(db: Database, opts?: {
|
|
147
|
+
agent?: string;
|
|
148
|
+
date?: string;
|
|
149
|
+
since?: string;
|
|
150
|
+
}): import('../types/index.js').UsageSnapshot[];
|
|
151
|
+
export declare function listMachineRegistry(db: Database): import('../types/index.js').MachineRegistry[];
|
|
152
|
+
export declare function dedupeRequests(db: Database): number;
|
|
153
|
+
export declare function bulkIngest(db: Database, body: Record<string, unknown>): {
|
|
154
|
+
ingested: Record<string, number>;
|
|
155
|
+
total: number;
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/db/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAM/D,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,cAAc,EACd,UAAU,EACV,mBAAmB,EACnB,cAAc,EACd,MAAM,EACN,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,MAAM,EACN,KAAK,EACL,aAAa,EACd,MAAM,mBAAmB,CAAA;AAyB1B,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAkBnC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAIlC;AAkCD,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,QAAQ,CAwBxE;AAoSD,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAUvE;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAEzE;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,GAAG,IAAI,CAwBrE;AAID,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAm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mB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,mBAAmB,EAAE,eAAe,EAAE,CAE/F;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAqBnD;AAoJD,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAuC3H"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Dialect = 'sqlite' | 'pg';
|
|
2
|
+
/**
|
|
3
|
+
* Translate SQLite-flavored SQL to PostgreSQL.
|
|
4
|
+
* When `dialect` is "sqlite", returns the SQL unchanged.
|
|
5
|
+
*/
|
|
6
|
+
export declare function translateSql(sql: string, dialect: Dialect): string;
|
|
7
|
+
/**
|
|
8
|
+
* Flatten params for PG — bun:sqlite accepts either variadic params or a single
|
|
9
|
+
* array; pg always wants a flat array. Also maps `undefined` -> `null`, which pg
|
|
10
|
+
* would otherwise reject.
|
|
11
|
+
*/
|
|
12
|
+
export declare function translateParams(params: any[]): any[];
|
|
13
|
+
//# sourceMappingURL=dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../../src/db/dialect.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAA;AAErC;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAGlE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,CAGpD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface PgMigrationResult {
|
|
2
|
+
service: string;
|
|
3
|
+
applied: number[];
|
|
4
|
+
alreadyApplied: number[];
|
|
5
|
+
errors: string[];
|
|
6
|
+
totalMigrations: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* TLS settings for a Postgres DSN. RDS presents a certificate chain the default
|
|
10
|
+
* Node trust store does not carry, so `sslmode=require`/`ssl=true` DSNs opt into
|
|
11
|
+
* encryption without chain verification — matching how every other economy
|
|
12
|
+
* Postgres connection in this repo is dialled.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolvePgSsl(dsn: string): {
|
|
15
|
+
rejectUnauthorized: false;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Apply an ordered array of SQL migrations to a PostgreSQL database.
|
|
19
|
+
*
|
|
20
|
+
* The statements are executed verbatim: `PG_MIGRATIONS` is already Postgres DDL,
|
|
21
|
+
* so it is NOT passed through the SQLite->PG translator in `dialect.ts` (doing so
|
|
22
|
+
* would be a no-op today — `pg-migrations.test.ts` asserts that — and simply
|
|
23
|
+
* wrong for any future Postgres-native statement).
|
|
24
|
+
*
|
|
25
|
+
* @param connectionString - PG connection string (postgres://...)
|
|
26
|
+
* @param migrations - Ordered array of SQL strings. Index = version number.
|
|
27
|
+
* @param service - Service name for result reporting.
|
|
28
|
+
*/
|
|
29
|
+
export declare function applyPgMigrations(connectionString: string, migrations: string[], service?: string): Promise<PgMigrationResult>;
|
|
30
|
+
//# sourceMappingURL=pg-migrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg-migrate.d.ts","sourceRoot":"","sources":["../../src/db/pg-migrate.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,kBAAkB,EAAE,KAAK,CAAA;CAAE,GAAG,SAAS,CAEnF;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,EACxB,UAAU,EAAE,MAAM,EAAE,EACpB,OAAO,SAAY,GAClB,OAAO,CAAC,iBAAiB,CAAC,CAwC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg-migrations.d.ts","sourceRoot":"","sources":["../../src/db/pg-migrations.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,aAAa,EAAE,MAAM,EAwQjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg-sync-worker.d.ts","sourceRoot":"","sources":["../../src/db/pg-sync-worker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Database } from 'bun:sqlite';
|
|
2
|
+
export interface RunResult {
|
|
3
|
+
changes: number;
|
|
4
|
+
lastInsertRowid: number | bigint;
|
|
5
|
+
}
|
|
6
|
+
export interface PreparedStatement {
|
|
7
|
+
run(...params: any[]): RunResult;
|
|
8
|
+
get(...params: any[]): any;
|
|
9
|
+
all(...params: any[]): any[];
|
|
10
|
+
finalize(): void;
|
|
11
|
+
}
|
|
12
|
+
export interface DbAdapter {
|
|
13
|
+
run(sql: string, ...params: any[]): RunResult;
|
|
14
|
+
get(sql: string, ...params: any[]): any;
|
|
15
|
+
all(sql: string, ...params: any[]): any[];
|
|
16
|
+
exec(sql: string): void;
|
|
17
|
+
prepare(sql: string): PreparedStatement;
|
|
18
|
+
close(): void;
|
|
19
|
+
transaction<T>(fn: () => T): T;
|
|
20
|
+
}
|
|
21
|
+
export declare class SqliteAdapter implements DbAdapter {
|
|
22
|
+
private db;
|
|
23
|
+
constructor(path: string);
|
|
24
|
+
run(sql: string, ...params: any[]): RunResult;
|
|
25
|
+
get(sql: string, ...params: any[]): any;
|
|
26
|
+
all(sql: string, ...params: any[]): any[];
|
|
27
|
+
exec(sql: string): void;
|
|
28
|
+
/** Passthrough to bun:sqlite's `.query()` for callers that use `db.query()`. */
|
|
29
|
+
query(sql: string): import("bun:sqlite").Statement<unknown, import("bun:sqlite").SQLQueryBindings[] | [null] | [string] | [number] | [bigint] | [false] | [true] | [Uint8Array<ArrayBufferLike>] | [Uint8ClampedArray<ArrayBufferLike>] | [Uint16Array<ArrayBufferLike>] | [Uint32Array<ArrayBufferLike>] | [Int8Array<ArrayBufferLike>] | [Int16Array<ArrayBufferLike>] | [Int32Array<ArrayBufferLike>] | [BigUint64Array<ArrayBufferLike>] | [BigInt64Array<ArrayBufferLike>] | [Float16Array<ArrayBufferLike>] | [Float32Array<ArrayBufferLike>] | [Float64Array<ArrayBufferLike>] | [Record<string, string | number | bigint | boolean | NodeJS.TypedArray<ArrayBufferLike> | null>]>;
|
|
30
|
+
prepare(sql: string): PreparedStatement;
|
|
31
|
+
close(): void;
|
|
32
|
+
transaction<T>(fn: () => T): T;
|
|
33
|
+
/** Expose the underlying bun:sqlite Database for advanced usage. */
|
|
34
|
+
get raw(): Database;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=sqlite-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-adapter.d.ts","sourceRoot":"","sources":["../../src/db/sqlite-adapter.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,GAAG,MAAM,CAAA;CACjC;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,CAAA;IAChC,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAA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B,oEAAoE;IACpE,IAAI,GAAG,IAAI,QAAQ,CAElB;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DbAdapter, PreparedStatement, RunResult } from './sqlite-adapter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Translate the closed set of SQLite date/time idioms the economy query layer
|
|
4
|
+
* uses into Postgres equivalents. Runs AFTER `translateSql` (so `?` are already
|
|
5
|
+
* `$n`). Timestamp columns are stored as ISO-8601 TEXT in both dialects, so bare
|
|
6
|
+
* `DATE(col)` casts through `timestamptz`. Ordered most-specific first.
|
|
7
|
+
*/
|
|
8
|
+
export declare function translateSqliteDates(sql: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Connection-level failures where the query provably never executed (the pool
|
|
11
|
+
* could not hand out or keep a live backend). These are safe to retry once —
|
|
12
|
+
* the pg pool discards the dead client and dials a fresh one on the next query,
|
|
13
|
+
* so a single retry transparently absorbs RDS failover / idle-drop / connect
|
|
14
|
+
* timeout blips instead of surfacing a 500 the caller has to retry by hand.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isTransientConnError(message: string): boolean;
|
|
17
|
+
export declare class SyncPgAdapter implements DbAdapter {
|
|
18
|
+
private readonly worker;
|
|
19
|
+
private readonly port;
|
|
20
|
+
private counter;
|
|
21
|
+
private readonly sleeper;
|
|
22
|
+
constructor(dsn: string);
|
|
23
|
+
/**
|
|
24
|
+
* Drain the reply matching `expectedId`. The reply is enqueued on the port
|
|
25
|
+
* before the worker notifies, but cross-thread delivery can lag under CPU
|
|
26
|
+
* pressure — so poll on a wall-clock deadline (yielding via a 1ms Atomics.wait
|
|
27
|
+
* between empty reads) rather than a fixed iteration count, which could give
|
|
28
|
+
* up prematurely on a busy box and throw a spurious 500. Replies whose id does
|
|
29
|
+
* not match are stale results of a previously abandoned (timed-out) query;
|
|
30
|
+
* discard them so the port never cross-talks between requests.
|
|
31
|
+
*/
|
|
32
|
+
private drainReply;
|
|
33
|
+
private queryOnce;
|
|
34
|
+
private query;
|
|
35
|
+
run(sql: string, ...params: unknown[]): RunResult;
|
|
36
|
+
get(sql: string, ...params: unknown[]): unknown;
|
|
37
|
+
all(sql: string, ...params: unknown[]): unknown[];
|
|
38
|
+
exec(sql: string): void;
|
|
39
|
+
prepare(sql: string): PreparedStatement;
|
|
40
|
+
transaction<T>(fn: () => T): T;
|
|
41
|
+
close(): void;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=sync-pg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-pg.d.ts","sourceRoot":"","sources":["../../src/db/sync-pg.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAIlF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiCxD;AAaD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAY7D;AAED,qBAAa,aAAc,YAAW,SAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,OAAO,CAAI;IAInB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2C;gBAEvD,GAAG,EAAE,MAAM;IAYvB;;;;;;;;OAQG;IACH,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,SAAS;IAcjB,OAAO,CAAC,KAAK;IAcb,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS;IAIjD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO;IAG/C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE;IAGj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