@odata2ts/odata2ts 0.20.3 → 0.22.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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateServices = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const odata_core_1 = require("@odata2ts/odata-core");
6
+ const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
6
7
  const ts_morph_1 = require("ts-morph");
7
8
  const upper_case_first_1 = require("upper-case-first");
8
9
  const processors_1 = require("xml2js/lib/processors");
@@ -26,7 +27,7 @@ class ServiceGenerator {
26
27
  this.project = project;
27
28
  this.version = version;
28
29
  this.namingHelper = namingHelper;
29
- this.generateQOperationProps = (operation) => {
30
+ this.generateQOperationProp = (operation) => {
30
31
  return {
31
32
  scope: ts_morph_1.Scope.Private,
32
33
  name: this.namingHelper.getPrivatePropName(operation.qName),
@@ -45,97 +46,131 @@ class ServiceGenerator {
45
46
  const importContainer = new ImportContainer_1.ImportContainer(this.namingHelper.getFileNames());
46
47
  importContainer.addFromClientApi("ODataClient");
47
48
  importContainer.addFromService(ROOT_SERVICE);
49
+ const { properties, methods } = (0, deepmerge_1.default)(this.generateMainServiceProperties(container, importContainer), this.generateMainServiceOperations(unboundOperations, importContainer));
48
50
  sourceFile.addClass({
49
51
  isExported: true,
50
52
  name: serviceName,
51
53
  typeParameters: ["ClientType extends ODataClient"],
52
54
  extends: `${ROOT_SERVICE}<ClientType>`,
53
- properties: [
54
- {
55
- scope: ts_morph_1.Scope.Private,
56
- name: this.namingHelper.getPrivatePropName("name"),
57
- type: "string",
58
- initializer: `"${this.namingHelper.getODataServiceName()}"`,
59
- },
60
- ...this.generateEntityServiceResolverProp(container.entitySets, importContainer),
61
- ...this.generateServiceGettersByAssignment(container.entitySets),
62
- ...this.generateServiceTypeProps(container.singletons, this.namingHelper.getServiceName, importContainer),
63
- ...Object.values(unboundOperations).map(({ operation }) => this.generateQOperationProps(operation)),
64
- ],
65
- methods: [
66
- ...this.generateServiceTypeGetters(container.singletons, this.namingHelper.getServiceName),
67
- ...this.generateUnboundOperations(unboundOperations, importContainer),
68
- ],
55
+ properties /*: [
56
+ {
57
+ scope: Scope.Private,
58
+ name: this.namingHelper.getPrivatePropName("name"),
59
+ type: "string",
60
+ initializer: `"${this.namingHelper.getODataServiceName()}"`,
61
+ },
62
+ ]*/,
63
+ methods,
69
64
  });
70
65
  sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));
71
66
  });
72
67
  }
73
- generateEntityServiceResolverProp(services, importContainer) {
74
- return Object.values(services).map(({ name, entityType }) => {
75
- const resolverName = this.namingHelper.getServiceResolverName(entityType.name);
76
- importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), resolverName);
77
- return {
78
- name: this.namingHelper.getPublicPropNameForService(name),
79
- scope: ts_morph_1.Scope.Public,
80
- initializer: `${resolverName}(this.client, this.getPath(), "${name}")`,
81
- };
68
+ generateMainServiceProperties(container, importContainer) {
69
+ const result = { properties: [], methods: [] };
70
+ Object.values(container.entitySets).forEach(({ name, entityType }) => {
71
+ result.methods.push(this.generateRelatedServiceGetter(name, entityType, importContainer));
82
72
  });
83
- }
84
- generateServiceGettersByAssignment(services) {
85
- return Object.values(services).map(({ name, odataName, entityType }) => {
86
- const propName = this.namingHelper.getPublicPropNameForService(name);
87
- return {
88
- scope: ts_morph_1.Scope.Public,
89
- name: this.namingHelper.getRelatedServiceGetter(name),
90
- initializer: `this.${propName}.get.bind(this.${propName})`,
91
- };
73
+ Object.values(container.singletons).forEach((singleton) => {
74
+ result.properties.push(this.generateSingletonProp(singleton, importContainer));
75
+ result.methods.push(this.generateSingletonGetter(singleton));
92
76
  });
77
+ return result;
93
78
  }
94
- generateServiceTypeProps(services, typeRetriever, importContainer) {
95
- return Object.values(services).map(({ name, entityType }) => {
96
- const type = typeRetriever(entityType.name);
97
- importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), type);
98
- return {
99
- scope: ts_morph_1.Scope.Private,
100
- name: this.namingHelper.getPrivatePropName(name),
101
- type: `${type}<ClientType>`,
102
- hasQuestionToken: true,
103
- };
79
+ generateMainServiceOperations(ops, importContainer) {
80
+ const result = { properties: [], methods: [] };
81
+ ops.forEach(({ operation, name }) => {
82
+ result.properties.push(this.generateQOperationProp(operation));
83
+ result.methods.push(this.generateMethod(name, operation, importContainer));
104
84
  });
85
+ return result;
105
86
  }
106
- generateServiceTypeGetters(services, typeRetriever) {
107
- return Object.values(services).map(({ name, odataName, entityType }) => {
108
- const propName = "this." + this.namingHelper.getPrivatePropName(name);
109
- const serviceType = typeRetriever(entityType.name);
110
- return {
111
- scope: ts_morph_1.Scope.Public,
112
- name: this.namingHelper.getRelatedServiceGetter(name),
113
- statements: [
114
- `if(!${propName}) {`,
115
- // prettier-ignore
116
- ` ${propName} = new ${serviceType}(this.client, this.getPath(), "${odataName}")`,
117
- "}",
118
- `return ${propName}`,
119
- ],
120
- };
121
- });
87
+ generateRelatedServiceGetter(propName, entityType, importContainer, currentServiceName) {
88
+ const idName = entityType.idModelName;
89
+ const idFunctionName = entityType.qIdFunctionName;
90
+ const serviceName = this.namingHelper.getServiceName(entityType.name);
91
+ const collectionName = this.namingHelper.getCollectionServiceName(entityType.name);
92
+ importContainer.addFromClientApi("ODataClient");
93
+ importContainer.addGeneratedModel(idName);
94
+ importContainer.addGeneratedQObject(idFunctionName);
95
+ // make sure to not falsely import self-referential stuff
96
+ if (!currentServiceName || currentServiceName !== serviceName) {
97
+ importContainer.addGeneratedService(serviceName, collectionName, serviceName);
98
+ }
99
+ return {
100
+ scope: ts_morph_1.Scope.Public,
101
+ name: this.namingHelper.getRelatedServiceGetter(propName),
102
+ parameters: [
103
+ {
104
+ name: "id",
105
+ type: `${idName} | undefined`,
106
+ hasQuestionToken: true,
107
+ },
108
+ ],
109
+ overloads: [
110
+ {
111
+ parameters: [],
112
+ returnType: `${collectionName}<ClientType>`,
113
+ },
114
+ {
115
+ parameters: [
116
+ {
117
+ name: "id",
118
+ type: idName,
119
+ },
120
+ ],
121
+ returnType: `${serviceName}<ClientType>`,
122
+ },
123
+ ],
124
+ statements: [
125
+ `const fieldName = "${propName}";`,
126
+ 'return typeof id === "undefined" || id === null',
127
+ `? new ${collectionName}(this.client, this.getPath(), fieldName)`,
128
+ `: new ${serviceName}(this.client, this.getPath(), new ${idFunctionName}(fieldName).buildUrl(id));`,
129
+ ],
130
+ };
131
+ }
132
+ generateSingletonProp(singleton, importContainer) {
133
+ const { name, entityType } = singleton;
134
+ const type = this.namingHelper.getServiceName(entityType.name);
135
+ importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), type);
136
+ return {
137
+ scope: ts_morph_1.Scope.Private,
138
+ name: this.namingHelper.getPrivatePropName(name),
139
+ type: `${type}<ClientType>`,
140
+ hasQuestionToken: true,
141
+ };
142
+ }
143
+ generateSingletonGetter(singleton) {
144
+ const { name, odataName, entityType } = singleton;
145
+ const propName = "this." + this.namingHelper.getPrivatePropName(name);
146
+ const serviceType = this.namingHelper.getServiceName(entityType.name);
147
+ return {
148
+ scope: ts_morph_1.Scope.Public,
149
+ name: this.namingHelper.getRelatedServiceGetter(name),
150
+ statements: [
151
+ `if(!${propName}) {`,
152
+ // prettier-ignore
153
+ ` ${propName} = new ${serviceType}(this.client, this.getPath(), "${odataName}")`,
154
+ "}",
155
+ `return ${propName}`,
156
+ ],
157
+ };
122
158
  }
123
159
  getVersionSuffix() {
124
160
  return this.version === odata_core_1.ODataVersions.V2 ? "V2" : "V4";
125
161
  }
126
- generateModelService(model, serviceName, serviceFile, importContainer) {
162
+ generateEntityTypeService(model, serviceName, serviceFile, importContainer) {
127
163
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
128
164
  const entityServiceType = "EntityTypeService" + this.getVersionSuffix();
129
- const collectionServiceType = "CollectionService" + this.getVersionSuffix();
130
165
  const editableModelName = model.editableName;
166
+ const qObjectName = (0, processors_1.firstCharLowerCase)(model.qName);
131
167
  const operations = this.dataModel.getOperationTypeByBinding(model.name);
132
168
  const props = [...model.baseProps, ...model.props];
133
- const modelProps = props.filter((prop) => prop.dataType === "ModelType" /* DataTypes.ModelType */ || prop.dataType === "ComplexType" /* DataTypes.ComplexType */);
134
- const primColProps = props.filter((prop) => prop.isCollection && prop.dataType !== "ModelType" /* DataTypes.ModelType */ && prop.dataType !== "ComplexType" /* DataTypes.ComplexType */);
135
169
  importContainer.addFromService(entityServiceType);
136
170
  importContainer.addFromClientApi("ODataClient");
137
171
  importContainer.addGeneratedModel(model.name, editableModelName);
138
- importContainer.addGeneratedQObject(model.qName, (0, processors_1.firstCharLowerCase)(model.qName));
172
+ importContainer.addGeneratedQObject(model.qName, qObjectName);
173
+ const { properties, methods } = (0, deepmerge_1.default)(this.generateServiceProperties(serviceName, props, importContainer), this.generateServiceOperations(operations, importContainer));
139
174
  // generate EntityTypeService
140
175
  serviceFile.addClass({
141
176
  isExported: true,
@@ -149,119 +184,134 @@ class ServiceGenerator {
149
184
  { name: "basePath", type: "string" },
150
185
  { name: "name", type: "string" },
151
186
  ],
152
- statements: [`super(client, basePath, name, ${(0, processors_1.firstCharLowerCase)(model.qName)});`],
187
+ statements: [`super(client, basePath, name, ${qObjectName});`],
153
188
  },
154
189
  ],
155
- properties: [
156
- ...this.generateModelProps(modelProps, collectionServiceType, serviceName, importContainer),
157
- ...this.generatePrimitiveCollectionProps(primColProps, collectionServiceType, importContainer),
158
- ...operations.map(this.generateQOperationProps),
159
- ],
160
- methods: [
161
- ...this.generateModelPropGetters(modelProps, collectionServiceType),
162
- ...this.generatePrimitiveCollectionGetters(primColProps, collectionServiceType),
163
- ...this.generateBoundOperations(operations, importContainer),
164
- ],
190
+ properties,
191
+ methods,
165
192
  });
166
193
  });
167
194
  }
168
- generateModelProps(modelProps, collectionServiceType, serviceName, importContainer) {
169
- return modelProps.map((prop) => {
170
- const complexType = this.dataModel.getComplexType(prop.type);
171
- const key = this.namingHelper.getServiceName(prop.type);
172
- let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;
173
- if (prop.isCollection && complexType) {
174
- const editableName = complexType.editableName;
175
- importContainer.addFromService(collectionServiceType);
176
- importContainer.addGeneratedModel(complexType.name, editableName);
177
- importContainer.addGeneratedQObject(complexType.qName, (0, processors_1.firstCharLowerCase)(complexType.qName));
178
- propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;
195
+ generateServiceProperties(serviceName, props, importContainer) {
196
+ const collectionServiceType = "CollectionService" + this.getVersionSuffix();
197
+ const result = { properties: [], methods: [] };
198
+ props.forEach((prop) => {
199
+ if ((prop.dataType === "ModelType" /* DataTypes.ModelType */ && !prop.isCollection) || prop.dataType === "ComplexType" /* DataTypes.ComplexType */) {
200
+ result.properties.push(this.generateModelProp(prop, collectionServiceType, serviceName, importContainer));
201
+ result.methods.push(this.generateModelPropGetter(prop, collectionServiceType));
179
202
  }
180
- else {
181
- // don't include imports for this type
182
- if (serviceName !== key) {
183
- importContainer.addGeneratedService(key, propModelType);
203
+ else if (prop.isCollection) {
204
+ // collection of entity types
205
+ if (prop.dataType === "ModelType" /* DataTypes.ModelType */) {
206
+ const entityType = this.dataModel.getModel(prop.type);
207
+ result.methods.push(this.generateRelatedServiceGetter(prop.name, entityType, importContainer, serviceName));
208
+ }
209
+ // collection of primitive or complex types
210
+ else {
211
+ result.properties.push(this.generatePrimitiveCollectionProp(prop, collectionServiceType, importContainer));
212
+ result.methods.push(this.generatePrimitiveCollectionGetter(prop, collectionServiceType));
184
213
  }
185
- propModelType = `${propModelType}<ClientType>`;
186
214
  }
187
- return {
188
- scope: ts_morph_1.Scope.Private,
189
- name: this.namingHelper.getPrivatePropName(prop.name),
190
- type: propModelType,
191
- hasQuestionToken: true,
192
- };
193
215
  });
216
+ return result;
194
217
  }
195
- generatePrimitiveCollectionProps(primColProps, collectionServiceType, importContainer) {
196
- return primColProps.map((prop) => {
197
- const isEnum = prop.dataType === "EnumType" /* DataTypes.EnumType */;
198
- const type = isEnum ? `EnumCollection<${prop.type}>` : `${(0, upper_case_first_1.upperCaseFirst)(prop.type)}Collection`;
199
- const qType = isEnum ? "QEnumCollection" : `Q${type}`;
200
- const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;
201
- if (!prop.qObject) {
202
- throw new Error("Illegal State: [qObject] must be provided for Collection types!");
203
- }
218
+ generateServiceOperations(operations, importContainer) {
219
+ const result = { properties: [], methods: [] };
220
+ operations.forEach((operation) => {
221
+ result.properties.push(this.generateQOperationProp(operation));
222
+ result.methods.push(this.generateMethod(operation.name, operation, importContainer));
223
+ });
224
+ return result;
225
+ }
226
+ generateModelProp(prop, collectionServiceType, serviceName, importContainer) {
227
+ const complexType = this.dataModel.getComplexType(prop.type);
228
+ const key = this.namingHelper.getServiceName(prop.type);
229
+ let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;
230
+ if (prop.isCollection && complexType) {
231
+ const editableName = complexType.editableName;
204
232
  importContainer.addFromService(collectionServiceType);
205
- importContainer.addFromQObject(prop.qObject, (0, processors_1.firstCharLowerCase)(prop.qObject));
206
- if (isEnum) {
207
- importContainer.addGeneratedModel(prop.type);
208
- importContainer.addFromQObject("EnumCollection");
209
- }
210
- else {
211
- importContainer.addFromQObject(type);
233
+ importContainer.addGeneratedModel(complexType.name, editableName);
234
+ importContainer.addGeneratedQObject(complexType.qName, (0, processors_1.firstCharLowerCase)(complexType.qName));
235
+ propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;
236
+ }
237
+ else {
238
+ // don't include imports for this type
239
+ if (serviceName !== key) {
240
+ importContainer.addGeneratedService(key, propModelType);
212
241
  }
213
- return {
214
- scope: ts_morph_1.Scope.Private,
215
- name: this.namingHelper.getPrivatePropName(prop.name),
216
- type: `${collectionType}`,
217
- hasQuestionToken: true,
218
- };
219
- });
242
+ propModelType = `${propModelType}<ClientType>`;
243
+ }
244
+ return {
245
+ scope: ts_morph_1.Scope.Private,
246
+ name: this.namingHelper.getPrivatePropName(prop.name),
247
+ type: propModelType,
248
+ hasQuestionToken: true,
249
+ };
220
250
  }
221
- generateModelPropGetters(modelProps, collectionServiceType) {
222
- return modelProps.map((prop) => {
223
- const complexType = this.dataModel.getComplexType(prop.type);
224
- const isComplexCollection = prop.isCollection && complexType;
225
- const type = isComplexCollection
226
- ? collectionServiceType
227
- : prop.isCollection
228
- ? this.namingHelper.getCollectionServiceName(prop.type)
229
- : this.namingHelper.getServiceName(prop.type);
230
- const typeWithGenerics = isComplexCollection
231
- ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`
232
- : `${type}<ClientType>`;
233
- const privateSrvProp = "this." + this.namingHelper.getPrivatePropName(prop.name);
234
- return {
235
- scope: ts_morph_1.Scope.Public,
236
- name: this.namingHelper.getRelatedServiceGetter(prop.name),
237
- returnType: typeWithGenerics,
238
- statements: [
239
- `if(!${privateSrvProp}) {`,
240
- // prettier-ignore
241
- ` ${privateSrvProp} = new ${type}(this.client, this.getPath(), "${prop.odataName}"${isComplexCollection ? `, ${(0, processors_1.firstCharLowerCase)(complexType.qName)}` : ""})`,
242
- "}",
243
- `return ${privateSrvProp}`,
244
- ],
245
- };
246
- });
251
+ generatePrimitiveCollectionProp(prop, collectionServiceType, importContainer) {
252
+ const isEnum = prop.dataType === "EnumType" /* DataTypes.EnumType */;
253
+ const type = isEnum ? `EnumCollection<${prop.type}>` : `${(0, upper_case_first_1.upperCaseFirst)(prop.type)}Collection`;
254
+ const qType = isEnum ? "QEnumCollection" : `Q${type}`;
255
+ const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;
256
+ if (!prop.qObject) {
257
+ throw new Error("Illegal State: [qObject] must be provided for Collection types!");
258
+ }
259
+ importContainer.addFromService(collectionServiceType);
260
+ importContainer.addFromQObject(prop.qObject, (0, processors_1.firstCharLowerCase)(prop.qObject));
261
+ if (isEnum) {
262
+ importContainer.addGeneratedModel(prop.type);
263
+ importContainer.addFromQObject("EnumCollection");
264
+ }
265
+ else {
266
+ importContainer.addFromQObject(type);
267
+ }
268
+ return {
269
+ scope: ts_morph_1.Scope.Private,
270
+ name: this.namingHelper.getPrivatePropName(prop.name),
271
+ type: `${collectionType}`,
272
+ hasQuestionToken: true,
273
+ };
247
274
  }
248
- generatePrimitiveCollectionGetters(primColProps, collectionServiceType) {
249
- return primColProps.map((prop) => {
250
- const propName = "this." + this.namingHelper.getPrivatePropName(prop.name);
251
- return {
252
- scope: ts_morph_1.Scope.Public,
253
- name: this.namingHelper.getRelatedServiceGetter(prop.name),
254
- statements: [
255
- `if(!${propName}) {`,
256
- // prettier-ignore
257
- ` ${propName} = new ${collectionServiceType}(this.client, this.getPath(), "${prop.odataName}", ${(0, processors_1.firstCharLowerCase)(prop.qObject)})`,
258
- "}",
259
- `return ${propName}`,
260
- ],
261
- };
262
- });
275
+ generateModelPropGetter(prop, collectionServiceType) {
276
+ const complexType = this.dataModel.getComplexType(prop.type);
277
+ const isComplexCollection = prop.isCollection && complexType;
278
+ const type = isComplexCollection
279
+ ? collectionServiceType
280
+ : prop.isCollection
281
+ ? this.namingHelper.getCollectionServiceName(prop.type)
282
+ : this.namingHelper.getServiceName(prop.type);
283
+ const typeWithGenerics = isComplexCollection
284
+ ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`
285
+ : `${type}<ClientType>`;
286
+ const privateSrvProp = "this." + this.namingHelper.getPrivatePropName(prop.name);
287
+ return {
288
+ scope: ts_morph_1.Scope.Public,
289
+ name: this.namingHelper.getRelatedServiceGetter(prop.name),
290
+ returnType: typeWithGenerics,
291
+ statements: [
292
+ `if(!${privateSrvProp}) {`,
293
+ // prettier-ignore
294
+ ` ${privateSrvProp} = new ${type}(this.client, this.getPath(), "${prop.odataName}"${isComplexCollection ? `, ${(0, processors_1.firstCharLowerCase)(complexType.qName)}` : ""})`,
295
+ "}",
296
+ `return ${privateSrvProp}`,
297
+ ],
298
+ };
299
+ }
300
+ generatePrimitiveCollectionGetter(prop, collectionServiceType) {
301
+ const propName = "this." + this.namingHelper.getPrivatePropName(prop.name);
302
+ return {
303
+ scope: ts_morph_1.Scope.Public,
304
+ name: this.namingHelper.getRelatedServiceGetter(prop.name),
305
+ statements: [
306
+ `if(!${propName}) {`,
307
+ // prettier-ignore
308
+ ` ${propName} = new ${collectionServiceType}(this.client, this.getPath(), "${prop.odataName}", ${(0, processors_1.firstCharLowerCase)(prop.qObject)})`,
309
+ "}",
310
+ `return ${propName}`,
311
+ ],
312
+ };
263
313
  }
264
- generateEntityCollectionService(model, serviceName, serviceFile, importContainer) {
314
+ generateEntityCollectionService(model, serviceFile, importContainer) {
265
315
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
266
316
  const entitySetServiceType = "EntitySetService" + this.getVersionSuffix();
267
317
  const editableModelName = model.editableName;
@@ -270,12 +320,13 @@ class ServiceGenerator {
270
320
  importContainer.addGeneratedModel(model.idModelName);
271
321
  importContainer.addGeneratedQObject(model.qIdFunctionName);
272
322
  const collectionOperations = this.dataModel.getOperationTypeByBinding(`Collection(${model.name})`);
323
+ const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);
273
324
  serviceFile.addClass({
274
325
  isExported: true,
275
326
  name: this.namingHelper.getCollectionServiceName(model.name),
276
327
  typeParameters: ["ClientType extends ODataClient"],
277
328
  extends: entitySetServiceType +
278
- `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}, ${serviceName}<ClientType>>`,
329
+ `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}>`,
279
330
  ctors: [
280
331
  {
281
332
  parameters: [
@@ -283,44 +334,14 @@ class ServiceGenerator {
283
334
  { name: "basePath", type: "string" },
284
335
  { name: "name", type: "string" },
285
336
  ],
286
- statements: [
287
- `super(client, basePath, name, ${qObjectName}, ${serviceName}, new ${model.qIdFunctionName}(name));`,
288
- ],
337
+ statements: [`super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name));`],
289
338
  },
290
339
  ],
291
- properties: [...collectionOperations.map(this.generateQOperationProps)],
292
- methods: [...this.generateBoundOperations(collectionOperations, importContainer)],
340
+ properties,
341
+ methods,
293
342
  });
294
343
  });
295
344
  }
296
- generateEntityServiceResolver(model, serviceName, serviceFile, importContainer) {
297
- const idFunctionName = model.qIdFunctionName;
298
- const collectionName = this.namingHelper.getCollectionServiceName(model.name);
299
- importContainer.addFromClientApi("ODataClient");
300
- importContainer.addFromService("EntityServiceResolver");
301
- importContainer.addGeneratedQObject(idFunctionName);
302
- serviceFile.addFunction({
303
- name: this.namingHelper.getServiceResolverName(model.name),
304
- isExported: true,
305
- parameters: [
306
- {
307
- name: "client",
308
- type: "ODataClient",
309
- },
310
- {
311
- name: "basePath",
312
- type: "string",
313
- },
314
- {
315
- name: "entityName",
316
- type: "string",
317
- },
318
- ],
319
- statements: [
320
- `return new EntityServiceResolver(client, basePath, entityName, ${idFunctionName}, ${serviceName}, ${collectionName});`,
321
- ],
322
- });
323
- }
324
345
  generateModelServices() {
325
346
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
326
347
  // build service file for each entity, consisting of EntityTypeService & EntityCollectionService
@@ -329,11 +350,9 @@ class ServiceGenerator {
329
350
  const serviceFile = yield this.project.createServiceFile(serviceName);
330
351
  const importContainer = new ImportContainer_1.ImportContainer(this.namingHelper.getFileNames());
331
352
  // entity type service
332
- yield this.generateModelService(model, serviceName, serviceFile, importContainer);
353
+ yield this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);
333
354
  // entity collection service
334
- yield this.generateEntityCollectionService(model, serviceName, serviceFile, importContainer);
335
- // the resolver function
336
- yield this.generateEntityServiceResolver(model, serviceName, serviceFile, importContainer);
355
+ yield this.generateEntityCollectionService(model, serviceFile, importContainer);
337
356
  serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));
338
357
  }
339
358
  // build service file for complex types
@@ -342,23 +361,11 @@ class ServiceGenerator {
342
361
  const serviceFile = yield this.project.createServiceFile(serviceName);
343
362
  const importContainer = new ImportContainer_1.ImportContainer(this.namingHelper.getFileNames());
344
363
  // entity type service
345
- yield this.generateModelService(model, serviceName, serviceFile, importContainer);
364
+ yield this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);
346
365
  serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));
347
366
  }
348
367
  });
349
368
  }
350
- generateBoundOperations(operations, importContainer) {
351
- return operations.reduce((collector, operation) => {
352
- collector.push(this.generateMethod(operation.name, operation, importContainer));
353
- return collector;
354
- }, []);
355
- }
356
- generateUnboundOperations(operations, importContainer) {
357
- return Object.values(operations).reduce((collector, { name, operation }) => {
358
- collector.push(this.generateMethod(name, operation, importContainer));
359
- return collector;
360
- }, []);
361
- }
362
369
  generateMethod(name, operation, importContainer) {
363
370
  var _a, _b;
364
371
  const isFunc = operation.type === "Function" /* OperationTypes.Function */;