@odata2ts/odata2ts 0.33.0 → 0.33.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/CHANGELOG.md +15 -0
- package/lib/FactoryFunctionModel.d.ts +3 -3
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/OptionModel.d.ts +9 -0
- package/lib/OptionModel.js.map +1 -1
- package/lib/app.js +18 -8
- package/lib/app.js.map +1 -1
- package/lib/data-model/DataModel.d.ts +12 -6
- package/lib/data-model/DataModel.js +10 -0
- package/lib/data-model/DataModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.js +37 -20
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataModelDigestionV4.js +0 -9
- package/lib/data-model/DataModelDigestionV4.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +17 -7
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/NamingHelper.d.ts +1 -0
- package/lib/data-model/NamingHelper.js +4 -1
- package/lib/data-model/NamingHelper.js.map +1 -1
- package/lib/data-model/ServiceConfigHelper.js +2 -2
- package/lib/data-model/ServiceConfigHelper.js.map +1 -1
- package/lib/data-model/validation/NameClashValidator.d.ts +23 -0
- package/lib/data-model/validation/NameClashValidator.js +89 -0
- package/lib/data-model/validation/NameClashValidator.js.map +1 -0
- package/lib/data-model/validation/NameValidator.d.ts +6 -17
- package/lib/data-model/validation/NameValidator.js +0 -77
- package/lib/data-model/validation/NameValidator.js.map +1 -1
- package/lib/data-model/validation/NoopValidator.d.ts +12 -0
- package/lib/data-model/validation/NoopValidator.js +34 -0
- package/lib/data-model/validation/NoopValidator.js.map +1 -0
- package/lib/defaultConfig.js +1 -0
- package/lib/defaultConfig.js.map +1 -1
- package/lib/generator/ImportContainer.d.ts +44 -11
- package/lib/generator/ImportContainer.js +150 -47
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/ImportedNameValidator.d.ts +5 -0
- package/lib/generator/ImportedNameValidator.js +26 -0
- package/lib/generator/ImportedNameValidator.js.map +1 -0
- package/lib/generator/ModelGenerator.js +113 -72
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.js +134 -107
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.d.ts +1 -1
- package/lib/generator/ServiceGenerator.js +160 -161
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/generator/import/ImportObjects.d.ts +66 -0
- package/lib/generator/import/ImportObjects.js +83 -0
- package/lib/generator/import/ImportObjects.js.map +1 -0
- package/lib/project/FileHandler.d.ts +28 -0
- package/lib/project/FileHandler.js +66 -0
- package/lib/project/FileHandler.js.map +1 -0
- package/lib/project/ProjectManager.d.ts +44 -18
- package/lib/project/ProjectManager.js +155 -111
- package/lib/project/ProjectManager.js.map +1 -1
- package/lib/project/TsMorphHelper.d.ts +11 -0
- package/lib/project/TsMorphHelper.js +66 -0
- package/lib/project/TsMorphHelper.js.map +1 -0
- package/package.json +10 -8
|
@@ -1,79 +1,105 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateQueryObjects = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const odata_core_1 = require("@odata2ts/odata-core");
|
|
5
6
|
const ts_morph_1 = require("ts-morph");
|
|
6
7
|
const processors_1 = require("xml2js/lib/processors");
|
|
7
|
-
const
|
|
8
|
-
const generateQueryObjects = (
|
|
9
|
-
const generator = new QueryObjectGenerator(
|
|
8
|
+
const ImportObjects_1 = require("./import/ImportObjects");
|
|
9
|
+
const generateQueryObjects = (project, dataModel, version, options, namingHelper) => {
|
|
10
|
+
const generator = new QueryObjectGenerator(project, dataModel, version, options, namingHelper);
|
|
10
11
|
return generator.generate();
|
|
11
12
|
};
|
|
12
13
|
exports.generateQueryObjects = generateQueryObjects;
|
|
13
14
|
class QueryObjectGenerator {
|
|
14
|
-
constructor(
|
|
15
|
+
constructor(project, dataModel, version, options, namingHelper) {
|
|
16
|
+
this.project = project;
|
|
15
17
|
this.dataModel = dataModel;
|
|
16
|
-
this.sourceFile = sourceFile;
|
|
17
18
|
this.version = version;
|
|
18
19
|
this.options = options;
|
|
19
20
|
this.namingHelper = namingHelper;
|
|
20
21
|
}
|
|
21
22
|
generate() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
this.project.initQObjects();
|
|
25
|
+
// process EntityType & ComplexType
|
|
26
|
+
const promises = [...this.generateEntityTypes(), ...this.generateComplexTypes()];
|
|
27
|
+
if (!this.options.skipOperations) {
|
|
28
|
+
// process unbound operations
|
|
29
|
+
promises.push(this.generateUnboundOperations());
|
|
30
|
+
}
|
|
31
|
+
yield Promise.all(promises);
|
|
32
|
+
return this.project.finalizeQObjects();
|
|
33
|
+
});
|
|
28
34
|
}
|
|
29
|
-
|
|
30
|
-
this.dataModel.getEntityTypes().
|
|
31
|
-
this.
|
|
35
|
+
generateEntityTypes() {
|
|
36
|
+
return this.dataModel.getEntityTypes().map((model) => {
|
|
37
|
+
const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [
|
|
38
|
+
model.qName,
|
|
39
|
+
(0, processors_1.firstCharLowerCase)(model.qName),
|
|
40
|
+
model.id.qName,
|
|
41
|
+
]);
|
|
42
|
+
// q object
|
|
43
|
+
this.generateModel(file, model);
|
|
44
|
+
// qId function
|
|
32
45
|
if (!this.options.skipIdModels && model.generateId) {
|
|
33
|
-
this.generateIdFunction(
|
|
46
|
+
this.generateIdFunction(file, model);
|
|
34
47
|
}
|
|
48
|
+
// bound q operations
|
|
35
49
|
if (!this.options.skipOperations) {
|
|
36
|
-
|
|
50
|
+
[
|
|
51
|
+
...this.dataModel.getEntityTypeOperations(model.fqName),
|
|
52
|
+
...this.dataModel.getEntitySetOperations(model.fqName),
|
|
53
|
+
].forEach((operation) => {
|
|
54
|
+
this.generateOperation(file, operation, model.fqName);
|
|
55
|
+
});
|
|
37
56
|
}
|
|
57
|
+
return this.project.finalizeFile(file);
|
|
38
58
|
});
|
|
39
|
-
|
|
40
|
-
|
|
59
|
+
}
|
|
60
|
+
generateComplexTypes() {
|
|
61
|
+
return this.dataModel.getComplexTypes().map((model) => {
|
|
62
|
+
const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [
|
|
63
|
+
model.qName,
|
|
64
|
+
(0, processors_1.firstCharLowerCase)(model.qName),
|
|
65
|
+
]);
|
|
66
|
+
this.generateModel(file, model);
|
|
67
|
+
return this.project.finalizeFile(file);
|
|
41
68
|
});
|
|
42
|
-
if (this.dataModel.getEntityTypes().length || this.dataModel.getComplexTypes().length) {
|
|
43
|
-
importContainer.addFromQObject("QueryObject");
|
|
44
|
-
}
|
|
45
69
|
}
|
|
46
|
-
generateModel(
|
|
47
|
-
|
|
70
|
+
generateModel(file, model) {
|
|
71
|
+
const imports = file.getImports();
|
|
72
|
+
let extendsClause;
|
|
48
73
|
if (model.baseClasses.length) {
|
|
49
74
|
const baseClass = model.baseClasses[0];
|
|
50
|
-
const baseModel = this.dataModel.
|
|
75
|
+
const baseModel = this.dataModel.getModel(baseClass);
|
|
51
76
|
if (!baseModel) {
|
|
52
77
|
throw new Error(`Entity or complex type "${baseClass}" from baseClass attribute not found!`);
|
|
53
78
|
}
|
|
54
|
-
extendsClause = baseModel.qName;
|
|
79
|
+
extendsClause = imports.addGeneratedQObject(baseClass, baseModel.qName);
|
|
55
80
|
}
|
|
56
|
-
|
|
81
|
+
else {
|
|
82
|
+
[extendsClause] = imports.addQObject(ImportObjects_1.QueryObjectImports.QueryObject);
|
|
83
|
+
}
|
|
84
|
+
file.getFile().addClass({
|
|
57
85
|
name: model.qName,
|
|
58
86
|
isExported: true,
|
|
59
87
|
extends: extendsClause,
|
|
60
|
-
isAbstract: model.abstract,
|
|
61
|
-
properties: this.generateQueryObjectProps(model.props
|
|
88
|
+
// isAbstract: model.abstract,
|
|
89
|
+
properties: this.generateQueryObjectProps(file.getImports(), model.props),
|
|
90
|
+
});
|
|
91
|
+
file.getFile().addVariableStatement({
|
|
92
|
+
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
93
|
+
isExported: true,
|
|
94
|
+
declarations: [
|
|
95
|
+
{
|
|
96
|
+
name: (0, processors_1.firstCharLowerCase)(model.qName),
|
|
97
|
+
initializer: `new ${model.qName}()`,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
62
100
|
});
|
|
63
|
-
if (!model.abstract) {
|
|
64
|
-
this.sourceFile.addVariableStatement({
|
|
65
|
-
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
66
|
-
isExported: true,
|
|
67
|
-
declarations: [
|
|
68
|
-
{
|
|
69
|
-
name: (0, processors_1.firstCharLowerCase)(model.qName),
|
|
70
|
-
initializer: `new ${model.qName}()`,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
101
|
}
|
|
76
|
-
generateQueryObjectProps(
|
|
102
|
+
generateQueryObjectProps(importContainer, props) {
|
|
77
103
|
return props.map((prop) => {
|
|
78
104
|
const { odataName } = prop;
|
|
79
105
|
const name = this.namingHelper.getQPropName(prop.name);
|
|
@@ -81,27 +107,24 @@ class QueryObjectGenerator {
|
|
|
81
107
|
let qPathInit;
|
|
82
108
|
// factor in collections
|
|
83
109
|
if (prop.isCollection) {
|
|
84
|
-
const cType =
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
qPathInit = `new ${
|
|
90
|
-
importContainer.addFromQObject(cType);
|
|
91
|
-
if (!isModelType) {
|
|
92
|
-
importContainer.addFromQObject(qObject);
|
|
93
|
-
}
|
|
110
|
+
const cType = isModelType ? ImportObjects_1.QueryObjectImports.QEntityCollectionPath : ImportObjects_1.QueryObjectImports.QCollectionPath;
|
|
111
|
+
const collectionType = importContainer.addQObject(cType);
|
|
112
|
+
const qObject = isModelType
|
|
113
|
+
? importContainer.addGeneratedQObject(prop.fqType, prop.qObject)
|
|
114
|
+
: importContainer.addFromQObject(prop.qObject)[0];
|
|
115
|
+
qPathInit = `new ${collectionType}(this.withPrefix("${odataName}"), () => ${qObject})`;
|
|
94
116
|
}
|
|
95
117
|
else {
|
|
118
|
+
// add import for data type
|
|
119
|
+
const qPath = importContainer.addFromQObject(prop.qPath);
|
|
96
120
|
if (isModelType) {
|
|
97
|
-
|
|
121
|
+
const qObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject);
|
|
122
|
+
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), () => ${qObject})`;
|
|
98
123
|
}
|
|
99
124
|
else {
|
|
100
|
-
let converterStmt = this.generateConverterStmt(prop.converters
|
|
101
|
-
qPathInit = `new ${
|
|
125
|
+
let converterStmt = this.generateConverterStmt(importContainer, prop.converters);
|
|
126
|
+
qPathInit = `new ${qPath}(this.withPrefix("${odataName}")${converterStmt ? `, ${converterStmt}` : ""})`;
|
|
102
127
|
}
|
|
103
|
-
// add import for data type
|
|
104
|
-
importContainer.addFromQObject(prop.qPath);
|
|
105
128
|
}
|
|
106
129
|
return {
|
|
107
130
|
name,
|
|
@@ -111,36 +134,36 @@ class QueryObjectGenerator {
|
|
|
111
134
|
};
|
|
112
135
|
});
|
|
113
136
|
}
|
|
114
|
-
generateConverterStmt(
|
|
137
|
+
generateConverterStmt(importContainer, converters) {
|
|
115
138
|
if (!(converters === null || converters === void 0 ? void 0 : converters.length)) {
|
|
116
|
-
return;
|
|
139
|
+
return undefined;
|
|
117
140
|
}
|
|
118
|
-
converters.
|
|
119
|
-
importContainer.addCustomType(converter.package, converter.converterId);
|
|
141
|
+
const converterIds = converters.map((converter) => {
|
|
142
|
+
return importContainer.addCustomType(converter.package, converter.converterId);
|
|
120
143
|
});
|
|
121
|
-
if (
|
|
122
|
-
return
|
|
144
|
+
if (converterIds.length === 1) {
|
|
145
|
+
return converterIds[0];
|
|
123
146
|
}
|
|
124
147
|
else {
|
|
125
|
-
importContainer.addCustomType("@odata2ts/converter-runtime", "createChain");
|
|
126
|
-
const [first, second, ...moreConverters] =
|
|
127
|
-
return moreConverters.reduce((stmt,
|
|
148
|
+
const createChain = importContainer.addCustomType("@odata2ts/converter-runtime", "createChain");
|
|
149
|
+
const [first, second, ...moreConverters] = converterIds;
|
|
150
|
+
return moreConverters.reduce((stmt, convId) => `${stmt}.chain(${convId})`, `${createChain}(${first}, ${second})`);
|
|
128
151
|
}
|
|
129
152
|
}
|
|
130
|
-
generateIdFunction(
|
|
131
|
-
const
|
|
132
|
-
importContainer.
|
|
133
|
-
importContainer.addGeneratedModel(model.
|
|
134
|
-
|
|
135
|
-
name: model.
|
|
153
|
+
generateIdFunction(file, model) {
|
|
154
|
+
const importContainer = file.getImports();
|
|
155
|
+
const qFunc = importContainer.addQObject(ImportObjects_1.QueryObjectImports.QId);
|
|
156
|
+
const idModelName = importContainer.addGeneratedModel(model.fqName, model.id.modelName);
|
|
157
|
+
file.getFile().addClass({
|
|
158
|
+
name: model.id.qName,
|
|
136
159
|
isExported: true,
|
|
137
|
-
extends: `${qFunc}<${
|
|
160
|
+
extends: `${qFunc}<${idModelName}>`,
|
|
138
161
|
properties: [
|
|
139
162
|
{
|
|
140
163
|
name: "params",
|
|
141
164
|
scope: ts_morph_1.Scope.Private,
|
|
142
165
|
isReadonly: true,
|
|
143
|
-
initializer: this.getParamInitString(model.keys
|
|
166
|
+
initializer: this.getParamInitString(importContainer, model.keys),
|
|
144
167
|
},
|
|
145
168
|
],
|
|
146
169
|
methods: [
|
|
@@ -151,76 +174,80 @@ class QueryObjectGenerator {
|
|
|
151
174
|
],
|
|
152
175
|
});
|
|
153
176
|
}
|
|
154
|
-
getParamInitString(
|
|
177
|
+
getParamInitString(importContainer, props) {
|
|
155
178
|
return `[${props
|
|
156
179
|
.map((prop) => {
|
|
157
180
|
var _a;
|
|
158
|
-
|
|
159
|
-
if (prop.
|
|
160
|
-
importContainer.
|
|
181
|
+
let complexQParam = "";
|
|
182
|
+
if (prop.dataType === "ModelType" /* DataTypes.ModelType */ || prop.dataType === "ComplexType" /* DataTypes.ComplexType */) {
|
|
183
|
+
const importedQObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject);
|
|
184
|
+
complexQParam = `, new ${importedQObject}()`;
|
|
161
185
|
}
|
|
186
|
+
const qParam = importContainer.addFromQObject(prop.qParam);
|
|
162
187
|
const isMappedNameNecessary = prop.odataName !== prop.name;
|
|
163
188
|
const mappedName = isMappedNameNecessary ? `"${prop.name}"` : ((_a = prop.converters) === null || _a === void 0 ? void 0 : _a.length) ? "undefined" : undefined;
|
|
164
|
-
const converterStmt = this.generateConverterStmt(prop.converters
|
|
189
|
+
const converterStmt = this.generateConverterStmt(importContainer, prop.converters);
|
|
165
190
|
const mappedNameParam = mappedName ? `, ${mappedName}` : "";
|
|
166
|
-
const complexQParam = isComplexParam ? `, new ${prop.qObject}()` : "";
|
|
167
191
|
const converterParam = converterStmt ? `, ${converterStmt}` : "";
|
|
168
|
-
return `new ${
|
|
192
|
+
return `new ${qParam}("${prop.odataName}"${complexQParam}${mappedNameParam}${converterParam})`;
|
|
169
193
|
})
|
|
170
194
|
.join(",")}]`;
|
|
171
195
|
}
|
|
172
|
-
generateUnboundOperations(
|
|
173
|
-
|
|
174
|
-
this.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
...this.dataModel.getEntitySetOperations(fqEntityName),
|
|
181
|
-
].forEach((operation) => {
|
|
182
|
-
this.generateOperation(operation, importContainer);
|
|
196
|
+
generateUnboundOperations() {
|
|
197
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
const unboundOps = this.dataModel.getUnboundOperationTypes();
|
|
199
|
+
const reservedNames = unboundOps.map((op) => op.qName);
|
|
200
|
+
const file = this.project.createOrGetMainQObjectFile(reservedNames);
|
|
201
|
+
unboundOps.forEach((operation) => {
|
|
202
|
+
this.generateOperation(file, operation, "");
|
|
203
|
+
});
|
|
183
204
|
});
|
|
184
205
|
}
|
|
185
|
-
generateOperation(operation,
|
|
206
|
+
generateOperation(file, operation, baseFqName) {
|
|
186
207
|
var _a;
|
|
208
|
+
const imports = file.getImports();
|
|
187
209
|
const isV2 = this.version === odata_core_1.ODataVersions.V2;
|
|
188
|
-
const qOperation = operation.type === "Action" /* OperationTypes.Action */ ? "QAction" : "QFunction";
|
|
189
210
|
const returnType = operation.returnType;
|
|
190
|
-
let returnTypeOpStmt = "";
|
|
191
211
|
const hasParams = operation.parameters.length > 0;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
212
|
+
// imports
|
|
213
|
+
const qOp = operation.type === "Action" /* OperationTypes.Action */ ? ImportObjects_1.QueryObjectImports.QAction : ImportObjects_1.QueryObjectImports.QFunction;
|
|
214
|
+
const qOperation = imports.addQObject(qOp);
|
|
215
|
+
const paramModelName = operation.parameters.length
|
|
216
|
+
? imports.addGeneratedModel(baseFqName, operation.paramsModelName)
|
|
217
|
+
: undefined;
|
|
218
|
+
let returnTypeOpStmt = "";
|
|
196
219
|
if (returnType) {
|
|
220
|
+
const collectionSuffix = returnType.isCollection ? "_COLLECTION" : "";
|
|
197
221
|
if (returnType.dataType === "ComplexType" /* DataTypes.ComplexType */ || returnType.dataType === "ModelType" /* DataTypes.ModelType */) {
|
|
198
222
|
if (returnType.qObject) {
|
|
199
|
-
|
|
200
|
-
|
|
223
|
+
const [opRt, rts, qComplexParam] = imports.addQObject(ImportObjects_1.QueryObjectImports.OperationReturnType, ImportObjects_1.QueryObjectImports.ReturnTypes, ImportObjects_1.QueryObjectImports.QComplexParam);
|
|
224
|
+
const returnQName = imports.addGeneratedQObject(returnType.fqType, returnType.qObject);
|
|
225
|
+
returnTypeOpStmt = `new ${opRt}(${rts}.COMPLEX${collectionSuffix}, new ${qComplexParam}("NONE", new ${returnQName}))`;
|
|
201
226
|
}
|
|
202
227
|
}
|
|
203
228
|
// currently, it only makes sense to add the OperationReturnType if a converter is present
|
|
204
229
|
else if (returnType.converters && returnType.qParam) {
|
|
205
|
-
|
|
206
|
-
const
|
|
230
|
+
const [rtClass, rtTypes] = imports.addQObject(ImportObjects_1.QueryObjectImports.OperationReturnType, ImportObjects_1.QueryObjectImports.ReturnTypes);
|
|
231
|
+
const [qParam] = imports.addFromQObject(returnType.qParam);
|
|
232
|
+
// TODO: some constants with string concat
|
|
233
|
+
const rtKind = `${rtTypes}.VALUE${collectionSuffix}`;
|
|
207
234
|
const converterParam = returnType.converters
|
|
208
|
-
? ", " + this.generateConverterStmt(returnType.converters
|
|
235
|
+
? ", " + this.generateConverterStmt(imports, returnType.converters)
|
|
209
236
|
: "";
|
|
210
|
-
returnTypeOpStmt = `new
|
|
237
|
+
returnTypeOpStmt = `new ${rtClass}(${rtKind}, new ${qParam}("NONE", undefined${converterParam}))`;
|
|
211
238
|
}
|
|
212
239
|
}
|
|
213
|
-
|
|
240
|
+
file.getFile().addClass({
|
|
214
241
|
name: operation.qName,
|
|
215
242
|
isExported: true,
|
|
216
|
-
extends: qOperation + (hasParams ? `<${
|
|
243
|
+
extends: qOperation + (hasParams ? `<${paramModelName}>` : ""),
|
|
217
244
|
properties: [
|
|
218
245
|
{
|
|
219
246
|
name: "params",
|
|
220
247
|
scope: ts_morph_1.Scope.Private,
|
|
221
248
|
isReadonly: true,
|
|
222
249
|
type: ((_a = operation.parameters) === null || _a === void 0 ? void 0 : _a.length) ? undefined : "[]",
|
|
223
|
-
initializer: this.getParamInitString(operation.parameters
|
|
250
|
+
initializer: this.getParamInitString(imports, operation.parameters),
|
|
224
251
|
},
|
|
225
252
|
],
|
|
226
253
|
ctors: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryObjectGenerator.js","sourceRoot":"","sources":["../../src/generator/QueryObjectGenerator.ts"],"names":[],"mappings":";;;AACA,qDAAqD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gBACD,+GAA+G;gBAC/G,GAAG,CAAC,SAAS,CAAC,IAAI,6CAA4B,IAAI,CAAC,SAAS;oBAC1D,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE,UAAU;4BAChB,UAAU,EAAE,CAAC,kCAAkC,CAAC;yBACjD;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\nimport { ODataVersions } from \"@odata2ts/odata-core\";\nimport { OptionalKind, PropertyDeclarationStructure, Scope, SourceFile, VariableDeclarationKind } from \"ts-morph\";\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport {\n ComplexType,\n DataTypes,\n ModelType,\n OperationType,\n OperationTypes,\n PropertyModel,\n} from \"../data-model/DataTypeModel\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\nimport { ImportContainer } from \"./ImportContainer\";\n\nexport const generateQueryObjects: EntityBasedGeneratorFunction = (\n dataModel,\n sourceFile,\n version,\n options,\n namingHelper\n) => {\n const generator = new QueryObjectGenerator(dataModel, sourceFile, version, options, namingHelper);\n return generator.generate();\n};\n\nclass QueryObjectGenerator {\n constructor(\n private dataModel: DataModel,\n private sourceFile: SourceFile,\n private version: ODataVersions,\n private options: GeneratorFunctionOptions,\n private namingHelper: NamingHelper\n ) {}\n\n public generate(): void {\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n this.generateModels(importContainer);\n if (!this.options.skipOperations) {\n this.generateUnboundOperations(importContainer);\n }\n\n this.sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\n }\n\n private generateModels(importContainer: ImportContainer) {\n this.dataModel.getEntityTypes().forEach((model) => {\n this.generateModel(model, importContainer);\n if (!this.options.skipIdModels && model.generateId) {\n this.generateIdFunction(model, importContainer);\n }\n if (!this.options.skipOperations) {\n this.generateBoundOperations(model.fqName, importContainer);\n }\n });\n this.dataModel.getComplexTypes().forEach((model) => {\n this.generateModel(model, importContainer);\n });\n\n if (this.dataModel.getEntityTypes().length || this.dataModel.getComplexTypes().length) {\n importContainer.addFromQObject(\"QueryObject\");\n }\n }\n\n private generateModel(model: ComplexType, importContainer: ImportContainer) {\n let extendsClause = \"QueryObject\";\n if (model.baseClasses.length) {\n const baseClass = model.baseClasses[0];\n const baseModel = this.dataModel.getEntityType(baseClass) || this.dataModel.getComplexType(baseClass);\n if (!baseModel) {\n throw new Error(`Entity or complex type \"${baseClass}\" from baseClass attribute not found!`);\n }\n\n extendsClause = baseModel.qName;\n }\n\n this.sourceFile.addClass({\n name: model.qName,\n isExported: true,\n extends: extendsClause,\n isAbstract: model.abstract,\n properties: this.generateQueryObjectProps(model.props, importContainer),\n });\n\n if (!model.abstract) {\n this.sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: firstCharLowerCase(model.qName),\n initializer: `new ${model.qName}()`,\n },\n ],\n });\n }\n }\n\n private generateQueryObjectProps(\n props: Array<PropertyModel>,\n importContainer: ImportContainer\n ): Array<OptionalKind<PropertyDeclarationStructure>> {\n return props.map((prop) => {\n const { odataName } = prop;\n const name = this.namingHelper.getQPropName(prop.name);\n const isModelType = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\n let qPathInit: string;\n\n // factor in collections\n if (prop.isCollection) {\n const cType = `Q${isModelType ? \"Entity\" : \"\"}CollectionPath`;\n const qObject = prop.qObject;\n\n if (!qObject) {\n throw new Error(\"QObject for collection is missing!\");\n }\n\n qPathInit = `new ${cType}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\n\n importContainer.addFromQObject(cType);\n if (!isModelType) {\n importContainer.addFromQObject(qObject);\n }\n } else {\n if (isModelType) {\n qPathInit = `new ${prop.qPath}(this.withPrefix(\"${odataName}\"), () => ${prop.qObject!})`;\n } else {\n let converterStmt = this.generateConverterStmt(prop.converters, importContainer);\n qPathInit = `new ${prop.qPath}(this.withPrefix(\"${odataName}\")${converterStmt ? `, ${converterStmt}` : \"\"})`;\n }\n // add import for data type\n importContainer.addFromQObject(prop.qPath);\n }\n\n return {\n name,\n scope: Scope.Public,\n isReadonly: true,\n initializer: qPathInit,\n } as OptionalKind<PropertyDeclarationStructure>;\n });\n }\n\n private generateConverterStmt(converters: Array<ValueConverterImport> | undefined, importContainer: ImportContainer) {\n if (!converters?.length) {\n return;\n }\n converters.forEach((converter) => {\n importContainer.addCustomType(converter.package, converter.converterId);\n });\n\n if (converters.length === 1) {\n return converters[0].converterId;\n } else {\n importContainer.addCustomType(\"@odata2ts/converter-runtime\", \"createChain\");\n\n const [first, second, ...moreConverters] = converters;\n return moreConverters.reduce(\n (stmt, conv) => `${stmt}.chain(${conv.converterId})`,\n `createChain(${first.converterId}, ${second.converterId})`\n );\n }\n }\n\n private generateIdFunction(model: ModelType, importContainer: ImportContainer) {\n const qFunc = \"QId\";\n importContainer.addFromQObject(qFunc);\n importContainer.addGeneratedModel(model.idModelName);\n\n this.sourceFile.addClass({\n name: model.qIdFunctionName,\n isExported: true,\n extends: `${qFunc}<${model.idModelName}>`,\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n initializer: this.getParamInitString(model.keys, importContainer),\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n ],\n });\n }\n\n private getParamInitString(props: Array<PropertyModel>, importContainer: ImportContainer) {\n return `[${props\n .map((prop) => {\n const isComplexParam = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\n if (prop.qParam) {\n importContainer.addFromQObject(prop.qParam);\n }\n const isMappedNameNecessary = prop.odataName !== prop.name;\n const mappedName = isMappedNameNecessary ? `\"${prop.name}\"` : prop.converters?.length ? \"undefined\" : undefined;\n const converterStmt = this.generateConverterStmt(prop.converters, importContainer);\n const mappedNameParam = mappedName ? `, ${mappedName}` : \"\";\n const complexQParam = isComplexParam ? `, new ${prop.qObject}()` : \"\";\n const converterParam = converterStmt ? `, ${converterStmt}` : \"\";\n return `new ${prop.qParam}(\"${prop.odataName}\"${complexQParam}${mappedNameParam}${converterParam})`;\n })\n .join(\",\")}]`;\n }\n\n private generateUnboundOperations(importContainer: ImportContainer) {\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\n this.generateOperation(operation, importContainer);\n });\n }\n\n private generateBoundOperations(fqEntityName: string, importContainer: ImportContainer) {\n [\n ...this.dataModel.getEntityTypeOperations(fqEntityName),\n ...this.dataModel.getEntitySetOperations(fqEntityName),\n ].forEach((operation) => {\n this.generateOperation(operation, importContainer);\n });\n }\n\n private generateOperation(operation: OperationType, importContainer: ImportContainer) {\n const isV2 = this.version === ODataVersions.V2;\n const qOperation = operation.type === OperationTypes.Action ? \"QAction\" : \"QFunction\";\n const returnType = operation.returnType;\n let returnTypeOpStmt: string = \"\";\n const hasParams = operation.parameters.length > 0;\n importContainer.addFromQObject(qOperation);\n if (hasParams) {\n importContainer.addGeneratedModel(operation.paramsModelName);\n }\n if (returnType) {\n if (returnType.dataType === DataTypes.ComplexType || returnType.dataType === DataTypes.ModelType) {\n if (returnType.qObject) {\n importContainer.addFromQObject(\"OperationReturnType\", \"ReturnTypes\", \"QComplexParam\");\n returnTypeOpStmt = `new OperationReturnType(ReturnTypes.COMPLEX${\n returnType.isCollection ? \"_COLLECTION\" : \"\"\n }, new QComplexParam(\"NONE\", new ${returnType.qObject}))`;\n }\n }\n // currently, it only makes sense to add the OperationReturnType if a converter is present\n else if (returnType.converters && returnType.qParam) {\n importContainer.addFromQObject(\"OperationReturnType\", \"ReturnTypes\", returnType.qParam);\n const rtKind = \"ReturnTypes.VALUE\" + (returnType.isCollection ? \"_COLLECTION\" : \"\");\n const converterParam = returnType.converters\n ? \", \" + this.generateConverterStmt(returnType.converters, importContainer)\n : \"\";\n returnTypeOpStmt = `new OperationReturnType(${rtKind}, new ${returnType.qParam}(\"NONE\", undefined${converterParam}))`;\n }\n }\n\n this.sourceFile.addClass({\n name: operation.qName,\n isExported: true,\n extends: qOperation + (hasParams ? `<${operation.paramsModelName}>` : \"\"),\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n type: operation.parameters?.length ? undefined : \"[]\",\n initializer: this.getParamInitString(operation.parameters, importContainer),\n },\n ],\n ctors: [\n {\n statements: [\n `super(\"${operation.odataName}\"${returnTypeOpStmt ? \", \" + returnTypeOpStmt : isV2 ? \", undefined\" : \"\"}${\n isV2 ? \", { v2Mode: true }\" : \"\"\n })`,\n ],\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n // functions without params: add an overriding buildUrl() to not force users to have to pass undefined as param\n ...(operation.type === OperationTypes.Function && !hasParams\n ? [\n {\n name: \"buildUrl\",\n statements: [\"return super.buildUrl(undefined)\"],\n },\n ]\n : []),\n ],\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"QueryObjectGenerator.js","sourceRoot":"","sources":["../../src/generator/QueryObjectGenerator.ts"],"names":[],"mappings":";;;;AACA,qDAAqD;AACrD,uCAAsG;AACtG,sDAA2D;AAe3D,0DAA4D;AAGrD,MAAM,oBAAoB,GAAiC,CAChE,OAAO,EACP,SAAS,EACT,OAAO,EACP,OAAO,EACP,YAAY,EACZ,EAAE;IACF,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC/F,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AATW,QAAA,oBAAoB,wBAS/B;AAEF,MAAM,oBAAoB;IACxB,YACU,OAAuB,EACvB,SAAoB,EACpB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,YAAO,GAAP,OAAO,CAAgB;QACvB,cAAS,GAAT,SAAS,CAAW;QACpB,YAAO,GAAP,OA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wBACE;4BACE,IAAI,EAAE,UAAU;4BAChB,UAAU,EAAE,CAAC,kCAAkC,CAAC;yBACjD;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\nimport { ODataVersions } from \"@odata2ts/odata-core\";\nimport { OptionalKind, PropertyDeclarationStructure, Scope, VariableDeclarationKind } from \"ts-morph\";\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport {\n ComplexType,\n DataTypes,\n EntityType,\n OperationType,\n OperationTypes,\n PropertyModel,\n} from \"../data-model/DataTypeModel\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\nimport { FileHandler } from \"../project/FileHandler\";\nimport { ProjectManager } from \"../project/ProjectManager\";\nimport { QueryObjectImports } from \"./import/ImportObjects\";\nimport { ImportContainer } from \"./ImportContainer\";\n\nexport const generateQueryObjects: EntityBasedGeneratorFunction = (\n project,\n dataModel,\n version,\n options,\n namingHelper\n) => {\n const generator = new QueryObjectGenerator(project, dataModel, version, options, namingHelper);\n return generator.generate();\n};\n\nclass QueryObjectGenerator {\n constructor(\n private project: ProjectManager,\n private dataModel: DataModel,\n private version: ODataVersions,\n private options: GeneratorFunctionOptions,\n private namingHelper: NamingHelper\n ) {}\n\n public async generate(): Promise<void> {\n this.project.initQObjects();\n\n // process EntityType & ComplexType\n const promises: Array<Promise<void>> = [...this.generateEntityTypes(), ...this.generateComplexTypes()];\n if (!this.options.skipOperations) {\n // process unbound operations\n promises.push(this.generateUnboundOperations());\n }\n\n await Promise.all(promises);\n\n return this.project.finalizeQObjects();\n }\n\n private generateEntityTypes() {\n return this.dataModel.getEntityTypes().map((model) => {\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\n model.qName,\n firstCharLowerCase(model.qName),\n model.id.qName,\n ]);\n\n // q object\n this.generateModel(file, model);\n\n // qId function\n if (!this.options.skipIdModels && model.generateId) {\n this.generateIdFunction(file, model);\n }\n\n // bound q operations\n if (!this.options.skipOperations) {\n [\n ...this.dataModel.getEntityTypeOperations(model.fqName),\n ...this.dataModel.getEntitySetOperations(model.fqName),\n ].forEach((operation) => {\n this.generateOperation(file, operation, model.fqName);\n });\n }\n\n return this.project.finalizeFile(file);\n });\n }\n\n private generateComplexTypes() {\n return this.dataModel.getComplexTypes().map((model) => {\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\n model.qName,\n firstCharLowerCase(model.qName),\n ]);\n\n this.generateModel(file, model);\n\n return this.project.finalizeFile(file);\n });\n }\n\n private generateModel(file: FileHandler, model: ComplexType) {\n const imports = file.getImports();\n\n let extendsClause: string;\n if (model.baseClasses.length) {\n const baseClass = model.baseClasses[0];\n const baseModel = this.dataModel.getModel(baseClass) as ComplexType;\n if (!baseModel) {\n throw new Error(`Entity or complex type \"${baseClass}\" from baseClass attribute not found!`);\n }\n extendsClause = imports.addGeneratedQObject(baseClass, baseModel.qName);\n } else {\n [extendsClause] = imports.addQObject(QueryObjectImports.QueryObject);\n }\n\n file.getFile().addClass({\n name: model.qName,\n isExported: true,\n extends: extendsClause,\n // isAbstract: model.abstract,\n properties: this.generateQueryObjectProps(file.getImports(), model.props),\n });\n\n file.getFile().addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: firstCharLowerCase(model.qName),\n initializer: `new ${model.qName}()`,\n },\n ],\n });\n }\n\n private generateQueryObjectProps(\n importContainer: ImportContainer,\n props: Array<PropertyModel>\n ): Array<OptionalKind<PropertyDeclarationStructure>> {\n return props.map((prop) => {\n const { odataName } = prop;\n const name = this.namingHelper.getQPropName(prop.name);\n const isModelType = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\n let qPathInit: string;\n\n // factor in collections\n if (prop.isCollection) {\n const cType = isModelType ? QueryObjectImports.QEntityCollectionPath : QueryObjectImports.QCollectionPath;\n const collectionType = importContainer.addQObject(cType);\n const qObject = isModelType\n ? importContainer.addGeneratedQObject(prop.fqType, prop.qObject!)\n : importContainer.addFromQObject(prop.qObject!)[0];\n\n qPathInit = `new ${collectionType}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\n } else {\n // add import for data type\n const qPath = importContainer.addFromQObject(prop.qPath);\n if (isModelType) {\n const qObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\n } else {\n let converterStmt = this.generateConverterStmt(importContainer, prop.converters);\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\")${converterStmt ? `, ${converterStmt}` : \"\"})`;\n }\n }\n\n return {\n name,\n scope: Scope.Public,\n isReadonly: true,\n initializer: qPathInit,\n } as OptionalKind<PropertyDeclarationStructure>;\n });\n }\n\n private generateConverterStmt(importContainer: ImportContainer, converters: Array<ValueConverterImport> | undefined) {\n if (!converters?.length) {\n return undefined;\n }\n const converterIds = converters.map((converter) => {\n return importContainer.addCustomType(converter.package, converter.converterId);\n });\n\n if (converterIds.length === 1) {\n return converterIds[0];\n } else {\n const createChain = importContainer.addCustomType(\"@odata2ts/converter-runtime\", \"createChain\");\n\n const [first, second, ...moreConverters] = converterIds;\n return moreConverters.reduce((stmt, convId) => `${stmt}.chain(${convId})`, `${createChain}(${first}, ${second})`);\n }\n }\n\n private generateIdFunction(file: FileHandler, model: EntityType) {\n const importContainer = file.getImports();\n const qFunc = importContainer.addQObject(QueryObjectImports.QId);\n const idModelName = importContainer.addGeneratedModel(model.fqName, model.id.modelName);\n\n file.getFile().addClass({\n name: model.id.qName,\n isExported: true,\n extends: `${qFunc}<${idModelName}>`,\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n initializer: this.getParamInitString(importContainer, model.keys),\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n ],\n });\n }\n\n private getParamInitString(importContainer: ImportContainer, props: Array<PropertyModel>) {\n return `[${props\n .map((prop) => {\n let complexQParam = \"\";\n if (prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType) {\n const importedQObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\n complexQParam = `, new ${importedQObject}()`;\n }\n\n const qParam = importContainer.addFromQObject(prop.qParam!);\n const isMappedNameNecessary = prop.odataName !== prop.name;\n const mappedName = isMappedNameNecessary ? `\"${prop.name}\"` : prop.converters?.length ? \"undefined\" : undefined;\n const converterStmt = this.generateConverterStmt(importContainer, prop.converters);\n const mappedNameParam = mappedName ? `, ${mappedName}` : \"\";\n const converterParam = converterStmt ? `, ${converterStmt}` : \"\";\n return `new ${qParam}(\"${prop.odataName}\"${complexQParam}${mappedNameParam}${converterParam})`;\n })\n .join(\",\")}]`;\n }\n\n private async generateUnboundOperations() {\n const unboundOps = this.dataModel.getUnboundOperationTypes();\n const reservedNames = unboundOps.map((op) => op.qName);\n const file = this.project.createOrGetMainQObjectFile(reservedNames);\n\n unboundOps.forEach((operation) => {\n this.generateOperation(file, operation, \"\");\n });\n }\n\n private generateOperation(file: FileHandler, operation: OperationType, baseFqName: string) {\n const imports = file.getImports();\n const isV2 = this.version === ODataVersions.V2;\n const returnType = operation.returnType;\n const hasParams = operation.parameters.length > 0;\n\n // imports\n const qOp = operation.type === OperationTypes.Action ? QueryObjectImports.QAction : QueryObjectImports.QFunction;\n const qOperation = imports.addQObject(qOp);\n const paramModelName = operation.parameters.length\n ? imports.addGeneratedModel(baseFqName, operation.paramsModelName)\n : undefined;\n\n let returnTypeOpStmt: string = \"\";\n if (returnType) {\n const collectionSuffix = returnType.isCollection ? \"_COLLECTION\" : \"\";\n if (returnType.dataType === DataTypes.ComplexType || returnType.dataType === DataTypes.ModelType) {\n if (returnType.qObject) {\n const [opRt, rts, qComplexParam] = imports.addQObject(\n QueryObjectImports.OperationReturnType,\n QueryObjectImports.ReturnTypes,\n QueryObjectImports.QComplexParam\n );\n const returnQName = imports.addGeneratedQObject(returnType.fqType, returnType.qObject);\n\n returnTypeOpStmt = `new ${opRt}(${rts}.COMPLEX${collectionSuffix}, new ${qComplexParam}(\"NONE\", new ${returnQName}))`;\n }\n }\n // currently, it only makes sense to add the OperationReturnType if a converter is present\n else if (returnType.converters && returnType.qParam) {\n const [rtClass, rtTypes] = imports.addQObject(\n QueryObjectImports.OperationReturnType,\n QueryObjectImports.ReturnTypes\n );\n const [qParam] = imports.addFromQObject(returnType.qParam);\n\n // TODO: some constants with string concat\n const rtKind = `${rtTypes}.VALUE${collectionSuffix}`;\n\n const converterParam = returnType.converters\n ? \", \" + this.generateConverterStmt(imports, returnType.converters)\n : \"\";\n returnTypeOpStmt = `new ${rtClass}(${rtKind}, new ${qParam}(\"NONE\", undefined${converterParam}))`;\n }\n }\n\n file.getFile().addClass({\n name: operation.qName,\n isExported: true,\n extends: qOperation + (hasParams ? `<${paramModelName}>` : \"\"),\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n type: operation.parameters?.length ? undefined : \"[]\",\n initializer: this.getParamInitString(imports, operation.parameters),\n },\n ],\n ctors: [\n {\n statements: [\n `super(\"${operation.odataName}\"${returnTypeOpStmt ? \", \" + returnTypeOpStmt : isV2 ? \", undefined\" : \"\"}${\n isV2 ? \", { v2Mode: true }\" : \"\"\n })`,\n ],\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n // functions without params: add an overriding buildUrl() to not force users to have to pass undefined as param\n ...(operation.type === OperationTypes.Function && !hasParams\n ? [\n {\n name: \"buildUrl\",\n statements: [\"return super.buildUrl(undefined)\"],\n },\n ]\n : []),\n ],\n });\n }\n}\n"]}
|
|
@@ -8,4 +8,4 @@ export interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, "p
|
|
|
8
8
|
}
|
|
9
9
|
export interface ServiceGeneratorOptions extends Pick<ConfigFileOptions, "enablePrimitivePropertyServices" | "v4BigNumberAsString"> {
|
|
10
10
|
}
|
|
11
|
-
export declare function generateServices(
|
|
11
|
+
export declare function generateServices(project: ProjectManager, dataModel: DataModel, version: ODataVersions, namingHelper: NamingHelper, options?: ServiceGeneratorOptions): Promise<void>;
|