cdk-real-drift 0.12.70 → 0.12.71

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
@@ -4222,9 +4222,23 @@ const UNORDERED_NESTED_OBJECT_ARRAY_PATHS = {
4222
4222
  "AWS::AutoScaling::AutoScalingGroup": new Set(["MetricsCollection.Metrics", "NotificationConfigurations.NotificationTypes"]),
4223
4223
  "AWS::Lambda::EventSourceMapping": new Set(["SelfManagedEventSource.Endpoints.KafkaBootstrapServers"])
4224
4224
  };
4225
- function sortNestedObjectArrays(value, subPaths) {
4225
+ const NESTED_OBJECT_ARRAY_IDENTITY = {
4226
+ "AWS::Bedrock::Guardrail": {
4227
+ "ContentPolicyConfig.FiltersConfig": "Type",
4228
+ "TopicPolicyConfig.TopicsConfig": "Name",
4229
+ "SensitiveInformationPolicyConfig.PiiEntitiesConfig": "Type",
4230
+ "SensitiveInformationPolicyConfig.RegexesConfig": "Name",
4231
+ "WordPolicyConfig.WordsConfig": "Text"
4232
+ },
4233
+ "AWS::ECS::TaskDefinition": {
4234
+ "ContainerDefinitions.PortMappings": "ContainerPort",
4235
+ "ContainerDefinitions.VolumesFrom": "SourceContainer"
4236
+ },
4237
+ "AWS::Backup::BackupSelection": { "BackupSelection.ListOfTags": "ConditionKey" }
4238
+ };
4239
+ function sortNestedObjectArrays(value, subPaths, identityBySubPath) {
4226
4240
  if (subPaths.length === 0 || value === null || typeof value !== "object") return value;
4227
- if (Array.isArray(value)) return value.map((el) => sortNestedObjectArrays(el, subPaths));
4241
+ if (Array.isArray(value)) return value.map((el) => sortNestedObjectArrays(el, subPaths, identityBySubPath));
4228
4242
  const clone = structuredClone(value);
4229
4243
  for (const sub of subPaths) {
4230
4244
  const segs = sub.split(".");
@@ -4234,7 +4248,7 @@ function sortNestedObjectArrays(value, subPaths) {
4234
4248
  cur = next !== null && typeof next === "object" ? next : void 0;
4235
4249
  }
4236
4250
  const last = segs[segs.length - 1];
4237
- if (cur && Array.isArray(cur[last])) cur[last] = sortUnorderedObjectArray(cur[last]);
4251
+ if (cur && Array.isArray(cur[last])) cur[last] = sortUnorderedObjectArray(cur[last], identityBySubPath?.[sub]);
4238
4252
  }
4239
4253
  return clone;
4240
4254
  }
@@ -5862,7 +5876,6 @@ function cloneDeepWithSymbols(v) {
5862
5876
  }
5863
5877
  const isPolicyStatementArray = (arr) => arr.length > 0 && arr.every((el) => isNestedObject(el) && "Effect" in el);
5864
5878
  const isInlinePolicyArray = (arr) => arr.length > 0 && arr.every((el) => isNestedObject(el) && "PolicyDocument" in el);
5865
- const isIdentitySortedObjectArray = (arr) => arr.length > 0 && identityField(arr) !== void 0;
5866
5879
  function isPolicySubsetOf(sub, sup) {
5867
5880
  for (const [k, v] of Object.entries(sub)) {
5868
5881
  if (!(k in sup)) return false;
@@ -5980,6 +5993,31 @@ function remapSortedIndexToDeclared(path, arrayKey, sortedDeclared, rawDeclared)
5980
5993
  const rawIdx = rawDeclared.findIndex((e) => deepEqual(e, el));
5981
5994
  return rawIdx < 0 ? path : `${arrayKey}.${rawIdx}${m[2]}`;
5982
5995
  }
5996
+ function crossedSortedArrayRevert(v, k, driftPath, resourceType, nestedSubPaths, nestedIdentityBySubPath) {
5997
+ if (!driftPath.startsWith(`${k}.`)) return void 0;
5998
+ const orderSigKeys = ORDER_SIGNIFICANT_ARRAY_KEYS[resourceType];
5999
+ const orderSigPaths = ORDER_SIGNIFICANT_PATHS[resourceType];
6000
+ const rel = driftPath.slice(k.length + 1).split(".");
6001
+ let cur = v;
6002
+ let arrPathRel = "";
6003
+ let parentKey = k;
6004
+ for (const seg of rel) if (Array.isArray(cur)) {
6005
+ const arr = cur;
6006
+ if (!/^\d+$/.test(seg)) return void 0;
6007
+ const fullPath = arrPathRel ? `${k}.${arrPathRel}` : k;
6008
+ const orderSig = (orderSigKeys?.has(parentKey) || orderSigPaths?.has(fullPath)) ?? false;
6009
+ const idField = identityField(arr) ?? nestedIdentityBySubPath[arrPathRel];
6010
+ if (!orderSig && (idField !== void 0 || nestedSubPaths.includes(arrPathRel)) && arr.length >= 2) return {
6011
+ path: fullPath,
6012
+ value: arr
6013
+ };
6014
+ cur = arr[Number(seg)];
6015
+ } else if (cur !== null && typeof cur === "object") {
6016
+ cur = cur[seg];
6017
+ arrPathRel = arrPathRel ? `${arrPathRel}.${seg}` : seg;
6018
+ parentKey = seg;
6019
+ } else return;
6020
+ }
5983
6021
  const S3_NOTIF_FILTER_RULE_NAMES = {
5984
6022
  prefix: "prefix",
5985
6023
  suffix: "suffix",
@@ -6744,6 +6782,8 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6744
6782
  const nestedUnordered = UNORDERED_NESTED_OBJECT_ARRAY_PATHS[resourceType];
6745
6783
  const orderSigPathsForType = ORDER_SIGNIFICANT_PATHS[resourceType];
6746
6784
  const nestedSubPaths = [...new Set([...nestedUnordered ?? [], ...schema.unorderedObjectArrayPaths ?? []].filter((p) => p.startsWith(`${k}.`) && !orderSigPathsForType?.has(p)).map((p) => p.slice(k.length + 1)))];
6785
+ const nestedIdentityBySubPath = {};
6786
+ for (const [fullPath, idf] of Object.entries(NESTED_OBJECT_ARRAY_IDENTITY[resourceType] ?? {})) if (fullPath.startsWith(`${k}.`)) nestedIdentityBySubPath[fullPath.slice(k.length + 1)] = idf;
6747
6787
  let declaredVal = v;
6748
6788
  let liveVal = live[k];
6749
6789
  let declaredRemapSource;
@@ -6796,14 +6836,14 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6796
6836
  declaredVal = declaredSorted;
6797
6837
  liveVal = liveAligned;
6798
6838
  } else if (unorderedObjArray) {
6799
- const declaredNestedSorted = nestedSubPaths.length > 0 ? sortNestedObjectArrays(v, nestedSubPaths) : v;
6839
+ const declaredNestedSorted = nestedSubPaths.length > 0 ? sortNestedObjectArrays(v, nestedSubPaths, nestedIdentityBySubPath) : v;
6800
6840
  const idField = UNORDERED_OBJECT_ARRAY_IDENTITY[resourceType]?.[k];
6801
6841
  declaredVal = sortUnorderedObjectArray(declaredNestedSorted, idField);
6802
- liveVal = sortUnorderedObjectArray(nestedSubPaths.length > 0 ? sortNestedObjectArrays(live[k], nestedSubPaths) : live[k], idField);
6842
+ liveVal = sortUnorderedObjectArray(nestedSubPaths.length > 0 ? sortNestedObjectArrays(live[k], nestedSubPaths, nestedIdentityBySubPath) : live[k], idField);
6803
6843
  if (Array.isArray(declaredNestedSorted)) declaredRemapSource = declaredNestedSorted;
6804
6844
  } else if (nestedSubPaths.length > 0) {
6805
- declaredVal = sortNestedObjectArrays(v, nestedSubPaths);
6806
- liveVal = sortNestedObjectArrays(live[k], nestedSubPaths);
6845
+ declaredVal = sortNestedObjectArrays(v, nestedSubPaths, nestedIdentityBySubPath);
6846
+ liveVal = sortNestedObjectArrays(live[k], nestedSubPaths, nestedIdentityBySubPath);
6807
6847
  }
6808
6848
  for (const d of calculateResourceDrift({ [k]: declaredVal }, { [k]: liveVal })) {
6809
6849
  if (d.stateValue === UNRESOLVED || hasUnresolved(d.stateValue)) continue;
@@ -6894,17 +6934,14 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6894
6934
  const transformExpr = schema.propertyTransforms?.[d.path] ?? schema.propertyTransforms?.[d.path.replace(/\.\d+(?=\.|$)/g, ".*")];
6895
6935
  if (transformExpr !== void 0 && matchesPropertyTransform(transformExpr, d.stateValue, resolveParentObject(declared, d.path), declared, d.awsValue, d.path.split(".").at(-1) ?? d.path)) continue;
6896
6936
  if (schema.propertyTransforms !== void 0 && transformExpr === void 0 && matchesAncestorPropertyTransform(schema.propertyTransforms, d.path, declared, live)) continue;
6897
- const identitySortedWhole = !unorderedObjArray && Array.isArray(v) && isIdentitySortedObjectArray(v) && d.path.startsWith(`${k}.`);
6937
+ const crossedSorted = unorderedObjArray ? void 0 : crossedSortedArrayRevert(v, k, d.path, resourceType, nestedSubPaths, nestedIdentityBySubPath);
6898
6938
  const unorderedExtra = unorderedObjArray && Array.isArray(declaredVal) && declaredRemapSource ? {
6899
6939
  path: remapSortedIndexToDeclared(d.path, k, declaredVal, declaredRemapSource),
6900
6940
  wholeArrayRevert: {
6901
6941
  path: k,
6902
6942
  value: v
6903
6943
  }
6904
- } : identitySortedWhole ? { wholeArrayRevert: {
6905
- path: k,
6906
- value: v
6907
- } } : {};
6944
+ } : crossedSorted ? { wholeArrayRevert: crossedSorted } : {};
6908
6945
  pushDeclaredFinding(findings, {
6909
6946
  logicalId,
6910
6947
  resourceType,