@terraforge/core 0.0.21 → 0.0.23

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/README.md CHANGED
@@ -18,13 +18,15 @@ npm i @terraforge/core @terraforge/terraform @terraforge/aws
18
18
  ## Example
19
19
 
20
20
  First, you need to create a workspace instance and pass in the cloud providers that you will use.
21
- We also need to give it a lock provider & state provider.
21
+ We also need to give it a lock backend & state backend.
22
22
 
23
23
  - A cloud provider is used to create resources on a specific cloud provider. We have built-in cloud providers for AWS resources, but you could simply add your own as well.
24
24
 
25
- - The state provider is used for storing the latest deployment state.
25
+ - The state backend is used for storing the latest deployment state.
26
26
 
27
- - The lock provider is used for acquiring a lock when you deploy your app. This will guarantee that multiple people can never deploy the same application at the same time.
27
+ - The lock backend is used for acquiring a lock when you deploy your app. This will guarantee that multiple people can never deploy the same application at the same time.
28
+
29
+ - The activity log backend is used for storing the activity log when every you deploy / delete your app.
28
30
 
29
31
  In this example, we will use a local file lock & state provider.
30
32
 
package/dist/index.d.mts CHANGED
@@ -355,7 +355,7 @@ declare class WorkSpace {
355
355
  /**
356
356
  * Refresh the state of the resources & data-sources inside your app.
357
357
  */
358
- refresh(app: App): Promise<void>;
358
+ refresh(app: App, options?: ProcedureOptions): Promise<void>;
359
359
  /**
360
360
  * Get the status of all resources in the app by comparing current config with state file.
361
361
  */
package/dist/index.mjs CHANGED
@@ -984,25 +984,31 @@ const deployApp = async (app, opt) => {
984
984
  let newResourceState;
985
985
  const ignoreReplace = forcedUpdateDependents.has(meta$1.urn);
986
986
  if (!ignoreReplace && requiresReplacement(nodeState.input, input, meta$1.config?.replaceOnChanges ?? [])) if (meta$1.config?.createBeforeReplace) {
987
- for (const [dependentUrn, dependentNode] of nodeByUrn.entries()) {
988
- if (!isResource(dependentNode)) continue;
989
- const dependentMeta = getMeta(dependentNode);
990
- if (!dependentMeta.dependencies.has(meta$1.urn)) continue;
991
- const dependentStackState = stackStates.get(dependentMeta.stack.urn);
992
- const dependentState = dependentStackState?.nodes[dependentUrn];
993
- if (!dependentStackState || !dependentState) continue;
994
- const dependencyPaths = findDependencyPaths(dependentMeta.input, meta$1.urn);
995
- if (dependencyPaths.length === 0) continue;
996
- const dependentProvider = findProvider(opt.providers, dependentMeta.provider);
997
- if (dependentProvider.planResourceChange) {
998
- if ((await dependentProvider.planResourceChange({
999
- type: dependentMeta.type,
1000
- priorState: dependentState.output,
1001
- proposedState: input
1002
- })).requiresReplacement) {
1003
- if (!allowsDependentReplace(dependentMeta.config?.replaceOnChanges, dependencyPaths)) throw ResourceError.wrap(dependentMeta.urn, dependentMeta.type, "update", /* @__PURE__ */ new Error(`Replacing ${meta$1.urn} requires ${dependentMeta.urn} to set replaceOnChanges for its dependency fields.`));
987
+ meta$1.resolve(input);
988
+ try {
989
+ for (const [dependentUrn, dependentNode] of nodeByUrn.entries()) {
990
+ if (!isResource(dependentNode)) continue;
991
+ const dependentMeta = getMeta(dependentNode);
992
+ if (!dependentMeta.dependencies.has(meta$1.urn)) continue;
993
+ const dependentStackState = stackStates.get(dependentMeta.stack.urn);
994
+ const dependentState = dependentStackState?.nodes[dependentUrn];
995
+ if (!dependentStackState || !dependentState) continue;
996
+ const dependencyPaths = findDependencyPaths(dependentMeta.input, meta$1.urn);
997
+ if (dependencyPaths.length === 0) continue;
998
+ const dependentProvider = findProvider(opt.providers, dependentMeta.provider);
999
+ if (dependentProvider.planResourceChange) {
1000
+ const dependentProposedInput = await resolveInputs(dependentMeta.input);
1001
+ if ((await dependentProvider.planResourceChange({
1002
+ type: dependentMeta.type,
1003
+ priorState: dependentState.output,
1004
+ proposedState: dependentProposedInput
1005
+ })).requiresReplacement) {
1006
+ if (!allowsDependentReplace(dependentMeta.config?.replaceOnChanges, dependencyPaths)) throw ResourceError.wrap(dependentMeta.urn, dependentMeta.type, "update", /* @__PURE__ */ new Error(`Replacing ${meta$1.urn} requires ${dependentMeta.urn} to set replaceOnChanges for its dependency fields.`));
1007
+ }
1004
1008
  }
1005
1009
  }
1010
+ } finally {
1011
+ meta$1.resolve(nodeState.output);
1006
1012
  }
1007
1013
  const priorState = { ...nodeState };
1008
1014
  newResourceState = await createResource(node, appState.idempotentToken, input, opt);
@@ -1108,8 +1114,12 @@ const hydrate = async (app, opt) => {
1108
1114
  const refresh = async (app, opt) => {
1109
1115
  const appState = await opt.backend.state.get(app.urn);
1110
1116
  const queue = createConcurrencyQueue(opt.concurrency ?? 10);
1111
- if (appState) {
1112
- await Promise.all(Object.values(appState.stacks).map((stackState) => {
1117
+ let filteredStacks = [];
1118
+ if (opt.filters && opt.filters.length > 0) filteredStacks = Object.entries(appState?.stacks ?? {}).filter(([stackName]) => {
1119
+ return opt.filters.includes(stackName);
1120
+ }).map(([_, state]) => state);
1121
+ if (appState && filteredStacks.length > 0) {
1122
+ await Promise.all(filteredStacks.map((stackState) => {
1113
1123
  return Promise.all(Object.values(stackState.nodes).map((nodeState) => {
1114
1124
  return queue(async () => {
1115
1125
  const provider = findProvider(opt.providers, nodeState.provider);
@@ -1290,10 +1300,13 @@ var WorkSpace = class {
1290
1300
  /**
1291
1301
  * Refresh the state of the resources & data-sources inside your app.
1292
1302
  */
1293
- refresh(app) {
1303
+ refresh(app, options = {}) {
1294
1304
  return lockApp(this.props.backend.lock, app, async () => {
1295
1305
  try {
1296
- await refresh(app, this.props);
1306
+ await refresh(app, {
1307
+ ...this.props,
1308
+ ...options
1309
+ });
1297
1310
  } finally {
1298
1311
  await this.destroyProviders();
1299
1312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraforge/core",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",