@odata2ts/odata2ts 0.32.0 → 0.33.0
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 +12 -0
- package/lib/app.js +12 -2
- package/lib/app.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +1 -0
- package/lib/data-model/DataModelDigestion.js +45 -22
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +2 -0
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/edmx/ODataEdmxModelBase.d.ts +2 -0
- package/lib/data-model/edmx/ODataEdmxModelBase.js.map +1 -1
- package/lib/generator/ModelGenerator.js +3 -6
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.js +14 -14
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.js +66 -66
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/project/ProjectManager.js +5 -4
- package/lib/project/ProjectManager.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.33.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.32.0...@odata2ts/odata2ts@0.33.0) (2024-03-17)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **generator:** enumerate generated files for emit mode ts ([#249](https://github.com/odata2ts/odata2ts/issues/249)) ([e58e3d5](https://github.com/odata2ts/odata2ts/commit/e58e3d5c6a9f73ec8eb9c011b9b42747d0576fc4))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **generator:** auto detected service names are run through pascalCase to ensure valid class names ([#250](https://github.com/odata2ts/odata2ts/issues/250)) ([04fcf49](https://github.com/odata2ts/odata2ts/commit/04fcf490aee43dc1c2bc70af394fe9d1d8ce3249))
|
|
15
|
+
* **generator:** no collection services for entity types without keys ([#248](https://github.com/odata2ts/odata2ts/issues/248)) ([56540b2](https://github.com/odata2ts/odata2ts/commit/56540b22aa92a7a8c929b4088c69d8af30b63364))
|
|
16
|
+
* **generator:** support abstract entities ([#247](https://github.com/odata2ts/odata2ts/issues/247)) ([cbf5121](https://github.com/odata2ts/odata2ts/commit/cbf51214da0fdbccba7fff5a3c0b770f73ed06bd))
|
|
17
|
+
|
|
6
18
|
# [0.32.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.31.1...@odata2ts/odata2ts@0.32.0) (2024-03-10)
|
|
7
19
|
|
|
8
20
|
### Bug Fixes
|
package/lib/app.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.runApp = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const odata_core_1 = require("@odata2ts/odata-core");
|
|
6
|
+
const pascal_case_1 = require("pascal-case");
|
|
6
7
|
const DataModelDigestionV2_1 = require("./data-model/DataModelDigestionV2");
|
|
7
8
|
const DataModelDigestionV4_1 = require("./data-model/DataModelDigestionV4");
|
|
8
9
|
const NamingHelper_1 = require("./data-model/NamingHelper");
|
|
@@ -15,6 +16,16 @@ function isQObjectGen(mode) {
|
|
|
15
16
|
function isServiceGen(mode) {
|
|
16
17
|
return [OptionModel_1.Modes.service, OptionModel_1.Modes.all].includes(mode);
|
|
17
18
|
}
|
|
19
|
+
function getServiceName(options, schemas) {
|
|
20
|
+
if (options.serviceName) {
|
|
21
|
+
return options.serviceName;
|
|
22
|
+
}
|
|
23
|
+
// auto-detection of first namespace with defined EntityTypes
|
|
24
|
+
// NOTE: we make use of PascalCase here to enforce valid class names
|
|
25
|
+
const detectedSchema = schemas.find((schema) => { var _a; return schema.$.Namespace && ((_a = schema.EntityType) === null || _a === void 0 ? void 0 : _a.length); }) || schemas[0];
|
|
26
|
+
const serviceName = detectedSchema.$.Namespace;
|
|
27
|
+
return (0, pascal_case_1.pascalCase)(serviceName);
|
|
28
|
+
}
|
|
18
29
|
/**
|
|
19
30
|
*
|
|
20
31
|
* @param metadataJson metadata of a given OData service already parsed as JSON
|
|
@@ -27,8 +38,7 @@ function runApp(metadataJson, options) {
|
|
|
27
38
|
const version = edmxVersion === "1.0" ? odata_core_1.ODataVersions.V2 : odata_core_1.ODataVersions.V4;
|
|
28
39
|
const dataService = metadataJson["edmx:Edmx"]["edmx:DataServices"][0];
|
|
29
40
|
const schemas = dataService.Schema;
|
|
30
|
-
const
|
|
31
|
-
const serviceName = options.serviceName || detectedSchema.$.Namespace;
|
|
41
|
+
const serviceName = getServiceName(options, schemas);
|
|
32
42
|
const namespaces = schemas.map((schema) => [schema.$.Namespace, schema.$.Alias]);
|
|
33
43
|
// encapsulate the whole naming logic
|
|
34
44
|
const namingHelper = new NamingHelper_1.NamingHelper(options, serviceName, namespaces);
|
package/lib/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AACrD,6CAAyC;AAGzC,4EAAuE;AACvE,4EAAuE;AAIvE,4DAAyD;AACzD,2CAAqF;AACrF,+CAAkD;AAClD,6DAAgE;AAEhE,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,QAAQ,EAAE,mBAAK,CAAC,OAAO,EAAE,mBAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,OAAO,EAAE,mBAAK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;QAC5B,0DAA0D;QAC1D,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;QACnD,IAAA,0BAAc,EAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAEtE,yBAAyB;QACzB,gDAAgD;QAChD,mJAAmJ;QACnJ,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAChD,IAAA,gCAAoB,EAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;SACxE;QAED,oCAAoC;QACpC,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,IAAA,4BAAgB,EAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;SAC5E;QAED,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;CAAA;AAlED,wBAkEC","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\nimport { pascalCase } from \"pascal-case\";\n\nimport { NamespaceWithAlias } from \"./data-model/DataModel\";\nimport { digest as digestV2 } from \"./data-model/DataModelDigestionV2\";\nimport { digest as digestV4 } from \"./data-model/DataModelDigestionV4\";\nimport { ODataEdmxModelBase, Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\nimport { SchemaV3 } from \"./data-model/edmx/ODataEdmxModelV3\";\nimport { SchemaV4 } from \"./data-model/edmx/ODataEdmxModelV4\";\nimport { NamingHelper } from \"./data-model/NamingHelper\";\nimport { generateModels, generateQueryObjects, generateServices } from \"./generator\";\nimport { Modes, RunOptions } from \"./OptionModel\";\nimport { createProjectManager } from \"./project/ProjectManager\";\n\nfunction isQObjectGen(mode: Modes) {\n return [Modes.qobjects, Modes.service, Modes.all].includes(mode);\n}\n\nfunction isServiceGen(mode: Modes) {\n return [Modes.service, Modes.all].includes(mode);\n}\n\nfunction getServiceName(options: RunOptions, schemas: Array<SchemaV3 | SchemaV4>) {\n if (options.serviceName) {\n return options.serviceName;\n }\n\n // auto-detection of first namespace with defined EntityTypes\n // NOTE: we make use of PascalCase here to enforce valid class names\n const detectedSchema = schemas.find((schema) => schema.$.Namespace && schema.EntityType?.length) || schemas[0];\n const serviceName = detectedSchema.$.Namespace;\n return pascalCase(serviceName);\n}\n\n/**\n *\n * @param metadataJson metadata of a given OData service already parsed as JSON\n * @param options further options\n */\nexport async function runApp(metadataJson: ODataEdmxModelBase<any>, options: RunOptions): Promise<void> {\n // determine edmx edmxVersion attribute\n const edmxVersion = metadataJson[\"edmx:Edmx\"].$.Version;\n const version = edmxVersion === \"1.0\" ? ODataVersions.V2 : ODataVersions.V4;\n\n const dataService = metadataJson[\"edmx:Edmx\"][\"edmx:DataServices\"][0];\n const schemas = dataService.Schema as Array<SchemaV3 | SchemaV4>;\n\n const serviceName = getServiceName(options, schemas);\n\n const namespaces = schemas.map<NamespaceWithAlias>((schema) => [schema.$.Namespace, schema.$.Alias]);\n\n // encapsulate the whole naming logic\n const namingHelper = new NamingHelper(options, serviceName, namespaces);\n // parse model information from edmx into something we can really work with\n // => that stuff is called dataModel!\n const dataModel =\n version === ODataVersions.V2\n ? await digestV2(dataService.Schema as Array<SchemaV3>, options, namingHelper)\n : await digestV4(dataService.Schema as Array<SchemaV4>, options, namingHelper);\n\n // Validation of entity names: the same name might be used across different namespaces\n const validationErrors = dataModel.getNameValidation();\n if (validationErrors.size) {\n console.log(\"---\");\n validationErrors.forEach((errors, name) => {\n console.log(\n `Duplicate name: ${name} - Fully Qualified Names: ${errors\n .map((error) => error.fqName + (error.renamedTo ? ` (renamed to: ${error.renamedTo})` : \"\"))\n .join(\", \")}`\n );\n });\n\n if (options.disableAutomaticNameClashResolution) {\n throw new Error(\"Name validation failed: Multiple entities have the same name across different namespaces!\");\n }\n }\n\n // handling the overall generation project\n const project = await createProjectManager(\n namingHelper.getFileNames(),\n options.output,\n options.emitMode,\n options.prettier,\n options.tsconfig\n );\n\n // Generate Model Interfaces\n // supported edmx types: EntityType, ComplexType, EnumType\n const modelsFile = await project.createModelFile();\n generateModels(dataModel, modelsFile, version, options, namingHelper);\n\n // Generate Query Objects\n // supported edmx types: EntityType, ComplexType\n // supported edmx prop types: primitive types, enum types, primitive collection (incl enum types), entity collection, entity object, complex object\n if (isQObjectGen(options.mode)) {\n const qFile = await project.createQObjectFile();\n generateQueryObjects(dataModel, qFile, version, options, namingHelper);\n }\n\n // Generate Individual OData-Service\n if (isServiceGen(options.mode)) {\n await generateServices(dataModel, project, version, namingHelper, options);\n }\n\n await project.writeFiles();\n}\n"]}
|
|
@@ -46,6 +46,7 @@ export declare abstract class Digester<S extends Schema<ET, CT>, ET extends Enti
|
|
|
46
46
|
private addComplexType;
|
|
47
47
|
private addEntityType;
|
|
48
48
|
private postProcessModel;
|
|
49
|
+
private postProcessKeys;
|
|
49
50
|
private collectBaseClassPropsAndKeys;
|
|
50
51
|
protected mapProp: (p: Property, entityPropConfig?: PropertyGenerationOptions | undefined) => PropertyModel;
|
|
51
52
|
}
|
|
@@ -5,6 +5,12 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const DataModel_1 = require("./DataModel");
|
|
6
6
|
const ServiceConfigHelper_1 = require("./ServiceConfigHelper");
|
|
7
7
|
const NameValidator_1 = require("./validation/NameValidator");
|
|
8
|
+
function ifTrue(value) {
|
|
9
|
+
return value === "true";
|
|
10
|
+
}
|
|
11
|
+
function ifFalse(value) {
|
|
12
|
+
return value === "false";
|
|
13
|
+
}
|
|
8
14
|
class Digester {
|
|
9
15
|
constructor(version, schemas, options, namingHelper, converters) {
|
|
10
16
|
this.version = version;
|
|
@@ -82,7 +88,7 @@ class Digester {
|
|
|
82
88
|
else {
|
|
83
89
|
throw new Error(`Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`);
|
|
84
90
|
}
|
|
85
|
-
return Object.assign({ odataName: p.$.Name, name, odataType: p.$.Type, fqType: dataType, required: p.$.Nullable
|
|
91
|
+
return Object.assign({ odataName: p.$.Name, name, odataType: p.$.Type, fqType: dataType, required: ifFalse(p.$.Nullable), isCollection: isCollection, managed: typeof (entityPropConfig === null || entityPropConfig === void 0 ? void 0 : entityPropConfig.managed) !== "undefined" ? entityPropConfig.managed : configProp === null || configProp === void 0 ? void 0 : configProp.managed }, result);
|
|
86
92
|
};
|
|
87
93
|
const namespaces = schemas.map((s) => [s.$.Namespace, s.$.Alias]);
|
|
88
94
|
this.dataModel = new DataModel_1.DataModel(namespaces, version, converters);
|
|
@@ -135,6 +141,7 @@ class Digester {
|
|
|
135
141
|
this.digestOperations(schema);
|
|
136
142
|
});
|
|
137
143
|
this.postProcessModel();
|
|
144
|
+
this.postProcessKeys();
|
|
138
145
|
}
|
|
139
146
|
getBaseModel(entityConfig, model, name, fqName) {
|
|
140
147
|
var _a, _b;
|
|
@@ -164,7 +171,9 @@ class Digester {
|
|
|
164
171
|
baseClasses,
|
|
165
172
|
finalBaseClass,
|
|
166
173
|
props,
|
|
167
|
-
baseProps: [],
|
|
174
|
+
baseProps: [],
|
|
175
|
+
abstract: ifTrue(model.$.Abstract),
|
|
176
|
+
open: ifTrue(model.$.OpenType),
|
|
168
177
|
};
|
|
169
178
|
}
|
|
170
179
|
addTypeDefinition(ns, types) {
|
|
@@ -227,31 +236,40 @@ class Digester {
|
|
|
227
236
|
keyNames.push(...propNames);
|
|
228
237
|
}
|
|
229
238
|
}
|
|
230
|
-
this.dataModel.addEntityType(namespace[0], baseModel.odataName, Object.assign(Object.assign({}, baseModel), { idModelName: this.namingHelper.getIdModelName(name), qIdFunctionName: this.namingHelper.getQIdFunctionName(name), generateId:
|
|
239
|
+
this.dataModel.addEntityType(namespace[0], baseModel.odataName, Object.assign(Object.assign({}, baseModel), { idModelName: this.namingHelper.getIdModelName(name), qIdFunctionName: this.namingHelper.getQIdFunctionName(name), generateId: !!keyNames.length, keyNames: keyNames, keys: [], getKeyUnion: () => keyNames.join(" | ") }));
|
|
231
240
|
}
|
|
232
241
|
}
|
|
233
242
|
postProcessModel() {
|
|
234
243
|
// complex types
|
|
235
244
|
const complexTypes = this.dataModel.getComplexTypes();
|
|
236
245
|
complexTypes.forEach((ct) => {
|
|
237
|
-
const [baseProps] = this.collectBaseClassPropsAndKeys(ct, []);
|
|
238
|
-
|
|
246
|
+
const [baseProps, _, baseAttributes] = this.collectBaseClassPropsAndKeys(ct, []);
|
|
247
|
+
const { open } = baseAttributes;
|
|
248
|
+
ct.baseProps = baseProps.map((bp) => (Object.assign({}, bp)));
|
|
249
|
+
if (open) {
|
|
250
|
+
ct.open = true;
|
|
251
|
+
}
|
|
239
252
|
});
|
|
240
253
|
// entity types
|
|
241
254
|
const entityTypes = this.dataModel.getEntityTypes();
|
|
242
255
|
entityTypes.forEach((et) => {
|
|
243
|
-
const [baseProps, baseKeys,
|
|
244
|
-
|
|
256
|
+
const [baseProps, baseKeys, baseAttributes] = this.collectBaseClassPropsAndKeys(et, []);
|
|
257
|
+
const { idName, qIdName, open } = baseAttributes;
|
|
258
|
+
et.baseProps = baseProps.map((bp) => (Object.assign({}, bp)));
|
|
245
259
|
if (!et.keyNames.length && idName) {
|
|
246
260
|
et.idModelName = idName;
|
|
247
261
|
et.qIdFunctionName = qIdName;
|
|
248
262
|
et.generateId = false;
|
|
249
263
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (!et.keyNames.length) {
|
|
253
|
-
throw new Error(`Key property is missing from Entity "${et.name}" (${et.odataName})!`);
|
|
264
|
+
if (open) {
|
|
265
|
+
et.open = open;
|
|
254
266
|
}
|
|
267
|
+
et.keyNames.unshift(...baseKeys);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
postProcessKeys() {
|
|
271
|
+
const entityTypes = this.dataModel.getEntityTypes();
|
|
272
|
+
entityTypes.forEach((et) => {
|
|
255
273
|
const isSingleKey = et.keyNames.length === 1;
|
|
256
274
|
const props = [...et.baseProps, ...et.props];
|
|
257
275
|
et.keys = et.keyNames.map((keyName) => {
|
|
@@ -272,33 +290,38 @@ class Digester {
|
|
|
272
290
|
throw new Error(`Cyclic inheritance detected for model ${model.fqName}!`);
|
|
273
291
|
}
|
|
274
292
|
visitedModels.push(model.fqName);
|
|
275
|
-
return model.baseClasses.reduce(([props, keys,
|
|
293
|
+
return model.baseClasses.reduce(([props, keys, attributes], bc) => {
|
|
276
294
|
var _a;
|
|
277
295
|
const baseModel = this.dataModel.getEntityType(bc) || this.dataModel.getComplexType(bc);
|
|
278
296
|
if (!baseModel) {
|
|
279
297
|
throw new Error(`BaseModel "${bc}" doesn't exist!`);
|
|
280
298
|
}
|
|
281
|
-
let
|
|
282
|
-
let qIdNameResult = qIdName;
|
|
299
|
+
let { idName, qIdName, open } = attributes;
|
|
283
300
|
// recursive
|
|
284
301
|
if (baseModel.baseClasses.length) {
|
|
285
|
-
const [parentProps, parentKeys,
|
|
302
|
+
const [parentProps, parentKeys, parentAttributes] = this.collectBaseClassPropsAndKeys(baseModel, visitedModels);
|
|
286
303
|
props.unshift(...parentProps);
|
|
287
304
|
keys.unshift(...parentKeys);
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
|
|
305
|
+
if (parentAttributes === null || parentAttributes === void 0 ? void 0 : parentAttributes.idName) {
|
|
306
|
+
idName = parentAttributes.idName;
|
|
307
|
+
qIdName = parentAttributes.qIdName;
|
|
308
|
+
}
|
|
309
|
+
if (parentAttributes === null || parentAttributes === void 0 ? void 0 : parentAttributes.open) {
|
|
310
|
+
open = true;
|
|
291
311
|
}
|
|
292
312
|
}
|
|
293
313
|
props.push(...baseModel.props);
|
|
294
314
|
const entityModel = baseModel;
|
|
295
315
|
if ((_a = entityModel.keyNames) === null || _a === void 0 ? void 0 : _a.length) {
|
|
296
316
|
keys.push(...entityModel.keyNames.filter((kn) => !keys.includes(kn)));
|
|
297
|
-
|
|
298
|
-
|
|
317
|
+
idName = entityModel.idModelName;
|
|
318
|
+
qIdName = entityModel.qIdFunctionName;
|
|
319
|
+
}
|
|
320
|
+
if (baseModel.open) {
|
|
321
|
+
open = true;
|
|
299
322
|
}
|
|
300
|
-
return [props, keys,
|
|
301
|
-
}, [[], [], "", ""]);
|
|
323
|
+
return [props, keys, { idName, qIdName, open }];
|
|
324
|
+
}, [[], [], { idName: "", qIdName: "", open: false }]);
|
|
302
325
|
}
|
|
303
326
|
}
|
|
304
327
|
exports.Digester = Digester;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataModelDigestion.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestion.ts"],"names":[],"mappings":";;;;AAIA,2CAA2E;AAM3E,+DAAyE;AACzE,8DAA2D;AAS3D,MAAsB,QAAQ;IAS5B,YACY,OAAqB,EACrB,OAAiB,EACjB,OAAyB,EACzB,YAA0B,EACpC,UAAkC;QAJxB,YAAO,GAAP,OAAO,CAAc;QACrB,YAAO,GAAP,OAAO,CAAU;QACjB,YAAO,GAAP,OAAO,CAAkB;QACzB,iBAAY,GAAZ,YAAY,CAAc;QAN9B,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;QAoSxC,YAAO,GAAG,CAAC,CAAW,EAAE,gBAAwD,EAAiB,EAAE;;YAC3G,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;gBACb,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;aAC1E;YAED,MAAM,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC3E,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,UAAU,MAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,UAAU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AAC;IACJ,CAAC;;AAzSH,4BAuYC;AAtYkB,mBAAU,GAAG,MAAM,AAAT,CAAU","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\n\nimport { DigestionOptions } from \"../FactoryFunctionModel\";\nimport { ComplexTypeGenerationOptions, EntityTypeGenerationOptions, PropertyGenerationOptions } from \"../OptionModel\";\nimport { DataModel, NamespaceWithAlias, withNamespace } from \"./DataModel\";\nimport { ComplexType as ComplexModelType, DataTypes, ModelType, ODataVersion, PropertyModel } from \"./DataTypeModel\";\nimport { ComplexType, EntityType, EnumType, Property, Schema, TypeDefinition } from \"./edmx/ODataEdmxModelBase\";\nimport { SchemaV3 } from \"./edmx/ODataEdmxModelV3\";\nimport { SchemaV4 } from \"./edmx/ODataEdmxModelV4\";\nimport { NamingHelper } from \"./NamingHelper\";\nimport { ServiceConfigHelper, WithoutName } from \"./ServiceConfigHelper\";\nimport { NameValidator } from \"./validation/NameValidator\";\n\nexport interface TypeModel {\n outputType: string;\n qPath: string;\n qCollection: string;\n qParam: string | undefined;\n}\n\nexport abstract class Digester<S extends Schema<ET, CT>, ET extends EntityType, CT extends ComplexType> {\n protected static EDM_PREFIX = \"Edm.\";\n\n protected readonly dataModel: DataModel;\n protected readonly serviceConfigHelper: ServiceConfigHelper;\n protected readonly nameValidator: NameValidator;\n\n private model2Type = new Map<string, DataTypes>();\n\n protected constructor(\n protected version: ODataVersion,\n protected schemas: Array<S>,\n protected options: DigestionOptions,\n protected namingHelper: NamingHelper,\n converters?: MappedConverterChains\n ) {\n const namespaces = schemas.map<NamespaceWithAlias>((s) => [s.$.Namespace, s.$.Alias]);\n this.dataModel = new DataModel(namespaces, version, converters);\n this.serviceConfigHelper = new ServiceConfigHelper(options);\n this.nameValidator = new NameValidator(options);\n\n this.collectModelTypes(schemas);\n }\n\n private collectModelTypes(schemas: Array<S>) {\n schemas.forEach((schema) => {\n const { Namespace: ns, Alias: alias } = schema.$;\n\n schema.EnumType?.forEach((et) => {\n this.addModel2Type(ns, alias, et.$.Name, DataTypes.EnumType);\n });\n schema.ComplexType?.forEach((ct) => {\n this.addModel2Type(ns, alias, ct.$.Name, DataTypes.ComplexType);\n });\n schema.EntityType?.forEach((et) => {\n this.addModel2Type(ns, alias, et.$.Name, DataTypes.ModelType);\n });\n });\n }\n\n private addModel2Type(ns: string, alias: string | undefined, name: string, dt: DataTypes) {\n this.model2Type.set(withNamespace(ns, name), dt);\n if (alias) {\n this.model2Type.set(withNamespace(alias, name), dt);\n }\n }\n\n protected abstract getNavigationProps(entityType: ET | ComplexType): Array<Property>;\n\n protected abstract digestOperations(schema: SchemaV3 | SchemaV4): void;\n\n protected abstract digestEntityContainer(schema: SchemaV3 | SchemaV4): void;\n\n /**\n * Get essential infos about a given odata type from the version specific service variants.\n *\n * @param type\n * @return tuple of return type, query object, query collection object\n */\n protected abstract mapODataType(type: string): TypeModel;\n\n public async digest(): Promise<DataModel> {\n this.digestEntityTypesAndOperations();\n\n // delegate to version specific entity container digestion\n this.schemas.forEach((schema) => this.digestEntityContainer(schema));\n\n this.dataModel.setNameValidation(this.nameValidator.validate());\n return this.dataModel;\n }\n\n private digestEntityTypesAndOperations() {\n this.schemas.forEach((schema) => {\n const ns: NamespaceWithAlias = [schema.$.Namespace, schema.$.Alias];\n\n // type definitions: alias for primitive types\n this.addTypeDefinition(schema.$.Namespace, schema.TypeDefinition);\n\n // enums\n this.addEnum(ns, schema.EnumType);\n\n // complex types\n this.addComplexType(ns, schema.ComplexType);\n\n // entity types\n this.addEntityType(ns, schema.EntityType);\n\n // V4 only: function & action types\n this.digestOperations(schema);\n });\n\n this.postProcessModel();\n }\n\n private getBaseModel(\n entityConfig: WithoutName<EntityTypeGenerationOptions | ComplexTypeGenerationOptions> | undefined,\n model: ComplexType,\n name: string,\n fqName: string\n ) {\n const odataName = model.$.Name;\n\n // map properties respecting the config\n const props = [...(model.Property ?? []), ...this.getNavigationProps(model)].map((p) => {\n const epConfig = entityConfig?.properties?.find((ep) => ep.name === p.$.Name);\n return this.mapProp(p, epConfig);\n });\n\n // support for base types, i.e. extends clause of interfaces\n const baseClasses = [];\n let finalBaseClass: string | undefined = undefined;\n if (model.$.BaseType) {\n baseClasses.push(model.$.BaseType);\n const [baseName, basePrefix] = this.namingHelper.getNameAndServicePrefix(model.$.BaseType);\n const baseConfig =\n this.serviceConfigHelper.findEntityTypeConfig([basePrefix!], baseName) ||\n this.serviceConfigHelper.findComplexTypeConfig([basePrefix!], baseName);\n finalBaseClass = baseConfig?.mappedName ?? baseName;\n }\n\n return {\n fqName,\n odataName,\n name: this.namingHelper.getModelName(name),\n qName: this.namingHelper.getQName(name),\n editableName: this.namingHelper.getEditableModelName(name),\n baseClasses,\n finalBaseClass,\n props,\n baseProps: [], // postprocess required\n };\n }\n\n private addTypeDefinition(ns: string, types: Array<TypeDefinition> | undefined) {\n if (!types || !types.length) {\n return;\n }\n\n for (const t of types) {\n this.dataModel.addTypeDefinition(ns, t.$.Name, t.$.UnderlyingType);\n }\n }\n\n private addEnum(namespace: NamespaceWithAlias, models: Array<EnumType> | undefined) {\n if (!models || !models.length) {\n return;\n }\n\n for (const et of models) {\n const odataName = et.$.Name;\n const fqName = withNamespace(namespace[0], odataName);\n const config = this.serviceConfigHelper.findEnumTypeConfig(namespace, odataName);\n const enumName = this.nameValidator.addEnumType(fqName, config?.mappedName || odataName);\n\n this.dataModel.addEnum(namespace[0], odataName, {\n fqName,\n odataName,\n name: this.namingHelper.getEnumName(enumName),\n members: et.Member.map((m) => m.$.Name),\n });\n }\n }\n\n private addComplexType(namespace: NamespaceWithAlias, models: Array<ComplexType> | undefined) {\n if (!models || !models.length) {\n return;\n }\n\n for (const model of models) {\n const config = this.serviceConfigHelper.findComplexTypeConfig(namespace, model.$.Name);\n const fqName = withNamespace(namespace[0], model.$.Name);\n const name = this.nameValidator.addComplexType(fqName, config?.mappedName || model.$.Name);\n const baseModel = this.getBaseModel(config, model, name, fqName);\n this.dataModel.addComplexType(namespace[0], baseModel.odataName, baseModel);\n }\n }\n\n private addEntityType(namespace: NamespaceWithAlias, models: Array<ET> | undefined) {\n if (!models || !models.length) {\n return;\n }\n\n for (const model of models) {\n const entityConfig = this.serviceConfigHelper.findEntityTypeConfig(namespace, model.$.Name);\n const fqName = withNamespace(namespace[0], model.$.Name);\n const name = this.nameValidator.addEntityType(fqName, entityConfig?.mappedName || model.$.Name);\n const baseModel = this.getBaseModel(entityConfig, model, name, fqName);\n\n // key support: we add keys from this entity,\n // but not keys stemming from base classes (postprocess required)\n const keyNames: Array<string> = [];\n if (entityConfig?.keys?.length) {\n keyNames.push(...entityConfig.keys);\n } else {\n const entity = model as EntityType;\n if (entity.Key && entity.Key.length && entity.Key[0].PropertyRef.length) {\n const propNames = entity.Key[0].PropertyRef.map((key) => key.$.Name);\n keyNames.push(...propNames);\n }\n }\n\n this.dataModel.addEntityType(namespace[0], baseModel.odataName, {\n ...baseModel,\n idModelName: this.namingHelper.getIdModelName(name),\n qIdFunctionName: this.namingHelper.getQIdFunctionName(name),\n generateId: true,\n keyNames: keyNames, // postprocess required to include key specs from base classes\n keys: [], // postprocess required to include props from base classes\n getKeyUnion: () => keyNames.join(\" | \"),\n });\n }\n }\n\n private postProcessModel() {\n // complex types\n const complexTypes = this.dataModel.getComplexTypes();\n complexTypes.forEach((ct) => {\n const [baseProps] = this.collectBaseClassPropsAndKeys(ct, []);\n ct.baseProps = baseProps;\n });\n // entity types\n const entityTypes = this.dataModel.getEntityTypes();\n entityTypes.forEach((et) => {\n const [baseProps, baseKeys, idName, qIdName] = this.collectBaseClassPropsAndKeys(et, []);\n et.baseProps = baseProps;\n\n if (!et.keyNames.length && idName) {\n et.idModelName = idName;\n et.qIdFunctionName = qIdName;\n et.generateId = false;\n }\n et.keyNames.unshift(...baseKeys);\n\n // sanity check: entity types require key specification\n if (!et.keyNames.length) {\n throw new Error(`Key property is missing from Entity \"${et.name}\" (${et.odataName})!`);\n }\n\n const isSingleKey = et.keyNames.length === 1;\n const props = [...et.baseProps, ...et.props];\n et.keys = et.keyNames.map((keyName) => {\n const prop = props.find((p) => p.odataName === keyName);\n if (!prop) {\n throw new Error(`Key with name [${keyName}] not found in props!`);\n }\n // automatically set key prop to managed, if this is the only key of the given entity\n if (prop.managed === undefined) {\n prop.managed = !this.options.disableAutoManagedKey && isSingleKey;\n }\n return prop;\n });\n });\n }\n\n private collectBaseClassPropsAndKeys(\n model: ComplexModelType,\n visitedModels: string[]\n ): [Array<PropertyModel>, Array<string>, string, string] {\n if (visitedModels.includes(model.fqName)) {\n throw new Error(`Cyclic inheritance detected for model ${model.fqName}!`);\n }\n visitedModels.push(model.fqName);\n return model.baseClasses.reduce(\n ([props, keys, idName, qIdName], bc) => {\n const baseModel = this.dataModel.getEntityType(bc) || this.dataModel.getComplexType(bc);\n if (!baseModel) {\n throw new Error(`BaseModel \"${bc}\" doesn't exist!`);\n }\n\n let idNameResult = idName;\n let qIdNameResult = qIdName;\n\n // recursive\n if (baseModel.baseClasses.length) {\n const [parentProps, parentKeys, parentIdName, parentQIdName] = this.collectBaseClassPropsAndKeys(\n baseModel,\n visitedModels\n );\n props.unshift(...parentProps);\n keys.unshift(...parentKeys);\n if (parentIdName) {\n idNameResult = parentIdName;\n qIdNameResult = parentQIdName;\n }\n }\n\n props.push(...baseModel.props);\n const entityModel = baseModel as ModelType;\n if (entityModel.keyNames?.length) {\n keys.push(...entityModel.keyNames.filter((kn) => !keys.includes(kn)));\n idNameResult = entityModel.idModelName;\n qIdNameResult = entityModel.qIdFunctionName;\n }\n return [props, keys, idNameResult, qIdNameResult];\n },\n [[], [], \"\", \"\"] as [Array<PropertyModel>, Array<string>, string, string]\n );\n }\n\n protected mapProp = (p: Property, entityPropConfig?: PropertyGenerationOptions | undefined): PropertyModel => {\n if (!p.$.Type) {\n throw new Error(`No type information given for property [${p.$.Name}]!`);\n }\n\n const configProp = this.serviceConfigHelper.findPropConfigByName(p.$.Name);\n const name = this.namingHelper.getModelPropName(entityPropConfig?.mappedName || configProp?.mappedName || p.$.Name);\n const isCollection = !!p.$.Type.match(/^Collection\\(/);\n let dataType = p.$.Type.replace(/^Collection\\(([^\\)]+)\\)/, \"$1\");\n\n // support for primitive type mapping\n if (this.namingHelper.includesServicePrefix(dataType)) {\n const dt = this.dataModel.getPrimitiveType(dataType);\n if (dt !== undefined) {\n dataType = dt;\n }\n }\n\n let result: Pick<PropertyModel, \"dataType\" | \"type\" | \"typeModule\" | \"qPath\" | \"qParam\" | \"qObject\" | \"converters\">;\n\n // domain object known from service:\n // EntityType, ComplexType, EnumType\n if (this.namingHelper.includesServicePrefix(dataType)) {\n const resultDt = this.model2Type.get(dataType)!;\n const [dataTypeName, dataTypePrefix] = this.namingHelper.getNameAndServicePrefix(dataType);\n const dataTypeNamespace: NamespaceWithAlias = [dataTypePrefix!];\n if (!resultDt) {\n throw new Error(\n `Couldn't determine model data type for property \"${p.$.Name}\"! Given data type: \"${dataType}\".`\n );\n }\n\n // special handling for enums\n if (resultDt === DataTypes.EnumType) {\n const enumConfig = this.serviceConfigHelper.findEnumTypeConfig(dataTypeNamespace, dataTypeName);\n result = {\n dataType: resultDt,\n type: this.namingHelper.getEnumName(enumConfig?.mappedName ?? dataType),\n qPath: \"QEnumPath\",\n qObject: isCollection ? \"QEnumCollection\" : undefined,\n qParam: \"QEnumParam\",\n };\n }\n // handling of complex & entity types\n else {\n const entityConfig =\n resultDt === DataTypes.ComplexType\n ? this.serviceConfigHelper.findComplexTypeConfig(dataTypeNamespace, dataTypeName)\n : this.serviceConfigHelper.findEntityTypeConfig(dataTypeNamespace, dataTypeName);\n const resultDataType = entityConfig?.mappedName ?? dataType;\n result = {\n dataType: resultDt,\n type: this.namingHelper.getModelName(resultDataType),\n qPath: \"QEntityPath\",\n qObject: this.namingHelper.getQName(resultDataType),\n qParam: \"QComplexParam\",\n };\n }\n }\n // OData built-in data types\n else if (dataType.startsWith(Digester.EDM_PREFIX)) {\n const { outputType, qPath, qParam, qCollection } = this.mapODataType(dataType);\n const { to, toModule: typeModule, converters } = this.dataModel.getConverter(dataType) || {};\n\n const type = !to ? outputType : to.startsWith(Digester.EDM_PREFIX) ? this.mapODataType(to).outputType : to;\n\n result = {\n dataType: DataTypes.PrimitiveType,\n type,\n typeModule,\n qPath,\n qParam,\n qObject: isCollection ? qCollection : undefined,\n converters,\n };\n } else {\n throw new Error(\n `Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`\n );\n }\n\n return {\n odataName: p.$.Name,\n name,\n odataType: p.$.Type,\n fqType: dataType,\n required: p.$.Nullable === \"false\",\n isCollection: isCollection,\n managed: typeof entityPropConfig?.managed !== \"undefined\" ? entityPropConfig.managed : configProp?.managed,\n ...result,\n };\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DataModelDigestion.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestion.ts"],"names":[],"mappings":";;;;AAIA,2CAA2E;AAM3E,+DAAyE;AACzE,8DAA2D;AAI3D,SAAS,MAAM,CAAC,KAAyB;IACvC,OAAO,KAAK,KAAK,MAAM,CAAC;AAC1B,CAAC;AAED,SAAS,OAAO,CAAC,KAAyB;IACxC,OAAO,KAAK,KAAK,OAAO,CAAC;AAC3B,CAAC;AASD,MAAsB,QAAQ;IAS5B,YACY,OAAqB,EACrB,OAAiB,EACjB,OAAyB,EACzB,YAA0B,EACpC,UAAkC;QAJxB,YAAO,GAAP,OAAO,CAAc;QACrB,YAAO,GAAP,OAAO,CAAU;QACjB,YAAO,GAAP,OAAO,CAAkB;QACzB,iBAAY,GAAZ,YAAY,CAAc;QAN9B,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;QAmTxC,YAAO,GAAG,CAAC,CAAW,EAAE,gBAAwD,EAAiB,EAAE;;YAC3G,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;gBACb,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;aAC1E;YAED,MAAM,UAAU,G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T,CAAU","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\n\nimport { DigestionOptions } from \"../FactoryFunctionModel\";\nimport { ComplexTypeGenerationOptions, EntityTypeGenerationOptions, PropertyGenerationOptions } from \"../OptionModel\";\nimport { DataModel, NamespaceWithAlias, withNamespace } from \"./DataModel\";\nimport { ComplexType as ComplexModelType, DataTypes, ModelType, ODataVersion, PropertyModel } from \"./DataTypeModel\";\nimport { ComplexType, EntityType, EnumType, Property, Schema, TypeDefinition } from \"./edmx/ODataEdmxModelBase\";\nimport { SchemaV3 } from \"./edmx/ODataEdmxModelV3\";\nimport { SchemaV4 } from \"./edmx/ODataEdmxModelV4\";\nimport { NamingHelper } from \"./NamingHelper\";\nimport { ServiceConfigHelper, WithoutName } from \"./ServiceConfigHelper\";\nimport { NameValidator } from \"./validation/NameValidator\";\n\ntype CollectorTuple = [Array<PropertyModel>, Array<string>, { idName: string; qIdName: string; open: boolean }];\n\nfunction ifTrue(value: string | undefined): boolean {\n return value === \"true\";\n}\n\nfunction ifFalse(value: string | undefined): boolean {\n return value === \"false\";\n}\n\nexport interface TypeModel {\n outputType: string;\n qPath: string;\n qCollection: string;\n qParam: string | undefined;\n}\n\nexport abstract class Digester<S extends Schema<ET, CT>, ET extends EntityType, CT extends ComplexType> {\n protected static EDM_PREFIX = \"Edm.\";\n\n protected readonly dataModel: DataModel;\n protected readonly serviceConfigHelper: ServiceConfigHelper;\n protected readonly nameValidator: NameValidator;\n\n private model2Type = new Map<string, DataTypes>();\n\n protected constructor(\n protected version: ODataVersion,\n protected schemas: Array<S>,\n protected options: DigestionOptions,\n protected namingHelper: NamingHelper,\n converters?: MappedConverterChains\n ) {\n const namespaces = schemas.map<NamespaceWithAlias>((s) => [s.$.Namespace, s.$.Alias]);\n this.dataModel = new DataModel(namespaces, version, converters);\n this.serviceConfigHelper = new ServiceConfigHelper(options);\n this.nameValidator = new NameValidator(options);\n\n this.collectModelTypes(schemas);\n }\n\n private collectModelTypes(schemas: Array<S>) {\n schemas.forEach((schema) => {\n const { Namespace: ns, Alias: alias } = schema.$;\n\n schema.EnumType?.forEach((et) => {\n this.addModel2Type(ns, alias, et.$.Name, DataTypes.EnumType);\n });\n schema.ComplexType?.forEach((ct) => {\n this.addModel2Type(ns, alias, ct.$.Name, DataTypes.ComplexType);\n });\n schema.EntityType?.forEach((et) => {\n this.addModel2Type(ns, alias, et.$.Name, DataTypes.ModelType);\n });\n });\n }\n\n private addModel2Type(ns: string, alias: string | undefined, name: string, dt: DataTypes) {\n this.model2Type.set(withNamespace(ns, name), dt);\n if (alias) {\n this.model2Type.set(withNamespace(alias, name), dt);\n }\n }\n\n protected abstract getNavigationProps(entityType: ET | ComplexType): Array<Property>;\n\n protected abstract digestOperations(schema: SchemaV3 | SchemaV4): void;\n\n protected abstract digestEntityContainer(schema: SchemaV3 | SchemaV4): void;\n\n /**\n * Get essential infos about a given odata type from the version specific service variants.\n *\n * @param type\n * @return tuple of return type, query object, query collection object\n */\n protected abstract mapODataType(type: string): TypeModel;\n\n public async digest(): Promise<DataModel> {\n this.digestEntityTypesAndOperations();\n\n // delegate to version specific entity container digestion\n this.schemas.forEach((schema) => this.digestEntityContainer(schema));\n\n this.dataModel.setNameValidation(this.nameValidator.validate());\n return this.dataModel;\n }\n\n private digestEntityTypesAndOperations() {\n this.schemas.forEach((schema) => {\n const ns: NamespaceWithAlias = [schema.$.Namespace, schema.$.Alias];\n\n // type definitions: alias for primitive types\n this.addTypeDefinition(schema.$.Namespace, schema.TypeDefinition);\n\n // enums\n this.addEnum(ns, schema.EnumType);\n\n // complex types\n this.addComplexType(ns, schema.ComplexType);\n\n // entity types\n this.addEntityType(ns, schema.EntityType);\n\n // V4 only: function & action types\n this.digestOperations(schema);\n });\n\n this.postProcessModel();\n this.postProcessKeys();\n }\n\n private getBaseModel(\n entityConfig: WithoutName<EntityTypeGenerationOptions | ComplexTypeGenerationOptions> | undefined,\n model: ComplexType,\n name: string,\n fqName: string\n ) {\n const odataName = model.$.Name;\n\n // map properties respecting the config\n const props = [...(model.Property ?? []), ...this.getNavigationProps(model)].map((p) => {\n const epConfig = entityConfig?.properties?.find((ep) => ep.name === p.$.Name);\n return this.mapProp(p, epConfig);\n });\n\n // support for base types, i.e. extends clause of interfaces\n const baseClasses = [];\n let finalBaseClass: string | undefined = undefined;\n if (model.$.BaseType) {\n baseClasses.push(model.$.BaseType);\n const [baseName, basePrefix] = this.namingHelper.getNameAndServicePrefix(model.$.BaseType);\n const baseConfig =\n this.serviceConfigHelper.findEntityTypeConfig([basePrefix!], baseName) ||\n this.serviceConfigHelper.findComplexTypeConfig([basePrefix!], baseName);\n finalBaseClass = baseConfig?.mappedName ?? baseName;\n }\n\n return {\n fqName,\n odataName,\n name: this.namingHelper.getModelName(name),\n qName: this.namingHelper.getQName(name),\n editableName: this.namingHelper.getEditableModelName(name),\n baseClasses,\n finalBaseClass,\n props,\n baseProps: [], // postprocess required\n abstract: ifTrue(model.$.Abstract),\n open: ifTrue(model.$.OpenType),\n };\n }\n\n private addTypeDefinition(ns: string, types: Array<TypeDefinition> | undefined) {\n if (!types || !types.length) {\n return;\n }\n\n for (const t of types) {\n this.dataModel.addTypeDefinition(ns, t.$.Name, t.$.UnderlyingType);\n }\n }\n\n private addEnum(namespace: NamespaceWithAlias, models: Array<EnumType> | undefined) {\n if (!models || !models.length) {\n return;\n }\n\n for (const et of models) {\n const odataName = et.$.Name;\n const fqName = withNamespace(namespace[0], odataName);\n const config = this.serviceConfigHelper.findEnumTypeConfig(namespace, odataName);\n const enumName = this.nameValidator.addEnumType(fqName, config?.mappedName || odataName);\n\n this.dataModel.addEnum(namespace[0], odataName, {\n fqName,\n odataName,\n name: this.namingHelper.getEnumName(enumName),\n members: et.Member.map((m) => m.$.Name),\n });\n }\n }\n\n private addComplexType(namespace: NamespaceWithAlias, models: Array<ComplexType> | undefined) {\n if (!models || !models.length) {\n return;\n }\n\n for (const model of models) {\n const config = this.serviceConfigHelper.findComplexTypeConfig(namespace, model.$.Name);\n const fqName = withNamespace(namespace[0], model.$.Name);\n const name = this.nameValidator.addComplexType(fqName, config?.mappedName || model.$.Name);\n const baseModel = this.getBaseModel(config, model, name, fqName);\n this.dataModel.addComplexType(namespace[0], baseModel.odataName, baseModel);\n }\n }\n\n private addEntityType(namespace: NamespaceWithAlias, models: Array<ET> | undefined) {\n if (!models || !models.length) {\n return;\n }\n\n for (const model of models) {\n const entityConfig = this.serviceConfigHelper.findEntityTypeConfig(namespace, model.$.Name);\n const fqName = withNamespace(namespace[0], model.$.Name);\n const name = this.nameValidator.addEntityType(fqName, entityConfig?.mappedName || model.$.Name);\n const baseModel = this.getBaseModel(entityConfig, model, name, fqName);\n\n // key support: we add keys from this entity,\n // but not keys stemming from base classes (postprocess required)\n const keyNames: Array<string> = [];\n if (entityConfig?.keys?.length) {\n keyNames.push(...entityConfig.keys);\n } else {\n const entity = model as EntityType;\n if (entity.Key && entity.Key.length && entity.Key[0].PropertyRef.length) {\n const propNames = entity.Key[0].PropertyRef.map((key) => key.$.Name);\n keyNames.push(...propNames);\n }\n }\n\n this.dataModel.addEntityType(namespace[0], baseModel.odataName, {\n ...baseModel,\n idModelName: this.namingHelper.getIdModelName(name),\n qIdFunctionName: this.namingHelper.getQIdFunctionName(name),\n generateId: !!keyNames.length,\n keyNames: keyNames, // postprocess required to include key specs from base classes\n keys: [], // postprocess required to include props from base classes\n getKeyUnion: () => keyNames.join(\" | \"),\n });\n }\n }\n\n private postProcessModel() {\n // complex types\n const complexTypes = this.dataModel.getComplexTypes();\n complexTypes.forEach((ct) => {\n const [baseProps, _, baseAttributes] = this.collectBaseClassPropsAndKeys(ct, []);\n const { open } = baseAttributes;\n ct.baseProps = baseProps.map((bp) => ({ ...bp }));\n if (open) {\n ct.open = true;\n }\n });\n // entity types\n const entityTypes = this.dataModel.getEntityTypes();\n entityTypes.forEach((et) => {\n const [baseProps, baseKeys, baseAttributes] = this.collectBaseClassPropsAndKeys(et, []);\n const { idName, qIdName, open } = baseAttributes;\n et.baseProps = baseProps.map((bp) => ({ ...bp }));\n\n if (!et.keyNames.length && idName) {\n et.idModelName = idName;\n et.qIdFunctionName = qIdName;\n et.generateId = false;\n }\n if (open) {\n et.open = open;\n }\n et.keyNames.unshift(...baseKeys);\n });\n }\n\n private postProcessKeys() {\n const entityTypes = this.dataModel.getEntityTypes();\n entityTypes.forEach((et) => {\n const isSingleKey = et.keyNames.length === 1;\n const props = [...et.baseProps, ...et.props];\n et.keys = et.keyNames.map((keyName) => {\n const prop = props.find((p) => p.odataName === keyName);\n if (!prop) {\n throw new Error(`Key with name [${keyName}] not found in props!`);\n }\n\n // automatically set key prop to managed, if this is the only key of the given entity\n if (prop.managed === undefined) {\n prop.managed = !this.options.disableAutoManagedKey && isSingleKey;\n }\n\n return prop;\n });\n });\n }\n\n private collectBaseClassPropsAndKeys(model: ComplexModelType, visitedModels: string[]): CollectorTuple {\n if (visitedModels.includes(model.fqName)) {\n throw new Error(`Cyclic inheritance detected for model ${model.fqName}!`);\n }\n visitedModels.push(model.fqName);\n return model.baseClasses.reduce(\n ([props, keys, attributes], bc) => {\n const baseModel = this.dataModel.getEntityType(bc) || this.dataModel.getComplexType(bc);\n if (!baseModel) {\n throw new Error(`BaseModel \"${bc}\" doesn't exist!`);\n }\n\n let { idName, qIdName, open } = attributes;\n\n // recursive\n if (baseModel.baseClasses.length) {\n const [parentProps, parentKeys, parentAttributes] = this.collectBaseClassPropsAndKeys(\n baseModel,\n visitedModels\n );\n props.unshift(...parentProps);\n keys.unshift(...parentKeys);\n if (parentAttributes?.idName) {\n idName = parentAttributes.idName;\n qIdName = parentAttributes.qIdName;\n }\n if (parentAttributes?.open) {\n open = true;\n }\n }\n\n props.push(...baseModel.props);\n const entityModel = baseModel as ModelType;\n if (entityModel.keyNames?.length) {\n keys.push(...entityModel.keyNames.filter((kn) => !keys.includes(kn)));\n idName = entityModel.idModelName;\n qIdName = entityModel.qIdFunctionName;\n }\n if (baseModel.open) {\n open = true;\n }\n return [props, keys, { idName, qIdName, open }];\n },\n [[], [], { idName: \"\", qIdName: \"\", open: false }] as CollectorTuple\n );\n }\n\n protected mapProp = (p: Property, entityPropConfig?: PropertyGenerationOptions | undefined): PropertyModel => {\n if (!p.$.Type) {\n throw new Error(`No type information given for property [${p.$.Name}]!`);\n }\n\n const configProp = this.serviceConfigHelper.findPropConfigByName(p.$.Name);\n const name = this.namingHelper.getModelPropName(entityPropConfig?.mappedName || configProp?.mappedName || p.$.Name);\n const isCollection = !!p.$.Type.match(/^Collection\\(/);\n let dataType = p.$.Type.replace(/^Collection\\(([^\\)]+)\\)/, \"$1\");\n\n // support for primitive type mapping\n if (this.namingHelper.includesServicePrefix(dataType)) {\n const dt = this.dataModel.getPrimitiveType(dataType);\n if (dt !== undefined) {\n dataType = dt;\n }\n }\n\n let result: Pick<PropertyModel, \"dataType\" | \"type\" | \"typeModule\" | \"qPath\" | \"qParam\" | \"qObject\" | \"converters\">;\n\n // domain object known from service:\n // EntityType, ComplexType, EnumType\n if (this.namingHelper.includesServicePrefix(dataType)) {\n const resultDt = this.model2Type.get(dataType)!;\n const [dataTypeName, dataTypePrefix] = this.namingHelper.getNameAndServicePrefix(dataType);\n const dataTypeNamespace: NamespaceWithAlias = [dataTypePrefix!];\n if (!resultDt) {\n throw new Error(\n `Couldn't determine model data type for property \"${p.$.Name}\"! Given data type: \"${dataType}\".`\n );\n }\n\n // special handling for enums\n if (resultDt === DataTypes.EnumType) {\n const enumConfig = this.serviceConfigHelper.findEnumTypeConfig(dataTypeNamespace, dataTypeName);\n result = {\n dataType: resultDt,\n type: this.namingHelper.getEnumName(enumConfig?.mappedName ?? dataType),\n qPath: \"QEnumPath\",\n qObject: isCollection ? \"QEnumCollection\" : undefined,\n qParam: \"QEnumParam\",\n };\n }\n // handling of complex & entity types\n else {\n const entityConfig =\n resultDt === DataTypes.ComplexType\n ? this.serviceConfigHelper.findComplexTypeConfig(dataTypeNamespace, dataTypeName)\n : this.serviceConfigHelper.findEntityTypeConfig(dataTypeNamespace, dataTypeName);\n const resultDataType = entityConfig?.mappedName ?? dataType;\n result = {\n dataType: resultDt,\n type: this.namingHelper.getModelName(resultDataType),\n qPath: \"QEntityPath\",\n qObject: this.namingHelper.getQName(resultDataType),\n qParam: \"QComplexParam\",\n };\n }\n }\n // OData built-in data types\n else if (dataType.startsWith(Digester.EDM_PREFIX)) {\n const { outputType, qPath, qParam, qCollection } = this.mapODataType(dataType);\n const { to, toModule: typeModule, converters } = this.dataModel.getConverter(dataType) || {};\n\n const type = !to ? outputType : to.startsWith(Digester.EDM_PREFIX) ? this.mapODataType(to).outputType : to;\n\n result = {\n dataType: DataTypes.PrimitiveType,\n type,\n typeModule,\n qPath,\n qParam,\n qObject: isCollection ? qCollection : undefined,\n converters,\n };\n } else {\n throw new Error(\n `Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`\n );\n }\n\n return {\n odataName: p.$.Name,\n name,\n odataType: p.$.Type,\n fqType: dataType,\n required: ifFalse(p.$.Nullable),\n isCollection: isCollection,\n managed: typeof entityPropConfig?.managed !== \"undefined\" ? entityPropConfig.managed : configProp?.managed,\n ...result,\n };\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTypeModel.js","sourceRoot":"","sources":["../../src/data-model/DataTypeModel.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,0BAAU,CAAA;IACV,0BAAU,CAAA;AACZ,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\n\nexport enum ODataVersion {\n V2 = \"2.0\",\n V4 = \"4.0\",\n}\n\nexport const enum DataTypes {\n PrimitiveType = \"PrimitiveType\",\n EnumType = \"EnumType\",\n ComplexType = \"ComplexType\",\n ModelType = \"ModelType\",\n}\n\nexport const enum OperationTypes {\n Function = \"Function\",\n Action = \"Action\",\n}\n\nexport interface PropertyModel {\n odataName: string;\n name: string;\n odataType: string;\n fqType: string;\n type: string;\n typeModule?: string;\n qObject?: string;\n qPath: string;\n qParam?: string;\n required: boolean;\n isCollection: boolean;\n dataType: DataTypes;\n converters?: Array<ValueConverterImport>;\n managed?: boolean;\n}\n\nexport interface ModelType extends ComplexType {\n idModelName: string;\n qIdFunctionName: string;\n generateId: boolean;\n keyNames: Array<string>;\n keys: Array<PropertyModel>;\n getKeyUnion(): string;\n}\n\nexport interface ComplexType {\n dataType: DataTypes;\n fqName: string;\n odataName: string;\n name: string;\n editableName: string;\n qName: string;\n props: Array<PropertyModel>;\n baseProps: Array<PropertyModel>;\n baseClasses: Array<string>;\n finalBaseClass: string | undefined;\n}\n\nexport interface EnumType {\n dataType: DataTypes;\n fqName: string;\n odataName: string;\n name: string;\n members: Array<string>;\n}\n\nexport interface OperationType {\n fqName: string;\n odataName: string;\n name: string;\n paramsModelName: string;\n qName: string;\n type: OperationTypes;\n parameters: Array<PropertyModel>;\n returnType?: ReturnTypeModel;\n usePost?: boolean;\n}\n\nexport interface ReturnTypeModel extends PropertyModel {}\n\nexport type EntityContainerModel = {\n entitySets: { [name: string]: EntitySetType };\n singletons: { [name: string]: SingletonType };\n functions: { [name: string]: FunctionImportType };\n actions: { [name: string]: ActionImportType };\n};\n\nexport interface SingletonType {\n fqName: string;\n odataName: string;\n name: string;\n entityType: ModelType;\n navPropBinding?: Array<NavPropBindingType>;\n}\n\nexport interface EntitySetType {\n fqName: string;\n odataName: string;\n name: string;\n entityType: ModelType;\n navPropBinding?: Array<NavPropBindingType>;\n}\n\nexport interface NavPropBindingType {\n path: string;\n target: string;\n}\n\nexport interface ActionImportType {\n fqName: string;\n odataName: string;\n name: string;\n operation: string;\n}\n\nexport interface FunctionImportType extends ActionImportType {\n entitySet: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DataTypeModel.js","sourceRoot":"","sources":["../../src/data-model/DataTypeModel.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,0BAAU,CAAA;IACV,0BAAU,CAAA;AACZ,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\n\nexport enum ODataVersion {\n V2 = \"2.0\",\n V4 = \"4.0\",\n}\n\nexport const enum DataTypes {\n PrimitiveType = \"PrimitiveType\",\n EnumType = \"EnumType\",\n ComplexType = \"ComplexType\",\n ModelType = \"ModelType\",\n}\n\nexport const enum OperationTypes {\n Function = \"Function\",\n Action = \"Action\",\n}\n\nexport interface PropertyModel {\n odataName: string;\n name: string;\n odataType: string;\n fqType: string;\n type: string;\n typeModule?: string;\n qObject?: string;\n qPath: string;\n qParam?: string;\n required: boolean;\n isCollection: boolean;\n dataType: DataTypes;\n converters?: Array<ValueConverterImport>;\n managed?: boolean;\n}\n\nexport interface ModelType extends ComplexType {\n idModelName: string;\n qIdFunctionName: string;\n generateId: boolean;\n keyNames: Array<string>;\n keys: Array<PropertyModel>;\n getKeyUnion(): string;\n}\n\nexport interface ComplexType {\n dataType: DataTypes;\n fqName: string;\n odataName: string;\n name: string;\n editableName: string;\n qName: string;\n props: Array<PropertyModel>;\n baseProps: Array<PropertyModel>;\n baseClasses: Array<string>;\n finalBaseClass: string | undefined;\n abstract: boolean;\n open: boolean;\n}\n\nexport interface EnumType {\n dataType: DataTypes;\n fqName: string;\n odataName: string;\n name: string;\n members: Array<string>;\n}\n\nexport interface OperationType {\n fqName: string;\n odataName: string;\n name: string;\n paramsModelName: string;\n qName: string;\n type: OperationTypes;\n parameters: Array<PropertyModel>;\n returnType?: ReturnTypeModel;\n usePost?: boolean;\n}\n\nexport interface ReturnTypeModel extends PropertyModel {}\n\nexport type EntityContainerModel = {\n entitySets: { [name: string]: EntitySetType };\n singletons: { [name: string]: SingletonType };\n functions: { [name: string]: FunctionImportType };\n actions: { [name: string]: ActionImportType };\n};\n\nexport interface SingletonType {\n fqName: string;\n odataName: string;\n name: string;\n entityType: ModelType;\n navPropBinding?: Array<NavPropBindingType>;\n}\n\nexport interface EntitySetType {\n fqName: string;\n odataName: string;\n name: string;\n entityType: ModelType;\n navPropBinding?: Array<NavPropBindingType>;\n}\n\nexport interface NavPropBindingType {\n path: string;\n target: string;\n}\n\nexport interface ActionImportType {\n fqName: string;\n odataName: string;\n name: string;\n operation: string;\n}\n\nexport interface FunctionImportType extends ActionImportType {\n entitySet: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ODataEdmxModelBase.js","sourceRoot":"","sources":["../../../src/data-model/edmx/ODataEdmxModelBase.ts"],"names":[],"mappings":"","sourcesContent":["export interface ODataEdmxModelBase<VersionedSchema> {\
|
|
1
|
+
{"version":3,"file":"ODataEdmxModelBase.js","sourceRoot":"","sources":["../../../src/data-model/edmx/ODataEdmxModelBase.ts"],"names":[],"mappings":"","sourcesContent":["export interface ODataEdmxModelBase<VersionedSchema> {\n \"edmx:Edmx\": {\n $: {\n Version: string;\n \"xmlns:edmx\": string;\n };\n // \"edmx:Reference\": Array<any>;\n \"edmx:DataServices\": Array<DataService<VersionedSchema>>;\n };\n}\n\nexport interface DataService<VersionedSchema> {\n Schema: Array<VersionedSchema>;\n}\n\nexport interface Schema<ET extends EntityType, CT extends ComplexType> {\n $: {\n Namespace: string;\n xmlns: string;\n Alias?: string;\n };\n EntityType?: Array<ET>;\n ComplexType?: Array<CT>;\n EnumType?: Array<EnumType>;\n EntityContainer?: Array<any>;\n TypeDefinition?: Array<TypeDefinition>;\n}\n\nexport interface EntityContainer<ES = EntitySet> {\n $: {\n Name: string;\n };\n EntitySet?: Array<ES>;\n}\n\nexport interface EntitySet {\n $: {\n Name: string;\n EntityType: string;\n };\n}\n\nexport interface EntityType {\n $: {\n Name: string;\n BaseType?: string;\n Abstract?: \"true\" | \"false\";\n OpenType?: \"true\" | \"false\";\n };\n Key: Array<PropertyRef>;\n Property: Array<Property>;\n}\n\nexport interface ComplexType extends Omit<EntityType, \"Key\"> {}\n\nexport interface PropertyRef {\n PropertyRef: Array<{ $: { Name: string } }>;\n}\n\nexport interface Property {\n $: {\n Name: string;\n Type: string;\n Nullable?: \"true\" | \"false\";\n MaxLength?: number;\n Precision?: number;\n Scale?: number;\n };\n}\n\nexport interface EnumType {\n $: {\n Name: string;\n };\n Member: Array<Member>;\n}\n\nexport interface Member {\n $: {\n Name: string;\n Value: number;\n };\n}\n\nexport interface Parameter extends Property {\n Unicode?: boolean;\n}\n\nexport interface ReturnType {\n $: {\n Type: string;\n };\n}\n\nexport interface TypeDefinition {\n $: {\n Name: string;\n UnderlyingType: string;\n MaxLength?: number;\n Precision?: number;\n Scale?: number;\n };\n}\n"]}
|
|
@@ -37,10 +37,10 @@ class ModelGenerator {
|
|
|
37
37
|
generateModels() {
|
|
38
38
|
this.dataModel.getEntityTypes().forEach((model) => {
|
|
39
39
|
this.generateModel(model);
|
|
40
|
-
if (!this.options.skipIdModels) {
|
|
40
|
+
if (!this.options.skipIdModels && model.generateId) {
|
|
41
41
|
this.generateIdModel(model);
|
|
42
42
|
}
|
|
43
|
-
if (!this.options.skipEditableModels) {
|
|
43
|
+
if (!this.options.skipEditableModels && !model.abstract) {
|
|
44
44
|
this.generateEditableModel(model);
|
|
45
45
|
}
|
|
46
46
|
if (!this.options.skipOperations) {
|
|
@@ -49,7 +49,7 @@ class ModelGenerator {
|
|
|
49
49
|
});
|
|
50
50
|
this.dataModel.getComplexTypes().forEach((model) => {
|
|
51
51
|
this.generateModel(model);
|
|
52
|
-
if (!this.options.skipEditableModels) {
|
|
52
|
+
if (!this.options.skipEditableModels && !model.abstract) {
|
|
53
53
|
this.generateEditableModel(model);
|
|
54
54
|
}
|
|
55
55
|
});
|
|
@@ -124,9 +124,6 @@ class ModelGenerator {
|
|
|
124
124
|
return prop.type + (prop.required ? "" : " | null") + suffix;
|
|
125
125
|
}
|
|
126
126
|
generateIdModel(model) {
|
|
127
|
-
if (!model.generateId) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
127
|
const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : "";
|
|
131
128
|
const keyTypes = model.keys.map((keyProp) => `${keyProp.name}: ${this.getPropType(keyProp)}`).join(",");
|
|
132
129
|
const type = `${singleType}{${keyTypes}}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";;;AACA,uCAAmF;AAMnF,uDAAoD;AAE7C,MAAM,cAAc,GAAiC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACpH,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,cAAc;IAGlB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAe;QACtB,YAAO,GAAP,OAAO,CAA0B;QACjC,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEG,QAAQ;QACb,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC;QAE7E,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;YAChC,IAAI,CAAC,8BAA8B,EAAE,CAAC;SACvC;IACH,CAAC;IAEO,aAAa;QACnB,IAAI,CAAC,SAAS,CAAC,QAAQ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C,SAAS,EAAE,EAAE;YAC9D,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,4BAA4B,CAAC,UAAkB;QACrD;YACE,GAAG,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,UAAU,CAAC;YACrD,GAAG,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,UAAU,CAAC;SACrD,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YACtB,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,uBAAuB,CAAC,SAAwB;QACtD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE;YAChC,OAAO;SACR;QACD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;YAC3B,IAAI,EAAE,SAAS,CAAC,eAAe;YAC/B,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACzC,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;oBACzB,gBAAgB,EAAE,CAAC,CAAC,CAAC,QAAQ;iBAC9B,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\nimport { JSDocStructure, OptionalKind, SourceFile, StructureKind } from \"ts-morph\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport { ComplexType, DataTypes, ModelType, OperationType, PropertyModel } from \"../data-model/DataTypeModel\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\nimport { ImportContainer } from \"./ImportContainer\";\n\nexport const generateModels: EntityBasedGeneratorFunction = (dataModel, sourceFile, version, options, namingHelper) => {\n const generator = new ModelGenerator(dataModel, sourceFile, version, options, namingHelper);\n return generator.generate();\n};\n\nconst DEFERRED_CONTENT = \"DeferredContent\";\n\nclass ModelGenerator {\n private importContainer!: ImportContainer;\n\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 this.importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n this.generateEnums();\n this.generateModels();\n if (!this.options.skipOperations) {\n this.generateUnboundOperationParams();\n }\n }\n\n private generateEnums() {\n this.dataModel.getEnums().forEach((et) => {\n this.sourceFile.addEnum({\n name: et.name,\n isExported: true,\n members: et.members.map((mem) => ({ name: mem, initializer: `\"${mem}\"` })),\n });\n });\n }\n\n private generateModels() {\n this.dataModel.getEntityTypes().forEach((model) => {\n this.generateModel(model);\n if (!this.options.skipIdModels) {\n this.generateIdModel(model);\n }\n if (!this.options.skipEditableModels) {\n this.generateEditableModel(model);\n }\n if (!this.options.skipOperations) {\n this.generateBoundOperationParams(model.fqName);\n }\n });\n this.dataModel.getComplexTypes().forEach((model) => {\n this.generateModel(model);\n if (!this.options.skipEditableModels) {\n this.generateEditableModel(model);\n }\n });\n\n this.sourceFile.addImportDeclarations(this.importContainer.getImportDeclarations());\n }\n\n private generateModel(model: ComplexType | ModelType) {\n this.sourceFile.addInterface({\n name: model.name,\n isExported: true,\n properties: model.props.map((p) => {\n const isEntity = p.dataType == DataTypes.ModelType;\n return {\n name: p.name,\n type: this.getPropType(p),\n // props for entities or entity collections are not added in V4 if not explicitly expanded\n hasQuestionToken: this.dataModel.isV4() && isEntity,\n docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\n };\n }),\n extends: model.finalBaseClass ? [this.namingHelper.getModelName(model.finalBaseClass)] : undefined,\n });\n }\n\n private generatePropDoc(prop: PropertyModel, model: ComplexType | ModelType): OptionalKind<JSDocStructure> {\n const isKeyProp = (model as ModelType).keyNames?.includes(prop.odataName);\n const baseAttribs: Array<string> = [];\n if (isKeyProp) {\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\n }\n if (prop.managed) {\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\n }\n if (prop.converters?.length) {\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\n }\n\n const attributeTable: Array<[string, string]> = [\n [\"Name\", prop.odataName],\n [\"Type\", prop.odataType],\n ];\n if (prop.required) {\n attributeTable.push([\"Nullable\", \"false\"]);\n }\n\n const description =\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\n \"OData Attributes:\\n\" +\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\n\n return { kind: StructureKind.JSDoc, description };\n }\n\n private getPropType(prop: PropertyModel): string {\n const isEntity = prop.dataType == DataTypes.ModelType;\n\n // V2 entity special: deferred content\n let suffix = \"\";\n if (isEntity && this.dataModel.isV2()) {\n this.importContainer.addFromCore(DEFERRED_CONTENT);\n suffix = ` | ${DEFERRED_CONTENT}`;\n }\n // custom types which require type imports => possible via converters\n else if (prop.typeModule) {\n this.importContainer.addCustomType(prop.typeModule, prop.type);\n }\n\n // Collections\n if (prop.isCollection) {\n const type = `Array<${prop.type}>`;\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\n return `{ results: ${type} }` + suffix;\n } else {\n return type + suffix;\n }\n }\n\n // primitive, enum & complex types\n return prop.type + (prop.required ? \"\" : \" | null\") + suffix;\n }\n\n private generateIdModel(model: ModelType) {\n if (!model.generateId) {\n return;\n }\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\n const keyTypes = model.keys.map((keyProp) => `${keyProp.name}: ${this.getPropType(keyProp)}`).join(\",\");\n const type = `${singleType}{${keyTypes}}`;\n\n this.sourceFile.addTypeAlias({\n name: model.idModelName,\n isExported: true,\n type,\n });\n }\n\n private generateEditableModel(model: ComplexType) {\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\n\n const requiredProps = allProps\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\n .map((p) => `\"${p.name}\"`)\n .join(\" | \");\n const optionalProps = allProps\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\n .map((p) => `\"${p.name}\"`)\n .join(\" | \");\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\n\n const extendsClause = [\n requiredProps ? `Pick<${model.name}, ${requiredProps}>` : null,\n optionalProps ? `Partial<Pick<${model.name}, ${optionalProps}>>` : null,\n ].filter((e): e is string => !!e);\n\n this.sourceFile.addInterface({\n name: model.editableName,\n isExported: true,\n extends: extendsClause,\n properties: !complexProps\n ? undefined\n : complexProps.map((p) => {\n return {\n name: p.name,\n type: this.getEditablePropType(p),\n // optional props don't need to be specified in editable model\n // also, entities would require deep insert func => we make it optional for now\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\n };\n }),\n });\n }\n\n private getEditablePropType(prop: PropertyModel): string {\n const type =\n prop.dataType === DataTypes.ModelType\n ? this.dataModel.getEntityType(prop.fqType)!.editableName\n : prop.dataType === DataTypes.ComplexType\n ? this.dataModel.getComplexType(prop.fqType)!.editableName\n : prop.type;\n\n // Collections\n if (prop.isCollection) {\n return `Array<${type}>`;\n }\n\n // primitive, enum & complex types\n return type + (prop.required ? \"\" : \" | null\");\n }\n\n private generateUnboundOperationParams() {\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\n this.generateOperationParams(operation);\n });\n }\n\n private generateBoundOperationParams(entityName: string) {\n [\n ...this.dataModel.getEntityTypeOperations(entityName),\n ...this.dataModel.getEntitySetOperations(entityName),\n ].forEach((operation) => {\n this.generateOperationParams(operation);\n });\n }\n\n private generateOperationParams(operation: OperationType) {\n if (!operation.parameters.length) {\n return;\n }\n this.sourceFile.addInterface({\n name: operation.paramsModelName,\n isExported: true,\n properties: operation.parameters.map((p) => {\n return {\n name: p.name,\n type: this.getPropType(p),\n hasQuestionToken: !p.required,\n };\n }),\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";;;AACA,uCAAmF;AAMnF,uDAAoD;AAE7C,MAAM,cAAc,GAAiC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACpH,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,cAAc;IAGlB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAe;QACtB,YAAO,GAAP,OAAO,CAA0B;QACjC,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEG,QAAQ;QACb,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC;QAE7E,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;YAChC,IAAI,CAAC,8BAA8B,EAAE,CAAC;SACvC;IACH,CAAC;IAEO,aAAa;QACnB,IAAI,CAAC,SAAS,CAAC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AAwB,EAAE,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YAC9D,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,4BAA4B,CAAC,UAAkB;QACrD;YACE,GAAG,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,UAAU,CAAC;YACrD,GAAG,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,UAAU,CAAC;SACrD,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YACtB,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,uBAAuB,CAAC,SAAwB;QACtD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE;YAChC,OAAO;SACR;QACD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;YAC3B,IAAI,EAAE,SAAS,CAAC,eAAe;YAC/B,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACzC,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;oBACzB,gBAAgB,EAAE,CAAC,CAAC,CAAC,QAAQ;iBAC9B,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\nimport { JSDocStructure, OptionalKind, SourceFile, StructureKind } from \"ts-morph\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport { ComplexType, DataTypes, ModelType, OperationType, PropertyModel } from \"../data-model/DataTypeModel\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\nimport { ImportContainer } from \"./ImportContainer\";\n\nexport const generateModels: EntityBasedGeneratorFunction = (dataModel, sourceFile, version, options, namingHelper) => {\n const generator = new ModelGenerator(dataModel, sourceFile, version, options, namingHelper);\n return generator.generate();\n};\n\nconst DEFERRED_CONTENT = \"DeferredContent\";\n\nclass ModelGenerator {\n private importContainer!: ImportContainer;\n\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 this.importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n this.generateEnums();\n this.generateModels();\n if (!this.options.skipOperations) {\n this.generateUnboundOperationParams();\n }\n }\n\n private generateEnums() {\n this.dataModel.getEnums().forEach((et) => {\n this.sourceFile.addEnum({\n name: et.name,\n isExported: true,\n members: et.members.map((mem) => ({ name: mem, initializer: `\"${mem}\"` })),\n });\n });\n }\n\n private generateModels() {\n this.dataModel.getEntityTypes().forEach((model) => {\n this.generateModel(model);\n if (!this.options.skipIdModels && model.generateId) {\n this.generateIdModel(model);\n }\n if (!this.options.skipEditableModels && !model.abstract) {\n this.generateEditableModel(model);\n }\n if (!this.options.skipOperations) {\n this.generateBoundOperationParams(model.fqName);\n }\n });\n this.dataModel.getComplexTypes().forEach((model) => {\n this.generateModel(model);\n if (!this.options.skipEditableModels && !model.abstract) {\n this.generateEditableModel(model);\n }\n });\n\n this.sourceFile.addImportDeclarations(this.importContainer.getImportDeclarations());\n }\n\n private generateModel(model: ComplexType | ModelType) {\n this.sourceFile.addInterface({\n name: model.name,\n isExported: true,\n properties: model.props.map((p) => {\n const isEntity = p.dataType == DataTypes.ModelType;\n return {\n name: p.name,\n type: this.getPropType(p),\n // props for entities or entity collections are not added in V4 if not explicitly expanded\n hasQuestionToken: this.dataModel.isV4() && isEntity,\n docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\n };\n }),\n extends: model.finalBaseClass ? [this.namingHelper.getModelName(model.finalBaseClass)] : undefined,\n });\n }\n\n private generatePropDoc(prop: PropertyModel, model: ComplexType | ModelType): OptionalKind<JSDocStructure> {\n const isKeyProp = (model as ModelType).keyNames?.includes(prop.odataName);\n const baseAttribs: Array<string> = [];\n if (isKeyProp) {\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\n }\n if (prop.managed) {\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\n }\n if (prop.converters?.length) {\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\n }\n\n const attributeTable: Array<[string, string]> = [\n [\"Name\", prop.odataName],\n [\"Type\", prop.odataType],\n ];\n if (prop.required) {\n attributeTable.push([\"Nullable\", \"false\"]);\n }\n\n const description =\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\n \"OData Attributes:\\n\" +\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\n\n return { kind: StructureKind.JSDoc, description };\n }\n\n private getPropType(prop: PropertyModel): string {\n const isEntity = prop.dataType == DataTypes.ModelType;\n\n // V2 entity special: deferred content\n let suffix = \"\";\n if (isEntity && this.dataModel.isV2()) {\n this.importContainer.addFromCore(DEFERRED_CONTENT);\n suffix = ` | ${DEFERRED_CONTENT}`;\n }\n // custom types which require type imports => possible via converters\n else if (prop.typeModule) {\n this.importContainer.addCustomType(prop.typeModule, prop.type);\n }\n\n // Collections\n if (prop.isCollection) {\n const type = `Array<${prop.type}>`;\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\n return `{ results: ${type} }` + suffix;\n } else {\n return type + suffix;\n }\n }\n\n // primitive, enum & complex types\n return prop.type + (prop.required ? \"\" : \" | null\") + suffix;\n }\n\n private generateIdModel(model: ModelType) {\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\n const keyTypes = model.keys.map((keyProp) => `${keyProp.name}: ${this.getPropType(keyProp)}`).join(\",\");\n const type = `${singleType}{${keyTypes}}`;\n\n this.sourceFile.addTypeAlias({\n name: model.idModelName,\n isExported: true,\n type,\n });\n }\n\n private generateEditableModel(model: ComplexType) {\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\n\n const requiredProps = allProps\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\n .map((p) => `\"${p.name}\"`)\n .join(\" | \");\n const optionalProps = allProps\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\n .map((p) => `\"${p.name}\"`)\n .join(\" | \");\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\n\n const extendsClause = [\n requiredProps ? `Pick<${model.name}, ${requiredProps}>` : null,\n optionalProps ? `Partial<Pick<${model.name}, ${optionalProps}>>` : null,\n ].filter((e): e is string => !!e);\n\n this.sourceFile.addInterface({\n name: model.editableName,\n isExported: true,\n extends: extendsClause,\n properties: !complexProps\n ? undefined\n : complexProps.map((p) => {\n return {\n name: p.name,\n type: this.getEditablePropType(p),\n // optional props don't need to be specified in editable model\n // also, entities would require deep insert func => we make it optional for now\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\n };\n }),\n });\n }\n\n private getEditablePropType(prop: PropertyModel): string {\n const type =\n prop.dataType === DataTypes.ModelType\n ? this.dataModel.getEntityType(prop.fqType)!.editableName\n : prop.dataType === DataTypes.ComplexType\n ? this.dataModel.getComplexType(prop.fqType)!.editableName\n : prop.type;\n\n // Collections\n if (prop.isCollection) {\n return `Array<${type}>`;\n }\n\n // primitive, enum & complex types\n return type + (prop.required ? \"\" : \" | null\");\n }\n\n private generateUnboundOperationParams() {\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\n this.generateOperationParams(operation);\n });\n }\n\n private generateBoundOperationParams(entityName: string) {\n [\n ...this.dataModel.getEntityTypeOperations(entityName),\n ...this.dataModel.getEntitySetOperations(entityName),\n ].forEach((operation) => {\n this.generateOperationParams(operation);\n });\n }\n\n private generateOperationParams(operation: OperationType) {\n if (!operation.parameters.length) {\n return;\n }\n this.sourceFile.addInterface({\n name: operation.paramsModelName,\n isExported: true,\n properties: operation.parameters.map((p) => {\n return {\n name: p.name,\n type: this.getPropType(p),\n hasQuestionToken: !p.required,\n };\n }),\n });\n }\n}\n"]}
|
|
@@ -29,7 +29,7 @@ class QueryObjectGenerator {
|
|
|
29
29
|
generateModels(importContainer) {
|
|
30
30
|
this.dataModel.getEntityTypes().forEach((model) => {
|
|
31
31
|
this.generateModel(model, importContainer);
|
|
32
|
-
if (!this.options.skipIdModels) {
|
|
32
|
+
if (!this.options.skipIdModels && model.generateId) {
|
|
33
33
|
this.generateIdFunction(model, importContainer);
|
|
34
34
|
}
|
|
35
35
|
if (!this.options.skipOperations) {
|
|
@@ -57,18 +57,21 @@ class QueryObjectGenerator {
|
|
|
57
57
|
name: model.qName,
|
|
58
58
|
isExported: true,
|
|
59
59
|
extends: extendsClause,
|
|
60
|
+
isAbstract: model.abstract,
|
|
60
61
|
properties: this.generateQueryObjectProps(model.props, importContainer),
|
|
61
62
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
}
|
|
72
75
|
}
|
|
73
76
|
generateQueryObjectProps(props, importContainer) {
|
|
74
77
|
return props.map((prop) => {
|
|
@@ -125,9 +128,6 @@ class QueryObjectGenerator {
|
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
130
|
generateIdFunction(model, importContainer) {
|
|
128
|
-
if (!model.generateId) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
131
|
const qFunc = "QId";
|
|
132
132
|
importContainer.addFromQObject(qFunc);
|
|
133
133
|
importContainer.addGeneratedModel(model.idModelName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryObjectGenerator.js","sourceRoot":"","sources":["../../src/generator/QueryObjectGenerator.ts"],"names":[],"mappings":";;;AACA,qDAAqD;AACrD,uCAAkH;AAClH,sDAA2D;AAa3D,uDAAoD;AAE7C,MAAM,oBAAoB,GAAiC,CAChE,SAAS,EACT,UAAU,EACV,OAAO,EACP,OAAO,EACP,YAAY,EACZ,EAAE;IACF,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAClG,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AATW,QAAA,oBAAoB,wBAS/B;AAEF,MAAM,oBAAoB;IACxB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAe;QACtB,YAAO,GAAP,OAAO,CAA0B;QACjC,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEG,QAAQ;QACb,MAAM,eAAe,GAAG,IAAI,iCAAe,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC;QAE9E,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;YAChC,IAAI,CAAC,yBAAyB,CAAC,eAAe,CAAC,CAAC;SACjD;QAED,IAAI,CAAC,UAAU,C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CAAC,CAAC,IAAI,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GACrG,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAChC,GAAG;qBACJ;iBACF;aACF;YACD,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,WAAW;oBACjB,UAAU,EAAE,CAAC,oBAAoB,CAAC;iBACnC;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\";\r\nimport { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { OptionalKind, PropertyDeclarationStructure, Scope, SourceFile, VariableDeclarationKind } from \"ts-morph\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport {\r\n ComplexType,\r\n DataTypes,\r\n ModelType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n} from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nexport const generateQueryObjects: EntityBasedGeneratorFunction = (\r\n dataModel,\r\n sourceFile,\r\n version,\r\n options,\r\n namingHelper\r\n) => {\r\n const generator = new QueryObjectGenerator(dataModel, sourceFile, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nclass QueryObjectGenerator {\r\n constructor(\r\n private dataModel: DataModel,\r\n private sourceFile: SourceFile,\r\n private version: ODataVersions,\r\n private options: GeneratorFunctionOptions,\r\n private namingHelper: NamingHelper\r\n ) {}\r\n\r\n public generate(): void {\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n this.generateModels(importContainer);\r\n if (!this.options.skipOperations) {\r\n this.generateUnboundOperations(importContainer);\r\n }\r\n\r\n this.sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\r\n }\r\n\r\n private generateModels(importContainer: ImportContainer) {\r\n this.dataModel.getEntityTypes().forEach((model) => {\r\n this.generateModel(model, importContainer);\r\n if (!this.options.skipIdModels) {\r\n this.generateIdFunction(model, importContainer);\r\n }\r\n if (!this.options.skipOperations) {\r\n this.generateBoundOperations(model.fqName, importContainer);\r\n }\r\n });\r\n this.dataModel.getComplexTypes().forEach((model) => {\r\n this.generateModel(model, importContainer);\r\n });\r\n\r\n if (this.dataModel.getEntityTypes().length || this.dataModel.getComplexTypes().length) {\r\n importContainer.addFromQObject(\"QueryObject\");\r\n }\r\n }\r\n\r\n private generateModel(model: ComplexType, importContainer: ImportContainer) {\r\n let extendsClause = \"QueryObject\";\r\n if (model.baseClasses.length) {\r\n const baseClass = model.baseClasses[0];\r\n const baseModel = this.dataModel.getEntityType(baseClass) || this.dataModel.getComplexType(baseClass);\r\n if (!baseModel) {\r\n throw new Error(`Entity or complex type \"${baseClass}\" from baseClass attribute not found!`);\r\n }\r\n\r\n extendsClause = baseModel.qName;\r\n }\r\n\r\n this.sourceFile.addClass({\r\n name: model.qName,\r\n isExported: true,\r\n extends: extendsClause,\r\n properties: this.generateQueryObjectProps(model.props, importContainer),\r\n });\r\n\r\n this.sourceFile.addVariableStatement({\r\n declarationKind: VariableDeclarationKind.Const,\r\n isExported: true,\r\n declarations: [\r\n {\r\n name: firstCharLowerCase(model.qName),\r\n initializer: `new ${model.qName}()`,\r\n },\r\n ],\r\n });\r\n }\r\n\r\n private generateQueryObjectProps(\r\n props: Array<PropertyModel>,\r\n importContainer: ImportContainer\r\n ): Array<OptionalKind<PropertyDeclarationStructure>> {\r\n return props.map((prop) => {\r\n const { odataName } = prop;\r\n const name = this.namingHelper.getQPropName(prop.name);\r\n const isModelType = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\r\n let qPathInit: string;\r\n\r\n // factor in collections\r\n if (prop.isCollection) {\r\n const cType = `Q${isModelType ? \"Entity\" : \"\"}CollectionPath`;\r\n const qObject = prop.qObject;\r\n\r\n if (!qObject) {\r\n throw new Error(\"QObject for collection is missing!\");\r\n }\r\n\r\n qPathInit = `new ${cType}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\r\n\r\n importContainer.addFromQObject(cType);\r\n if (!isModelType) {\r\n importContainer.addFromQObject(qObject);\r\n }\r\n } else {\r\n if (isModelType) {\r\n qPathInit = `new ${prop.qPath}(this.withPrefix(\"${odataName}\"), () => ${prop.qObject!})`;\r\n } else {\r\n let converterStmt = this.generateConverterStmt(prop.converters, importContainer);\r\n qPathInit = `new ${prop.qPath}(this.withPrefix(\"${odataName}\")${converterStmt ? `, ${converterStmt}` : \"\"})`;\r\n }\r\n // add import for data type\r\n importContainer.addFromQObject(prop.qPath);\r\n }\r\n\r\n return {\r\n name,\r\n scope: Scope.Public,\r\n isReadonly: true,\r\n initializer: qPathInit,\r\n } as OptionalKind<PropertyDeclarationStructure>;\r\n });\r\n }\r\n\r\n private generateConverterStmt(converters: Array<ValueConverterImport> | undefined, importContainer: ImportContainer) {\r\n if (!converters?.length) {\r\n return;\r\n }\r\n converters.forEach((converter) => {\r\n importContainer.addCustomType(converter.package, converter.converterId);\r\n });\r\n\r\n if (converters.length === 1) {\r\n return converters[0].converterId;\r\n } else {\r\n importContainer.addCustomType(\"@odata2ts/converter-runtime\", \"createChain\");\r\n\r\n const [first, second, ...moreConverters] = converters;\r\n return moreConverters.reduce(\r\n (stmt, conv) => `${stmt}.chain(${conv.converterId})`,\r\n `createChain(${first.converterId}, ${second.converterId})`\r\n );\r\n }\r\n }\r\n\r\n private generateIdFunction(model: ModelType, importContainer: ImportContainer) {\r\n if (!model.generateId) {\r\n return;\r\n }\r\n\r\n const qFunc = \"QId\";\r\n importContainer.addFromQObject(qFunc);\r\n importContainer.addGeneratedModel(model.idModelName);\r\n\r\n this.sourceFile.addClass({\r\n name: model.qIdFunctionName,\r\n isExported: true,\r\n extends: `${qFunc}<${model.idModelName}>`,\r\n properties: [\r\n {\r\n name: \"params\",\r\n scope: Scope.Private,\r\n isReadonly: true,\r\n initializer: this.getParamInitString(model.keys, importContainer),\r\n },\r\n ],\r\n methods: [\r\n {\r\n name: \"getParams\",\r\n statements: [\"return this.params\"],\r\n },\r\n ],\r\n });\r\n }\r\n\r\n private getParamInitString(props: Array<PropertyModel>, importContainer: ImportContainer) {\r\n return `[${props\r\n .map((prop) => {\r\n const isComplexParam = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\r\n if (prop.qParam) {\r\n importContainer.addFromQObject(prop.qParam);\r\n }\r\n const isMappedNameNecessary = prop.odataName !== prop.name;\r\n const mappedName = isMappedNameNecessary ? `\"${prop.name}\"` : prop.converters?.length ? \"undefined\" : undefined;\r\n const converterStmt = this.generateConverterStmt(prop.converters, importContainer);\r\n const mappedNameParam = mappedName ? `, ${mappedName}` : \"\";\r\n const complexQParam = isComplexParam ? `, new ${prop.qObject}()` : \"\";\r\n const converterParam = converterStmt ? `, ${converterStmt}` : \"\";\r\n return `new ${prop.qParam}(\"${prop.odataName}\"${complexQParam}${mappedNameParam}${converterParam})`;\r\n })\r\n .join(\",\")}]`;\r\n }\r\n\r\n private generateUnboundOperations(importContainer: ImportContainer) {\r\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\r\n this.generateOperation(operation, importContainer);\r\n });\r\n }\r\n\r\n private generateBoundOperations(fqEntityName: string, importContainer: ImportContainer) {\r\n [\r\n ...this.dataModel.getEntityTypeOperations(fqEntityName),\r\n ...this.dataModel.getEntitySetOperations(fqEntityName),\r\n ].forEach((operation) => {\r\n this.generateOperation(operation, importContainer);\r\n });\r\n }\r\n\r\n private generateOperation(operation: OperationType, importContainer: ImportContainer) {\r\n const isV2 = this.version === ODataVersions.V2;\r\n const qOperation = operation.type === OperationTypes.Action ? \"QAction\" : \"QFunction\";\r\n const returnType = operation.returnType;\r\n let returnTypeOpStmt: string = \"\";\r\n const hasParams = operation.parameters.length > 0;\r\n importContainer.addFromQObject(qOperation);\r\n if (hasParams) {\r\n importContainer.addGeneratedModel(operation.paramsModelName);\r\n }\r\n if (returnType) {\r\n if (returnType.dataType === DataTypes.ComplexType || returnType.dataType === DataTypes.ModelType) {\r\n if (returnType.qObject) {\r\n importContainer.addFromQObject(\"OperationReturnType\", \"ReturnTypes\", \"QComplexParam\");\r\n returnTypeOpStmt = `new OperationReturnType(ReturnTypes.COMPLEX${\r\n returnType.isCollection ? \"_COLLECTION\" : \"\"\r\n }, new QComplexParam(\"NONE\", new ${returnType.qObject}))`;\r\n }\r\n }\r\n // currently, it only makes sense to add the OperationReturnType if a converter is present\r\n else if (returnType.converters && returnType.qParam) {\r\n importContainer.addFromQObject(\"OperationReturnType\", \"ReturnTypes\", returnType.qParam);\r\n const rtKind = \"ReturnTypes.VALUE\" + (returnType.isCollection ? \"_COLLECTION\" : \"\");\r\n const converterParam = returnType.converters\r\n ? \", \" + this.generateConverterStmt(returnType.converters, importContainer)\r\n : \"\";\r\n returnTypeOpStmt = `new OperationReturnType(${rtKind}, new ${returnType.qParam}(\"NONE\", undefined${converterParam}))`;\r\n }\r\n }\r\n\r\n this.sourceFile.addClass({\r\n name: operation.qName,\r\n isExported: true,\r\n extends: qOperation + (hasParams ? `<${operation.paramsModelName}>` : \"\"),\r\n properties: [\r\n {\r\n name: \"params\",\r\n scope: Scope.Private,\r\n isReadonly: true,\r\n type: operation.parameters?.length ? undefined : \"[]\",\r\n initializer: this.getParamInitString(operation.parameters, importContainer),\r\n },\r\n ],\r\n ctors: [\r\n {\r\n statements: [\r\n `super(\"${operation.odataName}\"${returnTypeOpStmt ? \", \" + returnTypeOpStmt : isV2 ? \", undefined\" : \"\"}${\r\n isV2 ? \", { v2Mode: true }\" : \"\"\r\n })`,\r\n ],\r\n },\r\n ],\r\n methods: [\r\n {\r\n name: \"getParams\",\r\n statements: [\"return this.params\"],\r\n },\r\n // functions without params: add an overriding buildUrl() to not force users to have to pass undefined as param\r\n ...(operation.type === OperationTypes.Function && !hasParams\r\n ? [\r\n {\r\n name: \"buildUrl\",\r\n statements: [\"return super.buildUrl(undefined)\"],\r\n },\r\n ]\r\n : []),\r\n ],\r\n });\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"QueryObjectGenerator.js","sourceRoot":"","sources":["../../src/generator/QueryObjectGenerator.ts"],"names":[],"mappings":";;;AACA,qDAAqD;AACrD,uCAAkH;AAClH,sDAA2D;AAa3D,uDAAoD;AAE7C,MAAM,oBAAoB,GAAiC,CAChE,SAAS,EACT,UAAU,EACV,OAAO,EACP,OAAO,EACP,YAAY,EACZ,EAAE;IACF,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAClG,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AATW,QAAA,oBAAoB,wBAS/B;AAEF,MAAM,oBAAoB;IACxB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAe;QACtB,YAAO,GAAP,OAAO,CAA0B;QACjC,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEG,QAAQ;QACb,MAAM,eAAe,GAAG,IAAI,iCAAe,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC;QAE9E,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;QACrC,IAAI,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,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,UAAU,EAAE,eAAe,CAAC;iBAC5E;aACF;YACD,KAAK,EAAE;gBACL;oBACE,UAAU,EAAE;wBACV,UAAU,SAAS,CAAC,SAAS,IAAI,gBAAgB,CAAC,CAAC,CAAC,IAAI,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GACrG,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAChC,GAAG;qBACJ;iBACF;aACF;YACD,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,WAAW;oBACjB,UAAU,EAAE,CAAC,oBAAoB,CAAC;iBACnC;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"]}
|
|
@@ -169,36 +169,34 @@ class ServiceGenerator {
|
|
|
169
169
|
return this.version === odata_core_1.ODataVersions.V2 ? "V2" : "V4";
|
|
170
170
|
}
|
|
171
171
|
generateEntityTypeService(model, serviceName, serviceFile, importContainer) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
methods,
|
|
201
|
-
});
|
|
172
|
+
const entityServiceType = "EntityTypeService" + this.getVersionSuffix();
|
|
173
|
+
const editableModelName = model.editableName;
|
|
174
|
+
const qObjectName = (0, processors_1.firstCharLowerCase)(model.qName);
|
|
175
|
+
const operations = this.dataModel.getEntityTypeOperations(model.fqName);
|
|
176
|
+
const props = [...model.baseProps, ...model.props];
|
|
177
|
+
importContainer.addFromService(entityServiceType);
|
|
178
|
+
importContainer.addFromClientApi("ODataHttpClient");
|
|
179
|
+
importContainer.addGeneratedModel(model.name, editableModelName);
|
|
180
|
+
importContainer.addGeneratedQObject(model.qName, qObjectName);
|
|
181
|
+
const { properties, methods } = (0, deepmerge_1.default)(this.generateServiceProperties(serviceName, props, importContainer), this.generateServiceOperations(operations, importContainer));
|
|
182
|
+
// generate EntityTypeService
|
|
183
|
+
serviceFile.addClass({
|
|
184
|
+
isExported: true,
|
|
185
|
+
name: serviceName,
|
|
186
|
+
typeParameters: ["ClientType extends ODataHttpClient"],
|
|
187
|
+
extends: entityServiceType + `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}>`,
|
|
188
|
+
ctors: [
|
|
189
|
+
{
|
|
190
|
+
parameters: [
|
|
191
|
+
{ name: "client", type: "ClientType" },
|
|
192
|
+
{ name: "basePath", type: "string" },
|
|
193
|
+
{ name: "name", type: "string" },
|
|
194
|
+
],
|
|
195
|
+
statements: [`super(client, basePath, name, ${qObjectName}${this.isV4BigNumber() ? ", true" : ""});`],
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
properties,
|
|
199
|
+
methods,
|
|
202
200
|
});
|
|
203
201
|
}
|
|
204
202
|
getPrimitiveServiceType() {
|
|
@@ -362,53 +360,55 @@ class ServiceGenerator {
|
|
|
362
360
|
};
|
|
363
361
|
}
|
|
364
362
|
generateEntityCollectionService(model, serviceFile, importContainer) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
methods,
|
|
394
|
-
});
|
|
363
|
+
const entitySetServiceType = "EntitySetService" + this.getVersionSuffix();
|
|
364
|
+
const editableModelName = model.editableName;
|
|
365
|
+
const qObjectName = (0, processors_1.firstCharLowerCase)(model.qName);
|
|
366
|
+
importContainer.addFromService(entitySetServiceType);
|
|
367
|
+
importContainer.addGeneratedModel(model.idModelName);
|
|
368
|
+
importContainer.addGeneratedQObject(model.qIdFunctionName);
|
|
369
|
+
const collectionOperations = this.dataModel.getEntitySetOperations(model.fqName);
|
|
370
|
+
const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);
|
|
371
|
+
serviceFile.addClass({
|
|
372
|
+
isExported: true,
|
|
373
|
+
name: this.namingHelper.getCollectionServiceName(model.name),
|
|
374
|
+
typeParameters: ["ClientType extends ODataHttpClient"],
|
|
375
|
+
extends: entitySetServiceType +
|
|
376
|
+
`<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}>`,
|
|
377
|
+
ctors: [
|
|
378
|
+
{
|
|
379
|
+
parameters: [
|
|
380
|
+
{ name: "client", type: "ClientType" },
|
|
381
|
+
{ name: "basePath", type: "string" },
|
|
382
|
+
{ name: "name", type: "string" },
|
|
383
|
+
],
|
|
384
|
+
statements: [
|
|
385
|
+
`super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name)${this.isV4BigNumber() ? ", true" : ""});`,
|
|
386
|
+
],
|
|
387
|
+
},
|
|
388
|
+
],
|
|
389
|
+
properties,
|
|
390
|
+
methods,
|
|
395
391
|
});
|
|
396
392
|
}
|
|
397
393
|
generateModelServices(serviceFile, importContainer) {
|
|
398
394
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
399
395
|
// build service file for each entity, consisting of EntityTypeService & EntityCollectionService
|
|
400
|
-
|
|
396
|
+
const entities = this.dataModel.getEntityTypes().filter((et) => !et.abstract);
|
|
397
|
+
for (const model of entities) {
|
|
401
398
|
const serviceName = this.namingHelper.getServiceName(model.name);
|
|
402
399
|
// entity type service
|
|
403
|
-
|
|
404
|
-
// entity collection service
|
|
405
|
-
|
|
400
|
+
this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);
|
|
401
|
+
// entity collection service if this entity specified keys at all
|
|
402
|
+
if (model.keyNames.length) {
|
|
403
|
+
this.generateEntityCollectionService(model, serviceFile, importContainer);
|
|
404
|
+
}
|
|
406
405
|
}
|
|
407
406
|
// build service file for complex types
|
|
408
|
-
|
|
407
|
+
const complexTypes = this.dataModel.getComplexTypes().filter((ct) => !ct.abstract);
|
|
408
|
+
for (const model of complexTypes) {
|
|
409
409
|
const serviceName = this.namingHelper.getServiceName(model.name);
|
|
410
410
|
// entity type service
|
|
411
|
-
|
|
411
|
+
this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);
|
|
412
412
|
}
|
|
413
413
|
});
|
|
414
414
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceGenerator.js","sourceRoot":"","sources":["../../src/generator/ServiceGenerator.ts"],"names":[],"mappings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OAAO,aAAa,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK;gBACvF,GAAG,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,QAAQ,WAClD,CAAC,MAAM;oBACL,CAAC,CAAC,oBAAoB;wBACpB,aAAa,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,4BAA4B,CAAC,CAAC,CAAC,IAAI,KACpE,kBAAkB,CAAC,IACrB,wBAAwB;oBAC1B,CAAC,CAAC,SAAS,CAAC,OAAO;wBACnB,CAAC,CAAC,sFAAsF;4BACtF,wBAAwB,kBAAkB,CAAC,IAAI,wBAAwB;wBACzE,CAAC,CAAC,sBAAsB;4BACtB,YAAY,kBAAkB,CAAC,IAAI,wBACzC,GAAG;gBACH,UAAU,CAAC,CAAC,CAAC,UAAU,OAAO,6BAA6B,CAAC,CAAC,CAAC,EAAE;aACjE;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport deepmerge from \"deepmerge\";\r\nimport {\r\n ClassDeclarationStructure,\r\n MethodDeclarationStructure,\r\n OptionalKind,\r\n PropertyDeclarationStructure,\r\n Scope,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport { upperCaseFirst } from \"upper-case-first\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntityContainerModel,\r\n FunctionImportType,\r\n ModelType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { ConfigFileOptions } from \"../OptionModel\";\r\nimport { ProjectManager } from \"../project/ProjectManager\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nconst ROOT_SERVICE = \"ODataService\";\r\n\r\nconst RESPONSE_TYPES = {\r\n collection: \"ODataCollectionResponse\",\r\n model: \"ODataModelResponse\",\r\n value: \"ODataValueResponse\",\r\n};\r\n\r\nexport interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, \"properties\" | \"methods\">> {}\r\n\r\nexport interface ServiceGeneratorOptions\r\n extends Pick<ConfigFileOptions, \"enablePrimitivePropertyServices\" | \"v4BigNumberAsString\"> {}\r\n\r\nexport async function generateServices(\r\n dataModel: DataModel,\r\n project: ProjectManager,\r\n version: ODataVersions,\r\n namingHelper: NamingHelper,\r\n options?: ServiceGeneratorOptions\r\n) {\r\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper, options);\r\n return generator.generate();\r\n}\r\n\r\nclass ServiceGenerator {\r\n constructor(\r\n private dataModel: DataModel,\r\n private project: ProjectManager,\r\n private version: ODataVersions,\r\n private namingHelper: NamingHelper,\r\n private options: ServiceGeneratorOptions = {}\r\n ) {}\r\n\r\n private isV4BigNumber() {\r\n return this.options.v4BigNumberAsString && this.version === ODataVersions.V4;\r\n }\r\n\r\n public async generate(): Promise<void> {\r\n const sourceFile = await this.project.createMainServiceFile();\r\n const serviceName = this.namingHelper.getMainServiceName();\r\n const container = this.dataModel.getEntityContainer();\r\n const unboundOperations = [...Object.values(container.functions), ...Object.values(container.actions)];\r\n\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addFromService(ROOT_SERVICE);\r\n\r\n const { properties, methods }: PropsAndOps = deepmerge(\r\n this.generateMainServiceProperties(container, importContainer),\r\n this.generateMainServiceOperations(unboundOperations, importContainer)\r\n );\r\n\r\n sourceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends: `${ROOT_SERVICE}<ClientType>`,\r\n ctors: this.isV4BigNumber()\r\n ? [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n ],\r\n statements: [`super(client, basePath, true);`],\r\n },\r\n ]\r\n : [],\r\n properties,\r\n methods,\r\n });\r\n\r\n await this.generateModelServices(sourceFile, importContainer);\r\n\r\n sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\r\n }\r\n\r\n private generateMainServiceProperties(\r\n container: EntityContainerModel,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n Object.values(container.entitySets).forEach(({ name, odataName, entityType }) => {\r\n result.methods.push(this.generateRelatedServiceGetter(name, odataName, entityType, importContainer));\r\n });\r\n\r\n Object.values(container.singletons).forEach((singleton) => {\r\n result.properties.push(this.generateSingletonProp(singleton, importContainer));\r\n result.methods.push(this.generateSingletonGetter(singleton));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateMainServiceOperations(\r\n ops: Array<FunctionImportType | ActionImportType>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n ops.forEach(({ operation, name }) => {\r\n const op = this.dataModel.getUnboundOperationType(operation);\r\n if (!op) {\r\n throw new Error(`Operation \"${operation}\" not found!`);\r\n }\r\n\r\n result.properties.push(this.generateQOperationProp(op));\r\n result.methods.push(this.generateMethod(name, op, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateRelatedServiceGetter(\r\n propName: string,\r\n odataPropName: string,\r\n entityType: ModelType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const idName = entityType.idModelName;\r\n const idFunctionName = entityType.qIdFunctionName;\r\n const serviceName = this.namingHelper.getServiceName(entityType.name);\r\n const collectionName = this.namingHelper.getCollectionServiceName(entityType.name);\r\n\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addGeneratedModel(idName);\r\n importContainer.addGeneratedQObject(idFunctionName);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(propName),\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: `${idName} | undefined`,\r\n hasQuestionToken: true,\r\n },\r\n ],\r\n overloads: [\r\n {\r\n parameters: [],\r\n returnType: `${collectionName}<ClientType>`,\r\n },\r\n {\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: idName,\r\n },\r\n ],\r\n returnType: `${serviceName}<ClientType>`,\r\n },\r\n ],\r\n statements: [\r\n `const fieldName = \"${odataPropName}\";`,\r\n `const { client, path } = this.__base;`,\r\n 'return typeof id === \"undefined\" || id === null',\r\n `? new ${collectionName}(client, path, fieldName)`,\r\n `: new ${serviceName}(client, path, new ${idFunctionName}(fieldName).buildUrl(id));`,\r\n ],\r\n };\r\n }\r\n\r\n private generateSingletonProp(\r\n singleton: SingletonType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const { name, entityType } = singleton;\r\n const type = this.namingHelper.getServiceName(entityType.name);\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(name),\r\n type: `${type}<ClientType>`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateQOperationProp = (operation: OperationType) => {\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(operation.qName),\r\n type: operation.qName,\r\n hasQuestionToken: true,\r\n };\r\n };\r\n\r\n private generateSingletonGetter(singleton: SingletonType): OptionalKind<MethodDeclarationStructure> {\r\n const { name, odataName, entityType } = singleton;\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(name);\r\n const serviceType = this.namingHelper.getServiceName(entityType.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${propName} = new ${serviceType}(client, path, \"${odataName}\")`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private getVersionSuffix() {\r\n return this.version === ODataVersions.V2 ? \"V2\" : \"V4\";\r\n }\r\n\r\n private async generateEntityTypeService(\r\n model: ComplexType,\r\n serviceName: string,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entityServiceType = \"EntityTypeService\" + this.getVersionSuffix();\r\n\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n const operations = this.dataModel.getEntityTypeOperations(model.fqName);\r\n const props = [...model.baseProps, ...model.props];\r\n\r\n importContainer.addFromService(entityServiceType);\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addGeneratedModel(model.name, editableModelName);\r\n importContainer.addGeneratedQObject(model.qName, qObjectName);\r\n\r\n const { properties, methods }: PropsAndOps = deepmerge(\r\n this.generateServiceProperties(serviceName, props, importContainer),\r\n this.generateServiceOperations(operations, importContainer)\r\n );\r\n\r\n // generate EntityTypeService\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends: entityServiceType + `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [`super(client, basePath, name, ${qObjectName}${this.isV4BigNumber() ? \", true\" : \"\"});`],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private getPrimitiveServiceType() {\r\n return \"PrimitiveTypeService\" + this.getVersionSuffix();\r\n }\r\n\r\n private generateServiceProperties(\r\n serviceName: string,\r\n props: Array<PropertyModel>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const collectionServiceType = \"CollectionService\" + this.getVersionSuffix();\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n props.forEach((prop) => {\r\n if ((prop.dataType === DataTypes.ModelType && !prop.isCollection) || prop.dataType === DataTypes.ComplexType) {\r\n result.properties.push(this.generateModelProp(prop, collectionServiceType, serviceName, importContainer));\r\n result.methods.push(this.generateModelPropGetter(prop, collectionServiceType));\r\n } else if (prop.isCollection) {\r\n // collection of entity types\r\n if (prop.dataType === DataTypes.ModelType) {\r\n const entityType = this.dataModel.getEntityType(prop.fqType);\r\n if (!entityType) {\r\n throw new Error(`Entity type \"${prop.fqType}\" specified by property not found!`);\r\n }\r\n\r\n result.methods.push(\r\n this.generateRelatedServiceGetter(prop.name, prop.odataName, entityType, importContainer)\r\n );\r\n }\r\n // collection of primitive or complex types\r\n else {\r\n result.properties.push(this.generatePrimitiveCollectionProp(prop, collectionServiceType, importContainer));\r\n result.methods.push(this.generatePrimitiveCollectionGetter(prop, collectionServiceType));\r\n }\r\n } else if (this.options.enablePrimitivePropertyServices && prop.dataType === DataTypes.PrimitiveType) {\r\n result.properties.push(this.generatePrimitiveTypeProp(prop, importContainer));\r\n result.methods.push(this.generatePrimitiveTypeGetter(prop));\r\n }\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateServiceOperations(operations: Array<OperationType>, importContainer: ImportContainer): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n operations.forEach((operation) => {\r\n result.properties.push(this.generateQOperationProp(operation));\r\n result.methods.push(this.generateMethod(operation.name, operation, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateModelProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n serviceName: string,\r\n importContainer: ImportContainer\r\n ): PropertyDeclarationStructure {\r\n const complexType = this.dataModel.getComplexType(prop.fqType);\r\n const key = this.namingHelper.getServiceName(prop.type);\r\n let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;\r\n\r\n if (prop.isCollection && complexType) {\r\n const editableName = complexType.editableName;\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addGeneratedModel(complexType.name, editableName);\r\n importContainer.addGeneratedQObject(complexType.qName, firstCharLowerCase(complexType.qName));\r\n propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;\r\n } else {\r\n propModelType = `${propModelType}<ClientType>`;\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: propModelType,\r\n hasQuestionToken: true,\r\n } as PropertyDeclarationStructure;\r\n }\r\n\r\n private generatePrimitiveCollectionProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const isEnum = prop.dataType === DataTypes.EnumType;\r\n const type = isEnum ? `EnumCollection<${prop.type}>` : `${upperCaseFirst(prop.type)}Collection`;\r\n const qType = isEnum ? \"QEnumCollection\" : prop.qObject;\r\n const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;\r\n\r\n if (!prop.qObject) {\r\n throw new Error(\"Illegal State: [qObject] must be provided for Collection types!\");\r\n }\r\n\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addFromQObject(prop.qObject, firstCharLowerCase(prop.qObject));\r\n if (isEnum) {\r\n importContainer.addGeneratedModel(prop.type);\r\n importContainer.addFromQObject(\"EnumCollection\");\r\n } else {\r\n importContainer.addFromQObject(type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${collectionType}`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generatePrimitiveTypeProp(\r\n prop: PropertyModel,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const serviceType = this.getPrimitiveServiceType();\r\n importContainer.addFromService(serviceType);\r\n if (prop.typeModule) {\r\n importContainer.addCustomType(prop.typeModule, prop.type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${serviceType}<ClientType, ${prop.type}>`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateModelPropGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const complexType = this.dataModel.getComplexType(prop.fqType);\r\n const isComplexCollection = prop.isCollection && complexType;\r\n const type = isComplexCollection\r\n ? collectionServiceType\r\n : prop.isCollection\r\n ? this.namingHelper.getCollectionServiceName(prop.type)\r\n : this.namingHelper.getServiceName(prop.type);\r\n const typeWithGenerics = isComplexCollection\r\n ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`\r\n : `${type}<ClientType>`;\r\n\r\n const privateSrvProp = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n returnType: typeWithGenerics,\r\n statements: [\r\n `if(!${privateSrvProp}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${privateSrvProp} = new ${type}(client, path, \"${prop.odataName}\"${isComplexCollection ? `, ${firstCharLowerCase(complexType.qName)}`: \"\"})`,\r\n \"}\",\r\n `return ${privateSrvProp}`,\r\n ],\r\n };\r\n }\r\n\r\n private generatePrimitiveCollectionGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${propName} = new ${collectionServiceType}(client, path, \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)}${this.isV4BigNumber() ? \", true\": \"\"})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private generatePrimitiveTypeGetter(prop: PropertyModel): OptionalKind<MethodDeclarationStructure> {\r\n const serviceType = this.getPrimitiveServiceType();\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n // for V2: mapped name must be specified\r\n const useMappedName = this.version === ODataVersions.V2 && prop.name !== prop.odataName;\r\n // for V4: big number support\r\n const useBigNumber = this.isV4BigNumber();\r\n const addParamString = useMappedName ? `, \"${prop.name}\"` : useBigNumber ? \", true\" : \"\";\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path, qModel } = this.__base;`,\r\n ` ${propName} = new ${serviceType}(client, path, \"${prop.odataName}\", qModel.${prop.name}.converter${addParamString})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private async generateEntityCollectionService(\r\n model: ModelType,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entitySetServiceType = \"EntitySetService\" + this.getVersionSuffix();\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n\r\n importContainer.addFromService(entitySetServiceType);\r\n importContainer.addGeneratedModel(model.idModelName);\r\n importContainer.addGeneratedQObject(model.qIdFunctionName);\r\n\r\n const collectionOperations = this.dataModel.getEntitySetOperations(model.fqName);\r\n\r\n const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);\r\n\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: this.namingHelper.getCollectionServiceName(model.name),\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends:\r\n entitySetServiceType +\r\n `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [\r\n `super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name)${\r\n this.isV4BigNumber() ? \", true\" : \"\"\r\n });`,\r\n ],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private async generateModelServices(serviceFile: SourceFile, importContainer: ImportContainer) {\r\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\r\n for (const model of this.dataModel.getEntityTypes()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n\r\n // entity type service\r\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n\r\n // entity collection service\r\n await this.generateEntityCollectionService(model, serviceFile, importContainer);\r\n }\r\n\r\n // build service file for complex types\r\n for (const model of this.dataModel.getComplexTypes()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n\r\n // entity type service\r\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n }\r\n }\r\n\r\n private generateMethod(\r\n name: string,\r\n operation: OperationType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const isFunc = operation.type === OperationTypes.Function;\r\n const odataType = operation.returnType?.isCollection\r\n ? RESPONSE_TYPES.collection + this.getVersionSuffix()\r\n : operation.returnType?.dataType === DataTypes.PrimitiveType\r\n ? RESPONSE_TYPES.value + this.getVersionSuffix()\r\n : RESPONSE_TYPES.model + this.getVersionSuffix();\r\n const returnType = operation.returnType;\r\n const requestConfigParam = {\r\n name: \"requestConfig\",\r\n hasQuestionToken: true,\r\n type: \"ODataHttpClientConfig<ClientType>\",\r\n };\r\n const hasParams = operation.parameters.length > 0;\r\n\r\n // importing dependencies\r\n importContainer.addFromClientApi(\"ODataHttpClientConfig\", \"ODataResponse\");\r\n importContainer.addFromCore(odataType);\r\n if (returnType?.type) {\r\n if ([DataTypes.EnumType, DataTypes.ModelType, DataTypes.ComplexType].includes(returnType.dataType)) {\r\n importContainer.addGeneratedModel(returnType.type);\r\n }\r\n }\r\n importContainer.addGeneratedQObject(operation.qName);\r\n if (hasParams) {\r\n importContainer.addGeneratedModel(operation.paramsModelName);\r\n }\r\n\r\n const qOpProp = \"this.\" + this.namingHelper.getPrivatePropName(operation.qName);\r\n\r\n return {\r\n scope: Scope.Public,\r\n isAsync: true,\r\n name,\r\n parameters: hasParams\r\n ? [{ name: \"params\", type: operation.paramsModelName }, requestConfigParam]\r\n : [requestConfigParam],\r\n returnType: `ODataResponse<${odataType}<${returnType?.type || \"void\"}>>`,\r\n statements: [\r\n `if(!${qOpProp}) {`,\r\n ` ${qOpProp} = new ${operation.qName}()`,\r\n \"}\",\r\n\r\n `const { addFullPath, client, getDefaultHeaders } = this.__base;`,\r\n `const url = addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\r\n `${returnType ? \"const response = await \" : \"return\"} client.${\r\n !isFunc\r\n ? // actions: since V4\r\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${\r\n requestConfigParam.name\r\n }, getDefaultHeaders())`\r\n : operation.usePost\r\n ? // V2 POST => BUT values are still query params, they are not part of the request body\r\n `post(url, undefined, ${requestConfigParam.name}, getDefaultHeaders())`\r\n : // functions: since V2\r\n `get(url, ${requestConfigParam.name}, getDefaultHeaders())`\r\n };`,\r\n returnType ? `return ${qOpProp}.convertResponse(response);` : \"\",\r\n ],\r\n };\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ServiceGenerator.js","sourceRoot":"","sources":["../../src/generator/ServiceGenerator.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AACrD,kEAAkC;AAClC,uCAOkB;AAClB,uDAAkD;AAClD,sDAA2D;AAkB3D,uDAAoD;AAEpD,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,MAAM,cAAc,GAAG;IACrB,UAAU,EAAE,yBAAyB;IACrC,KAAK,EAAE,oBAAoB;IAC3B,KAAK,EAAE,oBAAoB;CAC5B,CAAC;AAOF,SAAsB,gBAAgB,CACpC,SAAoB,EACpB,OAAuB,EACvB,OAAsB,EACtB,YAA0B,E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vF,GAAG,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,QAAQ,WAClD,CAAC,MAAM;oBACL,CAAC,CAAC,oBAAoB;wBACpB,aAAa,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,4BAA4B,CAAC,CAAC,CAAC,IAAI,KACpE,kBAAkB,CAAC,IACrB,wBAAwB;oBAC1B,CAAC,CAAC,SAAS,CAAC,OAAO;wBACnB,CAAC,CAAC,sFAAsF;4BACtF,wBAAwB,kBAAkB,CAAC,IAAI,wBAAwB;wBACzE,CAAC,CAAC,sBAAsB;4BACtB,YAAY,kBAAkB,CAAC,IAAI,wBACzC,GAAG;gBACH,UAAU,CAAC,CAAC,CAAC,UAAU,OAAO,6BAA6B,CAAC,CAAC,CAAC,EAAE;aACjE;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport deepmerge from \"deepmerge\";\r\nimport {\r\n ClassDeclarationStructure,\r\n MethodDeclarationStructure,\r\n OptionalKind,\r\n PropertyDeclarationStructure,\r\n Scope,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport { upperCaseFirst } from \"upper-case-first\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntityContainerModel,\r\n FunctionImportType,\r\n ModelType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { ConfigFileOptions } from \"../OptionModel\";\r\nimport { ProjectManager } from \"../project/ProjectManager\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nconst ROOT_SERVICE = \"ODataService\";\r\n\r\nconst RESPONSE_TYPES = {\r\n collection: \"ODataCollectionResponse\",\r\n model: \"ODataModelResponse\",\r\n value: \"ODataValueResponse\",\r\n};\r\n\r\nexport interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, \"properties\" | \"methods\">> {}\r\n\r\nexport interface ServiceGeneratorOptions\r\n extends Pick<ConfigFileOptions, \"enablePrimitivePropertyServices\" | \"v4BigNumberAsString\"> {}\r\n\r\nexport async function generateServices(\r\n dataModel: DataModel,\r\n project: ProjectManager,\r\n version: ODataVersions,\r\n namingHelper: NamingHelper,\r\n options?: ServiceGeneratorOptions\r\n) {\r\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper, options);\r\n return generator.generate();\r\n}\r\n\r\nclass ServiceGenerator {\r\n constructor(\r\n private dataModel: DataModel,\r\n private project: ProjectManager,\r\n private version: ODataVersions,\r\n private namingHelper: NamingHelper,\r\n private options: ServiceGeneratorOptions = {}\r\n ) {}\r\n\r\n private isV4BigNumber() {\r\n return this.options.v4BigNumberAsString && this.version === ODataVersions.V4;\r\n }\r\n\r\n public async generate(): Promise<void> {\r\n const sourceFile = await this.project.createMainServiceFile();\r\n const serviceName = this.namingHelper.getMainServiceName();\r\n const container = this.dataModel.getEntityContainer();\r\n const unboundOperations = [...Object.values(container.functions), ...Object.values(container.actions)];\r\n\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addFromService(ROOT_SERVICE);\r\n\r\n const { properties, methods }: PropsAndOps = deepmerge(\r\n this.generateMainServiceProperties(container, importContainer),\r\n this.generateMainServiceOperations(unboundOperations, importContainer)\r\n );\r\n\r\n sourceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends: `${ROOT_SERVICE}<ClientType>`,\r\n ctors: this.isV4BigNumber()\r\n ? [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n ],\r\n statements: [`super(client, basePath, true);`],\r\n },\r\n ]\r\n : [],\r\n properties,\r\n methods,\r\n });\r\n\r\n await this.generateModelServices(sourceFile, importContainer);\r\n\r\n sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\r\n }\r\n\r\n private generateMainServiceProperties(\r\n container: EntityContainerModel,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n Object.values(container.entitySets).forEach(({ name, odataName, entityType }) => {\r\n result.methods.push(this.generateRelatedServiceGetter(name, odataName, entityType, importContainer));\r\n });\r\n\r\n Object.values(container.singletons).forEach((singleton) => {\r\n result.properties.push(this.generateSingletonProp(singleton, importContainer));\r\n result.methods.push(this.generateSingletonGetter(singleton));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateMainServiceOperations(\r\n ops: Array<FunctionImportType | ActionImportType>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n ops.forEach(({ operation, name }) => {\r\n const op = this.dataModel.getUnboundOperationType(operation);\r\n if (!op) {\r\n throw new Error(`Operation \"${operation}\" not found!`);\r\n }\r\n\r\n result.properties.push(this.generateQOperationProp(op));\r\n result.methods.push(this.generateMethod(name, op, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateRelatedServiceGetter(\r\n propName: string,\r\n odataPropName: string,\r\n entityType: ModelType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const idName = entityType.idModelName;\r\n const idFunctionName = entityType.qIdFunctionName;\r\n const serviceName = this.namingHelper.getServiceName(entityType.name);\r\n const collectionName = this.namingHelper.getCollectionServiceName(entityType.name);\r\n\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addGeneratedModel(idName);\r\n importContainer.addGeneratedQObject(idFunctionName);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(propName),\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: `${idName} | undefined`,\r\n hasQuestionToken: true,\r\n },\r\n ],\r\n overloads: [\r\n {\r\n parameters: [],\r\n returnType: `${collectionName}<ClientType>`,\r\n },\r\n {\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: idName,\r\n },\r\n ],\r\n returnType: `${serviceName}<ClientType>`,\r\n },\r\n ],\r\n statements: [\r\n `const fieldName = \"${odataPropName}\";`,\r\n `const { client, path } = this.__base;`,\r\n 'return typeof id === \"undefined\" || id === null',\r\n `? new ${collectionName}(client, path, fieldName)`,\r\n `: new ${serviceName}(client, path, new ${idFunctionName}(fieldName).buildUrl(id));`,\r\n ],\r\n };\r\n }\r\n\r\n private generateSingletonProp(\r\n singleton: SingletonType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const { name, entityType } = singleton;\r\n const type = this.namingHelper.getServiceName(entityType.name);\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(name),\r\n type: `${type}<ClientType>`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateQOperationProp = (operation: OperationType) => {\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(operation.qName),\r\n type: operation.qName,\r\n hasQuestionToken: true,\r\n };\r\n };\r\n\r\n private generateSingletonGetter(singleton: SingletonType): OptionalKind<MethodDeclarationStructure> {\r\n const { name, odataName, entityType } = singleton;\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(name);\r\n const serviceType = this.namingHelper.getServiceName(entityType.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${propName} = new ${serviceType}(client, path, \"${odataName}\")`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private getVersionSuffix() {\r\n return this.version === ODataVersions.V2 ? \"V2\" : \"V4\";\r\n }\r\n\r\n private generateEntityTypeService(\r\n model: ComplexType,\r\n serviceName: string,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entityServiceType = \"EntityTypeService\" + this.getVersionSuffix();\r\n\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n const operations = this.dataModel.getEntityTypeOperations(model.fqName);\r\n const props = [...model.baseProps, ...model.props];\r\n\r\n importContainer.addFromService(entityServiceType);\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addGeneratedModel(model.name, editableModelName);\r\n importContainer.addGeneratedQObject(model.qName, qObjectName);\r\n\r\n const { properties, methods }: PropsAndOps = deepmerge(\r\n this.generateServiceProperties(serviceName, props, importContainer),\r\n this.generateServiceOperations(operations, importContainer)\r\n );\r\n\r\n // generate EntityTypeService\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends: entityServiceType + `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [`super(client, basePath, name, ${qObjectName}${this.isV4BigNumber() ? \", true\" : \"\"});`],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private getPrimitiveServiceType() {\r\n return \"PrimitiveTypeService\" + this.getVersionSuffix();\r\n }\r\n\r\n private generateServiceProperties(\r\n serviceName: string,\r\n props: Array<PropertyModel>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const collectionServiceType = \"CollectionService\" + this.getVersionSuffix();\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n props.forEach((prop) => {\r\n if ((prop.dataType === DataTypes.ModelType && !prop.isCollection) || prop.dataType === DataTypes.ComplexType) {\r\n result.properties.push(this.generateModelProp(prop, collectionServiceType, serviceName, importContainer));\r\n result.methods.push(this.generateModelPropGetter(prop, collectionServiceType));\r\n } else if (prop.isCollection) {\r\n // collection of entity types\r\n if (prop.dataType === DataTypes.ModelType) {\r\n const entityType = this.dataModel.getEntityType(prop.fqType);\r\n if (!entityType) {\r\n throw new Error(`Entity type \"${prop.fqType}\" specified by property not found!`);\r\n }\r\n\r\n result.methods.push(\r\n this.generateRelatedServiceGetter(prop.name, prop.odataName, entityType, importContainer)\r\n );\r\n }\r\n // collection of primitive or complex types\r\n else {\r\n result.properties.push(this.generatePrimitiveCollectionProp(prop, collectionServiceType, importContainer));\r\n result.methods.push(this.generatePrimitiveCollectionGetter(prop, collectionServiceType));\r\n }\r\n } else if (this.options.enablePrimitivePropertyServices && prop.dataType === DataTypes.PrimitiveType) {\r\n result.properties.push(this.generatePrimitiveTypeProp(prop, importContainer));\r\n result.methods.push(this.generatePrimitiveTypeGetter(prop));\r\n }\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateServiceOperations(operations: Array<OperationType>, importContainer: ImportContainer): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n operations.forEach((operation) => {\r\n result.properties.push(this.generateQOperationProp(operation));\r\n result.methods.push(this.generateMethod(operation.name, operation, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateModelProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n serviceName: string,\r\n importContainer: ImportContainer\r\n ): PropertyDeclarationStructure {\r\n const complexType = this.dataModel.getComplexType(prop.fqType);\r\n const key = this.namingHelper.getServiceName(prop.type);\r\n let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;\r\n\r\n if (prop.isCollection && complexType) {\r\n const editableName = complexType.editableName;\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addGeneratedModel(complexType.name, editableName);\r\n importContainer.addGeneratedQObject(complexType.qName, firstCharLowerCase(complexType.qName));\r\n propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;\r\n } else {\r\n propModelType = `${propModelType}<ClientType>`;\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: propModelType,\r\n hasQuestionToken: true,\r\n } as PropertyDeclarationStructure;\r\n }\r\n\r\n private generatePrimitiveCollectionProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const isEnum = prop.dataType === DataTypes.EnumType;\r\n const type = isEnum ? `EnumCollection<${prop.type}>` : `${upperCaseFirst(prop.type)}Collection`;\r\n const qType = isEnum ? \"QEnumCollection\" : prop.qObject;\r\n const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;\r\n\r\n if (!prop.qObject) {\r\n throw new Error(\"Illegal State: [qObject] must be provided for Collection types!\");\r\n }\r\n\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addFromQObject(prop.qObject, firstCharLowerCase(prop.qObject));\r\n if (isEnum) {\r\n importContainer.addGeneratedModel(prop.type);\r\n importContainer.addFromQObject(\"EnumCollection\");\r\n } else {\r\n importContainer.addFromQObject(type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${collectionType}`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generatePrimitiveTypeProp(\r\n prop: PropertyModel,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const serviceType = this.getPrimitiveServiceType();\r\n importContainer.addFromService(serviceType);\r\n if (prop.typeModule) {\r\n importContainer.addCustomType(prop.typeModule, prop.type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${serviceType}<ClientType, ${prop.type}>`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateModelPropGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const complexType = this.dataModel.getComplexType(prop.fqType);\r\n const isComplexCollection = prop.isCollection && complexType;\r\n const type = isComplexCollection\r\n ? collectionServiceType\r\n : prop.isCollection\r\n ? this.namingHelper.getCollectionServiceName(prop.type)\r\n : this.namingHelper.getServiceName(prop.type);\r\n const typeWithGenerics = isComplexCollection\r\n ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`\r\n : `${type}<ClientType>`;\r\n\r\n const privateSrvProp = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n returnType: typeWithGenerics,\r\n statements: [\r\n `if(!${privateSrvProp}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${privateSrvProp} = new ${type}(client, path, \"${prop.odataName}\"${isComplexCollection ? `, ${firstCharLowerCase(complexType.qName)}`: \"\"})`,\r\n \"}\",\r\n `return ${privateSrvProp}`,\r\n ],\r\n };\r\n }\r\n\r\n private generatePrimitiveCollectionGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${propName} = new ${collectionServiceType}(client, path, \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)}${this.isV4BigNumber() ? \", true\": \"\"})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private generatePrimitiveTypeGetter(prop: PropertyModel): OptionalKind<MethodDeclarationStructure> {\r\n const serviceType = this.getPrimitiveServiceType();\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n // for V2: mapped name must be specified\r\n const useMappedName = this.version === ODataVersions.V2 && prop.name !== prop.odataName;\r\n // for V4: big number support\r\n const useBigNumber = this.isV4BigNumber();\r\n const addParamString = useMappedName ? `, \"${prop.name}\"` : useBigNumber ? \", true\" : \"\";\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path, qModel } = this.__base;`,\r\n ` ${propName} = new ${serviceType}(client, path, \"${prop.odataName}\", qModel.${prop.name}.converter${addParamString})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private generateEntityCollectionService(model: ModelType, serviceFile: SourceFile, importContainer: ImportContainer) {\r\n const entitySetServiceType = \"EntitySetService\" + this.getVersionSuffix();\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n\r\n importContainer.addFromService(entitySetServiceType);\r\n importContainer.addGeneratedModel(model.idModelName);\r\n importContainer.addGeneratedQObject(model.qIdFunctionName);\r\n\r\n const collectionOperations = this.dataModel.getEntitySetOperations(model.fqName);\r\n\r\n const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);\r\n\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: this.namingHelper.getCollectionServiceName(model.name),\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends:\r\n entitySetServiceType +\r\n `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [\r\n `super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name)${\r\n this.isV4BigNumber() ? \", true\" : \"\"\r\n });`,\r\n ],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private async generateModelServices(serviceFile: SourceFile, importContainer: ImportContainer) {\r\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\r\n const entities = this.dataModel.getEntityTypes().filter((et) => !et.abstract);\r\n for (const model of entities) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n\r\n // entity type service\r\n this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n // entity collection service if this entity specified keys at all\r\n if (model.keyNames.length) {\r\n this.generateEntityCollectionService(model, serviceFile, importContainer);\r\n }\r\n }\r\n\r\n // build service file for complex types\r\n const complexTypes = this.dataModel.getComplexTypes().filter((ct) => !ct.abstract);\r\n for (const model of complexTypes) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n\r\n // entity type service\r\n this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n }\r\n }\r\n\r\n private generateMethod(\r\n name: string,\r\n operation: OperationType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const isFunc = operation.type === OperationTypes.Function;\r\n const odataType = operation.returnType?.isCollection\r\n ? RESPONSE_TYPES.collection + this.getVersionSuffix()\r\n : operation.returnType?.dataType === DataTypes.PrimitiveType\r\n ? RESPONSE_TYPES.value + this.getVersionSuffix()\r\n : RESPONSE_TYPES.model + this.getVersionSuffix();\r\n const returnType = operation.returnType;\r\n const requestConfigParam = {\r\n name: \"requestConfig\",\r\n hasQuestionToken: true,\r\n type: \"ODataHttpClientConfig<ClientType>\",\r\n };\r\n const hasParams = operation.parameters.length > 0;\r\n\r\n // importing dependencies\r\n importContainer.addFromClientApi(\"ODataHttpClientConfig\", \"ODataResponse\");\r\n importContainer.addFromCore(odataType);\r\n if (returnType?.type) {\r\n if ([DataTypes.EnumType, DataTypes.ModelType, DataTypes.ComplexType].includes(returnType.dataType)) {\r\n importContainer.addGeneratedModel(returnType.type);\r\n }\r\n }\r\n importContainer.addGeneratedQObject(operation.qName);\r\n if (hasParams) {\r\n importContainer.addGeneratedModel(operation.paramsModelName);\r\n }\r\n\r\n const qOpProp = \"this.\" + this.namingHelper.getPrivatePropName(operation.qName);\r\n\r\n return {\r\n scope: Scope.Public,\r\n isAsync: true,\r\n name,\r\n parameters: hasParams\r\n ? [{ name: \"params\", type: operation.paramsModelName }, requestConfigParam]\r\n : [requestConfigParam],\r\n returnType: `ODataResponse<${odataType}<${returnType?.type || \"void\"}>>`,\r\n statements: [\r\n `if(!${qOpProp}) {`,\r\n ` ${qOpProp} = new ${operation.qName}()`,\r\n \"}\",\r\n\r\n `const { addFullPath, client, getDefaultHeaders } = this.__base;`,\r\n `const url = addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\r\n `${returnType ? \"const response = await \" : \"return\"} client.${\r\n !isFunc\r\n ? // actions: since V4\r\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${\r\n requestConfigParam.name\r\n }, getDefaultHeaders())`\r\n : operation.usePost\r\n ? // V2 POST => BUT values are still query params, they are not part of the request body\r\n `post(url, undefined, ${requestConfigParam.name}, getDefaultHeaders())`\r\n : // functions: since V2\r\n `get(url, ${requestConfigParam.name}, getDefaultHeaders())`\r\n };`,\r\n returnType ? `return ${qOpProp}.convertResponse(response);` : \"\",\r\n ],\r\n };\r\n }\r\n}\r\n"]}
|
|
@@ -71,7 +71,7 @@ class ProjectManager {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
catch (formattingError) {
|
|
74
|
-
console.error("Formatting failed");
|
|
74
|
+
console.error("Formatting failed", formattingError);
|
|
75
75
|
yield (0, promises_1.writeFile)("error.log", (formattingError === null || formattingError === void 0 ? void 0 : formattingError.toString()) || "no error message!");
|
|
76
76
|
process.exit(99);
|
|
77
77
|
}
|
|
@@ -148,9 +148,10 @@ class ProjectManager {
|
|
|
148
148
|
}
|
|
149
149
|
emitTsFiles() {
|
|
150
150
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
const files = [this.getModelFile(), this.getQObjectFile(), this.getMainServiceFile()];
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
const files = [this.getModelFile(), this.getQObjectFile(), this.getMainServiceFile()].filter((file) => !!file);
|
|
152
|
+
const text = files.length === 1 ? "Emitting 1 TS file" : `Emitting ${files.length} TS files`;
|
|
153
|
+
console.log(`${text}: ${files.map((f) => path.basename(f.getFilePath())).join(", ")}`);
|
|
154
|
+
return Promise.all(files.map(this.formatAndWriteFile));
|
|
154
155
|
});
|
|
155
156
|
}
|
|
156
157
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectManager.js","sourceRoot":"","sources":["../../src/project/ProjectManager.ts"],"names":[],"mappings":";;;;AAAA,0CAAwC;AACxC,mDAA6B;AAE7B,uCAAkC;AAClC,uCAQkB;AAClB,8EAAmC;AACnC,oEAA4B;AAG5B,gDAA2C;AAC3C,2CAA8C;AAG9C,SAAsB,oBAAoB,CACxC,YAA0B,EAC1B,SAAiB,EACjB,QAAmB,EACnB,WAAoB,EACpB,eAAuB,eAAe;;QAEtC,MAAM,oBAAoB,GAAG,uBAAS,CAAC,MAAM,KAAK,QAAQ,IAAI,uBAAS,CAAC,GAAG,KAAK,QAAQ,CAAC;QACzF,MAAM,IAAI,GAAG,IAAA,yBAAI,EAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,MAAM,IAAA,2BAAe,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAEhE,MAAM,KAeF,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC,eAAe,KAAI,EAAE,EAflC;QACJ,gBAAgB;QAChB,MAAM,EAAE,yBAAyB;QACjC,sBAAsB,EAAE,kBAAkB;QAC1C,GAAG,EACH,OAAO;QACP,eAAe;QACf,gBAAgB,EAChB,GAAG,EACH,MAAM,EACN,OAAO,EACP,MAAM,EACN,OAAO,EACP,QAAQ,OAE8B,EADnC,WAAW,sBAdV,uIA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,CAAC,4BAA4B;gBAC9B,CAAC,CAAC,sBAAsB,IAAI,CAAC,QAAQ,KAAK,uBAAS,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,qBAAqB,CAC5G,CAAC;YAEF,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;YAEjE;;gBAEI;QACN,CAAC;KAAA;IAEa,WAAW;;YACvB,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC;YACtF,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,CAAC,MAAM,WAAW,CAAC,CAAC;YACjD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACvF,CAAC;KAAA;CAqBF;AA7GD,wCA6GC","sourcesContent":["import { writeFile } from \"fs/promises\";\r\nimport * as path from \"path\";\r\n\r\nimport { remove } from \"fs-extra\";\r\nimport {\r\n CompilerOptions,\r\n ModuleKind,\r\n ModuleResolutionKind,\r\n NewLineKind,\r\n Project,\r\n ScriptTarget,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport load from \"tsconfig-loader\";\r\nimport ts from \"typescript\";\r\n\r\nimport { ProjectFiles } from \"../data-model/DataModel\";\r\nimport { EmitModes } from \"../OptionModel\";\r\nimport { createFormatter } from \"./formatter\";\r\nimport { FileFormatter } from \"./formatter/FileFormatter\";\r\n\r\nexport async function createProjectManager(\r\n projectFiles: ProjectFiles,\r\n outputDir: string,\r\n emitMode: EmitModes,\r\n usePrettier: boolean,\r\n tsConfigPath: string = \"tsconfig.json\"\r\n): Promise<ProjectManager> {\r\n const generateDeclarations = EmitModes.js_dts === emitMode || EmitModes.dts === emitMode;\r\n const conf = load({ filename: tsConfigPath });\r\n const formatter = await createFormatter(outputDir, usePrettier);\r\n\r\n const {\r\n // ignored props\r\n noEmit, // we always want to emit\r\n importsNotUsedAsValues, // type is missing\r\n jsx,\r\n plugins,\r\n // mapped props\r\n moduleResolution,\r\n lib,\r\n module,\r\n newLine,\r\n target,\r\n rootDir,\r\n rootDirs,\r\n ...passThrough\r\n } = conf?.tsConfig.compilerOptions || {};\r\n\r\n const compilerOpts: CompilerOptions = {\r\n ...passThrough,\r\n outDir: outputDir,\r\n declaration: generateDeclarations,\r\n moduleResolution: getModuleResolutionKind(moduleResolution),\r\n module: getModuleKind(module),\r\n target: getTarget(target),\r\n lib: lib as string[],\r\n newLine:\r\n newLine?.toLowerCase() === \"crlf\"\r\n ? NewLineKind.CarriageReturnLineFeed\r\n : newLine?.toLowerCase() === \"lf\"\r\n ? NewLineKind.LineFeed\r\n : undefined,\r\n };\r\n\r\n return new ProjectManager(projectFiles, outputDir, emitMode, formatter, compilerOpts);\r\n}\r\n\r\nfunction getModuleResolutionKind(\r\n moduleResolution: string | undefined | Record<string, any>\r\n): ModuleResolutionKind | undefined {\r\n const modRes =\r\n typeof moduleResolution === \"string\"\r\n ? moduleResolution.toLowerCase() === \"node\"\r\n ? \"nodejs\"\r\n : moduleResolution.toLowerCase()\r\n : undefined;\r\n const matchedKey = Object.keys(ts.ModuleResolutionKind).find(\r\n (mk): mk is keyof typeof ModuleResolutionKind => mk.toLowerCase() === modRes\r\n );\r\n return matchedKey ? (ts.ModuleResolutionKind[matchedKey] as ModuleResolutionKind) : undefined;\r\n}\r\n\r\nfunction getModuleKind(module: string | undefined | Record<string, any>): ModuleKind | undefined {\r\n const mod = typeof module === \"string\" ? module.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ModuleKind).find((mk): mk is keyof typeof ModuleKind => mk.toLowerCase() === mod);\r\n return matchedKey ? (ts.ModuleKind[matchedKey] as ModuleKind) : undefined;\r\n}\r\n\r\nfunction getTarget(target: string | undefined | Record<string, any>): ScriptTarget | undefined {\r\n const t = typeof target === \"string\" ? target.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ScriptTarget).find((st): st is keyof typeof ScriptTarget => st.toLowerCase() === t);\r\n return matchedKey ? (ts.ScriptTarget[matchedKey] as ScriptTarget) : undefined;\r\n}\r\n\r\nexport class ProjectManager {\r\n private project!: Project;\r\n\r\n private files: { [name: string]: SourceFile } = {};\r\n\r\n constructor(\r\n private projectFiles: ProjectFiles,\r\n private outputDir: string,\r\n private emitMode: EmitModes,\r\n private formatter: FileFormatter,\r\n compilerOptions: CompilerOptions | undefined\r\n ) {\r\n // Create ts-morph project\r\n this.project = new Project({\r\n manipulationSettings: this.formatter.getSettings(),\r\n skipAddingFilesFromTsConfig: true,\r\n compilerOptions,\r\n });\r\n }\r\n\r\n private async createFile(name: string) {\r\n const fileName = path.join(this.outputDir, `${name}.ts`);\r\n await remove(fileName);\r\n return this.project.createSourceFile(fileName);\r\n }\r\n\r\n public async createModelFile() {\r\n this.files.model = await this.createFile(this.projectFiles.model);\r\n return this.getModelFile();\r\n }\r\n\r\n public getModelFile() {\r\n return this.files.model;\r\n }\r\n\r\n public async createQObjectFile() {\r\n this.files.qobject = await this.createFile(this.projectFiles.qObject);\r\n return this.getQObjectFile();\r\n }\r\n\r\n public getQObjectFile() {\r\n return this.files.qobject;\r\n }\r\n\r\n public async createMainServiceFile() {\r\n this.files.mainService = await this.createFile(this.projectFiles.service);\r\n return this.getMainServiceFile();\r\n }\r\n\r\n public getMainServiceFile() {\r\n return this.files.mainService;\r\n }\r\n\r\n public async writeFiles() {\r\n switch (this.emitMode) {\r\n case EmitModes.js:\r\n case EmitModes.js_dts:\r\n await this.emitJsFiles();\r\n break;\r\n case EmitModes.dts:\r\n await this.emitJsFiles(true);\r\n break;\r\n case EmitModes.ts:\r\n await this.emitTsFiles();\r\n break;\r\n default:\r\n throw new Error(`Emit mode \"${this.emitMode}\" is invalid!`);\r\n }\r\n }\r\n\r\n private async emitJsFiles(declarationOnly?: boolean) {\r\n console.log(\r\n declarationOnly\r\n ? \"Emitting declaration files\"\r\n : `Emitting JS files (${this.emitMode === EmitModes.js_dts ? \"including\" : \"without\"} declaration files)`\r\n );\r\n\r\n await this.project.emit({ emitOnlyDtsFiles: !!declarationOnly });\r\n\r\n /* for (const diagnostic of this.project.getPreEmitDiagnostics()) {\r\n console.log(diagnostic.getMessageText());\r\n } */\r\n }\r\n\r\n private async emitTsFiles() {\r\n const files = [this.getModelFile(), this.getQObjectFile(), this.getMainServiceFile()];\r\n console.log(`Emitting ${files.length} TS files`);\r\n return Promise.all([...files.filter((file) => !!file).map(this.formatAndWriteFile)]);\r\n }\r\n\r\n private formatAndWriteFile = async (file: SourceFile) => {\r\n const fileName = file.getFilePath();\r\n const content = file.getFullText();\r\n\r\n try {\r\n const formatted = await this.formatter.format(content);\r\n\r\n try {\r\n return writeFile(fileName, formatted);\r\n } catch (writeError) {\r\n console.error(`Failed to write file [/${fileName}]`, writeError);\r\n process.exit(3);\r\n }\r\n } catch (formattingError) {\r\n console.error(\"Formatting failed\");\r\n await writeFile(\"error.log\", formattingError?.toString() || \"no error message!\");\r\n process.exit(99);\r\n }\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ProjectManager.js","sourceRoot":"","sources":["../../src/project/ProjectManager.ts"],"names":[],"mappings":";;;;AAAA,0CAAwC;AACxC,mDAA6B;AAE7B,uCAAkC;AAClC,uCAQkB;AAClB,8EAAmC;AACnC,oEAA4B;AAG5B,gDAA2C;AAC3C,2CAA8C;AAG9C,SAAsB,oBAAoB,CACxC,YAA0B,EAC1B,SAAiB,EACjB,QAAmB,EACnB,WAAoB,EACpB,eAAuB,eAAe;;QAEtC,MAAM,oBAAoB,GAAG,uBAAS,CAAC,MAAM,KAAK,QAAQ,IAAI,uBAAS,CAAC,GAAG,KAAK,QAA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CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACvF,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;QACzD,CAAC;KAAA;CAqBF;AA9GD,wCA8GC","sourcesContent":["import { writeFile } from \"fs/promises\";\r\nimport * as path from \"path\";\r\n\r\nimport { remove } from \"fs-extra\";\r\nimport {\r\n CompilerOptions,\r\n ModuleKind,\r\n ModuleResolutionKind,\r\n NewLineKind,\r\n Project,\r\n ScriptTarget,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport load from \"tsconfig-loader\";\r\nimport ts from \"typescript\";\r\n\r\nimport { ProjectFiles } from \"../data-model/DataModel\";\r\nimport { EmitModes } from \"../OptionModel\";\r\nimport { createFormatter } from \"./formatter\";\r\nimport { FileFormatter } from \"./formatter/FileFormatter\";\r\n\r\nexport async function createProjectManager(\r\n projectFiles: ProjectFiles,\r\n outputDir: string,\r\n emitMode: EmitModes,\r\n usePrettier: boolean,\r\n tsConfigPath: string = \"tsconfig.json\"\r\n): Promise<ProjectManager> {\r\n const generateDeclarations = EmitModes.js_dts === emitMode || EmitModes.dts === emitMode;\r\n const conf = load({ filename: tsConfigPath });\r\n const formatter = await createFormatter(outputDir, usePrettier);\r\n\r\n const {\r\n // ignored props\r\n noEmit, // we always want to emit\r\n importsNotUsedAsValues, // type is missing\r\n jsx,\r\n plugins,\r\n // mapped props\r\n moduleResolution,\r\n lib,\r\n module,\r\n newLine,\r\n target,\r\n rootDir,\r\n rootDirs,\r\n ...passThrough\r\n } = conf?.tsConfig.compilerOptions || {};\r\n\r\n const compilerOpts: CompilerOptions = {\r\n ...passThrough,\r\n outDir: outputDir,\r\n declaration: generateDeclarations,\r\n moduleResolution: getModuleResolutionKind(moduleResolution),\r\n module: getModuleKind(module),\r\n target: getTarget(target),\r\n lib: lib as string[],\r\n newLine:\r\n newLine?.toLowerCase() === \"crlf\"\r\n ? NewLineKind.CarriageReturnLineFeed\r\n : newLine?.toLowerCase() === \"lf\"\r\n ? NewLineKind.LineFeed\r\n : undefined,\r\n };\r\n\r\n return new ProjectManager(projectFiles, outputDir, emitMode, formatter, compilerOpts);\r\n}\r\n\r\nfunction getModuleResolutionKind(\r\n moduleResolution: string | undefined | Record<string, any>\r\n): ModuleResolutionKind | undefined {\r\n const modRes =\r\n typeof moduleResolution === \"string\"\r\n ? moduleResolution.toLowerCase() === \"node\"\r\n ? \"nodejs\"\r\n : moduleResolution.toLowerCase()\r\n : undefined;\r\n const matchedKey = Object.keys(ts.ModuleResolutionKind).find(\r\n (mk): mk is keyof typeof ModuleResolutionKind => mk.toLowerCase() === modRes\r\n );\r\n return matchedKey ? (ts.ModuleResolutionKind[matchedKey] as ModuleResolutionKind) : undefined;\r\n}\r\n\r\nfunction getModuleKind(module: string | undefined | Record<string, any>): ModuleKind | undefined {\r\n const mod = typeof module === \"string\" ? module.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ModuleKind).find((mk): mk is keyof typeof ModuleKind => mk.toLowerCase() === mod);\r\n return matchedKey ? (ts.ModuleKind[matchedKey] as ModuleKind) : undefined;\r\n}\r\n\r\nfunction getTarget(target: string | undefined | Record<string, any>): ScriptTarget | undefined {\r\n const t = typeof target === \"string\" ? target.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ScriptTarget).find((st): st is keyof typeof ScriptTarget => st.toLowerCase() === t);\r\n return matchedKey ? (ts.ScriptTarget[matchedKey] as ScriptTarget) : undefined;\r\n}\r\n\r\nexport class ProjectManager {\r\n private project!: Project;\r\n\r\n private files: { [name: string]: SourceFile } = {};\r\n\r\n constructor(\r\n private projectFiles: ProjectFiles,\r\n private outputDir: string,\r\n private emitMode: EmitModes,\r\n private formatter: FileFormatter,\r\n compilerOptions: CompilerOptions | undefined\r\n ) {\r\n // Create ts-morph project\r\n this.project = new Project({\r\n manipulationSettings: this.formatter.getSettings(),\r\n skipAddingFilesFromTsConfig: true,\r\n compilerOptions,\r\n });\r\n }\r\n\r\n private async createFile(name: string) {\r\n const fileName = path.join(this.outputDir, `${name}.ts`);\r\n await remove(fileName);\r\n return this.project.createSourceFile(fileName);\r\n }\r\n\r\n public async createModelFile() {\r\n this.files.model = await this.createFile(this.projectFiles.model);\r\n return this.getModelFile();\r\n }\r\n\r\n public getModelFile() {\r\n return this.files.model;\r\n }\r\n\r\n public async createQObjectFile() {\r\n this.files.qobject = await this.createFile(this.projectFiles.qObject);\r\n return this.getQObjectFile();\r\n }\r\n\r\n public getQObjectFile() {\r\n return this.files.qobject;\r\n }\r\n\r\n public async createMainServiceFile() {\r\n this.files.mainService = await this.createFile(this.projectFiles.service);\r\n return this.getMainServiceFile();\r\n }\r\n\r\n public getMainServiceFile() {\r\n return this.files.mainService;\r\n }\r\n\r\n public async writeFiles() {\r\n switch (this.emitMode) {\r\n case EmitModes.js:\r\n case EmitModes.js_dts:\r\n await this.emitJsFiles();\r\n break;\r\n case EmitModes.dts:\r\n await this.emitJsFiles(true);\r\n break;\r\n case EmitModes.ts:\r\n await this.emitTsFiles();\r\n break;\r\n default:\r\n throw new Error(`Emit mode \"${this.emitMode}\" is invalid!`);\r\n }\r\n }\r\n\r\n private async emitJsFiles(declarationOnly?: boolean) {\r\n console.log(\r\n declarationOnly\r\n ? \"Emitting declaration files\"\r\n : `Emitting JS files (${this.emitMode === EmitModes.js_dts ? \"including\" : \"without\"} declaration files)`\r\n );\r\n\r\n await this.project.emit({ emitOnlyDtsFiles: !!declarationOnly });\r\n\r\n /* for (const diagnostic of this.project.getPreEmitDiagnostics()) {\r\n console.log(diagnostic.getMessageText());\r\n } */\r\n }\r\n\r\n private async emitTsFiles() {\r\n const files = [this.getModelFile(), this.getQObjectFile(), this.getMainServiceFile()].filter((file) => !!file);\r\n const text = files.length === 1 ? \"Emitting 1 TS file\" : `Emitting ${files.length} TS files`;\r\n console.log(`${text}: ${files.map((f) => path.basename(f.getFilePath())).join(\", \")}`);\r\n return Promise.all(files.map(this.formatAndWriteFile));\r\n }\r\n\r\n private formatAndWriteFile = async (file: SourceFile) => {\r\n const fileName = file.getFilePath();\r\n const content = file.getFullText();\r\n\r\n try {\r\n const formatted = await this.formatter.format(content);\r\n\r\n try {\r\n return writeFile(fileName, formatted);\r\n } catch (writeError) {\r\n console.error(`Failed to write file [/${fileName}]`, writeError);\r\n process.exit(3);\r\n }\r\n } catch (formattingError) {\r\n console.error(\"Formatting failed\", formattingError);\r\n await writeFile(\"error.log\", formattingError?.toString() || \"no error message!\");\r\n process.exit(99);\r\n }\r\n };\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odata2ts/odata2ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -88,6 +88,6 @@
|
|
|
88
88
|
"typescript": "^5.1.3"
|
|
89
89
|
},
|
|
90
90
|
"types": "./lib/index.d.ts",
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "76da31570a037c222fa40bc587694f371ef70c32",
|
|
92
92
|
"readme": "README.md"
|
|
93
93
|
}
|