@hasna/cloud 0.1.23 → 0.1.24

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.
Files changed (2) hide show
  1. package/dist/cli/index.js +34 -2
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -12798,6 +12798,17 @@ import { existsSync as existsSync9, statSync as statSync6 } from "fs";
12798
12798
  import { join as join9 } from "path";
12799
12799
  import { homedir as homedir8 } from "os";
12800
12800
  var program2 = new Command;
12801
+ function logSync(direction, service, rows, errors2) {
12802
+ try {
12803
+ const logDir = join9(homedir8(), ".hasna", "cloud");
12804
+ const logPath = join9(logDir, "sync.log");
12805
+ const { mkdirSync: mkdirSync6, appendFileSync } = __require("fs");
12806
+ mkdirSync6(logDir, { recursive: true });
12807
+ const ts = new Date().toISOString();
12808
+ appendFileSync(logPath, `${ts} ${direction.padEnd(4)} ${service.padEnd(20)} ${rows} rows, ${errors2} errors
12809
+ `);
12810
+ } catch {}
12811
+ }
12801
12812
  program2.name("cloud").description("Shared cloud infrastructure \u2014 database adapter, sync engine, feedback, dotfile migration").version("0.1.8");
12802
12813
  program2.command("setup").description("Configure cloud settings").option("--host <host>", "RDS hostname").option("--port <port>", "RDS port", "5432").option("--username <user>", "RDS username").option("--password-env <env>", "Env var for RDS password", "HASNA_RDS_PASSWORD").option("--ssl", "Enable SSL", true).option("--no-ssl", "Disable SSL").option("--mode <mode>", "Mode: local, cloud, or hybrid", "local").option("--sync-interval <minutes>", "Auto-sync interval in minutes", "0").action((opts) => {
12803
12814
  const config = getCloudConfig();
@@ -12843,7 +12854,7 @@ Checking PostgreSQL connection...`);
12843
12854
  }
12844
12855
  });
12845
12856
  var syncCmd = program2.command("sync").description("Sync data between local and cloud");
12846
- syncCmd.command("push").description("Push local data to cloud").option("--service <name>", "Service name").option("--all", "Push all discovered services").option("--tables <tables>", "Comma-separated table names (default: all)").action(async (opts) => {
12857
+ syncCmd.command("push").description("Push local data to cloud").option("--service <name>", "Service name").option("--all", "Push all discovered services").option("--tables <tables>", "Comma-separated table names (default: all)").option("--dry-run", "Preview what would be synced without executing").action(async (opts) => {
12847
12858
  const config = getCloudConfig();
12848
12859
  if (config.mode === "local") {
12849
12860
  console.error("Error: mode is 'local'. Run `cloud setup --mode hybrid` or `--mode cloud` first.");
@@ -12878,6 +12889,19 @@ syncCmd.command("push").description("Push local data to cloud").option("--servic
12878
12889
  local.close();
12879
12890
  continue;
12880
12891
  }
12892
+ if (opts.dryRun) {
12893
+ const rowCounts = tables.map((t) => {
12894
+ try {
12895
+ const r = local.get(`SELECT COUNT(*) as cnt FROM "${t}"`);
12896
+ return `${t}: ${r?.cnt ?? 0} rows`;
12897
+ } catch {
12898
+ return `${t}: ?`;
12899
+ }
12900
+ });
12901
+ console.log(`[${service}] Would push ${tables.length} table(s): ${rowCounts.join(", ")}`);
12902
+ local.close();
12903
+ continue;
12904
+ }
12881
12905
  console.log(`[${service}] Pushing ${tables.length} table(s) to cloud...`);
12882
12906
  let connStr;
12883
12907
  try {
@@ -12903,6 +12927,7 @@ syncCmd.command("push").description("Push local data to cloud").option("--servic
12903
12927
  const totalErrors = results.reduce((s, r) => s + r.errors.length, 0);
12904
12928
  grandTotalWritten += totalWritten;
12905
12929
  grandTotalErrors += totalErrors;
12930
+ logSync("push", service, totalWritten, totalErrors);
12906
12931
  if (opts.all) {
12907
12932
  console.log(` ${service}: ${totalWritten} rows pushed${totalErrors > 0 ? `, ${totalErrors} errors` : ""}`);
12908
12933
  } else {
@@ -12922,7 +12947,7 @@ Done. ${totalWritten} rows pushed, ${totalErrors} errors.`);
12922
12947
  Done. ${services.length} services, ${grandTotalWritten} rows pushed, ${grandTotalErrors} errors.`);
12923
12948
  }
12924
12949
  });
12925
- syncCmd.command("pull").description("Pull cloud data to local").option("--service <name>", "Service name").option("--all", "Pull all discovered services").option("--tables <tables>", "Comma-separated table names (default: all)").action(async (opts) => {
12950
+ syncCmd.command("pull").description("Pull cloud data to local").option("--service <name>", "Service name").option("--all", "Pull all discovered services").option("--tables <tables>", "Comma-separated table names (default: all)").option("--dry-run", "Preview what would be synced without executing").action(async (opts) => {
12926
12951
  const config = getCloudConfig();
12927
12952
  if (config.mode === "local") {
12928
12953
  console.error("Error: mode is 'local'. Run `cloud setup --mode hybrid` or `--mode cloud` first.");
@@ -12981,6 +13006,12 @@ syncCmd.command("pull").description("Pull cloud data to local").option("--servic
12981
13006
  await cloud.close();
12982
13007
  continue;
12983
13008
  }
13009
+ if (opts.dryRun) {
13010
+ console.log(`[${service}] Would pull ${tables.length} table(s): ${tables.join(", ")}`);
13011
+ local.close();
13012
+ await cloud.close();
13013
+ continue;
13014
+ }
12984
13015
  if (!opts.all)
12985
13016
  console.log(`Pulling ${tables.length} table(s) from cloud...`);
12986
13017
  const results = await syncPull(cloud, local, {
@@ -12997,6 +13028,7 @@ syncCmd.command("pull").description("Pull cloud data to local").option("--servic
12997
13028
  const totalErrors = results.reduce((s, r) => s + r.errors.length, 0);
12998
13029
  grandTotalWritten += totalWritten;
12999
13030
  grandTotalErrors += totalErrors;
13031
+ logSync("pull", service, totalWritten, totalErrors);
13000
13032
  if (opts.all) {
13001
13033
  if (totalWritten > 0 || totalErrors > 0) {
13002
13034
  console.log(` ${service}: ${totalWritten} rows pulled${totalErrors > 0 ? `, ${totalErrors} errors` : ""}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/cloud",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "Shared cloud infrastructure — database adapter (SQLite + PostgreSQL), sync engine, feedback system, unified dotfile config",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",