@terraforge/terraform 0.0.26 → 0.0.28
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 +39 -6
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -235,6 +235,24 @@ const sortStateValues = (values) => {
|
|
|
235
235
|
return 0;
|
|
236
236
|
});
|
|
237
237
|
};
|
|
238
|
+
const tryNormalizeJsonString = (value) => {
|
|
239
|
+
const trimmed = value.trim();
|
|
240
|
+
if (!(trimmed.startsWith("{") || trimmed.startsWith("["))) return value;
|
|
241
|
+
try {
|
|
242
|
+
return stableStringify(JSON.parse(trimmed));
|
|
243
|
+
} catch {
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const uniqueStateValues = (values) => {
|
|
248
|
+
const seen = /* @__PURE__ */ new Set();
|
|
249
|
+
return values.filter((value) => {
|
|
250
|
+
const key = stableStringify(value);
|
|
251
|
+
if (seen.has(key)) return false;
|
|
252
|
+
seen.add(key);
|
|
253
|
+
return true;
|
|
254
|
+
});
|
|
255
|
+
};
|
|
238
256
|
const encodeDynamicValue = (value) => {
|
|
239
257
|
return {
|
|
240
258
|
msgpack: pack(value),
|
|
@@ -297,22 +315,34 @@ const hasInputValue = (value) => typeof value !== "undefined";
|
|
|
297
315
|
const shouldIncludeFieldForComparison = (schema, inputValue) => {
|
|
298
316
|
return schema.required || hasInputValue(inputValue);
|
|
299
317
|
};
|
|
318
|
+
const isContainerSchema = (schema) => {
|
|
319
|
+
return [
|
|
320
|
+
"array",
|
|
321
|
+
"record",
|
|
322
|
+
"object",
|
|
323
|
+
"array-object"
|
|
324
|
+
].includes(schema.type);
|
|
325
|
+
};
|
|
300
326
|
const normalizeStateForComparison = (schema, state, inputState) => {
|
|
301
327
|
if (!shouldIncludeFieldForComparison(schema, inputState)) return;
|
|
328
|
+
if ((state === null || typeof state === "undefined") && isContainerSchema(schema) && isEmptyOutputValue(inputState)) state = inputState;
|
|
302
329
|
if (state === null || typeof state === "undefined") return state;
|
|
303
330
|
if (schema.type === "array") {
|
|
304
331
|
if (!Array.isArray(state)) return state;
|
|
305
|
-
const
|
|
332
|
+
const filtered = state.map((item, index) => {
|
|
306
333
|
const inputItem = Array.isArray(inputState) ? inputState[index] : void 0;
|
|
307
334
|
return normalizeStateForComparison(schema.item, item, inputItem);
|
|
308
|
-
});
|
|
309
|
-
|
|
335
|
+
}).filter((item) => typeof item !== "undefined");
|
|
336
|
+
if (schema.collectionKind === "set") return sortStateValues(uniqueStateValues(filtered.filter((item) => item !== null)));
|
|
337
|
+
return filtered;
|
|
310
338
|
}
|
|
311
339
|
if (schema.type === "record") {
|
|
312
340
|
if (typeof state !== "object" || state === null) return state;
|
|
313
|
-
return Object.fromEntries(Object.entries(state).
|
|
341
|
+
return Object.fromEntries(Object.entries(state).flatMap(([key, value]) => {
|
|
314
342
|
const inputValue = inputState && typeof inputState === "object" ? inputState[key] : void 0;
|
|
315
|
-
|
|
343
|
+
const normalized = normalizeStateForComparison(schema.item, value, inputValue);
|
|
344
|
+
if (typeof normalized === "undefined") return [];
|
|
345
|
+
return [[key, normalized]];
|
|
316
346
|
}));
|
|
317
347
|
}
|
|
318
348
|
if (schema.type === "object") {
|
|
@@ -333,6 +363,9 @@ const normalizeStateForComparison = (schema, state, inputState) => {
|
|
|
333
363
|
return [[camelCase(key), normalized]];
|
|
334
364
|
}));
|
|
335
365
|
}
|
|
366
|
+
if (schema.type === "string") {
|
|
367
|
+
if (typeof state === "string") return tryNormalizeJsonString(state);
|
|
368
|
+
}
|
|
336
369
|
return state;
|
|
337
370
|
};
|
|
338
371
|
const formatInputState = (schema, state, includeSchemaFields = true, path = []) => {
|
|
@@ -521,7 +554,7 @@ var TerraformProvider = class {
|
|
|
521
554
|
if (!refreshedState) return { kind: "deleted" };
|
|
522
555
|
const normalizedPriorInputState = normalizeStateForComparison(schema, priorInputState, priorInputState);
|
|
523
556
|
const normalizedRefreshedState = normalizeStateForComparison(schema, refreshedState, priorInputState);
|
|
524
|
-
if (
|
|
557
|
+
if (stableStringify(normalizedPriorInputState) === stableStringify(normalizedRefreshedState)) return {
|
|
525
558
|
kind: "unchanged",
|
|
526
559
|
state: refreshedState
|
|
527
560
|
};
|