@quadnix/octo 0.0.2 → 0.0.3
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/package.json +6 -1
- package/.eslintrc.cjs +0 -26
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/src/app.type.ts +0 -56
- package/src/decorators/action.decorator.spec.ts +0 -43
- package/src/decorators/action.decorator.ts +0 -24
- package/src/decorators/anchor.decorator.ts +0 -10
- package/src/decorators/container.spec.ts +0 -104
- package/src/decorators/container.ts +0 -133
- package/src/decorators/factory.decorator.ts +0 -13
- package/src/decorators/model.decorator.ts +0 -10
- package/src/decorators/module.decorator.ts +0 -13
- package/src/decorators/overlay.decorator.ts +0 -10
- package/src/decorators/resource.decorator.ts +0 -10
- package/src/decorators/test-container.spec.ts +0 -50
- package/src/decorators/test-container.ts +0 -56
- package/src/functions/dependency/dependency.model.spec.ts +0 -43
- package/src/functions/dependency/dependency.model.ts +0 -178
- package/src/functions/diff/diff-metadata.model.ts +0 -51
- package/src/functions/diff/diff.model.ts +0 -33
- package/src/functions/diff/diff.utility.ts +0 -163
- package/src/functions/module/module.abstract.ts +0 -59
- package/src/functions/module/module.interface.ts +0 -5
- package/src/index.ts +0 -62
- package/src/models/action.interface.ts +0 -35
- package/src/models/app/app.interface.ts +0 -5
- package/src/models/app/app.model.ts +0 -111
- package/src/models/deployment/deployment.interface.ts +0 -5
- package/src/models/deployment/deployment.model.ts +0 -35
- package/src/models/environment/environment.interface.ts +0 -6
- package/src/models/environment/environment.model.spec.ts +0 -125
- package/src/models/environment/environment.model.ts +0 -55
- package/src/models/execution/execution.interface.ts +0 -8
- package/src/models/execution/execution.model.spec.ts +0 -62
- package/src/models/execution/execution.model.ts +0 -89
- package/src/models/image/image.interface.ts +0 -8
- package/src/models/image/image.model.ts +0 -62
- package/src/models/model.abstract.ts +0 -324
- package/src/models/model.interface.ts +0 -42
- package/src/models/pipeline/pipeline.interface.ts +0 -6
- package/src/models/pipeline/pipeline.model.ts +0 -47
- package/src/models/region/region.interface.ts +0 -5
- package/src/models/region/region.model.spec.ts +0 -162
- package/src/models/region/region.model.ts +0 -48
- package/src/models/server/server.interface.ts +0 -7
- package/src/models/server/server.model.ts +0 -56
- package/src/models/service/service.interface.ts +0 -5
- package/src/models/service/service.model.ts +0 -25
- package/src/models/support/support.interface.ts +0 -6
- package/src/models/support/support.model.spec.ts +0 -78
- package/src/models/support/support.model.ts +0 -52
- package/src/overlays/anchor.abstract.ts +0 -41
- package/src/overlays/anchor.interface.ts +0 -7
- package/src/overlays/anchor.spec.ts +0 -41
- package/src/overlays/overlay-data.repository.ts +0 -76
- package/src/overlays/overlay.abstract.ts +0 -64
- package/src/overlays/overlay.interface.ts +0 -9
- package/src/overlays/overlay.service.ts +0 -38
- package/src/overlays/overlay.spec.ts +0 -86
- package/src/resources/resource-action.interface.ts +0 -9
- package/src/resources/resource-data.repository.spec.ts +0 -133
- package/src/resources/resource-data.repository.ts +0 -92
- package/src/resources/resource.abstract.ts +0 -108
- package/src/resources/resource.interface.ts +0 -7
- package/src/resources/resource.spec.ts +0 -60
- package/src/resources/shared-resource.abstract.ts +0 -53
- package/src/resources/shared-resource.spec.ts +0 -133
- package/src/services/serialization/model/__snapshots__/model-serialization.service.spec.ts.snap +0 -656
- package/src/services/serialization/model/model-serialization.service.spec.ts +0 -195
- package/src/services/serialization/model/model-serialization.service.ts +0 -172
- package/src/services/serialization/resource/__snapshots__/resource-serialization.service.spec.ts.snap +0 -284
- package/src/services/serialization/resource/resource-serialization.service.spec.ts +0 -311
- package/src/services/serialization/resource/resource-serialization.service.ts +0 -166
- package/src/services/state-management/local.state-provider.spec.ts +0 -42
- package/src/services/state-management/local.state-provider.ts +0 -23
- package/src/services/state-management/state-management.service.ts +0 -43
- package/src/services/state-management/state-provider.interface.ts +0 -5
- package/src/services/transaction/__snapshots__/transaction.service.spec.ts.snap +0 -284
- package/src/services/transaction/transaction.service.spec.ts +0 -823
- package/src/services/transaction/transaction.service.ts +0 -386
- package/test/app.e2e-spec.ts +0 -104
- package/test/helpers/test-classes.ts +0 -31
- package/test/models/__snapshots__/model.e2e-spec.ts.snap +0 -451
- package/test/models/model.e2e-spec.ts +0 -366
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -9
package/src/index.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export { Anchor } from './decorators/anchor.decorator.js';
|
|
2
|
-
export { Action } from './decorators/action.decorator.js';
|
|
3
|
-
export { Container } from './decorators/container.js';
|
|
4
|
-
export { Factory } from './decorators/factory.decorator.js';
|
|
5
|
-
export { Model } from './decorators/model.decorator.js';
|
|
6
|
-
export { Module } from './decorators/module.decorator.js';
|
|
7
|
-
export { Overlay } from './decorators/overlay.decorator.js';
|
|
8
|
-
export { Resource } from './decorators/resource.decorator.js';
|
|
9
|
-
export { TestContainer } from './decorators/test-container.js';
|
|
10
|
-
|
|
11
|
-
export { Diff, DiffAction } from './functions/diff/diff.model.js';
|
|
12
|
-
export { DiffUtility } from './functions/diff/diff.utility.js';
|
|
13
|
-
export { DiffMetadata } from './functions/diff/diff-metadata.model.js';
|
|
14
|
-
export { AModule } from './functions/module/module.abstract.js';
|
|
15
|
-
export { IModule } from './functions/module/module.interface.js';
|
|
16
|
-
|
|
17
|
-
export { App } from './models/app/app.model.js';
|
|
18
|
-
export { IApp } from './models/app/app.interface.js';
|
|
19
|
-
export { Deployment } from './models/deployment/deployment.model.js';
|
|
20
|
-
export { IDeployment } from './models/deployment/deployment.interface.js';
|
|
21
|
-
export { Environment } from './models/environment/environment.model.js';
|
|
22
|
-
export { IEnvironment } from './models/environment/environment.interface.js';
|
|
23
|
-
export { Execution } from './models/execution/execution.model.js';
|
|
24
|
-
export { IExecution } from './models/execution/execution.interface.js';
|
|
25
|
-
export { IImageDockerOptions, Image } from './models/image/image.model.js';
|
|
26
|
-
export { IImage } from './models/image/image.interface.js';
|
|
27
|
-
export { Pipeline } from './models/pipeline/pipeline.model.js';
|
|
28
|
-
export { IPipeline } from './models/pipeline/pipeline.interface.js';
|
|
29
|
-
export { Region } from './models/region/region.model.js';
|
|
30
|
-
export { IRegion } from './models/region/region.interface.js';
|
|
31
|
-
export { Server } from './models/server/server.model.js';
|
|
32
|
-
export { IServer } from './models/server/server.interface.js';
|
|
33
|
-
export { Service } from './models/service/service.model.js';
|
|
34
|
-
export { IService } from './models/service/service.interface.js';
|
|
35
|
-
export { Support } from './models/support/support.model.js';
|
|
36
|
-
export { ISupport } from './models/support/support.interface.js';
|
|
37
|
-
|
|
38
|
-
export { IAction } from './models/action.interface.js';
|
|
39
|
-
export { AModel } from './models/model.abstract.js';
|
|
40
|
-
export { IModel, IModelReference } from './models/model.interface.js';
|
|
41
|
-
|
|
42
|
-
export { AAnchor } from './overlays/anchor.abstract.js';
|
|
43
|
-
export { IAnchor } from './overlays/anchor.interface.js';
|
|
44
|
-
export { AOverlay } from './overlays/overlay.abstract.js';
|
|
45
|
-
export { IOverlay } from './overlays/overlay.interface.js';
|
|
46
|
-
export { OverlayService } from './overlays/overlay.service.js';
|
|
47
|
-
|
|
48
|
-
export { AResource } from './resources/resource.abstract.js';
|
|
49
|
-
export { IResource } from './resources/resource.interface.js';
|
|
50
|
-
export { IResourceAction } from './resources/resource-action.interface.js';
|
|
51
|
-
export { ASharedResource } from './resources/shared-resource.abstract.js';
|
|
52
|
-
|
|
53
|
-
export { ModelSerializationService } from './services/serialization/model/model-serialization.service.js';
|
|
54
|
-
export { ResourceSerializationService } from './services/serialization/resource/resource-serialization.service.js';
|
|
55
|
-
|
|
56
|
-
export { LocalStateProvider } from './services/state-management/local.state-provider.js';
|
|
57
|
-
export { StateManagementService } from './services/state-management/state-management.service.js';
|
|
58
|
-
export { IStateProvider } from './services/state-management/state-provider.interface.js';
|
|
59
|
-
|
|
60
|
-
export { TransactionService } from './services/transaction/transaction.service.js';
|
|
61
|
-
|
|
62
|
-
export * from './app.type.js';
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ActionInputs, ActionOutputs } from '../app.type.js';
|
|
2
|
-
import { Diff } from '../functions/diff/diff.model.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Actions are translation functions between Diff and underlying infrastructure.
|
|
6
|
-
* An action can translate a specific type of Diff into underlying infrastructure, and can revert it back.
|
|
7
|
-
*/
|
|
8
|
-
export interface IAction<I extends ActionInputs, O extends ActionOutputs> {
|
|
9
|
-
/**
|
|
10
|
-
* The name of the action.
|
|
11
|
-
* It can be used to easily identify an action and its purpose.
|
|
12
|
-
*/
|
|
13
|
-
readonly ACTION_NAME: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* This function contains the list of inputs to ask before processing the diff.
|
|
17
|
-
* A missing input key will not be populated in the inputs provided to the action.
|
|
18
|
-
*/
|
|
19
|
-
collectInput(diff: Diff): (keyof I)[];
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* This function determines if the handle is applicable to the diff.
|
|
23
|
-
*/
|
|
24
|
-
filter(diff: Diff): boolean;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* This function contains the logic to apply the diff(s) to the underlying infrastructure.
|
|
28
|
-
*/
|
|
29
|
-
handle(diff: Diff, actionInputs: I): Promise<O>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* This function contains the logic to revert the diff(s) from the underlying infrastructure.
|
|
33
|
-
*/
|
|
34
|
-
revert(diff: Diff, actionInputs: I, actionOutputs: O): Promise<O>;
|
|
35
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { UnknownModel } from '../../app.type.js';
|
|
2
|
-
import { Model } from '../../decorators/model.decorator.js';
|
|
3
|
-
import { Image } from '../image/image.model.js';
|
|
4
|
-
import { AModel } from '../model.abstract.js';
|
|
5
|
-
import { Pipeline } from '../pipeline/pipeline.model.js';
|
|
6
|
-
import { Region } from '../region/region.model.js';
|
|
7
|
-
import { Server } from '../server/server.model.js';
|
|
8
|
-
import { Service } from '../service/service.model.js';
|
|
9
|
-
import { Support } from '../support/support.model.js';
|
|
10
|
-
import { IApp } from './app.interface.js';
|
|
11
|
-
|
|
12
|
-
@Model()
|
|
13
|
-
export class App extends AModel<IApp, App> {
|
|
14
|
-
readonly MODEL_NAME: string = 'app';
|
|
15
|
-
|
|
16
|
-
readonly name: string;
|
|
17
|
-
|
|
18
|
-
constructor(name: string) {
|
|
19
|
-
super();
|
|
20
|
-
this.name = name;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
addImage(image: Image): void {
|
|
24
|
-
const childrenDependencies = this.getChildren('image');
|
|
25
|
-
if (!childrenDependencies['image']) childrenDependencies['image'] = [];
|
|
26
|
-
|
|
27
|
-
// Check for duplicates.
|
|
28
|
-
const images = childrenDependencies['image'].map((d) => d.to);
|
|
29
|
-
if (images.find((i: Image) => i.imageId === image.imageId)) {
|
|
30
|
-
throw new Error('Image already exists!');
|
|
31
|
-
}
|
|
32
|
-
this.addChild('name', image, 'imageId');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
addPipeline(pipeline: Pipeline): void {
|
|
36
|
-
const childrenDependencies = this.getChildren('pipeline');
|
|
37
|
-
if (!childrenDependencies['pipeline']) childrenDependencies['pipeline'] = [];
|
|
38
|
-
|
|
39
|
-
// Check for duplicates.
|
|
40
|
-
const pipelines = childrenDependencies['pipeline'].map((d) => d.to);
|
|
41
|
-
if (pipelines.find((p: Pipeline) => p.pipelineName === pipeline.pipelineName)) {
|
|
42
|
-
throw new Error('Pipeline already exists!');
|
|
43
|
-
}
|
|
44
|
-
this.addChild('name', pipeline, 'pipelineName');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
addRegion(region: Region): void {
|
|
48
|
-
const childrenDependencies = this.getChildren('region');
|
|
49
|
-
if (!childrenDependencies['region']) childrenDependencies['region'] = [];
|
|
50
|
-
|
|
51
|
-
// Check for duplicates.
|
|
52
|
-
const regions = childrenDependencies['region'].map((d) => d.to);
|
|
53
|
-
if (regions.find((r: Region) => r.regionId === region.regionId)) {
|
|
54
|
-
throw new Error('Region already exists!');
|
|
55
|
-
}
|
|
56
|
-
this.addChild('name', region, 'regionId');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
addServer(server: Server): void {
|
|
60
|
-
const childrenDependencies = this.getChildren('server');
|
|
61
|
-
if (!childrenDependencies['server']) childrenDependencies['server'] = [];
|
|
62
|
-
|
|
63
|
-
// Check for duplicates.
|
|
64
|
-
const servers = childrenDependencies['server'].map((d) => d.to);
|
|
65
|
-
if (servers.find((s: Server) => s.serverKey === server.serverKey)) {
|
|
66
|
-
throw new Error('Server already exists!');
|
|
67
|
-
}
|
|
68
|
-
this.addChild('name', server, 'serverKey');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
addService(service: Service): void {
|
|
72
|
-
const childrenDependencies = this.getChildren('service');
|
|
73
|
-
if (!childrenDependencies['service']) childrenDependencies['service'] = [];
|
|
74
|
-
|
|
75
|
-
// Check for duplicates.
|
|
76
|
-
const services = childrenDependencies['service'].map((d) => d.to);
|
|
77
|
-
if (services.find((s: Service) => s.serviceId === service.serviceId)) {
|
|
78
|
-
throw new Error('Service already exists!');
|
|
79
|
-
}
|
|
80
|
-
this.addChild('name', service, 'serviceId');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
addSupport(support: Support): void {
|
|
84
|
-
const childrenDependencies = this.getChildren('support');
|
|
85
|
-
if (!childrenDependencies['support']) childrenDependencies['support'] = [];
|
|
86
|
-
|
|
87
|
-
// Check for duplicates.
|
|
88
|
-
const supports = childrenDependencies['support'].map((d) => d.to);
|
|
89
|
-
if (supports.find((s: Support) => s.serverKey === support.serverKey)) {
|
|
90
|
-
throw new Error('Support already exists!');
|
|
91
|
-
}
|
|
92
|
-
this.addChild('name', support, 'serverKey');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
getContext(): string {
|
|
96
|
-
return `${this.MODEL_NAME}=${this.name}`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
synth(): IApp {
|
|
100
|
-
return {
|
|
101
|
-
name: this.name,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
static override async unSynth(
|
|
106
|
-
app: IApp,
|
|
107
|
-
deReferenceContext: (context: string) => Promise<UnknownModel>,
|
|
108
|
-
): Promise<App> {
|
|
109
|
-
return new App(app.name);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { UnknownModel } from '../../app.type.js';
|
|
2
|
-
import { Model } from '../../decorators/model.decorator.js';
|
|
3
|
-
import { AModel } from '../model.abstract.js';
|
|
4
|
-
import { IDeployment } from './deployment.interface.js';
|
|
5
|
-
|
|
6
|
-
@Model()
|
|
7
|
-
export class Deployment extends AModel<IDeployment, Deployment> {
|
|
8
|
-
readonly MODEL_NAME: string = 'deployment';
|
|
9
|
-
|
|
10
|
-
readonly deploymentTag: string;
|
|
11
|
-
|
|
12
|
-
constructor(deploymentTag: string) {
|
|
13
|
-
super();
|
|
14
|
-
this.deploymentTag = deploymentTag;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getContext(): string {
|
|
18
|
-
const parents = this.getParents();
|
|
19
|
-
const parent = (parents['server'] || parents['support'])[0].to;
|
|
20
|
-
return [`${this.MODEL_NAME}=${this.deploymentTag}`, parent.getContext()].join(',');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
synth(): IDeployment {
|
|
24
|
-
return {
|
|
25
|
-
deploymentTag: this.deploymentTag,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static override async unSynth(
|
|
30
|
-
deployment: IDeployment,
|
|
31
|
-
deReferenceContext: (context: string) => Promise<UnknownModel>,
|
|
32
|
-
): Promise<Deployment> {
|
|
33
|
-
return new Deployment(deployment.deploymentTag);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { Environment } from './environment.model.js';
|
|
2
|
-
|
|
3
|
-
describe('Environment UT', () => {
|
|
4
|
-
describe('diff()', () => {
|
|
5
|
-
describe('when diff of environmentVariables', () => {
|
|
6
|
-
it('should capture addition', async () => {
|
|
7
|
-
const environment0 = new Environment('qa');
|
|
8
|
-
|
|
9
|
-
const environment1 = new Environment('qa');
|
|
10
|
-
environment1.environmentVariables.set('key', 'value');
|
|
11
|
-
|
|
12
|
-
const diff = await environment1.diff(environment0);
|
|
13
|
-
|
|
14
|
-
expect(diff).toMatchInlineSnapshot(`
|
|
15
|
-
[
|
|
16
|
-
{
|
|
17
|
-
"action": "add",
|
|
18
|
-
"field": "environmentVariables",
|
|
19
|
-
"value": {
|
|
20
|
-
"key": "key",
|
|
21
|
-
"value": "value",
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
]
|
|
25
|
-
`);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should capture update', async () => {
|
|
29
|
-
const environment0 = new Environment('qa');
|
|
30
|
-
environment0.environmentVariables.set('key', 'value 1');
|
|
31
|
-
|
|
32
|
-
const environment1 = new Environment('qa');
|
|
33
|
-
environment1.environmentVariables.set('key', 'value 2');
|
|
34
|
-
|
|
35
|
-
const diff = await environment1.diff(environment0);
|
|
36
|
-
|
|
37
|
-
expect(diff).toMatchInlineSnapshot(`
|
|
38
|
-
[
|
|
39
|
-
{
|
|
40
|
-
"action": "update",
|
|
41
|
-
"field": "environmentVariables",
|
|
42
|
-
"value": {
|
|
43
|
-
"key": "key",
|
|
44
|
-
"value": "value 2",
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
]
|
|
48
|
-
`);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should capture replace', async () => {
|
|
52
|
-
const environment0 = new Environment('qa');
|
|
53
|
-
environment0.environmentVariables.set('key1', 'value 1');
|
|
54
|
-
|
|
55
|
-
const environment1 = new Environment('qa');
|
|
56
|
-
environment1.environmentVariables.set('key2', 'value 2');
|
|
57
|
-
|
|
58
|
-
const diff = await environment1.diff(environment0);
|
|
59
|
-
|
|
60
|
-
expect(diff).toMatchInlineSnapshot(`
|
|
61
|
-
[
|
|
62
|
-
{
|
|
63
|
-
"action": "delete",
|
|
64
|
-
"field": "environmentVariables",
|
|
65
|
-
"value": {
|
|
66
|
-
"key": "key1",
|
|
67
|
-
"value": "value 1",
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
"action": "add",
|
|
72
|
-
"field": "environmentVariables",
|
|
73
|
-
"value": {
|
|
74
|
-
"key": "key2",
|
|
75
|
-
"value": "value 2",
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
]
|
|
79
|
-
`);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should capture deletion', async () => {
|
|
83
|
-
const environment0 = new Environment('qa');
|
|
84
|
-
environment0.environmentVariables.set('key', 'value');
|
|
85
|
-
|
|
86
|
-
const environment1 = new Environment('qa');
|
|
87
|
-
|
|
88
|
-
const diff = await environment1.diff(environment0);
|
|
89
|
-
|
|
90
|
-
expect(diff).toMatchInlineSnapshot(`
|
|
91
|
-
[
|
|
92
|
-
{
|
|
93
|
-
"action": "delete",
|
|
94
|
-
"field": "environmentVariables",
|
|
95
|
-
"value": {
|
|
96
|
-
"key": "key",
|
|
97
|
-
"value": "value",
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
]
|
|
101
|
-
`);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should capture diff without a previous instance', async () => {
|
|
105
|
-
const environment = new Environment('qa');
|
|
106
|
-
environment.environmentVariables.set('key', 'value');
|
|
107
|
-
|
|
108
|
-
const diff = await environment.diff();
|
|
109
|
-
|
|
110
|
-
expect(diff).toMatchInlineSnapshot(`
|
|
111
|
-
[
|
|
112
|
-
{
|
|
113
|
-
"action": "add",
|
|
114
|
-
"field": "environmentVariables",
|
|
115
|
-
"value": {
|
|
116
|
-
"key": "key",
|
|
117
|
-
"value": "value",
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
]
|
|
121
|
-
`);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { UnknownModel } from '../../app.type.js';
|
|
2
|
-
import { Model } from '../../decorators/model.decorator.js';
|
|
3
|
-
import { DiffUtility } from '../../functions/diff/diff.utility.js';
|
|
4
|
-
import { Diff } from '../../functions/diff/diff.model.js';
|
|
5
|
-
import { AModel } from '../model.abstract.js';
|
|
6
|
-
import { IEnvironment } from './environment.interface.js';
|
|
7
|
-
|
|
8
|
-
@Model()
|
|
9
|
-
export class Environment extends AModel<IEnvironment, Environment> {
|
|
10
|
-
readonly MODEL_NAME: string = 'environment';
|
|
11
|
-
|
|
12
|
-
readonly environmentName: string;
|
|
13
|
-
|
|
14
|
-
readonly environmentVariables: Map<string, string> = new Map();
|
|
15
|
-
|
|
16
|
-
constructor(environmentName: string) {
|
|
17
|
-
super();
|
|
18
|
-
this.environmentName = environmentName;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
override async diff(previous?: Environment): Promise<Diff[]> {
|
|
22
|
-
// Generate diff of environmentVariables.
|
|
23
|
-
return DiffUtility.diffMap(
|
|
24
|
-
previous || ({ environmentVariables: new Map() } as Environment),
|
|
25
|
-
this,
|
|
26
|
-
'environmentVariables',
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getContext(): string {
|
|
31
|
-
const parents = this.getParents();
|
|
32
|
-
const region = parents['region'][0].to;
|
|
33
|
-
return [`${this.MODEL_NAME}=${this.environmentName}`, region.getContext()].join(',');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
synth(): IEnvironment {
|
|
37
|
-
return {
|
|
38
|
-
environmentName: this.environmentName,
|
|
39
|
-
environmentVariables: Object.fromEntries(this.environmentVariables || new Map()),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static override async unSynth(
|
|
44
|
-
environment: IEnvironment,
|
|
45
|
-
deReferenceContext: (context: string) => Promise<UnknownModel>,
|
|
46
|
-
): Promise<Environment> {
|
|
47
|
-
const newEnvironment = new Environment(environment.environmentName);
|
|
48
|
-
|
|
49
|
-
for (const key in environment.environmentVariables) {
|
|
50
|
-
newEnvironment.environmentVariables.set(key, environment.environmentVariables[key]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return newEnvironment;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Container } from '../../decorators/container.js';
|
|
2
|
-
import { ModelSerializationService } from '../../services/serialization/model/model-serialization.service.js';
|
|
3
|
-
import { App } from '../app/app.model.js';
|
|
4
|
-
import { Deployment } from '../deployment/deployment.model.js';
|
|
5
|
-
import { Environment } from '../environment/environment.model.js';
|
|
6
|
-
import { Image } from '../image/image.model.js';
|
|
7
|
-
import { Region } from '../region/region.model.js';
|
|
8
|
-
import { Support } from '../support/support.model.js';
|
|
9
|
-
import { Execution } from './execution.model.js';
|
|
10
|
-
|
|
11
|
-
describe('Execution UT', () => {
|
|
12
|
-
let modelSerializationService: ModelSerializationService;
|
|
13
|
-
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
modelSerializationService = await Container.get(ModelSerializationService);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('diff()', () => {
|
|
19
|
-
describe('when diff of object with children', () => {
|
|
20
|
-
it('should capture delete of children', async () => {
|
|
21
|
-
const app0_0 = new App('test');
|
|
22
|
-
const image0_0 = new Image('test', 'imageTag', {
|
|
23
|
-
dockerfilePath: 'path/to/Dockerfile',
|
|
24
|
-
});
|
|
25
|
-
app0_0.addImage(image0_0);
|
|
26
|
-
const region0_0 = new Region('region');
|
|
27
|
-
app0_0.addRegion(region0_0);
|
|
28
|
-
const environment0_0 = new Environment('qa');
|
|
29
|
-
region0_0.addEnvironment(environment0_0);
|
|
30
|
-
const support0_0 = new Support('nginx', 'nginx');
|
|
31
|
-
app0_0.addSupport(support0_0);
|
|
32
|
-
const deployment0_0 = new Deployment('nginx@0.0.1');
|
|
33
|
-
support0_0.addDeployment(deployment0_0);
|
|
34
|
-
new Execution(deployment0_0, environment0_0, image0_0);
|
|
35
|
-
|
|
36
|
-
const app0_1 = (await modelSerializationService.deserialize(
|
|
37
|
-
await modelSerializationService.serialize(app0_0),
|
|
38
|
-
)) as App;
|
|
39
|
-
const region0_1 = app0_1.getChild('region', [{ key: 'regionId', value: 'region' }]) as Region;
|
|
40
|
-
const environment0_1 = region0_1.getChild('environment', [
|
|
41
|
-
{ key: 'environmentName', value: 'qa' },
|
|
42
|
-
]) as Environment;
|
|
43
|
-
const execution0_1 = environment0_1.getChild('execution', [
|
|
44
|
-
{ key: 'executionId', value: 'nginx@0.0.1_qa' },
|
|
45
|
-
]) as Execution;
|
|
46
|
-
|
|
47
|
-
execution0_1.remove(true);
|
|
48
|
-
const diff = await app0_1.diff(app0_0);
|
|
49
|
-
|
|
50
|
-
expect(diff).toMatchInlineSnapshot(`
|
|
51
|
-
[
|
|
52
|
-
{
|
|
53
|
-
"action": "delete",
|
|
54
|
-
"field": "executionId",
|
|
55
|
-
"value": "nginx@0.0.1_qa",
|
|
56
|
-
},
|
|
57
|
-
]
|
|
58
|
-
`);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { UnknownModel } from '../../app.type.js';
|
|
2
|
-
import { Model } from '../../decorators/model.decorator.js';
|
|
3
|
-
import { DiffUtility } from '../../functions/diff/diff.utility.js';
|
|
4
|
-
import { Diff } from '../../functions/diff/diff.model.js';
|
|
5
|
-
import { Deployment } from '../deployment/deployment.model.js';
|
|
6
|
-
import { Environment } from '../environment/environment.model.js';
|
|
7
|
-
import { Image } from '../image/image.model.js';
|
|
8
|
-
import { AModel } from '../model.abstract.js';
|
|
9
|
-
import { IExecution } from './execution.interface.js';
|
|
10
|
-
|
|
11
|
-
@Model()
|
|
12
|
-
export class Execution extends AModel<IExecution, Execution> {
|
|
13
|
-
readonly MODEL_NAME: string = 'execution';
|
|
14
|
-
|
|
15
|
-
readonly environmentVariables: Map<string, string> = new Map();
|
|
16
|
-
|
|
17
|
-
readonly executionId: string;
|
|
18
|
-
|
|
19
|
-
readonly image: Image;
|
|
20
|
-
|
|
21
|
-
constructor(deployment: Deployment, environment: Environment, image: Image) {
|
|
22
|
-
super();
|
|
23
|
-
this.executionId = [deployment.deploymentTag, environment.environmentName].join('_');
|
|
24
|
-
|
|
25
|
-
// Check for duplicates.
|
|
26
|
-
if (
|
|
27
|
-
deployment.getChild('execution', [{ key: 'executionId', value: this.executionId }]) ||
|
|
28
|
-
environment.getChild('execution', [{ key: 'executionId', value: this.executionId }])
|
|
29
|
-
) {
|
|
30
|
-
throw new Error('Execution already exists!');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// In order for this execution to properly have defined its parent-child relationship, both execution and deployment
|
|
34
|
-
// must claim it as their child. Doing it here, prevents the confusion.
|
|
35
|
-
deployment.addChild('deploymentTag', this, 'executionId');
|
|
36
|
-
environment.addChild('environmentName', this, 'executionId');
|
|
37
|
-
|
|
38
|
-
this.image = image;
|
|
39
|
-
this.addRelationship('executionId', image, 'imageId');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
override async diff(previous?: Execution): Promise<Diff[]> {
|
|
43
|
-
// deployment, environment, and executionId intentionally not included in diff,
|
|
44
|
-
// since they all contribute to executionId (primary key) which can never change.
|
|
45
|
-
|
|
46
|
-
// Generate diff of environmentVariables.
|
|
47
|
-
return DiffUtility.diffMap(
|
|
48
|
-
previous || ({ environmentVariables: new Map() } as Execution),
|
|
49
|
-
this,
|
|
50
|
-
'environmentVariables',
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
getContext(): string {
|
|
55
|
-
const parents = this.getParents();
|
|
56
|
-
const deployment: Deployment = parents['deployment'][0]['to'] as Deployment;
|
|
57
|
-
const environment: Environment = parents['environment'][0]['to'] as Environment;
|
|
58
|
-
return [`${this.MODEL_NAME}=${this.executionId}`, deployment.getContext(), environment.getContext()].join(',');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
synth(): IExecution {
|
|
62
|
-
const parents = this.getParents();
|
|
63
|
-
const deployment: Deployment = parents['deployment'][0]['to'] as Deployment;
|
|
64
|
-
const environment: Environment = parents['environment'][0]['to'] as Environment;
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
deployment: { context: deployment.getContext() },
|
|
68
|
-
environment: { context: environment.getContext() },
|
|
69
|
-
environmentVariables: Object.fromEntries(this.environmentVariables || new Map()),
|
|
70
|
-
image: { context: this.image.getContext() },
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static override async unSynth(
|
|
75
|
-
execution: IExecution,
|
|
76
|
-
deReferenceContext: (context: string) => Promise<UnknownModel>,
|
|
77
|
-
): Promise<Execution> {
|
|
78
|
-
const deployment = (await deReferenceContext(execution.deployment.context)) as Deployment;
|
|
79
|
-
const environment = (await deReferenceContext(execution.environment.context)) as Environment;
|
|
80
|
-
const image = (await deReferenceContext(execution.image.context)) as Image;
|
|
81
|
-
const newExecution = new Execution(deployment, environment, image);
|
|
82
|
-
|
|
83
|
-
for (const key in execution.environmentVariables) {
|
|
84
|
-
newExecution.environmentVariables.set(key, execution.environmentVariables[key]);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return newExecution;
|
|
88
|
-
}
|
|
89
|
-
}
|