@terraforge/core 0.0.32 → 0.0.33

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 (2) hide show
  1. package/dist/index.mjs +18 -7
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1122,16 +1122,17 @@ const hydrate = async (app, opt) => {
1122
1122
  const copy = (value) => {
1123
1123
  return JSON.parse(JSON.stringify(value));
1124
1124
  };
1125
- const createDeleteOperation = (urn, stackState) => {
1125
+ const createDeleteOperation = (urn, stackState, onCommit) => {
1126
1126
  return {
1127
1127
  urn,
1128
1128
  operation: "delete",
1129
1129
  commit() {
1130
1130
  delete stackState.nodes[urn];
1131
+ onCommit();
1131
1132
  }
1132
1133
  };
1133
1134
  };
1134
- const createUpdateOperation = (urn, state, before, after, nodeState) => {
1135
+ const createUpdateOperation = (urn, state, before, after, nodeState, onCommit) => {
1135
1136
  return {
1136
1137
  urn,
1137
1138
  operation: "update",
@@ -1140,6 +1141,7 @@ const createUpdateOperation = (urn, state, before, after, nodeState) => {
1140
1141
  commit() {
1141
1142
  nodeState.output = state;
1142
1143
  nodeState.drifted = true;
1144
+ onCommit();
1143
1145
  }
1144
1146
  };
1145
1147
  };
@@ -1150,6 +1152,7 @@ const refresh = async (app, opt) => {
1150
1152
  if (opt.filters && opt.filters.length > 0) filteredStacks = Object.values(appState?.stacks ?? {}).filter((stackState) => {
1151
1153
  return opt.filters.includes(stackState.name);
1152
1154
  });
1155
+ let committed = 0;
1153
1156
  if (appState && filteredStacks.length > 0) {
1154
1157
  const filteredOperations = (await Promise.all(filteredStacks.map((stackState) => {
1155
1158
  return Promise.all(Object.entries(stackState.nodes).map(([_urn, nodeState]) => {
@@ -1161,9 +1164,13 @@ const refresh = async (app, opt) => {
1161
1164
  type: nodeState.type,
1162
1165
  state: nodeState.output
1163
1166
  });
1164
- if (!result) return createDeleteOperation(urn, stackState);
1167
+ if (!result) return createDeleteOperation(urn, stackState, () => {
1168
+ committed++;
1169
+ });
1165
1170
  if (compareState(result.state, nodeState.output)) return;
1166
- return createUpdateOperation(urn, result.state, nodeState.input, result.state, nodeState);
1171
+ return createUpdateOperation(urn, result.state, nodeState.input, result.state, nodeState, () => {
1172
+ committed++;
1173
+ });
1167
1174
  }
1168
1175
  if (!provider.refreshResource) return;
1169
1176
  const refreshed = await provider.refreshResource({
@@ -1172,8 +1179,12 @@ const refresh = async (app, opt) => {
1172
1179
  priorOutputState: nodeState.output
1173
1180
  });
1174
1181
  if (!refreshed || refreshed.kind === "unchanged") return;
1175
- if (refreshed.kind === "deleted") return createDeleteOperation(urn, stackState);
1176
- return createUpdateOperation(urn, refreshed.state, nodeState.input, refreshed.inputState, nodeState);
1182
+ if (refreshed.kind === "deleted") return createDeleteOperation(urn, stackState, () => {
1183
+ committed++;
1184
+ });
1185
+ return createUpdateOperation(urn, refreshed.state, nodeState.input, refreshed.inputState, nodeState, () => {
1186
+ committed++;
1187
+ });
1177
1188
  });
1178
1189
  }));
1179
1190
  }))).flat().filter((op) => !!op);
@@ -1181,7 +1192,7 @@ const refresh = async (app, opt) => {
1181
1192
  return {
1182
1193
  operations: filteredOperations,
1183
1194
  async commit() {
1184
- await opt.backend.state.update(app.urn, appState);
1195
+ if (committed > 0) await opt.backend.state.update(app.urn, appState);
1185
1196
  }
1186
1197
  };
1187
1198
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraforge/core",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",