@odata2ts/odata2ts 0.20.3 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/lib/FactoryFunctionModel.d.ts +2 -2
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/NamingModel.d.ts +4 -13
- package/lib/NamingModel.js.map +1 -1
- package/lib/OptionModel.d.ts +14 -0
- package/lib/OptionModel.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 +2 -13
- package/lib/defaultConfig.js.map +1 -1
- package/lib/evaluateConfig.js +9 -4
- package/lib/evaluateConfig.js.map +1 -1
- package/lib/generator/ModelGenerator.js +7 -1
- package/lib/generator/ModelGenerator.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,24 @@
|
|
|
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
|
+
|
|
18
|
+
# [0.21.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.20.3...@odata2ts/odata2ts@0.21.0) (2023-04-20)
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* option for extra-results-wrapping for V2 services and model generation only ([#155](https://github.com/odata2ts/odata2ts/issues/155)) ([795a04c](https://github.com/odata2ts/odata2ts/commit/795a04c42b9e2485975b85b70bc72772bd4bf25a))
|
|
23
|
+
|
|
6
24
|
## [0.20.3](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.20.2...@odata2ts/odata2ts@0.20.3) (2023-04-18)
|
|
7
25
|
|
|
8
26
|
### Bug Fixes
|
|
@@ -4,10 +4,10 @@ import { DataModel } from "./data-model/DataModel";
|
|
|
4
4
|
import { Schema } from "./data-model/edmx/ODataEdmxModelBase";
|
|
5
5
|
import { NamingHelper } from "./data-model/NamingHelper";
|
|
6
6
|
import { RunOptions } from "./OptionModel";
|
|
7
|
-
export type DigestionOptions = Pick<RunOptions, "converters" | "disableAutoManagedKey" | "propertiesByName" | "entitiesByName">;
|
|
7
|
+
export type DigestionOptions = Pick<RunOptions, "converters" | "disableAutoManagedKey" | "propertiesByName" | "entitiesByName" | "v2ModelsWithExtraResultsWrapping" | "skipEditableModels">;
|
|
8
8
|
/**
|
|
9
9
|
* Takes an EdmxSchema plus the run options and creates a DataModel.
|
|
10
10
|
*/
|
|
11
11
|
export type DigesterFunction<S extends Schema<any, any>> = (schema: S, options: DigestionOptions, namingHelper: NamingHelper) => Promise<DataModel>;
|
|
12
|
-
export type GeneratorFunctionOptions = Pick<RunOptions, "skipEditableModels" | "skipIdModels" | "skipOperations">;
|
|
12
|
+
export type GeneratorFunctionOptions = Pick<RunOptions, "skipEditableModels" | "skipIdModels" | "skipOperations" | "v2ModelsWithExtraResultsWrapping">;
|
|
13
13
|
export type EntityBasedGeneratorFunction = (dataModel: DataModel, sourceFile: SourceFile, version: ODataVersions, options: GeneratorFunctionOptions, namingHelper: NamingHelper) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FactoryFunctionModel.js","sourceRoot":"","sources":["../src/FactoryFunctionModel.ts"],"names":[],"mappings":"","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { SourceFile } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"./data-model/DataModel\";\r\nimport { Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { RunOptions } from \"./OptionModel\";\r\n\r\nexport type DigestionOptions = Pick<\r\n RunOptions,\r\n \"converters\"
|
|
1
|
+
{"version":3,"file":"FactoryFunctionModel.js","sourceRoot":"","sources":["../src/FactoryFunctionModel.ts"],"names":[],"mappings":"","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { SourceFile } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"./data-model/DataModel\";\r\nimport { Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { RunOptions } from \"./OptionModel\";\r\n\r\nexport type DigestionOptions = Pick<\r\n RunOptions,\r\n | \"converters\"\r\n | \"disableAutoManagedKey\"\r\n | \"propertiesByName\"\r\n | \"entitiesByName\"\r\n | \"v2ModelsWithExtraResultsWrapping\"\r\n | \"skipEditableModels\"\r\n>;\r\n\r\n/**\r\n * Takes an EdmxSchema plus the run options and creates a DataModel.\r\n */\r\nexport type DigesterFunction<S extends Schema<any, any>> = (\r\n schema: S,\r\n options: DigestionOptions,\r\n namingHelper: NamingHelper\r\n) => Promise<DataModel>;\r\n\r\nexport type GeneratorFunctionOptions = Pick<\r\n RunOptions,\r\n \"skipEditableModels\" | \"skipIdModels\" | \"skipOperations\" | \"v2ModelsWithExtraResultsWrapping\"\r\n>;\r\n\r\nexport type EntityBasedGeneratorFunction = (\r\n dataModel: DataModel,\r\n sourceFile: SourceFile,\r\n version: ODataVersions,\r\n options: GeneratorFunctionOptions,\r\n namingHelper: NamingHelper\r\n) => void;\r\n"]}
|
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"]}
|
package/lib/OptionModel.d.ts
CHANGED
|
@@ -152,6 +152,20 @@ export interface ConfigFileOptions extends Omit<CliOptions, "source" | "output"
|
|
|
152
152
|
* The naming options regarding the generated artefacts.
|
|
153
153
|
*/
|
|
154
154
|
naming?: OverridableNamingOptions;
|
|
155
|
+
/**
|
|
156
|
+
* Some OData V2 services generate an extra wrapping for entity collection attributes:
|
|
157
|
+
* <code>trips: {results: [...]}</code>. So instead of directly returning an array of entities
|
|
158
|
+
* an object with the property "results" is wrapped around the entity collection.
|
|
159
|
+
*
|
|
160
|
+
* If you're using the odata client then there's a build-in workaround in place which transforms
|
|
161
|
+
* the results to remove this extra mapping. However, if you're only interested in the types, then
|
|
162
|
+
* the generated models will not match that extra wrapping.
|
|
163
|
+
*
|
|
164
|
+
* Setting this configuration option to <code>true</code> (default: false) will add this extra
|
|
165
|
+
* wrapping to the generated models. But this option is only valid if the generation mode is set
|
|
166
|
+
* to <code>models</code>; it is ignored otherwise.
|
|
167
|
+
*/
|
|
168
|
+
v2ModelsWithExtraResultsWrapping?: boolean;
|
|
155
169
|
}
|
|
156
170
|
/**
|
|
157
171
|
* Custom generation options which are dependent on a specific odata service.
|
package/lib/OptionModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptionModel.js","sourceRoot":"","sources":["../src/OptionModel.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACH,IAAY,KAKX;AALD,WAAY,KAAK;IACf,qCAAM,CAAA;IACN,yCAAQ,CAAA;IACR,uCAAO,CAAA;IACP,+BAAG,CAAA;AACL,CAAC,EALW,KAAK,GAAL,aAAK,KAAL,aAAK,QAKhB;AAED;;GAEG;AACH,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,sBAAS,CAAA;IACT,sBAAS,CAAA;IACT,wBAAW,CAAA;IACX,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAKpB","sourcesContent":["import { TypeConverterConfig } from \"@odata2ts/converter-runtime\";\r\n\r\nimport { NameSettings, OverridableNamingOptions } from \"./NamingModel\";\r\n\r\n/**\r\n * Generation mode, by default \"all\".\r\n */\r\nexport enum Modes {\r\n models,\r\n qobjects,\r\n service,\r\n all,\r\n}\r\n\r\n/**\r\n * What kind of stuff to emit: Either raw TS or TS that has been compiled to JS / DTS.\r\n */\r\nexport enum EmitModes {\r\n ts = \"ts\",\r\n js = \"js\",\r\n dts = \"dts\",\r\n js_dts = \"js_dts\",\r\n}\r\n\r\n/**\r\n * Config options for CLI.\r\n */\r\nexport interface CliOptions {\r\n /**\r\n * The source file to use. Must be an EDMX compliant XML file.\r\n *\r\n * If not specified, at least one service must be configured in config file.\r\n */\r\n source?: string;\r\n /**\r\n * Specifies the output directory for the generated stuff.\r\n *\r\n * If not specified, at least one service must be configured in config file.\r\n */\r\n output?: string;\r\n /**\r\n * Only generates the specified services.\r\n * Relies on an existing config file where these service names are maintained.\r\n */\r\n services?: Array<string>;\r\n /**\r\n * Specifies what to generate:\r\n * - {@code Modes.models} will only generate TS interfaces\r\n * - {@code Modes.qobjects} will generate functional units used in QueryBuilder and for functions and actions\r\n * - {@code Modes.service} will generate one main OData service client and one per each entity\r\n * - {@code Modes.all} the same as {@code Modes.service}\r\n *\r\n * QObjects will also generate models, and generating the service client will also generate models and QObjects.\r\n * Defaults to {@code Modes.all}\r\n */\r\n mode?: Modes;\r\n /**\r\n * Specifies the type of the output files: TypeScript, JS, DTS only, JS with DTS.\r\n * Defaults to {@code EmitModes.js_dts}\r\n */\r\n emitMode?: EmitModes;\r\n /**\r\n * Uses prettier with your local configuration to pretty print TypeScript files.\r\n * Only applies if mode is set to {@code EmitModes.ts}.\r\n */\r\n prettier?: boolean;\r\n /**\r\n * When compiling TypeScript to JS, \"tsconfig.json\" is used by default to add compilerOptions.\r\n * This option allows to specify an alternative file.\r\n *\r\n * Only takes effect, when mode is set to anything else than {@code EmitModes.ts}.\r\n */\r\n tsconfig?: string;\r\n /**\r\n * Verbose debugging information.\r\n */\r\n debug?: boolean;\r\n /**\r\n * Overrides the service name found in the source file.\r\n *\r\n * The service name is the basis for all file names and the name of the main OData client service\r\n * that serves as entry point for the user.\r\n */\r\n serviceName?: string;\r\n /**\r\n * odata2ts will automatically decide if a key prop is managed on the server side.\r\n * If managed, the property will not be editable (create, update, patch).\r\n * The following rule applies:\r\n * If a property is the only key prop of an entity, then the prop is deemed to be managed;\r\n * in ony other case the prop is unmanaged.\r\n */\r\n disableAutoManagedKey?: boolean;\r\n /**\r\n * By default, odata2ts doesn't change param, operation, property or model names.\r\n * The generated models and their properties are named exactly as advertised by the server.\r\n *\r\n * By allowing odata2ts to change these names, certain predefined formatting strategies are used:\r\n * Model / class names are formatted with PascalCase; property, param, and operation names with camelCase.\r\n *\r\n * The naming configuration allows to control this and other naming related settings.\r\n * Note: Even if renaming is disabled, model prefixing / suffing still applies.\r\n */\r\n allowRenaming?: boolean;\r\n}\r\n\r\n/**\r\n * Available options for the actual generation run.\r\n * Every property is required, except the overriding service name.\r\n */\r\nexport interface RunOptions extends Required<Omit<ServiceGenerationOptions, \"serviceName\">> {\r\n serviceName?: string;\r\n naming: NameSettings;\r\n}\r\n\r\n/**\r\n * Available options for configuration files, i.e. odata2ts.config.ts.\r\n */\r\nexport interface ConfigFileOptions extends Omit<CliOptions, \"source\" | \"output\" | \"services\"> {\r\n services?: { [serviceName: string]: ServiceGenerationOptions };\r\n\r\n /**\r\n * Specify which converters to use by their package name, e.g. \"@odata2ts/converter-v2-to-v4\".\r\n * Each converter knows which data type to map.\r\n *\r\n * To only use specific converters, the object syntax must be used, where supported converters\r\n * must be listed by their ids.\r\n */\r\n converters?: Array<string | TypeConverterConfig>;\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 skip the generation altogether, not generating editable model variants,\r\n * if the generation mode is {@code Mode.model} or {@code Mode.qobject}.\r\n */\r\n skipEditableModels?: boolean;\r\n\r\n /**\r\n * ID models are generated from entity id parameters.\r\n * The generation for one entity entails one model interface representing the id parameters and\r\n * one QId function which allows to format the parameters for URL usage and to parse parameters\r\n * from a URL string.\r\n *\r\n * You can skip the generation altogether, not generating models and QId objects, if the\r\n * generation mode is {@code Mode.model} or {@code Mode.qobject}.\r\n */\r\n skipIdModels?: boolean;\r\n /**\r\n * Operations are functions and actions of the OData service.\r\n * The generation for one operation entails one parameter model interface\r\n * and one QFunction / QAction class.\r\n *\r\n * You can skip the generation altogether, neither generating model nor query object,\r\n * if the generation mode is {@code Mode.model} or {@code Mode.qobject}.\r\n */\r\n skipOperations?: boolean;\r\n\r\n /**\r\n * The naming options regarding the generated artefacts.\r\n */\r\n naming?: OverridableNamingOptions;\r\n}\r\n\r\n/**\r\n * Custom generation options which are dependent on a specific odata service.\r\n */\r\nexport interface ServiceGenerationOptions\r\n extends Required<Pick<CliOptions, \"source\" | \"output\">>,\r\n Omit<ConfigFileOptions, \"services\"> {\r\n /**\r\n * Configure generation process for EntityTypes and ComplexTypes including their keys and properties.\r\n */\r\n entitiesByName?: Array<EntityGenerationOptions>;\r\n /**\r\n * Configure generation process for individual properties based on their name.\r\n */\r\n propertiesByName?: Array<PropertyGenerationOptions>;\r\n}\r\n\r\n/**\r\n * Configuration options for EntityTypes and ComplexTypes.\r\n * This config applies if the name matches the name of an EntityType or ComplexType as it is specified\r\n * in the metadata (e.g. in EDMX <EntityType name=\"Test\" ...)\r\n */\r\nexport interface EntityGenerationOptions {\r\n /**\r\n * Name of the EntityType or ComplexType, e.g. \"Person\".\r\n * Must match exactly or can be a regular expression.\r\n */\r\n name: string | RegExp;\r\n /**\r\n * Use a different name.\r\n * If name is a regular expression, mappedName allows to specify captured groups (via $1, $2, ...).\r\n */\r\n mappedName?: string;\r\n /**\r\n * Overwrite the key specification by naming the props by their EDMX name.\r\n */\r\n keys?: Array<string>;\r\n /**\r\n * Configuration of individual properties.\r\n */\r\n // properties?: Array<PropertyGenerationOptions>;\r\n\r\n // converter: string | Array<string>\r\n\r\n /**\r\n * Whether the generated service should allow for querying this model.\r\n * True by default.\r\n */\r\n // queryable?: boolean;\r\n /**\r\n * Whether the generated service should allow for creating new models (POST).\r\n * True by default.\r\n */\r\n // creatable?: boolean;\r\n /**\r\n * Whether the generated service should allow for updates (PUT).\r\n * True by default.\r\n */\r\n // updatable?: boolean;\r\n /**\r\n * Whether the generated service should allow for partial updates (PATCH).\r\n * True by default.\r\n */\r\n // patchable?: boolean;\r\n /**\r\n * Whether the generated service should allow for deletion.\r\n * True by default.\r\n */\r\n // deletable?: boolean;\r\n}\r\n\r\n/**\r\n * All configuration options for properties of models.\r\n */\r\nexport interface PropertyGenerationOptions {\r\n /**\r\n * Name of the property to match.\r\n * Must match exactly or can be a regular expression.\r\n */\r\n name: string | RegExp;\r\n /**\r\n * Use a different name.\r\n * If name is a regular expression, mappedName allows to specify captured groups (via $1, $2, ...).\r\n */\r\n mappedName?: string;\r\n /**\r\n * Managed attributes - i.e. managed by the server - cannot be created or updated.\r\n * Hence, they are left out of the editable model versions.\r\n */\r\n managed?: boolean;\r\n\r\n /**\r\n * TODO\r\n *\r\n * Each converter must specify its package name, e.g. \"@odata2ts/converter-v2-to-v4\",\r\n * as well it's i\r\n * and their ids, e.g. \"timeToDurationConverter\".\r\n *\r\n * To only use specific converters, the object syntax must be used, where supported converters\r\n * must be listed by their ids.\r\n */\r\n // converters?: Array<Required<TypeConverterConfig>>;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"OptionModel.js","sourceRoot":"","sources":["../src/OptionModel.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACH,IAAY,KAKX;AALD,WAAY,KAAK;IACf,qCAAM,CAAA;IACN,yCAAQ,CAAA;IACR,uCAAO,CAAA;IACP,+BAAG,CAAA;AACL,CAAC,EALW,KAAK,GAAL,aAAK,KAAL,aAAK,QAKhB;AAED;;GAEG;AACH,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,sBAAS,CAAA;IACT,sBAAS,CAAA;IACT,wBAAW,CAAA;IACX,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAKpB","sourcesContent":["import { TypeConverterConfig } from \"@odata2ts/converter-runtime\";\r\n\r\nimport { NameSettings, OverridableNamingOptions } from \"./NamingModel\";\r\n\r\n/**\r\n * Generation mode, by default \"all\".\r\n */\r\nexport enum Modes {\r\n models,\r\n qobjects,\r\n service,\r\n all,\r\n}\r\n\r\n/**\r\n * What kind of stuff to emit: Either raw TS or TS that has been compiled to JS / DTS.\r\n */\r\nexport enum EmitModes {\r\n ts = \"ts\",\r\n js = \"js\",\r\n dts = \"dts\",\r\n js_dts = \"js_dts\",\r\n}\r\n\r\n/**\r\n * Config options for CLI.\r\n */\r\nexport interface CliOptions {\r\n /**\r\n * The source file to use. Must be an EDMX compliant XML file.\r\n *\r\n * If not specified, at least one service must be configured in config file.\r\n */\r\n source?: string;\r\n /**\r\n * Specifies the output directory for the generated stuff.\r\n *\r\n * If not specified, at least one service must be configured in config file.\r\n */\r\n output?: string;\r\n /**\r\n * Only generates the specified services.\r\n * Relies on an existing config file where these service names are maintained.\r\n */\r\n services?: Array<string>;\r\n /**\r\n * Specifies what to generate:\r\n * - {@code Modes.models} will only generate TS interfaces\r\n * - {@code Modes.qobjects} will generate functional units used in QueryBuilder and for functions and actions\r\n * - {@code Modes.service} will generate one main OData service client and one per each entity\r\n * - {@code Modes.all} the same as {@code Modes.service}\r\n *\r\n * QObjects will also generate models, and generating the service client will also generate models and QObjects.\r\n * Defaults to {@code Modes.all}\r\n */\r\n mode?: Modes;\r\n /**\r\n * Specifies the type of the output files: TypeScript, JS, DTS only, JS with DTS.\r\n * Defaults to {@code EmitModes.js_dts}\r\n */\r\n emitMode?: EmitModes;\r\n /**\r\n * Uses prettier with your local configuration to pretty print TypeScript files.\r\n * Only applies if mode is set to {@code EmitModes.ts}.\r\n */\r\n prettier?: boolean;\r\n /**\r\n * When compiling TypeScript to JS, \"tsconfig.json\" is used by default to add compilerOptions.\r\n * This option allows to specify an alternative file.\r\n *\r\n * Only takes effect, when mode is set to anything else than {@code EmitModes.ts}.\r\n */\r\n tsconfig?: string;\r\n /**\r\n * Verbose debugging information.\r\n */\r\n debug?: boolean;\r\n /**\r\n * Overrides the service name found in the source file.\r\n *\r\n * The service name is the basis for all file names and the name of the main OData client service\r\n * that serves as entry point for the user.\r\n */\r\n serviceName?: string;\r\n /**\r\n * odata2ts will automatically decide if a key prop is managed on the server side.\r\n * If managed, the property will not be editable (create, update, patch).\r\n * The following rule applies:\r\n * If a property is the only key prop of an entity, then the prop is deemed to be managed;\r\n * in ony other case the prop is unmanaged.\r\n */\r\n disableAutoManagedKey?: boolean;\r\n /**\r\n * By default, odata2ts doesn't change param, operation, property or model names.\r\n * The generated models and their properties are named exactly as advertised by the server.\r\n *\r\n * By allowing odata2ts to change these names, certain predefined formatting strategies are used:\r\n * Model / class names are formatted with PascalCase; property, param, and operation names with camelCase.\r\n *\r\n * The naming configuration allows to control this and other naming related settings.\r\n * Note: Even if renaming is disabled, model prefixing / suffing still applies.\r\n */\r\n allowRenaming?: boolean;\r\n}\r\n\r\n/**\r\n * Available options for the actual generation run.\r\n * Every property is required, except the overriding service name.\r\n */\r\nexport interface RunOptions extends Required<Omit<ServiceGenerationOptions, \"serviceName\">> {\r\n serviceName?: string;\r\n naming: NameSettings;\r\n}\r\n\r\n/**\r\n * Available options for configuration files, i.e. odata2ts.config.ts.\r\n */\r\nexport interface ConfigFileOptions extends Omit<CliOptions, \"source\" | \"output\" | \"services\"> {\r\n services?: { [serviceName: string]: ServiceGenerationOptions };\r\n\r\n /**\r\n * Specify which converters to use by their package name, e.g. \"@odata2ts/converter-v2-to-v4\".\r\n * Each converter knows which data type to map.\r\n *\r\n * To only use specific converters, the object syntax must be used, where supported converters\r\n * must be listed by their ids.\r\n */\r\n converters?: Array<string | TypeConverterConfig>;\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 skip the generation altogether, not generating editable model variants,\r\n * if the generation mode is {@code Mode.model} or {@code Mode.qobject}.\r\n */\r\n skipEditableModels?: boolean;\r\n\r\n /**\r\n * ID models are generated from entity id parameters.\r\n * The generation for one entity entails one model interface representing the id parameters and\r\n * one QId function which allows to format the parameters for URL usage and to parse parameters\r\n * from a URL string.\r\n *\r\n * You can skip the generation altogether, not generating models and QId objects, if the\r\n * generation mode is {@code Mode.model} or {@code Mode.qobject}.\r\n */\r\n skipIdModels?: boolean;\r\n /**\r\n * Operations are functions and actions of the OData service.\r\n * The generation for one operation entails one parameter model interface\r\n * and one QFunction / QAction class.\r\n *\r\n * You can skip the generation altogether, neither generating model nor query object,\r\n * if the generation mode is {@code Mode.model} or {@code Mode.qobject}.\r\n */\r\n skipOperations?: boolean;\r\n\r\n /**\r\n * The naming options regarding the generated artefacts.\r\n */\r\n naming?: OverridableNamingOptions;\r\n\r\n /**\r\n * Some OData V2 services generate an extra wrapping for entity collection attributes:\r\n * <code>trips: {results: [...]}</code>. So instead of directly returning an array of entities\r\n * an object with the property \"results\" is wrapped around the entity collection.\r\n *\r\n * If you're using the odata client then there's a build-in workaround in place which transforms\r\n * the results to remove this extra mapping. However, if you're only interested in the types, then\r\n * the generated models will not match that extra wrapping.\r\n *\r\n * Setting this configuration option to <code>true</code> (default: false) will add this extra\r\n * wrapping to the generated models. But this option is only valid if the generation mode is set\r\n * to <code>models</code>; it is ignored otherwise.\r\n */\r\n v2ModelsWithExtraResultsWrapping?: boolean;\r\n}\r\n\r\n/**\r\n * Custom generation options which are dependent on a specific odata service.\r\n */\r\nexport interface ServiceGenerationOptions\r\n extends Required<Pick<CliOptions, \"source\" | \"output\">>,\r\n Omit<ConfigFileOptions, \"services\"> {\r\n /**\r\n * Configure generation process for EntityTypes and ComplexTypes including their keys and properties.\r\n */\r\n entitiesByName?: Array<EntityGenerationOptions>;\r\n /**\r\n * Configure generation process for individual properties based on their name.\r\n */\r\n propertiesByName?: Array<PropertyGenerationOptions>;\r\n}\r\n\r\n/**\r\n * Configuration options for EntityTypes and ComplexTypes.\r\n * This config applies if the name matches the name of an EntityType or ComplexType as it is specified\r\n * in the metadata (e.g. in EDMX <EntityType name=\"Test\" ...)\r\n */\r\nexport interface EntityGenerationOptions {\r\n /**\r\n * Name of the EntityType or ComplexType, e.g. \"Person\".\r\n * Must match exactly or can be a regular expression.\r\n */\r\n name: string | RegExp;\r\n /**\r\n * Use a different name.\r\n * If name is a regular expression, mappedName allows to specify captured groups (via $1, $2, ...).\r\n */\r\n mappedName?: string;\r\n /**\r\n * Overwrite the key specification by naming the props by their EDMX name.\r\n */\r\n keys?: Array<string>;\r\n /**\r\n * Configuration of individual properties.\r\n */\r\n // properties?: Array<PropertyGenerationOptions>;\r\n\r\n // converter: string | Array<string>\r\n\r\n /**\r\n * Whether the generated service should allow for querying this model.\r\n * True by default.\r\n */\r\n // queryable?: boolean;\r\n /**\r\n * Whether the generated service should allow for creating new models (POST).\r\n * True by default.\r\n */\r\n // creatable?: boolean;\r\n /**\r\n * Whether the generated service should allow for updates (PUT).\r\n * True by default.\r\n */\r\n // updatable?: boolean;\r\n /**\r\n * Whether the generated service should allow for partial updates (PATCH).\r\n * True by default.\r\n */\r\n // patchable?: boolean;\r\n /**\r\n * Whether the generated service should allow for deletion.\r\n * True by default.\r\n */\r\n // deletable?: boolean;\r\n}\r\n\r\n/**\r\n * All configuration options for properties of models.\r\n */\r\nexport interface PropertyGenerationOptions {\r\n /**\r\n * Name of the property to match.\r\n * Must match exactly or can be a regular expression.\r\n */\r\n name: string | RegExp;\r\n /**\r\n * Use a different name.\r\n * If name is a regular expression, mappedName allows to specify captured groups (via $1, $2, ...).\r\n */\r\n mappedName?: string;\r\n /**\r\n * Managed attributes - i.e. managed by the server - cannot be created or updated.\r\n * Hence, they are left out of the editable model versions.\r\n */\r\n managed?: boolean;\r\n\r\n /**\r\n * TODO\r\n *\r\n * Each converter must specify its package name, e.g. \"@odata2ts/converter-v2-to-v4\",\r\n * as well it's i\r\n * and their ids, e.g. \"timeToDurationConverter\".\r\n *\r\n * To only use specific converters, the object syntax must be used, where supported converters\r\n * must be listed by their ids.\r\n */\r\n // converters?: Array<Required<TypeConverterConfig>>;\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,g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AAC,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;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,E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CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACxF,CAAC;IAcM,eAAe,CAAC,IAAY;;QACjC,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,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
|
@@ -20,6 +20,7 @@ const defaultConfig = {
|
|
|
20
20
|
skipOperations: false,
|
|
21
21
|
disableAutoManagedKey: false,
|
|
22
22
|
allowRenaming: false,
|
|
23
|
+
v2ModelsWithExtraResultsWrapping: false,
|
|
23
24
|
naming: {
|
|
24
25
|
models: {
|
|
25
26
|
namingStrategy: NamingModel_1.NamingStrategies.PASCAL_CASE,
|
|
@@ -72,17 +73,12 @@ const defaultConfig = {
|
|
|
72
73
|
suffix: "Collection",
|
|
73
74
|
applyServiceNaming: true,
|
|
74
75
|
},
|
|
75
|
-
serviceResolverFunction: {
|
|
76
|
-
namingStrategy: NamingModel_1.NamingStrategies.CAMEL_CASE,
|
|
77
|
-
prefix: "create",
|
|
78
|
-
suffix: "serviceResolver",
|
|
79
|
-
},
|
|
80
76
|
operations: {
|
|
81
77
|
namingStrategy: NamingModel_1.NamingStrategies.CAMEL_CASE,
|
|
82
78
|
},
|
|
83
79
|
relatedServiceGetter: {
|
|
84
80
|
namingStrategy: NamingModel_1.NamingStrategies.CAMEL_CASE,
|
|
85
|
-
prefix: "
|
|
81
|
+
prefix: "",
|
|
86
82
|
suffix: "",
|
|
87
83
|
},
|
|
88
84
|
privateProps: {
|
|
@@ -90,9 +86,6 @@ const defaultConfig = {
|
|
|
90
86
|
prefix: "_",
|
|
91
87
|
suffix: "",
|
|
92
88
|
},
|
|
93
|
-
publicProps: {
|
|
94
|
-
namingStrategy: NamingModel_1.NamingStrategies.PASCAL_CASE,
|
|
95
|
-
},
|
|
96
89
|
},
|
|
97
90
|
},
|
|
98
91
|
propertiesByName: [],
|
|
@@ -152,10 +145,6 @@ const minimalNamingConfig = {
|
|
|
152
145
|
prefix: services.relatedServiceGetter.prefix,
|
|
153
146
|
suffix: services.relatedServiceGetter.suffix,
|
|
154
147
|
},
|
|
155
|
-
serviceResolverFunction: {
|
|
156
|
-
prefix: services.serviceResolverFunction.prefix,
|
|
157
|
-
suffix: services.serviceResolverFunction.suffix,
|
|
158
|
-
},
|
|
159
148
|
},
|
|
160
149
|
};
|
|
161
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,KA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AgB,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"]}
|
package/lib/evaluateConfig.js
CHANGED
|
@@ -47,7 +47,7 @@ function evaluateConfigOptions(cliOpts, configOpts) {
|
|
|
47
47
|
throw new Error("No services were configured in config file, so options --source and --output must be specified!");
|
|
48
48
|
}
|
|
49
49
|
const merged = deepmerge_1.default.all([defaultConfig, confBaseOpts, cliOpts]);
|
|
50
|
-
return [
|
|
50
|
+
return [safeGuardOptions(merged)];
|
|
51
51
|
}
|
|
52
52
|
// Either services are specified or we use all configured services
|
|
53
53
|
const servicesToUse = (cliServices === null || cliServices === void 0 ? void 0 : cliServices.length) ? cliServices : Object.keys(confServices);
|
|
@@ -59,20 +59,25 @@ function evaluateConfigOptions(cliOpts, configOpts) {
|
|
|
59
59
|
}
|
|
60
60
|
const serviceDefault = ((_a = service.naming) === null || _a === void 0 ? void 0 : _a.minimalDefaults) && !((_b = configOpts === null || configOpts === void 0 ? void 0 : configOpts.naming) === null || _b === void 0 ? void 0 : _b.minimalDefaults) ? (0, defaultConfig_1.getMinimalConfig)() : defaultConfig;
|
|
61
61
|
const merged = deepmerge_1.default.all([serviceDefault, confBaseOpts, service, cliBaseOpts]);
|
|
62
|
-
return
|
|
62
|
+
return safeGuardOptions(merged);
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
exports.evaluateConfigOptions = evaluateConfigOptions;
|
|
66
66
|
/**
|
|
67
|
-
* Make sure that
|
|
67
|
+
* Make sure that some options are only active if in correct mode.
|
|
68
68
|
* @param options
|
|
69
69
|
*/
|
|
70
|
-
function
|
|
70
|
+
function safeGuardOptions(options) {
|
|
71
|
+
// skip options are not valid for service generation
|
|
71
72
|
if (options.mode === OptionModel_1.Modes.service || options.mode === OptionModel_1.Modes.all) {
|
|
72
73
|
options.skipEditableModels = false;
|
|
73
74
|
options.skipIdModels = false;
|
|
74
75
|
options.skipOperations = false;
|
|
75
76
|
}
|
|
77
|
+
// special option which is only valid for model generation
|
|
78
|
+
if (options.mode !== OptionModel_1.Modes.models) {
|
|
79
|
+
options.v2ModelsWithExtraResultsWrapping = false;
|
|
80
|
+
}
|
|
76
81
|
return options;
|
|
77
82
|
}
|
|
78
83
|
//# sourceMappingURL=evaluateConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateConfig.js","sourceRoot":"","sources":["../src/evaluateConfig.ts"],"names":[],"mappings":";;;;AAAA,kEAAkC;AAElC,mDAAqE;AACrE,+CAAiF;AAEjF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,qBAAqB,CACnC,OAAmB,EACnB,UAAyC;;IAEzC,MAAM,aAAa,GAAG,CAAA,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,0CAAE,eAAe,EAAC,CAAC,CAAC,IAAA,gCAAgB,GAAE,CAAC,CAAC,CAAC,IAAA,gCAAgB,GAAE,CAAC;IACpG,iBAAiB;IACjB,IAAI,CAAC,UAAU,EAAE;QACf,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAC;SACpG;QACD,OAAO,CAAC,IAAA,mBAAS,EAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;KAC5C;IAED,MAAM,EAAE,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,EAAE,OAAO,EAAE,WAAW,CAAC,CAAe,CAAC;QACjG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC;AAxCD,sDAwCC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,OAAmB;IAC3C,oDAAoD;IACpD,IAAI,OAAO,CAAC,IAAI,KAAK,mBAAK,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,mBAAK,CAAC,GAAG,EAAE;QAChE,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,OAAO,CAAC,YAAY,GAAG,KAAK,CAAC;QAC7B,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC;KAChC;IACD,0DAA0D;IAC1D,IAAI,OAAO,CAAC,IAAI,KAAK,mBAAK,CAAC,MAAM,EAAE;QACjC,OAAO,CAAC,gCAAgC,GAAG,KAAK,CAAC;KAClD;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import deepmerge from \"deepmerge\";\r\n\r\nimport { getDefaultConfig, getMinimalConfig } from \"./defaultConfig\";\r\nimport { CliOptions, ConfigFileOptions, Modes, RunOptions } from \"./OptionModel\";\r\n\r\n/**\r\n * Provides default values and evaluates the various config file and CLI options.\r\n * This function always returns a list of RunOptions,\r\n * whereby each item represents one generation run / one service.\r\n *\r\n * Configurations are merged in the following order (last one wins):\r\n * - default values\r\n * - config file: base settings\r\n * - config file: service specific settings\r\n * - CLI options\r\n *\r\n * If the CLI options specify source and output, then the service config is completely ignored and only the\r\n * base settings are applied from the config file.\r\n *\r\n * If the CLI options do not specify source and output, but do specify services, then these services must\r\n * exist in the config file and each service must supply values for source and output as a minimum.\r\n *\r\n * If the CLI options neither entail source nor services, then at least one service must be configured in the\r\n * config file. All configured services are returned.\r\n *\r\n * @param cliOpts CLI passed options\r\n * @param configOpts config file options\r\n */\r\nexport function evaluateConfigOptions(\r\n cliOpts: CliOptions,\r\n configOpts: ConfigFileOptions | undefined\r\n): Array<RunOptions> {\r\n const defaultConfig = configOpts?.naming?.minimalDefaults ? getMinimalConfig() : getDefaultConfig();\r\n // No config file\r\n if (!configOpts) {\r\n if (!cliOpts.source || !cliOpts.output) {\r\n throw new Error(\"Without any configuration file options --source and --output must be specified!\");\r\n }\r\n return [deepmerge(defaultConfig, cliOpts)];\r\n }\r\n\r\n const { services: cliServices, source, output, ...cliBaseOpts } = cliOpts;\r\n const { services: confServices, ...confBaseOpts } = configOpts;\r\n\r\n // No configurations of services in config file\r\n // or CLI opts specify source and output => ignore service config\r\n if ((source && output) || !confServices) {\r\n if (!source || !output) {\r\n throw new Error(\r\n \"No services were configured in config file, so options --source and --output must be specified!\"\r\n );\r\n }\r\n const merged = deepmerge.all([defaultConfig, confBaseOpts, cliOpts]) as RunOptions;\r\n return [safeGuardOptions(merged)];\r\n }\r\n\r\n // Either services are specified or we use all configured services\r\n const servicesToUse = cliServices?.length ? cliServices : Object.keys(confServices);\r\n return servicesToUse.map((s) => {\r\n const service = confServices[s];\r\n if (!service) {\r\n throw new Error(`Specified service \"${s}\" doesn't exist in configuration!`);\r\n }\r\n const serviceDefault =\r\n service.naming?.minimalDefaults && !configOpts?.naming?.minimalDefaults ? getMinimalConfig() : defaultConfig;\r\n const merged = deepmerge.all([serviceDefault, confBaseOpts, service, cliBaseOpts]) as RunOptions;\r\n return safeGuardOptions(merged);\r\n });\r\n}\r\n\r\n/**\r\n * Make sure that some options are only active if in correct mode.\r\n * @param options\r\n */\r\nfunction safeGuardOptions(options: RunOptions): RunOptions {\r\n // skip options are not valid for service generation\r\n if (options.mode === Modes.service || options.mode === Modes.all) {\r\n options.skipEditableModels = false;\r\n options.skipIdModels = false;\r\n options.skipOperations = false;\r\n }\r\n // special option which is only valid for model generation\r\n if (options.mode !== Modes.models) {\r\n options.v2ModelsWithExtraResultsWrapping = false;\r\n }\r\n\r\n return options;\r\n}\r\n"]}
|
|
@@ -84,7 +84,13 @@ class ModelGenerator {
|
|
|
84
84
|
}
|
|
85
85
|
// Collections
|
|
86
86
|
if (prop.isCollection) {
|
|
87
|
-
|
|
87
|
+
const type = `Array<${prop.type}>`;
|
|
88
|
+
if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {
|
|
89
|
+
return `{ results: ${type} }` + suffix;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return type + suffix;
|
|
93
|
+
}
|
|
88
94
|
}
|
|
89
95
|
// primitive, enum & complex types
|
|
90
96
|
return prop.type + (prop.required ? "" : " | null") + suffix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";;;AAOA,uDAAoD;AAE7C,MAAM,cAAc,GAAiC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACpH,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,cAAc;IAGlB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAe;QACtB,YAAO,GAAP,OAAO,CAA0B;QACjC,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEG,QAAQ;QACb,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC;QAE7E,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,cAAc,EAAE,CA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IAEO,uBAAuB,CAAC,SAAwB;QACtD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE;YAChC,OAAO;SACR;QACD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;YAC3B,IAAI,EAAE,SAAS,CAAC,eAAe;YAC/B,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACzC,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;oBACzB,gBAAgB,EAAE,CAAC,CAAC,CAAC,QAAQ;iBAC9B,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { SourceFile } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport { ComplexType, DataTypes, ModelType, OperationType, PropertyModel } from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nexport const generateModels: EntityBasedGeneratorFunction = (dataModel, sourceFile, version, options, namingHelper) => {\r\n const generator = new ModelGenerator(dataModel, sourceFile, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nconst DEFERRED_CONTENT = \"DeferredContent\";\r\n\r\nclass ModelGenerator {\r\n private importContainer!: ImportContainer;\r\n\r\n constructor(\r\n private dataModel: DataModel,\r\n private sourceFile: SourceFile,\r\n private version: ODataVersions,\r\n private options: GeneratorFunctionOptions,\r\n private namingHelper: NamingHelper\r\n ) {}\r\n\r\n public generate(): void {\r\n this.importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n this.generateEnums();\r\n this.generateModels();\r\n if (!this.options.skipOperations) {\r\n this.generateUnboundOperationParams();\r\n }\r\n }\r\n\r\n private generateEnums() {\r\n this.dataModel.getEnums().forEach((et) => {\r\n this.sourceFile.addEnum({\r\n name: et.name,\r\n isExported: true,\r\n members: et.members.map((mem) => ({ name: mem, initializer: `\"${mem}\"` })),\r\n });\r\n });\r\n }\r\n\r\n private generateModels() {\r\n this.dataModel.getModels().forEach((model) => {\r\n this.generateModel(model);\r\n if (!this.options.skipIdModels) {\r\n this.generateIdModel(model);\r\n }\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(model);\r\n }\r\n if (!this.options.skipOperations) {\r\n this.generateBoundOperationParams(model.name);\r\n }\r\n });\r\n this.dataModel.getComplexTypes().forEach((model) => {\r\n this.generateModel(model);\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(model);\r\n }\r\n });\r\n\r\n this.sourceFile.addImportDeclarations(this.importContainer.getImportDeclarations());\r\n }\r\n\r\n private generateModel(model: ComplexType) {\r\n this.sourceFile.addInterface({\r\n name: model.name,\r\n isExported: true,\r\n properties: model.props.map((p) => {\r\n const isEntity = p.dataType == DataTypes.ModelType;\r\n return {\r\n name: p.name,\r\n type: this.getPropType(p),\r\n // props for entities or entity collections are not added in V4 if not explicitly expanded\r\n hasQuestionToken: this.dataModel.isV4() && isEntity,\r\n };\r\n }),\r\n extends: model.baseClasses,\r\n });\r\n }\r\n\r\n private getPropType(prop: PropertyModel): string {\r\n const isEntity = prop.dataType == DataTypes.ModelType;\r\n\r\n // V2 entity special: deferred content\r\n let suffix = \"\";\r\n if (isEntity && this.dataModel.isV2()) {\r\n this.importContainer.addFromCore(DEFERRED_CONTENT);\r\n suffix = ` | ${DEFERRED_CONTENT}`;\r\n }\r\n // custom types which require type imports => possible via converters\r\n else if (prop.typeModule) {\r\n this.importContainer.addCustomType(prop.typeModule, prop.type);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n return `Array<${prop.type}>` + suffix;\r\n }\r\n\r\n // primitive, enum & complex types\r\n return prop.type + (prop.required ? \"\" : \" | null\") + suffix;\r\n }\r\n\r\n private generateIdModel(model: ModelType) {\r\n if (!model.generateId) {\r\n return;\r\n }\r\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\r\n const keyTypes = model.keys.map((keyProp) => `${keyProp.name}: ${this.getPropType(keyProp)}`).join(\",\");\r\n const type = `${singleType}{${keyTypes}}`;\r\n\r\n this.sourceFile.addTypeAlias({\r\n name: model.idModelName,\r\n isExported: true,\r\n type,\r\n });\r\n }\r\n\r\n private generateEditableModel(model: ComplexType) {\r\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\r\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\r\n\r\n const requiredProps = allProps\r\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const optionalProps = allProps\r\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\r\n\r\n const extendsClause = [\r\n requiredProps ? `Pick<${model.name}, ${requiredProps}>` : null,\r\n optionalProps ? `Partial<Pick<${model.name}, ${optionalProps}>>` : null,\r\n ].filter((e): e is string => !!e);\r\n\r\n this.sourceFile.addInterface({\r\n name: model.editableName,\r\n isExported: true,\r\n extends: extendsClause,\r\n properties: !complexProps\r\n ? undefined\r\n : complexProps.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getEditablePropType(p),\r\n // optional props don't need to be specified in editable model\r\n // also, entities would require deep insert func => we make it optional for now\r\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\r\n };\r\n }),\r\n });\r\n }\r\n\r\n private getEditablePropType(prop: PropertyModel): string {\r\n const type =\r\n prop.dataType === DataTypes.ModelType\r\n ? this.dataModel.getModel(prop.type).editableName\r\n : prop.dataType === DataTypes.ComplexType\r\n ? this.dataModel.getComplexType(prop.type).editableName\r\n : prop.type;\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n return `Array<${type}>`;\r\n }\r\n\r\n // primitive, enum & complex types\r\n return type + (prop.required ? \"\" : \" | null\");\r\n }\r\n\r\n private generateUnboundOperationParams() {\r\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\r\n this.generateOperationParams(operation);\r\n });\r\n }\r\n\r\n private generateBoundOperationParams(entityName: string) {\r\n this.dataModel.getOperationTypeByEntityOrCollectionBinding(entityName).forEach((operation) => {\r\n this.generateOperationParams(operation);\r\n });\r\n }\r\n\r\n private generateOperationParams(operation: OperationType) {\r\n if (!operation.parameters.length) {\r\n return;\r\n }\r\n this.sourceFile.addInterface({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n properties: operation.parameters.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getPropType(p),\r\n hasQuestionToken: !p.required,\r\n };\r\n }),\r\n });\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";;;AAOA,uDAAoD;AAE7C,MAAM,cAAc,GAAiC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACpH,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,cAAc;IAGlB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAe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E,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC;IAEO,8BAA8B;QACpC,IAAI,CAAC,SAAS,CAAC,wBAAwB,EAAE,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YAC9D,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,4BAA4B,CAAC,UAAkB;QACrD,IAAI,CAAC,SAAS,CAAC,2CAA2C,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YAC3F,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,uBAAuB,CAAC,SAAwB;QACtD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE;YAChC,OAAO;SACR;QACD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;YAC3B,IAAI,EAAE,SAAS,CAAC,eAAe;YAC/B,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACzC,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;oBACzB,gBAAgB,EAAE,CAAC,CAAC,CAAC,QAAQ;iBAC9B,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { SourceFile } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport { ComplexType, DataTypes, ModelType, OperationType, PropertyModel } from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nexport const generateModels: EntityBasedGeneratorFunction = (dataModel, sourceFile, version, options, namingHelper) => {\r\n const generator = new ModelGenerator(dataModel, sourceFile, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nconst DEFERRED_CONTENT = \"DeferredContent\";\r\n\r\nclass ModelGenerator {\r\n private importContainer!: ImportContainer;\r\n\r\n constructor(\r\n private dataModel: DataModel,\r\n private sourceFile: SourceFile,\r\n private version: ODataVersions,\r\n private options: GeneratorFunctionOptions,\r\n private namingHelper: NamingHelper\r\n ) {}\r\n\r\n public generate(): void {\r\n this.importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n this.generateEnums();\r\n this.generateModels();\r\n if (!this.options.skipOperations) {\r\n this.generateUnboundOperationParams();\r\n }\r\n }\r\n\r\n private generateEnums() {\r\n this.dataModel.getEnums().forEach((et) => {\r\n this.sourceFile.addEnum({\r\n name: et.name,\r\n isExported: true,\r\n members: et.members.map((mem) => ({ name: mem, initializer: `\"${mem}\"` })),\r\n });\r\n });\r\n }\r\n\r\n private generateModels() {\r\n this.dataModel.getModels().forEach((model) => {\r\n this.generateModel(model);\r\n if (!this.options.skipIdModels) {\r\n this.generateIdModel(model);\r\n }\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(model);\r\n }\r\n if (!this.options.skipOperations) {\r\n this.generateBoundOperationParams(model.name);\r\n }\r\n });\r\n this.dataModel.getComplexTypes().forEach((model) => {\r\n this.generateModel(model);\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(model);\r\n }\r\n });\r\n\r\n this.sourceFile.addImportDeclarations(this.importContainer.getImportDeclarations());\r\n }\r\n\r\n private generateModel(model: ComplexType) {\r\n this.sourceFile.addInterface({\r\n name: model.name,\r\n isExported: true,\r\n properties: model.props.map((p) => {\r\n const isEntity = p.dataType == DataTypes.ModelType;\r\n return {\r\n name: p.name,\r\n type: this.getPropType(p),\r\n // props for entities or entity collections are not added in V4 if not explicitly expanded\r\n hasQuestionToken: this.dataModel.isV4() && isEntity,\r\n };\r\n }),\r\n extends: model.baseClasses,\r\n });\r\n }\r\n\r\n private getPropType(prop: PropertyModel): string {\r\n const isEntity = prop.dataType == DataTypes.ModelType;\r\n\r\n // V2 entity special: deferred content\r\n let suffix = \"\";\r\n if (isEntity && this.dataModel.isV2()) {\r\n this.importContainer.addFromCore(DEFERRED_CONTENT);\r\n suffix = ` | ${DEFERRED_CONTENT}`;\r\n }\r\n // custom types which require type imports => possible via converters\r\n else if (prop.typeModule) {\r\n this.importContainer.addCustomType(prop.typeModule, prop.type);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n const type = `Array<${prop.type}>`;\r\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\r\n return `{ results: ${type} }` + suffix;\r\n } else {\r\n return type + suffix;\r\n }\r\n }\r\n\r\n // primitive, enum & complex types\r\n return prop.type + (prop.required ? \"\" : \" | null\") + suffix;\r\n }\r\n\r\n private generateIdModel(model: ModelType) {\r\n if (!model.generateId) {\r\n return;\r\n }\r\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\r\n const keyTypes = model.keys.map((keyProp) => `${keyProp.name}: ${this.getPropType(keyProp)}`).join(\",\");\r\n const type = `${singleType}{${keyTypes}}`;\r\n\r\n this.sourceFile.addTypeAlias({\r\n name: model.idModelName,\r\n isExported: true,\r\n type,\r\n });\r\n }\r\n\r\n private generateEditableModel(model: ComplexType) {\r\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\r\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\r\n\r\n const requiredProps = allProps\r\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const optionalProps = allProps\r\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\r\n\r\n const extendsClause = [\r\n requiredProps ? `Pick<${model.name}, ${requiredProps}>` : null,\r\n optionalProps ? `Partial<Pick<${model.name}, ${optionalProps}>>` : null,\r\n ].filter((e): e is string => !!e);\r\n\r\n this.sourceFile.addInterface({\r\n name: model.editableName,\r\n isExported: true,\r\n extends: extendsClause,\r\n properties: !complexProps\r\n ? undefined\r\n : complexProps.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getEditablePropType(p),\r\n // optional props don't need to be specified in editable model\r\n // also, entities would require deep insert func => we make it optional for now\r\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\r\n };\r\n }),\r\n });\r\n }\r\n\r\n private getEditablePropType(prop: PropertyModel): string {\r\n const type =\r\n prop.dataType === DataTypes.ModelType\r\n ? this.dataModel.getModel(prop.type).editableName\r\n : prop.dataType === DataTypes.ComplexType\r\n ? this.dataModel.getComplexType(prop.type).editableName\r\n : prop.type;\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n return `Array<${type}>`;\r\n }\r\n\r\n // primitive, enum & complex types\r\n return type + (prop.required ? \"\" : \" | null\");\r\n }\r\n\r\n private generateUnboundOperationParams() {\r\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\r\n this.generateOperationParams(operation);\r\n });\r\n }\r\n\r\n private generateBoundOperationParams(entityName: string) {\r\n this.dataModel.getOperationTypeByEntityOrCollectionBinding(entityName).forEach((operation) => {\r\n this.generateOperationParams(operation);\r\n });\r\n }\r\n\r\n private generateOperationParams(operation: OperationType) {\r\n if (!operation.parameters.length) {\r\n return;\r\n }\r\n this.sourceFile.addInterface({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n properties: operation.parameters.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getPropType(p),\r\n hasQuestionToken: !p.required,\r\n };\r\n }),\r\n });\r\n }\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>;
|