@hasna/cloud 0.1.0
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/LICENSE +190 -0
- package/dist/adapter.d.ts +63 -0
- package/dist/adapter.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 +11881 -0
- package/dist/cli-helpers.d.ts +17 -0
- package/dist/cli-helpers.d.ts.map +1 -0
- package/dist/config.d.ts +73 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/dialect.d.ts +17 -0
- package/dist/dialect.d.ts.map +1 -0
- package/dist/dotfile.d.ts +27 -0
- package/dist/dotfile.d.ts.map +1 -0
- package/dist/feedback.d.ts +32 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9716 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +25245 -0
- package/dist/mcp-helpers.d.ts +16 -0
- package/dist/mcp-helpers.d.ts.map +1 -0
- package/dist/sync.d.ts +48 -0
- package/dist/sync.d.ts.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* Register cloud-related subcommands onto an existing Commander program.
|
|
4
|
+
* Services call this to embed cloud sync/feedback commands into their own CLI.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { Command } from "commander";
|
|
9
|
+
* import { registerCloudCommands } from "@hasna/cloud";
|
|
10
|
+
*
|
|
11
|
+
* const program = new Command();
|
|
12
|
+
* registerCloudCommands(program, "my-service");
|
|
13
|
+
* program.parse();
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function registerCloudCommands(program: Command, serviceName: string): void;
|
|
17
|
+
//# sourceMappingURL=cli-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-helpers.d.ts","sourceRoot":"","sources":["../src/cli-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWzC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,MAAM,GAClB,IAAI,CAwHN"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CloudConfigSchema: z.ZodObject<{
|
|
3
|
+
rds: z.ZodDefault<z.ZodObject<{
|
|
4
|
+
host: z.ZodDefault<z.ZodString>;
|
|
5
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
6
|
+
username: z.ZodDefault<z.ZodString>;
|
|
7
|
+
password_env: z.ZodDefault<z.ZodString>;
|
|
8
|
+
ssl: z.ZodDefault<z.ZodBoolean>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
host: string;
|
|
11
|
+
port: number;
|
|
12
|
+
username: string;
|
|
13
|
+
password_env: string;
|
|
14
|
+
ssl: boolean;
|
|
15
|
+
}, {
|
|
16
|
+
host?: string | undefined;
|
|
17
|
+
port?: number | undefined;
|
|
18
|
+
username?: string | undefined;
|
|
19
|
+
password_env?: string | undefined;
|
|
20
|
+
ssl?: boolean | undefined;
|
|
21
|
+
}>>;
|
|
22
|
+
mode: z.ZodDefault<z.ZodEnum<["local", "cloud", "hybrid"]>>;
|
|
23
|
+
auto_sync_interval_minutes: z.ZodDefault<z.ZodNumber>;
|
|
24
|
+
feedback_endpoint: z.ZodDefault<z.ZodString>;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
rds: {
|
|
27
|
+
host: string;
|
|
28
|
+
port: number;
|
|
29
|
+
username: string;
|
|
30
|
+
password_env: string;
|
|
31
|
+
ssl: boolean;
|
|
32
|
+
};
|
|
33
|
+
mode: "local" | "cloud" | "hybrid";
|
|
34
|
+
auto_sync_interval_minutes: number;
|
|
35
|
+
feedback_endpoint: string;
|
|
36
|
+
}, {
|
|
37
|
+
rds?: {
|
|
38
|
+
host?: string | undefined;
|
|
39
|
+
port?: number | undefined;
|
|
40
|
+
username?: string | undefined;
|
|
41
|
+
password_env?: string | undefined;
|
|
42
|
+
ssl?: boolean | undefined;
|
|
43
|
+
} | undefined;
|
|
44
|
+
mode?: "local" | "cloud" | "hybrid" | undefined;
|
|
45
|
+
auto_sync_interval_minutes?: number | undefined;
|
|
46
|
+
feedback_endpoint?: string | undefined;
|
|
47
|
+
}>;
|
|
48
|
+
export type CloudConfig = z.infer<typeof CloudConfigSchema>;
|
|
49
|
+
export declare function getConfigDir(): string;
|
|
50
|
+
export declare function getConfigPath(): string;
|
|
51
|
+
export declare function getCloudConfig(): CloudConfig;
|
|
52
|
+
export declare function saveCloudConfig(config: CloudConfig): void;
|
|
53
|
+
export declare function getConnectionString(dbName: string): string;
|
|
54
|
+
import { type DbAdapter } from "./adapter.js";
|
|
55
|
+
export interface CreateDatabaseOptions {
|
|
56
|
+
/** Service name — used to locate the SQLite file and PG database. */
|
|
57
|
+
service: string;
|
|
58
|
+
/** Override mode from config. */
|
|
59
|
+
mode?: "local" | "cloud" | "hybrid";
|
|
60
|
+
/** Override the SQLite file path. */
|
|
61
|
+
sqlitePath?: string;
|
|
62
|
+
/** Override the PG connection string. */
|
|
63
|
+
pgConnectionString?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a database adapter based on the current configuration.
|
|
67
|
+
*
|
|
68
|
+
* - `local` mode → SqliteAdapter
|
|
69
|
+
* - `cloud` mode → PgAdapter
|
|
70
|
+
* - `hybrid` mode → SqliteAdapter (PG is used only for sync)
|
|
71
|
+
*/
|
|
72
|
+
export declare function createDatabase(options: CreateDatabaseOptions): DbAdapter;
|
|
73
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAe5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAS5D,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAMD,wBAAgB,cAAc,IAAI,WAAW,CAU5C;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAGzD;AAMD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAa1D;AAMD,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAGxE,MAAM,WAAW,qBAAqB;IACpC,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpC,qCAAqC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,SAAS,CAaxE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 variadic params or a single
|
|
9
|
+
* array; pg always wants a flat array. Also handles undefined → null.
|
|
10
|
+
*/
|
|
11
|
+
export declare function translateParams(params: any[]): any[];
|
|
12
|
+
/**
|
|
13
|
+
* Translate a CREATE TABLE statement from SQLite DDL to PostgreSQL DDL.
|
|
14
|
+
* More aggressive transformations than query-level translation.
|
|
15
|
+
*/
|
|
16
|
+
export declare function translateDdl(ddl: string, dialect: Dialect): string;
|
|
17
|
+
//# sourceMappingURL=dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC;AAEtC;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAGlE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,CAKpD;AAyFD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CA6BlE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns `~/.hasna/<serviceName>/`, creating it if needed.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getDataDir(serviceName: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the path for the service's SQLite database:
|
|
7
|
+
* `~/.hasna/<serviceName>/<serviceName>.db`
|
|
8
|
+
*/
|
|
9
|
+
export declare function getDbPath(serviceName: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Migrate from legacy `~/.<serviceName>/` to `~/.hasna/<serviceName>/`.
|
|
12
|
+
*
|
|
13
|
+
* - If `~/.<serviceName>/` exists and `~/.hasna/<serviceName>/` does NOT,
|
|
14
|
+
* copies all contents over.
|
|
15
|
+
* - Returns a list of migrated file paths (relative to the source dir),
|
|
16
|
+
* or an empty array if no migration was needed.
|
|
17
|
+
*/
|
|
18
|
+
export declare function migrateDotfile(serviceName: string): string[];
|
|
19
|
+
/**
|
|
20
|
+
* Check if a legacy dotfile directory exists for the given service.
|
|
21
|
+
*/
|
|
22
|
+
export declare function hasLegacyDotfile(serviceName: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Get the `.hasna` base directory.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getHasnaDir(): string;
|
|
27
|
+
//# sourceMappingURL=dotfile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dotfile.d.ts","sourceRoot":"","sources":["../src/dotfile.ts"],"names":[],"mappings":"AAoBA;;GAEG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAItD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAGrD;AAMD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAe5D;AAsBD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAGpC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DbAdapter } from "./adapter.js";
|
|
2
|
+
export interface Feedback {
|
|
3
|
+
id?: string;
|
|
4
|
+
service: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
message: string;
|
|
7
|
+
email?: string;
|
|
8
|
+
machine_id?: string;
|
|
9
|
+
created_at?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ensure the feedback table exists in the given database.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ensureFeedbackTable(db: DbAdapter): void;
|
|
15
|
+
/**
|
|
16
|
+
* Save feedback to the local database.
|
|
17
|
+
*/
|
|
18
|
+
export declare function saveFeedback(db: DbAdapter, feedback: Feedback): string;
|
|
19
|
+
/**
|
|
20
|
+
* Send feedback to the remote endpoint.
|
|
21
|
+
* If the POST fails, saves locally and does NOT throw.
|
|
22
|
+
*/
|
|
23
|
+
export declare function sendFeedback(feedback: Feedback, db?: DbAdapter): Promise<{
|
|
24
|
+
sent: boolean;
|
|
25
|
+
id: string;
|
|
26
|
+
error?: string;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Get all feedback entries from the local database.
|
|
30
|
+
*/
|
|
31
|
+
export declare function listFeedback(db: DbAdapter): Feedback[];
|
|
32
|
+
//# sourceMappingURL=feedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAO9C,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAiBD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI,CAEvD;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAsBtE;AAMD;;;GAGG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,EAAE,CAAC,EAAE,SAAS,GACb,OAAO,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAsDxD;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,SAAS,GAAG,QAAQ,EAAE,CAKtD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { SqliteAdapter, PgAdapter, PgAdapterAsync, type DbAdapter, type PreparedStatement, type RunResult, } from "./adapter.js";
|
|
2
|
+
export { translateSql, translateDdl, translateParams, type Dialect, } from "./dialect.js";
|
|
3
|
+
export { getCloudConfig, saveCloudConfig, getConnectionString, createDatabase, getConfigDir, getConfigPath, CloudConfigSchema, type CloudConfig, type CreateDatabaseOptions, } from "./config.js";
|
|
4
|
+
export { syncPush, syncPull, listSqliteTables, listPgTables, type SyncOptions, type SyncResult, type SyncProgress, type SyncProgressCallback, } from "./sync.js";
|
|
5
|
+
export { saveFeedback, sendFeedback, listFeedback, ensureFeedbackTable, type Feedback, } from "./feedback.js";
|
|
6
|
+
export { migrateDotfile, getDataDir, getDbPath, hasLegacyDotfile, getHasnaDir, } from "./dotfile.js";
|
|
7
|
+
export { registerCloudTools } from "./mcp-helpers.js";
|
|
8
|
+
export { registerCloudCommands } from "./cli-helpers.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,aAAa,EACb,SAAS,EACT,cAAc,EACd,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,SAAS,GACf,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,KAAK,OAAO,GACb,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,qBAAqB,GAC3B,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,oBAAoB,GAC1B,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,KAAK,QAAQ,GACd,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,WAAW,GACZ,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
|