@go-to-k/cdkd 0.99.1 → 0.99.3

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/dist/cli.js CHANGED
@@ -654,6 +654,16 @@ function toYaml(obj, indent = 0) {
654
654
  //#endregion
655
655
  //#region src/cli/commands/synth.ts
656
656
  /**
657
+ * Count deployable resources in a synth template.
658
+ *
659
+ * Excludes `AWS::CDK::Metadata` (CDK-injected construct-tree marker; cdkd deploy
660
+ * also filters this out, so the two commands stay in sync — see
661
+ * deploy-engine.ts `validateResourceTypes` call site).
662
+ */
663
+ function countDeployableResources(template) {
664
+ return Object.values(template.Resources ?? {}).filter((r) => r.Type !== "AWS::CDK::Metadata").length;
665
+ }
666
+ /**
657
667
  * Synth command implementation
658
668
  */
659
669
  async function synthCommand(options) {
@@ -687,7 +697,7 @@ async function synthCommand(options) {
687
697
  }
688
698
  logger.info(`\n✅ Synthesis complete! Found ${stacks.length} stack(s):`);
689
699
  for (const stack of stacks) {
690
- const resourceCount = Object.keys(stack.template.Resources ?? {}).length;
700
+ const resourceCount = countDeployableResources(stack.template);
691
701
  const outputCount = Object.keys(stack.template.Outputs ?? {}).length;
692
702
  logger.info(` • ${stack.stackName}`);
693
703
  logger.info(` - Resources: ${resourceCount}`);
@@ -32122,7 +32132,8 @@ async function importCommand(stackArg, options) {
32122
32132
  stackName: stackInfo.stackName,
32123
32133
  region: targetRegion,
32124
32134
  providerRegistry,
32125
- override: overrides.get(logicalId)
32135
+ override: overrides.get(logicalId),
32136
+ overrides
32126
32137
  });
32127
32138
  rows.push(outcome);
32128
32139
  }
@@ -32176,9 +32187,54 @@ async function importCommand(stackArg, options) {
32176
32187
  awsClients.destroy();
32177
32188
  }
32178
32189
  }
32190
+ /**
32191
+ * Recursively substitute `{Ref: <LogicalId>}` shapes in an arbitrary value
32192
+ * tree with the matching entry from `overrides`. Used to bridge the gap
32193
+ * between CDK synth's template (which carries raw intrinsics) and what a
32194
+ * provider's `import()` needs to see at the time it's called — specifically
32195
+ * for sub-resource providers like `SQSQueuePolicyProvider` whose fallback
32196
+ * path reads `properties.<ParentKey>` as a literal operational identifier
32197
+ * (queue URL / topic ARN / bucket name) rather than the unresolved intrinsic.
32198
+ *
32199
+ * Scope is intentionally narrow:
32200
+ * - Only `{Ref: <X>}` shapes are substituted. `Fn::GetAtt` is NOT handled
32201
+ * here — the overrides map carries physical IDs only, not the
32202
+ * per-resource attributes a GetAtt resolution needs. Full GetAtt /
32203
+ * Fn::Sub / Fn::Join handling happens later in
32204
+ * `resolveImportedProperties` against the populated `stackState.resources`.
32205
+ * - Pseudo-parameter refs (`AWS::Region` / `AWS::AccountId` / etc.) are
32206
+ * left untouched — those are handled by the full resolver post-import.
32207
+ * - When the `Ref` target is NOT in the overrides map, the intrinsic is
32208
+ * left in place (the post-import resolver may resolve it from the
32209
+ * `stackState.resources` built by other imports).
32210
+ *
32211
+ * Closes issue #361 — `AWS::SQS::QueuePolicy` under
32212
+ * `--migrate-from-cloudformation` previously hard-errored because
32213
+ * `properties.Queues[0]` arrived at `provider.import()` as
32214
+ * `{Ref: <Queue>}` and the queue URL needed for the fallback identification
32215
+ * branch was never substituted in.
32216
+ *
32217
+ * Pure-functional — does not mutate `value`.
32218
+ */
32219
+ function substituteOverrideRefs(value, overrides) {
32220
+ if (value === null || value === void 0) return value;
32221
+ if (typeof value !== "object") return value;
32222
+ if (Array.isArray(value)) return value.map((v) => substituteOverrideRefs(v, overrides));
32223
+ const obj = value;
32224
+ const keys = Object.keys(obj);
32225
+ if (keys.length === 1 && keys[0] === "Ref" && typeof obj["Ref"] === "string") {
32226
+ const refTarget = obj["Ref"];
32227
+ const resolved = overrides.get(refTarget);
32228
+ if (resolved !== void 0) return resolved;
32229
+ return value;
32230
+ }
32231
+ const result = {};
32232
+ for (const [k, v] of Object.entries(obj)) result[k] = substituteOverrideRefs(v, overrides);
32233
+ return result;
32234
+ }
32179
32235
  async function importOne(task) {
32180
32236
  const logger = getLogger();
32181
- const { logicalId, resource, stackName, region, providerRegistry, override } = task;
32237
+ const { logicalId, resource, stackName, region, providerRegistry, override, overrides } = task;
32182
32238
  if (!providerRegistry.hasProvider(resource.Type)) return {
32183
32239
  logicalId,
32184
32240
  resourceType: resource.Type,
@@ -32193,13 +32249,14 @@ async function importOne(task) {
32193
32249
  reason: `provider does not implement import (yet)`
32194
32250
  };
32195
32251
  const cdkPath = readCdkPath(resource);
32252
+ const properties = substituteOverrideRefs(resource.Properties ?? {}, overrides);
32196
32253
  const input = {
32197
32254
  logicalId,
32198
32255
  resourceType: resource.Type,
32199
32256
  cdkPath,
32200
32257
  stackName,
32201
32258
  region,
32202
- properties: resource.Properties ?? {},
32259
+ properties,
32203
32260
  ...override !== void 0 && { knownPhysicalId: override }
32204
32261
  };
32205
32262
  try {
@@ -42547,7 +42604,7 @@ function reorderArgs(argv) {
42547
42604
  */
42548
42605
  async function main() {
42549
42606
  const program = new Command();
42550
- program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.99.0");
42607
+ program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.99.2");
42551
42608
  program.addCommand(createBootstrapCommand());
42552
42609
  program.addCommand(createSynthCommand());
42553
42610
  program.addCommand(createListCommand());