ardent-cli 0.0.39 → 0.0.41

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/index.js +155 -51
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -510,11 +510,15 @@ async function createAction(name, options) {
510
510
  try {
511
511
  const startTime = performance.now();
512
512
  const connectorId = await requireCurrentConnectorId();
513
- await api.post("/v1/branch/create", {
514
- connector_id: connectorId,
515
- service_type: options.service,
516
- name
517
- });
513
+ const createResponse = await api.post(
514
+ "/v1/branch/create",
515
+ {
516
+ connector_id: connectorId,
517
+ service_type: options.service,
518
+ name
519
+ }
520
+ );
521
+ const warning = createResponse?.warning;
518
522
  const response = await api.get(`/v1/cli/branches?connector_id=${connectorId}`);
519
523
  const apiBranches = response.branches || [];
520
524
  let apiBranch;
@@ -544,12 +548,20 @@ async function createAction(name, options) {
544
548
  setCacheEntry("branches", cachedBranches);
545
549
  setCurrentBranch(name);
546
550
  const elapsed = ((performance.now() - startTime) / 1e3).toFixed(1);
547
- trackEvent("CLI: branch create succeeded", { service_type: options.service, duration_seconds: parseFloat(elapsed) });
551
+ trackEvent("CLI: branch create succeeded", {
552
+ service_type: options.service,
553
+ duration_seconds: parseFloat(elapsed),
554
+ warning_type: warning?.type
555
+ });
548
556
  console.log(`\u2713 Branch '${name}' created and checked out in ${elapsed}s`);
549
557
  if (branch.branch_url) {
550
558
  console.log(`
551
559
  ${branch.branch_url}`);
552
560
  }
561
+ if (warning) {
562
+ console.log(`
563
+ ! ${warning.message}`);
564
+ }
553
565
  } catch (err) {
554
566
  if (isNetworkError(err)) {
555
567
  trackEvent("CLI: branch create failed", { reason: "offline" });
@@ -804,6 +816,126 @@ function printDegradedWarnings(warnings) {
804
816
  console.log(" Review this connector with: ardent connector list");
805
817
  }
806
818
 
819
+ // src/lib/operation_stage_display.ts
820
+ var STAGE_DISPLAY = {
821
+ // engine_setup_worker / postgres_engine_setup
822
+ "dispatched": "Starting",
823
+ "preparing": "Preparing",
824
+ "creating-neon-project": "Provisioning the branch target",
825
+ "preparing-target-databases": "Preparing target databases",
826
+ "deploying-pgstream": "Starting replication",
827
+ "applying-rls": "Applying RLS policies",
828
+ "storing-credentials": "Storing connection credentials",
829
+ "validating": "Validating the branch target",
830
+ // reset_worker / reset_connector
831
+ "resetting": "Resetting",
832
+ "deleting-pgstream": "Stopping replication",
833
+ "rediscovering-source": "Re-checking the source database",
834
+ "resetting-neon-main": "Resetting the branch target",
835
+ "creating-target-schemas": "Recreating target schemas",
836
+ "redeploying-pgstream": "Restarting replication",
837
+ // environment deploy_worker
838
+ "loading_config": "Loading environment configuration",
839
+ "deploying_infrastructure": "Provisioning environment infrastructure",
840
+ "recording_success": "Finalizing environment",
841
+ "cleaning_failed_deploy": "Cleaning up failed environment provisioning",
842
+ // environment destroy_worker
843
+ "deleting_private_links": "Removing private network links",
844
+ "destroying_infrastructure": "Tearing down environment infrastructure",
845
+ "recording_destroy_success": "Finalizing environment teardown",
846
+ // discovery_worker / run_discovery_crawl (ARD-1098)
847
+ "connecting": "Connecting to source",
848
+ "enumerating_databases": "Listing databases",
849
+ "scanning_database": "Scanning schema",
850
+ "writing_schema": "Saving discovered schema",
851
+ "merging_results": "Combining results"
852
+ };
853
+ function humanizeRawStage(_raw) {
854
+ return "Working";
855
+ }
856
+ function operationStageDisplay(stage) {
857
+ if (!stage) return "Working";
858
+ const colonIndex = stage.indexOf(":");
859
+ const base = colonIndex === -1 ? stage : stage.slice(0, colonIndex);
860
+ const suffix = colonIndex === -1 ? "" : stage.slice(colonIndex + 1);
861
+ const label = STAGE_DISPLAY[base] ?? humanizeRawStage(base);
862
+ return suffix ? `${label} (for ${suffix})` : label;
863
+ }
864
+
865
+ // src/lib/discover.ts
866
+ var DiscoveryTimeoutError = class extends Error {
867
+ constructor(message) {
868
+ super(message);
869
+ this.name = "DiscoveryTimeoutError";
870
+ }
871
+ };
872
+ var DiscoveryOperationFailedError = class extends Error {
873
+ operationError;
874
+ constructor(operationError) {
875
+ super(
876
+ `Discovery failed: ${operationError ?? "unknown error"}. Inspect the connector with \`ardent connector list\`, fix the underlying issue, then re-run \`ardent connector create\` or \`ardent connector rediscover\`.`
877
+ );
878
+ this.name = "DiscoveryOperationFailedError";
879
+ this.operationError = operationError;
880
+ }
881
+ };
882
+ async function runDiscoveryWithPolling(connectorId, options) {
883
+ const maxWaitMs = options?.maxWaitMs ?? 10 * 60 * 1e3;
884
+ const pollIntervalMs = options?.pollIntervalMs ?? 3 * 1e3;
885
+ let dispatch;
886
+ try {
887
+ dispatch = await api.post(
888
+ `/v1/connectors/${connectorId}/discover`,
889
+ {}
890
+ );
891
+ } catch (err) {
892
+ if (isGatewayTimeoutError(err)) {
893
+ throw new Error(
894
+ "Backend dispatch timed out. The /discover endpoint is now async and should respond in under a few seconds; this may indicate a backend incident. Try again, or check `ardent connector list` to see if a discovery operation was created anyway."
895
+ );
896
+ }
897
+ throw err;
898
+ }
899
+ if (options?.onPrerequisites) {
900
+ options.onPrerequisites(dispatch.prerequisites, dispatch.source_metadata);
901
+ }
902
+ const operationId = dispatch.operation_id;
903
+ const startedAt = Date.now();
904
+ let lastStage = null;
905
+ while (Date.now() - startedAt < maxWaitMs) {
906
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
907
+ let op;
908
+ try {
909
+ op = await api.get(`/v1/operations/${operationId}`);
910
+ } catch (pollErr) {
911
+ if (isGatewayTimeoutError(pollErr)) continue;
912
+ throw pollErr;
913
+ }
914
+ if (op.stage && op.stage !== lastStage) {
915
+ const progressLabel = op.progress != null ? ` (${op.progress}%)` : "";
916
+ console.log(` ${operationStageDisplay(op.stage)}${progressLabel}`);
917
+ lastStage = op.stage;
918
+ }
919
+ if (op.status === "completed") {
920
+ const result = op.result ?? {};
921
+ const schemaVersion = typeof result.schema_version === "number" ? result.schema_version : 0;
922
+ const databasesCount = typeof result.databases_count === "number" ? result.databases_count : 0;
923
+ return {
924
+ prerequisites: dispatch.prerequisites,
925
+ source_metadata: dispatch.source_metadata,
926
+ schema_version: schemaVersion,
927
+ databases_count: databasesCount
928
+ };
929
+ }
930
+ if (op.status === "failed") {
931
+ throw new DiscoveryOperationFailedError(op.error);
932
+ }
933
+ }
934
+ throw new DiscoveryTimeoutError(
935
+ `Discovery did not complete within ${Math.round(maxWaitMs / 6e4)} minutes. The catalog walk may still be running server-side \u2014 do NOT delete the connector. Check status with: ardent connector list. If you contact Ardent support, reference operation id ${operationId}.`
936
+ );
937
+ }
938
+
807
939
  // src/lib/connector_status_display.ts
808
940
  var ENGINE_STATUS_DISPLAY = {
809
941
  healthy: "ready",
@@ -890,46 +1022,6 @@ function assertEngineSetupCompleted(operation, connectorName) {
890
1022
  );
891
1023
  }
892
1024
 
893
- // src/lib/operation_stage_display.ts
894
- var STAGE_DISPLAY = {
895
- // engine_setup_worker / postgres_engine_setup
896
- "dispatched": "Starting",
897
- "preparing": "Preparing",
898
- "creating-neon-project": "Provisioning the branch target",
899
- "preparing-target-databases": "Preparing target databases",
900
- "deploying-pgstream": "Starting replication",
901
- "applying-rls": "Applying RLS policies",
902
- "storing-credentials": "Storing connection credentials",
903
- "validating": "Validating the branch target",
904
- // reset_worker / reset_connector
905
- "resetting": "Resetting",
906
- "deleting-pgstream": "Stopping replication",
907
- "rediscovering-source": "Re-checking the source database",
908
- "resetting-neon-main": "Resetting the branch target",
909
- "creating-target-schemas": "Recreating target schemas",
910
- "redeploying-pgstream": "Restarting replication",
911
- // environment deploy_worker
912
- "loading_config": "Loading environment configuration",
913
- "deploying_infrastructure": "Provisioning environment infrastructure",
914
- "recording_success": "Finalizing environment",
915
- "cleaning_failed_deploy": "Cleaning up failed environment provisioning",
916
- // environment destroy_worker
917
- "deleting_private_links": "Removing private network links",
918
- "destroying_infrastructure": "Tearing down environment infrastructure",
919
- "recording_destroy_success": "Finalizing environment teardown"
920
- };
921
- function humanizeRawStage(_raw) {
922
- return "Working";
923
- }
924
- function operationStageDisplay(stage) {
925
- if (!stage) return "Working";
926
- const colonIndex = stage.indexOf(":");
927
- const base = colonIndex === -1 ? stage : stage.slice(0, colonIndex);
928
- const suffix = colonIndex === -1 ? "" : stage.slice(colonIndex + 1);
929
- const label = STAGE_DISPLAY[base] ?? humanizeRawStage(base);
930
- return suffix ? `${label} (for ${suffix})` : label;
931
- }
932
-
933
1025
  // src/lib/engine_setup.ts
934
1026
  var EngineSetupTimeoutError = class extends Error {
935
1027
  constructor(message) {
@@ -1705,11 +1797,23 @@ async function createAction2(type, url, options) {
1705
1797
  }
1706
1798
  } else {
1707
1799
  console.log("Discovering schema...");
1708
- const discoverResult = await api.post(
1709
- `/v1/connectors/${connectorId}/discover`,
1710
- {}
1711
- );
1712
- const discoveryWarnings = discoverResult?.source_metadata?.warnings ?? [];
1800
+ let discoverPollResult;
1801
+ try {
1802
+ discoverPollResult = await runDiscoveryWithPolling(connectorId, {
1803
+ onPrerequisites: (prereqs) => {
1804
+ if (prereqs.pass) {
1805
+ console.log("Connected \u2713 \u2014 scanning your schema\u2026");
1806
+ }
1807
+ }
1808
+ });
1809
+ } catch (discoverErr) {
1810
+ if (discoverErr instanceof DiscoveryTimeoutError || discoverErr instanceof DiscoveryOperationFailedError) {
1811
+ console.error(`\u2717 ${discoverErr.message}`);
1812
+ process.exit(1);
1813
+ }
1814
+ throw discoverErr;
1815
+ }
1816
+ const discoveryWarnings = discoverPollResult.source_metadata?.warnings ?? [];
1713
1817
  if (discoveryWarnings.length > 0) {
1714
1818
  const yellow = "\x1B[33m";
1715
1819
  const reset2 = "\x1B[0m";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ardent-cli",
3
- "version": "0.0.39",
3
+ "version": "0.0.41",
4
4
  "description": "Git for Data infrastructure",
5
5
  "type": "module",
6
6
  "bin": {