@fjall/generator 2.34.0 → 3.1.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.
Files changed (110) hide show
  1. package/dist/.minified +1 -1
  2. package/dist/src/ast/astTestHelpers.js +1 -1
  3. package/dist/src/ast/domain/astDomainParser.d.ts +15 -7
  4. package/dist/src/ast/domain/astDomainParser.js +1 -1
  5. package/dist/src/ast/index.d.ts +1 -1
  6. package/dist/src/ast/mutation/astCodeInjection.js +4 -4
  7. package/dist/src/ast/mutation/astExpressionEvaluator.js +1 -1
  8. package/dist/src/ast/mutation/astSurgicalModification.js +5 -5
  9. package/dist/src/ast/parsers/common/astCommonParser.js +1 -1
  10. package/dist/src/ast/parsers/common/astStatementClassifier.js +1 -1
  11. package/dist/src/ast/parsers/common/astStatementQueries.js +3 -3
  12. package/dist/src/ast/parsers/orchestrator/astInfrastructureParser.js +1 -1
  13. package/dist/src/ast/parsers/orchestrator/astPlanConverter.js +2 -2
  14. package/dist/src/ast/parsers/resources/astCdnParser.js +1 -1
  15. package/dist/src/ast/parsers/resources/astClickHouseParser.js +1 -1
  16. package/dist/src/ast/parsers/resources/astComputeConnectionParser.js +1 -1
  17. package/dist/src/ast/parsers/resources/astComputeParser.js +1 -1
  18. package/dist/src/ast/parsers/resources/astComputeParserHelpers.js +1 -1
  19. package/dist/src/ast/parsers/resources/astDatabaseParser.js +1 -1
  20. package/dist/src/ast/parsers/resources/astDynamoDBParser.js +1 -1
  21. package/dist/src/ast/parsers/resources/astMessagingParser.js +1 -1
  22. package/dist/src/ast/parsers/resources/astNetworkParser.js +1 -1
  23. package/dist/src/ast/parsers/resources/astPatternParser.js +1 -1
  24. package/dist/src/ast/parsers/resources/astScheduleParser.js +1 -1
  25. package/dist/src/ast/parsers/resources/astStorageParser.js +1 -1
  26. package/dist/src/aws/regions.js +1 -1
  27. package/dist/src/codemod/_internal.js +1 -1
  28. package/dist/src/codemod/drift/detect.js +1 -1
  29. package/dist/src/codemod/drift/merge.js +1 -1
  30. package/dist/src/codemod/drift/snapshot.js +1 -1
  31. package/dist/src/codemod/edits/addResource/bodyIndex.js +1 -1
  32. package/dist/src/codemod/edits/addResource/propertyBuilder.js +1 -1
  33. package/dist/src/codemod/edits/addResource.js +1 -1
  34. package/dist/src/codemod/edits/appendAccountToStage.js +1 -1
  35. package/dist/src/codemod/edits/controlFlowPolicy.js +1 -1
  36. package/dist/src/codemod/edits/crossPlanConnection.js +1 -1
  37. package/dist/src/codemod/edits/driftPolicy.js +1 -1
  38. package/dist/src/codemod/edits/ensureImports.js +1 -1
  39. package/dist/src/codemod/edits/findInsertionPosition.js +1 -1
  40. package/dist/src/codemod/edits/modifyResource/literalConversion.js +1 -1
  41. package/dist/src/codemod/edits/modifyResource.js +1 -1
  42. package/dist/src/codemod/edits/removeResource/commentHeuristic.js +1 -1
  43. package/dist/src/codemod/edits/removeResource/importPruning.js +1 -1
  44. package/dist/src/codemod/edits/removeResource.js +1 -1
  45. package/dist/src/codemod/edits/vpcPeer.js +1 -1
  46. package/dist/src/codemod/edits/vpcPeerAccepter.js +1 -1
  47. package/dist/src/codemod/fileRewriter/builders.js +1 -1
  48. package/dist/src/codemod/fileRewriter/locateByRange.js +1 -1
  49. package/dist/src/codemod/fileRewriter/parse.js +2 -2
  50. package/dist/src/codemod/fileRewriter/print.js +2 -2
  51. package/dist/src/codemod/historyPaths.js +1 -1
  52. package/dist/src/codemod/listResources.js +1 -1
  53. package/dist/src/codemod/llmFallback/apply.js +1 -1
  54. package/dist/src/codemod/llmFallback/claudeTier.js +1 -1
  55. package/dist/src/codemod/llmFallback/egressGate.js +1 -1
  56. package/dist/src/codemod/llmFallback/morphTier.js +2 -2
  57. package/dist/src/codemod/llmFallback/prompt.js +13 -13
  58. package/dist/src/codemod/llmFallback/runFallback.js +1 -1
  59. package/dist/src/codemod/llmFallback/shouldTryFallback.js +1 -1
  60. package/dist/src/codemod/llmFallback/signals.js +1 -1
  61. package/dist/src/codemod/llmFallback/telemetryEvents.js +1 -1
  62. package/dist/src/codemod/llmFallback/tierRunner.js +1 -1
  63. package/dist/src/codemod/registry.js +1 -1
  64. package/dist/src/codemod/semanticIndex/classifyControlFlow.js +1 -1
  65. package/dist/src/codemod/semanticIndex/findReferences.js +2 -2
  66. package/dist/src/codemod/semanticIndex/listImports.js +1 -1
  67. package/dist/src/codemod/semanticIndex/locateByShape.js +1 -1
  68. package/dist/src/codemod/semanticIndex/projectCache.js +1 -1
  69. package/dist/src/codemod/semanticIndex/resolveConstructByLiteralProperty.js +1 -1
  70. package/dist/src/codemod/validationGate/gates/classify.js +1 -1
  71. package/dist/src/codemod/validationGate/gates/locate.js +1 -1
  72. package/dist/src/codemod/validationGate/types.js +1 -1
  73. package/dist/src/detection/index.js +1 -1
  74. package/dist/src/dns/bindParser.js +2 -2
  75. package/dist/src/dns/bindWriter.js +2 -2
  76. package/dist/src/dns/domainFileGenerator.js +18 -28
  77. package/dist/src/dns/domainRecords.d.ts +11 -0
  78. package/dist/src/dns/domainRecords.js +1 -1
  79. package/dist/src/generation/common.js +7 -7
  80. package/dist/src/generation/compute/ec2.js +3 -3
  81. package/dist/src/generation/compute/ecs.js +24 -24
  82. package/dist/src/generation/compute/lambda.js +8 -8
  83. package/dist/src/generation/compute/shared.js +4 -4
  84. package/dist/src/generation/compute.js +5 -5
  85. package/dist/src/generation/database.js +18 -18
  86. package/dist/src/generation/generatePatternCode.js +16 -16
  87. package/dist/src/generation/infrastructure.js +14 -14
  88. package/dist/src/generation/messagingConnections.js +1 -1
  89. package/dist/src/generation/storage.js +14 -14
  90. package/dist/src/generation/storageConnections.js +1 -1
  91. package/dist/src/planning/generateResourceChange.js +1 -1
  92. package/dist/src/planning/openNextPlanning.js +1 -1
  93. package/dist/src/planning/resourceAddition.js +1 -1
  94. package/dist/src/planning/resourceConnections.js +1 -1
  95. package/dist/src/planning/resourcePlanning.js +1 -1
  96. package/dist/src/planning/staticSitePlanning.js +1 -1
  97. package/dist/src/presets/patternTierPresets.js +1 -1
  98. package/dist/src/presets/storagePresets.js +1 -1
  99. package/dist/src/presets/tierPresets.js +1 -1
  100. package/dist/src/schemas/baseSchemas.js +2 -2
  101. package/dist/src/schemas/computeSchemas.js +1 -1
  102. package/dist/src/schemas/constants.js +1 -1
  103. package/dist/src/schemas/devRolePolicies.js +1 -1
  104. package/dist/src/schemas/instanceTypeArchitecture.js +1 -1
  105. package/dist/src/schemas/securityBoundary.js +1 -1
  106. package/dist/src/types/Result.js +1 -1
  107. package/dist/src/validation/validationPatterns.js +1 -1
  108. package/dist/src/version.d.ts +1 -1
  109. package/dist/src/version.js +1 -1
  110. package/package.json +3 -3
@@ -1 +1 @@
1
- import*as y from"typescript";import{STATIC_SITE_ROUTING_VALUES as P}from"@fjall/util";import{asBoolean as p,asNumber as s,asString as o,asStringArray as v,asStringUnion as h,asObjectOrFalse as g,collectFromAst as I,extractSubConfig as u,extractVariableName as _,isFactoryBuildCall as C,isFactoryMethodCall as F,isParsedObject as O,isPlainObject as D,parseObjectLiteral as E,parseOptionalConfig as d,typed as S}from"../common/astCommonParser.js";import{parseDeadLetterQueueConfig as L}from"./astMessagingParser.js";const N=["Instance","Aurora"],z=["postgresql","mysql"];function x(t){if(!O(t))return;const e={...t.memorySize!==void 0&&{memorySize:s(t.memorySize)},...t.timeout!==void 0&&{timeout:s(t.timeout)},...t.ephemeralStorageSize!==void 0&&{ephemeralStorageSize:s(t.ephemeralStorageSize)}};return Object.keys(e).length>0?e:void 0}function R(t){return u(t,"database",e=>({type:h(e.type,N),databaseName:o(e.databaseName),databaseEngine:h(e.databaseEngine,z),deletionProtection:p(e.deletionProtection),backupRetention:s(e.backupRetention),port:s(e.port),publiclyAccessible:p(e.publiclyAccessible),allowedIpCidr:o(e.allowedIpCidr),instanceType:o(e.instanceType),allocatedStorage:s(e.allocatedStorage),multiAz:p(e.multiAz),allowVpcAccess:p(e.allowVpcAccess),monitoringInterval:s(e.monitoringInterval),preferredMaintenanceWindow:o(e.preferredMaintenanceWindow),snapshotIdentifier:o(e.snapshotIdentifier),snapshotUsername:o(e.snapshotUsername),readReplica:g(e.readReplica),writer:d(e.writer,S()),readers:g(e.readers),databaseInsights:g(e.databaseInsights),proxy:g(e.proxy),credentials:d(e.credentials,S()),encryption:d(e.encryption,S())}))}function T(t){return u(t,"compute",e=>({server:d(e.server,x),imageOptimisation:d(e.imageOptimisation,x),revalidation:d(e.revalidation,x)}))}function k(t){const e=n=>({versioned:p(n.versioned)});return u(t,"storage",n=>({assets:d(n.assets,e),cache:d(n.cache,e),media:d(n.media,e)}))}function j(t){return u(t,"messaging",e=>({revalidationQueue:d(e.revalidationQueue,n=>({visibilityTimeout:s(n.visibilityTimeout),messageRetentionPeriod:s(n.messageRetentionPeriod),maxMessageSize:s(n.maxMessageSize),deadLetterQueue:L(n.deadLetterQueue)}))}))}function U(t){return u(t,"cdn",e=>({domainNames:v(e.domainNames),certificateArn:o(e.certificateArn)}))}function V(t){return u(t,"environment",e=>{const n=Object.fromEntries(Object.entries(e).filter(r=>typeof r[1]=="string"));return Object.keys(n).length>0?n:void 0})}function M(t,e){const n=B(t);return{name:e,source:o(t.source),build:u(t,"build",r=>({command:o(r.command),outputDir:o(r.outputDir)})),routing:h(t.routing,P),security:u(t,"security",r=>({headers:p(r.headers),contentSecurityPolicy:o(r.contentSecurityPolicy)})),domain:o(t.domain),forms:u(t,"forms",r=>({to:o(r.to),from:o(r.from),corsOrigin:o(r.corsOrigin),maxConcurrency:s(r.maxConcurrency)})),cdn:u(t,"cdn",r=>({behaviours:Array.isArray(r.behaviours)?r.behaviours:void 0})),...n.length>0&&{unreadableFields:n}}}function A(t){return D(t)&&("__identifier"in t||"__expression"in t||"__call"in t||"__unknown"in t)}function B(t){const e=[],n=(i,a)=>{A(i)&&e.push(a)};n(t.source,"source"),n(t.routing,"routing"),n(t.domain,"domain");const r=[[t.build,"build",["command","outputDir"]],[t.security,"security",["headers","contentSecurityPolicy"]],[t.forms,"forms",["to","from","corsOrigin","maxConcurrency"]],[t.cdn,"cdn",["behaviours"]]];for(const[i,a,c]of r)if(A(i))e.push(a);else if(O(i))for(const m of c)n(i[m],`${a}.${m}`);return e}function f(t){return t!==void 0&&t!==""}function b(t,e){return new Error(`Static-site pattern '${t}' in infrastructure.ts: Fjall could not read ${e.join(", ")} as inline literal(s). Fjall reads these fields out of the file and writes them back, so they must be written inline (source: "./site"), not as a variable or an expression.`)}function Q(t,e){const n=e.to;if(!f(n))throw b(t,["forms.to"]);return{to:n,...e.from!==void 0&&{from:e.from},...e.corsOrigin!==void 0&&{corsOrigin:e.corsOrigin},...e.maxConcurrency!==void 0&&{maxConcurrency:e.maxConcurrency}}}function $(t,e){if(t.arguments.length<2)return null;const n=t.arguments[0],r=t.arguments[1];if(!y.isStringLiteral(n)||!y.isObjectLiteralExpression(r))return null;const i=n.text,a=E(r),c=a.type,m=_(e),l=o(a.name);return l?c==="payload"||c==="nextjs"?{variableName:m,constructId:i,type:c,config:{name:l,domain:o(a.domain),database:R(a),compute:T(a),storage:k(a),messaging:j(a),cdn:U(a),environment:V(a)},node:t}:c==="staticsite"?{variableName:m,constructId:i,type:"staticsite",config:M(a,l),node:t}:null:null}function K(t){return I(t,e=>{if(!y.isCallExpression(e)||!F(e,"addPattern"))return null;const n=e.arguments[0];return C(n,"PatternFactory")?$(n,e):null})}function Y(t,e){if(!e||e.length===0)return;const n=e[0];if(t.pattern=n.type,n.type==="staticsite"){const{config:i}=n,a=i.source,c=i.build?.command,m=i.build?.outputDir;if(i.unreadableFields!==void 0)throw b(i.name,i.unreadableFields);if(!f(a)||!f(c)||!f(m)){const l=[];throw f(a)||l.push("source"),f(c)||l.push("build.command"),f(m)||l.push("build.outputDir"),b(i.name,l)}t.patternConfig={type:"staticsite",name:i.name,source:a,build:{command:c,outputDir:m},routing:i.routing,security:i.security,domain:i.domain,...i.forms!==void 0&&{forms:Q(i.name,i.forms)},cdn:i.cdn};return}const{config:r}=n;t.patternConfig={type:n.type,name:r.name,domain:r.domain,database:r.database,compute:r.compute,storage:r.storage,messaging:r.messaging,cdn:r.cdn,environment:r.environment}}export{Y as applyPatternConfig,K as findPatternResources};
1
+ var v=Object.defineProperty;var o=(t,e)=>v(t,"name",{value:e,configurable:!0});import*as h from"typescript";import{STATIC_SITE_ROUTING_VALUES as I}from"@fjall/util";import{asBoolean as g,asNumber as c,asString as s,asStringArray as _,asStringUnion as S,asObjectOrFalse as y,collectFromAst as C,extractSubConfig as d,extractVariableName as F,isFactoryBuildCall as D,isFactoryMethodCall as E,isParsedObject as A,isPlainObject as L,parseObjectLiteral as N,parseOptionalConfig as m,typed as x}from"../common/astCommonParser.js";import{parseDeadLetterQueueConfig as z}from"./astMessagingParser.js";const R=["Instance","Aurora"],T=["postgresql","mysql"];function b(t){if(!A(t))return;const e={...t.memorySize!==void 0&&{memorySize:c(t.memorySize)},...t.timeout!==void 0&&{timeout:c(t.timeout)},...t.ephemeralStorageSize!==void 0&&{ephemeralStorageSize:c(t.ephemeralStorageSize)}};return Object.keys(e).length>0?e:void 0}o(b,"parseLambdaConfig");function k(t){return d(t,"database",e=>({type:S(e.type,R),databaseName:s(e.databaseName),databaseEngine:S(e.databaseEngine,T),deletionProtection:g(e.deletionProtection),backupRetention:c(e.backupRetention),port:c(e.port),publiclyAccessible:g(e.publiclyAccessible),allowedIpCidr:s(e.allowedIpCidr),instanceType:s(e.instanceType),allocatedStorage:c(e.allocatedStorage),multiAz:g(e.multiAz),allowVpcAccess:g(e.allowVpcAccess),monitoringInterval:c(e.monitoringInterval),preferredMaintenanceWindow:s(e.preferredMaintenanceWindow),snapshotIdentifier:s(e.snapshotIdentifier),snapshotUsername:s(e.snapshotUsername),readReplica:y(e.readReplica),writer:m(e.writer,x()),readers:y(e.readers),databaseInsights:y(e.databaseInsights),proxy:y(e.proxy),credentials:m(e.credentials,x()),encryption:m(e.encryption,x())}))}o(k,"extractPatternDatabaseConfig");function j(t){return d(t,"compute",e=>({server:m(e.server,b),imageOptimisation:m(e.imageOptimisation,b),revalidation:m(e.revalidation,b)}))}o(j,"extractPatternComputeConfig");function U(t){const e=o(n=>({versioned:g(n.versioned)}),"parseVersionedConfig");return d(t,"storage",n=>({assets:m(n.assets,e),cache:m(n.cache,e),media:m(n.media,e)}))}o(U,"extractPatternStorageConfig");function V(t){return d(t,"messaging",e=>({revalidationQueue:m(e.revalidationQueue,n=>({visibilityTimeout:c(n.visibilityTimeout),messageRetentionPeriod:c(n.messageRetentionPeriod),maxMessageSize:c(n.maxMessageSize),deadLetterQueue:z(n.deadLetterQueue)}))}))}o(V,"extractPatternMessagingConfig");function M(t){return d(t,"cdn",e=>({domainNames:_(e.domainNames),certificateArn:s(e.certificateArn)}))}o(M,"extractPatternCdnConfig");function B(t){return d(t,"environment",e=>{const n=Object.fromEntries(Object.entries(e).filter(r=>typeof r[1]=="string"));return Object.keys(n).length>0?n:void 0})}o(B,"extractPatternEnvironmentConfig");function Q(t,e){const n=$(t);return{name:e,source:s(t.source),build:d(t,"build",r=>({command:s(r.command),outputDir:s(r.outputDir)})),routing:S(t.routing,I),security:d(t,"security",r=>({headers:g(r.headers),contentSecurityPolicy:s(r.contentSecurityPolicy)})),domain:s(t.domain),forms:d(t,"forms",r=>({to:s(r.to),from:s(r.from),corsOrigin:s(r.corsOrigin),maxConcurrency:c(r.maxConcurrency)})),cdn:d(t,"cdn",r=>({behaviours:Array.isArray(r.behaviours)?r.behaviours:void 0})),...n.length>0&&{unreadableFields:n}}}o(Q,"extractStaticSiteConfig");function P(t){return L(t)&&("__identifier"in t||"__expression"in t||"__call"in t||"__unknown"in t)}o(P,"isUnreadableRef");function $(t){const e=[],n=o((i,a)=>{P(i)&&e.push(a)},"check");n(t.source,"source"),n(t.routing,"routing"),n(t.domain,"domain");const r=[[t.build,"build",["command","outputDir"]],[t.security,"security",["headers","contentSecurityPolicy"]],[t.forms,"forms",["to","from","corsOrigin","maxConcurrency"]],[t.cdn,"cdn",["behaviours"]]];for(const[i,a,u]of r)if(P(i))e.push(a);else if(A(i))for(const l of u)n(i[l],`${a}.${l}`);return e}o($,"collectUnreadableStaticSiteFields");function p(t){return t!==void 0&&t!==""}o(p,"isReadable");function O(t,e){return new Error(`Static-site pattern '${t}' in infrastructure.ts: Fjall could not read ${e.join(", ")} as inline literal(s). Fjall reads these fields out of the file and writes them back, so they must be written inline (source: "./site"), not as a variable or an expression.`)}o(O,"unreadableStaticSiteFields");function w(t,e){const n=e.to;if(!p(n))throw O(t,["forms.to"]);return{to:n,...e.from!==void 0&&{from:e.from},...e.corsOrigin!==void 0&&{corsOrigin:e.corsOrigin},...e.maxConcurrency!==void 0&&{maxConcurrency:e.maxConcurrency}}}o(w,"readStaticSiteForms");function G(t,e){if(t.arguments.length<2)return null;const n=t.arguments[0],r=t.arguments[1];if(!h.isStringLiteral(n)||!h.isObjectLiteralExpression(r))return null;const i=n.text,a=N(r),u=a.type,l=F(e),f=s(a.name);return f?u==="payload"||u==="nextjs"?{variableName:l,constructId:i,type:u,config:{name:f,domain:s(a.domain),database:k(a),compute:j(a),storage:U(a),messaging:V(a),cdn:M(a),environment:B(a)},node:t}:u==="staticsite"?{variableName:l,constructId:i,type:"staticsite",config:Q(a,f),node:t}:null:null}o(G,"extractPatternResource");function J(t){return C(t,e=>{if(!h.isCallExpression(e)||!E(e,"addPattern"))return null;const n=e.arguments[0];return D(n,"PatternFactory")?G(n,e):null})}o(J,"findPatternResources");function X(t,e){if(!e||e.length===0)return;const n=e[0];if(t.pattern=n.type,n.type==="staticsite"){const{config:i}=n,a=i.source,u=i.build?.command,l=i.build?.outputDir;if(i.unreadableFields!==void 0)throw O(i.name,i.unreadableFields);if(!p(a)||!p(u)||!p(l)){const f=[];throw p(a)||f.push("source"),p(u)||f.push("build.command"),p(l)||f.push("build.outputDir"),O(i.name,f)}t.patternConfig={type:"staticsite",name:i.name,source:a,build:{command:u,outputDir:l},routing:i.routing,security:i.security,domain:i.domain,...i.forms!==void 0&&{forms:w(i.name,i.forms)},cdn:i.cdn};return}const{config:r}=n;t.patternConfig={type:n.type,name:r.name,domain:r.domain,database:r.database,compute:r.compute,storage:r.storage,messaging:r.messaging,cdn:r.cdn,environment:r.environment}}o(X,"applyPatternConfig");export{X as applyPatternConfig,J as findPatternResources};
@@ -1 +1 @@
1
- import*as r from"typescript";import{asString as o,collectFromAst as c,isFactoryMethodCall as f,parseObjectLiteral as g}from"../common/astCommonParser.js";function p(u){return c(u,t=>{if(!r.isCallExpression(t)||!f(t,"addSchedule")||t.arguments.length<2)return null;const s=t.arguments[0],i=t.arguments[1];if(!r.isStringLiteral(s)||!r.isObjectLiteralExpression(i))return null;const a=g(i),l=o(a.schedule);if(l===void 0)return null;const e=i.properties.find(n=>r.isPropertyAssignment(n)&&r.isIdentifier(n.name)&&n.name.text==="target");return!e||!r.isPropertyAssignment(e)||!r.isIdentifier(e.initializer)?null:{id:s.text,schedule:l,targetVariableName:e.initializer.text}})}export{p as findSchedules};
1
+ var c=Object.defineProperty;var a=(i,r)=>c(i,"name",{value:r,configurable:!0});import*as t from"typescript";import{asString as f,collectFromAst as g,isFactoryMethodCall as m,parseObjectLiteral as p}from"../common/astCommonParser.js";function x(i){return g(i,r=>{if(!t.isCallExpression(r)||!m(r,"addSchedule")||r.arguments.length<2)return null;const l=r.arguments[0],n=r.arguments[1];if(!t.isStringLiteral(l)||!t.isObjectLiteralExpression(n))return null;const o=p(n),u=f(o.schedule);if(u===void 0)return null;const e=n.properties.find(s=>t.isPropertyAssignment(s)&&t.isIdentifier(s.name)&&s.name.text==="target");return!e||!t.isPropertyAssignment(e)||!t.isIdentifier(e.initializer)?null:{id:l.text,schedule:u,targetVariableName:e.initializer.text}})}a(x,"findSchedules");export{x as findSchedules};
@@ -1 +1 @@
1
- import*as i from"typescript";import{S3_STACK_PLACEMENTS as g}from"../../../schemas/resourceSchemas.js";import{S3_ENCRYPTION_TYPES as f,BACKUP_VAULT_TIERS as p}from"../../../schemas/constants.js";import{asBoolean as c,asNumber as d,asString as o,asStringUnion as a,captureExtraProperties as x,collectFromAst as b,extractVariableName as N,isFactoryBuildCall as k,isFactoryMethodCall as h,isParsedObject as u,parseObjectLiteral as y}from"../common/astCommonParser.js";const A=new Set(["S3Bucket"]);function C(n,e,r){const t=i.isIdentifier(n.name)?n.name.text:"";if(e.arguments&&e.arguments.length>=2){const s=e.arguments[1],m=i.isStringLiteral(s)?s.text:"",l=e.arguments.length>=3?e.arguments[2]:void 0,S=l&&i.isObjectLiteralExpression(l)?y(l):{};return{variableName:t,resourceName:m,bucketClass:r,config:S,node:n}}return null}function P(n,e){if(e.arguments.length<2)return null;const r=e.arguments[0],t=e.arguments[1];if(!i.isStringLiteral(r)||!i.isObjectLiteralExpression(t))return null;const s=y(t);return{variableName:N(n)??"",resourceName:r.text,bucketClass:"StorageFactory",config:s,node:n}}function R(n){return b(n,e=>{if(!i.isVariableDeclaration(e)||!e.initializer||!i.isNewExpression(e.initializer))return null;const r=e.initializer;if(!i.isIdentifier(r.expression))return null;const t=r.expression.text;return A.has(t)?C(e,r,t):null})}function _(n){return b(n,e=>{if(!i.isCallExpression(e)||!h(e,"addStorage"))return null;const r=e.arguments[0];return k(r,"StorageFactory")?P(e,r):null})}function v(n){return n.map(e=>({name:e.resourceName,...o(e.config.bucketName)&&{bucketName:o(e.config.bucketName)},...c(e.config.publicReadAccess)===!0&&{publicReadAccess:!0},...u(e.config.websiteHosting)&&(()=>{const r=e.config.websiteHosting;return{websiteHosting:{indexDocument:o(r.indexDocument)??"index.html",...o(r.errorDocument)&&{errorDocument:o(r.errorDocument)}}}})(),...a(e.config.backupVaultTier,p)&&{backupVaultTier:a(e.config.backupVaultTier,p)},...c(e.config.versioned)!==void 0&&{versioned:c(e.config.versioned)},...a(e.config.encryption,f)&&{encryption:a(e.config.encryption,f)},...o(e.config.kmsKeyArn)&&{kmsKeyArn:o(e.config.kmsKeyArn)},...Array.isArray(e.config.cors)&&e.config.cors.length>0&&{cors:e.config.cors.filter(u).map(r=>({allowedOrigins:Array.isArray(r.allowedOrigins)?r.allowedOrigins.filter(t=>typeof t=="string"):[],allowedMethods:Array.isArray(r.allowedMethods)?r.allowedMethods.filter(t=>typeof t=="string"):[]}))},...u(e.config.deployment)&&(()=>{const r=e.config.deployment;return{deployment:{source:o(r.source)??"",...c(r.prune)!==void 0&&{prune:c(r.prune)},...u(r.cacheControl)&&(()=>{const t=r.cacheControl;return{cacheControl:{...d(t.maxAge)!==void 0&&{maxAge:d(t.maxAge)},...c(t.immutable)!==void 0&&{immutable:c(t.immutable)}}}})()}}})(),...a(e.config.stackPlacement,g)&&{stackPlacement:a(e.config.stackPlacement,g)},...e.variableName&&{variableName:e.variableName},...(()=>{const r=new Set(["bucketName","publicReadAccess","websiteHosting","backupVaultTier","versioned","encryption","kmsKeyArn","cors","deployment","stackPlacement"]),t=x(e.config,r);return t.length>0?{extraProperties:t}:{}})()}))}export{A as S3_BUCKET_CLASSES,v as convertS3Resources,_ as findS3FactoryResources,R as findS3Resources};
1
+ var N=Object.defineProperty;var a=(n,e)=>N(n,"name",{value:e,configurable:!0});import*as i from"typescript";import{S3_STACK_PLACEMENTS as f}from"../../../schemas/resourceSchemas.js";import{S3_ENCRYPTION_TYPES as p,BACKUP_VAULT_TIERS as d}from"../../../schemas/constants.js";import{asBoolean as c,asNumber as b,asString as o,asStringUnion as s,captureExtraProperties as k,collectFromAst as y,extractVariableName as h,isFactoryBuildCall as C,isFactoryMethodCall as P,isParsedObject as l,parseObjectLiteral as A}from"../common/astCommonParser.js";const S=new Set(["S3Bucket"]);function T(n,e,r){const t=i.isIdentifier(n.name)?n.name.text:"";if(e.arguments&&e.arguments.length>=2){const u=e.arguments[1],g=i.isStringLiteral(u)?u.text:"",m=e.arguments.length>=3?e.arguments[2]:void 0,x=m&&i.isObjectLiteralExpression(m)?A(m):{};return{variableName:t,resourceName:g,bucketClass:r,config:x,node:n}}return null}a(T,"extractS3Resource");function w(n,e){if(e.arguments.length<2)return null;const r=e.arguments[0],t=e.arguments[1];if(!i.isStringLiteral(r)||!i.isObjectLiteralExpression(t))return null;const u=A(t);return{variableName:h(n)??"",resourceName:r.text,bucketClass:"StorageFactory",config:u,node:n}}a(w,"extractS3FactoryResource");function K(n){return y(n,e=>{if(!i.isVariableDeclaration(e)||!e.initializer||!i.isNewExpression(e.initializer))return null;const r=e.initializer;if(!i.isIdentifier(r.expression))return null;const t=r.expression.text;return S.has(t)?T(e,r,t):null})}a(K,"findS3Resources");function O(n){return y(n,e=>{if(!i.isCallExpression(e)||!P(e,"addStorage"))return null;const r=e.arguments[0];return C(r,"StorageFactory")?w(e,r):null})}a(O,"findS3FactoryResources");function L(n){return n.map(e=>({name:e.resourceName,...o(e.config.bucketName)&&{bucketName:o(e.config.bucketName)},...c(e.config.publicReadAccess)===!0&&{publicReadAccess:!0},...l(e.config.websiteHosting)&&(()=>{const r=e.config.websiteHosting;return{websiteHosting:{indexDocument:o(r.indexDocument)??"index.html",...o(r.errorDocument)&&{errorDocument:o(r.errorDocument)}}}})(),...s(e.config.backupVaultTier,d)&&{backupVaultTier:s(e.config.backupVaultTier,d)},...c(e.config.versioned)!==void 0&&{versioned:c(e.config.versioned)},...s(e.config.encryption,p)&&{encryption:s(e.config.encryption,p)},...o(e.config.kmsKeyArn)&&{kmsKeyArn:o(e.config.kmsKeyArn)},...Array.isArray(e.config.cors)&&e.config.cors.length>0&&{cors:e.config.cors.filter(l).map(r=>({allowedOrigins:Array.isArray(r.allowedOrigins)?r.allowedOrigins.filter(t=>typeof t=="string"):[],allowedMethods:Array.isArray(r.allowedMethods)?r.allowedMethods.filter(t=>typeof t=="string"):[]}))},...l(e.config.deployment)&&(()=>{const r=e.config.deployment;return{deployment:{source:o(r.source)??"",...c(r.prune)!==void 0&&{prune:c(r.prune)},...l(r.cacheControl)&&(()=>{const t=r.cacheControl;return{cacheControl:{...b(t.maxAge)!==void 0&&{maxAge:b(t.maxAge)},...c(t.immutable)!==void 0&&{immutable:c(t.immutable)}}}})()}}})(),...s(e.config.stackPlacement,f)&&{stackPlacement:s(e.config.stackPlacement,f)},...e.variableName&&{variableName:e.variableName},...(()=>{const r=new Set(["bucketName","publicReadAccess","websiteHosting","backupVaultTier","versioned","encryption","kmsKeyArn","cors","deployment","stackPlacement"]),t=k(e.config,r);return t.length>0?{extraProperties:t}:{}})()}))}a(L,"convertS3Resources");export{S as S3_BUCKET_CLASSES,L as convertS3Resources,O as findS3FactoryResources,K as findS3Resources};
@@ -1 +1 @@
1
- import{AWS_REGIONS_METADATA as s,getRegionInfo as f,regions as u}from"@fjall/util";import{AWS_REGIONS_METADATA as $,DEFAULT_REGION as w,getRegionInfo as D,OPT_IN_REGION_CODES as y,optInRegionWarning as z,regions as G,suggestRegionForTimezone as L}from"@fjall/util";const p=["us-east-2","us-west-2","us-east-1","eu-west-1","eu-central-1","ap-southeast-1"],E=Object.freeze(p.flatMap(t=>{const e=f(t);return e?[e]:[]})),c=Object.freeze(["us-east-2","us-west-2","us-east-1","eu-west-1","ap-southeast-1"]);function g(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean):[]}function l(t){return u.includes(t)}function R(t){return/^[a-z]{2}-[a-z]+-[1-9]$/.test(t)}function x(t){if(!t)return c.slice(0,3);const e=t.toLowerCase().split("-"),n=e[0],o=e.length>1?e[1]:"";let r=[];return n&&o&&(r=u.filter(i=>i.startsWith(`${n}-${o}`))),r.length===0&&n&&(r=u.filter(i=>i.startsWith(`${n}-`))),r.length>0?r.slice(0,3):c.slice(0,3)}function d(t){if(l(t))return!0;const e=x(t);return R(t)?`Unknown region. Try: ${e.join(", ")}`:`Invalid format. Try: ${e.join(", ")}`}function I(t){if(!t||t.trim()==="")return!0;const e=g(t);for(const n of e){const o=d(n);if(o!==!0)return o}return!0}function m(t,e){return t.filter(n=>n!==e)}function a(t){return{label:t.city,value:t.code,description:t.optIn?`${t.code} \u2014 opt-in required`:t.code}}function T(){return s.map(a)}function _(t){return s.filter(e=>e.code!==t).map(a)}function A(t){const e=s.find(n=>n.code===t);return e?e.city:t}function h(t){return e=>{const n=g(e);return m(n,t)}}export{$ as AWS_REGIONS_METADATA,w as DEFAULT_REGION,y as OPT_IN_REGION_CODES,c as commonRegions,h as createRegionFormatter,m as filterDuplicateRegions,D as getRegionInfo,A as getRegionName,T as getRegionOptions,_ as getRegionOptionsExcluding,x as getSuggestions,l as isValidRegion,R as isValidRegionFormat,z as optInRegionWarning,g as parseRegionList,G as regions,L as suggestRegionForTimezone,E as topRegions,d as validateRegion,I as validateRegionList};
1
+ var p=Object.defineProperty;var n=(t,e)=>p(t,"name",{value:e,configurable:!0});import{AWS_REGIONS_METADATA as u,getRegionInfo as l,regions as c}from"@fjall/util";import{AWS_REGIONS_METADATA as y,DEFAULT_REGION as z,getRegionInfo as G,OPT_IN_REGION_CODES as L,optInRegionWarning as W,regions as j,suggestRegionForTimezone as F}from"@fjall/util";const R=["us-east-2","us-west-2","us-east-1","eu-west-1","eu-central-1","ap-southeast-1"],_=Object.freeze(R.flatMap(t=>{const e=l(t);return e?[e]:[]})),g=Object.freeze(["us-east-2","us-west-2","us-east-1","eu-west-1","ap-southeast-1"]);function a(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean):[]}n(a,"parseRegionList");function x(t){return c.includes(t)}n(x,"isValidRegion");function d(t){return/^[a-z]{2}-[a-z]+-[1-9]$/.test(t)}n(d,"isValidRegionFormat");function m(t){if(!t)return g.slice(0,3);const e=t.toLowerCase().split("-"),o=e[0],r=e.length>1?e[1]:"";let i=[];return o&&r&&(i=c.filter(s=>s.startsWith(`${o}-${r}`))),i.length===0&&o&&(i=c.filter(s=>s.startsWith(`${o}-`))),i.length>0?i.slice(0,3):g.slice(0,3)}n(m,"getSuggestions");function O(t){if(x(t))return!0;const e=m(t);return d(t)?`Unknown region. Try: ${e.join(", ")}`:`Invalid format. Try: ${e.join(", ")}`}n(O,"validateRegion");function A(t){if(!t||t.trim()==="")return!0;const e=a(t);for(const o of e){const r=O(o);if(r!==!0)return r}return!0}n(A,"validateRegionList");function E(t,e){return t.filter(o=>o!==e)}n(E,"filterDuplicateRegions");function f(t){return{label:t.city,value:t.code,description:t.optIn?`${t.code} \u2014 opt-in required`:t.code}}n(f,"toRegionOption");function h(){return u.map(f)}n(h,"getRegionOptions");function N(t){return u.filter(e=>e.code!==t).map(f)}n(N,"getRegionOptionsExcluding");function S(t){const e=u.find(o=>o.code===t);return e?e.city:t}n(S,"getRegionName");function $(t){return e=>{const o=a(e);return E(o,t)}}n($,"createRegionFormatter");export{y as AWS_REGIONS_METADATA,z as DEFAULT_REGION,L as OPT_IN_REGION_CODES,g as commonRegions,$ as createRegionFormatter,E as filterDuplicateRegions,G as getRegionInfo,S as getRegionName,h as getRegionOptions,N as getRegionOptionsExcluding,m as getSuggestions,x as isValidRegion,d as isValidRegionFormat,W as optInRegionWarning,a as parseRegionList,j as regions,F as suggestRegionForTimezone,_ as topRegions,O as validateRegion,A as validateRegionList};
@@ -1 +1 @@
1
- import{detectLineTerminator as i}from"./fileRewriter/index.js";const c="/__codemod__/input.ts";function o(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function f(r){if(!o(r))return;const t=r.program;if(!o(t))return;const e=t.body;if(Array.isArray(e)&&e.every(o))return e}function d(r,t){return r.length===0?0:r.split(t).length}function a(r,t){const e=i(r),n=d(t,e)-d(r,e);return n>=0?{added:n,removed:0}:{added:0,removed:-n}}export{c as DEFAULT_FILE_PATH,a as computeLinesDelta,f as extractProgramBody,o as isRecord};
1
+ var u=Object.defineProperty;var n=(r,t)=>u(r,"name",{value:t,configurable:!0});import{detectLineTerminator as c}from"./fileRewriter/index.js";const m="/__codemod__/input.ts";function d(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}n(d,"isRecord");function p(r){if(!d(r))return;const t=r.program;if(!d(t))return;const e=t.body;if(Array.isArray(e)&&e.every(d))return e}n(p,"extractProgramBody");function i(r,t){return r.length===0?0:r.split(t).length}n(i,"countLines");function s(r,t){const e=c(r),o=i(t,e)-i(r,e);return o>=0?{added:o,removed:0}:{added:0,removed:-o}}n(s,"computeLinesDelta");export{m as DEFAULT_FILE_PATH,s as computeLinesDelta,p as extractProgramBody,d as isRecord};
@@ -1 +1 @@
1
- import{failure as c,success as m}from"../../types/Result.js";import{listResources as l}from"../listResources.js";import{mergeProperties as y}from"./merge.js";import{snapshotProperties as h}from"./snapshot.js";function R(o,e,n){const r=l(o);if(!r.success)return c(r.error);if(r.data.resources.find(s=>s.type===e.type&&s.name===e.name)===void 0)return e.op==="add"?m({resource:{type:e.type,name:e.name},deltas:[],summary:"clean"}):c({kind:"ResourceNotFoundError",type:e.type,name:e.name,knownNames:r.data.resources.filter(s=>s.type===e.type).map(s=>s.name)});const t=h(o,e.type,e.name);if(!t.success)return c(t.error);const i={...t.data.properties},d={...e.properties},u=n===void 0?void 0:{...n.properties},f=y(u,i,d),p=b(f.deltas,u!==void 0);return m({resource:{type:e.type,name:e.name},deltas:f.deltas,summary:p})}function b(o,e){if(o.length===0)return"clean";let n=!1,r=!1,a=!1,t=!1;for(const i of o)switch(i.verdict){case"conflict":n=!0;break;case"compatible":r=!0;break;case"clean":a=!0;break;case"no-op":t=!0;break}return n?"drifted-conflict":r?"drifted-compatible":t&&!a?"no-op":"clean"}export{R as detectDrift};
1
+ var y=Object.defineProperty;var c=(r,e)=>y(r,"name",{value:e,configurable:!0});import{failure as u,success as d}from"../../types/Result.js";import{listResources as h}from"../listResources.js";import{mergeProperties as b}from"./merge.js";import{snapshotProperties as k}from"./snapshot.js";function P(r,e,n){const t=h(r);if(!t.success)return u(t.error);if(t.data.resources.find(o=>o.type===e.type&&o.name===e.name)===void 0)return e.op==="add"?d({resource:{type:e.type,name:e.name},deltas:[],summary:"clean"}):u({kind:"ResourceNotFoundError",type:e.type,name:e.name,knownNames:t.data.resources.filter(o=>o.type===e.type).map(o=>o.name)});const s=k(r,e.type,e.name);if(!s.success)return u(s.error);const i={...s.data.properties},p={...e.properties},f=n===void 0?void 0:{...n.properties},m=b(f,i,p),l=g(m.deltas,f!==void 0);return d({resource:{type:e.type,name:e.name},deltas:m.deltas,summary:l})}c(P,"detectDrift");function g(r,e){if(r.length===0)return"clean";let n=!1,t=!1,a=!1,s=!1;for(const i of r)switch(i.verdict){case"conflict":n=!0;break;case"compatible":t=!0;break;case"clean":a=!0;break;case"no-op":s=!0;break}return n?"drifted-conflict":t?"drifted-compatible":s&&!a?"no-op":"clean"}c(g,"summariseDeltas");export{P as detectDrift};
@@ -1 +1 @@
1
- import{isDeepStrictEqual as v}from"node:util";function P(e,t,n){const o=[...new Set([...e===void 0?[]:Object.keys(e),...Object.keys(t),...Object.keys(n)])].sort((r,u)=>r.localeCompare(u,"en")),i={},d=[];for(const r of o){const u=e!==void 0&&g(e,r),l=g(t,r),m=g(n,r),k=u?e[r]:void 0,p=l?t[r]:void 0,s=m?n[r]:void 0,y=e===void 0?j(l,p,m,s):b(u,k,l,p,m,s);d.push({property:r,base:k,theirs:p,ours:s,verdict:y.verdict}),y.merged.has&&(i[r]=y.merged.value)}return{merged:i,deltas:d}}function j(e,t,n,c){return!e&&n?f(c):e&&!n||v(t,c)?f(t):a()}function b(e,t,n,c,o,i){if(!e&&!n&&o)return f(i);if(e&&!n&&o)return a();const d=e===n&&v(t,c);return d&&o?f(i):d&&!o?f(t):o?n===o&&v(c,i)?{verdict:"no-op",merged:{has:!0,value:c}}:a():n?{verdict:"compatible",merged:{has:!0,value:c}}:{verdict:"compatible",merged:{has:!1}}}function f(e){return{verdict:"clean",merged:{has:!0,value:e}}}function a(){return{verdict:"conflict",merged:{has:!1}}}function g(e,t){return Object.prototype.hasOwnProperty.call(e,t)}export{P as mergeProperties};
1
+ var b=Object.defineProperty;var i=(e,t)=>b(e,"name",{value:t,configurable:!0});import{isDeepStrictEqual as a}from"node:util";function q(e,t,n){const o=[...new Set([...e===void 0?[]:Object.keys(e),...Object.keys(t),...Object.keys(n)])].sort((r,l)=>r.localeCompare(l,"en")),f={},u=[];for(const r of o){const l=e!==void 0&&k(e,r),m=k(t,r),p=k(n,r),j=l?e[r]:void 0,s=m?t[r]:void 0,y=p?n[r]:void 0,v=e===void 0?w(m,s,p,y):P(l,j,m,s,p,y);u.push({property:r,base:j,theirs:s,ours:y,verdict:v.verdict}),v.merged.has&&(f[r]=v.merged.value)}return{merged:f,deltas:u}}i(q,"mergeProperties");function w(e,t,n,c){return!e&&n?d(c):e&&!n||a(t,c)?d(t):g()}i(w,"classifyWithoutBase");function P(e,t,n,c,o,f){if(!e&&!n&&o)return d(f);if(e&&!n&&o)return g();const u=e===n&&a(t,c);return u&&o?d(f):u&&!o?d(t):o?n===o&&a(c,f)?{verdict:"no-op",merged:{has:!0,value:c}}:g():n?{verdict:"compatible",merged:{has:!0,value:c}}:{verdict:"compatible",merged:{has:!1}}}i(P,"classifyWithBase");function d(e){return{verdict:"clean",merged:{has:!0,value:e}}}i(d,"clean");function g(){return{verdict:"conflict",merged:{has:!1}}}i(g,"conflict");function k(e,t){return Object.prototype.hasOwnProperty.call(e,t)}i(k,"hasOwn");export{q as mergeProperties};
@@ -1 +1 @@
1
- import{failure as a,success as y}from"../../types/Result.js";import{extractProgramBody as h,isRecord as p}from"../_internal.js";import{astToLiteral as g,isNodeShape as l,NON_LITERAL as k,readKeyName as b}from"../edits/modifyResource/literalConversion.js";import{parse as E}from"../fileRewriter/index.js";import{listResources as x}from"../listResources.js";import{STATEMENT_REGISTRY as N}from"../registry.js";function F(t,n,r){const e=x(t);if(!e.success)return a(e.error);const i=e.data.resources.find(o=>o.type===n&&o.name===r);if(i===void 0)return a({kind:"ResourceNotFoundError",type:n,name:r,knownNames:e.data.resources.filter(o=>o.type===n).map(o=>o.name)});const s=E(t,i.filePath);if(!s.success)return a(s.error);const c=h(s.data);if(c===void 0)return a({kind:"SemanticQueryError",reason:"recast File is missing program.body"});const f=O(c,i);if(f===void 0)return a({kind:"SemanticQueryError",reason:"Unable to resolve config ObjectExpression for the located resource."});const u=new Set(Object.keys(N[n].schemaFragment.shape)),m={};for(const o of f.properties){if(o.type!=="Property"&&o.type!=="ObjectProperty"||o.shorthand===!0||o.computed===!0)continue;const d=b(o.key);d===void 0||!u.has(d)||o.value!==void 0&&(m[d]=j(o.value,t))}return y({type:n,name:r,properties:m,schemaVersion:1})}function O(t,n){const r=n.start+n.length;let e;const i=s=>{if(e!==void 0||s.type!=="CallExpression")return;const c=s.arguments;if(!Array.isArray(c)||c.length<2)return;const f=c[0];if(!l(f)||f.type!=="StringLiteral"||f.start!==n.start||f.end!==r)return;const u=c[1];l(u)&&u.type==="ObjectExpression"&&(e=u)};for(const s of t)if(v(s,i),e!==void 0)break;return e}function j(t,n){const r=g(t);return r!==k?r:S(t,n)}function S(t,n){const r=typeof t.start=="number"?t.start:void 0,e=typeof t.end=="number"?t.end:void 0;return{kind:"expression",text:r!==void 0&&e!==void 0&&r<e?n.slice(r,e):""}}function v(t,n){const r=[t];for(;r.length>0;){const e=r.pop();if(p(e)){typeof e.type=="string"&&n(e);for(const i of Object.keys(e)){if(i==="loc"||i==="comments"||i==="tokens")continue;const s=e[i];if(Array.isArray(s))for(const c of s)p(c)&&r.push(c);else p(s)&&r.push(s)}}}}export{F as snapshotProperties};
1
+ var h=Object.defineProperty;var u=(r,t)=>h(r,"name",{value:t,configurable:!0});import{failure as d,success as g}from"../../types/Result.js";import{extractProgramBody as k,isRecord as m}from"../_internal.js";import{astToLiteral as b,isNodeShape as y,NON_LITERAL as E,readKeyName as x}from"../edits/modifyResource/literalConversion.js";import{parse as N}from"../fileRewriter/index.js";import{listResources as O}from"../listResources.js";import{STATEMENT_REGISTRY as j}from"../registry.js";function I(r,t,n){const e=O(r);if(!e.success)return d(e.error);const i=e.data.resources.find(o=>o.type===t&&o.name===n);if(i===void 0)return d({kind:"ResourceNotFoundError",type:t,name:n,knownNames:e.data.resources.filter(o=>o.type===t).map(o=>o.name)});const s=N(r,i.filePath);if(!s.success)return d(s.error);const c=k(s.data);if(c===void 0)return d({kind:"SemanticQueryError",reason:"recast File is missing program.body"});const f=S(c,i);if(f===void 0)return d({kind:"SemanticQueryError",reason:"Unable to resolve config ObjectExpression for the located resource."});const a=new Set(Object.keys(j[t].schemaFragment.shape)),l={};for(const o of f.properties){if(o.type!=="Property"&&o.type!=="ObjectProperty"||o.shorthand===!0||o.computed===!0)continue;const p=x(o.key);p===void 0||!a.has(p)||o.value!==void 0&&(l[p]=v(o.value,r))}return g({type:t,name:n,properties:l,schemaVersion:1})}u(I,"snapshotProperties");function S(r,t){const n=t.start+t.length;let e;const i=u(s=>{if(e!==void 0||s.type!=="CallExpression")return;const c=s.arguments;if(!Array.isArray(c)||c.length<2)return;const f=c[0];if(!y(f)||f.type!=="StringLiteral"||f.start!==t.start||f.end!==n)return;const a=c[1];y(a)&&a.type==="ObjectExpression"&&(e=a)},"visitor");for(const s of r)if(P(s,i),e!==void 0)break;return e}u(S,"findConfigObject");function v(r,t){const n=b(r);return n!==E?n:A(r,t)}u(v,"extractPropertyValue");function A(r,t){const n=typeof r.start=="number"?r.start:void 0,e=typeof r.end=="number"?r.end:void 0;return{kind:"expression",text:n!==void 0&&e!==void 0&&n<e?t.slice(n,e):""}}u(A,"toExpressionValue");function P(r,t){const n=[r];for(;n.length>0;){const e=n.pop();if(m(e)){typeof e.type=="string"&&t(e);for(const i of Object.keys(e)){if(i==="loc"||i==="comments"||i==="tokens")continue;const s=e[i];if(Array.isArray(s))for(const c of s)m(c)&&n.push(c);else m(s)&&n.push(s)}}}}u(P,"visit");export{I as snapshotProperties};
@@ -1 +1 @@
1
- import{isRecord as c}from"../../_internal.js";import{findTypeByIdentifier as a}from"../../registry.js";function x(n,r){const e=[],t=[],i=[];let o=r.length;for(let f=0;f<n.length;f+=1){const s=n[f];if(s===void 0)continue;const u=typeof s.start=="number"?s.start:0,p=typeof s.end=="number"?s.end:u;p>o&&(o=p);const d=l(s);e.push({index:f,start:u,end:p,type:d}),d==="import"?t.push({endPos:p}):(d==="app-init"||d==="tags")&&i.push({endPos:p,type:d})}return{anchors:e,importInfos:t,appInitLocations:i,programEnd:o}}function l(n){if(n.type==="ImportDeclaration")return"import";if(n.type!=="ExpressionStatement")return;const r=n.expression;if(!c(r)||r.type!=="CallExpression")return;const e=r.callee;if(!c(e)||e.type!=="MemberExpression")return;const t=e.object,i=e.property;if(!c(t)||t.type!=="Identifier"||!c(i)||i.type!=="Identifier"||i.name!=="build")return;const o=t.name;if(typeof o=="string")return o==="AppFactory"?"app-init":a(o)}function h(n,r){const e=[];for(const t of r){const i=n.find(o=>o.start<=t.start&&o.end>=t.start+t.length);i!==void 0&&e.push({endPos:i.end,type:t.type})}return e}function I(n){return[...n].sort((r,e)=>r.endPos-e.endPos)}function g(n,r){const e=n.find(t=>t.end===r);return e!==void 0?e.index+1:n.length}export{h as buildResourceLocations,x as indexBody,I as orderByEndPos,g as resolveInsertIndex};
1
+ var l=Object.defineProperty;var p=(e,t)=>l(e,"name",{value:t,configurable:!0});import{isRecord as u}from"../../_internal.js";import{findTypeByIdentifier as y}from"../../registry.js";function g(e,t){const n=[],r=[],i=[];let o=t.length;for(let c=0;c<e.length;c+=1){const s=e[c];if(s===void 0)continue;const a=typeof s.start=="number"?s.start:0,d=typeof s.end=="number"?s.end:a;d>o&&(o=d);const f=m(s);n.push({index:c,start:a,end:d,type:f}),f==="import"?r.push({endPos:d}):(f==="app-init"||f==="tags")&&i.push({endPos:d,type:f})}return{anchors:n,importInfos:r,appInitLocations:i,programEnd:o}}p(g,"indexBody");function m(e){if(e.type==="ImportDeclaration")return"import";if(e.type!=="ExpressionStatement")return;const t=e.expression;if(!u(t)||t.type!=="CallExpression")return;const n=t.callee;if(!u(n)||n.type!=="MemberExpression")return;const r=n.object,i=n.property;if(!u(r)||r.type!=="Identifier"||!u(i)||i.type!=="Identifier"||i.name!=="build")return;const o=r.name;if(typeof o=="string")return o==="AppFactory"?"app-init":y(o)}p(m,"classifyStatement");function b(e,t){const n=[];for(const r of t){const i=e.find(o=>o.start<=r.start&&o.end>=r.start+r.length);i!==void 0&&n.push({endPos:i.end,type:r.type})}return n}p(b,"buildResourceLocations");function P(e){return[...e].sort((t,n)=>t.endPos-n.endPos)}p(P,"orderByEndPos");function E(e,t){const n=e.find(r=>r.end===t);return n!==void 0?n.index+1:e.length}p(E,"resolveInsertIndex");export{b as buildResourceLocations,g as indexBody,P as orderByEndPos,E as resolveInsertIndex};
@@ -1 +1 @@
1
- import{builders as i}from"ast-types";import{failure as p,success as c}from"../../../types/Result.js";import{buildObjectProperty as u}from"../../fileRewriter/index.js";function m(r,n){const e=[];for(const[t,o]of Object.entries(r)){const s=f(o,n);if(s===void 0)return p({kind:"InvalidPropertyError",property:t,reason:`Unsupported property value for "${t}" (accepts string/number/boolean/null/array/object of the same).`});e.push({key:t,value:s})}return c(e)}function f(r,n){if(typeof r=="string")return a(r,n);if(typeof r=="number"&&Number.isFinite(r))return i.numericLiteral(r);if(typeof r=="boolean")return i.booleanLiteral(r);if(r===null)return i.nullLiteral();if(Array.isArray(r)){const e=[];for(const t of r){const o=f(t,n);if(o===void 0)return;e.push(o)}return i.arrayExpression(e)}if(typeof r=="object"&&r!==null){const e=[];for(const[t,o]of Object.entries(r)){const s=f(o,n);if(s===void 0)return;e.push(u(t,s,n))}return i.objectExpression(e)}}function a(r,n){const e=n==="single"?"'":'"',t=n==="single"?r.replace(/\\/g,"\\\\").replace(/'/g,"\\'"):r.replace(/\\/g,"\\\\").replace(/"/g,'\\"'),o=`${e}${t}${e}`;return i.stringLiteral.from({value:r,extra:{rawValue:r,raw:o}})}export{m as buildPropertyInputs,a as makeStringLiteral,f as toAstValue};
1
+ var c=Object.defineProperty;var f=(r,e)=>c(r,"name",{value:e,configurable:!0});import{builders as i}from"ast-types";import{failure as u,success as a}from"../../../types/Result.js";import{buildObjectProperty as d}from"../../fileRewriter/index.js";function j(r,e){const n=[];for(const[t,o]of Object.entries(r)){const s=p(o,e);if(s===void 0)return u({kind:"InvalidPropertyError",property:t,reason:`Unsupported property value for "${t}" (accepts string/number/boolean/null/array/object of the same).`});n.push({key:t,value:s})}return a(n)}f(j,"buildPropertyInputs");function p(r,e){if(typeof r=="string")return l(r,e);if(typeof r=="number"&&Number.isFinite(r))return i.numericLiteral(r);if(typeof r=="boolean")return i.booleanLiteral(r);if(r===null)return i.nullLiteral();if(Array.isArray(r)){const n=[];for(const t of r){const o=p(t,e);if(o===void 0)return;n.push(o)}return i.arrayExpression(n)}if(typeof r=="object"&&r!==null){const n=[];for(const[t,o]of Object.entries(r)){const s=p(o,e);if(s===void 0)return;n.push(d(t,s,e))}return i.objectExpression(n)}}f(p,"toAstValue");function l(r,e){const n=e==="single"?"'":'"',t=e==="single"?r.replace(/\\/g,"\\\\").replace(/'/g,"\\'"):r.replace(/\\/g,"\\\\").replace(/"/g,'\\"'),o=`${n}${t}${n}`;return i.stringLiteral.from({value:r,extra:{rawValue:r,raw:o}})}f(l,"makeStringLiteral");export{j as buildPropertyInputs,l as makeStringLiteral,p as toAstValue};
@@ -1 +1 @@
1
- import{failure as o,success as E}from"../../types/Result.js";import{DEFAULT_FILE_PATH as g,computeLinesDelta as T,extractProgramBody as F,isRecord as C}from"../_internal.js";import{appendSpecifier as D,buildFactoryStatement as b,buildImportDeclaration as x,detectQuoteStyle as w,parse as Q,printFile as v}from"../fileRewriter/index.js";import{STATEMENT_REGISTRY as A}from"../registry.js";import{locateAllShapes as _,locateByShape as B}from"../semanticIndex/index.js";import{checkControlFlowPolicy as G}from"./controlFlowPolicy.js";import{driftGate as N,runPipeline as O,schemaGate as U}from"../validationGate/index.js";import{buildResourceLocations as M,indexBody as Y,orderByEndPos as j,resolveInsertIndex as q}from"./addResource/bodyIndex.js";import{buildPropertyInputs as H}from"./addResource/propertyBuilder.js";import{findInsertionPosition as $}from"./findInsertionPosition.js";const S="@fjall/components-infrastructure";function nr(e,r,u={}){const i=r.filePath??g,a=Q(e,i);if(!a.success)return o(a.error);const t=B(e,{type:r.type,name:r.name},i);if(!t.success)return t.error.kind==="TemplateLiteralNameError"?o(t.error):o({kind:"SemanticQueryError",reason:t.error.reason,cause:t.error.cause});if(t.data!==void 0){const y=G({ast:a.data,target:t.data,resource:{type:r.type,name:r.name},op:"add"});if(y.refusal!==void 0)return o(y.refusal);const l=O([U,N],{content:e,plan:{type:r.type,name:r.name,properties:r.properties,op:"add"},baseline:u.baseline,policy:r.driftPolicy});return l.success?l.data.action==="skip"?E({content:e,linesChanged:{added:0,removed:0},skipped:!0}):o({kind:"DuplicateResourceError",type:r.type,name:r.name}):o(z(l.error))}const d=w(a.data),p=H(r.properties,d);if(!p.success)return o(p.error);const m=A[r.type].factoryIdentifier,I=b({factory:m,name:r.name,properties:p.data,quoteStyle:d}),c=F(a.data);if(c===void 0)return o({kind:"SemanticQueryError",reason:"recast File is missing program.body"});const s=Y(c,e),n=_(e,i);if(!n.success)return n.error.kind==="TemplateLiteralNameError"?o(n.error):o({kind:"SemanticQueryError",reason:n.error.reason,cause:n.error.cause});const h=M(s.anchors,n.data),k=j([...s.appInitLocations,...h]),L=$(s.importInfos,k,r.type,s.programEnd),P=q(s.anchors,L);c.splice(P,0,I),J(c,m,d);const f=v(a.data,e),R=T(e,f);return E({content:f,linesChanged:R})}function z(e){switch(e.kind){case"ParseError":case"TemplateLiteralNameError":case"DuplicateResourceError":case"InvalidPropertyError":case"SemanticQueryError":case"DriftConflictError":case"ControlFlowClassifierError":return e;default:return{kind:"SemanticQueryError",reason:`Unexpected codemod error in validation-gate pipeline: ${e.kind}`}}}function J(e,r,u){for(const a of e){if(a.type!=="ImportDeclaration")continue;const t=a.source;if(!(!C(t)||t.type!=="StringLiteral")&&t.value===S){D(a,r);return}}const i=x([r],S,u);e.unshift(i)}export{nr as addResource};
1
+ var T=Object.defineProperty;var u=(e,r)=>T(e,"name",{value:r,configurable:!0});import{failure as o,success as S}from"../../types/Result.js";import{DEFAULT_FILE_PATH as F,computeLinesDelta as C,extractProgramBody as D,isRecord as b}from"../_internal.js";import{appendSpecifier as x,buildFactoryStatement as w,buildImportDeclaration as Q,detectQuoteStyle as v,parse as A,printFile as _}from"../fileRewriter/index.js";import{STATEMENT_REGISTRY as B}from"../registry.js";import{locateAllShapes as G,locateByShape as N}from"../semanticIndex/index.js";import{checkControlFlowPolicy as O}from"./controlFlowPolicy.js";import{driftGate as U,runPipeline as M,schemaGate as Y}from"../validationGate/index.js";import{buildResourceLocations as j,indexBody as q,orderByEndPos as H,resolveInsertIndex as $}from"./addResource/bodyIndex.js";import{buildPropertyInputs as z}from"./addResource/propertyBuilder.js";import{findInsertionPosition as J}from"./findInsertionPosition.js";const I="@fjall/components-infrastructure";function cr(e,r,d={}){const i=r.filePath??F,a=A(e,i);if(!a.success)return o(a.error);const t=N(e,{type:r.type,name:r.name},i);if(!t.success)return t.error.kind==="TemplateLiteralNameError"?o(t.error):o({kind:"SemanticQueryError",reason:t.error.reason,cause:t.error.cause});if(t.data!==void 0){const E=O({ast:a.data,target:t.data,resource:{type:r.type,name:r.name},op:"add"});if(E.refusal!==void 0)return o(E.refusal);const m=M([Y,U],{content:e,plan:{type:r.type,name:r.name,properties:r.properties,op:"add"},baseline:d.baseline,policy:r.driftPolicy});return m.success?m.data.action==="skip"?S({content:e,linesChanged:{added:0,removed:0},skipped:!0}):o({kind:"DuplicateResourceError",type:r.type,name:r.name}):o(K(m.error))}const p=v(a.data),l=z(r.properties,p);if(!l.success)return o(l.error);const f=B[r.type].factoryIdentifier,h=w({factory:f,name:r.name,properties:l.data,quoteStyle:p}),c=D(a.data);if(c===void 0)return o({kind:"SemanticQueryError",reason:"recast File is missing program.body"});const s=q(c,e),n=G(e,i);if(!n.success)return n.error.kind==="TemplateLiteralNameError"?o(n.error):o({kind:"SemanticQueryError",reason:n.error.reason,cause:n.error.cause});const k=j(s.anchors,n.data),L=H([...s.appInitLocations,...k]),P=J(s.importInfos,L,r.type,s.programEnd),R=$(s.anchors,P);c.splice(R,0,h),V(c,f,p);const y=_(a.data,e),g=C(e,y);return S({content:y,linesChanged:g})}u(cr,"addResource");function K(e){switch(e.kind){case"ParseError":case"TemplateLiteralNameError":case"DuplicateResourceError":case"InvalidPropertyError":case"SemanticQueryError":case"DriftConflictError":case"ControlFlowClassifierError":return e;default:return{kind:"SemanticQueryError",reason:`Unexpected codemod error in validation-gate pipeline: ${e.kind}`}}}u(K,"narrowGateError");function V(e,r,d){for(const a of e){if(a.type!=="ImportDeclaration")continue;const t=a.source;if(!(!b(t)||t.type!=="StringLiteral")&&t.value===I){x(a,r);return}}const i=Q([r],I,d);e.unshift(i)}u(V,"ensureFactoryImport");export{cr as addResource};
@@ -1 +1 @@
1
- import{failure as u,success as p}from"../../types/Result.js";import{DEFAULT_FILE_PATH as P,computeLinesDelta as T,extractProgramBody as x}from"../_internal.js";import{buildObjectProperty as k,detectQuoteStyle as b,parse as h,printFile as D}from"../fileRewriter/index.js";import{makeStringLiteral as C,toAstValue as F}from"./addResource/propertyBuilder.js";import{astToLiteral as L,isNodeShape as c,readKeyName as m}from"./modifyResource/literalConversion.js";const w="ACCOUNTS",I="workloads";function Y(e,r){const n=r.filePath??P,t=r.constName??w,a=r.nestedKey??I,{stage:i,displayName:o}=r,s=h(e,n);if(!s.success)return u(s.error);const f=x(s.data);if(f===void 0)return u({kind:"InvalidStageTargetError",stage:i,reason:"recast File is missing program.body"});const y=V(f,t);if(y===void 0)return u({kind:"ConstNotFoundError",constName:t});const l=b(s.data),d=K(y,{constName:t,stage:i,nestedKey:a,displayName:o,quoteStyle:l});if(!d.success)return u(d.error);if(d.data.created)return N(s.data,e);const A=d.data.array;return A.elements.some(v=>c(v)&&L(v)===o)?p({content:e,linesChanged:{added:0,removed:0},skipped:!0}):(A.elements.push(C(o,l)),N(s.data,e))}function N(e,r){const n=D(e,r);return p({content:n,linesChanged:T(r,n)})}function K(e,r){const{constName:n,stage:t,nestedKey:a,displayName:i,quoteStyle:o}=r,s=g(e,t);if(s!==void 0)return S(s.value)?p({created:!1,array:s.value}):u({kind:"InvalidStageTargetError",stage:t,reason:`Top-level "${t}" is not an array literal.`});const f=g(e,a);if(f!==void 0&&E(f.value)){const y=f.value,l=g(y,t);if(l!==void 0)return S(l.value)?p({created:!1,array:l.value}):u({kind:"InvalidStageTargetError",stage:t,reason:`Nested "${a}.${t}" is not an array literal.`});const d=O(y,t,i,o);return d.success?p({created:!0}):u(d.error)}return u({kind:"StageNotFoundError",constName:n,stage:t,knownStages:U(e,a)})}function O(e,r,n,t){const a=F([n],t);if(a===void 0)return u({kind:"InvalidStageTargetError",stage:r,reason:`Unable to build an array literal for "${r}".`});const i=k(r,a,t);return e.properties[e.properties.length-1]?.extra?.trailingComma===!0&&(i.extra={...i.extra??{},trailingComma:!0}),e.properties.push(i),p(void 0)}function V(e,r){for(const n of e){const t=_(n);if(t===void 0)continue;const a=t.declarations;if(Array.isArray(a))for(const i of a){if(!c(i)||i.type!=="VariableDeclarator")continue;const o=i.id,s=$(i.init);if(c(o)&&o.type==="Identifier"&&o.name===r&&E(s))return s}}}function _(e){if(e.type==="VariableDeclaration")return e;if(e.type==="ExportNamedDeclaration"){const r=e.declaration;if(c(r)&&r.type==="VariableDeclaration")return r}}function $(e){let r=e;for(;c(r)&&(r.type==="TSAsExpression"||r.type==="TSSatisfiesExpression");)r=r.expression;return r}function g(e,r){return e.properties.find(n=>(n.type==="Property"||n.type==="ObjectProperty")&&n.shorthand!==!0&&n.computed!==!0&&m(n.key)===r)}function U(e,r){const n=[];for(const t of e.properties){if(t.type!=="Property"&&t.type!=="ObjectProperty")continue;const a=m(t.key);if(a!==void 0)if(a===r&&E(t.value))for(const i of t.value.properties){const o=m(i.key);o!==void 0&&n.push(`${r}.${o}`)}else S(t.value)&&n.push(a)}return n}function E(e){return c(e)&&e.type==="ObjectExpression"&&Array.isArray(e.properties)}function S(e){return c(e)&&e.type==="ArrayExpression"&&Array.isArray(e.elements)}export{Y as appendAccountToStage};
1
+ var T=Object.defineProperty;var u=(e,r)=>T(e,"name",{value:r,configurable:!0});import{failure as d,success as y}from"../../types/Result.js";import{DEFAULT_FILE_PATH as x,computeLinesDelta as k,extractProgramBody as b}from"../_internal.js";import{buildObjectProperty as h,detectQuoteStyle as D,parse as C,printFile as F}from"../fileRewriter/index.js";import{makeStringLiteral as L,toAstValue as w}from"./addResource/propertyBuilder.js";import{astToLiteral as I,isNodeShape as f,readKeyName as g}from"./modifyResource/literalConversion.js";const K="ACCOUNTS",O="workloads";function J(e,r){const n=r.filePath??x,t=r.constName??K,a=r.nestedKey??O,{stage:i,displayName:o}=r,s=C(e,n);if(!s.success)return d(s.error);const l=b(s.data);if(l===void 0)return d({kind:"InvalidStageTargetError",stage:i,reason:"recast File is missing program.body"});const m=$(l,t);if(m===void 0)return d({kind:"ConstNotFoundError",constName:t});const p=D(s.data),c=V(m,{constName:t,stage:i,nestedKey:a,displayName:o,quoteStyle:p});if(!c.success)return d(c.error);if(c.data.created)return P(s.data,e);const v=c.data.array;return v.elements.some(N=>f(N)&&I(N)===o)?y({content:e,linesChanged:{added:0,removed:0},skipped:!0}):(v.elements.push(L(o,p)),P(s.data,e))}u(J,"appendAccountToStage");function P(e,r){const n=F(e,r);return y({content:n,linesChanged:k(r,n)})}u(P,"printSuccess");function V(e,r){const{constName:n,stage:t,nestedKey:a,displayName:i,quoteStyle:o}=r,s=E(e,t);if(s!==void 0)return A(s.value)?y({created:!1,array:s.value}):d({kind:"InvalidStageTargetError",stage:t,reason:`Top-level "${t}" is not an array literal.`});const l=E(e,a);if(l!==void 0&&S(l.value)){const m=l.value,p=E(m,t);if(p!==void 0)return A(p.value)?y({created:!1,array:p.value}):d({kind:"InvalidStageTargetError",stage:t,reason:`Nested "${a}.${t}" is not an array literal.`});const c=_(m,t,i,o);return c.success?y({created:!0}):d(c.error)}return d({kind:"StageNotFoundError",constName:n,stage:t,knownStages:B(e,a)})}u(V,"resolveStageArray");function _(e,r,n,t){const a=w([n],t);if(a===void 0)return d({kind:"InvalidStageTargetError",stage:r,reason:`Unable to build an array literal for "${r}".`});const i=h(r,a,t);return e.properties[e.properties.length-1]?.extra?.trailingComma===!0&&(i.extra={...i.extra??{},trailingComma:!0}),e.properties.push(i),y(void 0)}u(_,"appendStageProperty");function $(e,r){for(const n of e){const t=U(n);if(t===void 0)continue;const a=t.declarations;if(Array.isArray(a))for(const i of a){if(!f(i)||i.type!=="VariableDeclarator")continue;const o=i.id,s=j(i.init);if(f(o)&&o.type==="Identifier"&&o.name===r&&S(s))return s}}}u($,"findConstObjectExpression");function U(e){if(e.type==="VariableDeclaration")return e;if(e.type==="ExportNamedDeclaration"){const r=e.declaration;if(f(r)&&r.type==="VariableDeclaration")return r}}u(U,"unwrapVariableDeclaration");function j(e){let r=e;for(;f(r)&&(r.type==="TSAsExpression"||r.type==="TSSatisfiesExpression");)r=r.expression;return r}u(j,"unwrapExpression");function E(e,r){return e.properties.find(n=>(n.type==="Property"||n.type==="ObjectProperty")&&n.shorthand!==!0&&n.computed!==!0&&g(n.key)===r)}u(E,"findPropertyByKey");function B(e,r){const n=[];for(const t of e.properties){if(t.type!=="Property"&&t.type!=="ObjectProperty")continue;const a=g(t.key);if(a!==void 0)if(a===r&&S(t.value))for(const i of t.value.properties){const o=g(i.key);o!==void 0&&n.push(`${r}.${o}`)}else A(t.value)&&n.push(a)}return n}u(B,"collectStageKeys");function S(e){return f(e)&&e.type==="ObjectExpression"&&Array.isArray(e.properties)}u(S,"isObjectExpression");function A(e){return f(e)&&e.type==="ArrayExpression"&&Array.isArray(e.elements)}u(A,"isArrayExpression");export{J as appendAccountToStage};
@@ -1 +1 @@
1
- import{isRecord as y}from"../_internal.js";const h=new Set(["loc","tokens","comments","original","range"]),p=new Set(["ForStatement","ForInStatement","ForOfStatement","WhileStatement","DoWhileStatement"]),m={"try-catch":"Move the resource declaration outside the try block.","switch-fall-through":"Add a break statement or convert to if/else.","nested-ternary":"Convert nested ternaries to if/else.",loop:"Extract the resource declaration before the loop.","generator-function":"Extract the resource declaration outside the generator.","async-iterator":"Extract the resource declaration outside the async iterator.","anonymous-helper":"Extract the resource to module scope.","decorator-return":"Extract the resource declaration outside the decorated function."};function g(e,r){if(!c(e))return;const n=[{node:e,ancestors:[]}];for(;n.length>0;){const s=n.pop();if(s===void 0)continue;const{node:o,ancestors:a}=s;if(o.type==="StringLiteral"&&typeof o.start=="number"&&o.start===r)return{node:o,ancestors:a};const t=[...a,o];for(const u of Object.keys(o)){if(h.has(u))continue;const f=o[u];if(Array.isArray(f))for(let d=f.length-1;d>=0;d-=1){const l=f[d];c(l)&&n.push({node:l,ancestors:t})}else c(f)&&n.push({node:f,ancestors:t})}}}function c(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"}function i(e,r,n){return{kind:"ControlFlowClassifierError",reason:e,resource:r,location:S(n),remediation:m[e]}}function S(e){const r=e.loc;if(r?.start!==void 0&&typeof r.start.line=="number"&&typeof r.start.column=="number")return{line:r.start.line,column:r.start.column}}function F(e,r){const n=e.finalizer;return n!==void 0&&n===r}function E(e,r){const n=e.handler;return n!==void 0&&n===r}function b(e){const r=e.consequent;if(!Array.isArray(r)||r.length===0)return!0;const n=r[r.length-1];return c(n)?n.type!=="BreakStatement"&&n.type!=="ReturnStatement":!0}function k(e){const r=A(e.ast);if(r===void 0)return{};const n=g(r,e.target.start);if(n===void 0)return{};const{ancestors:s}=n;let o=n.node;for(let a=s.length-1;a>=0;a-=1){const t=s[a];if(t!==void 0){if(p.has(t.type))return{refusal:i("loop",e.resource,t)};if(t.type==="TryStatement"){if(E(t,o)||F(t,o))return{refusal:i("try-catch",e.resource,t)};o=t;continue}if(t.type==="CatchClause")return{refusal:i("try-catch",e.resource,t)};if(t.type==="SwitchCase"&&b(t))return{refusal:i("switch-fall-through",e.resource,t)};if(t.type==="ConditionalExpression"){const u=a-1;if((u>=0?s[u]:void 0)?.type==="ConditionalExpression")return{refusal:i("nested-ternary",e.resource,t)};if(e.op==="modify")return{warning:{message:`Modified property on resource "${e.resource.name}" declared in a ternary expression \u2014 consider converting to if/else.`}};if(e.op==="add"||e.op==="remove")return{refusal:i("nested-ternary",e.resource,t)}}if(t.type==="FunctionDeclaration"||t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="ObjectMethod"||t.type==="ClassMethod")return t.generator===!0?{refusal:i("generator-function",e.resource,t)}:t.async===!0&&w(t)?{refusal:i("async-iterator",e.resource,t)}:x(t)===void 0?{refusal:i("anonymous-helper",e.resource,t)}:{refusal:i("anonymous-helper",e.resource,t)};o=t}}return{}}function x(e){if(e.type==="FunctionDeclaration"){const r=e.id;if(c(r)&&typeof r.name=="string")return r.name}}function w(e){if(e.type!=="FunctionDeclaration"&&e.type!=="FunctionExpression")return!1;const r=e.body;if(!c(r)||r.type!=="BlockStatement")return!1;const n=r.body;return Array.isArray(n)?n.some(s=>c(s)&&s.type==="ForOfStatement"&&s.await===!0):!1}function A(e){if(!y(e))return;const r=e.program;if(y(r)&&typeof r.type=="string")return e}export{k as checkControlFlowPolicy};
1
+ var p=Object.defineProperty;var s=(e,t)=>p(e,"name",{value:t,configurable:!0});import{isRecord as h}from"../_internal.js";const m=new Set(["loc","tokens","comments","original","range"]),g=new Set(["ForStatement","ForInStatement","ForOfStatement","WhileStatement","DoWhileStatement"]),S={"try-catch":"Move the resource declaration outside the try block.","switch-fall-through":"Add a break statement or convert to if/else.","nested-ternary":"Convert nested ternaries to if/else.",loop:"Extract the resource declaration before the loop.","generator-function":"Extract the resource declaration outside the generator.","async-iterator":"Extract the resource declaration outside the async iterator.","anonymous-helper":"Extract the resource to module scope.","decorator-return":"Extract the resource declaration outside the decorated function."};function F(e,t){if(!u(e))return;const n=[{node:e,ancestors:[]}];for(;n.length>0;){const i=n.pop();if(i===void 0)continue;const{node:o,ancestors:c}=i;if(o.type==="StringLiteral"&&typeof o.start=="number"&&o.start===t)return{node:o,ancestors:c};const r=[...c,o];for(const f of Object.keys(o)){if(m.has(f))continue;const d=o[f];if(Array.isArray(d))for(let l=d.length-1;l>=0;l-=1){const y=d[l];u(y)&&n.push({node:y,ancestors:r})}else u(d)&&n.push({node:d,ancestors:r})}}}s(F,"findNodeAtOffset");function u(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"}s(u,"isAstNode");function a(e,t,n){return{kind:"ControlFlowClassifierError",reason:e,resource:t,location:E(n),remediation:S[e]}}s(a,"buildRefusal");function E(e){const t=e.loc;if(t?.start!==void 0&&typeof t.start.line=="number"&&typeof t.start.column=="number")return{line:t.start.line,column:t.start.column}}s(E,"resolveLocation");function b(e,t){const n=e.finalizer;return n!==void 0&&n===t}s(b,"cameFromFinaliser");function x(e,t){const n=e.handler;return n!==void 0&&n===t}s(x,"cameFromHandler");function w(e){const t=e.consequent;if(!Array.isArray(t)||t.length===0)return!0;const n=t[t.length-1];return u(n)?n.type!=="BreakStatement"&&n.type!=="ReturnStatement":!0}s(w,"isSwitchFallThrough");function I(e){const t=k(e.ast);if(t===void 0)return{};const n=F(t,e.target.start);if(n===void 0)return{};const{ancestors:i}=n;let o=n.node;for(let c=i.length-1;c>=0;c-=1){const r=i[c];if(r!==void 0){if(g.has(r.type))return{refusal:a("loop",e.resource,r)};if(r.type==="TryStatement"){if(x(r,o)||b(r,o))return{refusal:a("try-catch",e.resource,r)};o=r;continue}if(r.type==="CatchClause")return{refusal:a("try-catch",e.resource,r)};if(r.type==="SwitchCase"&&w(r))return{refusal:a("switch-fall-through",e.resource,r)};if(r.type==="ConditionalExpression"){const f=c-1;if((f>=0?i[f]:void 0)?.type==="ConditionalExpression")return{refusal:a("nested-ternary",e.resource,r)};if(e.op==="modify")return{warning:{message:`Modified property on resource "${e.resource.name}" declared in a ternary expression \u2014 consider converting to if/else.`}};if(e.op==="add"||e.op==="remove")return{refusal:a("nested-ternary",e.resource,r)}}if(r.type==="FunctionDeclaration"||r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression"||r.type==="ObjectMethod"||r.type==="ClassMethod")return r.generator===!0?{refusal:a("generator-function",e.resource,r)}:r.async===!0&&C(r)?{refusal:a("async-iterator",e.resource,r)}:A(r)===void 0?{refusal:a("anonymous-helper",e.resource,r)}:{refusal:a("anonymous-helper",e.resource,r)};o=r}}return{}}s(I,"checkControlFlowPolicy");function A(e){if(e.type==="FunctionDeclaration"){const t=e.id;if(u(t)&&typeof t.name=="string")return t.name}}s(A,"resolveFunctionName");function C(e){if(e.type!=="FunctionDeclaration"&&e.type!=="FunctionExpression")return!1;const t=e.body;if(!u(t)||t.type!=="BlockStatement")return!1;const n=t.body;return Array.isArray(n)?n.some(i=>u(i)&&i.type==="ForOfStatement"&&i.await===!0):!1}s(C,"isIteratorShape");function k(e){if(!h(e))return;const t=e.program;if(h(t)&&typeof t.type=="string")return e}s(k,"extractBody");export{I as checkControlFlowPolicy};
@@ -1 +1 @@
1
- import{failure as i,success as d}from"../../types/Result.js";import{addResource as u}from"./addResource.js";import{modifyResource as f}from"./modifyResource.js";import{removeResource as l}from"./removeResource.js";function y(e,n){const{name:t,filePath:o,...s}=n,a={...s},r=u(e,{type:"cross-plan-connection",name:t,properties:a,...o!==void 0?{filePath:o}:{}});if(!r.success)return i(r.error);const c=m(n);return d({content:r.data.content,linesChanged:r.data.linesChanged,...c.length>0?{warnings:c}:{}})}function R(e,n){const t=l(e,{type:"cross-plan-connection",name:n.name,...n.filePath!==void 0?{filePath:n.filePath}:{},...n.force!==void 0?{force:n.force}:{}});return t.success?d({content:t.data.content,linesChanged:t.data.linesChanged}):i(t.error)}function A(e,n){const{name:t,filePath:o,...s}=n,a={...s},r=f(e,{type:"cross-plan-connection",name:t,properties:a,...o!==void 0?{filePath:o}:{}});if(!r.success)return i(r.error);const c=p(s);return d({content:r.data.content,linesChanged:r.data.linesChanged,...c.length>0?{warnings:c}:{}})}function m(e){return[`Cross-plan connection to "${e.remoteApp}/${e.remoteResource}" requires an accepter role granting ${e.permission} access on the remote plan.`]}function p(e){return e.remoteApp===void 0&&e.remoteResource===void 0&&e.permission===void 0?[]:["Updating remoteApp, remoteResource, or permission may require a corresponding change to the accepter role on the remote plan."]}export{y as addCrossPlanConnection,A as modifyCrossPlanConnection,R as removeCrossPlanConnection};
1
+ var f=Object.defineProperty;var o=(e,n)=>f(e,"name",{value:n,configurable:!0});import{failure as d,success as u}from"../../types/Result.js";import{addResource as l}from"./addResource.js";import{modifyResource as m}from"./modifyResource.js";import{removeResource as p}from"./removeResource.js";function x(e,n){const{name:t,filePath:c,...a}=n,i={...a},r=l(e,{type:"cross-plan-connection",name:t,properties:i,...c!==void 0?{filePath:c}:{}});if(!r.success)return d(r.error);const s=g(n);return u({content:r.data.content,linesChanged:r.data.linesChanged,...s.length>0?{warnings:s}:{}})}o(x,"addCrossPlanConnection");function $(e,n){const t=p(e,{type:"cross-plan-connection",name:n.name,...n.filePath!==void 0?{filePath:n.filePath}:{},...n.force!==void 0?{force:n.force}:{}});return t.success?u({content:t.data.content,linesChanged:t.data.linesChanged}):d(t.error)}o($,"removeCrossPlanConnection");function b(e,n){const{name:t,filePath:c,...a}=n,i={...a},r=m(e,{type:"cross-plan-connection",name:t,properties:i,...c!==void 0?{filePath:c}:{}});if(!r.success)return d(r.error);const s=h(a);return u({content:r.data.content,linesChanged:r.data.linesChanged,...s.length>0?{warnings:s}:{}})}o(b,"modifyCrossPlanConnection");function g(e){return[`Cross-plan connection to "${e.remoteApp}/${e.remoteResource}" requires an accepter role granting ${e.permission} access on the remote plan.`]}o(g,"buildAddWarnings");function h(e){return e.remoteApp===void 0&&e.remoteResource===void 0&&e.permission===void 0?[]:["Updating remoteApp, remoteResource, or permission may require a corresponding change to the accepter role on the remote plan."]}o(h,"buildModifyWarnings");export{x as addCrossPlanConnection,b as modifyCrossPlanConnection,$ as removeCrossPlanConnection};
@@ -1 +1 @@
1
- function t(e,o,n){const r=e.summary;return r==="clean"?{action:"proceed",driftState:e}:r==="no-op"?{action:"skip",driftState:e}:n?.force===!0?{action:"proceed",driftState:e}:r==="drifted-compatible"?{action:"proceed",driftState:e}:r==="drifted-conflict"?i(e,n)?{action:"proceed",driftState:e}:{action:"reject",driftState:e}:o==="add"?{action:"proceed",driftState:e}:{action:"reject",driftState:e}}function i(e,o){const n=o?.resolutionMap;if(n===void 0)return!1;const r=e.deltas.filter(c=>c.verdict==="conflict");return r.length===0?!1:r.every(c=>Object.prototype.hasOwnProperty.call(n,c.property))}export{t as resolveDriftPolicy};
1
+ var t=Object.defineProperty;var i=(e,n)=>t(e,"name",{value:n,configurable:!0});function l(e,n,o){const r=e.summary;return r==="clean"?{action:"proceed",driftState:e}:r==="no-op"?{action:"skip",driftState:e}:o?.force===!0?{action:"proceed",driftState:e}:r==="drifted-compatible"?{action:"proceed",driftState:e}:r==="drifted-conflict"?u(e,o)?{action:"proceed",driftState:e}:{action:"reject",driftState:e}:n==="add"?{action:"proceed",driftState:e}:{action:"reject",driftState:e}}i(l,"resolveDriftPolicy");function u(e,n){const o=n?.resolutionMap;if(o===void 0)return!1;const r=e.deltas.filter(c=>c.verdict==="conflict");return r.length===0?!1:r.every(c=>Object.prototype.hasOwnProperty.call(o,c.property))}i(u,"isResolvedByMap");export{l as resolveDriftPolicy};
@@ -1 +1 @@
1
- import{failure as m,success as f}from"../../types/Result.js";import{extractProgramBody as l,isRecord as d}from"../_internal.js";import{appendSpecifier as y,buildImportDeclaration as I,detectQuoteStyle as g}from"../fileRewriter/index.js";function L(t,r){const e=l(t);if(e===void 0)return m({kind:"SemanticQueryError",reason:"recast File is missing program.body"});if(r.length===0)return f({mutated:!1});const n=g(t);let o=!1;for(const i of r){const s=S(e,i.module);if(s!==void 0){for(const p of i.specifiers){const a=c(s);y(s,p),c(s)>a&&(o=!0)}continue}if(i.specifiers.length===0)continue;const u=I(i.specifiers,i.module,n);x(e,u),o=!0}return f({mutated:o})}function S(t,r){for(const e of t){if(e.type!=="ImportDeclaration")continue;const n=e.source;if(d(n)&&!(n.type!=="StringLiteral"&&n.type!=="Literal")&&n.value===r)return e}}function x(t,r){let e=-1;for(let o=0;o<t.length;o+=1){const i=t[o];i!==void 0&&i.type==="ImportDeclaration"&&(e=o)}const n=e===-1?0:e+1;t.splice(n,0,r)}function c(t){if(!Array.isArray(t.specifiers))return 0;let r=0;for(const e of t.specifiers)e!==null&&typeof e=="object"&&"type"in e&&e.type==="ImportSpecifier"&&(r+=1);return r}export{L as ensureImports};
1
+ var l=Object.defineProperty;var s=(t,r)=>l(t,"name",{value:r,configurable:!0});import{failure as d,success as c}from"../../types/Result.js";import{extractProgramBody as y,isRecord as I}from"../_internal.js";import{appendSpecifier as g,buildImportDeclaration as S,detectQuoteStyle as x}from"../fileRewriter/index.js";function k(t,r){const e=y(t);if(e===void 0)return d({kind:"SemanticQueryError",reason:"recast File is missing program.body"});if(r.length===0)return c({mutated:!1});const n=x(t);let o=!1;for(const i of r){const f=A(e,i.module);if(f!==void 0){for(const a of i.specifiers){const m=u(f);g(f,a),u(f)>m&&(o=!0)}continue}if(i.specifiers.length===0)continue;const p=S(i.specifiers,i.module,n);D(e,p),o=!0}return c({mutated:o})}s(k,"ensureImports");function A(t,r){for(const e of t){if(e.type!=="ImportDeclaration")continue;const n=e.source;if(I(n)&&!(n.type!=="StringLiteral"&&n.type!=="Literal")&&n.value===r)return e}}s(A,"findImportDeclaration");function D(t,r){let e=-1;for(let o=0;o<t.length;o+=1){const i=t[o];i!==void 0&&i.type==="ImportDeclaration"&&(e=o)}const n=e===-1?0:e+1;t.splice(n,0,r)}s(D,"insertAfterLastImport");function u(t){if(!Array.isArray(t.specifiers))return 0;let r=0;for(const e of t.specifiers)e!==null&&typeof e=="object"&&"type"in e&&e.type==="ImportSpecifier"&&(r+=1);return r}s(u,"countImportedNames");export{k as ensureImports};
@@ -1 +1 @@
1
- const e={import:0,"app-init":1,tags:2,organisation:3,database:4,storage:5,messaging:6,compute:7,network:8,"vpc-peer":9,"vpc-peer-accepter":10,"cross-plan-connection":11,cdn:12,pattern:13};function p(r,s,i,a){const o=e[i];let n;const c=e.import;for(const t of r)c<=o&&(n=t.endPos);for(const t of s)e[t.type]<=o&&(n=t.endPos);return n??a}export{p as findInsertionPosition};
1
+ var d=Object.defineProperty;var i=(n,e)=>d(n,"name",{value:e,configurable:!0});const r={import:0,"app-init":1,tags:2,organisation:3,database:4,storage:5,messaging:6,compute:7,network:8,"vpc-peer":9,"vpc-peer-accepter":10,"cross-plan-connection":11,cdn:12,pattern:13};function g(n,e,a,c){const s=r[a];let o;const p=r.import;for(const t of n)p<=s&&(o=t.endPos);for(const t of e)r[t.type]<=s&&(o=t.endPos);return o??c}i(g,"findInsertionPosition");export{g as findInsertionPosition};
@@ -1 +1 @@
1
- const n=Symbol("non-literal");function y(e,r){const o={};for(const t of e.properties){if(t.type!=="Property"&&t.type!=="ObjectProperty"||t.shorthand===!0||t.computed===!0)continue;const i=f(t.key);if(i===void 0||t.value===void 0)continue;const u=a(t.value);u!==n&&(o[i]=u)}return{...o,...r}}function a(e){const r=e.value;switch(e.type){case"StringLiteral":return typeof r=="string"?r:n;case"NumericLiteral":return typeof r=="number"?r:n;case"BooleanLiteral":return typeof r=="boolean"?r:n;case"NullLiteral":return null;case"ArrayExpression":return p(e);case"ObjectExpression":return l(e);default:return n}}function p(e){const r=e.elements;if(!Array.isArray(r))return n;const o=[];for(const t of r){if(!c(t))return n;const i=a(t);if(i===n)return n;o.push(i)}return o}function l(e){const r=e.properties;if(!Array.isArray(r))return n;const o={};for(const t of r){if(!c(t)||t.type!=="Property"&&t.type!=="ObjectProperty")return n;const i=f(t.key),u=t.value;if(i===void 0||u===void 0)return n;const s=a(u);if(s===n)return n;o[i]=s}return o}function f(e){if(e===void 0)return;const r=e;if(e.type==="Identifier"&&typeof r.name=="string")return r.name;if(e.type==="StringLiteral"&&typeof r.value=="string")return r.value}function c(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}export{n as NON_LITERAL,a as astToLiteral,y as buildMergedLiteral,c as isNodeShape,f as readKeyName};
1
+ var l=Object.defineProperty;var u=(e,r)=>l(e,"name",{value:r,configurable:!0});const n=Symbol("non-literal");function L(e,r){const o={};for(const t of e.properties){if(t.type!=="Property"&&t.type!=="ObjectProperty"||t.shorthand===!0||t.computed===!0)continue;const i=c(t.key);if(i===void 0||t.value===void 0)continue;const a=s(t.value);a!==n&&(o[i]=a)}return{...o,...r}}u(L,"buildMergedLiteral");function s(e){const r=e.value;switch(e.type){case"StringLiteral":return typeof r=="string"?r:n;case"NumericLiteral":return typeof r=="number"?r:n;case"BooleanLiteral":return typeof r=="boolean"?r:n;case"NullLiteral":return null;case"ArrayExpression":return y(e);case"ObjectExpression":return d(e);default:return n}}u(s,"astToLiteral");function y(e){const r=e.elements;if(!Array.isArray(r))return n;const o=[];for(const t of r){if(!p(t))return n;const i=s(t);if(i===n)return n;o.push(i)}return o}u(y,"arrayToLiteral");function d(e){const r=e.properties;if(!Array.isArray(r))return n;const o={};for(const t of r){if(!p(t)||t.type!=="Property"&&t.type!=="ObjectProperty")return n;const i=c(t.key),a=t.value;if(i===void 0||a===void 0)return n;const f=s(a);if(f===n)return n;o[i]=f}return o}u(d,"objectToLiteral");function c(e){if(e===void 0)return;const r=e;if(e.type==="Identifier"&&typeof r.name=="string")return r.name;if(e.type==="StringLiteral"&&typeof r.value=="string")return r.value}u(c,"readKeyName");function p(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}u(p,"isNodeShape");export{n as NON_LITERAL,s as astToLiteral,L as buildMergedLiteral,p as isNodeShape,c as readKeyName};
@@ -1 +1 @@
1
- import{failure as c,success as l}from"../../types/Result.js";import{DEFAULT_FILE_PATH as P,computeLinesDelta as S,extractProgramBody as v,isRecord as p}from"../_internal.js";import{buildObjectProperty as w,detectQuoteStyle as C,parse as N,printFile as x}from"../fileRewriter/index.js";import{STATEMENT_REGISTRY as T}from"../registry.js";import{locateAllShapes as A,locateByShape as F}from"../semanticIndex/index.js";import{checkControlFlowPolicy as R}from"./controlFlowPolicy.js";import{driftGate as L,runPipeline as j,schemaGate as O}from"../validationGate/index.js";import{toAstValue as Q}from"./addResource/propertyBuilder.js";import{buildMergedLiteral as I,isNodeShape as h,readKeyName as G}from"./modifyResource/literalConversion.js";function ee(r,e,a={}){const i=e.filePath??P,t=N(r,i);if(!t.success)return c(t.error);const n=F(r,{type:e.type,name:e.name},i);if(!n.success)return n.error.kind==="TemplateLiteralNameError"?c(n.error):c({kind:"SemanticQueryError",reason:n.error.reason,cause:n.error.cause});if(n.data===void 0)return c({kind:"ResourceNotFoundError",type:e.type,name:e.name,knownNames:M(r,e.type,i)});const o=R({ast:t.data,target:n.data,resource:{type:e.type,name:e.name},op:"modify"});if(o.refusal!==void 0)return c(o.refusal);const s=j([O,L],{content:r,plan:{type:e.type,name:e.name,properties:e.properties,op:"modify"},baseline:a.baseline,policy:e.driftPolicy});if(!s.success)return c(U(s.error));if(s.data.action==="skip")return l({content:r,linesChanged:{added:0,removed:0},skipped:!0});const u=v(t.data);if(u===void 0)return c({kind:"SemanticQueryError",reason:"recast File is missing program.body"});const f=B(u,n.data);if(f===void 0)return c({kind:"SemanticQueryError",reason:"Unable to resolve config ObjectExpression for the located resource."});const E=C(t.data),k=I(f,e.properties),m=T[e.type].schemaFragment.safeParse(k);if(!m.success){const d=m.error.issues[0];return c({kind:"InvalidPropertyError",property:d!==void 0&&d.path.length>0?String(d.path[0]):Object.keys(e.properties)[0]??"<unknown>",reason:d?.message??"Schema validation failed"})}const y=D(f,e.properties,E);if(!y.success)return c(y.error);const g=x(t.data,r),b=o.warning!==void 0?[o.warning.message]:void 0;return l({content:g,linesChanged:S(r,g),warnings:b})}function U(r){switch(r.kind){case"ParseError":case"ResourceNotFoundError":case"InvalidPropertyError":case"TemplateLiteralNameError":case"SemanticQueryError":case"DriftConflictError":case"ControlFlowClassifierError":return r;default:return{kind:"SemanticQueryError",reason:`Unexpected codemod error in validation-gate pipeline: ${r.kind}`}}}function B(r,e){const a=e.start+e.length;let i;const t=n=>{if(i!==void 0||n.type!=="CallExpression")return;const o=n.arguments;if(!Array.isArray(o)||o.length<2)return;const s=o[0];if(!h(s)||s.type!=="StringLiteral"||s.start!==e.start||s.end!==a)return;const u=o[1];h(u)&&u.type==="ObjectExpression"&&(i=u)};for(const n of r)if(V(n,t),i!==void 0)break;return i}function D(r,e,a){const i=_(r);for(const[t,n]of Object.entries(e)){const o=Q(n,a);if(o===void 0)return c({kind:"InvalidPropertyError",property:t,reason:`Unsupported property value for "${t}" (accepts string/number/boolean/null/array/object of the same).`});const s=K(r,t);if(s!==void 0){s.value=o;continue}const u=w(t,o,a);i&&(u.extra={...u.extra??{},trailingComma:!0}),r.properties.push(u)}return l(void 0)}function K(r,e){return r.properties.find(a=>(a.type==="Property"||a.type==="ObjectProperty")&&a.shorthand!==!0&&a.computed!==!0&&G(a.key)===e)}function _(r){return r.properties[r.properties.length-1]?.extra?.trailingComma===!0}function M(r,e,a){const i=A(r,a);return i.success?i.data.filter(t=>t.type===e).map(t=>t.symbolName):[]}function V(r,e){const a=[r];for(;a.length>0;){const i=a.pop();if(p(i)){typeof i.type=="string"&&e(i);for(const t of Object.keys(i)){if(t==="loc"||t==="comments"||t==="tokens")continue;const n=i[t];if(Array.isArray(n))for(const o of n)p(o)&&a.push(o);else p(n)&&a.push(n)}}}}export{ee as modifyResource};
1
+ var S=Object.defineProperty;var d=(r,e)=>S(r,"name",{value:e,configurable:!0});import{failure as c,success as p}from"../../types/Result.js";import{DEFAULT_FILE_PATH as v,computeLinesDelta as w,extractProgramBody as C,isRecord as m}from"../_internal.js";import{buildObjectProperty as N,detectQuoteStyle as x,parse as T,printFile as A}from"../fileRewriter/index.js";import{STATEMENT_REGISTRY as F}from"../registry.js";import{locateAllShapes as R,locateByShape as L}from"../semanticIndex/index.js";import{checkControlFlowPolicy as j}from"./controlFlowPolicy.js";import{driftGate as O,runPipeline as Q,schemaGate as I}from"../validationGate/index.js";import{toAstValue as G}from"./addResource/propertyBuilder.js";import{buildMergedLiteral as U,isNodeShape as E,readKeyName as B}from"./modifyResource/literalConversion.js";function ne(r,e,a={}){const i=e.filePath??v,t=T(r,i);if(!t.success)return c(t.error);const n=L(r,{type:e.type,name:e.name},i);if(!n.success)return n.error.kind==="TemplateLiteralNameError"?c(n.error):c({kind:"SemanticQueryError",reason:n.error.reason,cause:n.error.cause});if(n.data===void 0)return c({kind:"ResourceNotFoundError",type:e.type,name:e.name,knownNames:$(r,e.type,i)});const o=j({ast:t.data,target:n.data,resource:{type:e.type,name:e.name},op:"modify"});if(o.refusal!==void 0)return c(o.refusal);const s=Q([I,O],{content:r,plan:{type:e.type,name:e.name,properties:e.properties,op:"modify"},baseline:a.baseline,policy:e.driftPolicy});if(!s.success)return c(D(s.error));if(s.data.action==="skip")return p({content:r,linesChanged:{added:0,removed:0},skipped:!0});const u=C(t.data);if(u===void 0)return c({kind:"SemanticQueryError",reason:"recast File is missing program.body"});const l=K(u,n.data);if(l===void 0)return c({kind:"SemanticQueryError",reason:"Unable to resolve config ObjectExpression for the located resource."});const k=x(t.data),b=U(l,e.properties),y=F[e.type].schemaFragment.safeParse(b);if(!y.success){const f=y.error.issues[0];return c({kind:"InvalidPropertyError",property:f!==void 0&&f.path.length>0?String(f.path[0]):Object.keys(e.properties)[0]??"<unknown>",reason:f?.message??"Schema validation failed"})}const g=_(l,e.properties,k);if(!g.success)return c(g.error);const h=A(t.data,r),P=o.warning!==void 0?[o.warning.message]:void 0;return p({content:h,linesChanged:w(r,h),warnings:P})}d(ne,"modifyResource");function D(r){switch(r.kind){case"ParseError":case"ResourceNotFoundError":case"InvalidPropertyError":case"TemplateLiteralNameError":case"SemanticQueryError":case"DriftConflictError":case"ControlFlowClassifierError":return r;default:return{kind:"SemanticQueryError",reason:`Unexpected codemod error in validation-gate pipeline: ${r.kind}`}}}d(D,"narrowGateError");function K(r,e){const a=e.start+e.length;let i;const t=d(n=>{if(i!==void 0||n.type!=="CallExpression")return;const o=n.arguments;if(!Array.isArray(o)||o.length<2)return;const s=o[0];if(!E(s)||s.type!=="StringLiteral"||s.start!==e.start||s.end!==a)return;const u=o[1];E(u)&&u.type==="ObjectExpression"&&(i=u)},"visitor");for(const n of r)if(H(n,t),i!==void 0)break;return i}d(K,"findConfigObject");function _(r,e,a){const i=V(r);for(const[t,n]of Object.entries(e)){const o=G(n,a);if(o===void 0)return c({kind:"InvalidPropertyError",property:t,reason:`Unsupported property value for "${t}" (accepts string/number/boolean/null/array/object of the same).`});const s=M(r,t);if(s!==void 0){s.value=o;continue}const u=N(t,o,a);i&&(u.extra={...u.extra??{},trailingComma:!0}),r.properties.push(u)}return p(void 0)}d(_,"applyPropertyEdits");function M(r,e){return r.properties.find(a=>(a.type==="Property"||a.type==="ObjectProperty")&&a.shorthand!==!0&&a.computed!==!0&&B(a.key)===e)}d(M,"findPropertyByKey");function V(r){return r.properties[r.properties.length-1]?.extra?.trailingComma===!0}d(V,"detectTrailingCommaStyle");function $(r,e,a){const i=R(r,a);return i.success?i.data.filter(t=>t.type===e).map(t=>t.symbolName):[]}d($,"collectKnownNames");function H(r,e){const a=[r];for(;a.length>0;){const i=a.pop();if(m(i)){typeof i.type=="string"&&e(i);for(const t of Object.keys(i)){if(t==="loc"||t==="comments"||t==="tokens")continue;const n=i[t];if(Array.isArray(n))for(const o of n)m(o)&&a.push(o);else m(n)&&a.push(n)}}}}d(H,"visit");export{ne as modifyResource};
@@ -1 +1 @@
1
- function a(n,e){const t=[],r=[],i=n.comments;if(!Array.isArray(i)||typeof n.start!="number")return{preserved:t,adjacent:r};for(const o of i){if(!f(o)||o.leading!==!0||typeof o.end!="number")continue;const s=e.slice(o.end,n.start);c(s)>=2?t.push(o):r.push(o)}return{preserved:t,adjacent:r}}function c(n){let e=0;for(let t=0;t<n.length;t+=1)n.charCodeAt(t)===10&&(e+=1);return e}function f(n){if(typeof n!="object"||n===null||Array.isArray(n))return!1;const e=n;return typeof e.type=="string"&&typeof e.value=="string"}export{a as classifyLeadingComments};
1
+ var f=Object.defineProperty;var r=(n,e)=>f(n,"name",{value:e,configurable:!0});function y(n,e){const t=[],i=[],s=n.comments;if(!Array.isArray(s)||typeof n.start!="number")return{preserved:t,adjacent:i};for(const o of s){if(!a(o)||o.leading!==!0||typeof o.end!="number")continue;const c=e.slice(o.end,n.start);u(c)>=2?t.push(o):i.push(o)}return{preserved:t,adjacent:i}}r(y,"classifyLeadingComments");function u(n){let e=0;for(let t=0;t<n.length;t+=1)n.charCodeAt(t)===10&&(e+=1);return e}r(u,"countNewlines");function a(n){if(typeof n!="object"||n===null||Array.isArray(n))return!1;const e=n;return typeof e.type=="string"&&typeof e.value=="string"}r(a,"isCommentNode");export{y as classifyLeadingComments};
@@ -1 +1 @@
1
- import{isRecord as f}from"../../_internal.js";function m(e){const r=p(e);for(let n=e.length-1;n>=0;n-=1){const t=e[n];if(t===void 0||t.type!=="ImportDeclaration")continue;const i=t.specifiers;if(!Array.isArray(i))continue;const o=i.filter(s=>{if(!u(s))return!0;const c=a(s);return(r.get(c)??0)>0});if(o.length!==i.length){if(o.length===0){e.splice(n,1);continue}t.specifiers=o}}}function p(e){const r=new Map,n=[...e];for(;n.length>0;){const t=n.pop();if(!(!f(t)||typeof t.type!="string")&&t.type!=="ImportDeclaration"){if(t.type==="Identifier"){const i=t.name;typeof i=="string"&&r.set(i,(r.get(i)??0)+1);continue}for(const i of Object.keys(t)){if(i==="loc"||i==="comments"||i==="tokens")continue;const o=t[i];if(Array.isArray(o))for(const s of o)f(s)&&typeof s.type=="string"&&n.push(s);else f(o)&&typeof o.type=="string"&&n.push(o)}}}return r}function a(e){const r=e.local;if(f(r)){const t=r.name;if(typeof t=="string")return t}const n=e.imported;if(f(n)){const t=n.name;if(typeof t=="string")return t}return""}function u(e){if(!f(e)||e.type!=="ImportSpecifier")return!1;const r=e.imported;return f(r)&&typeof r.name=="string"}export{m as pruneUnusedImports};
1
+ var a=Object.defineProperty;var c=(e,n)=>a(e,"name",{value:n,configurable:!0});import{isRecord as f}from"../../_internal.js";function d(e){const n=u(e);for(let i=e.length-1;i>=0;i-=1){const t=e[i];if(t===void 0||t.type!=="ImportDeclaration")continue;const r=t.specifiers;if(!Array.isArray(r))continue;const o=r.filter(s=>{if(!m(s))return!0;const p=l(s);return(n.get(p)??0)>0});if(o.length!==r.length){if(o.length===0){e.splice(i,1);continue}t.specifiers=o}}}c(d,"pruneUnusedImports");function u(e){const n=new Map,i=[...e];for(;i.length>0;){const t=i.pop();if(!(!f(t)||typeof t.type!="string")&&t.type!=="ImportDeclaration"){if(t.type==="Identifier"){const r=t.name;typeof r=="string"&&n.set(r,(n.get(r)??0)+1);continue}for(const r of Object.keys(t)){if(r==="loc"||r==="comments"||r==="tokens")continue;const o=t[r];if(Array.isArray(o))for(const s of o)f(s)&&typeof s.type=="string"&&i.push(s);else f(o)&&typeof o.type=="string"&&i.push(o)}}}return n}c(u,"collectIdentifierUsage");function l(e){const n=e.local;if(f(n)){const t=n.name;if(typeof t=="string")return t}const i=e.imported;if(f(i)){const t=i.name;if(typeof t=="string")return t}return""}c(l,"readLocalName");function m(e){if(!f(e)||e.type!=="ImportSpecifier")return!1;const n=e.imported;return f(n)&&typeof n.name=="string"}c(m,"isNamedImportSpecifier");export{d as pruneUnusedImports};
@@ -1 +1 @@
1
- import{failure as f,success as u}from"../../types/Result.js";import{DEFAULT_FILE_PATH as m,computeLinesDelta as y,extractProgramBody as g,isRecord as d}from"../_internal.js";import{parse as h,printFile as b}from"../fileRewriter/index.js";import{findReferences as E,locateAllShapes as v,locateByShape as k}from"../semanticIndex/index.js";import{checkControlFlowPolicy as R}from"./controlFlowPolicy.js";import{classifyLeadingComments as S}from"./removeResource/commentHeuristic.js";import{pruneUnusedImports as N}from"./removeResource/importPruning.js";function V(n,r){const a=r.filePath??m,t=h(n,a);if(!t.success)return f(t.error);const e=k(n,{type:r.type,name:r.name},a);if(!e.success)return e.error.kind==="TemplateLiteralNameError"?f(e.error):f({kind:"SemanticQueryError",reason:e.error.reason,cause:e.error.cause});if(e.data===void 0)return f({kind:"ResourceNotFoundError",type:r.type,name:r.name,knownNames:L(n,r.type,a)});const o=R({ast:t.data,target:e.data,resource:{type:r.type,name:r.name},op:"remove"});if(o.refusal!==void 0)return f(o.refusal);const i=g(t.data);if(i===void 0)return f({kind:"SemanticQueryError",reason:"recast File is missing program.body"});const c=D(i,e.data);if(c===void 0)return f({kind:"SemanticQueryError",reason:"Unable to resolve enclosing statement for the located resource."});const s=F(n,c.statement,a);if(!s.success)return f(s.error);if(s.data.locations.length>0&&r.force!==!0)return f({kind:"ReferencesRemainError",variable:s.data.variable??r.name,references:s.data.locations});A(i,c.index,n),N(i);const l=b(t.data,n),p=y(n,l);return u({content:l,linesChanged:p,references:s.data.locations})}function D(n,r){const a=r.start+r.length;for(let t=0;t<n.length;t+=1){const e=n[t];if(e!==void 0&&!(typeof e.start!="number"||typeof e.end!="number")&&e.start<=r.start&&e.end>=a)return{index:t,statement:e}}}function F(n,r,a){const t=P(r);if(t===void 0)return u({variable:void 0,locations:[]});const e=E(n,t.location,a);return e.success?u({variable:t.name,locations:e.data}):f({kind:"SemanticQueryError",reason:e.error.reason,cause:e.error.cause})}function P(n){let r=n;if(n.type==="ExportNamedDeclaration"){const s=n.declaration;if(!d(s)||s.type!=="VariableDeclaration")return;r=s}if(r.type!=="VariableDeclaration")return;const a=r.declarations;if(!Array.isArray(a)||a.length!==1)return;const t=a[0];if(!d(t))return;const e=t.id;if(!d(e)||e.type!=="Identifier")return;const o=e.name,i=e.start,c=e.end;if(!(typeof o!="string"||typeof i!="number"||typeof c!="number"))return{name:o,location:{filePath:m,start:i,length:c-i,symbolName:o}}}function A(n,r,a){const t=n[r];if(t===void 0)return;const{preserved:e}=S(t,a);if(e.length>0){const o=n[r+1];if(o!==void 0){const i=e.map(c=>({...c,leading:!0,trailing:!1}));o.comments=[...i,...o.comments??[]]}else{const i=n[r-1];if(i!==void 0){const c=e.map(s=>({...s,leading:!1,trailing:!0}));i.comments=[...i.comments??[],...c]}}}n.splice(r,1)}function L(n,r,a){const t=v(n,a);if(!t.success)return[];const e=[];for(const o of t.data)o.type===r&&e.push(o.symbolName);return e}export{V as removeResource};
1
+ var g=Object.defineProperty;var u=(n,r)=>g(n,"name",{value:r,configurable:!0});import{failure as f,success as d}from"../../types/Result.js";import{DEFAULT_FILE_PATH as p,computeLinesDelta as h,extractProgramBody as b,isRecord as l}from"../_internal.js";import{parse as E,printFile as v}from"../fileRewriter/index.js";import{findReferences as k,locateAllShapes as R,locateByShape as S}from"../semanticIndex/index.js";import{checkControlFlowPolicy as N}from"./controlFlowPolicy.js";import{classifyLeadingComments as D}from"./removeResource/commentHeuristic.js";import{pruneUnusedImports as F}from"./removeResource/importPruning.js";function H(n,r){const a=r.filePath??p,t=E(n,a);if(!t.success)return f(t.error);const e=S(n,{type:r.type,name:r.name},a);if(!e.success)return e.error.kind==="TemplateLiteralNameError"?f(e.error):f({kind:"SemanticQueryError",reason:e.error.reason,cause:e.error.cause});if(e.data===void 0)return f({kind:"ResourceNotFoundError",type:r.type,name:r.name,knownNames:Q(n,r.type,a)});const o=N({ast:t.data,target:e.data,resource:{type:r.type,name:r.name},op:"remove"});if(o.refusal!==void 0)return f(o.refusal);const i=b(t.data);if(i===void 0)return f({kind:"SemanticQueryError",reason:"recast File is missing program.body"});const c=P(i,e.data);if(c===void 0)return f({kind:"SemanticQueryError",reason:"Unable to resolve enclosing statement for the located resource."});const s=A(n,c.statement,a);if(!s.success)return f(s.error);if(s.data.locations.length>0&&r.force!==!0)return f({kind:"ReferencesRemainError",variable:s.data.variable??r.name,references:s.data.locations});x(i,c.index,n),F(i);const m=v(t.data,n),y=h(n,m);return d({content:m,linesChanged:y,references:s.data.locations})}u(H,"removeResource");function P(n,r){const a=r.start+r.length;for(let t=0;t<n.length;t+=1){const e=n[t];if(e!==void 0&&!(typeof e.start!="number"||typeof e.end!="number")&&e.start<=r.start&&e.end>=a)return{index:t,statement:e}}}u(P,"findEnclosingStatement");function A(n,r,a){const t=L(r);if(t===void 0)return d({variable:void 0,locations:[]});const e=k(n,t.location,a);return e.success?d({variable:t.name,locations:e.data}):f({kind:"SemanticQueryError",reason:e.error.reason,cause:e.error.cause})}u(A,"resolveReferences");function L(n){let r=n;if(n.type==="ExportNamedDeclaration"){const s=n.declaration;if(!l(s)||s.type!=="VariableDeclaration")return;r=s}if(r.type!=="VariableDeclaration")return;const a=r.declarations;if(!Array.isArray(a)||a.length!==1)return;const t=a[0];if(!l(t))return;const e=t.id;if(!l(e)||e.type!=="Identifier")return;const o=e.name,i=e.start,c=e.end;if(!(typeof o!="string"||typeof i!="number"||typeof c!="number"))return{name:o,location:{filePath:p,start:i,length:c-i,symbolName:o}}}u(L,"extractVariableDeclaration");function x(n,r,a){const t=n[r];if(t===void 0)return;const{preserved:e}=D(t,a);if(e.length>0){const o=n[r+1];if(o!==void 0){const i=e.map(c=>({...c,leading:!0,trailing:!1}));o.comments=[...i,...o.comments??[]]}else{const i=n[r-1];if(i!==void 0){const c=e.map(s=>({...s,leading:!1,trailing:!0}));i.comments=[...i.comments??[],...c]}}}n.splice(r,1)}u(x,"spliceStatement");function Q(n,r,a){const t=R(n,a);if(!t.success)return[];const e=[];for(const o of t.data)o.type===r&&e.push(o.symbolName);return e}u(Q,"collectKnownNames");export{H as removeResource};
@@ -1 +1 @@
1
- import{failure as o,success as l}from"../../types/Result.js";import{addResource as m}from"./addResource.js";import{modifyResource as P}from"./modifyResource.js";import{removeResource as A}from"./removeResource.js";const f="vpc-peer";function j(e,n){const t=g(n);if(t!==void 0)return o(t);const{name:r,filePath:c,currentAccount:d,...a}=n,s={...a},i=m(e,{type:f,name:r,properties:s,...c!==void 0?{filePath:c}:{}});if(!i.success)return o(i.error);const u=y(n);return l({content:i.data.content,linesChanged:i.data.linesChanged,...u.length>0?{warnings:u}:{}})}function w(e,n){const t=A(e,{type:f,name:n.name,...n.filePath!==void 0?{filePath:n.filePath}:{},...n.force!==void 0?{force:n.force}:{}});return t.success?l({content:t.data.content,linesChanged:t.data.linesChanged}):o(t.error)}function V(e,n){const t=g(n);if(t!==void 0)return o(t);const{name:r,filePath:c,currentAccount:d,...a}=n,s={...a},i=P(e,{type:f,name:r,properties:s,...c!==void 0?{filePath:c}:{}});if(!i.success)return o(i.error);const u=$(a,d);return l({content:i.data.content,linesChanged:i.data.linesChanged,...u.length>0?{warnings:u}:{}})}function y(e){return h(e.peerAppName,e.peerAccountId,e.currentAccount)}function $(e,n){return e.peerAccountId===void 0?[]:h(e.peerAppName,e.peerAccountId,n)}function h(e,n,t){if(t!==void 0&&n===t)return[];const r=e!==void 0?` (peer app ${e})`:"";return[`VPC peer targets AWS account ${n}${r}. Peer requires a VpcPeerAccepter in that account trusting the local account. Deploy the accepter stack first, then the requester.`]}function C(e,n,t){const r=p(n);if(r!==void 0)return{kind:"PermissionError",reason:"wildcard-principal-rejected",details:`Wildcard value detected in ${e} field "${r}". Fjall refuses to emit a ${e} statement that could map to a wildcard principal in the generated trust policy.`,remediation:t}}function g(e){const{name:n,filePath:t,currentAccount:r,...c}=e;return C(f,c,"Replace the wildcard with a concrete 12-digit AWS account id, region, or vpc-id.")}function p(e,n=""){if(typeof e=="string")return e.includes("*")?n:void 0;if(Array.isArray(e)){for(let t=0;t<e.length;t+=1){const r=p(e[t],`${n}[${t}]`);if(r!==void 0)return r}return}if(e!==null&&typeof e=="object")for(const[t,r]of Object.entries(e)){const c=n.length>0?`${n}.${t}`:t,d=p(r,c);if(d!==void 0)return d}}export{j as addVpcPeer,C as buildWildcardRejection,p as findWildcardField,V as modifyVpcPeer,w as removeVpcPeer};
1
+ var P=Object.defineProperty;var c=(e,n)=>P(e,"name",{value:n,configurable:!0});import{failure as a,success as p}from"../../types/Result.js";import{addResource as A}from"./addResource.js";import{modifyResource as y}from"./modifyResource.js";import{removeResource as $}from"./removeResource.js";const s="vpc-peer";function _(e,n){const t=m(n);if(t!==void 0)return a(t);const{name:r,filePath:i,currentAccount:u,...f}=n,l={...f},d=A(e,{type:s,name:r,properties:l,...i!==void 0?{filePath:i}:{}});if(!d.success)return a(d.error);const o=C(n);return p({content:d.data.content,linesChanged:d.data.linesChanged,...o.length>0?{warnings:o}:{}})}c(_,"addVpcPeer");function E(e,n){const t=$(e,{type:s,name:n.name,...n.filePath!==void 0?{filePath:n.filePath}:{},...n.force!==void 0?{force:n.force}:{}});return t.success?p({content:t.data.content,linesChanged:t.data.linesChanged}):a(t.error)}c(E,"removeVpcPeer");function k(e,n){const t=m(n);if(t!==void 0)return a(t);const{name:r,filePath:i,currentAccount:u,...f}=n,l={...f},d=y(e,{type:s,name:r,properties:l,...i!==void 0?{filePath:i}:{}});if(!d.success)return a(d.error);const o=W(f,u);return p({content:d.data.content,linesChanged:d.data.linesChanged,...o.length>0?{warnings:o}:{}})}c(k,"modifyVpcPeer");function C(e){return g(e.peerAppName,e.peerAccountId,e.currentAccount)}c(C,"buildAddWarnings");function W(e,n){return e.peerAccountId===void 0?[]:g(e.peerAppName,e.peerAccountId,n)}c(W,"buildModifyWarnings");function g(e,n,t){if(t!==void 0&&n===t)return[];const r=e!==void 0?` (peer app ${e})`:"";return[`VPC peer targets AWS account ${n}${r}. Peer requires a VpcPeerAccepter in that account trusting the local account. Deploy the accepter stack first, then the requester.`]}c(g,"buildCrossAccountWarnings");function x(e,n,t){const r=h(n);if(r!==void 0)return{kind:"PermissionError",reason:"wildcard-principal-rejected",details:`Wildcard value detected in ${e} field "${r}". Fjall refuses to emit a ${e} statement that could map to a wildcard principal in the generated trust policy.`,remediation:t}}c(x,"buildWildcardRejection");function m(e){const{name:n,filePath:t,currentAccount:r,...i}=e;return x(s,i,"Replace the wildcard with a concrete 12-digit AWS account id, region, or vpc-id.")}c(m,"rejectWildcardPrincipal");function h(e,n=""){if(typeof e=="string")return e.includes("*")?n:void 0;if(Array.isArray(e)){for(let t=0;t<e.length;t+=1){const r=h(e[t],`${n}[${t}]`);if(r!==void 0)return r}return}if(e!==null&&typeof e=="object")for(const[t,r]of Object.entries(e)){const i=n.length>0?`${n}.${t}`:t,u=h(r,i);if(u!==void 0)return u}}c(h,"findWildcardField");export{_ as addVpcPeer,x as buildWildcardRejection,h as findWildcardField,k as modifyVpcPeer,E as removeVpcPeer};
@@ -1 +1 @@
1
- import{failure as a,success as p}from"../../types/Result.js";import{addResource as m}from"./addResource.js";import{modifyResource as s}from"./modifyResource.js";import{removeResource as l}from"./removeResource.js";import{buildWildcardRejection as P}from"./vpcPeer.js";const i="vpc-peer-accepter";function f(e){return e.success?p({content:e.data.content,linesChanged:e.data.linesChanged}):a(e.error)}function E(e,r){const t=u(r);if(t!==void 0)return a(t);const{name:n,filePath:c,...d}=r,o={...d};return f(m(e,{type:i,name:n,properties:o,...c!==void 0?{filePath:c}:{}}))}function v(e,r){return f(l(e,{type:i,name:r.name,...r.filePath!==void 0?{filePath:r.filePath}:{},...r.force!==void 0?{force:r.force}:{}}))}function w(e,r){const t=u(r);if(t!==void 0)return a(t);const{name:n,filePath:c,...d}=r,o={...d};return f(s(e,{type:i,name:n,properties:o,...c!==void 0?{filePath:c}:{}}))}function u(e){const{name:r,filePath:t,...n}=e;return P(i,n,"Replace the wildcard with a concrete 12-digit AWS account id.")}export{E as addVpcPeerAccepter,w as modifyVpcPeerAccepter,v as removeVpcPeerAccepter};
1
+ var m=Object.defineProperty;var n=(e,r)=>m(e,"name",{value:r,configurable:!0});import{failure as f,success as s}from"../../types/Result.js";import{addResource as l}from"./addResource.js";import{modifyResource as P}from"./modifyResource.js";import{removeResource as h}from"./removeResource.js";import{buildWildcardRejection as R}from"./vpcPeer.js";const d="vpc-peer-accepter";function u(e){return e.success?s({content:e.data.content,linesChanged:e.data.linesChanged}):f(e.error)}n(u,"unwrapEditResult");function x(e,r){const t=p(r);if(t!==void 0)return f(t);const{name:c,filePath:i,...o}=r,a={...o};return u(l(e,{type:d,name:c,properties:a,...i!==void 0?{filePath:i}:{}}))}n(x,"addVpcPeerAccepter");function C(e,r){return u(h(e,{type:d,name:r.name,...r.filePath!==void 0?{filePath:r.filePath}:{},...r.force!==void 0?{force:r.force}:{}}))}n(C,"removeVpcPeerAccepter");function V(e,r){const t=p(r);if(t!==void 0)return f(t);const{name:c,filePath:i,...o}=r,a={...o};return u(P(e,{type:d,name:c,properties:a,...i!==void 0?{filePath:i}:{}}))}n(V,"modifyVpcPeerAccepter");function p(e){const{name:r,filePath:t,...c}=e;return R(d,c,"Replace the wildcard with a concrete 12-digit AWS account id.")}n(p,"rejectWildcardPrincipal");export{x as addVpcPeerAccepter,V as modifyVpcPeerAccepter,C as removeVpcPeerAccepter};
@@ -1 +1 @@
1
- import{builders as i}from"ast-types";function d(e){const t=i.memberExpression(i.identifier(e.factory),i.identifier("build"),!1),r=c(e.name,e.quoteStyle),n=i.objectExpression(e.properties.map(o=>f(o.key,o.value,e.quoteStyle))),s=i.callExpression(t,[r,n]);return i.expressionStatement(s)}function f(e,t,r){const n=u(e)?i.identifier(e):c(e,r);return i.property("init",n,t)}function b(e,t,r="double"){const n=e.map(o=>i.importSpecifier(i.identifier(o))),s=c(t,r);return i.importDeclaration(n,s)}function m(e,t){return i.memberExpression(i.identifier(e),i.identifier(t),!1)}function x(e,t){Array.isArray(e.specifiers)||(e.specifiers=[]);for(const r of e.specifiers)if(a(r)&&r.imported.name===t)return;e.specifiers.push(i.importSpecifier(i.identifier(t)))}function c(e,t){const r=t==="single"?"'":'"',n=`${r}${p(e,t)}${r}`;return i.stringLiteral.from({value:e,extra:{rawValue:e,raw:n}})}function p(e,t){const r=e.replace(/\\/g,"\\\\");return t==="single"?r.replace(/'/g,"\\'"):r.replace(/"/g,'\\"')}function u(e){return/^[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*$/u.test(e)}function a(e){return e!==null&&typeof e=="object"&&"type"in e&&e.type==="ImportSpecifier"}export{x as appendSpecifier,d as buildFactoryStatement,b as buildImportDeclaration,m as buildMemberExpression,f as buildObjectProperty};
1
+ var p=Object.defineProperty;var n=(e,i)=>p(e,"name",{value:i,configurable:!0});import{builders as t}from"ast-types";function x(e){const i=t.memberExpression(t.identifier(e.factory),t.identifier("build"),!1),r=f(e.name,e.quoteStyle),o=t.objectExpression(e.properties.map(s=>u(s.key,s.value,e.quoteStyle))),c=t.callExpression(i,[r,o]);return t.expressionStatement(c)}n(x,"buildFactoryStatement");function u(e,i,r){const o=l(e)?t.identifier(e):f(e,r);return t.property("init",o,i)}n(u,"buildObjectProperty");function y(e,i,r="double"){const o=e.map(s=>t.importSpecifier(t.identifier(s))),c=f(i,r);return t.importDeclaration(o,c)}n(y,"buildImportDeclaration");function S(e,i){return t.memberExpression(t.identifier(e),t.identifier(i),!1)}n(S,"buildMemberExpression");function g(e,i){Array.isArray(e.specifiers)||(e.specifiers=[]);for(const r of e.specifiers)if(d(r)&&r.imported.name===i)return;e.specifiers.push(t.importSpecifier(t.identifier(i)))}n(g,"appendSpecifier");function f(e,i){const r=i==="single"?"'":'"',o=`${r}${a(e,i)}${r}`;return t.stringLiteral.from({value:e,extra:{rawValue:e,raw:o}})}n(f,"makeStringLiteral");function a(e,i){const r=e.replace(/\\/g,"\\\\");return i==="single"?r.replace(/'/g,"\\'"):r.replace(/"/g,'\\"')}n(a,"escapeForQuote");function l(e){return/^[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*$/u.test(e)}n(l,"isValidIdentifier");function d(e){return e!==null&&typeof e=="object"&&"type"in e&&e.type==="ImportSpecifier"}n(d,"isNamedImportSpecifier");export{g as appendSpecifier,x as buildFactoryStatement,y as buildImportDeclaration,S as buildMemberExpression,u as buildObjectProperty};
@@ -1 +1 @@
1
- function b(u,r,i){const n=m(u,r);if(n!==void 0)return n;if(i?.line!==void 0)return p(u,{...r,...i})}function p(u,r){if(r.line===void 0)return;const i=r.line,n=r.column??0,e=[];if(y(u,t=>{if(t.type!=="StringLiteral"||typeof t.value!="string"||t.value!==r.symbolName||typeof t.start!="number"||typeof t.end!="number")return;const s=t.loc?.start?.line,f=t.loc?.start?.column;typeof s!="number"||typeof f!="number"||Math.abs(s-i)>2||e.push({node:t,line:s,column:f,start:t.start})}),e.length!==0)return e.sort((t,s)=>{const f=Math.abs(t.line-i),o=Math.abs(s.line-i);if(f!==o)return f-o;const c=Math.abs(t.column-n),l=Math.abs(s.column-n);return c!==l?c-l:t.start-s.start}),e[0]?.node}function m(u,r){const i=r.start+r.length;let n;return y(u,e=>{n===void 0&&(typeof e.start!="number"||typeof e.end!="number"||e.start===r.start&&e.end===i&&(n=e))}),n}function y(u,r){const i=[u];for(;i.length>0;){const n=i.pop();if(!(!a(n)||typeof n.type!="string")){r(n);for(const e of Object.keys(n)){if(e==="loc"||e==="comments"||e==="tokens")continue;const t=n[e];if(Array.isArray(t))for(const s of t)a(s)&&typeof s.type=="string"&&i.push(s);else a(t)&&typeof t.type=="string"&&i.push(t)}}}}function a(u){return typeof u=="object"&&u!==null&&!Array.isArray(u)}export{p as locateByLineColumn,b as locateByRange};
1
+ var m=Object.defineProperty;var f=(i,n)=>m(i,"name",{value:n,configurable:!0});function d(i,n,u){const e=g(i,n);if(e!==void 0)return e;if(u?.line!==void 0)return b(i,{...n,...u})}f(d,"locateByRange");function b(i,n){if(n.line===void 0)return;const u=n.line,e=n.column??0,r=[];if(p(i,t=>{if(t.type!=="StringLiteral"||typeof t.value!="string"||t.value!==n.symbolName||typeof t.start!="number"||typeof t.end!="number")return;const s=t.loc?.start?.line,a=t.loc?.start?.column;typeof s!="number"||typeof a!="number"||Math.abs(s-u)>2||r.push({node:t,line:s,column:a,start:t.start})}),r.length!==0)return r.sort((t,s)=>{const a=Math.abs(t.line-u),c=Math.abs(s.line-u);if(a!==c)return a-c;const l=Math.abs(t.column-e),y=Math.abs(s.column-e);return l!==y?l-y:t.start-s.start}),r[0]?.node}f(b,"locateByLineColumn");function g(i,n){const u=n.start+n.length;let e;return p(i,r=>{e===void 0&&(typeof r.start!="number"||typeof r.end!="number"||r.start===n.start&&r.end===u&&(e=r))}),e}f(g,"findByExactRange");function p(i,n){const u=[i];for(;u.length>0;){const e=u.pop();if(!(!o(e)||typeof e.type!="string")){n(e);for(const r of Object.keys(e)){if(r==="loc"||r==="comments"||r==="tokens")continue;const t=e[r];if(Array.isArray(t))for(const s of t)o(s)&&typeof s.type=="string"&&u.push(s);else o(t)&&typeof t.type=="string"&&u.push(t)}}}}f(p,"visit");function o(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}f(o,"isRecord");export{b as locateByLineColumn,d as locateByRange};
@@ -1,2 +1,2 @@
1
- import*as d from"recast";import x from"recast/parsers/typescript.js";import a from"recast/parsers/babel-ts.js";import{failure as E,success as y}from"../../types/Result.js";const m=1,l=120;function I(n,t){if((t?.endsWith(".tsx")??!1)||b(n))return f(n,a,t);const e=f(n,x,t);if(e.success)return e;const s=f(n,a,t);return s.success?s:e}function b(n){return/<[A-Z][A-Za-z0-9]*[\s/>]|<>/.test(n)}function f(n,t,r){try{const e=d.parse(n,{parser:t});return y(e)}catch(e){return E(g(e,n,r))}}function g(n,t,r){const e=n instanceof Error?n.message:String(n),s=S(n),o=s?.line,c=s?.column;return{kind:"ParseError",file:r,line:o,column:c,message:e,sourceSnippet:h(t,o)}}function S(n){if(typeof n!="object"||n===null)return;const t=n.loc;if(typeof t!="object"||t===null)return;const r=t.line,e=t.column;return{line:typeof r=="number"?r:void 0,column:typeof e=="number"?e:void 0}}function h(n,t){const r=n.split(/\r?\n/);if(r.length===0)return"";const e=t!==void 0&&t>=1&&t<=r.length?t-1:0,s=Math.max(0,e-m),o=Math.min(r.length-1,e+m),c=[];for(let u=s;u<=o;u+=1){const i=r[u]??"",p=i.length>l?`${i.slice(0,l)}\u2026`:i;c.push(p)}return c.join(`
2
- `)}export{I as parse};
1
+ var x=Object.defineProperty;var o=(n,t)=>x(n,"name",{value:t,configurable:!0});import*as E from"recast";import y from"recast/parsers/typescript.js";import m from"recast/parsers/babel-ts.js";import{failure as b,success as g}from"../../types/Result.js";const l=1,p=120;function j(n,t){if((t?.endsWith(".tsx")??!1)||S(n))return a(n,m,t);const e=a(n,y,t);if(e.success)return e;const s=a(n,m,t);return s.success?s:e}o(j,"parse");function S(n){return/<[A-Z][A-Za-z0-9]*[\s/>]|<>/.test(n)}o(S,"detectJsx");function a(n,t,r){try{const e=E.parse(n,{parser:t});return g(e)}catch(e){return b(h(e,n,r))}}o(a,"tryParse");function h(n,t,r){const e=n instanceof Error?n.message:String(n),s=L(n),c=s?.line,u=s?.column;return{kind:"ParseError",file:r,line:c,column:u,message:e,sourceSnippet:N(t,c)}}o(h,"toParseError");function L(n){if(typeof n!="object"||n===null)return;const t=n.loc;if(typeof t!="object"||t===null)return;const r=t.line,e=t.column;return{line:typeof r=="number"?r:void 0,column:typeof e=="number"?e:void 0}}o(L,"extractLoc");function N(n,t){const r=n.split(/\r?\n/);if(r.length===0)return"";const e=t!==void 0&&t>=1&&t<=r.length?t-1:0,s=Math.max(0,e-l),c=Math.min(r.length-1,e+l),u=[];for(let i=s;i<=c;i+=1){const f=r[i]??"",d=f.length>p?`${f.slice(0,p)}\u2026`:f;u.push(d)}return u.join(`
2
+ `)}o(N,"buildSourceSnippet");export{j as parse};
@@ -1,4 +1,4 @@
1
- import*as u from"recast";const p="\uFEFF",f=65279;function m(t,c){const o=a(c),e=l(t),r=u.print(t,{quote:e,lineTerminator:o,trailingComma:!0}).code,n=c.charCodeAt(0)===f,i=r.charCodeAt(0)===f;return n&&!i?`${p}${r}`:r}function a(t){return t.includes(`\r
1
+ var p=Object.defineProperty;var s=(t,o)=>p(t,"name",{value:o,configurable:!0});import*as a from"recast";const l="\uFEFF",u=65279;function h(t,o){const i=y(o),e=m(t),r=a.print(t,{quote:e,lineTerminator:i,trailingComma:!0}).code,n=o.charCodeAt(0)===u,c=r.charCodeAt(0)===u;return n&&!c?`${l}${r}`:r}s(h,"printFile");function y(t){return t.includes(`\r
2
2
  `)?`\r
3
3
  `:`
4
- `}function l(t){let c=0,o=0;return y(t,e=>{if(e.type!=="StringLiteral"&&e.type!=="Literal")return;const r=e.extra;if(!s(r))return;const n=r.raw;if(typeof n!="string"||n.length===0)return;const i=n.charAt(0);i==="'"?c+=1:i==='"'&&(o+=1)}),c>o?"single":"double"}function y(t,c){const o=[t];for(;o.length>0;){const e=o.pop();if(!(!s(e)||typeof e.type!="string")){c(e);for(const r of Object.keys(e)){if(r==="loc"||r==="comments"||r==="tokens")continue;const n=e[r];if(Array.isArray(n))for(const i of n)s(i)&&typeof i.type=="string"&&o.push(i);else s(n)&&typeof n.type=="string"&&o.push(n)}}}}function s(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}export{a as detectLineTerminator,l as detectQuoteStyle,m as printFile};
4
+ `}s(y,"detectLineTerminator");function m(t){let o=0,i=0;return g(t,e=>{if(e.type!=="StringLiteral"&&e.type!=="Literal")return;const r=e.extra;if(!f(r))return;const n=r.raw;if(typeof n!="string"||n.length===0)return;const c=n.charAt(0);c==="'"?o+=1:c==='"'&&(i+=1)}),o>i?"single":"double"}s(m,"detectQuoteStyle");function g(t,o){const i=[t];for(;i.length>0;){const e=i.pop();if(!(!f(e)||typeof e.type!="string")){o(e);for(const r of Object.keys(e)){if(r==="loc"||r==="comments"||r==="tokens")continue;const n=e[r];if(Array.isArray(n))for(const c of n)f(c)&&typeof c.type=="string"&&i.push(c);else f(n)&&typeof n.type=="string"&&i.push(n)}}}}s(g,"visit");function f(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}s(f,"isRecord");export{y as detectLineTerminator,m as detectQuoteStyle,h as printFile};
@@ -1 +1 @@
1
- function o(t){return`${t}.bak`}function a(t,r){const n=r.toISOString().replaceAll(":","");return`${t}/${n}.ts`}export{o as backupPath,a as historyEntryPath};
1
+ var a=Object.defineProperty;var n=(t,r)=>a(t,"name",{value:r,configurable:!0});function c(t){return`${t}.bak`}n(c,"backupPath");function p(t,r){const o=r.toISOString().replaceAll(":","");return`${t}/${o}.ts`}n(p,"historyEntryPath");export{c as backupPath,p as historyEntryPath};
@@ -1 +1 @@
1
- import{failure as a,success as c}from"../types/Result.js";import{DEFAULT_FILE_PATH as m}from"./_internal.js";import{locateAllShapes as l}from"./semanticIndex/index.js";function f(t,s=m){const r=l(t,s);if(!r.success)return a(r.error);const o=r.data.map(e=>({type:e.type,name:e.symbolName,filePath:e.filePath,start:e.start,length:e.length}));return c({filePath:s,resources:o})}export{f as listResources};
1
+ var c=Object.defineProperty;var o=(s,r)=>c(s,"name",{value:r,configurable:!0});import{failure as m,success as l}from"../types/Result.js";import{DEFAULT_FILE_PATH as n}from"./_internal.js";import{locateAllShapes as p}from"./semanticIndex/index.js";function A(s,r=n){const t=p(s,r);if(!t.success)return m(t.error);const a=t.data.map(e=>({type:e.type,name:e.symbolName,filePath:e.filePath,start:e.start,length:e.length}));return l({filePath:r,resources:a})}o(A,"listResources");export{A as listResources};
@@ -1 +1 @@
1
- import{success as l,failure as d}from"../../types/Result.js";function x(c,r){let e=c,n=0,o=0;for(let i=0;i<r.length;i+=1){const t=r[i];if(t===void 0)continue;const s=e.indexOf(t.old_str);if(s===-1){o+=1;continue}if(e.indexOf(t.old_str,s+1)!==-1)return d({kind:"ambiguous-str-replace",opIndex:i,old_str:t.old_str,matchCount:u(e,t.old_str)});e=e.slice(0,s)+t.new_str+e.slice(s+t.old_str.length),n+=1}return l({content:e,appliedCount:n,skippedCount:o})}function u(c,r){let e=0,n=0;for(;;){const o=c.indexOf(r,n);if(o===-1)break;e+=1,n=o+1}return e}export{x as applyStrReplaceOps};
1
+ var d=Object.defineProperty;var l=(o,n)=>d(o,"name",{value:n,configurable:!0});import{success as u,failure as f}from"../../types/Result.js";function O(o,n){let e=o,r=0,i=0;for(let s=0;s<n.length;s+=1){const t=n[s];if(t===void 0)continue;const c=e.indexOf(t.old_str);if(c===-1){i+=1;continue}if(e.indexOf(t.old_str,c+1)!==-1)return f({kind:"ambiguous-str-replace",opIndex:s,old_str:t.old_str,matchCount:p(e,t.old_str)});e=e.slice(0,c)+t.new_str+e.slice(c+t.old_str.length),r+=1}return u({content:e,appliedCount:r,skippedCount:i})}l(O,"applyStrReplaceOps");function p(o,n){let e=0,r=0;for(;;){const i=o.indexOf(n,r);if(i===-1)break;e+=1,r=i+1}return e}l(p,"countOccurrences");export{O as applyStrReplaceOps};
@@ -1 +1 @@
1
- import{gateEgress as p}from"./egressGate.js";import{buildPrompt as y}from"./prompt.js";import{applyStrReplaceOps as k}from"./apply.js";import{withTierTimeout as E}from"./tierRunner.js";import{PARSE_GATE as u}from"./types.js";const b=3e4,o="claude",m={name:"str_replace_based_edit_tool",type:"text_editor_20250728"};async function S(t,s){if(!t.orgAllowsFallback)return{state:"disabled",reason:"org-opt-out"};const r=p(t.content,o);if(r!==void 0)return r;const e=p(JSON.stringify(t.intent.properties),o);if(e!==void 0)return e;const{systemPrompt:i,userPrompt:c}=y({content:t.content,intent:t.intent,tier:o});return E(t.abortSignal,o,b,async({signal:f,started:_})=>{const a=await s.create({model:s.resolveModelId(),max_tokens:4096,system:i,messages:[{role:"user",content:c}],tools:[m],signal:f}),g=Date.now()-_,d=w(a.content);if(d.length===0)return{state:"rejected",tier:o,failedGate:u,diagnostics:"Model produced no str_replace operations"};const n=k(t.content,d);if(!n.success)return{state:"rejected",tier:o,failedGate:u,diagnostics:`Ambiguous str_replace at op ${n.error.opIndex}: "${n.error.old_str.slice(0,40)}\u2026" matched ${n.error.matchCount} times`};const l=p(n.data.content,o);if(l!==void 0)return l;const T={tier:o,elapsedMs:g,inputTokens:a.usage?.input_tokens??0,outputTokens:a.usage?.output_tokens??0,opsApplied:n.data.appliedCount};return{state:"applied",content:n.data.content,telemetry:T}})}function w(t){const s=[];for(const r of t){if(r.type!=="tool_use"||r.name!==m.name)continue;const e=r.input;if(!("command"in e)||e.command!=="str_replace"||!("old_str"in e)||!("new_str"in e))continue;const i=e.old_str,c=e.new_str;typeof i!="string"||typeof c!="string"||s.push({old_str:i,new_str:c})}return s}export{m as TEXT_EDITOR_TOOL,S as runClaudeTier};
1
+ var k=Object.defineProperty;var p=(t,n)=>k(t,"name",{value:n,configurable:!0});import{gateEgress as d}from"./egressGate.js";import{buildPrompt as E}from"./prompt.js";import{applyStrReplaceOps as b}from"./apply.js";import{withTierTimeout as w}from"./tierRunner.js";import{PARSE_GATE as m}from"./types.js";const O=3e4,o="claude",f={name:"str_replace_based_edit_tool",type:"text_editor_20250728"};async function P(t,n){if(!t.orgAllowsFallback)return{state:"disabled",reason:"org-opt-out"};const s=d(t.content,o);if(s!==void 0)return s;const e=d(JSON.stringify(t.intent.properties),o);if(e!==void 0)return e;const{systemPrompt:i,userPrompt:c}=E({content:t.content,intent:t.intent,tier:o});return w(t.abortSignal,o,O,async({signal:_,started:g})=>{const a=await n.create({model:n.resolveModelId(),max_tokens:4096,system:i,messages:[{role:"user",content:c}],tools:[f],signal:_}),T=Date.now()-g,l=x(a.content);if(l.length===0)return{state:"rejected",tier:o,failedGate:m,diagnostics:"Model produced no str_replace operations"};const r=b(t.content,l);if(!r.success)return{state:"rejected",tier:o,failedGate:m,diagnostics:`Ambiguous str_replace at op ${r.error.opIndex}: "${r.error.old_str.slice(0,40)}\u2026" matched ${r.error.matchCount} times`};const u=d(r.data.content,o);if(u!==void 0)return u;const y={tier:o,elapsedMs:T,inputTokens:a.usage?.input_tokens??0,outputTokens:a.usage?.output_tokens??0,opsApplied:r.data.appliedCount};return{state:"applied",content:r.data.content,telemetry:y}})}p(P,"runClaudeTier");function x(t){const n=[];for(const s of t){if(s.type!=="tool_use"||s.name!==f.name)continue;const e=s.input;if(!("command"in e)||e.command!=="str_replace"||!("old_str"in e)||!("new_str"in e))continue;const i=e.old_str,c=e.new_str;typeof i!="string"||typeof c!="string"||n.push({old_str:i,new_str:c})}return n}p(x,"extractStrReplaceOps");export{f as TEXT_EDITOR_TOOL,P as runClaudeTier};
@@ -1 +1 @@
1
- const E=32,l=4.5,T=8,c=/\barn:aws:[a-z0-9-]+:[a-z0-9-]*:[0-9]*:[^\s"']+/g,a=/(?<![A-Za-z0-9+/=_-])[A-Za-z0-9+/=_-]{32,}(?![A-Za-z0-9+/=_-])/g;function _(t){if(t.length===0)return 0;const e=new Map;for(const o of t)e.set(o,(e.get(o)??0)+1);let n=0;for(const o of e.values()){const s=o/t.length;n-=s*Math.log2(s)}return n}function r(t){return t.length<=8?t:`${t.slice(0,8)}\u2026`}function H(t){const e=[...t.matchAll(c)];if(e.length>0){const o=e[0]?.[0]??"";return{state:"block",reason:"arn-shape",count:e.length,sampleHint:r(o)}}const n=[];for(const o of t.matchAll(a)){const s=o[0]??"";s.length>=32&&_(s)>=4.5&&n.push(s)}return n.length>0?{state:"block",reason:"high-entropy",count:n.length,sampleHint:r(n[0]??"")}:{state:"pass"}}function h(t,e){const n=H(t);if(n.state==="block")return{state:"egress-blocked",tier:e,reason:n.reason,count:n.count}}export{h as gateEgress,H as scanForEgressRisk};
1
+ var a=Object.defineProperty;var r=(t,n)=>a(t,"name",{value:n,configurable:!0});const h=32,u=4.5,f=8,_=/\barn:aws:[a-z0-9-]+:[a-z0-9-]*:[0-9]*:[^\s"']+/g,H=/(?<![A-Za-z0-9+/=_-])[A-Za-z0-9+/=_-]{32,}(?![A-Za-z0-9+/=_-])/g;function E(t){if(t.length===0)return 0;const n=new Map;for(const o of t)n.set(o,(n.get(o)??0)+1);let e=0;for(const o of n.values()){const s=o/t.length;e-=s*Math.log2(s)}return e}r(E,"shannonEntropy");function c(t){return t.length<=8?t:`${t.slice(0,8)}\u2026`}r(c,"truncateHint");function l(t){const n=[...t.matchAll(_)];if(n.length>0){const o=n[0]?.[0]??"";return{state:"block",reason:"arn-shape",count:n.length,sampleHint:c(o)}}const e=[];for(const o of t.matchAll(H)){const s=o[0]??"";s.length>=32&&E(s)>=4.5&&e.push(s)}return e.length>0?{state:"block",reason:"high-entropy",count:e.length,sampleHint:c(e[0]??"")}:{state:"pass"}}r(l,"scanForEgressRisk");function g(t,n){const e=l(t);if(e.state==="block")return{state:"egress-blocked",tier:n,reason:e.reason,count:e.count}}r(g,"gateEgress");export{g as gateEgress,l as scanForEgressRisk};
@@ -1,3 +1,3 @@
1
- import{gateEgress as o}from"./egressGate.js";import{buildPrompt as g}from"./prompt.js";import{withTierTimeout as m}from"./tierRunner.js";import{PARSE_GATE as T}from"./types.js";const k=15e3,t="morph";async function M(e,r){if(!e.orgAllowsFallback)return{state:"disabled",reason:"org-opt-out"};if(!r.isAvailable())return{state:"disabled",reason:"env-flag"};const s=o(e.content,t);if(s!==void 0)return s;const i=o(JSON.stringify(e.intent.properties),t);if(i!==void 0)return i;const{systemPrompt:c,userPrompt:p}=g({content:e.content,intent:e.intent,tier:t});return m(e.abortSignal,t,k,async({signal:u,started:l})=>{const n=await r.apply({originalFile:e.content,update:`${c}
1
+ var m=Object.defineProperty;var c=(e,o)=>m(e,"name",{value:o,configurable:!0});import{gateEgress as r}from"./egressGate.js";import{buildPrompt as T}from"./prompt.js";import{withTierTimeout as k}from"./tierRunner.js";import{PARSE_GATE as E}from"./types.js";const b=15e3,t="morph";async function _(e,o){if(!e.orgAllowsFallback)return{state:"disabled",reason:"org-opt-out"};if(!o.isAvailable())return{state:"disabled",reason:"env-flag"};const s=r(e.content,t);if(s!==void 0)return s;const i=r(JSON.stringify(e.intent.properties),t);if(i!==void 0)return i;const{systemPrompt:p,userPrompt:u}=T({content:e.content,intent:e.intent,tier:t});return k(e.abortSignal,t,b,async({signal:l,started:d})=>{const n=await o.apply({originalFile:e.content,update:`${p}
2
2
 
3
- ${p}`,signal:u}),d=Date.now()-l;if(n.content===e.content)return{state:"rejected",tier:t,failedGate:T,diagnostics:"Morph returned unchanged content"};const a=o(n.content,t);if(a!==void 0)return a;const f={tier:t,elapsedMs:d,inputTokens:n.usage?.inputTokens??0,outputTokens:n.usage?.outputTokens??0,opsApplied:1};return{state:"applied",content:n.content,telemetry:f}})}export{M as runMorphTier};
3
+ ${u}`,signal:l}),f=Date.now()-d;if(n.content===e.content)return{state:"rejected",tier:t,failedGate:E,diagnostics:"Morph returned unchanged content"};const a=r(n.content,t);if(a!==void 0)return a;const g={tier:t,elapsedMs:f,inputTokens:n.usage?.inputTokens??0,outputTokens:n.usage?.outputTokens??0,opsApplied:1};return{state:"applied",content:n.content,telemetry:g}})}c(_,"runMorphTier");export{_ as runMorphTier};