Skip to content

Commit

Permalink
fix(graph): Make graph immutable (#693)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Muesch <michael.muesch@architect.io>
Co-authored-by: TJ Higgins <tj@architect.io>
  • Loading branch information
3 people authored Sep 6, 2022
1 parent f96e01e commit 6753170
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/dependency-manager/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GatewayNode } from './node/gateway';
import { ServiceNode } from './node/service';
import { TaskNode } from './node/task';

export class DependencyGraph {
export class DependencyGraphMutable {
@Type(() => DependencyNode, {
discriminator: {
property: '__type',
Expand Down Expand Up @@ -254,3 +254,5 @@ export class DependencyGraph {
return false;
}
}

export type DependencyGraph = Readonly<DependencyGraphMutable>;
6 changes: 3 additions & 3 deletions src/dependency-manager/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { classToPlain, plainToClass, serialize } from 'class-transformer';
import { isMatch } from 'matcher';
import { buildInterfacesRef, buildNodeRef, ComponentConfig } from './config/component-config';
import { ArchitectContext, ComponentContext, SecretValue } from './config/component-context';
import { DependencyGraph } from './graph';
import { DependencyGraph, DependencyGraphMutable } from './graph';
import { IngressEdge } from './graph/edge/ingress';
import { OutputEdge } from './graph/edge/output';
import { ServiceEdge } from './graph/edge/service';
Expand Down Expand Up @@ -576,7 +576,7 @@ export default abstract class DependencyManager {

const interpolateObject = options.validate ? interpolateObjectOrReject : interpolateObjectLoose;

const graph = new DependencyGraph();
const graph = new DependencyGraphMutable();

const context_map: Dictionary<ComponentContext> = {};
const dependency_context_map: Dictionary<ComponentContext> = {};
Expand Down Expand Up @@ -708,6 +708,6 @@ export default abstract class DependencyManager {
graph.validated = true;
}

return graph;
return Object.freeze(graph);
}
}

0 comments on commit 6753170

Please sign in to comment.