ardent-cli 0.0.39 → 0.0.40

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 +137 -45
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -804,6 +804,126 @@ function printDegradedWarnings(warnings) {
804
804
  console.log(" Review this connector with: ardent connector list");
805
805
  }
806
806
 
807
+ // src/lib/operation_stage_display.ts
808
+ var STAGE_DISPLAY = {
809
+ // engine_setup_worker / postgres_engine_setup
810
+ "dispatched": "Starting",
811
+ "preparing": "Preparing",
812
+ "creating-neon-project": "Provisioning the branch target",
813
+ "preparing-target-databases": "Preparing target databases",
814
+ "deploying-pgstream": "Starting replication",
815
+ "applying-rls": "Applying RLS policies",
816
+ "storing-credentials": "Storing connection credentials",
817
+ "validating": "Validating the branch target",
818
+ // reset_worker / reset_connector
819
+ "resetting": "Resetting",
820
+ "deleting-pgstream": "Stopping replication",
821
+ "rediscovering-source": "Re-checking the source database",
822
+ "resetting-neon-main": "Resetting the branch target",
823
+ "creating-target-schemas": "Recreating target schemas",
824
+ "redeploying-pgstream": "Restarting replication",
825
+ // environment deploy_worker
826
+ "loading_config": "Loading environment configuration",
827
+ "deploying_infrastructure": "Provisioning environment infrastructure",
828
+ "recording_success": "Finalizing environment",
829
+ "cleaning_failed_deploy": "Cleaning up failed environment provisioning",
830
+ // environment destroy_worker
831
+ "deleting_private_links": "Removing private network links",
832
+ "destroying_infrastructure": "Tearing down environment infrastructure",
833
+ "recording_destroy_success": "Finalizing environment teardown",
834
+ // discovery_worker / run_discovery_crawl (ARD-1098)
835
+ "connecting": "Connecting to source",
836
+ "enumerating_databases": "Listing databases",
837
+ "scanning_database": "Scanning schema",
838
+ "writing_schema": "Saving discovered schema",
839
+ "merging_results": "Combining results"
840
+ };
841
+ function humanizeRawStage(_raw) {
842
+ return "Working";
843
+ }
844
+ function operationStageDisplay(stage) {
845
+ if (!stage) return "Working";
846
+ const colonIndex = stage.indexOf(":");
847
+ const base = colonIndex === -1 ? stage : stage.slice(0, colonIndex);
848
+ const suffix = colonIndex === -1 ? "" : stage.slice(colonIndex + 1);
849
+ const label = STAGE_DISPLAY[base] ?? humanizeRawStage(base);
850
+ return suffix ? `${label} (for ${suffix})` : label;
851
+ }
852
+
853
+ // src/lib/discover.ts
854
+ var DiscoveryTimeoutError = class extends Error {
855
+ constructor(message) {
856
+ super(message);
857
+ this.name = "DiscoveryTimeoutError";
858
+ }
859
+ };
860
+ var DiscoveryOperationFailedError = class extends Error {
861
+ operationError;
862
+ constructor(operationError) {
863
+ super(
864
+ `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\`.`
865
+ );
866
+ this.name = "DiscoveryOperationFailedError";
867
+ this.operationError = operationError;
868
+ }
869
+ };
870
+ async function runDiscoveryWithPolling(connectorId, options) {
871
+ const maxWaitMs = options?.maxWaitMs ?? 10 * 60 * 1e3;
872
+ const pollIntervalMs = options?.pollIntervalMs ?? 3 * 1e3;
873
+ let dispatch;
874
+ try {
875
+ dispatch = await api.post(
876
+ `/v1/connectors/${connectorId}/discover`,
877
+ {}
878
+ );
879
+ } catch (err) {
880
+ if (isGatewayTimeoutError(err)) {
881
+ throw new Error(
882
+ "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."
883
+ );
884
+ }
885
+ throw err;
886
+ }
887
+ if (options?.onPrerequisites) {
888
+ options.onPrerequisites(dispatch.prerequisites, dispatch.source_metadata);
889
+ }
890
+ const operationId = dispatch.operation_id;
891
+ const startedAt = Date.now();
892
+ let lastStage = null;
893
+ while (Date.now() - startedAt < maxWaitMs) {
894
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
895
+ let op;
896
+ try {
897
+ op = await api.get(`/v1/operations/${operationId}`);
898
+ } catch (pollErr) {
899
+ if (isGatewayTimeoutError(pollErr)) continue;
900
+ throw pollErr;
901
+ }
902
+ if (op.stage && op.stage !== lastStage) {
903
+ const progressLabel = op.progress != null ? ` (${op.progress}%)` : "";
904
+ console.log(` ${operationStageDisplay(op.stage)}${progressLabel}`);
905
+ lastStage = op.stage;
906
+ }
907
+ if (op.status === "completed") {
908
+ const result = op.result ?? {};
909
+ const schemaVersion = typeof result.schema_version === "number" ? result.schema_version : 0;
910
+ const databasesCount = typeof result.databases_count === "number" ? result.databases_count : 0;
911
+ return {
912
+ prerequisites: dispatch.prerequisites,
913
+ source_metadata: dispatch.source_metadata,
914
+ schema_version: schemaVersion,
915
+ databases_count: databasesCount
916
+ };
917
+ }
918
+ if (op.status === "failed") {
919
+ throw new DiscoveryOperationFailedError(op.error);
920
+ }
921
+ }
922
+ throw new DiscoveryTimeoutError(
923
+ `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}.`
924
+ );
925
+ }
926
+
807
927
  // src/lib/connector_status_display.ts
808
928
  var ENGINE_STATUS_DISPLAY = {
809
929
  healthy: "ready",
@@ -890,46 +1010,6 @@ function assertEngineSetupCompleted(operation, connectorName) {
890
1010
  );
891
1011
  }
892
1012
 
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
1013
  // src/lib/engine_setup.ts
934
1014
  var EngineSetupTimeoutError = class extends Error {
935
1015
  constructor(message) {
@@ -1705,11 +1785,23 @@ async function createAction2(type, url, options) {
1705
1785
  }
1706
1786
  } else {
1707
1787
  console.log("Discovering schema...");
1708
- const discoverResult = await api.post(
1709
- `/v1/connectors/${connectorId}/discover`,
1710
- {}
1711
- );
1712
- const discoveryWarnings = discoverResult?.source_metadata?.warnings ?? [];
1788
+ let discoverPollResult;
1789
+ try {
1790
+ discoverPollResult = await runDiscoveryWithPolling(connectorId, {
1791
+ onPrerequisites: (prereqs) => {
1792
+ if (prereqs.pass) {
1793
+ console.log("Connected \u2713 \u2014 scanning your schema\u2026");
1794
+ }
1795
+ }
1796
+ });
1797
+ } catch (discoverErr) {
1798
+ if (discoverErr instanceof DiscoveryTimeoutError || discoverErr instanceof DiscoveryOperationFailedError) {
1799
+ console.error(`\u2717 ${discoverErr.message}`);
1800
+ process.exit(1);
1801
+ }
1802
+ throw discoverErr;
1803
+ }
1804
+ const discoveryWarnings = discoverPollResult.source_metadata?.warnings ?? [];
1713
1805
  if (discoveryWarnings.length > 0) {
1714
1806
  const yellow = "\x1B[33m";
1715
1807
  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.40",
4
4
  "description": "Git for Data infrastructure",
5
5
  "type": "module",
6
6
  "bin": {