@go-to-k/cdkd 0.50.13 → 0.51.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.
Binary file
package/dist/index.js CHANGED
@@ -8807,6 +8807,65 @@ var DeployEngine = class {
8807
8807
  }
8808
8808
  }
8809
8809
  }
8810
+ /**
8811
+ * Kick off `provider.readCurrentState` for every resource in the
8812
+ * loaded state that lacks `observedProperties` (e.g. state written
8813
+ * by a pre-v3 binary, or a v3 record where a NO_CHANGE-skipped
8814
+ * resource's baseline never landed). Calls go through
8815
+ * `kickOffObservedCapture`, so they share the same fire-and-forget
8816
+ * pipeline, error swallowing, and final-drain wiring that the
8817
+ * post-CREATE / post-UPDATE captures use.
8818
+ *
8819
+ * The deploy critical path does NOT wait on these; the cost is
8820
+ * bounded by `max(per-resource readCurrentState latency)` (typically
8821
+ * ~200-300ms in practice) once at the end-of-deploy drain. Any
8822
+ * resource that subsequently goes through CREATE / UPDATE in the
8823
+ * same deploy will overwrite this entry via the `Map.set` keyed by
8824
+ * `logicalId` (latest-wins) — so there's no double-write to state,
8825
+ * just a wasted SDK call for the (rare) UPDATE / DELETE intersection.
8826
+ *
8827
+ * Resources whose provider lookup throws (e.g. unsupported type) or
8828
+ * lacks `readCurrentState` are silently skipped — same policy as the
8829
+ * manual `cdkd state refresh-observed` command.
8830
+ */
8831
+ kickOffAutoRefreshObservedProperties(stateResources) {
8832
+ if (this.options.captureObservedState !== true)
8833
+ return;
8834
+ if (this.options.dryRun === true)
8835
+ return;
8836
+ let toRefresh = 0;
8837
+ const candidates = [];
8838
+ for (const [logicalId, resource] of Object.entries(stateResources)) {
8839
+ if (resource.observedProperties !== void 0)
8840
+ continue;
8841
+ candidates.push({ logicalId, resource });
8842
+ }
8843
+ if (candidates.length === 0)
8844
+ return;
8845
+ for (const { logicalId, resource } of candidates) {
8846
+ let provider;
8847
+ try {
8848
+ provider = this.providerRegistry.getProvider(resource.resourceType);
8849
+ } catch {
8850
+ continue;
8851
+ }
8852
+ if (!provider.readCurrentState)
8853
+ continue;
8854
+ this.kickOffObservedCapture(
8855
+ provider,
8856
+ logicalId,
8857
+ resource.physicalId,
8858
+ resource.resourceType,
8859
+ resource.properties ?? {}
8860
+ );
8861
+ toRefresh++;
8862
+ }
8863
+ if (toRefresh > 0) {
8864
+ this.logger.warn(
8865
+ `cdkd state schema upgrade detected \u2014 refreshing observed-properties baseline for ${toRefresh} resource(s) (one-time, runs in parallel with deploy)`
8866
+ );
8867
+ }
8868
+ }
8810
8869
  async doDeploy(stackName, template) {
8811
8870
  const startTime = Date.now();
8812
8871
  this.logger.debug(`Starting deployment for stack: ${stackName}`);
@@ -8838,6 +8897,7 @@ var DeployEngine = class {
8838
8897
  this.logger.debug(
8839
8898
  `Loaded current state: ${Object.keys(currentState.resources).length} resources`
8840
8899
  );
8900
+ this.kickOffAutoRefreshObservedProperties(currentState.resources);
8841
8901
  this.logger.debug(`Template has ${Object.keys(template.Resources || {}).length} resources`);
8842
8902
  const parameterValues = await this.resolver.resolveParameters(
8843
8903
  template,
@@ -8882,6 +8942,35 @@ var DeployEngine = class {
8882
8942
  const hasChanges = this.diffCalculator.hasChanges(changes);
8883
8943
  if (!hasChanges) {
8884
8944
  this.logger.info("No changes detected. Stack is up to date.");
8945
+ if (!this.options.dryRun && this.observedCaptureTasks.size > 0) {
8946
+ await this.drainObservedCaptures(currentState.resources);
8947
+ try {
8948
+ const refreshedState = {
8949
+ version: STATE_SCHEMA_VERSION_CURRENT,
8950
+ region: this.stackRegion,
8951
+ stackName: currentState.stackName,
8952
+ resources: currentState.resources,
8953
+ outputs: currentState.outputs,
8954
+ lastModified: Date.now()
8955
+ };
8956
+ const saveOptions = {};
8957
+ if (currentEtag !== void 0)
8958
+ saveOptions.expectedEtag = currentEtag;
8959
+ if (migrationPending)
8960
+ saveOptions.migrateLegacy = true;
8961
+ await this.stateBackend.saveState(
8962
+ stackName,
8963
+ this.stackRegion,
8964
+ refreshedState,
8965
+ saveOptions
8966
+ );
8967
+ this.logger.debug("Persisted refreshed observedProperties (no-change path)");
8968
+ } catch (saveError) {
8969
+ this.logger.warn(
8970
+ `Failed to persist refreshed observedProperties: ${saveError instanceof Error ? saveError.message : String(saveError)} \u2014 drift baseline will be re-fetched on next deploy.`
8971
+ );
8972
+ }
8973
+ }
8885
8974
  return {
8886
8975
  stackName,
8887
8976
  created: 0,