Skip to content

Commit 45b646b

Browse files
Robin BuschmannRobin Buschmann
Robin Buschmann
authored and
Robin Buschmann
committed
implementation + tests
1 parent 68cbe04 commit 45b646b

37 files changed

+1325
-0
lines changed

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.md]
13+
insert_final_newline = false
14+
trim_trailing_whitespace = false

.gitignore

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# mac
2+
*.DS_Store
3+
4+
# ide
5+
.idea
6+
7+
# libraries
8+
node_modules
9+
10+
# testing
11+
coverage
12+
13+
# certificates
14+
certificates/*
15+
16+
# documentation
17+
documentation
18+
19+
# js files
20+
# **/*.js
21+
# **/*.js.map
22+
23+
# Elastic Beanstalk Files
24+
.elasticbeanstalk/*
25+
!.elasticbeanstalk/*.cfg.yml
26+
!.elasticbeanstalk/*.global.yml
27+
28+
# logs
29+
npm-debug.log

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact=true

annotations/XMLAttribute.js

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

annotations/XMLAttribute.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

annotations/XMLAttribute.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'reflect-metadata';
2+
import {XMLAttribute as XMLAttributeModel} from "../models/XMLAttribute";
3+
4+
export function XMLAttribute(target: any, key: string, descriptor?: TypedPropertyDescriptor<any>): void;
5+
export function XMLAttribute(options: any): Function;
6+
export function XMLAttribute(...args: any[]): void|Function {
7+
8+
if (args.length === 1) {
9+
10+
return (target: any, key: string, descriptor?: TypedPropertyDescriptor<any>) => {
11+
12+
return XMLAttributeModel.process(target, key, args[0], descriptor);
13+
};
14+
}
15+
return XMLAttributeModel.process(args[0], args[1], void 0, args[2]);
16+
}

annotations/XMLChild.js

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

annotations/XMLChild.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

annotations/XMLChild.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'reflect-metadata';
2+
import {XMLChild as XMLChildModel} from "../models/XMLChild";
3+
4+
export function XMLChild(target: any, key: string, descriptor?: TypedPropertyDescriptor<any>): void;
5+
export function XMLChild(options: any): Function;
6+
export function XMLChild(...args: any[]): void|Function {
7+
8+
if (args.length === 1) {
9+
10+
return (target: any, key: string, descriptor?: TypedPropertyDescriptor<any>) => {
11+
12+
return XMLChildModel.process(target, key, args[0], descriptor);
13+
};
14+
}
15+
return XMLChildModel.process(args[0], args[1], void 0, args[2]);
16+
}

annotations/XMLElement.js

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

annotations/XMLElement.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

annotations/XMLElement.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'reflect-metadata';
2+
import {XMLElement as XMLElementModel} from "../models/XMLElement";
3+
4+
export function XMLElement(options: any): Function {
5+
6+
return (target: any) => {
7+
8+
return XMLElementModel.process(target, options);
9+
};
10+
}

models/XMLAttribute.js

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/XMLAttribute.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/XMLAttribute.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {XMLElement} from "./XMLElement";
2+
3+
export class XMLAttribute {
4+
5+
private name: string;
6+
7+
static process(target: any,
8+
key: string,
9+
options: any = {},
10+
descriptor?: TypedPropertyDescriptor<any>): void {
11+
12+
const targetClass = target.constructor;
13+
const element = XMLElement.getXMLElement(targetClass);
14+
15+
options.name = options.name || key;
16+
options.getter = entity => {
17+
18+
if (descriptor) {
19+
return descriptor.get.call(entity);
20+
}
21+
22+
return entity[key];
23+
};
24+
25+
element.addAttribute(new XMLAttribute(options));
26+
}
27+
28+
setSchema(target: any, entity: any): void {
29+
30+
const value = this.options.getter.call(null, entity);
31+
32+
if (value !== void 0) {
33+
target[this.name] = value;
34+
} else if (this.options.mandatory) {
35+
36+
throw new Error(`Attribute ${this.name} is mandatory, but empty.`);
37+
}
38+
}
39+
40+
private constructor(private options: any) {
41+
42+
this.name = options.name;
43+
44+
if (options.namespace) {
45+
46+
this.name = options.namespace + ':' + this.name;
47+
}
48+
}
49+
}

models/XMLChild.js

+131
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/XMLChild.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)