@darabonba/python-generator 2.0.0 → 2.0.2
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/lib/generator.js +43 -29
- package/package.json +1 -1
- package/tests/expected/complex/tea_python_tests/client.py +5 -4
- package/tests/expected/complex/tea_python_tests/models.py +16 -16
- package/tests/expected/model/tea_python_tests/models.py +41 -58
- package/tests/expected/multi/tea_python_tests/model/user.py +3 -0
- package/tests/fixtures/complex/main.dara +1 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +7 -1
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/util.tea +2 -0
- package/tests/fixtures/multi/model/user.dara +2 -0
- package/tests/output/complex/tea_python_tests/client.py +5 -4
- package/tests/output/complex/tea_python_tests/models.py +16 -16
- package/tests/output/model/tea_python_tests/models.py +41 -58
- package/tests/output/multi/tea_python_tests/model/user.py +3 -0
- package/src/generator.js +0 -231
- package/src/langs/common/combinator.js +0 -193
- package/src/langs/common/config.js +0 -60
- package/src/langs/common/enum.js +0 -179
- package/src/langs/common/items.js +0 -551
- package/src/langs/common/package_info.js +0 -53
- package/src/langs/python/combinator.js +0 -1898
- package/src/langs/python/config.js +0 -169
- package/src/langs/python/files/.gitignore.tmpl +0 -5
- package/src/langs/python/files/__init__.py.tmpl +0 -1
- package/src/langs/python/files/setup.py.tmpl +0 -74
- package/src/langs/python/package_info.js +0 -78
- package/src/langs/python2/combinator.js +0 -1770
- package/src/langs/python2/config.js +0 -162
- package/src/langs/python2/files/.gitignore.tmpl +0 -5
- package/src/langs/python2/files/__init__.py.tmpl +0 -1
- package/src/langs/python2/files/setup.py.tmpl +0 -82
- package/src/langs/python2/package_info.js +0 -78
- package/src/lib/debug.js +0 -55
- package/src/lib/emitter.js +0 -95
- package/src/lib/helper.js +0 -207
- package/src/resolver/base.js +0 -282
- package/src/resolver/client.js +0 -1013
- package/src/resolver/model.js +0 -159
package/src/resolver/model.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line no-unused-vars
|
|
4
|
-
const debug = require('../lib/debug');
|
|
5
|
-
const assert = require('assert');
|
|
6
|
-
const BaseResolver = require('./base');
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
_string,
|
|
10
|
-
_escape,
|
|
11
|
-
_isBasicType,
|
|
12
|
-
} = require('../lib/helper');
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
ObjectItem,
|
|
16
|
-
AnnotationItem,
|
|
17
|
-
PropItem,
|
|
18
|
-
NoteItem,
|
|
19
|
-
} = require('../langs/common/items');
|
|
20
|
-
|
|
21
|
-
const {
|
|
22
|
-
Modify,
|
|
23
|
-
} = require('../langs/common/enum');
|
|
24
|
-
|
|
25
|
-
class ModelResolver extends BaseResolver {
|
|
26
|
-
constructor(astNode, combinator, globalAst) {
|
|
27
|
-
super(astNode, combinator, globalAst);
|
|
28
|
-
this.object = new ObjectItem('model');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
resolve() {
|
|
32
|
-
const object = this.object;
|
|
33
|
-
const combinator = this.combinator;
|
|
34
|
-
const config = this.config;
|
|
35
|
-
const ast = this.ast;
|
|
36
|
-
|
|
37
|
-
assert.equal(ast.type, 'model');
|
|
38
|
-
|
|
39
|
-
combinator.config.emitType = 'model';
|
|
40
|
-
|
|
41
|
-
object.name = ast.modelName.lexeme;
|
|
42
|
-
if (config.modelDirName) {
|
|
43
|
-
config.model.dir = config.modelDirName;
|
|
44
|
-
}
|
|
45
|
-
config.layer = config.model.dir;
|
|
46
|
-
|
|
47
|
-
if (ast.annotation) {
|
|
48
|
-
this.initAnnotation(ast.annotation);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
object.topAnnotation.push(new AnnotationItem(
|
|
52
|
-
object.index,
|
|
53
|
-
'single',
|
|
54
|
-
config.generateFileInfo
|
|
55
|
-
));
|
|
56
|
-
|
|
57
|
-
object.addExtends(combinator.addInclude('$Model'));
|
|
58
|
-
|
|
59
|
-
this.initProp(ast.modelBody.nodes);
|
|
60
|
-
if (ast.modelBody.nodes.length === 0) {
|
|
61
|
-
if (ast.tokenRange) {
|
|
62
|
-
this.resolveAnnotations(
|
|
63
|
-
this.getBetweenComments(ast.tokenRange[0], ast.tokenRange[1]),
|
|
64
|
-
object.index
|
|
65
|
-
).forEach(c => {
|
|
66
|
-
object.addBodyNode(c);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
object.includeList = this.combinator.includeList;
|
|
72
|
-
return object;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
initProp(nodes) {
|
|
76
|
-
const object = this.object;
|
|
77
|
-
|
|
78
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
79
|
-
const node = nodes[i];
|
|
80
|
-
if (typeof node.fieldValue.fieldType === 'undefined') {
|
|
81
|
-
let subModelUsed = [];
|
|
82
|
-
this.findSubModelsUsed(node, subModelUsed, object.name);
|
|
83
|
-
subModelUsed.forEach(subModel => {
|
|
84
|
-
this.combinator.addModelInclude(subModel);
|
|
85
|
-
});
|
|
86
|
-
} else if (node.fieldValue.fieldType === 'array') {
|
|
87
|
-
let name = '';
|
|
88
|
-
if (node.fieldValue.fieldItemType.lexeme) {
|
|
89
|
-
name = node.fieldValue.fieldItemType.lexeme;
|
|
90
|
-
} else if (node.fieldValue.itemType) {
|
|
91
|
-
name = node.fieldValue.fieldItemType.lexeme;
|
|
92
|
-
}
|
|
93
|
-
if (name && !_isBasicType(name)) {
|
|
94
|
-
this.combinator.addModelInclude(name);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const prop = new PropItem();
|
|
99
|
-
prop.belong = object.index;
|
|
100
|
-
prop.name = _escape(node.fieldName.lexeme) || _string(node.fieldName);
|
|
101
|
-
prop.type = this.resolveType(node.fieldValue, node);
|
|
102
|
-
|
|
103
|
-
prop.modify.push(Modify.public());
|
|
104
|
-
if (node.required) {
|
|
105
|
-
prop.addNote(new NoteItem('required', true));
|
|
106
|
-
}
|
|
107
|
-
if (node.tokenRange) {
|
|
108
|
-
let annotations = this.resolveAnnotations(
|
|
109
|
-
this.getFrontComments(node.tokenRange[0]),
|
|
110
|
-
object.index
|
|
111
|
-
);
|
|
112
|
-
annotations.forEach(c => {
|
|
113
|
-
object.addBodyNode(c);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
for (let i = 0; i < node.attrs.length; i++) {
|
|
117
|
-
const attr = node.attrs[i];
|
|
118
|
-
let value;
|
|
119
|
-
if (typeof attr.attrValue.string !== 'undefined') {
|
|
120
|
-
value = attr.attrValue.string;
|
|
121
|
-
} else if (typeof attr.attrValue.value !== 'undefined') {
|
|
122
|
-
value = attr.attrValue.value;
|
|
123
|
-
} else if (typeof attr.attrValue.lexeme !== 'undefined') {
|
|
124
|
-
value = attr.attrValue.lexeme;
|
|
125
|
-
}
|
|
126
|
-
let note = new NoteItem(
|
|
127
|
-
attr.attrName.lexeme,
|
|
128
|
-
value
|
|
129
|
-
);
|
|
130
|
-
prop.addNote(note);
|
|
131
|
-
}
|
|
132
|
-
object.addBodyNode(prop);
|
|
133
|
-
}
|
|
134
|
-
if (nodes[nodes.length - 1] && nodes[nodes.length - 1].tokenRange) {
|
|
135
|
-
let annotations = this.resolveAnnotations(
|
|
136
|
-
this.getBackComments(nodes[nodes.length - 1].tokenRange[1]),
|
|
137
|
-
object.index
|
|
138
|
-
);
|
|
139
|
-
annotations.forEach(c => {
|
|
140
|
-
object.addBodyNode(c);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
findSubModelsUsed(node, subModelUsed = [], pre = '') {
|
|
146
|
-
let name = _escape(node.fieldName.lexeme) || _string(node.fieldName);
|
|
147
|
-
if (pre !== '') {
|
|
148
|
-
name = pre + '.' + name;
|
|
149
|
-
}
|
|
150
|
-
subModelUsed.push(name);
|
|
151
|
-
node.fieldValue.nodes.forEach(item => {
|
|
152
|
-
if (typeof item.fieldValue.fieldType === 'undefined') {
|
|
153
|
-
this.findSubModelsUsed(item, subModelUsed, name);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
module.exports = ModelResolver;
|