@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.
Files changed (86) hide show
  1. package/package.json +6 -1
  2. package/.eslintrc.cjs +0 -26
  3. package/dist/tsconfig.build.tsbuildinfo +0 -1
  4. package/src/app.type.ts +0 -56
  5. package/src/decorators/action.decorator.spec.ts +0 -43
  6. package/src/decorators/action.decorator.ts +0 -24
  7. package/src/decorators/anchor.decorator.ts +0 -10
  8. package/src/decorators/container.spec.ts +0 -104
  9. package/src/decorators/container.ts +0 -133
  10. package/src/decorators/factory.decorator.ts +0 -13
  11. package/src/decorators/model.decorator.ts +0 -10
  12. package/src/decorators/module.decorator.ts +0 -13
  13. package/src/decorators/overlay.decorator.ts +0 -10
  14. package/src/decorators/resource.decorator.ts +0 -10
  15. package/src/decorators/test-container.spec.ts +0 -50
  16. package/src/decorators/test-container.ts +0 -56
  17. package/src/functions/dependency/dependency.model.spec.ts +0 -43
  18. package/src/functions/dependency/dependency.model.ts +0 -178
  19. package/src/functions/diff/diff-metadata.model.ts +0 -51
  20. package/src/functions/diff/diff.model.ts +0 -33
  21. package/src/functions/diff/diff.utility.ts +0 -163
  22. package/src/functions/module/module.abstract.ts +0 -59
  23. package/src/functions/module/module.interface.ts +0 -5
  24. package/src/index.ts +0 -62
  25. package/src/models/action.interface.ts +0 -35
  26. package/src/models/app/app.interface.ts +0 -5
  27. package/src/models/app/app.model.ts +0 -111
  28. package/src/models/deployment/deployment.interface.ts +0 -5
  29. package/src/models/deployment/deployment.model.ts +0 -35
  30. package/src/models/environment/environment.interface.ts +0 -6
  31. package/src/models/environment/environment.model.spec.ts +0 -125
  32. package/src/models/environment/environment.model.ts +0 -55
  33. package/src/models/execution/execution.interface.ts +0 -8
  34. package/src/models/execution/execution.model.spec.ts +0 -62
  35. package/src/models/execution/execution.model.ts +0 -89
  36. package/src/models/image/image.interface.ts +0 -8
  37. package/src/models/image/image.model.ts +0 -62
  38. package/src/models/model.abstract.ts +0 -324
  39. package/src/models/model.interface.ts +0 -42
  40. package/src/models/pipeline/pipeline.interface.ts +0 -6
  41. package/src/models/pipeline/pipeline.model.ts +0 -47
  42. package/src/models/region/region.interface.ts +0 -5
  43. package/src/models/region/region.model.spec.ts +0 -162
  44. package/src/models/region/region.model.ts +0 -48
  45. package/src/models/server/server.interface.ts +0 -7
  46. package/src/models/server/server.model.ts +0 -56
  47. package/src/models/service/service.interface.ts +0 -5
  48. package/src/models/service/service.model.ts +0 -25
  49. package/src/models/support/support.interface.ts +0 -6
  50. package/src/models/support/support.model.spec.ts +0 -78
  51. package/src/models/support/support.model.ts +0 -52
  52. package/src/overlays/anchor.abstract.ts +0 -41
  53. package/src/overlays/anchor.interface.ts +0 -7
  54. package/src/overlays/anchor.spec.ts +0 -41
  55. package/src/overlays/overlay-data.repository.ts +0 -76
  56. package/src/overlays/overlay.abstract.ts +0 -64
  57. package/src/overlays/overlay.interface.ts +0 -9
  58. package/src/overlays/overlay.service.ts +0 -38
  59. package/src/overlays/overlay.spec.ts +0 -86
  60. package/src/resources/resource-action.interface.ts +0 -9
  61. package/src/resources/resource-data.repository.spec.ts +0 -133
  62. package/src/resources/resource-data.repository.ts +0 -92
  63. package/src/resources/resource.abstract.ts +0 -108
  64. package/src/resources/resource.interface.ts +0 -7
  65. package/src/resources/resource.spec.ts +0 -60
  66. package/src/resources/shared-resource.abstract.ts +0 -53
  67. package/src/resources/shared-resource.spec.ts +0 -133
  68. package/src/services/serialization/model/__snapshots__/model-serialization.service.spec.ts.snap +0 -656
  69. package/src/services/serialization/model/model-serialization.service.spec.ts +0 -195
  70. package/src/services/serialization/model/model-serialization.service.ts +0 -172
  71. package/src/services/serialization/resource/__snapshots__/resource-serialization.service.spec.ts.snap +0 -284
  72. package/src/services/serialization/resource/resource-serialization.service.spec.ts +0 -311
  73. package/src/services/serialization/resource/resource-serialization.service.ts +0 -166
  74. package/src/services/state-management/local.state-provider.spec.ts +0 -42
  75. package/src/services/state-management/local.state-provider.ts +0 -23
  76. package/src/services/state-management/state-management.service.ts +0 -43
  77. package/src/services/state-management/state-provider.interface.ts +0 -5
  78. package/src/services/transaction/__snapshots__/transaction.service.spec.ts.snap +0 -284
  79. package/src/services/transaction/transaction.service.spec.ts +0 -823
  80. package/src/services/transaction/transaction.service.ts +0 -386
  81. package/test/app.e2e-spec.ts +0 -104
  82. package/test/helpers/test-classes.ts +0 -31
  83. package/test/models/__snapshots__/model.e2e-spec.ts.snap +0 -451
  84. package/test/models/model.e2e-spec.ts +0 -366
  85. package/tsconfig.build.json +0 -4
  86. package/tsconfig.json +0 -9
@@ -1,7 +0,0 @@
1
- import { IModelReference } from '../model.interface.js';
2
- import { Server } from './server.model.js';
3
-
4
- export interface IServer {
5
- image: IModelReference;
6
- serverKey: Server['serverKey'];
7
- }
@@ -1,56 +0,0 @@
1
- import { UnknownModel } from '../../app.type.js';
2
- import { Model } from '../../decorators/model.decorator.js';
3
- import { Deployment } from '../deployment/deployment.model.js';
4
- import { Image } from '../image/image.model.js';
5
- import { AModel } from '../model.abstract.js';
6
- import { IServer } from './server.interface.js';
7
-
8
- @Model()
9
- export class Server extends AModel<IServer, Server> {
10
- readonly MODEL_NAME: string = 'server';
11
-
12
- readonly image: Image;
13
-
14
- readonly serverKey: string;
15
-
16
- constructor(serverKey: string, image: Image) {
17
- super();
18
- this.serverKey = serverKey;
19
-
20
- this.image = image;
21
- this.addRelationship('serverKey', image, 'imageId');
22
- }
23
-
24
- addDeployment(deployment: Deployment): void {
25
- const childrenDependencies = this.getChildren('deployment');
26
- if (!childrenDependencies['deployment']) childrenDependencies['deployment'] = [];
27
-
28
- // Check for duplicates.
29
- const deployments = childrenDependencies['deployment'].map((d) => d.to);
30
- if (deployments.find((d: Deployment) => d.deploymentTag === deployment.deploymentTag)) {
31
- throw new Error('Deployment already exists!');
32
- }
33
- this.addChild('serverKey', deployment, 'deploymentTag');
34
- }
35
-
36
- getContext(): string {
37
- const parents = this.getParents();
38
- const app = parents['app'][0].to;
39
- return [`${this.MODEL_NAME}=${this.serverKey}`, app.getContext()].join(',');
40
- }
41
-
42
- synth(): IServer {
43
- return {
44
- image: { context: this.image.getContext() },
45
- serverKey: this.serverKey,
46
- };
47
- }
48
-
49
- static override async unSynth(
50
- server: IServer,
51
- deReferenceContext: (context: string) => Promise<UnknownModel>,
52
- ): Promise<Server> {
53
- const image = (await deReferenceContext(server.image.context)) as Image;
54
- return new Server(server.serverKey, image);
55
- }
56
- }
@@ -1,5 +0,0 @@
1
- import { Service } from './service.model.js';
2
-
3
- export interface IService {
4
- serviceId: Service['serviceId'];
5
- }
@@ -1,25 +0,0 @@
1
- import { Model } from '../../decorators/model.decorator.js';
2
- import { AModel } from '../model.abstract.js';
3
- import { IService } from './service.interface.js';
4
-
5
- @Model()
6
- export class Service extends AModel<IService, Service> {
7
- readonly MODEL_NAME: string = 'service';
8
-
9
- readonly serviceId: string;
10
-
11
- constructor(serviceId: string) {
12
- super();
13
- this.serviceId = serviceId;
14
- }
15
-
16
- getContext(): string {
17
- const parents = this.getParents();
18
- const app = parents['app'][0].to;
19
- return [`${this.MODEL_NAME}=${this.serviceId}`, app.getContext()].join(',');
20
- }
21
-
22
- synth(): IService {
23
- throw new Error('Method not implemented! Use subclass');
24
- }
25
- }
@@ -1,6 +0,0 @@
1
- import { Support } from './support.model.js';
2
-
3
- export interface ISupport {
4
- applicationType: Support['applicationType'];
5
- serverKey: Support['serverKey'];
6
- }
@@ -1,78 +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 { Execution } from '../execution/execution.model.js';
7
- import { Image } from '../image/image.model.js';
8
- import { Region } from '../region/region.model.js';
9
- import { Support } from './support.model.js';
10
-
11
- describe('Support 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
- const support0_1 = app0_1.getChild('support', [{ key: 'serverKey', value: 'nginx' }]) as Support;
47
- const deployment0_1 = support0_1.getChild('deployment', [
48
- { key: 'deploymentTag', value: 'nginx@0.0.1' },
49
- ]) as Deployment;
50
-
51
- execution0_1.remove(true);
52
- deployment0_1.remove();
53
- support0_1.remove();
54
- const diff = await app0_1.diff(app0_0);
55
-
56
- expect(diff).toMatchInlineSnapshot(`
57
- [
58
- {
59
- "action": "delete",
60
- "field": "executionId",
61
- "value": "nginx@0.0.1_qa",
62
- },
63
- {
64
- "action": "delete",
65
- "field": "deploymentTag",
66
- "value": "nginx@0.0.1",
67
- },
68
- {
69
- "action": "delete",
70
- "field": "serverKey",
71
- "value": "nginx",
72
- },
73
- ]
74
- `);
75
- });
76
- });
77
- });
78
- });
@@ -1,52 +0,0 @@
1
- import { SupportApplicationType, UnknownModel } from '../../app.type.js';
2
- import { Model } from '../../decorators/model.decorator.js';
3
- import { Deployment } from '../deployment/deployment.model.js';
4
- import { AModel } from '../model.abstract.js';
5
- import { ISupport } from './support.interface.js';
6
-
7
- @Model()
8
- export class Support extends AModel<ISupport, Support> {
9
- readonly MODEL_NAME: string = 'support';
10
-
11
- readonly applicationType: SupportApplicationType;
12
-
13
- readonly serverKey: string;
14
-
15
- constructor(serverKey: string, applicationType: SupportApplicationType) {
16
- super();
17
- this.serverKey = serverKey;
18
- this.applicationType = applicationType;
19
- }
20
-
21
- addDeployment(deployment: Deployment): void {
22
- const childrenDependencies = this.getChildren('deployment');
23
- if (!childrenDependencies['deployment']) childrenDependencies['deployment'] = [];
24
-
25
- // Check for duplicates.
26
- const deployments = childrenDependencies['deployment'].map((d) => d.to);
27
- if (deployments.find((d: Deployment) => d.deploymentTag === deployment.deploymentTag)) {
28
- throw new Error('Deployment already exists!');
29
- }
30
- this.addChild('serverKey', deployment, 'deploymentTag');
31
- }
32
-
33
- getContext(): string {
34
- const parents = this.getParents();
35
- const app = parents['app'][0].to;
36
- return [`${this.MODEL_NAME}=${this.serverKey}`, app.getContext()].join(',');
37
- }
38
-
39
- synth(): ISupport {
40
- return {
41
- applicationType: this.applicationType,
42
- serverKey: this.serverKey,
43
- };
44
- }
45
-
46
- static override async unSynth(
47
- support: ISupport,
48
- deReferenceContext: (context: string) => Promise<UnknownModel>,
49
- ): Promise<Support> {
50
- return new Support(support.serverKey, support.applicationType);
51
- }
52
- }
@@ -1,41 +0,0 @@
1
- import { UnknownModel } from '../app.type.js';
2
- import { IAnchor } from './anchor.interface.js';
3
-
4
- export abstract class AAnchor {
5
- protected constructor(readonly anchorId: string, private readonly parent: UnknownModel) {
6
- if (parent.getAnchor(this.anchorId)) {
7
- throw new Error('Anchor already exists!');
8
- }
9
- }
10
-
11
- getParent(): UnknownModel {
12
- return this.parent;
13
- }
14
-
15
- synth(): IAnchor {
16
- return {
17
- anchorId: this.anchorId,
18
- parent: { context: this.parent.getContext() },
19
- };
20
- }
21
-
22
- toJSON(): object {
23
- return {
24
- anchorId: this.anchorId,
25
- parent: this.parent.getContext(),
26
- };
27
- }
28
-
29
- static async unSynth(
30
- deserializationClass: any,
31
- anchor: IAnchor,
32
- deReferenceContext: (context: string) => Promise<UnknownModel>,
33
- ): Promise<AAnchor> {
34
- const parent = await deReferenceContext(anchor.parent.context);
35
- const newAnchor = parent.getAnchor(anchor.anchorId);
36
- if (!newAnchor) {
37
- return new deserializationClass(anchor.anchorId, parent);
38
- }
39
- return newAnchor;
40
- }
41
- }
@@ -1,7 +0,0 @@
1
- import { IModelReference } from '../models/model.interface.js';
2
- import { AAnchor } from './anchor.abstract.js';
3
-
4
- export interface IAnchor {
5
- anchorId: AAnchor['anchorId'];
6
- parent: IModelReference;
7
- }
@@ -1,41 +0,0 @@
1
- import { UnknownModel } from '../app.type.js';
2
- import { App } from '../models/app/app.model.js';
3
- import { AAnchor } from './anchor.abstract.js';
4
-
5
- class TestAnchor extends AAnchor {
6
- constructor(anchorId: string, parent: UnknownModel) {
7
- super(anchorId, parent);
8
- }
9
- }
10
-
11
- describe('Anchor UT', () => {
12
- describe('synth()', () => {
13
- it('should be able to synth an anchor', () => {
14
- const app = new App('test');
15
- const anchor = new TestAnchor('anchor-1', app);
16
-
17
- expect(anchor.synth()).toMatchInlineSnapshot(`
18
- {
19
- "anchorId": "anchor-1",
20
- "parent": {
21
- "context": "app=test",
22
- },
23
- }
24
- `);
25
- });
26
- });
27
-
28
- describe('toJSON()', () => {
29
- it('should be able to JSON summarize an anchor', () => {
30
- const app = new App('test');
31
- const anchor = new TestAnchor('anchor-1', app);
32
-
33
- expect(anchor.toJSON()).toMatchInlineSnapshot(`
34
- {
35
- "anchorId": "anchor-1",
36
- "parent": "app=test",
37
- }
38
- `);
39
- });
40
- });
41
- });
@@ -1,76 +0,0 @@
1
- import { ModelType, UnknownOverlay } from '../app.type.js';
2
- import { Factory } from '../decorators/factory.decorator.js';
3
- import { Diff, DiffAction } from '../functions/diff/diff.model.js';
4
- import { IOverlay } from './overlay.interface.js';
5
-
6
- export class OverlayDataRepository {
7
- constructor(
8
- private readonly oldOverlays: UnknownOverlay[] = [],
9
- private readonly newOverlays: UnknownOverlay[] = [],
10
- ) {
11
- Object.freeze(this.oldOverlays);
12
- }
13
-
14
- add(overlay: UnknownOverlay): void {
15
- if (overlay.MODEL_TYPE !== ModelType.OVERLAY) {
16
- throw new Error('Adding non-overlay model!');
17
- }
18
-
19
- if (!this.getById(overlay.overlayId)) {
20
- this.newOverlays.push(overlay);
21
- }
22
- }
23
-
24
- diff(): Diff[] {
25
- const diffs: Diff[] = [];
26
-
27
- for (const overlay of this.oldOverlays) {
28
- if (!this.newOverlays.find((o) => o.overlayId === overlay.overlayId)) {
29
- diffs.push(new Diff(overlay, DiffAction.DELETE, 'overlayId', overlay.overlayId));
30
- }
31
- }
32
-
33
- for (const overlay of this.newOverlays) {
34
- if (!this.oldOverlays.find((o) => o.overlayId === overlay.overlayId)) {
35
- diffs.push(new Diff(overlay, DiffAction.ADD, 'overlayId', overlay.overlayId));
36
- }
37
- }
38
-
39
- return diffs;
40
- }
41
-
42
- getById(overlayId: IOverlay['overlayId']): UnknownOverlay | undefined {
43
- return this.newOverlays.find((o) => o.overlayId === overlayId);
44
- }
45
-
46
- getByProperties(filters: { key: string; value: any }[] = []): UnknownOverlay[] {
47
- return this.newOverlays.filter((o) => filters.every((c) => o.properties[c.key] === c.value));
48
- }
49
-
50
- remove(overlay: UnknownOverlay): void {
51
- if (overlay.MODEL_TYPE !== ModelType.OVERLAY) {
52
- throw new Error('Adding non-overlay model!');
53
- }
54
-
55
- const overlayIndex = this.newOverlays.findIndex((o) => o.overlayId === overlay.overlayId);
56
- if (overlayIndex > -1) {
57
- this.newOverlays.splice(overlayIndex, 1);
58
- }
59
- }
60
- }
61
-
62
- @Factory<OverlayDataRepository>(OverlayDataRepository)
63
- export class OverlayDataRepositoryFactory {
64
- private static instance: OverlayDataRepository;
65
-
66
- static async create(
67
- forceNew: boolean,
68
- newOverlays: UnknownOverlay[],
69
- oldOverlays: UnknownOverlay[],
70
- ): Promise<OverlayDataRepository> {
71
- if (forceNew || !this.instance) {
72
- this.instance = new OverlayDataRepository(newOverlays, oldOverlays);
73
- }
74
- return this.instance;
75
- }
76
- }
@@ -1,64 +0,0 @@
1
- import { ModelType, UnknownModel, UnknownOverlay } from '../app.type.js';
2
- import { AModel } from '../models/model.abstract.js';
3
- import { Diff } from '../functions/diff/diff.model.js';
4
- import { AAnchor } from './anchor.abstract.js';
5
- import { IOverlay } from './overlay.interface.js';
6
-
7
- export abstract class AOverlay<T> extends AModel<IOverlay, T> {
8
- abstract override readonly MODEL_NAME: string;
9
- override readonly MODEL_TYPE: ModelType = ModelType.OVERLAY;
10
-
11
- readonly overlayId: IOverlay['overlayId'];
12
-
13
- readonly properties: IOverlay['properties'] = {};
14
-
15
- protected constructor(overlayId: IOverlay['overlayId'], properties: IOverlay['properties'], anchors: AAnchor[]) {
16
- super();
17
-
18
- this.overlayId = overlayId;
19
-
20
- for (const key in properties) {
21
- this.properties[key] = properties[key];
22
- }
23
-
24
- for (const anchor of anchors) {
25
- this.addRelationship('overlayId', anchor.getParent(), 'MODEL_NAME');
26
- this.anchors.push(anchor);
27
- }
28
- }
29
-
30
- async diff(): Promise<Diff[]> {
31
- return [];
32
- }
33
-
34
- getContext(): string {
35
- return `${this.MODEL_NAME}=${this.overlayId}`;
36
- }
37
-
38
- synth(): IOverlay {
39
- return {
40
- anchors: this.anchors.map((a) => a.synth()),
41
- overlayId: this.overlayId,
42
- properties: { ...this.properties },
43
- };
44
- }
45
-
46
- static async unSynth(
47
- deserializationClass: any,
48
- overlay: IOverlay,
49
- deReferenceContext: (context: string) => Promise<UnknownModel>,
50
- ): Promise<UnknownOverlay> {
51
- const anchors = await Promise.all(
52
- overlay.anchors.map(async (a) => {
53
- const parent = await deReferenceContext(a.parent.context);
54
- const anchor = parent.getAnchor(a.anchorId);
55
- if (!anchor) {
56
- throw new Error('Cannot find anchor while deserializing overlay!');
57
- }
58
- return anchor;
59
- }),
60
- );
61
-
62
- return new deserializationClass(overlay.overlayId, overlay.properties, anchors);
63
- }
64
- }
@@ -1,9 +0,0 @@
1
- import { IAnchor } from './anchor.interface.js';
2
-
3
- export interface IOverlay {
4
- anchors: IAnchor[];
5
-
6
- overlayId: string;
7
-
8
- properties: { [key: string]: unknown };
9
- }
@@ -1,38 +0,0 @@
1
- import { UnknownOverlay } from '../app.type.js';
2
- import { Container } from '../decorators/container.js';
3
- import { Factory } from '../decorators/factory.decorator.js';
4
- import { OverlayDataRepository } from './overlay-data.repository.js';
5
-
6
- export class OverlayService {
7
- async addOverlay(overlay: UnknownOverlay): Promise<void> {
8
- const overlayDataRepository = await Container.get(OverlayDataRepository);
9
- overlayDataRepository.add(overlay);
10
- }
11
-
12
- async getOverlayById(overlayId: string): Promise<UnknownOverlay | undefined> {
13
- const overlayDataRepository = await Container.get(OverlayDataRepository);
14
- return overlayDataRepository.getById(overlayId);
15
- }
16
-
17
- async getOverlayByProperties(filters: { key: string; value: any }[] = []): Promise<UnknownOverlay[]> {
18
- const overlayDataRepository = await Container.get(OverlayDataRepository);
19
- return overlayDataRepository.getByProperties(filters);
20
- }
21
-
22
- async removeOverlay(overlay: UnknownOverlay): Promise<void> {
23
- const overlayDataRepository = await Container.get(OverlayDataRepository);
24
- overlayDataRepository.remove(overlay);
25
- }
26
- }
27
-
28
- @Factory<OverlayService>(OverlayService)
29
- export class OverlayServiceFactory {
30
- private static instance: OverlayService;
31
-
32
- static async create(): Promise<OverlayService> {
33
- if (!this.instance) {
34
- this.instance = new OverlayService();
35
- }
36
- return this.instance;
37
- }
38
- }
@@ -1,86 +0,0 @@
1
- import { TestAnchor, TestOverlay } from '../../test/helpers/test-classes.js';
2
- import { App } from '../models/app/app.model.js';
3
- import { AOverlay } from './overlay.abstract.js';
4
-
5
- describe('Overlay UT', () => {
6
- describe('synth()', () => {
7
- it('should be able to synth an empty overlay', () => {
8
- const overlay = new TestOverlay('overlay-1', {}, []);
9
-
10
- expect(overlay.synth()).toMatchInlineSnapshot(`
11
- {
12
- "anchors": [],
13
- "overlayId": "overlay-1",
14
- "properties": {},
15
- }
16
- `);
17
- });
18
-
19
- it('should be able to synth with anchors', () => {
20
- const app = new App('test');
21
- const anchor1 = new TestAnchor('anchor-1', app);
22
- const anchor2 = new TestAnchor('anchor-2', app);
23
- const overlay = new TestOverlay('overlay-1', { key1: 'value1' }, [anchor1, anchor2]);
24
-
25
- expect(overlay.synth()).toMatchInlineSnapshot(`
26
- {
27
- "anchors": [
28
- {
29
- "anchorId": "anchor-1",
30
- "parent": {
31
- "context": "app=test",
32
- },
33
- },
34
- {
35
- "anchorId": "anchor-2",
36
- "parent": {
37
- "context": "app=test",
38
- },
39
- },
40
- ],
41
- "overlayId": "overlay-1",
42
- "properties": {
43
- "key1": "value1",
44
- },
45
- }
46
- `);
47
- });
48
- });
49
-
50
- describe('unSynth', () => {
51
- it('should throw error while unSynth if anchor not found', async () => {
52
- const app = new App('test');
53
- const anchor1 = new TestAnchor('anchor-1', app);
54
- const anchor2 = new TestAnchor('anchor-2', app);
55
- const overlay = new TestOverlay('overlay-1', { key1: 'value1' }, [anchor1, anchor2]);
56
- const overlaySynth = overlay.synth();
57
-
58
- const deReferenceContext = async (): Promise<App> => {
59
- const app = new App('test');
60
- app['anchors'].push(anchor1);
61
- return app;
62
- };
63
-
64
- await expect(async () => {
65
- await AOverlay.unSynth(TestOverlay, overlaySynth, deReferenceContext);
66
- }).rejects.toThrowErrorMatchingInlineSnapshot(`"Cannot find anchor while deserializing overlay!"`);
67
- });
68
-
69
- it('should be able to unSynth with anchors', async () => {
70
- const app = new App('test');
71
- const anchor1 = new TestAnchor('anchor-1', app);
72
- const anchor2 = new TestAnchor('anchor-2', app);
73
- const overlay = new TestOverlay('overlay-1', { key1: 'value1' }, [anchor1, anchor2]);
74
- const overlaySynth = overlay.synth();
75
-
76
- const deReferenceContext = async (): Promise<App> => {
77
- const app = new App('test');
78
- app['anchors'].push(anchor1, anchor2);
79
- return app;
80
- };
81
- const overlayUnSynth = await AOverlay.unSynth(TestOverlay, overlaySynth, deReferenceContext);
82
-
83
- expect(overlayUnSynth.synth()).toEqual(overlaySynth);
84
- });
85
- });
86
- });
@@ -1,9 +0,0 @@
1
- import { Diff } from '../functions/diff/diff.model.js';
2
-
3
- export interface IResourceAction {
4
- readonly ACTION_NAME: string;
5
-
6
- filter(diff: Diff): boolean;
7
-
8
- handle(diff: Diff): Promise<void>;
9
- }