@terraforge/terraform 0.0.14 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +45 -12
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1966,6 +1966,23 @@ const formatAttributePath = (state) => {
|
|
|
1966
1966
|
});
|
|
1967
1967
|
});
|
|
1968
1968
|
};
|
|
1969
|
+
const getNestedValue = (obj, path) => {
|
|
1970
|
+
let current = obj;
|
|
1971
|
+
for (const key of path) {
|
|
1972
|
+
if (current === null || current === void 0) return current;
|
|
1973
|
+
if (Array.isArray(current)) current = current[key];
|
|
1974
|
+
else if (typeof current === "object") current = current[key];
|
|
1975
|
+
else return;
|
|
1976
|
+
}
|
|
1977
|
+
return current;
|
|
1978
|
+
};
|
|
1979
|
+
const filterRequiresReplace = (paths, priorState, proposedState) => {
|
|
1980
|
+
return paths.filter((path) => {
|
|
1981
|
+
const priorValue = getNestedValue(priorState, path);
|
|
1982
|
+
const proposedValue = getNestedValue(proposedState, path);
|
|
1983
|
+
return JSON.stringify(priorValue) !== JSON.stringify(proposedValue);
|
|
1984
|
+
});
|
|
1985
|
+
};
|
|
1969
1986
|
var IncorrectType = class extends TypeError {
|
|
1970
1987
|
constructor(type, path) {
|
|
1971
1988
|
super(`${path.join(".")} should be a ${type}`);
|
|
@@ -2018,7 +2035,7 @@ const formatInputState = (schema, state, includeSchemaFields = true, path = [])
|
|
|
2018
2035
|
throw new Error(`Unknown schema type: ${schema.type}`);
|
|
2019
2036
|
};
|
|
2020
2037
|
const formatOutputState = (schema, state, path = []) => {
|
|
2021
|
-
if (state === null) return;
|
|
2038
|
+
if (state === null) return null;
|
|
2022
2039
|
if (schema.type === "array") {
|
|
2023
2040
|
if (Array.isArray(state)) return state.map((item, i) => formatOutputState(schema.item, item, [...path, i]));
|
|
2024
2041
|
throw new IncorrectType(schema.type, path);
|
|
@@ -2050,7 +2067,7 @@ const formatOutputState = (schema, state, path = []) => {
|
|
|
2050
2067
|
object[camelCase(key)] = formatOutputState(prop, value, [...path, key]);
|
|
2051
2068
|
}
|
|
2052
2069
|
return object;
|
|
2053
|
-
} else return;
|
|
2070
|
+
} else return null;
|
|
2054
2071
|
throw new IncorrectType(schema.type, path);
|
|
2055
2072
|
}
|
|
2056
2073
|
return state;
|
|
@@ -2103,28 +2120,36 @@ const createPlugin5 = async ({ server, client }) => {
|
|
|
2103
2120
|
async planResourceChange(type, priorState, proposedState) {
|
|
2104
2121
|
const schema$1 = getResourceSchema(resources, type);
|
|
2105
2122
|
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2106
|
-
const preparedProposedState = formatInputState(schema$1,
|
|
2123
|
+
const preparedProposedState = formatInputState(schema$1, {
|
|
2124
|
+
...priorState,
|
|
2125
|
+
...proposedState
|
|
2126
|
+
});
|
|
2127
|
+
const configState = formatInputState(schema$1, proposedState);
|
|
2107
2128
|
const plan = await client.call("PlanResourceChange", {
|
|
2108
2129
|
typeName: type,
|
|
2109
2130
|
priorState: encodeDynamicValue(preparedPriorState),
|
|
2110
2131
|
proposedNewState: encodeDynamicValue(preparedProposedState),
|
|
2111
|
-
config: encodeDynamicValue(
|
|
2132
|
+
config: encodeDynamicValue(configState)
|
|
2112
2133
|
});
|
|
2113
2134
|
const plannedState = decodeDynamicValue(plan.plannedState);
|
|
2114
2135
|
return {
|
|
2115
|
-
requiresReplace: formatAttributePath(plan.requiresReplace),
|
|
2136
|
+
requiresReplace: filterRequiresReplace(formatAttributePath(plan.requiresReplace), preparedPriorState, preparedProposedState),
|
|
2116
2137
|
plannedState
|
|
2117
2138
|
};
|
|
2118
2139
|
},
|
|
2119
2140
|
async applyResourceChange(type, priorState, proposedState) {
|
|
2120
2141
|
const schema$1 = getResourceSchema(resources, type);
|
|
2121
2142
|
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2122
|
-
const preparedProposedState = formatInputState(schema$1,
|
|
2143
|
+
const preparedProposedState = formatInputState(schema$1, {
|
|
2144
|
+
...priorState,
|
|
2145
|
+
...proposedState
|
|
2146
|
+
});
|
|
2147
|
+
const configState = formatInputState(schema$1, proposedState);
|
|
2123
2148
|
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
|
|
2124
2149
|
typeName: type,
|
|
2125
2150
|
priorState: encodeDynamicValue(preparedPriorState),
|
|
2126
2151
|
plannedState: encodeDynamicValue(preparedProposedState),
|
|
2127
|
-
config: encodeDynamicValue(
|
|
2152
|
+
config: encodeDynamicValue(configState)
|
|
2128
2153
|
})).newState));
|
|
2129
2154
|
}
|
|
2130
2155
|
};
|
|
@@ -2177,28 +2202,36 @@ const createPlugin6 = async ({ server, client }) => {
|
|
|
2177
2202
|
async planResourceChange(type, priorState, proposedState) {
|
|
2178
2203
|
const schema$1 = getResourceSchema(resources, type);
|
|
2179
2204
|
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2180
|
-
const preparedProposedState = formatInputState(schema$1,
|
|
2205
|
+
const preparedProposedState = formatInputState(schema$1, {
|
|
2206
|
+
...priorState,
|
|
2207
|
+
...proposedState
|
|
2208
|
+
});
|
|
2209
|
+
const configState = formatInputState(schema$1, proposedState);
|
|
2181
2210
|
const plan = await client.call("PlanResourceChange", {
|
|
2182
2211
|
typeName: type,
|
|
2183
2212
|
priorState: encodeDynamicValue(preparedPriorState),
|
|
2184
2213
|
proposedNewState: encodeDynamicValue(preparedProposedState),
|
|
2185
|
-
config: encodeDynamicValue(
|
|
2214
|
+
config: encodeDynamicValue(configState)
|
|
2186
2215
|
});
|
|
2187
2216
|
const plannedState = decodeDynamicValue(plan.plannedState);
|
|
2188
2217
|
return {
|
|
2189
|
-
requiresReplace: formatAttributePath(plan.requiresReplace),
|
|
2218
|
+
requiresReplace: filterRequiresReplace(formatAttributePath(plan.requiresReplace), preparedPriorState, preparedProposedState),
|
|
2190
2219
|
plannedState
|
|
2191
2220
|
};
|
|
2192
2221
|
},
|
|
2193
2222
|
async applyResourceChange(type, priorState, proposedState) {
|
|
2194
2223
|
const schema$1 = getResourceSchema(resources, type);
|
|
2195
2224
|
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2196
|
-
const preparedProposedState = formatInputState(schema$1,
|
|
2225
|
+
const preparedProposedState = formatInputState(schema$1, {
|
|
2226
|
+
...priorState,
|
|
2227
|
+
...proposedState
|
|
2228
|
+
});
|
|
2229
|
+
const configState = formatInputState(schema$1, proposedState);
|
|
2197
2230
|
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
|
|
2198
2231
|
typeName: type,
|
|
2199
2232
|
priorState: encodeDynamicValue(preparedPriorState),
|
|
2200
2233
|
plannedState: encodeDynamicValue(preparedProposedState),
|
|
2201
|
-
config: encodeDynamicValue(
|
|
2234
|
+
config: encodeDynamicValue(configState)
|
|
2202
2235
|
})).newState));
|
|
2203
2236
|
}
|
|
2204
2237
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terraforge/terraform",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test": "bun test"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@terraforge/core": "0.0.
|
|
29
|
+
"@terraforge/core": "0.0.19"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@grpc/grpc-js": "1.12.6",
|