@odata2ts/odata2ts 0.21.0 → 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.
- package/CHANGELOG.md +12 -0
- package/lib/NamingModel.d.ts +4 -13
- package/lib/NamingModel.js.map +1 -1
- package/lib/data-model/NamingHelper.d.ts +0 -2
- package/lib/data-model/NamingHelper.js +0 -10
- package/lib/data-model/NamingHelper.js.map +1 -1
- package/lib/defaultConfig.js +1 -13
- package/lib/defaultConfig.js.map +1 -1
- package/lib/generator/ServiceGenerator.d.ts +3 -0
- package/lib/generator/ServiceGenerator.js +222 -215
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/package.json +4 -4
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.22.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.21.0...@odata2ts/odata2ts@0.22.0) (2023-04-27)
|
|
7
|
+
|
|
8
|
+
### Code Refactoring
|
|
9
|
+
|
|
10
|
+
* **odata2ts:** dispense with resolver & directly implement related services as getter ([9b49501](https://github.com/odata2ts/odata2ts/commit/9b49501e279b6c5869cbc5ac2fd246577780b81f))
|
|
11
|
+
|
|
12
|
+
### BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
* **odata2ts:** Changed defaults for properties representing related services: no prefix anymore, just the name of the property as function (previously, prefix `navTo`).
|
|
15
|
+
Removed `get` method of EntitySetServices: use property directly instead.
|
|
16
|
+
Removed the following naming options regarding generated services: `serviceResolverFunction`, `publicProps`
|
|
17
|
+
|
|
6
18
|
# [0.21.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.20.3...@odata2ts/odata2ts@0.21.0) (2023-04-20)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/lib/NamingModel.d.ts
CHANGED
|
@@ -160,16 +160,9 @@ export interface ServiceNamingOptions extends NamingStrategyOption, RequiredNami
|
|
|
160
160
|
applyServiceNaming?: boolean;
|
|
161
161
|
};
|
|
162
162
|
/**
|
|
163
|
-
* Naming for
|
|
163
|
+
* Naming for getter method of another service.
|
|
164
164
|
*
|
|
165
|
-
* By default,
|
|
166
|
-
* @example createTestEntityServiceResolver
|
|
167
|
-
*/
|
|
168
|
-
serviceResolverFunction: NamingStrategyOption & RequiredNamingOptions;
|
|
169
|
-
/**
|
|
170
|
-
* Naming for getter method. Another related service is returned.
|
|
171
|
-
*
|
|
172
|
-
* By default, prefix = "navTo" and namingStrategy = camelCase
|
|
165
|
+
* By default, namingStrategy = camelCase
|
|
173
166
|
*/
|
|
174
167
|
relatedServiceGetter: NamingStrategyOption & RequiredNamingOptions;
|
|
175
168
|
/**
|
|
@@ -182,10 +175,8 @@ export interface ServiceNamingOptions extends NamingStrategyOption, RequiredNami
|
|
|
182
175
|
operations?: NamingStrategyOption & OperationNamingOptions;
|
|
183
176
|
/**
|
|
184
177
|
* Naming options for private properties of service classes.
|
|
178
|
+
*
|
|
179
|
+
* By default, prefix = _
|
|
185
180
|
*/
|
|
186
181
|
privateProps: NamingStrategyOption & RequiredNamingOptions;
|
|
187
|
-
/**
|
|
188
|
-
* Naming options for public properties of service classes.
|
|
189
|
-
*/
|
|
190
|
-
publicProps?: NamingStrategyOption;
|
|
191
182
|
}
|
package/lib/NamingModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NamingModel.js","sourceRoot":"","sources":["../src/NamingModel.ts"],"names":[],"mappings":";;;AAKA,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,6BAAS,CAAA;IACT,8CAA0B,CAAA;IAC1B,4CAAwB,CAAA;IACxB,kDAA8B,CAAA;IAC9B,4CAAwB,CAAA;AAC1B,CAAC,EANW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAM3B","sourcesContent":["/**\r\n * The available naming strategies.\r\n */\r\nimport { PartialDeep } from \"type-fest\";\r\n\r\nexport enum NamingStrategies {\r\n NONE = \"\",\r\n PASCAL_CASE = \"pascalCase\",\r\n CAMEL_CASE = \"camelCase\",\r\n CONSTANT_CASE = \"constantCase\",\r\n SNAKE_CASE = \"snakeCase\",\r\n}\r\n\r\n/**\r\n * Based on an existing configuration (for example default settings) the user only specifies what needs\r\n * to be changed. Hence, all options are completely optional.\r\n */\r\nexport interface OverridableNamingOptions extends PartialDeep<NameSettings> {}\r\n\r\n/**\r\n * The required and optional name settings for the generator.\r\n */\r\nexport interface NameSettings {\r\n /**\r\n * Because multiple artefacts are generated out of the same entity, some name settings are required in order\r\n * to differentiate those artefacts. Out-of-the-box odata2ts provides you with sensible default settings,\r\n * so that you only need to override those settings you want to change.\r\n *\r\n * However, sometimes it makes more sense to start from scratch, so that the defaults don't interfere with\r\n * your own configuration. In this scenario this switch should be enabled to only have default values for\r\n * the required name settings.\r\n */\r\n minimalDefaults?: boolean;\r\n\r\n /**\r\n * Generation options for models, i.e. interfaces representing entity or complex types.\r\n */\r\n models: ModelNamingOptions;\r\n\r\n /**\r\n * Generation options for Query Objects.\r\n *\r\n * By default, prefix = \"Q\"\r\n */\r\n queryObjects: QueryObjectNamingOptions;\r\n\r\n services: ServiceNamingOptions;\r\n}\r\n\r\nexport interface ModelNamingOptions extends NamingStrategyOption, StandardNamingOptions {\r\n /**\r\n * All generated models are bundled into one file.\r\n * This option specifies the formatting of the file name.\r\n */\r\n fileName: FileNamingStrategyOption & RequiredNamingOptions;\r\n\r\n /**\r\n * Choose a specific strategy to format property names of models: pascal-case, camel-case, etc.\r\n * By default, camel-case.\r\n */\r\n propNamingStrategy?: NamingStrategies;\r\n\r\n /**\r\n * For each model an editable version is generated which represents the model definition for\r\n * create, update and patch actions.\r\n *\r\n * You can override the naming options here.\r\n * By default, prefix = \"Editable\"\r\n */\r\n editableModels: EntityDerivedNamingOptions;\r\n\r\n /**\r\n * ID models are generated from entity id parameters.\r\n *\r\n * You can configure the naming options here.\r\n * By default, suffix = \"Id\"\r\n */\r\n idModels: EntityDerivedNamingOptions;\r\n\r\n /**\r\n * Operation parameter models are generated from function or action signatures.\r\n *\r\n * You can configure the naming options here.\r\n * By default, suffix = \"Params\"\r\n */\r\n operationParamModels: EntityDerivedNamingOptions;\r\n}\r\n\r\nexport interface EntityDerivedNamingOptions extends RequiredNamingOptions {\r\n applyModelNaming?: boolean;\r\n}\r\n\r\nexport interface QueryObjectNamingOptions extends NamingStrategyOption, RequiredNamingOptions {\r\n /**\r\n * All generated models are bundled into one file.\r\n * This option specifies the formatting of the file name.\r\n */\r\n fileName: FileNamingStrategyOption & RequiredNamingOptions;\r\n\r\n /**\r\n * Choose a specific strategy to format property names of query objects: pascal-case, camel-case, etc.\r\n * By default, camel-case.\r\n */\r\n propNamingStrategy?: NamingStrategies;\r\n\r\n idFunctions: RequiredNamingOptions;\r\n\r\n operations?: OperationNamingOptions;\r\n}\r\n\r\nexport interface OperationNamingOptions extends StandardNamingOptions {\r\n /**\r\n * Naming options for actions only.\r\n * When this configuration is provided, the parent configuration regarding suffix and prefix is ignored.\r\n */\r\n action?: StandardNamingOptions;\r\n /**\r\n * Naming options for functions only.\r\n * When this configuration is provided, the parent configuration regarding suffix and prefix is ignored.\r\n */\r\n function?: StandardNamingOptions;\r\n}\r\n\r\nexport interface NamingStrategyOption {\r\n /**\r\n * Choose a specific strategy to format names: pascal-case, camel-case, etc.\r\n * Defaults to pascal-case.\r\n */\r\n namingStrategy?: NamingStrategies;\r\n}\r\n\r\nexport interface FileNamingStrategyOption {\r\n /**\r\n * Choose a specific strategy to format names: pascal-case, camel-case, etc.\r\n * Defaults to pascal-case.\r\n */\r\n namingStrategy?: NamingStrategies;\r\n}\r\n\r\nexport interface StandardNamingOptions {\r\n /**\r\n * Prefix all names, e.g. \"I\" => \"ITest\"\r\n */\r\n prefix?: string;\r\n /**\r\n * Suffix all names, e.g. \"model\" => \"TestModel\"\r\n */\r\n suffix?: string;\r\n}\r\n\r\nexport interface RequiredNamingOptions extends Required<StandardNamingOptions> {}\r\n\r\n/**\r\n * Naming options for generated service classes.\r\n * These options affect the main service as well as all services generated for each entity, complex and collection type.\r\n *\r\n * There exists one specialty about services: The file names are not configurable.\r\n * File names are determined by the name of their corresponding classes, so that service file name\r\n * and service class name always correspond.\r\n *\r\n * By default, suffix = Service and namingStrategy = PascalCase\r\n */\r\nexport interface ServiceNamingOptions extends NamingStrategyOption, RequiredNamingOptions {\r\n /**\r\n * Controls the naming options for the main odata service.\r\n * By default, the base service naming options are applied.\r\n * But since this is the main entry point for users, it can be configured individually here.\r\n *\r\n * By default, applyServiceNaming = true\r\n */\r\n main?: NamingStrategyOption & StandardNamingOptions & { applyServiceNaming?: boolean };\r\n\r\n /**\r\n * Name of the service responsible for entity collections.\r\n *\r\n * By default, suffix = Collection and applyServiceNaming = true\r\n */\r\n collection: RequiredNamingOptions & { applyServiceNaming?: boolean };\r\n\r\n /**\r\n * Naming for
|
|
1
|
+
{"version":3,"file":"NamingModel.js","sourceRoot":"","sources":["../src/NamingModel.ts"],"names":[],"mappings":";;;AAKA,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,6BAAS,CAAA;IACT,8CAA0B,CAAA;IAC1B,4CAAwB,CAAA;IACxB,kDAA8B,CAAA;IAC9B,4CAAwB,CAAA;AAC1B,CAAC,EANW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAM3B","sourcesContent":["/**\r\n * The available naming strategies.\r\n */\r\nimport { PartialDeep } from \"type-fest\";\r\n\r\nexport enum NamingStrategies {\r\n NONE = \"\",\r\n PASCAL_CASE = \"pascalCase\",\r\n CAMEL_CASE = \"camelCase\",\r\n CONSTANT_CASE = \"constantCase\",\r\n SNAKE_CASE = \"snakeCase\",\r\n}\r\n\r\n/**\r\n * Based on an existing configuration (for example default settings) the user only specifies what needs\r\n * to be changed. Hence, all options are completely optional.\r\n */\r\nexport interface OverridableNamingOptions extends PartialDeep<NameSettings> {}\r\n\r\n/**\r\n * The required and optional name settings for the generator.\r\n */\r\nexport interface NameSettings {\r\n /**\r\n * Because multiple artefacts are generated out of the same entity, some name settings are required in order\r\n * to differentiate those artefacts. Out-of-the-box odata2ts provides you with sensible default settings,\r\n * so that you only need to override those settings you want to change.\r\n *\r\n * However, sometimes it makes more sense to start from scratch, so that the defaults don't interfere with\r\n * your own configuration. In this scenario this switch should be enabled to only have default values for\r\n * the required name settings.\r\n */\r\n minimalDefaults?: boolean;\r\n\r\n /**\r\n * Generation options for models, i.e. interfaces representing entity or complex types.\r\n */\r\n models: ModelNamingOptions;\r\n\r\n /**\r\n * Generation options for Query Objects.\r\n *\r\n * By default, prefix = \"Q\"\r\n */\r\n queryObjects: QueryObjectNamingOptions;\r\n\r\n services: ServiceNamingOptions;\r\n}\r\n\r\nexport interface ModelNamingOptions extends NamingStrategyOption, StandardNamingOptions {\r\n /**\r\n * All generated models are bundled into one file.\r\n * This option specifies the formatting of the file name.\r\n */\r\n fileName: FileNamingStrategyOption & RequiredNamingOptions;\r\n\r\n /**\r\n * Choose a specific strategy to format property names of models: pascal-case, camel-case, etc.\r\n * By default, camel-case.\r\n */\r\n propNamingStrategy?: NamingStrategies;\r\n\r\n /**\r\n * For each model an editable version is generated which represents the model definition for\r\n * create, update and patch actions.\r\n *\r\n * You can override the naming options here.\r\n * By default, prefix = \"Editable\"\r\n */\r\n editableModels: EntityDerivedNamingOptions;\r\n\r\n /**\r\n * ID models are generated from entity id parameters.\r\n *\r\n * You can configure the naming options here.\r\n * By default, suffix = \"Id\"\r\n */\r\n idModels: EntityDerivedNamingOptions;\r\n\r\n /**\r\n * Operation parameter models are generated from function or action signatures.\r\n *\r\n * You can configure the naming options here.\r\n * By default, suffix = \"Params\"\r\n */\r\n operationParamModels: EntityDerivedNamingOptions;\r\n}\r\n\r\nexport interface EntityDerivedNamingOptions extends RequiredNamingOptions {\r\n applyModelNaming?: boolean;\r\n}\r\n\r\nexport interface QueryObjectNamingOptions extends NamingStrategyOption, RequiredNamingOptions {\r\n /**\r\n * All generated models are bundled into one file.\r\n * This option specifies the formatting of the file name.\r\n */\r\n fileName: FileNamingStrategyOption & RequiredNamingOptions;\r\n\r\n /**\r\n * Choose a specific strategy to format property names of query objects: pascal-case, camel-case, etc.\r\n * By default, camel-case.\r\n */\r\n propNamingStrategy?: NamingStrategies;\r\n\r\n idFunctions: RequiredNamingOptions;\r\n\r\n operations?: OperationNamingOptions;\r\n}\r\n\r\nexport interface OperationNamingOptions extends StandardNamingOptions {\r\n /**\r\n * Naming options for actions only.\r\n * When this configuration is provided, the parent configuration regarding suffix and prefix is ignored.\r\n */\r\n action?: StandardNamingOptions;\r\n /**\r\n * Naming options for functions only.\r\n * When this configuration is provided, the parent configuration regarding suffix and prefix is ignored.\r\n */\r\n function?: StandardNamingOptions;\r\n}\r\n\r\nexport interface NamingStrategyOption {\r\n /**\r\n * Choose a specific strategy to format names: pascal-case, camel-case, etc.\r\n * Defaults to pascal-case.\r\n */\r\n namingStrategy?: NamingStrategies;\r\n}\r\n\r\nexport interface FileNamingStrategyOption {\r\n /**\r\n * Choose a specific strategy to format names: pascal-case, camel-case, etc.\r\n * Defaults to pascal-case.\r\n */\r\n namingStrategy?: NamingStrategies;\r\n}\r\n\r\nexport interface StandardNamingOptions {\r\n /**\r\n * Prefix all names, e.g. \"I\" => \"ITest\"\r\n */\r\n prefix?: string;\r\n /**\r\n * Suffix all names, e.g. \"model\" => \"TestModel\"\r\n */\r\n suffix?: string;\r\n}\r\n\r\nexport interface RequiredNamingOptions extends Required<StandardNamingOptions> {}\r\n\r\n/**\r\n * Naming options for generated service classes.\r\n * These options affect the main service as well as all services generated for each entity, complex and collection type.\r\n *\r\n * There exists one specialty about services: The file names are not configurable.\r\n * File names are determined by the name of their corresponding classes, so that service file name\r\n * and service class name always correspond.\r\n *\r\n * By default, suffix = Service and namingStrategy = PascalCase\r\n */\r\nexport interface ServiceNamingOptions extends NamingStrategyOption, RequiredNamingOptions {\r\n /**\r\n * Controls the naming options for the main odata service.\r\n * By default, the base service naming options are applied.\r\n * But since this is the main entry point for users, it can be configured individually here.\r\n *\r\n * By default, applyServiceNaming = true\r\n */\r\n main?: NamingStrategyOption & StandardNamingOptions & { applyServiceNaming?: boolean };\r\n\r\n /**\r\n * Name of the service responsible for entity collections.\r\n *\r\n * By default, suffix = Collection and applyServiceNaming = true\r\n */\r\n collection: RequiredNamingOptions & { applyServiceNaming?: boolean };\r\n\r\n /**\r\n * Naming for getter method of another service.\r\n *\r\n * By default, namingStrategy = camelCase\r\n */\r\n relatedServiceGetter: NamingStrategyOption & RequiredNamingOptions;\r\n\r\n /**\r\n * Operations are functions and actions of the OData service and are represented as methods\r\n * of the generated service class. This setting controls the naming of the corresponding\r\n * function.\r\n *\r\n * By default, namingStrategy = camelCase\r\n */\r\n operations?: NamingStrategyOption & OperationNamingOptions;\r\n\r\n /**\r\n * Naming options for private properties of service classes.\r\n *\r\n * By default, prefix = _\r\n */\r\n privateProps: NamingStrategyOption & RequiredNamingOptions;\r\n}\r\n"]}
|
|
@@ -48,10 +48,8 @@ export declare class NamingHelper {
|
|
|
48
48
|
getMainServiceName(): string;
|
|
49
49
|
getServiceName: (name: string) => string;
|
|
50
50
|
getCollectionServiceName: (name: string) => string;
|
|
51
|
-
getServiceResolverName: (name: string) => string;
|
|
52
51
|
getFunctionName(name: string): string;
|
|
53
52
|
getActionName(name: string): string;
|
|
54
53
|
getRelatedServiceGetter(name: string): string;
|
|
55
|
-
getPublicPropNameForService(name: string): string;
|
|
56
54
|
getPrivatePropName: (name: string) => string;
|
|
57
55
|
}
|
|
@@ -37,11 +37,6 @@ class NamingHelper {
|
|
|
37
37
|
const result = this.getName(name, strategy, opts === null || opts === void 0 ? void 0 : opts.collection);
|
|
38
38
|
return ((_a = opts === null || opts === void 0 ? void 0 : opts.collection) === null || _a === void 0 ? void 0 : _a.applyServiceNaming) ? this.getName(result, strategy, opts) : result;
|
|
39
39
|
};
|
|
40
|
-
this.getServiceResolverName = (name) => {
|
|
41
|
-
var _a;
|
|
42
|
-
const opts = (_a = this.options.services) === null || _a === void 0 ? void 0 : _a.serviceResolverFunction;
|
|
43
|
-
return this.getName(name, this.namingFunction(opts === null || opts === void 0 ? void 0 : opts.namingStrategy), opts);
|
|
44
|
-
};
|
|
45
40
|
this.getPrivatePropName = (name) => {
|
|
46
41
|
var _a;
|
|
47
42
|
const opts = (_a = this.options.services) === null || _a === void 0 ? void 0 : _a.privateProps;
|
|
@@ -215,11 +210,6 @@ class NamingHelper {
|
|
|
215
210
|
const opts = (_a = this.options.services) === null || _a === void 0 ? void 0 : _a.relatedServiceGetter;
|
|
216
211
|
return this.getName(name, this.namingFunction(opts === null || opts === void 0 ? void 0 : opts.namingStrategy), opts);
|
|
217
212
|
}
|
|
218
|
-
getPublicPropNameForService(name) {
|
|
219
|
-
var _a;
|
|
220
|
-
const opts = (_a = this.options.services) === null || _a === void 0 ? void 0 : _a.publicProps;
|
|
221
|
-
return this.getName(name, this.namingFunction(opts === null || opts === void 0 ? void 0 : opts.namingStrategy));
|
|
222
|
-
}
|
|
223
213
|
}
|
|
224
214
|
exports.NamingHelper = NamingHelper;
|
|
225
215
|
//# sourceMappingURL=NamingHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NamingHelper.js","sourceRoot":"","sources":["../../src/data-model/NamingHelper.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,iDAA6C;AAC7C,6CAAyC;AACzC,2CAAuC;AAEvC,gDAAiH;AAGjH,SAAS,qBAAqB,CAAC,QAAsC;IACnE,QAAQ,QAAQ,EAAE;QAChB,KAAK,8BAAgB,CAAC,UAAU;YAC9B,OAAO,sBAAS,CAAC;QACnB,KAAK,8BAAgB,CAAC,WAAW;YAC/B,OAAO,wBAAU,CAAC;QACpB,KAAK,8BAAgB,CAAC,aAAa;YACjC,OAAO,4BAAY,CAAC;QACtB,KAAK,8BAAgB,CAAC,UAAU;YAC9B,OAAO,sBAA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,IAAI,CAAC,cAAc,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,CAAC,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC;IAEM,2BAA2B,CAAC,IAAY;;QAC7C,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,0CAAE,WAAW,CAAC;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,CAAC,CAAC,CAAC;IACvE,CAAC;CAMF;AA/ND,oCA+NC","sourcesContent":["import { camelCase } from \"camel-case\";\r\nimport { constantCase } from \"constant-case\";\r\nimport { pascalCase } from \"pascal-case\";\r\nimport { snakeCase } from \"snake-case\";\r\n\r\nimport { FileNamingStrategyOption, NameSettings, NamingStrategies, StandardNamingOptions } from \"../NamingModel\";\r\nimport { RunOptions } from \"../OptionModel\";\r\n\r\nfunction getNamingStrategyImpl(strategy: NamingStrategies | undefined) {\r\n switch (strategy) {\r\n case NamingStrategies.CAMEL_CASE:\r\n return camelCase;\r\n case NamingStrategies.PASCAL_CASE:\r\n return pascalCase;\r\n case NamingStrategies.CONSTANT_CASE:\r\n return constantCase;\r\n case NamingStrategies.SNAKE_CASE:\r\n return snakeCase;\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\nconst noopNamingFunction = (value: string, options?: StandardNamingOptions) => {\r\n return (options?.prefix || \"\") + value + (options?.suffix || \"\");\r\n};\r\n\r\nexport interface NamingHelperSettings extends Pick<RunOptions, \"allowRenaming\" | \"naming\"> {}\r\n\r\nexport class NamingHelper {\r\n private readonly allowModelPropRenaming: boolean;\r\n private readonly serviceName: string;\r\n private readonly servicePrefix: string;\r\n private readonly options: NameSettings;\r\n\r\n constructor(options: NamingHelperSettings, serviceName: string, overridingServiceName?: string) {\r\n if (!options) {\r\n throw new Error(\"NamingHelper: Options must be supplied!\");\r\n }\r\n if (!serviceName?.trim()) {\r\n throw new Error(\"NamingHelper: ServicePrefix must be supplied!\");\r\n }\r\n\r\n this.allowModelPropRenaming = options.allowRenaming ?? false;\r\n this.options = options.naming || {};\r\n this.servicePrefix = serviceName + \".\";\r\n this.serviceName = overridingServiceName || serviceName;\r\n }\r\n\r\n /**\r\n * The prefix used to reference model or enum types in this schema.\r\n *\r\n * @returns service prefix\r\n */\r\n public getServicePrefix() {\r\n return this.servicePrefix;\r\n }\r\n\r\n /**\r\n * The OData service name as it was found and is used in metadata file.\r\n *\r\n * @returns\r\n */\r\n public getODataServiceName() {\r\n return this.serviceName;\r\n }\r\n\r\n public getFileNames() {\r\n return {\r\n model: this.getFileName(this.options.models?.fileName),\r\n qObject: this.getFileName(this.options.queryObjects?.fileName),\r\n service: this.getMainServiceName(),\r\n };\r\n }\r\n\r\n private getFileName(opts?: FileNamingStrategyOption & StandardNamingOptions) {\r\n return this.getName(this.serviceName, this.namingFunction(opts?.namingStrategy), opts);\r\n }\r\n\r\n public getFileNameService(name: string) {\r\n const opts = this.options.services;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n }\r\n\r\n public stripServicePrefix(token: string) {\r\n return token.replace(this.servicePrefix, \"\");\r\n }\r\n\r\n private namingFunction(strategy: NamingStrategies | undefined) {\r\n const strategyFn = getNamingStrategyImpl(strategy);\r\n if (!strategyFn || !this.allowModelPropRenaming) {\r\n return noopNamingFunction;\r\n }\r\n\r\n return (value: string, options?: StandardNamingOptions) => {\r\n const prefix = options?.prefix;\r\n const suffix = options?.suffix;\r\n const isPrefixSpecialChar = prefix?.startsWith(\"_\");\r\n const isSuffixSpecialChar = suffix?.endsWith(\"_\");\r\n\r\n let result = strategyFn((prefix ? prefix + \"_\" : \"\") + value + (suffix ? \"_\" + suffix : \"\"));\r\n if (isPrefixSpecialChar) {\r\n result = \"_\" + result;\r\n }\r\n if (isSuffixSpecialChar) {\r\n result = result + \"_\";\r\n }\r\n return result;\r\n };\r\n }\r\n\r\n private getName(\r\n name: string,\r\n strategy: (value: string, options?: StandardNamingOptions) => string,\r\n options?: StandardNamingOptions\r\n ) {\r\n return strategy(this.stripServicePrefix(name), options);\r\n }\r\n\r\n private getModelNamingStrategy() {\r\n return this.namingFunction(this.options.models?.namingStrategy);\r\n }\r\n\r\n private getModelPropNamingStrategy() {\r\n return this.namingFunction(this.options.models?.propNamingStrategy);\r\n }\r\n\r\n private getQObjectNamingStrategy() {\r\n return this.namingFunction(this.options.queryObjects?.namingStrategy);\r\n }\r\n\r\n private getQObjectPropNamingStrategy() {\r\n return this.namingFunction(this.options.queryObjects?.propNamingStrategy);\r\n }\r\n\r\n private getOperationNamingStrategy() {\r\n return this.namingFunction(this.options.services?.operations?.namingStrategy);\r\n }\r\n\r\n public getModelName(name: string): string {\r\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\r\n }\r\n\r\n public getModelPropName(name: string): string {\r\n return this.getName(name, this.getModelPropNamingStrategy());\r\n }\r\n\r\n public getEnumName(name: string) {\r\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\r\n }\r\n\r\n public getEditableModelName(name: string) {\r\n let options = this.options.models?.editableModels;\r\n const result = this.getName(name, this.getModelNamingStrategy(), options);\r\n return options?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n }\r\n\r\n public getIdModelName(name: string) {\r\n let options = this.options.models?.idModels;\r\n const result = this.getName(name, this.getModelNamingStrategy(), options);\r\n return options?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n }\r\n\r\n public getOperationParamsModelName(name: string) {\r\n const settings = this.options.models?.operationParamModels;\r\n const result = this.getName(name, this.getModelNamingStrategy(), settings);\r\n return settings?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n }\r\n\r\n public getQName(name: string) {\r\n return this.getName(name, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getQPropName(name: string): string {\r\n return this.getName(name, this.getQObjectPropNamingStrategy());\r\n }\r\n\r\n public getQIdFunctionName(name: string) {\r\n const opts = this.options.queryObjects?.idFunctions;\r\n const result = this.getName(name, this.getQObjectNamingStrategy(), opts);\r\n return this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getQFunctionName(name: string) {\r\n const opts = this.options.queryObjects?.operations;\r\n const result = this.getName(name, this.getQObjectNamingStrategy(), opts?.function || opts);\r\n return this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getQActionName(name: string) {\r\n const opts = this.options.queryObjects?.operations;\r\n const result = this.getName(name, this.getQObjectNamingStrategy(), opts?.action || opts);\r\n return this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getMainServiceName() {\r\n const name = this.getODataServiceName();\r\n const opts = this.options.services;\r\n const strategy = this.namingFunction(\r\n opts?.main?.namingStrategy ?? (opts?.main?.applyServiceNaming ? opts.namingStrategy : undefined)\r\n );\r\n const result = this.getName(name, strategy, opts?.main);\r\n return opts?.main?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\r\n }\r\n\r\n public getServiceName = (name: string) => {\r\n const opts = this.options.services;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n };\r\n\r\n public getCollectionServiceName = (name: string) => {\r\n const opts = this.options.services;\r\n const strategy = this.namingFunction(opts?.namingStrategy);\r\n const result = this.getName(name, strategy, opts?.collection);\r\n return opts?.collection?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\r\n };\r\n\r\n public getServiceResolverName = (name: string) => {\r\n const opts = this.options.services?.serviceResolverFunction;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n };\r\n\r\n public getFunctionName(name: string) {\r\n const opts = this.options.services?.operations;\r\n return this.getName(name, this.getOperationNamingStrategy(), opts?.function || opts);\r\n }\r\n\r\n public getActionName(name: string) {\r\n const opts = this.options.services?.operations;\r\n return this.getName(name, this.getOperationNamingStrategy(), opts?.action || opts);\r\n }\r\n\r\n public getRelatedServiceGetter(name: string) {\r\n const opts = this.options.services?.relatedServiceGetter;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n }\r\n\r\n public getPublicPropNameForService(name: string) {\r\n const opts = this.options.services?.publicProps;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy));\r\n }\r\n\r\n public getPrivatePropName = (name: string) => {\r\n const opts = this.options.services?.privateProps;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"NamingHelper.js","sourceRoot":"","sources":["../../src/data-model/NamingHelper.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,iDAA6C;AAC7C,6CAAyC;AACzC,2CAAuC;AAEvC,gDAAiH;AAGjH,SAAS,qBAAqB,CAAC,QAAsC;IACnE,QAAQ,QAAQ,EAAE;QAChB,KAAK,8BAAgB,CAAC,UAAU;YAC9B,OAAO,sBAAS,CAAC;QACnB,KAAK,8BAAgB,CAAC,WAAW;YAC/B,OAAO,wBAAU,CAAC;QACpB,KAAK,8BAAgB,CAAC,aAAa;YACjC,OAAO,4BAAY,CAAC;QACtB,KAAK,8BAAgB,CAAC,UAAU;YAC9B,OAAO,sBAAS,CAAC;QACnB;YACE,OAAO,SAAS,CAAC;KACpB;AACH,CAAC;AAED,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAE,OAA+B,EAAE,EAAE;IAC5E,OAAO,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,KAAI,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,KAAI,EAAE,CAAC,CAAC;AACnE,CAAC,CAAC;AAIF,MAAa,YAAY;IAMvB,YAAY,OAA6B,EAAE,WAAmB,EAAE,qBAA8B;;QAgLvF,mBAAc,GAAG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E,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,KAAI,IAAI,CAAC,CAAC;IACvF,CAAC;IAEM,aAAa,CAAC,IAAY;;QAC/B,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,0CAAE,UAAU,CAAC;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,KAAI,IAAI,CAAC,CAAC;IACrF,CAAC;IAEM,uBAAuB,CAAC,IAAY;;QACzC,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,0CAAE,oBAAoB,CAAC;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,CAAC,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC;CAMF;AArND,oCAqNC","sourcesContent":["import { camelCase } from \"camel-case\";\r\nimport { constantCase } from \"constant-case\";\r\nimport { pascalCase } from \"pascal-case\";\r\nimport { snakeCase } from \"snake-case\";\r\n\r\nimport { FileNamingStrategyOption, NameSettings, NamingStrategies, StandardNamingOptions } from \"../NamingModel\";\r\nimport { RunOptions } from \"../OptionModel\";\r\n\r\nfunction getNamingStrategyImpl(strategy: NamingStrategies | undefined) {\r\n switch (strategy) {\r\n case NamingStrategies.CAMEL_CASE:\r\n return camelCase;\r\n case NamingStrategies.PASCAL_CASE:\r\n return pascalCase;\r\n case NamingStrategies.CONSTANT_CASE:\r\n return constantCase;\r\n case NamingStrategies.SNAKE_CASE:\r\n return snakeCase;\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\nconst noopNamingFunction = (value: string, options?: StandardNamingOptions) => {\r\n return (options?.prefix || \"\") + value + (options?.suffix || \"\");\r\n};\r\n\r\nexport interface NamingHelperSettings extends Pick<RunOptions, \"allowRenaming\" | \"naming\"> {}\r\n\r\nexport class NamingHelper {\r\n private readonly allowModelPropRenaming: boolean;\r\n private readonly serviceName: string;\r\n private readonly servicePrefix: string;\r\n private readonly options: NameSettings;\r\n\r\n constructor(options: NamingHelperSettings, serviceName: string, overridingServiceName?: string) {\r\n if (!options) {\r\n throw new Error(\"NamingHelper: Options must be supplied!\");\r\n }\r\n if (!serviceName?.trim()) {\r\n throw new Error(\"NamingHelper: ServicePrefix must be supplied!\");\r\n }\r\n\r\n this.allowModelPropRenaming = options.allowRenaming ?? false;\r\n this.options = options.naming || {};\r\n this.servicePrefix = serviceName + \".\";\r\n this.serviceName = overridingServiceName || serviceName;\r\n }\r\n\r\n /**\r\n * The prefix used to reference model or enum types in this schema.\r\n *\r\n * @returns service prefix\r\n */\r\n public getServicePrefix() {\r\n return this.servicePrefix;\r\n }\r\n\r\n /**\r\n * The OData service name as it was found and is used in metadata file.\r\n *\r\n * @returns\r\n */\r\n public getODataServiceName() {\r\n return this.serviceName;\r\n }\r\n\r\n public getFileNames() {\r\n return {\r\n model: this.getFileName(this.options.models?.fileName),\r\n qObject: this.getFileName(this.options.queryObjects?.fileName),\r\n service: this.getMainServiceName(),\r\n };\r\n }\r\n\r\n private getFileName(opts?: FileNamingStrategyOption & StandardNamingOptions) {\r\n return this.getName(this.serviceName, this.namingFunction(opts?.namingStrategy), opts);\r\n }\r\n\r\n public getFileNameService(name: string) {\r\n const opts = this.options.services;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n }\r\n\r\n public stripServicePrefix(token: string) {\r\n return token.replace(this.servicePrefix, \"\");\r\n }\r\n\r\n private namingFunction(strategy: NamingStrategies | undefined) {\r\n const strategyFn = getNamingStrategyImpl(strategy);\r\n if (!strategyFn || !this.allowModelPropRenaming) {\r\n return noopNamingFunction;\r\n }\r\n\r\n return (value: string, options?: StandardNamingOptions) => {\r\n const prefix = options?.prefix;\r\n const suffix = options?.suffix;\r\n const isPrefixSpecialChar = prefix?.startsWith(\"_\");\r\n const isSuffixSpecialChar = suffix?.endsWith(\"_\");\r\n\r\n let result = strategyFn((prefix ? prefix + \"_\" : \"\") + value + (suffix ? \"_\" + suffix : \"\"));\r\n if (isPrefixSpecialChar) {\r\n result = \"_\" + result;\r\n }\r\n if (isSuffixSpecialChar) {\r\n result = result + \"_\";\r\n }\r\n return result;\r\n };\r\n }\r\n\r\n private getName(\r\n name: string,\r\n strategy: (value: string, options?: StandardNamingOptions) => string,\r\n options?: StandardNamingOptions\r\n ) {\r\n return strategy(this.stripServicePrefix(name), options);\r\n }\r\n\r\n private getModelNamingStrategy() {\r\n return this.namingFunction(this.options.models?.namingStrategy);\r\n }\r\n\r\n private getModelPropNamingStrategy() {\r\n return this.namingFunction(this.options.models?.propNamingStrategy);\r\n }\r\n\r\n private getQObjectNamingStrategy() {\r\n return this.namingFunction(this.options.queryObjects?.namingStrategy);\r\n }\r\n\r\n private getQObjectPropNamingStrategy() {\r\n return this.namingFunction(this.options.queryObjects?.propNamingStrategy);\r\n }\r\n\r\n private getOperationNamingStrategy() {\r\n return this.namingFunction(this.options.services?.operations?.namingStrategy);\r\n }\r\n\r\n public getModelName(name: string): string {\r\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\r\n }\r\n\r\n public getModelPropName(name: string): string {\r\n return this.getName(name, this.getModelPropNamingStrategy());\r\n }\r\n\r\n public getEnumName(name: string) {\r\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\r\n }\r\n\r\n public getEditableModelName(name: string) {\r\n let options = this.options.models?.editableModels;\r\n const result = this.getName(name, this.getModelNamingStrategy(), options);\r\n return options?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n }\r\n\r\n public getIdModelName(name: string) {\r\n let options = this.options.models?.idModels;\r\n const result = this.getName(name, this.getModelNamingStrategy(), options);\r\n return options?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n }\r\n\r\n public getOperationParamsModelName(name: string) {\r\n const settings = this.options.models?.operationParamModels;\r\n const result = this.getName(name, this.getModelNamingStrategy(), settings);\r\n return settings?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n }\r\n\r\n public getQName(name: string) {\r\n return this.getName(name, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getQPropName(name: string): string {\r\n return this.getName(name, this.getQObjectPropNamingStrategy());\r\n }\r\n\r\n public getQIdFunctionName(name: string) {\r\n const opts = this.options.queryObjects?.idFunctions;\r\n const result = this.getName(name, this.getQObjectNamingStrategy(), opts);\r\n return this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getQFunctionName(name: string) {\r\n const opts = this.options.queryObjects?.operations;\r\n const result = this.getName(name, this.getQObjectNamingStrategy(), opts?.function || opts);\r\n return this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getQActionName(name: string) {\r\n const opts = this.options.queryObjects?.operations;\r\n const result = this.getName(name, this.getQObjectNamingStrategy(), opts?.action || opts);\r\n return this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getMainServiceName() {\r\n const name = this.getODataServiceName();\r\n const opts = this.options.services;\r\n const strategy = this.namingFunction(\r\n opts?.main?.namingStrategy ?? (opts?.main?.applyServiceNaming ? opts.namingStrategy : undefined)\r\n );\r\n const result = this.getName(name, strategy, opts?.main);\r\n return opts?.main?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\r\n }\r\n\r\n public getServiceName = (name: string) => {\r\n const opts = this.options.services;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n };\r\n\r\n public getCollectionServiceName = (name: string) => {\r\n const opts = this.options.services;\r\n const strategy = this.namingFunction(opts?.namingStrategy);\r\n const result = this.getName(name, strategy, opts?.collection);\r\n return opts?.collection?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\r\n };\r\n\r\n public getFunctionName(name: string) {\r\n const opts = this.options.services?.operations;\r\n return this.getName(name, this.getOperationNamingStrategy(), opts?.function || opts);\r\n }\r\n\r\n public getActionName(name: string) {\r\n const opts = this.options.services?.operations;\r\n return this.getName(name, this.getOperationNamingStrategy(), opts?.action || opts);\r\n }\r\n\r\n public getRelatedServiceGetter(name: string) {\r\n const opts = this.options.services?.relatedServiceGetter;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n }\r\n\r\n public getPrivatePropName = (name: string) => {\r\n const opts = this.options.services?.privateProps;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n };\r\n}\r\n"]}
|
package/lib/defaultConfig.js
CHANGED
|
@@ -73,17 +73,12 @@ const defaultConfig = {
|
|
|
73
73
|
suffix: "Collection",
|
|
74
74
|
applyServiceNaming: true,
|
|
75
75
|
},
|
|
76
|
-
serviceResolverFunction: {
|
|
77
|
-
namingStrategy: NamingModel_1.NamingStrategies.CAMEL_CASE,
|
|
78
|
-
prefix: "create",
|
|
79
|
-
suffix: "serviceResolver",
|
|
80
|
-
},
|
|
81
76
|
operations: {
|
|
82
77
|
namingStrategy: NamingModel_1.NamingStrategies.CAMEL_CASE,
|
|
83
78
|
},
|
|
84
79
|
relatedServiceGetter: {
|
|
85
80
|
namingStrategy: NamingModel_1.NamingStrategies.CAMEL_CASE,
|
|
86
|
-
prefix: "
|
|
81
|
+
prefix: "",
|
|
87
82
|
suffix: "",
|
|
88
83
|
},
|
|
89
84
|
privateProps: {
|
|
@@ -91,9 +86,6 @@ const defaultConfig = {
|
|
|
91
86
|
prefix: "_",
|
|
92
87
|
suffix: "",
|
|
93
88
|
},
|
|
94
|
-
publicProps: {
|
|
95
|
-
namingStrategy: NamingModel_1.NamingStrategies.PASCAL_CASE,
|
|
96
|
-
},
|
|
97
89
|
},
|
|
98
90
|
},
|
|
99
91
|
propertiesByName: [],
|
|
@@ -153,10 +145,6 @@ const minimalNamingConfig = {
|
|
|
153
145
|
prefix: services.relatedServiceGetter.prefix,
|
|
154
146
|
suffix: services.relatedServiceGetter.suffix,
|
|
155
147
|
},
|
|
156
|
-
serviceResolverFunction: {
|
|
157
|
-
prefix: services.serviceResolverFunction.prefix,
|
|
158
|
-
suffix: services.serviceResolverFunction.suffix,
|
|
159
|
-
},
|
|
160
148
|
},
|
|
161
149
|
};
|
|
162
150
|
/**
|
package/lib/defaultConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.ts"],"names":[],"mappings":";;;;AAAA,kEAAkC;AAElC,+CAA+D;AAC/D,+CAA6D;AAE7D;;GAEG;AACH,MAAM,aAAa,GAA0C;IAC3D,IAAI,EAAE,mBAAK,CAAC,GAAG;IACf,QAAQ,EAAE,uBAAS,CAAC,MAAM;IAC1B,KAAK,EAAE,KAAK;IACZ,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,eAAe;IACzB,UAAU,EAAE,EAAE;IACd,kBAAkB,EAAE,KAAK;IACzB,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,KAAK;IACrB,qBAAqB,EAAE,KAAK;IAC5B,aAAa,EAAE,KAAK;IACpB,gCAAgC,EAAE,KAAK;IACvC,MAAM,EAAE;QACN,MAAM,EAAE;YACN,cAAc,EAAE,8BAAgB,CAAC,WAAW;YAC5C,kBAAkB,EAAE,8BAAgB,CAAC,UAAU;YAC/C,cAAc,EAAE;gBACd,MAAM,EAAE,UAAU;gBAClB,MAAM,EAAE,EAAE;gBACV,gBAAgB,EAAE,IAAI;aACvB;YACD,QAAQ,EAAE;gBACR,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE,IAAI;gBACZ,gBAAgB,EAAE,IAAI;aACvB;YACD,oBAAoB,EAAE;gBACpB,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE,QAAQ;gBAChB,gBAAgB,EAAE,IAAI;aACvB;YACD,QAAQ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W,CAAC,MAAM;SACxC;KACF;IACD,QAAQ,EAAE;QACR,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,IAAI,EAAE;YACJ,kBAAkB,EAAE,IAAI;SACzB;QACD,UAAU,EAAE;YACV,kBAAkB,EAAE,IAAI;YACxB,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM;YAClC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM;SACnC;QACD,YAAY,EAAE;YACZ,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,MAAM;YACpC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,MAAM;SACrC;QACD,oBAAoB,EAAE;YACpB,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,MAAM;YAC5C,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,MAAM;SAC7C;KACF;CACF,CAAC;AAEF;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,mBAAS,EAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAFD,4CAEC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,MAAM,EAAE,MAAM,KAAqB,aAAa,EAA7B,WAAW,kBAAK,aAAa,EAA1C,UAA0B,CAAgB,CAAC;IACjD,OAAO,IAAA,mBAAS,EAAC,WAAW,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;AACjE,CAAC;AAHD,4CAGC","sourcesContent":["import deepmerge from \"deepmerge\";\r\n\r\nimport { NameSettings, NamingStrategies } from \"./NamingModel\";\r\nimport { EmitModes, Modes, RunOptions } from \"./OptionModel\";\r\n\r\n/**\r\n * The default configuration.\r\n */\r\nconst defaultConfig: Omit<RunOptions, \"source\" | \"output\"> = {\r\n mode: Modes.all,\r\n emitMode: EmitModes.js_dts,\r\n debug: false,\r\n prettier: false,\r\n tsconfig: \"tsconfig.json\",\r\n converters: [],\r\n skipEditableModels: false,\r\n skipIdModels: false,\r\n skipOperations: false,\r\n disableAutoManagedKey: false,\r\n allowRenaming: false,\r\n v2ModelsWithExtraResultsWrapping: false,\r\n naming: {\r\n models: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n editableModels: {\r\n prefix: \"Editable\",\r\n suffix: \"\",\r\n applyModelNaming: true,\r\n },\r\n idModels: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n applyModelNaming: true,\r\n },\r\n operationParamModels: {\r\n prefix: \"\",\r\n suffix: \"Params\",\r\n applyModelNaming: true,\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"\",\r\n suffix: \"Model\",\r\n },\r\n },\r\n queryObjects: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n idFunctions: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n },\r\n },\r\n services: {\r\n prefix: \"\",\r\n suffix: \"Service\",\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n prefix: \"\",\r\n suffix: \"Collection\",\r\n applyServiceNaming: true,\r\n },\r\n operations: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n },\r\n relatedServiceGetter: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"\",\r\n suffix: \"\",\r\n },\r\n privateProps: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"_\",\r\n suffix: \"\",\r\n },\r\n },\r\n },\r\n propertiesByName: [],\r\n entitiesByName: [],\r\n};\r\n\r\nconst { models, queryObjects, services } = defaultConfig.naming;\r\nconst minimalNamingConfig: NameSettings = {\r\n models: {\r\n fileName: {\r\n prefix: models.fileName.prefix,\r\n suffix: models.fileName.suffix,\r\n },\r\n idModels: {\r\n applyModelNaming: true,\r\n prefix: models.idModels.prefix,\r\n suffix: models.idModels.suffix,\r\n },\r\n editableModels: {\r\n applyModelNaming: true,\r\n prefix: models.editableModels.prefix,\r\n suffix: models.editableModels.suffix,\r\n },\r\n operationParamModels: {\r\n applyModelNaming: true,\r\n prefix: models.operationParamModels.prefix,\r\n suffix: models.operationParamModels.suffix,\r\n },\r\n },\r\n queryObjects: {\r\n prefix: queryObjects.prefix,\r\n suffix: queryObjects.suffix,\r\n fileName: {\r\n prefix: queryObjects.fileName.prefix,\r\n suffix: queryObjects.fileName.suffix,\r\n },\r\n idFunctions: {\r\n prefix: queryObjects.idFunctions.prefix,\r\n suffix: queryObjects.idFunctions.suffix,\r\n },\r\n },\r\n services: {\r\n prefix: services.prefix,\r\n suffix: services.suffix,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n applyServiceNaming: true,\r\n prefix: services.collection.prefix,\r\n suffix: services.collection.suffix,\r\n },\r\n privateProps: {\r\n prefix: services.privateProps.prefix,\r\n suffix: services.privateProps.suffix,\r\n },\r\n relatedServiceGetter: {\r\n prefix: services.relatedServiceGetter.prefix,\r\n suffix: services.relatedServiceGetter.suffix,\r\n },\r\n },\r\n};\r\n\r\n/**\r\n * Creates a defensive copy of the default config.\r\n */\r\nexport function getDefaultConfig(): Omit<RunOptions, \"source\" | \"output\"> {\r\n return deepmerge(defaultConfig, {});\r\n}\r\n\r\n/**\r\n * Creates a defensive copy of the minimal config: minimal in respect to naming.\r\n */\r\nexport function getMinimalConfig(): Omit<RunOptions, \"source\" | \"output\"> {\r\n const { naming, ...passThrough } = defaultConfig;\r\n return deepmerge(passThrough, { naming: minimalNamingConfig });\r\n}\r\n"]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ODataVersions } from "@odata2ts/odata-core";
|
|
2
|
+
import { ClassDeclarationStructure } from "ts-morph";
|
|
2
3
|
import { DataModel } from "../data-model/DataModel";
|
|
3
4
|
import { NamingHelper } from "../data-model/NamingHelper";
|
|
4
5
|
import { ProjectManager } from "../project/ProjectManager";
|
|
6
|
+
export interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, "properties" | "methods">> {
|
|
7
|
+
}
|
|
5
8
|
export declare function generateServices(dataModel: DataModel, project: ProjectManager, version: ODataVersions, namingHelper: NamingHelper): Promise<void>;
|
|
@@ -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.
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
85
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
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,
|
|
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, ${
|
|
187
|
+
statements: [`super(client, basePath, name, ${qObjectName});`],
|
|
153
188
|
},
|
|
154
189
|
],
|
|
155
|
-
properties
|
|
156
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
//
|
|
182
|
-
if (
|
|
183
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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,
|
|
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}
|
|
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
|
|
292
|
-
methods
|
|
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.
|
|
353
|
+
yield this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);
|
|
333
354
|
// entity collection service
|
|
334
|
-
yield this.generateEntityCollectionService(model,
|
|
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.
|
|
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 */;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceGenerator.js","sourceRoot":"","sources":["../../src/generator/ServiceGenerator.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AACrD,uCAAqH;AACrH,uDAAkD;AAClD,sDAA2D;AAiB3D,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;AAEF,SAAsB,gBAAgB,CACpC,SAAoB,EAC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AQ,EAAE,IAAI,EAAE,SAAS,CAAC,eAAe,EAAE,EAAE,kBAAkB,CAAC;gBAC3E,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACxB,UAAU,EAAE,iBAAiB,SAAS,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,KAAI,MAAM,IAAI;YACxE,UAAU,EAAE;gBACV,OAAO,OAAO,KAAK;gBACnB,KAAK,OAAO,UAAU,SAAS,CAAC,KAAK,IAAI;gBACzC,GAAG;gBAEH,gCAAgC,OAAO,aAAa,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK;gBAC5F,GAAG,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,QAAQ,gBAClD,CAAC,MAAM;oBACL,CAAC,CAAC,oBAAoB;wBACpB,aAAa,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,4BAA4B,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,CAAC,IAAI,GAAG;oBACvG,CAAC,CAAC,SAAS,CAAC,OAAO;wBACnB,CAAC,CAAC,sFAAsF;4BACtF,wBAAwB,kBAAkB,CAAC,IAAI,GAAG;wBACpD,CAAC,CAAC,sBAAsB;4BACtB,YAAY,kBAAkB,CAAC,IAAI,GACzC,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 { MethodDeclarationStructure, OptionalKind, PropertyDeclarationStructure, Scope, SourceFile } 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 EntitySetType,\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 { 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 async function generateServices(\r\n dataModel: DataModel,\r\n project: ProjectManager,\r\n version: ODataVersions,\r\n namingHelper: NamingHelper\r\n) {\r\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper);\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 ) {}\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 await this.generateModelServices();\r\n\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n importContainer.addFromClientApi(\"ODataClient\");\r\n importContainer.addFromService(ROOT_SERVICE);\r\n\r\n sourceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataClient\"],\r\n extends: `${ROOT_SERVICE}<ClientType>`,\r\n properties: [\r\n {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(\"name\"),\r\n type: \"string\",\r\n initializer: `\"${this.namingHelper.getODataServiceName()}\"`,\r\n },\r\n ...this.generateEntityServiceResolverProp(container.entitySets, importContainer),\r\n ...this.generateServiceGettersByAssignment(container.entitySets),\r\n ...this.generateServiceTypeProps(container.singletons, this.namingHelper.getServiceName, importContainer),\r\n ...Object.values(unboundOperations).map(({ operation }) => this.generateQOperationProps(operation)),\r\n ],\r\n methods: [\r\n ...this.generateServiceTypeGetters(container.singletons, this.namingHelper.getServiceName),\r\n ...this.generateUnboundOperations(unboundOperations, importContainer),\r\n ],\r\n });\r\n\r\n sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\r\n }\r\n\r\n private generateEntityServiceResolverProp(\r\n services: Record<string, EntitySetType>,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure>[] {\r\n return Object.values(services).map(({ name, entityType }) => {\r\n const resolverName = this.namingHelper.getServiceResolverName(entityType.name);\r\n\r\n importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), resolverName);\r\n\r\n return {\r\n name: this.namingHelper.getPublicPropNameForService(name),\r\n scope: Scope.Public,\r\n initializer: `${resolverName}(this.client, this.getPath(), \"${name}\")`,\r\n };\r\n });\r\n }\r\n\r\n private generateServiceGettersByAssignment(\r\n services: Record<string, EntitySetType>\r\n ): OptionalKind<PropertyDeclarationStructure>[] {\r\n return Object.values(services).map(({ name, odataName, entityType }) => {\r\n const propName = this.namingHelper.getPublicPropNameForService(name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(name),\r\n initializer: `this.${propName}.get.bind(this.${propName})`,\r\n };\r\n });\r\n }\r\n\r\n private generateServiceTypeProps(\r\n services: Record<string, SingletonType | EntitySetType>,\r\n typeRetriever: (name: string) => string,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure>[] {\r\n return Object.values(services).map(({ name, entityType }) => {\r\n const type = typeRetriever(entityType.name);\r\n\r\n importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), type);\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\r\n private generateQOperationProps = (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 generateServiceTypeGetters(\r\n services: Record<string, SingletonType | EntitySetType>,\r\n typeRetriever: (name: string) => string\r\n ): OptionalKind<MethodDeclarationStructure>[] {\r\n return Object.values(services).map(({ name, odataName, entityType }) => {\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(name);\r\n const serviceType = typeRetriever(entityType.name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n // prettier-ignore\r\n ` ${propName} = new ${serviceType}(this.client, this.getPath(), \"${odataName}\")`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\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 generateModelService(\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 const collectionServiceType = \"CollectionService\" + this.getVersionSuffix();\r\n\r\n const editableModelName = model.editableName;\r\n const operations = this.dataModel.getOperationTypeByBinding(model.name);\r\n const props = [...model.baseProps, ...model.props];\r\n const modelProps = props.filter(\r\n (prop) => prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType\r\n );\r\n const primColProps = props.filter(\r\n (prop) => prop.isCollection && prop.dataType !== DataTypes.ModelType && prop.dataType !== DataTypes.ComplexType\r\n );\r\n\r\n importContainer.addFromService(entityServiceType);\r\n importContainer.addFromClientApi(\"ODataClient\");\r\n importContainer.addGeneratedModel(model.name, editableModelName);\r\n importContainer.addGeneratedQObject(model.qName, firstCharLowerCase(model.qName));\r\n\r\n // generate EntityTypeService\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataClient\"],\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, ${firstCharLowerCase(model.qName)});`],\r\n },\r\n ],\r\n properties: [\r\n ...this.generateModelProps(modelProps, collectionServiceType, serviceName, importContainer),\r\n ...this.generatePrimitiveCollectionProps(primColProps, collectionServiceType, importContainer),\r\n ...operations.map(this.generateQOperationProps),\r\n ],\r\n methods: [\r\n ...this.generateModelPropGetters(modelProps, collectionServiceType),\r\n ...this.generatePrimitiveCollectionGetters(primColProps, collectionServiceType),\r\n ...this.generateBoundOperations(operations, importContainer),\r\n ],\r\n });\r\n }\r\n\r\n private generateModelProps(\r\n modelProps: Array<PropertyModel>,\r\n collectionServiceType: string,\r\n serviceName: string,\r\n importContainer: ImportContainer\r\n ): Array<PropertyDeclarationStructure> {\r\n return modelProps.map((prop) => {\r\n const complexType = this.dataModel.getComplexType(prop.type);\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 // don't include imports for this type\r\n if (serviceName !== key) {\r\n importContainer.addGeneratedService(key, propModelType);\r\n }\r\n\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\r\n private generatePrimitiveCollectionProps(\r\n primColProps: Array<PropertyModel>,\r\n collectionServiceType: string,\r\n importContainer: ImportContainer\r\n ): Array<PropertyDeclarationStructure> {\r\n return primColProps.map((prop) => {\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\" : `Q${type}`;\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 } as PropertyDeclarationStructure;\r\n });\r\n }\r\n\r\n private generateModelPropGetters(\r\n modelProps: Array<PropertyModel>,\r\n collectionServiceType: string\r\n ): Array<MethodDeclarationStructure> {\r\n return modelProps.map((prop) => {\r\n const complexType = this.dataModel.getComplexType(prop.type);\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 // prettier-ignore\r\n ` ${privateSrvProp} = new ${type}(this.client, this.getPath(), \"${prop.odataName}\"${isComplexCollection ? `, ${firstCharLowerCase(complexType.qName)}`: \"\"})`,\r\n \"}\",\r\n `return ${privateSrvProp}`,\r\n ],\r\n } as MethodDeclarationStructure;\r\n });\r\n }\r\n\r\n private generatePrimitiveCollectionGetters(\r\n primColProps: Array<PropertyModel>,\r\n collectionServiceType: string\r\n ): Array<MethodDeclarationStructure> {\r\n return primColProps.map((prop) => {\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 // prettier-ignore\r\n ` ${propName} = new ${collectionServiceType}(this.client, this.getPath(), \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n } as MethodDeclarationStructure;\r\n });\r\n }\r\n\r\n private async generateEntityCollectionService(\r\n model: ModelType,\r\n serviceName: string,\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.getOperationTypeByBinding(`Collection(${model.name})`);\r\n\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: this.namingHelper.getCollectionServiceName(model.name),\r\n typeParameters: [\"ClientType extends ODataClient\"],\r\n extends:\r\n entitySetServiceType +\r\n `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}, ${serviceName}<ClientType>>`,\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}, ${serviceName}, new ${model.qIdFunctionName}(name));`,\r\n ],\r\n },\r\n ],\r\n properties: [...collectionOperations.map(this.generateQOperationProps)],\r\n methods: [...this.generateBoundOperations(collectionOperations, importContainer)],\r\n });\r\n }\r\n\r\n private generateEntityServiceResolver(\r\n model: ModelType,\r\n serviceName: string,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const idFunctionName = model.qIdFunctionName;\r\n const collectionName = this.namingHelper.getCollectionServiceName(model.name);\r\n\r\n importContainer.addFromClientApi(\"ODataClient\");\r\n importContainer.addFromService(\"EntityServiceResolver\");\r\n importContainer.addGeneratedQObject(idFunctionName);\r\n\r\n serviceFile.addFunction({\r\n name: this.namingHelper.getServiceResolverName(model.name),\r\n isExported: true,\r\n parameters: [\r\n {\r\n name: \"client\",\r\n type: \"ODataClient\",\r\n },\r\n {\r\n name: \"basePath\",\r\n type: \"string\",\r\n },\r\n {\r\n name: \"entityName\",\r\n type: \"string\",\r\n },\r\n ],\r\n statements: [\r\n `return new EntityServiceResolver(client, basePath, entityName, ${idFunctionName}, ${serviceName}, ${collectionName});`,\r\n ],\r\n });\r\n }\r\n\r\n private async generateModelServices() {\r\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\r\n for (const model of this.dataModel.getModels()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n const serviceFile = await this.project.createServiceFile(serviceName);\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n // entity type service\r\n await this.generateModelService(model, serviceName, serviceFile, importContainer);\r\n\r\n // entity collection service\r\n await this.generateEntityCollectionService(model, serviceName, serviceFile, importContainer);\r\n\r\n // the resolver function\r\n await this.generateEntityServiceResolver(model, serviceName, serviceFile, importContainer);\r\n\r\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\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 const serviceFile = await this.project.createServiceFile(serviceName);\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n // entity type service\r\n await this.generateModelService(model, serviceName, serviceFile, importContainer);\r\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\r\n }\r\n }\r\n\r\n private generateBoundOperations(operations: Array<OperationType>, importContainer: ImportContainer) {\r\n return operations.reduce<Array<OptionalKind<MethodDeclarationStructure>>>((collector, operation) => {\r\n collector.push(this.generateMethod(operation.name, operation, importContainer));\r\n\r\n return collector;\r\n }, []);\r\n }\r\n\r\n private generateUnboundOperations(\r\n operations: Array<FunctionImportType | ActionImportType>,\r\n importContainer: ImportContainer\r\n ) {\r\n return Object.values(operations).reduce<Array<OptionalKind<MethodDeclarationStructure>>>(\r\n (collector, { name, operation }) => {\r\n collector.push(this.generateMethod(name, operation, importContainer));\r\n\r\n return collector;\r\n },\r\n []\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 = { name: \"requestConfig\", hasQuestionToken: true, type: \"ODataClientConfig<ClientType>\" };\r\n const hasParams = operation.parameters.length > 0;\r\n\r\n // importing dependencies\r\n importContainer.addFromClientApi(\"ODataClientConfig\", \"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 url = this.addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\r\n `${returnType ? \"const response = await \" : \"return\"} this.client.${\r\n !isFunc\r\n ? // actions: since V4\r\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${requestConfigParam.name})`\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})`\r\n : // functions: since V2\r\n `get(url, ${requestConfigParam.name})`\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;AAmB3D,uDAAoD;AAEpD,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,MAAM,cAAc,GAAG;IACrB,UAAU,EAAE,yBAAyB;IACrC,KAAK,EAAE,oBAAoB;IAC3B,KAAK,EAAE,oBAAoB;C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,UAAU,uBAAV,UAAU,CAAE,IAAI,KAAI,MAAM,IAAI;YACxE,UAAU,EAAE;gBACV,OAAO,OAAO,KAAK;gBACnB,KAAK,OAAO,UAAU,SAAS,CAAC,KAAK,IAAI;gBACzC,GAAG;gBAEH,gCAAgC,OAAO,aAAa,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK;gBAC5F,GAAG,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,QAAQ,gBAClD,CAAC,MAAM;oBACL,CAAC,CAAC,oBAAoB;wBACpB,aAAa,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,4BAA4B,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,CAAC,IAAI,GAAG;oBACvG,CAAC,CAAC,SAAS,CAAC,OAAO;wBACnB,CAAC,CAAC,sFAAsF;4BACtF,wBAAwB,kBAAkB,CAAC,IAAI,GAAG;wBACpD,CAAC,CAAC,sBAAsB;4BACtB,YAAY,kBAAkB,CAAC,IAAI,GACzC,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 EntitySetType,\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 { EntityType } from \"../data-model/edmx/ODataEdmxModelBase\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\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 async function generateServices(\r\n dataModel: DataModel,\r\n project: ProjectManager,\r\n version: ODataVersions,\r\n namingHelper: NamingHelper\r\n) {\r\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper);\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 ) {}\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 await this.generateModelServices();\r\n\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n importContainer.addFromClientApi(\"ODataClient\");\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 ODataClient\"],\r\n extends: `${ROOT_SERVICE}<ClientType>`,\r\n properties /*: [\r\n {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(\"name\"),\r\n type: \"string\",\r\n initializer: `\"${this.namingHelper.getODataServiceName()}\"`,\r\n },\r\n ]*/,\r\n methods,\r\n });\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, entityType }) => {\r\n result.methods.push(this.generateRelatedServiceGetter(name, 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 result.properties.push(this.generateQOperationProp(operation));\r\n result.methods.push(this.generateMethod(name, operation, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateRelatedServiceGetter(\r\n propName: string,\r\n entityType: ModelType,\r\n importContainer: ImportContainer,\r\n currentServiceName?: string\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(\"ODataClient\");\r\n importContainer.addGeneratedModel(idName);\r\n importContainer.addGeneratedQObject(idFunctionName);\r\n // make sure to not falsely import self-referential stuff\r\n if (!currentServiceName || currentServiceName !== serviceName) {\r\n importContainer.addGeneratedService(serviceName, collectionName, serviceName);\r\n }\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 = \"${propName}\";`,\r\n 'return typeof id === \"undefined\" || id === null',\r\n `? new ${collectionName}(this.client, this.getPath(), fieldName)`,\r\n `: new ${serviceName}(this.client, this.getPath(), 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 importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), type);\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 // prettier-ignore\r\n ` ${propName} = new ${serviceType}(this.client, this.getPath(), \"${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.getOperationTypeByBinding(model.name);\r\n const props = [...model.baseProps, ...model.props];\r\n\r\n importContainer.addFromService(entityServiceType);\r\n importContainer.addFromClientApi(\"ODataClient\");\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 ODataClient\"],\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});`],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\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.getModel(prop.type);\r\n result.methods.push(this.generateRelatedServiceGetter(prop.name, entityType, importContainer, serviceName));\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 }\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.type);\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 // don't include imports for this type\r\n if (serviceName !== key) {\r\n importContainer.addGeneratedService(key, propModelType);\r\n }\r\n\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\" : `Q${type}`;\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 generateModelPropGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const complexType = this.dataModel.getComplexType(prop.type);\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 // prettier-ignore\r\n ` ${privateSrvProp} = new ${type}(this.client, this.getPath(), \"${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 // prettier-ignore\r\n ` ${propName} = new ${collectionServiceType}(this.client, this.getPath(), \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)})`,\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.getOperationTypeByBinding(`Collection(${model.name})`);\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 ODataClient\"],\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: [`super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name));`],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private async generateModelServices() {\r\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\r\n for (const model of this.dataModel.getModels()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n const serviceFile = await this.project.createServiceFile(serviceName);\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\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 serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\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 const serviceFile = await this.project.createServiceFile(serviceName);\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n // entity type service\r\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\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 = { name: \"requestConfig\", hasQuestionToken: true, type: \"ODataClientConfig<ClientType>\" };\r\n const hasParams = operation.parameters.length > 0;\r\n\r\n // importing dependencies\r\n importContainer.addFromClientApi(\"ODataClientConfig\", \"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 url = this.addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\r\n `${returnType ? \"const response = await \" : \"return\"} this.client.${\r\n !isFunc\r\n ? // actions: since V4\r\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${requestConfigParam.name})`\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})`\r\n : // functions: since V2\r\n `get(url, ${requestConfigParam.name})`\r\n };`,\r\n returnType ? `return ${qOpProp}.convertResponse(response);` : \"\",\r\n ],\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.22.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@odata2ts/odata-client-api": "^0.6.3",
|
|
49
49
|
"@odata2ts/odata-query-objects": "^0.17.3",
|
|
50
|
-
"@odata2ts/odata-service": "^0.
|
|
50
|
+
"@odata2ts/odata-service": "^0.14.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@odata2ts/converter-api": "^0.1.2",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"@odata2ts/converter-v2-to-v4": "^0.1.4",
|
|
74
74
|
"@odata2ts/odata-client-api": "^0.6.3",
|
|
75
75
|
"@odata2ts/odata-query-objects": "^0.17.3",
|
|
76
|
-
"@odata2ts/odata-service": "^0.
|
|
76
|
+
"@odata2ts/odata-service": "^0.14.0",
|
|
77
77
|
"@types/fs-extra": "^9.0.13",
|
|
78
78
|
"@types/jest": "^27.4.1",
|
|
79
79
|
"@types/node": "^17.0.23",
|
|
@@ -87,6 +87,6 @@
|
|
|
87
87
|
"typescript": "^4.9.4"
|
|
88
88
|
},
|
|
89
89
|
"types": "./lib/index.d.ts",
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "420744615c73f04791c365869ad0258cd4a9d237",
|
|
91
91
|
"readme": "README.md"
|
|
92
92
|
}
|