@sap-ux/xml-odata-annotation-converter 0.1.1
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/LICENSE +201 -0
- package/README.md +55 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/attribute-getters.d.ts +18 -0
- package/dist/parser/attribute-getters.d.ts.map +1 -0
- package/dist/parser/attribute-getters.js +28 -0
- package/dist/parser/attribute-getters.js.map +1 -0
- package/dist/parser/document.d.ts +11 -0
- package/dist/parser/document.d.ts.map +1 -0
- package/dist/parser/document.js +325 -0
- package/dist/parser/document.js.map +1 -0
- package/dist/parser/element-getters.d.ts +10 -0
- package/dist/parser/element-getters.d.ts.map +1 -0
- package/dist/parser/element-getters.js +15 -0
- package/dist/parser/element-getters.js.map +1 -0
- package/dist/parser/escaping.d.ts +8 -0
- package/dist/parser/escaping.d.ts.map +1 -0
- package/dist/parser/escaping.js +21 -0
- package/dist/parser/escaping.js.map +1 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +10 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/metadata.d.ts +11 -0
- package/dist/parser/metadata.d.ts.map +1 -0
- package/dist/parser/metadata.js +515 -0
- package/dist/parser/metadata.js.map +1 -0
- package/dist/parser/range.d.ts +37 -0
- package/dist/parser/range.d.ts.map +1 -0
- package/dist/parser/range.js +67 -0
- package/dist/parser/range.js.map +1 -0
- package/dist/printer/builders.d.ts +49 -0
- package/dist/printer/builders.d.ts.map +1 -0
- package/dist/printer/builders.js +138 -0
- package/dist/printer/builders.js.map +1 -0
- package/dist/printer/csdl-to-xml.d.ts +23 -0
- package/dist/printer/csdl-to-xml.d.ts.map +1 -0
- package/dist/printer/csdl-to-xml.js +160 -0
- package/dist/printer/csdl-to-xml.js.map +1 -0
- package/dist/printer/document-modifier.d.ts +6 -0
- package/dist/printer/document-modifier.d.ts.map +1 -0
- package/dist/printer/document-modifier.js +47 -0
- package/dist/printer/document-modifier.js.map +1 -0
- package/dist/printer/index.d.ts +5 -0
- package/dist/printer/index.d.ts.map +1 -0
- package/dist/printer/index.js +31 -0
- package/dist/printer/index.js.map +1 -0
- package/dist/printer/namespaces.d.ts +3 -0
- package/dist/printer/namespaces.d.ts.map +1 -0
- package/dist/printer/namespaces.js +6 -0
- package/dist/printer/namespaces.js.map +1 -0
- package/dist/printer/serializer-edmx.d.ts +46 -0
- package/dist/printer/serializer-edmx.d.ts.map +1 -0
- package/dist/printer/serializer-edmx.js +214 -0
- package/dist/printer/serializer-edmx.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type Document = string | Concat | Indent | Line;
|
|
2
|
+
export interface Concat {
|
|
3
|
+
type: 'concat';
|
|
4
|
+
parts: Document[];
|
|
5
|
+
}
|
|
6
|
+
export interface Indent {
|
|
7
|
+
type: 'indent';
|
|
8
|
+
content: Document;
|
|
9
|
+
}
|
|
10
|
+
export interface Line {
|
|
11
|
+
type: 'line';
|
|
12
|
+
hard: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface Options {
|
|
15
|
+
/**
|
|
16
|
+
* Specify the number of spaces per indentation-level.
|
|
17
|
+
*/
|
|
18
|
+
tabWidth: number;
|
|
19
|
+
}
|
|
20
|
+
export interface IndentInfo {
|
|
21
|
+
value: string;
|
|
22
|
+
length: number;
|
|
23
|
+
level: number;
|
|
24
|
+
}
|
|
25
|
+
export declare const line: Line;
|
|
26
|
+
export declare const hardline: Line;
|
|
27
|
+
/**
|
|
28
|
+
* Creates Concat.
|
|
29
|
+
*
|
|
30
|
+
* @param parts
|
|
31
|
+
* @returns concat object
|
|
32
|
+
*/
|
|
33
|
+
export declare function concat(parts: Document[]): Concat;
|
|
34
|
+
/**
|
|
35
|
+
* Creates Indent.
|
|
36
|
+
*
|
|
37
|
+
* @param content
|
|
38
|
+
* @returns indent object
|
|
39
|
+
*/
|
|
40
|
+
export declare function indent(content: Document): Indent;
|
|
41
|
+
/**
|
|
42
|
+
* Serializes given document to string.
|
|
43
|
+
*
|
|
44
|
+
* @param document document object.
|
|
45
|
+
* @param options serialization options
|
|
46
|
+
* @returns stringified document
|
|
47
|
+
*/
|
|
48
|
+
export declare function printDocumentToString(document: Document, options: Options): string;
|
|
49
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../src/printer/builders.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAEvD,MAAM,WAAW,MAAM;IACnB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,QAAQ,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,MAAM;IACnB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,IAAI;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,OAAO;IACpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CACpB;AACD,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,IAAI,EAAE,IAAoC,CAAC;AACxD,eAAO,MAAM,QAAQ,EAAE,IAAmC,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,QAAQ,GAAG,MAAM,CAEhD;AAID;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAgBlF"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printDocumentToString = exports.indent = exports.concat = exports.hardline = exports.line = void 0;
|
|
4
|
+
exports.line = { type: 'line', hard: false };
|
|
5
|
+
exports.hardline = { type: 'line', hard: true };
|
|
6
|
+
/**
|
|
7
|
+
* Creates Concat.
|
|
8
|
+
*
|
|
9
|
+
* @param parts
|
|
10
|
+
* @returns concat object
|
|
11
|
+
*/
|
|
12
|
+
function concat(parts) {
|
|
13
|
+
return { type: 'concat', parts };
|
|
14
|
+
}
|
|
15
|
+
exports.concat = concat;
|
|
16
|
+
/**
|
|
17
|
+
* Creates Indent.
|
|
18
|
+
*
|
|
19
|
+
* @param content
|
|
20
|
+
* @returns indent object
|
|
21
|
+
*/
|
|
22
|
+
function indent(content) {
|
|
23
|
+
return { type: 'indent', content };
|
|
24
|
+
}
|
|
25
|
+
exports.indent = indent;
|
|
26
|
+
const TRAILING_WHITESPACE_PATTERN = /\n[\t ]*$/;
|
|
27
|
+
/**
|
|
28
|
+
* Serializes given document to string.
|
|
29
|
+
*
|
|
30
|
+
* @param document document object.
|
|
31
|
+
* @param options serialization options
|
|
32
|
+
* @returns stringified document
|
|
33
|
+
*/
|
|
34
|
+
function printDocumentToString(document, options) {
|
|
35
|
+
const commands = [[{ length: 0, value: '', level: 0 }, document]];
|
|
36
|
+
const fragments = [];
|
|
37
|
+
while (commands.length > 0) {
|
|
38
|
+
const command = commands.pop();
|
|
39
|
+
if (command === null || command === void 0 ? void 0 : command.length) {
|
|
40
|
+
const [indent, doc] = command;
|
|
41
|
+
if (typeof doc === 'string') {
|
|
42
|
+
processStringDoc(fragments, indent, doc);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
processComplexDoc(fragments, commands, options, indent, doc);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return fragments.join('');
|
|
50
|
+
}
|
|
51
|
+
exports.printDocumentToString = printDocumentToString;
|
|
52
|
+
/**
|
|
53
|
+
* Inserts given doc into fragments considering spacing.
|
|
54
|
+
*
|
|
55
|
+
* @param fragments fragments array
|
|
56
|
+
* @param indent current indent data
|
|
57
|
+
* @param doc new fragment
|
|
58
|
+
*/
|
|
59
|
+
function processStringDoc(fragments, indent, doc) {
|
|
60
|
+
// trim trailing whitespace of previous line
|
|
61
|
+
if (doc) {
|
|
62
|
+
if (fragments.length === 0) {
|
|
63
|
+
fragments.push(indent.value);
|
|
64
|
+
}
|
|
65
|
+
if (TRAILING_WHITESPACE_PATTERN.test(fragments[fragments.length - 1]) && doc.startsWith(indent.value)) {
|
|
66
|
+
fragments[fragments.length - 1] = fragments[fragments.length - 1].replace(TRAILING_WHITESPACE_PATTERN, '\n');
|
|
67
|
+
}
|
|
68
|
+
fragments.push(doc);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const newLine = '\n';
|
|
72
|
+
const whitespace = ' ';
|
|
73
|
+
/**
|
|
74
|
+
* Processes Concat, Indent and Line elements.
|
|
75
|
+
*
|
|
76
|
+
* @param fragments
|
|
77
|
+
* @param commands
|
|
78
|
+
* @param options
|
|
79
|
+
* @param indent
|
|
80
|
+
* @param doc
|
|
81
|
+
*/
|
|
82
|
+
function processComplexDoc(fragments, commands, options, indent, doc) {
|
|
83
|
+
switch (doc.type) {
|
|
84
|
+
case 'concat': {
|
|
85
|
+
for (let i = doc.parts.length - 1; i >= 0; i--) {
|
|
86
|
+
commands.push([indent, doc.parts[i]]);
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case 'indent': {
|
|
91
|
+
commands.push([addIndent(indent, options), doc.content]);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'line': {
|
|
95
|
+
// trim trailing whitespace of previous line
|
|
96
|
+
if (TRAILING_WHITESPACE_PATTERN.test(fragments[fragments.length - 1])) {
|
|
97
|
+
fragments[fragments.length - 1] = fragments[fragments.length - 1].replace(TRAILING_WHITESPACE_PATTERN, '\n');
|
|
98
|
+
}
|
|
99
|
+
if (doc.hard) {
|
|
100
|
+
fragments.push(newLine + indent.value);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
fragments.push(whitespace);
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Adds single indent.
|
|
112
|
+
*
|
|
113
|
+
* @param indent
|
|
114
|
+
* @param options
|
|
115
|
+
* @returns indent information
|
|
116
|
+
*/
|
|
117
|
+
function addIndent(indent, options) {
|
|
118
|
+
return generateIndent(indent, 1, options);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Generates indent by given level index.
|
|
122
|
+
*
|
|
123
|
+
* @param indent indent information
|
|
124
|
+
* @param change adjustment level
|
|
125
|
+
* @param options
|
|
126
|
+
* @returns indentation information
|
|
127
|
+
*/
|
|
128
|
+
function generateIndent(indent, change, options) {
|
|
129
|
+
const level = indent.level + change;
|
|
130
|
+
let value = '';
|
|
131
|
+
let length = 0;
|
|
132
|
+
for (let i = 0; i < level; i++) {
|
|
133
|
+
value += ' '.repeat(options.tabWidth);
|
|
134
|
+
length += options.tabWidth;
|
|
135
|
+
}
|
|
136
|
+
return { value, length, level };
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../../src/printer/builders.ts"],"names":[],"mappings":";;;AA6Ba,QAAA,IAAI,GAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC3C,QAAA,QAAQ,GAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IA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
import type { Options } from './builders';
|
|
4
|
+
export interface PrintContext {
|
|
5
|
+
namespaces?: NamespaceAliasMap;
|
|
6
|
+
/**
|
|
7
|
+
* Number that describes how deeply nested is this element relative to the document root element
|
|
8
|
+
* 0 based
|
|
9
|
+
*/
|
|
10
|
+
cursorIndentLevel: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const printCsdlNodeToXmlString: (snippet: Node | Node[], opts: Options, context: PrintContext) => string;
|
|
13
|
+
export interface NamespaceAliasMap {
|
|
14
|
+
[EDM_NAMESPACE_ALIAS]?: string;
|
|
15
|
+
[EDMX_NAMESPACE_ALIAS]?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const escapeText: (input: string) => string;
|
|
18
|
+
export declare const unescapeText: (input: string) => string;
|
|
19
|
+
export declare const escapeAttribute: (input: string) => string;
|
|
20
|
+
export declare const unescapeAttribute: (input: string) => string;
|
|
21
|
+
type Node = Element | TextNode;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=csdl-to-xml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csdl-to-xml.d.ts","sourceRoot":"","sources":["../../src/printer/csdl-to-xml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAuB,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAA2B,mBAAmB,EAAE,oBAAoB,EAAO,MAAM,+BAA+B,CAAC;AAExH,OAAO,KAAK,EAAoB,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5D,MAAM,WAAW,YAAY;IACzB,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,wBAAwB,YAAa,IAAI,GAAG,IAAI,EAAE,QAAQ,OAAO,WAAW,YAAY,KAAG,MAcvG,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAC9B,CAAC,mBAAmB,CAAC,CAAC,EAAE,MAAM,CAAC;IAC/B,CAAC,oBAAoB,CAAC,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,eAAO,MAAM,UAAU,UAAW,MAAM,KAAG,MAO1C,CAAC;AAEF,eAAO,MAAM,YAAY,UAAW,MAAM,WAOzC,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,MAAM,KAAG,MAO/C,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,MAAM,WAO9C,CAAC;AAEF,KAAK,IAAI,GAAG,OAAO,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unescapeAttribute = exports.escapeAttribute = exports.unescapeText = exports.escapeText = exports.printCsdlNodeToXmlString = void 0;
|
|
4
|
+
const odata_annotation_core_1 = require("@sap-ux/odata-annotation-core");
|
|
5
|
+
const builders_1 = require("./builders");
|
|
6
|
+
const printCsdlNodeToXmlString = (snippet, opts, context) => {
|
|
7
|
+
const snippets = Array.isArray(snippet) ? snippet : [snippet];
|
|
8
|
+
const doc = (0, builders_1.concat)(snippets.map((item, idx) => (0, builders_1.concat)([printCsdlRootNode(item, context), idx === snippets.length - 1 ? '' : builders_1.hardline])));
|
|
9
|
+
doc.parts.forEach((part, index) => {
|
|
10
|
+
for (let i = 0; i < context.cursorIndentLevel; i++) {
|
|
11
|
+
doc.parts[index] = (0, builders_1.indent)(doc.parts[index]);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return (0, builders_1.printDocumentToString)(doc, opts);
|
|
15
|
+
};
|
|
16
|
+
exports.printCsdlNodeToXmlString = printCsdlNodeToXmlString;
|
|
17
|
+
const escapeText = (input) => {
|
|
18
|
+
if (!input || typeof input !== 'string') {
|
|
19
|
+
return input;
|
|
20
|
+
}
|
|
21
|
+
return input.replace(/([<&])/g, (str, item) => {
|
|
22
|
+
return { '<': '<', '&': '&' }[item];
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.escapeText = escapeText;
|
|
26
|
+
const unescapeText = (input) => {
|
|
27
|
+
if (!input || typeof input !== 'string') {
|
|
28
|
+
return input;
|
|
29
|
+
}
|
|
30
|
+
return input.replace(/(<|&)/g, (str, item) => {
|
|
31
|
+
return { '<': '<', '&': '&' }[item];
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.unescapeText = unescapeText;
|
|
35
|
+
const escapeAttribute = (input) => {
|
|
36
|
+
if (!input || typeof input !== 'string') {
|
|
37
|
+
return input;
|
|
38
|
+
}
|
|
39
|
+
return input.replace(/([<&"])/g, (str, item) => {
|
|
40
|
+
return { '<': '<', '&': '&', '"': '"' }[item];
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.escapeAttribute = escapeAttribute;
|
|
44
|
+
const unescapeAttribute = (input) => {
|
|
45
|
+
if (!input || typeof input !== 'string') {
|
|
46
|
+
return input;
|
|
47
|
+
}
|
|
48
|
+
return input.replace(/(<|&|")/g, (str, item) => {
|
|
49
|
+
return { '<': '<', '&': '&', '"': '"' }[item];
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
exports.unescapeAttribute = unescapeAttribute;
|
|
53
|
+
const printCsdlRootNode = (node, context) => {
|
|
54
|
+
switch (node.type) {
|
|
55
|
+
case odata_annotation_core_1.ELEMENT_TYPE: {
|
|
56
|
+
return printElement(node, context);
|
|
57
|
+
}
|
|
58
|
+
case odata_annotation_core_1.TEXT_TYPE:
|
|
59
|
+
return printText(node, true);
|
|
60
|
+
default:
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const printCsdlNode = (node, context) => {
|
|
65
|
+
switch (node.type) {
|
|
66
|
+
case odata_annotation_core_1.ELEMENT_TYPE:
|
|
67
|
+
return printElement(node, context);
|
|
68
|
+
case odata_annotation_core_1.TEXT_TYPE:
|
|
69
|
+
return printText(node, true);
|
|
70
|
+
default:
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const join = (sep) => (values) => values.filter((value) => value !== undefined && value !== null).join(sep);
|
|
75
|
+
const joinWithColon = join(':');
|
|
76
|
+
const prefixName = (prefix, name) => joinWithColon([prefix, name]);
|
|
77
|
+
const prefixElementNameIfNeeded = (name, namespaceAlias, namespaces = {}) => {
|
|
78
|
+
switch (namespaceAlias) {
|
|
79
|
+
case odata_annotation_core_1.EDMX_NAMESPACE_ALIAS:
|
|
80
|
+
return prefixName(namespaces[odata_annotation_core_1.EDMX_NAMESPACE_ALIAS], name);
|
|
81
|
+
case odata_annotation_core_1.EDM_NAMESPACE_ALIAS:
|
|
82
|
+
return prefixName(namespaces[odata_annotation_core_1.EDM_NAMESPACE_ALIAS], name);
|
|
83
|
+
default:
|
|
84
|
+
return prefixName(namespaces[odata_annotation_core_1.EDM_NAMESPACE_ALIAS], name);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const printEmptyElement = (element, context) => {
|
|
88
|
+
const name = prefixElementNameIfNeeded(element.name, element.namespaceAlias, context.namespaces);
|
|
89
|
+
return (0, builders_1.concat)(['<', name, printAttributes(element.attributes), '/>']);
|
|
90
|
+
};
|
|
91
|
+
const printText = (node, doEscape) => {
|
|
92
|
+
return doEscape ? (0, exports.escapeText)(node.text) : node.text;
|
|
93
|
+
};
|
|
94
|
+
const printAttribute = (name, value) => {
|
|
95
|
+
if (value !== undefined && value !== null) {
|
|
96
|
+
return `${name}="${(0, exports.escapeAttribute)(value)}"`;
|
|
97
|
+
}
|
|
98
|
+
return name;
|
|
99
|
+
};
|
|
100
|
+
const structuredExpressions = new Set([
|
|
101
|
+
'Annotations',
|
|
102
|
+
'Annotation',
|
|
103
|
+
'Collection',
|
|
104
|
+
'Record',
|
|
105
|
+
'PropertyValue',
|
|
106
|
+
'Apply',
|
|
107
|
+
'LabeledElement'
|
|
108
|
+
]);
|
|
109
|
+
const dynamicExpressions = new Set([
|
|
110
|
+
"If" /* Edm.If */,
|
|
111
|
+
"Not" /* Edm.Not */,
|
|
112
|
+
"And" /* Edm.And */,
|
|
113
|
+
"Or" /* Edm.Or */,
|
|
114
|
+
"Eq" /* Edm.Eq */,
|
|
115
|
+
"Ne" /* Edm.Ne */,
|
|
116
|
+
"Gt" /* Edm.Gt */,
|
|
117
|
+
"Ge" /* Edm.Ge */,
|
|
118
|
+
"Lt" /* Edm.Lt */,
|
|
119
|
+
"Le" /* Edm.Le */,
|
|
120
|
+
"In" /* Edm.In */
|
|
121
|
+
]);
|
|
122
|
+
const printElement = (element, context) => {
|
|
123
|
+
const dynamicExpression = dynamicExpressions.has(element.name);
|
|
124
|
+
const structured = structuredExpressions.has(element.name) || dynamicExpression;
|
|
125
|
+
if ((element.content || []).length === 0) {
|
|
126
|
+
return printEmptyElement(element, context);
|
|
127
|
+
}
|
|
128
|
+
const textNode = element.content[0].type === odata_annotation_core_1.TEXT_TYPE;
|
|
129
|
+
const name = prefixElementNameIfNeeded(element.name, element.namespaceAlias, context.namespaces);
|
|
130
|
+
const opening = (0, builders_1.concat)(['<', name, printAttributes(element.attributes), '>']);
|
|
131
|
+
const closing = (0, builders_1.concat)(['</', name, '>']);
|
|
132
|
+
const content = concatElementContent(element, structured, context);
|
|
133
|
+
return (0, builders_1.concat)([opening, (0, builders_1.indent)(content), textNode && !structured ? '' : builders_1.hardline, closing]);
|
|
134
|
+
};
|
|
135
|
+
const printAttributes = (attributes = {}) => {
|
|
136
|
+
const names = Object.keys(attributes);
|
|
137
|
+
if (names.length === 0) {
|
|
138
|
+
return '';
|
|
139
|
+
}
|
|
140
|
+
const parts = names.reduce((accumulator, name) => [...accumulator, builders_1.line, printAttribute(name, attributes[name].value)], []);
|
|
141
|
+
return (0, builders_1.indent)((0, builders_1.concat)(parts));
|
|
142
|
+
};
|
|
143
|
+
const concatElementContent = (element, structured, context) => {
|
|
144
|
+
let addHardLineBeforeText = true;
|
|
145
|
+
return (0, builders_1.concat)(element.content.map((node, idx) => {
|
|
146
|
+
let result;
|
|
147
|
+
if (idx === 0 && node.type === odata_annotation_core_1.ELEMENT_TYPE) {
|
|
148
|
+
addHardLineBeforeText = false;
|
|
149
|
+
}
|
|
150
|
+
if (node.type === odata_annotation_core_1.TEXT_TYPE) {
|
|
151
|
+
const text = structured && addHardLineBeforeText ? builders_1.hardline : '';
|
|
152
|
+
result = (0, builders_1.concat)([text, printText(node)]);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
result = (0, builders_1.concat)([builders_1.hardline, printCsdlNode(node, context)]);
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}));
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=csdl-to-xml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csdl-to-xml.js","sourceRoot":"","sources":["../../src/printer/csdl-to-xml.ts"],"names":[],"mappings":";;;AACA,yEAAwH;AAGxH,yCAAmF;AAY5E,MAAM,wBAAwB,GAAG,CAAC,OAAsB,EAAE,IAAa,EAAE,OAAqB,EAAU,EAAE;IAC7G,MAAM,QAAQ,GAAW,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAEtE,MAAM,GAAG,GAAG,IAAA,iBAAM,EACd,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CACvB,IAAA,iBAAM,EAAC,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,mBAAQ,CAAC,CAAC,CAC1F,CACJ,CAAC;IACF,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CA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9B,IAAI,MAAM,CAAC;QACX,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,oCAAY,EAAE;YACzC,qBAAqB,GAAG,KAAK,CAAC;SACjC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,iCAAS,EAAE;YACzB,MAAM,IAAI,GAAG,UAAU,IAAI,qBAAqB,CAAC,CAAC,CAAC,mBAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;YACjE,MAAM,GAAG,IAAA,iBAAM,EAAC,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAC5C;aAAM;YACH,MAAM,GAAG,IAAA,iBAAM,EAAC,CAAC,mBAAQ,EAAE,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;SAC7D;QACD,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC,CACL,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { XMLElement } from '@xml-tools/ast';
|
|
2
|
+
import type { Element, FormatterOptions } from '@sap-ux/odata-annotation-core';
|
|
3
|
+
import { TextEdit } from '@sap-ux/odata-annotation-core';
|
|
4
|
+
export declare const insert: (options: FormatterOptions) => (target: XMLElement, element: Element) => TextEdit | undefined;
|
|
5
|
+
export declare const insertWithOptions: (target: XMLElement, element: Element, { printWidth, tabWidth, useTabs }: FormatterOptions) => TextEdit | undefined;
|
|
6
|
+
//# sourceMappingURL=document-modifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-modifier.d.ts","sourceRoot":"","sources":["../../src/printer/document-modifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAA6C,QAAQ,EAAY,MAAM,+BAA+B,CAAC;AAM9G,eAAO,MAAM,MAAM,YACL,gBAAgB,cACjB,UAAU,WAAW,OAAO,KAAG,QAAQ,GAAG,SACJ,CAAC;AAEpD,eAAO,MAAM,iBAAiB,WAClB,UAAU,WACT,OAAO,qCACmB,gBAAgB,KACpD,QAAQ,GAAG,SA0Bb,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.insertWithOptions = exports.insert = void 0;
|
|
4
|
+
const odata_annotation_core_1 = require("@sap-ux/odata-annotation-core");
|
|
5
|
+
const csdl_to_xml_1 = require("./csdl-to-xml");
|
|
6
|
+
const namespaces_1 = require("./namespaces");
|
|
7
|
+
const insert = (options) => (target, element) => (0, exports.insertWithOptions)(target, element, options);
|
|
8
|
+
exports.insert = insert;
|
|
9
|
+
const insertWithOptions = (target, element, { printWidth, tabWidth, useTabs }) => {
|
|
10
|
+
let result;
|
|
11
|
+
const prettierOptions = {
|
|
12
|
+
printWidth,
|
|
13
|
+
useTabs,
|
|
14
|
+
tabWidth
|
|
15
|
+
};
|
|
16
|
+
if (target.syntax.openBody) {
|
|
17
|
+
const startColumn = target.syntax.openBody.startColumn - 1;
|
|
18
|
+
const targetCursorIndentLevel = startColumn === 0 ? 0 : startColumn / tabWidth;
|
|
19
|
+
const namespaces = target.namespaces && createNamespaceAliasMap(target);
|
|
20
|
+
const printContext = {
|
|
21
|
+
cursorIndentLevel: targetCursorIndentLevel + 1,
|
|
22
|
+
namespaces
|
|
23
|
+
};
|
|
24
|
+
const textParts = ['\n', (0, csdl_to_xml_1.printCsdlNodeToXmlString)(element, prettierOptions, printContext)];
|
|
25
|
+
const text = String.prototype.concat.apply('', textParts);
|
|
26
|
+
result = odata_annotation_core_1.TextEdit.insert(odata_annotation_core_1.Position.create(target.syntax.openBody.endLine - 1, // -1 because chevrotain is 1 based,
|
|
27
|
+
target.syntax.openBody.endColumn // -1 chevrotain offset + 1 next symbol after closing bracket
|
|
28
|
+
), text);
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
exports.insertWithOptions = insertWithOptions;
|
|
33
|
+
const createNamespaceAliasMap = (element) => Object.keys(element.namespaces).reduce((map, prefix) => {
|
|
34
|
+
const namespace = element.namespaces[prefix];
|
|
35
|
+
switch (namespace) {
|
|
36
|
+
case namespaces_1.EDMX_V4_NAMESPACE: {
|
|
37
|
+
map[odata_annotation_core_1.EDMX_NAMESPACE_ALIAS] = prefix;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case namespaces_1.EDM_V4_NAMESPACE: {
|
|
41
|
+
map[odata_annotation_core_1.EDM_NAMESPACE_ALIAS] = prefix;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return map;
|
|
46
|
+
}, {});
|
|
47
|
+
//# sourceMappingURL=document-modifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-modifier.js","sourceRoot":"","sources":["../../src/printer/document-modifier.ts"],"names":[],"mappings":";;;AAEA,yEAA8G;AAE9G,+CAAyD;AAEzD,6CAAmE;AAE5D,MAAM,MAAM,GACf,CAAC,OAAyB,EAAE,EAAE,CAC9B,CAAC,MAAkB,EAAE,OAAgB,EAAwB,EAAE,CAC3D,IAAA,yBAAiB,EAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAHvC,QAAA,MAAM,UAGiC;AAE7C,MAAM,iBAAiB,GAAG,CAC7B,MAAkB,EAClB,OAAgB,EAChB,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAoB,EAC/B,EAAE;IACtB,IAAI,MAAM,CAAC;IACX,MAAM,eAAe,GAAwB;QACzC,UAAU;QACV,OAAO;QACP,QAAQ;KACX,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;QACxB,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,QAA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GAAG,CAAC,2CAAmB,CAAC,GAAG,MAAM,CAAC;YAClC,MAAM;SACT;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { serializeAttribute, getNewAnnotationFile, serializeElement, serializeReference, serializeTarget } from './serializer-edmx';
|
|
2
|
+
export * from './namespaces';
|
|
3
|
+
export { printCsdlNodeToXmlString, PrintContext, escapeAttribute } from './csdl-to-xml';
|
|
4
|
+
export { insert, insertWithOptions } from './document-modifier';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/printer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAClB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.insertWithOptions = exports.insert = exports.escapeAttribute = exports.printCsdlNodeToXmlString = exports.serializeTarget = exports.serializeReference = exports.serializeElement = exports.getNewAnnotationFile = exports.serializeAttribute = void 0;
|
|
18
|
+
var serializer_edmx_1 = require("./serializer-edmx");
|
|
19
|
+
Object.defineProperty(exports, "serializeAttribute", { enumerable: true, get: function () { return serializer_edmx_1.serializeAttribute; } });
|
|
20
|
+
Object.defineProperty(exports, "getNewAnnotationFile", { enumerable: true, get: function () { return serializer_edmx_1.getNewAnnotationFile; } });
|
|
21
|
+
Object.defineProperty(exports, "serializeElement", { enumerable: true, get: function () { return serializer_edmx_1.serializeElement; } });
|
|
22
|
+
Object.defineProperty(exports, "serializeReference", { enumerable: true, get: function () { return serializer_edmx_1.serializeReference; } });
|
|
23
|
+
Object.defineProperty(exports, "serializeTarget", { enumerable: true, get: function () { return serializer_edmx_1.serializeTarget; } });
|
|
24
|
+
__exportStar(require("./namespaces"), exports);
|
|
25
|
+
var csdl_to_xml_1 = require("./csdl-to-xml");
|
|
26
|
+
Object.defineProperty(exports, "printCsdlNodeToXmlString", { enumerable: true, get: function () { return csdl_to_xml_1.printCsdlNodeToXmlString; } });
|
|
27
|
+
Object.defineProperty(exports, "escapeAttribute", { enumerable: true, get: function () { return csdl_to_xml_1.escapeAttribute; } });
|
|
28
|
+
var document_modifier_1 = require("./document-modifier");
|
|
29
|
+
Object.defineProperty(exports, "insert", { enumerable: true, get: function () { return document_modifier_1.insert; } });
|
|
30
|
+
Object.defineProperty(exports, "insertWithOptions", { enumerable: true, get: function () { return document_modifier_1.insertWithOptions; } });
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/printer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAM2B;AALvB,qHAAA,kBAAkB,OAAA;AAClB,uHAAA,oBAAoB,OAAA;AACpB,mHAAA,gBAAgB,OAAA;AAChB,qHAAA,kBAAkB,OAAA;AAClB,kHAAA,eAAe,OAAA;AAEnB,+CAA6B;AAC7B,6CAAwF;AAA/E,uHAAA,wBAAwB,OAAA;AAAgB,8GAAA,eAAe,OAAA;AAChE,yDAAgE;AAAvD,2GAAA,MAAM,OAAA;AAAE,sHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespaces.d.ts","sourceRoot":"","sources":["../../src/printer/namespaces.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,6CAA6C,CAAC;AAC5E,eAAO,MAAM,gBAAgB,4CAA4C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EDM_V4_NAMESPACE = exports.EDMX_V4_NAMESPACE = void 0;
|
|
4
|
+
exports.EDMX_V4_NAMESPACE = 'http://docs.oasis-open.org/odata/ns/edmx';
|
|
5
|
+
exports.EDM_V4_NAMESPACE = 'http://docs.oasis-open.org/odata/ns/edm';
|
|
6
|
+
//# sourceMappingURL=namespaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespaces.js","sourceRoot":"","sources":["../../src/printer/namespaces.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,0CAA0C,CAAC;AAC/D,QAAA,gBAAgB,GAAG,yCAAyC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Element, Attribute, Target, NoUndefinedNamespaceData, Position, AliasInformation, FileContent } from '@sap-ux/odata-annotation-core';
|
|
2
|
+
import type { Vocabulary, Namespace as VocabularyNamespace } from '@sap-ux/odata-vocabularies';
|
|
3
|
+
/**
|
|
4
|
+
* Serializes reference.
|
|
5
|
+
*
|
|
6
|
+
* @param data namespace data (must not be undefined)
|
|
7
|
+
* @param parentStartPosition
|
|
8
|
+
* @returns string
|
|
9
|
+
*/
|
|
10
|
+
export declare function serializeReference(data: NoUndefinedNamespaceData, parentStartPosition?: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* Serializes attribute.
|
|
13
|
+
*
|
|
14
|
+
* @param attribute
|
|
15
|
+
* @returns string
|
|
16
|
+
*/
|
|
17
|
+
export declare function serializeAttribute(attribute: Attribute): string;
|
|
18
|
+
/**
|
|
19
|
+
* Serializes element.
|
|
20
|
+
*
|
|
21
|
+
* @param element
|
|
22
|
+
* @param parentElementStartPosition
|
|
23
|
+
* @returns string
|
|
24
|
+
*/
|
|
25
|
+
export declare function serializeElement(element: Element, parentElementStartPosition?: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Serializes target.
|
|
28
|
+
*
|
|
29
|
+
* @param target
|
|
30
|
+
* @param parentStartPostition
|
|
31
|
+
* @returns string
|
|
32
|
+
*/
|
|
33
|
+
export declare function serializeTarget(target: Target, parentStartPostition?: number): string;
|
|
34
|
+
/**
|
|
35
|
+
* Creates new annotation file object.
|
|
36
|
+
*
|
|
37
|
+
* @param aliasInfo
|
|
38
|
+
* @param metadataUri
|
|
39
|
+
* @param vocabularies
|
|
40
|
+
* @returns annotation file object
|
|
41
|
+
*/
|
|
42
|
+
export declare function getNewAnnotationFile(aliasInfo: AliasInformation, metadataUri: string, vocabularies: Map<VocabularyNamespace, Vocabulary>): {
|
|
43
|
+
fileContent: FileContent;
|
|
44
|
+
position: Position;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=serializer-edmx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer-edmx.d.ts","sourceRoot":"","sources":["../../src/printer/serializer-edmx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,OAAO,EACP,SAAS,EACT,MAAM,EACN,wBAAwB,EACxB,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACd,MAAM,+BAA+B,CAAC;AAcvC,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,IAAI,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAO/F;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,wBAAwB,EAAE,mBAAmB,SAAK,GAAG,MAAM,CA6BnG;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,0BAA0B,SAAK,GAAG,MAAM,CAG1F;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,oBAAoB,SAAI,GAAG,MAAM,CAmBhF;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAChC,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,GAAG,CAAC,mBAAmB,EAAE,UAAU,CAAC,GACnD;IAAE,WAAW,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,CA6ElD"}
|