forked from finos/architecture-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoment.ts
More file actions
65 lines (60 loc) · 2.17 KB
/
moment.ts
File metadata and controls
65 lines (60 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { CalmControls } from './control.js';
import { CalmMetadata } from './metadata.js';
import { CalmNodeDetails } from './node.js';
import { CalmMomentSchema } from '../types';
import { CalmAdaptable } from './adaptable.js';
import { CalmMomentCanonicalModel } from '../canonical/template-models.js';
import { CalmNode } from './node.js';
export class CalmMoment extends CalmNode implements CalmAdaptable<CalmMomentSchema, CalmMomentCanonicalModel> {
constructor(
public originalJson: CalmMomentSchema,
public uniqueId: string,
public name: string,
public description: string,
public validFrom?: string,
public details?: CalmNodeDetails,
public controls?: CalmControls,
public metadata?: CalmMetadata,
public adrs?: string[],
public additionalProperties?: Record<string, unknown>
) {
super(originalJson, uniqueId, 'moment', name, description, details, undefined, controls, metadata, additionalProperties);
this.validFrom = validFrom;
this.adrs = adrs;
}
toCanonicalSchema(): CalmMomentCanonicalModel {
const moment: CalmMomentCanonicalModel = super.toCanonicalSchema();
moment.adrs = this.adrs;
moment['valid-from'] = this.validFrom;
return moment;
}
static fromSchema(schema: CalmMomentSchema): CalmMoment {
const {
'unique-id': uniqueId,
name,
description,
'node-type': _, // will be 'moment'
'valid-from': validFrom,
details,
controls,
metadata,
adrs,
...additional
} = schema;
return new CalmMoment(
schema,
uniqueId,
name,
description,
validFrom,
details ? CalmNodeDetails.fromSchema(details) : undefined,
controls ? CalmControls.fromSchema(controls) : undefined,
metadata ? CalmMetadata.fromSchema(metadata) : undefined,
adrs,
Object.keys(additional).length > 0 ? additional : undefined
);
}
toSchema(): CalmMomentSchema {
return this.originalJson;
}
}