@odata2ts/odata2ts 0.31.0 → 0.31.1

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 CHANGED
@@ -3,6 +3,12 @@
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.31.1](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.31.0...@odata2ts/odata2ts@0.31.1) (2023-11-15)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **generator:** collection operations are not generated ([#235](https://github.com/odata2ts/odata2ts/issues/235)) ([5157ded](https://github.com/odata2ts/odata2ts/commit/5157dede1438f6551e0762eeaa1b82f1c7e06e7f))
11
+
6
12
  # [0.31.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.30.0...@odata2ts/odata2ts@0.31.0) (2023-10-29)
7
13
 
8
14
  ### Bug Fixes
@@ -12,6 +18,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
12
18
  ### Features
13
19
 
14
20
  * **generator:** allow for renaming of operations ([#231](https://github.com/odata2ts/odata2ts/issues/231)) ([8bff901](https://github.com/odata2ts/odata2ts/commit/8bff901c71522e9b7d48f49908e515e7812766f0))
21
+
15
22
  * **generator:** entity config supporting namespaces ([#226](https://github.com/odata2ts/odata2ts/issues/226)) ([ff52dc0](https://github.com/odata2ts/odata2ts/commit/ff52dc0f4b9aa0f255d3ec75506657c3f26709bc))
16
23
 
17
24
  ### BREAKING CHANGES
@@ -1 +1 @@
1
- {"version":3,"file":"FactoryFunctionModel.js","sourceRoot":"","sources":["../src/FactoryFunctionModel.ts"],"names":[],"mappings":"","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\nimport { SourceFile } from \"ts-morph\";\n\nimport { DataModel } from \"./data-model/DataModel\";\nimport { Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\nimport { NamingHelper } from \"./data-model/NamingHelper\";\nimport { RunOptions } from \"./OptionModel\";\n\nexport type DigestionOptions = Pick<\n RunOptions,\n | \"converters\"\n | \"disableAutoManagedKey\"\n | \"propertiesByName\"\n | \"entitiesByName\"\n | \"operationsByName\"\n | \"v2ModelsWithExtraResultsWrapping\"\n | \"v4BigNumberAsString\"\n | \"skipEditableModels\"\n | \"skipComments\"\n>;\n\n/**\n * Takes an EdmxSchema plus the run options and creates a DataModel.\n */\nexport type DigesterFunction<S extends Schema<any, any>> = (\n schema: Array<S>,\n options: DigestionOptions,\n namingHelper: NamingHelper\n) => Promise<DataModel>;\n\nexport type GeneratorFunctionOptions = Pick<\n RunOptions,\n \"skipEditableModels\" | \"skipIdModels\" | \"skipOperations\" | \"skipComments\" | \"v2ModelsWithExtraResultsWrapping\"\n>;\n\nexport type EntityBasedGeneratorFunction = (\n dataModel: DataModel,\n sourceFile: SourceFile,\n version: ODataVersions,\n options: GeneratorFunctionOptions,\n namingHelper: NamingHelper\n) => void;\n"]}
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 | \"operationsByName\"\r\n | \"v2ModelsWithExtraResultsWrapping\"\r\n | \"v4BigNumberAsString\"\r\n | \"skipEditableModels\"\r\n | \"skipComments\"\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: Array<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\" | \"skipComments\" | \"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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"OptionModel.js","sourceRoot":"","sources":["../src/OptionModel.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,IAAY,KAKX;AALD,WAAY,KAAK;IACf,qCAAM,CAAA;IACN,yCAAQ,CAAA;IACR,uCAAO,CAAA;IACP,+BAAG,CAAA;AACL,CAAC,EALW,KAAK,qBAAL,KAAK,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,yBAAT,SAAS,QAKpB","sourcesContent":["import { TypeConverterConfig } from \"@odata2ts/converter-runtime\";\nimport { AxiosRequestConfig } from \"axios\";\n\nimport { NameSettings, OverridableNamingOptions } from \"./NamingModel\";\n\n/**\n * Generation mode, by default \"all\".\n */\nexport enum Modes {\n models,\n qobjects,\n service,\n all,\n}\n\n/**\n * What kind of stuff to emit: Either raw TS or TS that has been compiled to JS / DTS.\n */\nexport enum EmitModes {\n ts = \"ts\",\n js = \"js\",\n dts = \"dts\",\n js_dts = \"js_dts\",\n}\n\n/**\n * Config options for CLI.\n */\nexport interface CliOptions {\n /**\n * The URL to the root of your OData service. The URL might end in a slash or not, it might also end\n * in $metadata, but we usually add this for you.\n *\n * Specifying the URL is a convenience feature to download the metadata file from the given URL.\n * You can configure this request via `sourceConfig` option.\n *\n * The `source` option must still be specified as it is used to store the downloaded file on your disk.\n * By default, the file is used once it has been downloaded.\n */\n sourceUrl?: string;\n /**\n * Downloads the metadata file and overwrites the existing one, if any.\n *\n * Only takes effect, if option `sourceUrl` is specified.\n */\n refreshFile?: boolean;\n /**\n * The source is the file to use (must be an EDMX compliant XML file) or the URL to the\n * metadata (ROOT_SERVICE/$metadata).\n *\n * If not specified, at least one service must be configured in config file.\n */\n source?: string;\n /**\n * Specifies the output directory for the generated stuff.\n *\n * If not specified, at least one service must be configured in config file.\n */\n output?: string;\n /**\n * Only generates the specified services.\n * Relies on an existing config file where these service names are maintained.\n */\n services?: Array<string>;\n /**\n * Specifies what to generate:\n * - {@code Modes.models} will only generate TS interfaces\n * - {@code Modes.qobjects} will generate functional units used in QueryBuilder and for functions and actions\n * - {@code Modes.service} will generate one main OData service client and one per each entity\n * - {@code Modes.all} the same as {@code Modes.service}\n *\n * QObjects will also generate models, and generating the service client will also generate models and QObjects.\n * Defaults to {@code Modes.all}\n */\n mode?: Modes;\n /**\n * Specifies the type of the output files: TypeScript, JS, DTS only, JS with DTS.\n * Defaults to {@code EmitModes.js_dts}\n */\n emitMode?: EmitModes;\n /**\n * Uses prettier with your local configuration to pretty print TypeScript files.\n * Only applies if mode is set to {@code EmitModes.ts}.\n */\n prettier?: boolean;\n /**\n * When compiling TypeScript to JS, \"tsconfig.json\" is used by default to add compilerOptions.\n * This option allows to specify an alternative file.\n *\n * Only takes effect, when mode is set to anything else than {@code EmitModes.ts}.\n */\n tsconfig?: string;\n /**\n * Verbose debugging information.\n */\n debug?: boolean;\n /**\n * Overrides the service name found in the source file.\n *\n * The service name is the basis for all file names and the name of the main OData client service\n * that serves as entry point for the user.\n */\n serviceName?: string;\n /**\n * odata2ts will automatically decide if a key prop is managed on the server side.\n * If managed, the property will not be editable (create, update, patch).\n * The following rule applies:\n * If a property is the only key prop of an entity, then the prop is deemed to be managed;\n * in ony other case the prop is unmanaged.\n */\n disableAutoManagedKey?: boolean;\n /**\n * By default, odata2ts doesn't change param, operation, property or model names.\n * The generated models and their properties are named exactly as advertised by the server.\n *\n * By allowing odata2ts to change these names, certain predefined formatting strategies are used:\n * Model / class names are formatted with PascalCase; property, param, and operation names with camelCase.\n *\n * The naming configuration allows to control this and other naming related settings.\n * Note: Even if renaming is disabled, model prefixing / suffixing still applies.\n */\n allowRenaming?: boolean;\n}\n\n/**\n * Configuration options of the request to retrieve the metadata.\n * Only takes effect if `source` is a URL.\n */\nexport interface UrlSourceConfiguration {\n /**\n * Basic auth credentials: the username.\n * Only takes effect if `password` has also been set.\n */\n username?: string;\n /**\n * Basic auth credentials: the password.\n * Only takes effect if `username` has also been set.\n */\n password?: string;\n /**\n * Custom request configuration.\n * URL and method `GET` are set by default, but can be overwritten.\n */\n custom?: AxiosRequestConfig;\n}\n\n/**\n * Available options for configuration files, i.e. odata2ts.config.ts.\n */\nexport interface ConfigFileOptions extends Omit<CliOptions, \"sourceUrl\" | \"source\" | \"output\" | \"services\"> {\n /**\n * Configuration options of the request to retrieve the metadata.\n * Only takes effect if `sourceUrl` is a URL.\n */\n sourceUrlConfig?: UrlSourceConfiguration;\n\n /**\n * Configuration of each service.\n *\n * @example { services: { trippin: { source: \"...\", ... } }}\n */\n services?: { [serviceName: string]: ServiceGenerationOptions };\n\n /**\n * Specify which converters to use by their package name, e.g. \"@odata2ts/converter-v2-to-v4\".\n * Each converter knows which data type to map.\n *\n * To only use specific converters, the object syntax must be used, where supported converters\n * must be listed by their ids.\n */\n converters?: Array<string | TypeConverterConfig>;\n\n /**\n * For each model an editable version is generated which represents the model definition for\n * create, update and patch actions.\n *\n * You can skip the generation altogether, not generating editable model variants,\n * if the generation mode is {@code Mode.model} or {@code Mode.qobject}.\n */\n skipEditableModels?: boolean;\n\n /**\n * ID models are generated from entity id parameters.\n * The generation for one entity entails one model interface representing the id parameters and\n * one QId function which allows to format the parameters for URL usage and to parse parameters\n * from a URL string.\n *\n * You can skip the generation altogether, not generating models and QId objects, if the\n * generation mode is {@code Mode.model} or {@code Mode.qobject}.\n */\n skipIdModels?: boolean;\n /**\n * Operations are functions and actions of the OData service.\n * The generation for one operation entails one parameter model interface\n * and one QFunction / QAction class.\n *\n * You can skip the generation altogether, neither generating model nor query object,\n * if the generation mode is {@code Mode.model} or {@code Mode.qobject}.\n */\n skipOperations?: boolean;\n /**\n * Model properties have explaining comments by default.\n * With this option you can turn that off.\n */\n skipComments?: boolean;\n /**\n * With OData you can read, update and delete data on a primitive property (`Edm.*`).\n * Usually, you wouldn't do that, but go for a bigger request, fetching more relevant information in one go.\n *\n * There's one exception: Handling `Edm.Stream´ properties and Media entities. Services for stream / media\n * stuff are generated regardless of this setting.\n */\n enablePrimitivePropertyServices?: boolean;\n\n /**\n * The naming options regarding the generated artefacts.\n */\n naming?: OverridableNamingOptions;\n\n /**\n * Some OData V2 services generate an extra wrapping for entity collection attributes:\n * <code>trips: {results: [...]}</code>. So instead of directly returning an array of entities\n * an object with the property \"results\" is wrapped around the entity collection.\n *\n * If you're using the odata client then there's a build-in workaround in place which transforms\n * the results to remove this extra mapping. However, if you're only interested in the types, then\n * the generated models will not match that extra wrapping.\n *\n * Setting this configuration option to <code>true</code> (default: false) will add this extra\n * wrapping to the generated models. But this option is only valid if the generation mode is set\n * to <code>models</code>; it is ignored otherwise.\n */\n v2ModelsWithExtraResultsWrapping?: boolean;\n /**\n * Numbers of type `Edm.Int64` and `Edm.Decimal` are represented as `number` in V4.\n * However, these numbers might not fit into JS' number type, which might result in precision loss.\n *\n * OData offers a special IEEE754 format option to get those types as `string` instead to prevent any\n * precision loss. So if you're handling very large or very small numbers (JS roughly supports 15 digits),\n * then you should use this option and, probably, also an appropriate converter (see available converters).\n *\n * Activating this option affects the type generation and will use `string` for both mentioned types.\n * All requests are executed with the \"accept\" header set to \"application/json;IEEE754Compatible=true\".\n * Additionally, when sending data the very same value will be set for the \"content-type\" header.\n */\n v4BigNumberAsString?: boolean;\n}\n\n/**\n * Custom generation options which are dependent on a specific odata service.\n */\nexport interface ServiceGenerationOptions\n extends Required<Pick<CliOptions, \"source\" | \"output\">>,\n Pick<CliOptions, \"sourceUrl\" | \"refreshFile\">,\n Omit<ConfigFileOptions, \"services\"> {\n /**\n * Configure generation process for EntityTypes and ComplexTypes including their keys and properties.\n */\n entitiesByName?: Array<EntityGenerationOptions>;\n /**\n * Configure generation process for individual properties based on their name.\n */\n propertiesByName?: Array<PropertyGenerationOptions>;\n /**\n * Configure generation process for individual function or actions by matching their name.\n */\n operationsByName?: Array<OperationGenerationOptions>;\n}\n\n/**\n * Available options for the actual generation run.\n * Every property is required, except the overriding service name.\n */\nexport interface RunOptions\n extends Required<Omit<ServiceGenerationOptions, \"serviceName\" | \"sourceUrl\" | \"sourceUrlConfig\" | \"refreshFile\">>,\n Pick<ServiceGenerationOptions, \"serviceName\" | \"sourceUrl\" | \"sourceUrlConfig\" | \"refreshFile\"> {\n naming: NameSettings;\n}\n\n/**\n * Configuration options for EntityTypes and ComplexTypes.\n * This config applies if the name matches the name of an EntityType or ComplexType as it is specified\n * in the metadata (e.g. in EDMX <EntityType name=\"Test\" ...)\n */\nexport interface EntityGenerationOptions {\n /**\n * Matches the name of the EntityType or ComplexType as it is stated in the EDMX model, e.g. \"Person\".\n * You can also address the fully qualified name including the namespace (annotated at the schema element), e.g.\n * \"Trippin.Person\".\n *\n * If the name is specified as plain string, it must match either the name or the fully qualified name\n * exactly (case-sensitive).\n *\n * Alternatively, a regular expression can be used which is always applied to the fully qualified name\n * (e.g. Trippin.Person). The regular expression must match the whole string\n * (e.g. `/Person/` won't do, `/.*\\.Person/` would work).\n *\n * To make regular expressions useful, captured groups are also supported. Works in combination with\n * the `mappedName` attribute.\n */\n name: string | RegExp;\n /**\n * If specified, this attribute value is used as name for the matched entity, complex or enum type as it will\n * appear in the generated typescript.\n *\n * When using a regular expression for matching the name, then captured groups can be referenced\n * as usual via $1, $2, etc. For example:\n * - name: /Trippin\\.(.+)/\n * - mappedName: \"T_$1\"\n * - result: \"T_Person\"\n */\n mappedName?: string;\n /**\n * Overwrite the key specification by naming the props by their EDMX name.\n */\n keys?: Array<string>;\n /**\n * Configuration of individual properties.\n */\n properties?: Array<PropertyGenerationOptions>;\n\n // converter: string | Array<string>\n\n /**\n * Whether the generated service should allow for querying this model.\n * True by default.\n */\n // queryable?: boolean;\n /**\n * Whether the generated service should allow for creating new models (POST).\n * True by default.\n */\n // creatable?: boolean;\n /**\n * Whether the generated service should allow for updates (PUT).\n * True by default.\n */\n // updatable?: boolean;\n /**\n * Whether the generated service should allow for partial updates (PATCH).\n * True by default.\n */\n // patchable?: boolean;\n /**\n * Whether the generated service should allow for deletion.\n * True by default.\n */\n // deletable?: boolean;\n}\n\n/**\n * All configuration options for properties of models.\n */\nexport interface PropertyGenerationOptions {\n /**\n * Name of the property to match.\n * Must match exactly or can be a regular expression.\n */\n name: string | RegExp;\n /**\n * Use a different name.\n * If name is a regular expression, mappedName allows to specify captured groups (via $1, $2, ...).\n */\n mappedName?: string;\n /**\n * Managed attributes - i.e. managed by the server - cannot be created or updated.\n * Hence, they are left out of the editable model versions.\n */\n managed?: boolean;\n\n /**\n * TODO\n *\n * Each converter must specify its package name, e.g. \"@odata2ts/converter-v2-to-v4\",\n * as well it's i\n * and their ids, e.g. \"timeToDurationConverter\".\n *\n * To only use specific converters, the object syntax must be used, where supported converters\n * must be listed by their ids.\n */\n // converters?: Array<Required<TypeConverterConfig>>;\n}\n\nexport interface OperationGenerationOptions {\n /**\n * Matches the name of the function or action as it is stated in the EDMX model, e.g. \"Person\".\n * You can also address the fully qualified name including the namespace (annotated at the schema element), e.g.\n * \"Trippin.Person\".\n *\n * If the name is specified as plain string, it must match either the name or the fully qualified name\n * exactly (case-sensitive).\n *\n * Alternatively, a regular expression can be used which is always applied to the fully qualified name\n * (e.g. Trippin.Person). The regular expression must match the whole string\n * (e.g. `/Person/` won't do, `/.*\\.Person/` would work).\n *\n * To make regular expressions useful, captured groups are also supported. Works in combination with\n * the `mappedName` attribute.\n */\n name: string | RegExp;\n\n /**\n * If specified, this attribute value is used as name for the matched operation as it will\n * appear in the generated typescript.\n *\n * When using a regular expression for matching the name, then captured groups can be referenced\n * as usual via $1, $2, etc. For example:\n * - name: /Trippin\\.(.+)/\n * - mappedName: \"T_$1\"\n * - result: \"T_Person\"\n */\n mappedName?: string;\n}\n"]}
1
+ {"version":3,"file":"OptionModel.js","sourceRoot":"","sources":["../src/OptionModel.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,IAAY,KAKX;AALD,WAAY,KAAK;IACf,qCAAM,CAAA;IACN,yCAAQ,CAAA;IACR,uCAAO,CAAA;IACP,+BAAG,CAAA;AACL,CAAC,EALW,KAAK,qBAAL,KAAK,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,yBAAT,SAAS,QAKpB","sourcesContent":["import { TypeConverterConfig } from \"@odata2ts/converter-runtime\";\r\nimport { AxiosRequestConfig } from \"axios\";\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 URL to the root of your OData service. The URL might end in a slash or not, it might also end\r\n * in $metadata, but we usually add this for you.\r\n *\r\n * Specifying the URL is a convenience feature to download the metadata file from the given URL.\r\n * You can configure this request via `sourceConfig` option.\r\n *\r\n * The `source` option must still be specified as it is used to store the downloaded file on your disk.\r\n * By default, the file is used once it has been downloaded.\r\n */\r\n sourceUrl?: string;\r\n /**\r\n * Downloads the metadata file and overwrites the existing one, if any.\r\n *\r\n * Only takes effect, if option `sourceUrl` is specified.\r\n */\r\n refreshFile?: boolean;\r\n /**\r\n * The source is the file to use (must be an EDMX compliant XML file) or the URL to the\r\n * metadata (ROOT_SERVICE/$metadata).\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 / suffixing still applies.\r\n */\r\n allowRenaming?: boolean;\r\n}\r\n\r\n/**\r\n * Configuration options of the request to retrieve the metadata.\r\n * Only takes effect if `source` is a URL.\r\n */\r\nexport interface UrlSourceConfiguration {\r\n /**\r\n * Basic auth credentials: the username.\r\n * Only takes effect if `password` has also been set.\r\n */\r\n username?: string;\r\n /**\r\n * Basic auth credentials: the password.\r\n * Only takes effect if `username` has also been set.\r\n */\r\n password?: string;\r\n /**\r\n * Custom request configuration.\r\n * URL and method `GET` are set by default, but can be overwritten.\r\n */\r\n custom?: AxiosRequestConfig;\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, \"sourceUrl\" | \"source\" | \"output\" | \"services\"> {\r\n /**\r\n * Configuration options of the request to retrieve the metadata.\r\n * Only takes effect if `sourceUrl` is a URL.\r\n */\r\n sourceUrlConfig?: UrlSourceConfiguration;\r\n\r\n /**\r\n * Configuration of each service.\r\n *\r\n * @example { services: { trippin: { source: \"...\", ... } }}\r\n */\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 * Model properties have explaining comments by default.\r\n * With this option you can turn that off.\r\n */\r\n skipComments?: boolean;\r\n /**\r\n * With OData you can read, update and delete data on a primitive property (`Edm.*`).\r\n * Usually, you wouldn't do that, but go for a bigger request, fetching more relevant information in one go.\r\n *\r\n * There's one exception: Handling `Edm.Stream´ properties and Media entities. Services for stream / media\r\n * stuff are generated regardless of this setting.\r\n */\r\n enablePrimitivePropertyServices?: 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 * Numbers of type `Edm.Int64` and `Edm.Decimal` are represented as `number` in V4.\r\n * However, these numbers might not fit into JS' number type, which might result in precision loss.\r\n *\r\n * OData offers a special IEEE754 format option to get those types as `string` instead to prevent any\r\n * precision loss. So if you're handling very large or very small numbers (JS roughly supports 15 digits),\r\n * then you should use this option and, probably, also an appropriate converter (see available converters).\r\n *\r\n * Activating this option affects the type generation and will use `string` for both mentioned types.\r\n * All requests are executed with the \"accept\" header set to \"application/json;IEEE754Compatible=true\".\r\n * Additionally, when sending data the very same value will be set for the \"content-type\" header.\r\n */\r\n v4BigNumberAsString?: 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 Pick<CliOptions, \"sourceUrl\" | \"refreshFile\">,\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 * Configure generation process for individual function or actions by matching their name.\r\n */\r\n operationsByName?: Array<OperationGenerationOptions>;\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\r\n extends Required<Omit<ServiceGenerationOptions, \"serviceName\" | \"sourceUrl\" | \"sourceUrlConfig\" | \"refreshFile\">>,\r\n Pick<ServiceGenerationOptions, \"serviceName\" | \"sourceUrl\" | \"sourceUrlConfig\" | \"refreshFile\"> {\r\n naming: NameSettings;\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 * Matches the name of the EntityType or ComplexType as it is stated in the EDMX model, e.g. \"Person\".\r\n * You can also address the fully qualified name including the namespace (annotated at the schema element), e.g.\r\n * \"Trippin.Person\".\r\n *\r\n * If the name is specified as plain string, it must match either the name or the fully qualified name\r\n * exactly (case-sensitive).\r\n *\r\n * Alternatively, a regular expression can be used which is always applied to the fully qualified name\r\n * (e.g. Trippin.Person). The regular expression must match the whole string\r\n * (e.g. `/Person/` won't do, `/.*\\.Person/` would work).\r\n *\r\n * To make regular expressions useful, captured groups are also supported. Works in combination with\r\n * the `mappedName` attribute.\r\n */\r\n name: string | RegExp;\r\n /**\r\n * If specified, this attribute value is used as name for the matched entity, complex or enum type as it will\r\n * appear in the generated typescript.\r\n *\r\n * When using a regular expression for matching the name, then captured groups can be referenced\r\n * as usual via $1, $2, etc. For example:\r\n * - name: /Trippin\\.(.+)/\r\n * - mappedName: \"T_$1\"\r\n * - result: \"T_Person\"\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\r\nexport interface OperationGenerationOptions {\r\n /**\r\n * Matches the name of the function or action as it is stated in the EDMX model, e.g. \"Person\".\r\n * You can also address the fully qualified name including the namespace (annotated at the schema element), e.g.\r\n * \"Trippin.Person\".\r\n *\r\n * If the name is specified as plain string, it must match either the name or the fully qualified name\r\n * exactly (case-sensitive).\r\n *\r\n * Alternatively, a regular expression can be used which is always applied to the fully qualified name\r\n * (e.g. Trippin.Person). The regular expression must match the whole string\r\n * (e.g. `/Person/` won't do, `/.*\\.Person/` would work).\r\n *\r\n * To make regular expressions useful, captured groups are also supported. Works in combination with\r\n * the `mappedName` attribute.\r\n */\r\n name: string | RegExp;\r\n\r\n /**\r\n * If specified, this attribute value is used as name for the matched operation as it will\r\n * appear in the generated typescript.\r\n *\r\n * When using a regular expression for matching the name, then captured groups can be referenced\r\n * as usual via $1, $2, etc. For example:\r\n * - name: /Trippin\\.(.+)/\r\n * - mappedName: \"T_$1\"\r\n * - result: \"T_Person\"\r\n */\r\n mappedName?: string;\r\n}\r\n"]}
package/lib/app.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AAGrD,4EAAuE;AACvE,4EAAuE;AAIvE,4DAAyD;AACzD,2CAAqF;AACrF,+CAA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AAU,EAAE,CAAC;IAC7B,CAAC;CAAA;AAjDD,wBAiDC","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\n\nimport { NamespaceWithAlias } from \"./data-model/DataModel\";\nimport { digest as digestV2 } from \"./data-model/DataModelDigestionV2\";\nimport { digest as digestV4 } from \"./data-model/DataModelDigestionV4\";\nimport { ODataEdmxModelBase, Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\nimport { SchemaV3 } from \"./data-model/edmx/ODataEdmxModelV3\";\nimport { SchemaV4 } from \"./data-model/edmx/ODataEdmxModelV4\";\nimport { NamingHelper } from \"./data-model/NamingHelper\";\nimport { generateModels, generateQueryObjects, generateServices } from \"./generator\";\nimport { Modes, RunOptions } from \"./OptionModel\";\nimport { createProjectManager } from \"./project/ProjectManager\";\n\nfunction isQObjectGen(mode: Modes) {\n return [Modes.qobjects, Modes.service, Modes.all].includes(mode);\n}\n\nfunction isServiceGen(mode: Modes) {\n return [Modes.service, Modes.all].includes(mode);\n}\n\n/**\n *\n * @param metadataJson metadata of a given OData service already parsed as JSON\n * @param options further options\n */\nexport async function runApp(metadataJson: ODataEdmxModelBase<any>, options: RunOptions): Promise<void> {\n // determine edmx edmxVersion attribute\n const edmxVersion = metadataJson[\"edmx:Edmx\"].$.Version;\n const version = edmxVersion === \"1.0\" ? ODataVersions.V2 : ODataVersions.V4;\n\n const dataService = metadataJson[\"edmx:Edmx\"][\"edmx:DataServices\"][0];\n const schemas = dataService.Schema as Array<SchemaV3 | SchemaV4>;\n\n const detectedSchema = schemas.find((schema) => schema.$.Namespace && schema.EntityType?.length) || schemas[0];\n const serviceName = options.serviceName || detectedSchema.$.Namespace;\n\n const namespaces = schemas.map<NamespaceWithAlias>((schema) => [schema.$.Namespace, schema.$.Alias]);\n\n // encapsulate the whole naming logic\n const namingHelper = new NamingHelper(options, serviceName, namespaces);\n // parse model information from edmx into something we can really work with\n // => that stuff is called dataModel!\n const dataModel =\n version === ODataVersions.V2\n ? await digestV2(dataService.Schema as Array<SchemaV3>, options, namingHelper)\n : await digestV4(dataService.Schema as Array<SchemaV4>, options, namingHelper);\n // handling the overall generation project\n const project = await createProjectManager(\n namingHelper.getFileNames(),\n options.output,\n options.emitMode,\n options.prettier,\n options.tsconfig\n );\n\n // Generate Model Interfaces\n // supported edmx types: EntityType, ComplexType, EnumType\n const modelsFile = await project.createModelFile();\n generateModels(dataModel, modelsFile, version, options, namingHelper);\n\n // Generate Query Objects\n // supported edmx types: EntityType, ComplexType\n // supported edmx prop types: primitive types, enum types, primitive collection (incl enum types), entity collection, entity object, complex object\n if (isQObjectGen(options.mode)) {\n const qFile = await project.createQObjectFile();\n generateQueryObjects(dataModel, qFile, version, options, namingHelper);\n }\n\n // Generate Individual OData-Service\n if (isServiceGen(options.mode)) {\n await generateServices(dataModel, project, version, namingHelper, options);\n }\n\n await project.writeFiles();\n}\n"]}
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AAGrD,4EAAuE;AACvE,4EAAuE;AAIvE,4DAAyD;AACzD,2CAAqF;AACrF,+CAAkD;AAClD,6DAAgE;AAEhE,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,QAAQ,EAAE,mBAAK,CAAC,OAAO,EAAE,mBAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,OAAO,EAAE,mBAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnD,CAAC;AAED;;;;GAIG;AACH,SAAsB,MAAM,CAAC,YAAqC,EAAE,OAAmB;;QACrF,uCAAuC;QACvC,MAAM,WAAW,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACxD,MAAM,OAAO,GAAG,WAAW,KAAK,KAAK,CA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C,QAAQ,EAChB,OAAO,CAAC,QAAQ,CACjB,CAAC;QAEF,4BAA4B;QAC5B,0DAA0D;QAC1D,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;QACnD,IAAA,0BAAc,EAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAEtE,yBAAyB;QACzB,gDAAgD;QAChD,mJAAmJ;QACnJ,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAChD,IAAA,gCAAoB,EAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;SACxE;QAED,oCAAoC;QACpC,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,IAAA,4BAAgB,EAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;SAC5E;QAED,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;CAAA;AAjDD,wBAiDC","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\n\r\nimport { NamespaceWithAlias } from \"./data-model/DataModel\";\r\nimport { digest as digestV2 } from \"./data-model/DataModelDigestionV2\";\r\nimport { digest as digestV4 } from \"./data-model/DataModelDigestionV4\";\r\nimport { ODataEdmxModelBase, Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { SchemaV3 } from \"./data-model/edmx/ODataEdmxModelV3\";\r\nimport { SchemaV4 } from \"./data-model/edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { generateModels, generateQueryObjects, generateServices } from \"./generator\";\r\nimport { Modes, RunOptions } from \"./OptionModel\";\r\nimport { createProjectManager } from \"./project/ProjectManager\";\r\n\r\nfunction isQObjectGen(mode: Modes) {\r\n return [Modes.qobjects, Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\nfunction isServiceGen(mode: Modes) {\r\n return [Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\n/**\r\n *\r\n * @param metadataJson metadata of a given OData service already parsed as JSON\r\n * @param options further options\r\n */\r\nexport async function runApp(metadataJson: ODataEdmxModelBase<any>, options: RunOptions): Promise<void> {\r\n // determine edmx edmxVersion attribute\r\n const edmxVersion = metadataJson[\"edmx:Edmx\"].$.Version;\r\n const version = edmxVersion === \"1.0\" ? ODataVersions.V2 : ODataVersions.V4;\r\n\r\n const dataService = metadataJson[\"edmx:Edmx\"][\"edmx:DataServices\"][0];\r\n const schemas = dataService.Schema as Array<SchemaV3 | SchemaV4>;\r\n\r\n const detectedSchema = schemas.find((schema) => schema.$.Namespace && schema.EntityType?.length) || schemas[0];\r\n const serviceName = options.serviceName || detectedSchema.$.Namespace;\r\n\r\n const namespaces = schemas.map<NamespaceWithAlias>((schema) => [schema.$.Namespace, schema.$.Alias]);\r\n\r\n // encapsulate the whole naming logic\r\n const namingHelper = new NamingHelper(options, serviceName, namespaces);\r\n // parse model information from edmx into something we can really work with\r\n // => that stuff is called dataModel!\r\n const dataModel =\r\n version === ODataVersions.V2\r\n ? await digestV2(dataService.Schema as Array<SchemaV3>, options, namingHelper)\r\n : await digestV4(dataService.Schema as Array<SchemaV4>, options, namingHelper);\r\n // handling the overall generation project\r\n const project = await createProjectManager(\r\n namingHelper.getFileNames(),\r\n options.output,\r\n options.emitMode,\r\n options.prettier,\r\n options.tsconfig\r\n );\r\n\r\n // Generate Model Interfaces\r\n // supported edmx types: EntityType, ComplexType, EnumType\r\n const modelsFile = await project.createModelFile();\r\n generateModels(dataModel, modelsFile, version, options, namingHelper);\r\n\r\n // Generate Query Objects\r\n // supported edmx types: EntityType, ComplexType\r\n // supported edmx prop types: primitive types, enum types, primitive collection (incl enum types), entity collection, entity object, complex object\r\n if (isQObjectGen(options.mode)) {\r\n const qFile = await project.createQObjectFile();\r\n generateQueryObjects(dataModel, qFile, version, options, namingHelper);\r\n }\r\n\r\n // Generate Individual OData-Service\r\n if (isServiceGen(options.mode)) {\r\n await generateServices(dataModel, project, version, namingHelper, options);\r\n }\r\n\r\n await project.writeFiles();\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DataModelDigestionV2.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestionV2.ts"],"names":[],"mappings":";;;;AAAA,mEAAoF;AACpF,qDAAmE;AAGnE,2CAA4C;AAC5C,6DAA2D;AAC3D,mDAA8E;AAK9E;;;;;;GAMG;AACI,MAAM,MAAM,GAA+B,CAAO,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACzF,MAAM,UAAU,GAAG,MAAM,IAAA,kCAAc,EAAC,0BAAa,CAAC,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAE9E,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;IAC5E,OAAO,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC3B,CAAC,CAAA,CAAC;AALW,QAAA,MAAM,UAKjB;AAEF,MAAM,UAAW,SAAQ,6BAA+C;IACtE,YACE,OAAwB,EACxB,OAAyB,EACzB,YAA0B,EAC1B,UAA6C;QAE7C,KAAK,CAAC,4BAAY,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;IACrE,CAAC;IAEO,kBAAkB,CAAC,EAAsB;;QAC/C,KAAK,IAAI,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE;YAC/B,IAAI,MAAM,CAAC,WAAW,EAAE;gBACtB,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;gBAC7E,MAAM,WAAW,GAAG,MAAA,MAAM,CAAC,WA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EAAE,QAAQ;oBACpB,KAAK,EAAE,aAAa;oBACpB,WAAW,EAAE,mBAAmB;oBAChC,MAAM,EAAE,SAAS;iBAClB,CAAC;YACJ,KAAK,yBAAY,CAAC,IAAI;gBACpB,OAAO;oBACL,UAAU,EAAE,QAAQ;oBACpB,KAAK,EAAE,aAAa;oBACpB,WAAW,EAAE,mBAAmB;oBAChC,MAAM,EAAE,cAAc;iBACvB,CAAC;YACJ;gBACE,OAAO;oBACL,UAAU,EAAE,QAAQ;oBACpB,KAAK,EAAE,eAAe;oBACtB,WAAW,EAAE,qBAAqB;oBAClC,MAAM,EAAE,SAAS;iBAClB,CAAC;SACL;IACH,CAAC;CACF","sourcesContent":["import { MappedConverterChains, loadConverters } from \"@odata2ts/converter-runtime\";\nimport { ODataTypesV2, ODataVersions } from \"@odata2ts/odata-core\";\n\nimport { DigesterFunction, DigestionOptions } from \"../FactoryFunctionModel\";\nimport { withNamespace } from \"./DataModel\";\nimport { Digester, TypeModel } from \"./DataModelDigestion\";\nimport { ODataVersion, OperationTypes, PropertyModel } from \"./DataTypeModel\";\nimport { ComplexType, Property } from \"./edmx/ODataEdmxModelBase\";\nimport { AssociationEnd, ComplexTypeV3, EntityTypeV3, NavigationProperty, SchemaV3 } from \"./edmx/ODataEdmxModelV3\";\nimport { NamingHelper } from \"./NamingHelper\";\n\n/**\n * Digests an EDMX schema to produce a DataModel.\n *\n * @param schemas\n * @param options\n * @param namingHelper\n */\nexport const digest: DigesterFunction<SchemaV3> = async (schemas, options, namingHelper) => {\n const converters = await loadConverters(ODataVersions.V2, options.converters);\n\n const digester = new DigesterV3(schemas, options, namingHelper, converters);\n return digester.digest();\n};\n\nclass DigesterV3 extends Digester<SchemaV3, EntityTypeV3, ComplexTypeV3> {\n constructor(\n schemas: Array<SchemaV3>,\n options: DigestionOptions,\n namingHelper: NamingHelper,\n converters: MappedConverterChains | undefined\n ) {\n super(ODataVersion.V2, schemas, options, namingHelper, converters);\n }\n\n private findAssociationEnd(np: NavigationProperty): AssociationEnd {\n for (let schema of this.schemas) {\n if (schema.Association) {\n const relationship = this.namingHelper.stripServicePrefix(np.$.Relationship);\n const association = schema.Association?.find((a) => a.$.Name === relationship);\n const result = association?.End.find((e) => e.$.Role === np.$.ToRole);\n if (result) {\n return result;\n }\n }\n }\n throw new Error(`Association end couldn't be determined for NavigationProperty [${np.$.Name}]`);\n }\n\n protected getNavigationProps(entityType: ComplexType | EntityTypeV3): Array<Property> {\n // return (entityType as EntityTypeV3).NavigationProperty || [];\n const et = entityType as EntityTypeV3;\n if (et.NavigationProperty) {\n return et.NavigationProperty.map((np) => {\n const end = this.findAssociationEnd(np);\n const isRequired = end.$.Multiplicity !== \"*\" && !end.$.Multiplicity.startsWith(\"0..\");\n const isCollection = end.$.Multiplicity !== \"1\" && !end.$.Multiplicity.endsWith(\"..1\");\n\n return {\n $: {\n Name: np.$.Name,\n Type: isCollection ? `Collection(${end.$.Type})` : end.$.Type,\n Nullable: isRequired ? \"false\" : \"true\",\n },\n };\n });\n }\n\n return [];\n }\n\n // in V2 all we have & need is the FunctionImport: Function & Action elements are only known in V4.\n protected digestOperations(schema: SchemaV3) {}\n\n protected digestEntityContainer(schema: SchemaV3) {\n const namespace = schema.$.Namespace;\n const alias = schema.$.Alias;\n if (schema.EntityContainer && schema.EntityContainer.length) {\n const container = schema.EntityContainer[0];\n\n container.FunctionImport?.forEach((funcImport) => {\n const odataName = funcImport.$.Name;\n const fqName = withNamespace(namespace, odataName);\n const opConfig = this.serviceConfigHelper.findOperationConfigByName([namespace, alias], odataName);\n const opName = opConfig?.mappedName || odataName;\n const name = this.namingHelper.getFunctionName(opName);\n const usePost = funcImport.$[\"m:HttpMethod\"]?.toUpperCase() === \"POST\";\n const parameters = funcImport.Parameter?.map((p) => this.mapProp(p)) ?? [];\n\n // TODO: the spec allows for multiple ReturnType elements\n // https://docs.microsoft.com/en-us/openspecs/windows_protocols/mc-csdl/f510f36a-36bf-47f4-ac41-4a0ff921fbfa\n // totally unclear how the response object would look like\n const returnTypeDef =\n funcImport.$.ReturnType || (funcImport.ReturnType?.length ? funcImport.ReturnType[0].$.Type : undefined);\n const returnType: PropertyModel | undefined = returnTypeDef\n ? this.mapProp({ $: { Name: \"NO_NAME_BECAUSE_RETURN_TYPE\", Type: returnTypeDef } })\n : undefined;\n\n // V2 only knows the FunctionImport element\n // we generate the data structure for the function here\n this.dataModel.addUnboundOperationType(namespace, {\n fqName,\n odataName,\n name,\n paramsModelName: this.namingHelper.getOperationParamsModelName(opName),\n qName: this.namingHelper.getQFunctionName(opName),\n type: OperationTypes.Function,\n parameters,\n returnType,\n usePost,\n });\n\n this.dataModel.addFunction(fqName, {\n fqName,\n odataName,\n name,\n entitySet: funcImport.$.EntitySet!,\n operation: fqName,\n });\n });\n\n container.EntitySet?.forEach((entitySet) => {\n const name = entitySet.$.Name;\n const fqName = withNamespace(namespace, name);\n const entityType = this.dataModel.getEntityType(entitySet.$.EntityType);\n if (!entityType) {\n throw new Error(`Entity type \"${entitySet.$.EntityType}\" not found!`);\n }\n\n this.dataModel.addEntitySet(fqName, {\n fqName,\n odataName: name,\n name,\n entityType,\n });\n });\n }\n }\n\n protected mapODataType(type: string): TypeModel {\n switch (type) {\n case ODataTypesV2.Boolean:\n return {\n outputType: \"boolean\",\n qPath: \"QBooleanPath\",\n qCollection: \"QBooleanCollection\",\n qParam: \"QBooleanParam\",\n };\n case ODataTypesV2.Int16:\n case ODataTypesV2.Int32:\n return {\n outputType: \"number\",\n qPath: \"QNumberV2Path\",\n qCollection: \"QNumberV2Collection\",\n qParam: \"QNumberParam\",\n };\n case ODataTypesV2.Byte:\n case ODataTypesV2.SByte:\n return {\n outputType: \"string\",\n qPath: \"QStringNumberV2Path\",\n qCollection: \"QStringNumberV2Collection\",\n qParam: \"QStringNumberV2Param\",\n };\n case ODataTypesV2.Int64:\n return {\n outputType: \"string\",\n qPath: \"QStringNumberV2Path\",\n qCollection: \"QStringNumberV2Collection\",\n qParam: \"QInt64V2Param\",\n };\n case ODataTypesV2.Single:\n return {\n outputType: \"string\",\n qPath: \"QStringNumberV2Path\",\n qCollection: \"QStringNumberV2Collection\",\n qParam: \"QSingleV2Param\",\n };\n case ODataTypesV2.Double:\n return {\n outputType: \"string\",\n qPath: \"QStringNumberV2Path\",\n qCollection: \"QStringNumberV2Collection\",\n qParam: \"QDoubleV2Param\",\n };\n case ODataTypesV2.Decimal:\n return {\n outputType: \"string\",\n qPath: \"QStringNumberV2Path\",\n qCollection: \"QStringNumberV2Collection\",\n qParam: \"QDecimalV2Param\",\n };\n case ODataTypesV2.String:\n return {\n outputType: \"string\",\n qPath: \"QStringV2Path\",\n qCollection: \"QStringV2Collection\",\n qParam: \"QStringParam\",\n };\n case ODataTypesV2.DateTime:\n return {\n outputType: \"string\",\n qPath: \"QDateTimeV2Path\",\n qCollection: \"QDateTimeV2Collection\",\n qParam: \"QDateTimeV2Param\",\n };\n case ODataTypesV2.Time:\n return {\n outputType: \"string\",\n qPath: \"QTimeV2Path\",\n qCollection: \"QTimeV2Collection\",\n qParam: \"QTimeV2Param\",\n };\n case ODataTypesV2.DateTimeOffset:\n return {\n outputType: \"string\",\n qPath: \"QDateTimeOffsetV2Path\",\n qCollection: \"QDateTimeOffsetV2Collection\",\n qParam: \"QDateTimeOffsetV2Param\",\n };\n case ODataTypesV2.Binary:\n return {\n outputType: \"string\",\n qPath: \"QBinaryPath\",\n qCollection: \"QBinaryCollection\",\n qParam: undefined,\n };\n case ODataTypesV2.Guid:\n return {\n outputType: \"string\",\n qPath: \"QGuidV2Path\",\n qCollection: \"QGuidV2Collection\",\n qParam: \"QGuidV2Param\",\n };\n default:\n return {\n outputType: \"string\",\n qPath: \"QStringV2Path\",\n qCollection: \"QStringV2Collection\",\n qParam: undefined,\n };\n }\n }\n}\n"]}
1
+ {"version":3,"file":"DataModelDigestionV2.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestionV2.ts"],"names":[],"mappings":";;;;AAAA,mEAAoF;AACpF,qDAAmE;AAGnE,2CA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AAe;oBACtB,WAAW,EAAE,qBAAqB;oBAClC,MAAM,EAAE,SAAS;iBAClB,CAAC;SACL;IACH,CAAC;CACF","sourcesContent":["import { MappedConverterChains, loadConverters } from \"@odata2ts/converter-runtime\";\r\nimport { ODataTypesV2, ODataVersions } from \"@odata2ts/odata-core\";\r\n\r\nimport { DigesterFunction, DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { withNamespace } from \"./DataModel\";\r\nimport { Digester, TypeModel } from \"./DataModelDigestion\";\r\nimport { ODataVersion, OperationTypes, PropertyModel } from \"./DataTypeModel\";\r\nimport { ComplexType, Property } from \"./edmx/ODataEdmxModelBase\";\r\nimport { AssociationEnd, ComplexTypeV3, EntityTypeV3, NavigationProperty, SchemaV3 } from \"./edmx/ODataEdmxModelV3\";\r\nimport { NamingHelper } from \"./NamingHelper\";\r\n\r\n/**\r\n * Digests an EDMX schema to produce a DataModel.\r\n *\r\n * @param schemas\r\n * @param options\r\n * @param namingHelper\r\n */\r\nexport const digest: DigesterFunction<SchemaV3> = async (schemas, options, namingHelper) => {\r\n const converters = await loadConverters(ODataVersions.V2, options.converters);\r\n\r\n const digester = new DigesterV3(schemas, options, namingHelper, converters);\r\n return digester.digest();\r\n};\r\n\r\nclass DigesterV3 extends Digester<SchemaV3, EntityTypeV3, ComplexTypeV3> {\r\n constructor(\r\n schemas: Array<SchemaV3>,\r\n options: DigestionOptions,\r\n namingHelper: NamingHelper,\r\n converters: MappedConverterChains | undefined\r\n ) {\r\n super(ODataVersion.V2, schemas, options, namingHelper, converters);\r\n }\r\n\r\n private findAssociationEnd(np: NavigationProperty): AssociationEnd {\r\n for (let schema of this.schemas) {\r\n if (schema.Association) {\r\n const relationship = this.namingHelper.stripServicePrefix(np.$.Relationship);\r\n const association = schema.Association?.find((a) => a.$.Name === relationship);\r\n const result = association?.End.find((e) => e.$.Role === np.$.ToRole);\r\n if (result) {\r\n return result;\r\n }\r\n }\r\n }\r\n throw new Error(`Association end couldn't be determined for NavigationProperty [${np.$.Name}]`);\r\n }\r\n\r\n protected getNavigationProps(entityType: ComplexType | EntityTypeV3): Array<Property> {\r\n // return (entityType as EntityTypeV3).NavigationProperty || [];\r\n const et = entityType as EntityTypeV3;\r\n if (et.NavigationProperty) {\r\n return et.NavigationProperty.map((np) => {\r\n const end = this.findAssociationEnd(np);\r\n const isRequired = end.$.Multiplicity !== \"*\" && !end.$.Multiplicity.startsWith(\"0..\");\r\n const isCollection = end.$.Multiplicity !== \"1\" && !end.$.Multiplicity.endsWith(\"..1\");\r\n\r\n return {\r\n $: {\r\n Name: np.$.Name,\r\n Type: isCollection ? `Collection(${end.$.Type})` : end.$.Type,\r\n Nullable: isRequired ? \"false\" : \"true\",\r\n },\r\n };\r\n });\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // in V2 all we have & need is the FunctionImport: Function & Action elements are only known in V4.\r\n protected digestOperations(schema: SchemaV3) {}\r\n\r\n protected digestEntityContainer(schema: SchemaV3) {\r\n const namespace = schema.$.Namespace;\r\n const alias = schema.$.Alias;\r\n if (schema.EntityContainer && schema.EntityContainer.length) {\r\n const container = schema.EntityContainer[0];\r\n\r\n container.FunctionImport?.forEach((funcImport) => {\r\n const odataName = funcImport.$.Name;\r\n const fqName = withNamespace(namespace, odataName);\r\n const opConfig = this.serviceConfigHelper.findOperationConfigByName([namespace, alias], odataName);\r\n const opName = opConfig?.mappedName || odataName;\r\n const name = this.namingHelper.getFunctionName(opName);\r\n const usePost = funcImport.$[\"m:HttpMethod\"]?.toUpperCase() === \"POST\";\r\n const parameters = funcImport.Parameter?.map((p) => this.mapProp(p)) ?? [];\r\n\r\n // TODO: the spec allows for multiple ReturnType elements\r\n // https://docs.microsoft.com/en-us/openspecs/windows_protocols/mc-csdl/f510f36a-36bf-47f4-ac41-4a0ff921fbfa\r\n // totally unclear how the response object would look like\r\n const returnTypeDef =\r\n funcImport.$.ReturnType || (funcImport.ReturnType?.length ? funcImport.ReturnType[0].$.Type : undefined);\r\n const returnType: PropertyModel | undefined = returnTypeDef\r\n ? this.mapProp({ $: { Name: \"NO_NAME_BECAUSE_RETURN_TYPE\", Type: returnTypeDef } })\r\n : undefined;\r\n\r\n // V2 only knows the FunctionImport element\r\n // we generate the data structure for the function here\r\n this.dataModel.addUnboundOperationType(namespace, {\r\n fqName,\r\n odataName,\r\n name,\r\n paramsModelName: this.namingHelper.getOperationParamsModelName(opName),\r\n qName: this.namingHelper.getQFunctionName(opName),\r\n type: OperationTypes.Function,\r\n parameters,\r\n returnType,\r\n usePost,\r\n });\r\n\r\n this.dataModel.addFunction(fqName, {\r\n fqName,\r\n odataName,\r\n name,\r\n entitySet: funcImport.$.EntitySet!,\r\n operation: fqName,\r\n });\r\n });\r\n\r\n container.EntitySet?.forEach((entitySet) => {\r\n const name = entitySet.$.Name;\r\n const fqName = withNamespace(namespace, name);\r\n const entityType = this.dataModel.getEntityType(entitySet.$.EntityType);\r\n if (!entityType) {\r\n throw new Error(`Entity type \"${entitySet.$.EntityType}\" not found!`);\r\n }\r\n\r\n this.dataModel.addEntitySet(fqName, {\r\n fqName,\r\n odataName: name,\r\n name,\r\n entityType,\r\n });\r\n });\r\n }\r\n }\r\n\r\n protected mapODataType(type: string): TypeModel {\r\n switch (type) {\r\n case ODataTypesV2.Boolean:\r\n return {\r\n outputType: \"boolean\",\r\n qPath: \"QBooleanPath\",\r\n qCollection: \"QBooleanCollection\",\r\n qParam: \"QBooleanParam\",\r\n };\r\n case ODataTypesV2.Int16:\r\n case ODataTypesV2.Int32:\r\n return {\r\n outputType: \"number\",\r\n qPath: \"QNumberV2Path\",\r\n qCollection: \"QNumberV2Collection\",\r\n qParam: \"QNumberParam\",\r\n };\r\n case ODataTypesV2.Byte:\r\n case ODataTypesV2.SByte:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringNumberV2Path\",\r\n qCollection: \"QStringNumberV2Collection\",\r\n qParam: \"QStringNumberV2Param\",\r\n };\r\n case ODataTypesV2.Int64:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringNumberV2Path\",\r\n qCollection: \"QStringNumberV2Collection\",\r\n qParam: \"QInt64V2Param\",\r\n };\r\n case ODataTypesV2.Single:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringNumberV2Path\",\r\n qCollection: \"QStringNumberV2Collection\",\r\n qParam: \"QSingleV2Param\",\r\n };\r\n case ODataTypesV2.Double:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringNumberV2Path\",\r\n qCollection: \"QStringNumberV2Collection\",\r\n qParam: \"QDoubleV2Param\",\r\n };\r\n case ODataTypesV2.Decimal:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringNumberV2Path\",\r\n qCollection: \"QStringNumberV2Collection\",\r\n qParam: \"QDecimalV2Param\",\r\n };\r\n case ODataTypesV2.String:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringV2Path\",\r\n qCollection: \"QStringV2Collection\",\r\n qParam: \"QStringParam\",\r\n };\r\n case ODataTypesV2.DateTime:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QDateTimeV2Path\",\r\n qCollection: \"QDateTimeV2Collection\",\r\n qParam: \"QDateTimeV2Param\",\r\n };\r\n case ODataTypesV2.Time:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QTimeV2Path\",\r\n qCollection: \"QTimeV2Collection\",\r\n qParam: \"QTimeV2Param\",\r\n };\r\n case ODataTypesV2.DateTimeOffset:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QDateTimeOffsetV2Path\",\r\n qCollection: \"QDateTimeOffsetV2Collection\",\r\n qParam: \"QDateTimeOffsetV2Param\",\r\n };\r\n case ODataTypesV2.Binary:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QBinaryPath\",\r\n qCollection: \"QBinaryCollection\",\r\n qParam: undefined,\r\n };\r\n case ODataTypesV2.Guid:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QGuidV2Path\",\r\n qCollection: \"QGuidV2Collection\",\r\n qParam: \"QGuidV2Param\",\r\n };\r\n default:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringV2Path\",\r\n qCollection: \"QStringV2Collection\",\r\n qParam: undefined,\r\n };\r\n }\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DataTypeModel.js","sourceRoot":"","sources":["../../src/data-model/DataTypeModel.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,0BAAU,CAAA;IACV,0BAAU,CAAA;AACZ,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\n\nexport enum ODataVersion {\n V2 = \"2.0\",\n V4 = \"4.0\",\n}\n\nexport const enum DataTypes {\n PrimitiveType = \"PrimitiveType\",\n EnumType = \"EnumType\",\n ComplexType = \"ComplexType\",\n ModelType = \"ModelType\",\n}\n\nexport const enum OperationTypes {\n Function = \"Function\",\n Action = \"Action\",\n}\n\nexport interface PropertyModel {\n odataName: string;\n name: string;\n odataType: string;\n fqType: string;\n type: string;\n typeModule?: string;\n qObject?: string;\n qPath: string;\n qParam?: string;\n required: boolean;\n isCollection: boolean;\n dataType: DataTypes;\n converters?: Array<ValueConverterImport>;\n managed?: boolean;\n}\n\nexport interface ModelType extends ComplexType {\n idModelName: string;\n qIdFunctionName: string;\n generateId: boolean;\n keyNames: Array<string>;\n keys: Array<PropertyModel>;\n getKeyUnion(): string;\n}\n\nexport interface ComplexType {\n dataType: DataTypes;\n fqName: string;\n odataName: string;\n name: string;\n editableName: string;\n qName: string;\n props: Array<PropertyModel>;\n baseProps: Array<PropertyModel>;\n baseClasses: Array<string>;\n}\n\nexport interface EnumType {\n dataType: DataTypes;\n fqName: string;\n odataName: string;\n name: string;\n members: Array<string>;\n}\n\nexport interface OperationType {\n fqName: string;\n odataName: string;\n name: string;\n paramsModelName: string;\n qName: string;\n type: OperationTypes;\n parameters: Array<PropertyModel>;\n returnType?: ReturnTypeModel;\n usePost?: boolean;\n}\n\nexport interface ReturnTypeModel extends PropertyModel {}\n\nexport type EntityContainerModel = {\n entitySets: { [name: string]: EntitySetType };\n singletons: { [name: string]: SingletonType };\n functions: { [name: string]: FunctionImportType };\n actions: { [name: string]: ActionImportType };\n};\n\nexport interface SingletonType {\n fqName: string;\n odataName: string;\n name: string;\n entityType: ModelType;\n navPropBinding?: Array<NavPropBindingType>;\n}\n\nexport interface EntitySetType {\n fqName: string;\n odataName: string;\n name: string;\n entityType: ModelType;\n navPropBinding?: Array<NavPropBindingType>;\n}\n\nexport interface NavPropBindingType {\n path: string;\n target: string;\n}\n\nexport interface ActionImportType {\n fqName: string;\n odataName: string;\n name: string;\n operation: string;\n}\n\nexport interface FunctionImportType extends ActionImportType {\n entitySet: string;\n}\n"]}
1
+ {"version":3,"file":"DataTypeModel.js","sourceRoot":"","sources":["../../src/data-model/DataTypeModel.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,0BAAU,CAAA;IACV,0BAAU,CAAA;AACZ,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\r\n\r\nexport enum ODataVersion {\r\n V2 = \"2.0\",\r\n V4 = \"4.0\",\r\n}\r\n\r\nexport const enum DataTypes {\r\n PrimitiveType = \"PrimitiveType\",\r\n EnumType = \"EnumType\",\r\n ComplexType = \"ComplexType\",\r\n ModelType = \"ModelType\",\r\n}\r\n\r\nexport const enum OperationTypes {\r\n Function = \"Function\",\r\n Action = \"Action\",\r\n}\r\n\r\nexport interface PropertyModel {\r\n odataName: string;\r\n name: string;\r\n odataType: string;\r\n fqType: string;\r\n type: string;\r\n typeModule?: string;\r\n qObject?: string;\r\n qPath: string;\r\n qParam?: string;\r\n required: boolean;\r\n isCollection: boolean;\r\n dataType: DataTypes;\r\n converters?: Array<ValueConverterImport>;\r\n managed?: boolean;\r\n}\r\n\r\nexport interface ModelType extends ComplexType {\r\n idModelName: string;\r\n qIdFunctionName: string;\r\n generateId: boolean;\r\n keyNames: Array<string>;\r\n keys: Array<PropertyModel>;\r\n getKeyUnion(): string;\r\n}\r\n\r\nexport interface ComplexType {\r\n dataType: DataTypes;\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n editableName: string;\r\n qName: string;\r\n props: Array<PropertyModel>;\r\n baseProps: Array<PropertyModel>;\r\n baseClasses: Array<string>;\r\n}\r\n\r\nexport interface EnumType {\r\n dataType: DataTypes;\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n members: Array<string>;\r\n}\r\n\r\nexport interface OperationType {\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n paramsModelName: string;\r\n qName: string;\r\n type: OperationTypes;\r\n parameters: Array<PropertyModel>;\r\n returnType?: ReturnTypeModel;\r\n usePost?: boolean;\r\n}\r\n\r\nexport interface ReturnTypeModel extends PropertyModel {}\r\n\r\nexport type EntityContainerModel = {\r\n entitySets: { [name: string]: EntitySetType };\r\n singletons: { [name: string]: SingletonType };\r\n functions: { [name: string]: FunctionImportType };\r\n actions: { [name: string]: ActionImportType };\r\n};\r\n\r\nexport interface SingletonType {\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n entityType: ModelType;\r\n navPropBinding?: Array<NavPropBindingType>;\r\n}\r\n\r\nexport interface EntitySetType {\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n entityType: ModelType;\r\n navPropBinding?: Array<NavPropBindingType>;\r\n}\r\n\r\nexport interface NavPropBindingType {\r\n path: string;\r\n target: string;\r\n}\r\n\r\nexport interface ActionImportType {\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n operation: string;\r\n}\r\n\r\nexport interface FunctionImportType extends ActionImportType {\r\n entitySet: string;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"NamingHelper.js","sourceRoot":"","sources":["../../src/data-model/NamingHelper.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,iDAA6C;AAC7C,6CAAyC;A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AAJ,IAAI,CAAE,MAAM,KAAI,IAAI,CAAC,CAAC;IAC9F,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;AA/OD,oCA+OC","sourcesContent":["import { camelCase } from \"camel-case\";\nimport { constantCase } from \"constant-case\";\nimport { pascalCase } from \"pascal-case\";\nimport { snakeCase } from \"snake-case\";\n\nimport { FileNamingStrategyOption, NameSettings, NamingStrategies, StandardNamingOptions } from \"../NamingModel\";\nimport { RunOptions } from \"../OptionModel\";\nimport { NamespaceWithAlias } from \"./DataModel\";\nimport { PropertyModel } from \"./DataTypeModel\";\n\nfunction getNamingStrategyImpl(strategy: NamingStrategies | undefined) {\n switch (strategy) {\n case NamingStrategies.CAMEL_CASE:\n return camelCase;\n case NamingStrategies.PASCAL_CASE:\n return pascalCase;\n case NamingStrategies.CONSTANT_CASE:\n return constantCase;\n case NamingStrategies.SNAKE_CASE:\n return snakeCase;\n default:\n return undefined;\n }\n}\n\nconst noopNamingFunction = (value: string, options?: StandardNamingOptions) => {\n return (options?.prefix || \"\") + value + (options?.suffix || \"\");\n};\n\nexport interface NamingHelperSettings extends Pick<RunOptions, \"allowRenaming\" | \"naming\"> {}\n\nexport class NamingHelper {\n private readonly allowModelPropRenaming: boolean;\n private readonly mainServiceName: string;\n private readonly namespacePrefixes: Array<string>;\n private readonly options: NameSettings;\n\n constructor(options: NamingHelperSettings, mainServiceName: string, namespaces?: Array<NamespaceWithAlias>) {\n if (!options) {\n throw new Error(\"NamingHelper: Options must be supplied!\");\n }\n if (!mainServiceName?.trim()) {\n throw new Error(\"NamingHelper: MainServiceName must be supplied!\");\n }\n\n if (!namespaces?.length) {\n namespaces = [[mainServiceName]];\n }\n\n this.allowModelPropRenaming = options.allowRenaming ?? false;\n this.options = options.naming;\n this.mainServiceName = mainServiceName;\n this.namespacePrefixes = namespaces\n .reduce<Array<string>>((accu, [ns, alias]) => {\n accu.push(ns);\n if (alias) {\n accu.push(alias);\n }\n return accu;\n }, [])\n .map((sn) => sn + \".\")\n .sort((a, b) => (a.length === b.length ? 0 : a.length > b.length ? -1 : 1));\n }\n\n /**\n * The prefix used to reference model or enum types in this schema.\n *\n * @returns service prefix\n */\n public includesServicePrefix(name: string) {\n for (let prefix of this.namespacePrefixes) {\n if (name.startsWith(prefix)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * The OData service name as it was found and is used in metadata file.\n *\n * @returns\n */\n public getODataServiceName() {\n return this.mainServiceName;\n }\n\n public getFileNames() {\n return {\n model: this.getFileName(this.options.models?.fileName),\n qObject: this.getFileName(this.options.queryObjects?.fileName),\n service: this.getMainServiceName(),\n };\n }\n\n private getFileName(opts?: FileNamingStrategyOption & StandardNamingOptions) {\n return this.getName(this.mainServiceName, this.namingFunction(opts?.namingStrategy), opts);\n }\n\n public getFileNameService(name: string) {\n const opts = this.options.services;\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\n }\n\n public stripServicePrefix(token: string) {\n const found = this.namespacePrefixes.find((prefix) => token.startsWith(prefix));\n return found ? token.replace(found, \"\") : token;\n }\n\n private namingFunction(strategy: NamingStrategies | undefined) {\n const strategyFn = getNamingStrategyImpl(strategy);\n if (!strategyFn || !this.allowModelPropRenaming) {\n return noopNamingFunction;\n }\n\n return (value: string, options?: StandardNamingOptions) => {\n const prefix = options?.prefix;\n const suffix = options?.suffix;\n const isPrefixSpecialChar = prefix?.startsWith(\"_\");\n const isSuffixSpecialChar = suffix?.endsWith(\"_\");\n\n let result = strategyFn((prefix ? prefix + \"_\" : \"\") + value + (suffix ? \"_\" + suffix : \"\"));\n if (isPrefixSpecialChar) {\n result = \"_\" + result;\n }\n if (isSuffixSpecialChar) {\n result = result + \"_\";\n }\n return result;\n };\n }\n\n private getName(\n name: string,\n strategy: (value: string, options?: StandardNamingOptions) => string,\n options?: StandardNamingOptions\n ) {\n return strategy(this.stripServicePrefix(name), options);\n }\n\n private getModelNamingStrategy() {\n return this.namingFunction(this.options.models?.namingStrategy);\n }\n\n private getModelPropNamingStrategy() {\n return this.namingFunction(this.options.models?.propNamingStrategy);\n }\n\n private getQObjectNamingStrategy() {\n return this.namingFunction(this.options.queryObjects?.namingStrategy);\n }\n\n private getQObjectPropNamingStrategy() {\n return this.namingFunction(this.options.queryObjects?.propNamingStrategy);\n }\n\n private getOperationNamingStrategy() {\n return this.namingFunction(this.options.services?.operations?.namingStrategy);\n }\n\n public getModelName(name: string): string {\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\n }\n\n public getModelPropName(name: string): string {\n return this.getName(name, this.getModelPropNamingStrategy());\n }\n\n public getEnumName(name: string) {\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\n }\n\n public getEditableModelName(name: string) {\n let options = this.options.models?.editableModels;\n const result = this.getName(name, this.getModelNamingStrategy(), options);\n return options?.applyModelNaming\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\n : result;\n }\n\n public getIdModelName(name: string) {\n let options = this.options.models?.idModels;\n const result = this.getName(name, this.getModelNamingStrategy(), options);\n return options?.applyModelNaming\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\n : result;\n }\n\n public getOperationParamsModelName(operationName: string, boundEntity?: string) {\n const settings = this.options.models?.operationParamModels;\n const result = this.getName(operationName, this.getModelNamingStrategy(), settings);\n const name = settings?.applyModelNaming\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\n : result;\n return this.getPrefixedName(name, boundEntity);\n }\n\n public getQName(name: string) {\n return this.getName(name, this.getQObjectNamingStrategy(), this.options.queryObjects);\n }\n\n public getQPropName(name: string): string {\n return this.getName(name, this.getQObjectPropNamingStrategy());\n }\n\n public getQIdFunctionName(name: string) {\n const opts = this.options.queryObjects?.idFunctions;\n const result = this.getName(name, this.getQObjectNamingStrategy(), opts);\n return this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\n }\n\n public getQFunctionName(operationName: string, boundEntity?: string) {\n const opts = this.options.queryObjects?.operations;\n const result = this.getName(operationName, this.getQObjectNamingStrategy(), opts?.function || opts);\n const name = this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\n return this.getPrefixedName(name, boundEntity);\n }\n\n public getQActionName(operationName: string, boundEntity?: string) {\n const opts = this.options.queryObjects?.operations;\n const result = this.getName(operationName, this.getQObjectNamingStrategy(), opts?.action || opts);\n const name = this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\n return this.getPrefixedName(name, boundEntity);\n }\n\n public getMainServiceName() {\n const name = this.getODataServiceName();\n const opts = this.options.services;\n const strategy = this.namingFunction(\n opts?.main?.namingStrategy ?? (opts?.main?.applyServiceNaming ? opts.namingStrategy : undefined)\n );\n const result = this.getName(name, strategy, opts?.main);\n return opts?.main?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\n }\n\n public getServiceName = (name: string) => {\n const opts = this.options.services;\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\n };\n\n public getCollectionServiceName = (name: string) => {\n const opts = this.options.services;\n const strategy = this.namingFunction(opts?.namingStrategy);\n const result = this.getName(name, strategy, opts?.collection);\n return opts?.collection?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\n };\n\n private getPrefixedName(name: string, boundEntity: string | undefined) {\n return boundEntity ? boundEntity + \"_\" + name : name;\n }\n\n public getFunctionName(operationName: string) {\n const opts = this.options.services?.operations;\n return this.getName(operationName, this.getOperationNamingStrategy(), opts?.function || opts);\n }\n\n public getActionName(operationName: string) {\n const opts = this.options.services?.operations;\n return this.getName(operationName, this.getOperationNamingStrategy(), opts?.action || opts);\n }\n\n public getRelatedServiceGetter(name: string) {\n const opts = this.options.services?.relatedServiceGetter;\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\n }\n\n public getPrivatePropName = (name: string) => {\n const opts = this.options.services?.privateProps;\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\n };\n}\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;AAKjH,SAAS,qBAAqB,CAAC,QAAsC;IACnE,QAAQ,QAAQ,EAAE;QAChB,KAAK,8BAAgB,CAAC,UAAU;YAC9B,OAAO,sBAAS,CAAC;QACnB,KAAK,8BAAgB,CAAC,WAAW;YAC/B,OAAO,wBAAU,CAAC;QACpB,KAAK,8BAAgB,CAAC,aAAa;YACjC,OAAO,4BAAY,CAAC;QACtB,KAAK,8BAAgB,CAAC,UAAU;YAC9B,OAAO,sBAAS,CAAC;QACnB;YACE,OAAO,SAAS,CAAC;KACpB;AACH,CAAC;AAED,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAE,OAA+B,EAAE,EAAE;IAC5E,OAAO,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,KAAI,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,KAAI,EAAE,CAAC,CAAC;AACnE,CAAC,CAAC;AAIF,MAAa,YAAY;IAMvB,YAAY,OAA6B,EAAE,eAAuB,EAAE,UAAsC;;QAsMnG,mBAAc,GAAG,CAAC,IAAY,EAAE,EAAE;YACvC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YACnC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,CAAC,EAAE,IAAI,CAAC,CAAC;QAC7E,CAAC,CAAC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AQ,KAAI,IAAI,CAAC,CAAC;IAChG,CAAC;IAEM,aAAa,CAAC,aAAqB;;QACxC,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,0CAAE,UAAU,CAAC;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,KAAI,IAAI,CAAC,CAAC;IAC9F,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;AA/OD,oCA+OC","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\nimport { NamespaceWithAlias } from \"./DataModel\";\r\nimport { PropertyModel } from \"./DataTypeModel\";\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 mainServiceName: string;\r\n private readonly namespacePrefixes: Array<string>;\r\n private readonly options: NameSettings;\r\n\r\n constructor(options: NamingHelperSettings, mainServiceName: string, namespaces?: Array<NamespaceWithAlias>) {\r\n if (!options) {\r\n throw new Error(\"NamingHelper: Options must be supplied!\");\r\n }\r\n if (!mainServiceName?.trim()) {\r\n throw new Error(\"NamingHelper: MainServiceName must be supplied!\");\r\n }\r\n\r\n if (!namespaces?.length) {\r\n namespaces = [[mainServiceName]];\r\n }\r\n\r\n this.allowModelPropRenaming = options.allowRenaming ?? false;\r\n this.options = options.naming;\r\n this.mainServiceName = mainServiceName;\r\n this.namespacePrefixes = namespaces\r\n .reduce<Array<string>>((accu, [ns, alias]) => {\r\n accu.push(ns);\r\n if (alias) {\r\n accu.push(alias);\r\n }\r\n return accu;\r\n }, [])\r\n .map((sn) => sn + \".\")\r\n .sort((a, b) => (a.length === b.length ? 0 : a.length > b.length ? -1 : 1));\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 includesServicePrefix(name: string) {\r\n for (let prefix of this.namespacePrefixes) {\r\n if (name.startsWith(prefix)) {\r\n return true;\r\n }\r\n }\r\n return false;\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.mainServiceName;\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.mainServiceName, 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 const found = this.namespacePrefixes.find((prefix) => token.startsWith(prefix));\r\n return found ? token.replace(found, \"\") : token;\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(operationName: string, boundEntity?: string) {\r\n const settings = this.options.models?.operationParamModels;\r\n const result = this.getName(operationName, this.getModelNamingStrategy(), settings);\r\n const name = settings?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n return this.getPrefixedName(name, boundEntity);\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(operationName: string, boundEntity?: string) {\r\n const opts = this.options.queryObjects?.operations;\r\n const result = this.getName(operationName, this.getQObjectNamingStrategy(), opts?.function || opts);\r\n const name = this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n return this.getPrefixedName(name, boundEntity);\r\n }\r\n\r\n public getQActionName(operationName: string, boundEntity?: string) {\r\n const opts = this.options.queryObjects?.operations;\r\n const result = this.getName(operationName, this.getQObjectNamingStrategy(), opts?.action || opts);\r\n const name = this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n return this.getPrefixedName(name, boundEntity);\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 private getPrefixedName(name: string, boundEntity: string | undefined) {\r\n return boundEntity ? boundEntity + \"_\" + name : name;\r\n }\r\n\r\n public getFunctionName(operationName: string) {\r\n const opts = this.options.services?.operations;\r\n return this.getName(operationName, this.getOperationNamingStrategy(), opts?.function || opts);\r\n }\r\n\r\n public getActionName(operationName: string) {\r\n const opts = this.options.services?.operations;\r\n return this.getName(operationName, 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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceConfigHelper.js","sourceRoot":"","sources":["../../src/data-model/ServiceConfigHelper.ts"],"names":[],"mappings":";;;;AAEA,2CAAgE;AAMhE,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;AAC9E,MAAM,yBAAyB,GAC7B,w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,EAAP,KAAK,sBAA5B,sBAA8B,CAAF;YAAQ,OAAA,iBACjD,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,IACpE,KAAK,EACR,CAAA;SAAA,CAAC,CAAC;QAEN,OAAO,CAAC,UAAU,CAAC,MAAM;YACvB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,UAAU,CAAC,MAAM,CAAmB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;gBACnD,uCAAY,MAAM,GAAK,IAAI,EAAG;YAChC,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,CAAC;CAQF;AAhMD,kDAgMC","sourcesContent":["import { DigestionOptions } from \"../FactoryFunctionModel\";\nimport { EntityGenerationOptions, OperationGenerationOptions, PropertyGenerationOptions } from \"../OptionModel\";\nimport { NamespaceWithAlias, withNamespace } from \"./DataModel\";\n\nexport interface ConfiguredProp extends Omit<PropertyGenerationOptions, \"name\"> {}\nexport interface ConfiguredEntity extends Omit<EntityGenerationOptions, \"name\"> {}\nexport interface ConfiguredOperation extends Omit<OperationGenerationOptions, \"name\"> {}\n\nconst EXCEPTION_NO_NAME = \"No value for required attribute [name] specified!\";\nconst EXCEPTION_WRONG_NAME_TYPE =\n \"Wrong type for attribute [name]! You have to supply either a plain string or a RegExp.\";\n\nexport class ServiceConfigHelper {\n private propMapping = new Map<string, PropertyGenerationOptions>();\n private entityMapping = new Map<string, EntityGenerationOptions>();\n private operationMapping = new Map<string, OperationGenerationOptions>();\n private propRegExps: Array<[RegExp, PropertyGenerationOptions]> = [];\n private entityRegExps: Array<[RegExp, EntityGenerationOptions]> = [];\n private operationRegExps: Array<[RegExp, OperationGenerationOptions]> = [];\n\n constructor(options: DigestionOptions) {\n this.evaluateProps(options);\n this.evaluateEntities(options);\n this.evaluateOperations(options);\n }\n\n private evaluateProps(options: DigestionOptions) {\n options.propertiesByName.forEach((prop) => {\n if (!prop.name) {\n throw new Error(EXCEPTION_NO_NAME);\n }\n switch (typeof prop.name) {\n case \"string\":\n // TODO: check for existing prop.name and throw?\n this.propMapping.set(prop.name, prop);\n break;\n case \"object\":\n const { source, ignoreCase } = prop.name as RegExp;\n if (!source) {\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n this.propRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), prop]);\n break;\n default:\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n });\n }\n\n private getPropByName(nameToMap: string): ConfiguredProp | undefined {\n const stringProp = this.propMapping.get(nameToMap);\n if (!stringProp) {\n return;\n }\n const { name, ...attrs } = stringProp;\n return { ...attrs };\n }\n\n private getPropByRegExp(nameToMap: string): ConfiguredProp | undefined {\n const resultList = this.propRegExps\n .filter(([regExp]) => regExp.test(nameToMap))\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\n mappedName: mappedName ? nameToMap.replace(regExp, mappedName) : undefined,\n ...attrs,\n }));\n\n return !resultList.length\n ? undefined\n : resultList.reduce<ConfiguredProp>((result, prop) => {\n return { ...result, ...prop };\n }, {});\n }\n\n public findPropConfigByName = (name: string): ConfiguredProp | undefined => {\n const stringProp = this.getPropByName(name);\n const reProp = this.getPropByRegExp(name);\n\n return stringProp && reProp ? { ...reProp, ...stringProp } : stringProp || reProp;\n };\n\n private evaluateEntities(options: DigestionOptions) {\n options.entitiesByName.forEach((ent) => {\n if (!ent.name) {\n throw new Error(EXCEPTION_NO_NAME);\n }\n switch (typeof ent.name) {\n case \"string\":\n // TODO: check for existing prop.name and throw?\n this.entityMapping.set(ent.name, ent);\n break;\n case \"object\":\n const { source, ignoreCase } = ent.name as RegExp;\n if (!source) {\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n this.entityRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), ent]);\n break;\n default:\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n });\n }\n\n // get entity config by name matching: simple name or fully qualified name (alias also supported)\n private getEntityByName(namespace: NamespaceWithAlias, nameToMap: string): ConfiguredEntity | undefined {\n const [ns, alias] = namespace;\n\n const config =\n this.entityMapping.get(withNamespace(ns, nameToMap)) ||\n (alias ? this.entityMapping.get(withNamespace(alias, nameToMap)) : undefined) ||\n this.entityMapping.get(nameToMap);\n if (!config) {\n return;\n }\n const { name, ...attrs } = config;\n return { ...attrs };\n }\n\n private getEntityByRegExp([mainNs, alias]: NamespaceWithAlias, nameToMap: string): ConfiguredEntity | undefined {\n const fqName = `${mainNs}.${nameToMap}`;\n const resultList = this.entityRegExps\n .filter(([regExp]) => regExp.test(fqName))\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\n mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined,\n ...attrs,\n }));\n\n return !resultList.length\n ? undefined\n : resultList.reduce<ConfiguredEntity>((result, prop) => {\n return { ...result, ...prop };\n }, {});\n }\n\n public findEntityConfigByName = (namespace: NamespaceWithAlias, name: string): ConfiguredEntity | undefined => {\n const stringEnt = this.getEntityByName(namespace, name);\n const reEnt = this.getEntityByRegExp(namespace, name);\n\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\n };\n\n private evaluateOperations(options: DigestionOptions) {\n options.operationsByName.forEach((op) => {\n if (!op.name) {\n throw new Error(EXCEPTION_NO_NAME);\n }\n switch (typeof op.name) {\n case \"string\":\n // TODO: check for existing operation name and throw?\n this.operationMapping.set(op.name, op);\n break;\n case \"object\":\n const { source, ignoreCase } = op.name as RegExp;\n if (!source) {\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n this.operationRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), op]);\n break;\n default:\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n });\n }\n\n // get entity config by name matching: simple name or fully qualified name (alias also supported)\n private getOperationByName(namespace: NamespaceWithAlias, nameToMap: string): ConfiguredOperation | undefined {\n const [ns, alias] = namespace;\n\n const config =\n this.operationMapping.get(withNamespace(ns, nameToMap)) ||\n (alias ? this.operationMapping.get(withNamespace(alias, nameToMap)) : undefined) ||\n this.operationMapping.get(nameToMap);\n if (!config) {\n return;\n }\n const { name, ...attrs } = config;\n return { ...attrs };\n }\n\n private getOperationByRegExp(\n [mainNs, alias]: NamespaceWithAlias,\n nameToMap: string\n ): ConfiguredOperation | undefined {\n const fqName = `${mainNs}.${nameToMap}`;\n const resultList = this.operationRegExps\n .filter(([regExp]) => regExp.test(fqName))\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\n mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined,\n ...attrs,\n }));\n\n return !resultList.length\n ? undefined\n : resultList.reduce<ConfiguredEntity>((result, prop) => {\n return { ...result, ...prop };\n }, {});\n }\n\n public findOperationConfigByName = (namespace: NamespaceWithAlias, name: string): ConfiguredOperation | undefined => {\n const stringEnt = this.getOperationByName(namespace, name);\n const reEnt = this.getOperationByRegExp(namespace, name);\n\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\n };\n}\n"]}
1
+ {"version":3,"file":"ServiceConfigHelper.js","sourceRoot":"","sources":["../../src/data-model/ServiceConfigHelper.ts"],"names":[],"mappings":";;;;AAEA,2CAAgE;AAMhE,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;AAC9E,MAAM,yBAAyB,GAC7B,wFAAwF,CAAC;AAE3F,MAAa,mBAAmB;IAQ9B,YAAY,OAAyB;QAP7B,gBAAW,GAAG,IAAI,GAAG,EAAqC,CAAC;QAC3D,kBAAa,GAAG,IAAI,GAAG,EAAmC,CAAC;QAC3D,qBAAgB,GAAG,IAAI,GAAG,EAAsC,CAAC;QACjE,gBAAW,GAA+C,EAAE,CAAC;QAC7D,kBAAa,GAA6C,EAAE,CAAC;QAC7D,qBAAgB,GAAgD,EAAE,CAAC;QAuDpE,yBAAoB,GAAG,CAAC,IAAY,EAA8B,EAAE;YACzE,MAAM,U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,MAAM,GAAK,IAAI,EAAG;YAChC,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,CAAC;CAQF;AAhMD,kDAgMC","sourcesContent":["import { DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { EntityGenerationOptions, OperationGenerationOptions, PropertyGenerationOptions } from \"../OptionModel\";\r\nimport { NamespaceWithAlias, withNamespace } from \"./DataModel\";\r\n\r\nexport interface ConfiguredProp extends Omit<PropertyGenerationOptions, \"name\"> {}\r\nexport interface ConfiguredEntity extends Omit<EntityGenerationOptions, \"name\"> {}\r\nexport interface ConfiguredOperation extends Omit<OperationGenerationOptions, \"name\"> {}\r\n\r\nconst EXCEPTION_NO_NAME = \"No value for required attribute [name] specified!\";\r\nconst EXCEPTION_WRONG_NAME_TYPE =\r\n \"Wrong type for attribute [name]! You have to supply either a plain string or a RegExp.\";\r\n\r\nexport class ServiceConfigHelper {\r\n private propMapping = new Map<string, PropertyGenerationOptions>();\r\n private entityMapping = new Map<string, EntityGenerationOptions>();\r\n private operationMapping = new Map<string, OperationGenerationOptions>();\r\n private propRegExps: Array<[RegExp, PropertyGenerationOptions]> = [];\r\n private entityRegExps: Array<[RegExp, EntityGenerationOptions]> = [];\r\n private operationRegExps: Array<[RegExp, OperationGenerationOptions]> = [];\r\n\r\n constructor(options: DigestionOptions) {\r\n this.evaluateProps(options);\r\n this.evaluateEntities(options);\r\n this.evaluateOperations(options);\r\n }\r\n\r\n private evaluateProps(options: DigestionOptions) {\r\n options.propertiesByName.forEach((prop) => {\r\n if (!prop.name) {\r\n throw new Error(EXCEPTION_NO_NAME);\r\n }\r\n switch (typeof prop.name) {\r\n case \"string\":\r\n // TODO: check for existing prop.name and throw?\r\n this.propMapping.set(prop.name, prop);\r\n break;\r\n case \"object\":\r\n const { source, ignoreCase } = prop.name as RegExp;\r\n if (!source) {\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n this.propRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), prop]);\r\n break;\r\n default:\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n });\r\n }\r\n\r\n private getPropByName(nameToMap: string): ConfiguredProp | undefined {\r\n const stringProp = this.propMapping.get(nameToMap);\r\n if (!stringProp) {\r\n return;\r\n }\r\n const { name, ...attrs } = stringProp;\r\n return { ...attrs };\r\n }\r\n\r\n private getPropByRegExp(nameToMap: string): ConfiguredProp | undefined {\r\n const resultList = this.propRegExps\r\n .filter(([regExp]) => regExp.test(nameToMap))\r\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\r\n mappedName: mappedName ? nameToMap.replace(regExp, mappedName) : undefined,\r\n ...attrs,\r\n }));\r\n\r\n return !resultList.length\r\n ? undefined\r\n : resultList.reduce<ConfiguredProp>((result, prop) => {\r\n return { ...result, ...prop };\r\n }, {});\r\n }\r\n\r\n public findPropConfigByName = (name: string): ConfiguredProp | undefined => {\r\n const stringProp = this.getPropByName(name);\r\n const reProp = this.getPropByRegExp(name);\r\n\r\n return stringProp && reProp ? { ...reProp, ...stringProp } : stringProp || reProp;\r\n };\r\n\r\n private evaluateEntities(options: DigestionOptions) {\r\n options.entitiesByName.forEach((ent) => {\r\n if (!ent.name) {\r\n throw new Error(EXCEPTION_NO_NAME);\r\n }\r\n switch (typeof ent.name) {\r\n case \"string\":\r\n // TODO: check for existing prop.name and throw?\r\n this.entityMapping.set(ent.name, ent);\r\n break;\r\n case \"object\":\r\n const { source, ignoreCase } = ent.name as RegExp;\r\n if (!source) {\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n this.entityRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), ent]);\r\n break;\r\n default:\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n });\r\n }\r\n\r\n // get entity config by name matching: simple name or fully qualified name (alias also supported)\r\n private getEntityByName(namespace: NamespaceWithAlias, nameToMap: string): ConfiguredEntity | undefined {\r\n const [ns, alias] = namespace;\r\n\r\n const config =\r\n this.entityMapping.get(withNamespace(ns, nameToMap)) ||\r\n (alias ? this.entityMapping.get(withNamespace(alias, nameToMap)) : undefined) ||\r\n this.entityMapping.get(nameToMap);\r\n if (!config) {\r\n return;\r\n }\r\n const { name, ...attrs } = config;\r\n return { ...attrs };\r\n }\r\n\r\n private getEntityByRegExp([mainNs, alias]: NamespaceWithAlias, nameToMap: string): ConfiguredEntity | undefined {\r\n const fqName = `${mainNs}.${nameToMap}`;\r\n const resultList = this.entityRegExps\r\n .filter(([regExp]) => regExp.test(fqName))\r\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\r\n mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined,\r\n ...attrs,\r\n }));\r\n\r\n return !resultList.length\r\n ? undefined\r\n : resultList.reduce<ConfiguredEntity>((result, prop) => {\r\n return { ...result, ...prop };\r\n }, {});\r\n }\r\n\r\n public findEntityConfigByName = (namespace: NamespaceWithAlias, name: string): ConfiguredEntity | undefined => {\r\n const stringEnt = this.getEntityByName(namespace, name);\r\n const reEnt = this.getEntityByRegExp(namespace, name);\r\n\r\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\r\n };\r\n\r\n private evaluateOperations(options: DigestionOptions) {\r\n options.operationsByName.forEach((op) => {\r\n if (!op.name) {\r\n throw new Error(EXCEPTION_NO_NAME);\r\n }\r\n switch (typeof op.name) {\r\n case \"string\":\r\n // TODO: check for existing operation name and throw?\r\n this.operationMapping.set(op.name, op);\r\n break;\r\n case \"object\":\r\n const { source, ignoreCase } = op.name as RegExp;\r\n if (!source) {\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n this.operationRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), op]);\r\n break;\r\n default:\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n });\r\n }\r\n\r\n // get entity config by name matching: simple name or fully qualified name (alias also supported)\r\n private getOperationByName(namespace: NamespaceWithAlias, nameToMap: string): ConfiguredOperation | undefined {\r\n const [ns, alias] = namespace;\r\n\r\n const config =\r\n this.operationMapping.get(withNamespace(ns, nameToMap)) ||\r\n (alias ? this.operationMapping.get(withNamespace(alias, nameToMap)) : undefined) ||\r\n this.operationMapping.get(nameToMap);\r\n if (!config) {\r\n return;\r\n }\r\n const { name, ...attrs } = config;\r\n return { ...attrs };\r\n }\r\n\r\n private getOperationByRegExp(\r\n [mainNs, alias]: NamespaceWithAlias,\r\n nameToMap: string\r\n ): ConfiguredOperation | undefined {\r\n const fqName = `${mainNs}.${nameToMap}`;\r\n const resultList = this.operationRegExps\r\n .filter(([regExp]) => regExp.test(fqName))\r\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\r\n mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined,\r\n ...attrs,\r\n }));\r\n\r\n return !resultList.length\r\n ? undefined\r\n : resultList.reduce<ConfiguredEntity>((result, prop) => {\r\n return { ...result, ...prop };\r\n }, {});\r\n }\r\n\r\n public findOperationConfigByName = (namespace: NamespaceWithAlias, name: string): ConfiguredOperation | undefined => {\r\n const stringEnt = this.getOperationByName(namespace, name);\r\n const reEnt = this.getOperationByRegExp(namespace, name);\r\n\r\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\r\n };\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.ts"],"names":[],"mappings":";;;;AAAA,kEAAkC;AAElC,+CAA+D;AAC/D,+CAA6D;AAG7D;;GAEG;AACH,MAAM,aAAa,GAAyB;IAC1C,eAAe,EAAE,EAAE;IACnB,WAAW,EAAE,KAAK;IAClB,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,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","sourcesContent":["import deepmerge from \"deepmerge\";\n\nimport { NameSettings, NamingStrategies } from \"./NamingModel\";\nimport { EmitModes, Modes, RunOptions } from \"./OptionModel\";\n\nexport type DefaultConfiguration = Omit<RunOptions, \"sourceUrl\" | \"source\" | \"output\" | \"serviceName\">;\n/**\n * The default configuration.\n */\nconst defaultConfig: DefaultConfiguration = {\n sourceUrlConfig: {},\n refreshFile: false,\n mode: Modes.all,\n emitMode: EmitModes.js_dts,\n debug: false,\n prettier: false,\n tsconfig: \"tsconfig.json\",\n converters: [],\n skipEditableModels: false,\n skipIdModels: false,\n skipOperations: false,\n skipComments: false,\n enablePrimitivePropertyServices: false,\n disableAutoManagedKey: false,\n allowRenaming: false,\n v2ModelsWithExtraResultsWrapping: false,\n v4BigNumberAsString: false,\n naming: {\n models: {\n namingStrategy: NamingStrategies.PASCAL_CASE,\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\n editableModels: {\n prefix: \"Editable\",\n suffix: \"\",\n applyModelNaming: true,\n },\n idModels: {\n prefix: \"\",\n suffix: \"Id\",\n applyModelNaming: true,\n },\n operationParamModels: {\n prefix: \"\",\n suffix: \"Params\",\n applyModelNaming: true,\n },\n fileName: {\n namingStrategy: NamingStrategies.PASCAL_CASE,\n prefix: \"\",\n suffix: \"Model\",\n },\n },\n queryObjects: {\n namingStrategy: NamingStrategies.PASCAL_CASE,\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\n prefix: \"Q\",\n suffix: \"\",\n idFunctions: {\n prefix: \"\",\n suffix: \"Id\",\n },\n fileName: {\n namingStrategy: NamingStrategies.PASCAL_CASE,\n prefix: \"Q\",\n suffix: \"\",\n },\n },\n services: {\n prefix: \"\",\n suffix: \"Service\",\n namingStrategy: NamingStrategies.PASCAL_CASE,\n main: {\n applyServiceNaming: true,\n },\n collection: {\n prefix: \"\",\n suffix: \"Collection\",\n applyServiceNaming: true,\n },\n operations: {\n namingStrategy: NamingStrategies.CAMEL_CASE,\n },\n relatedServiceGetter: {\n namingStrategy: NamingStrategies.CAMEL_CASE,\n prefix: \"\",\n suffix: \"\",\n },\n privateProps: {\n namingStrategy: NamingStrategies.CAMEL_CASE,\n prefix: \"_\",\n suffix: \"\",\n },\n },\n },\n propertiesByName: [],\n entitiesByName: [],\n operationsByName: [],\n};\n\nconst { models, queryObjects, services } = defaultConfig.naming;\nconst minimalNamingConfig: NameSettings = {\n models: {\n fileName: {\n prefix: models.fileName.prefix,\n suffix: models.fileName.suffix,\n },\n idModels: {\n applyModelNaming: true,\n prefix: models.idModels.prefix,\n suffix: models.idModels.suffix,\n },\n editableModels: {\n applyModelNaming: true,\n prefix: models.editableModels.prefix,\n suffix: models.editableModels.suffix,\n },\n operationParamModels: {\n applyModelNaming: true,\n prefix: models.operationParamModels.prefix,\n suffix: models.operationParamModels.suffix,\n },\n },\n queryObjects: {\n prefix: queryObjects.prefix,\n suffix: queryObjects.suffix,\n fileName: {\n prefix: queryObjects.fileName.prefix,\n suffix: queryObjects.fileName.suffix,\n },\n idFunctions: {\n prefix: queryObjects.idFunctions.prefix,\n suffix: queryObjects.idFunctions.suffix,\n },\n },\n services: {\n prefix: services.prefix,\n suffix: services.suffix,\n main: {\n applyServiceNaming: true,\n },\n collection: {\n applyServiceNaming: true,\n prefix: services.collection.prefix,\n suffix: services.collection.suffix,\n },\n privateProps: {\n prefix: services.privateProps.prefix,\n suffix: services.privateProps.suffix,\n },\n relatedServiceGetter: {\n prefix: services.relatedServiceGetter.prefix,\n suffix: services.relatedServiceGetter.suffix,\n },\n },\n};\n\n/**\n * Creates a defensive copy of the default config.\n */\nexport function getDefaultConfig(): DefaultConfiguration {\n return deepmerge(defaultConfig, {});\n}\n\n/**\n * Creates a defensive copy of the minimal config: minimal in respect to naming.\n */\nexport function getMinimalConfig(): DefaultConfiguration {\n const { naming, ...passThrough } = defaultConfig;\n return deepmerge(passThrough, { naming: minimalNamingConfig });\n}\n"]}
1
+ {"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.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BAAgB;IAC9B,OAAO,IAAA,mBAAS,EAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAFD,4CAEC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,MAAM,EAAE,MAAM,KAAqB,aAAa,EAA7B,WAAW,kBAAK,aAAa,EAA1C,UAA0B,CAAgB,CAAC;IACjD,OAAO,IAAA,mBAAS,EAAC,WAAW,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;AACjE,CAAC;AAHD,4CAGC","sourcesContent":["import deepmerge from \"deepmerge\";\r\n\r\nimport { NameSettings, NamingStrategies } from \"./NamingModel\";\r\nimport { EmitModes, Modes, RunOptions } from \"./OptionModel\";\r\n\r\nexport type DefaultConfiguration = Omit<RunOptions, \"sourceUrl\" | \"source\" | \"output\" | \"serviceName\">;\r\n/**\r\n * The default configuration.\r\n */\r\nconst defaultConfig: DefaultConfiguration = {\r\n sourceUrlConfig: {},\r\n refreshFile: false,\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 skipComments: false,\r\n enablePrimitivePropertyServices: false,\r\n disableAutoManagedKey: false,\r\n allowRenaming: false,\r\n v2ModelsWithExtraResultsWrapping: false,\r\n v4BigNumberAsString: 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 operationsByName: [],\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(): DefaultConfiguration {\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(): DefaultConfiguration {\r\n const { naming, ...passThrough } = defaultConfig;\r\n return deepmerge(passThrough, { naming: minimalNamingConfig });\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";;;AACA,uCAAmF;AAMnF,uDAAoD;AAE7C,MAAM,cAAc,GAAiC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACpH,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,cAAc;IAGlB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC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AI;oBACZ,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;oBACzB,gBAAgB,EAAE,CAAC,CAAC,CAAC,QAAQ;iBAC9B,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\nimport { JSDocStructure, OptionalKind, SourceFile, StructureKind } from \"ts-morph\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport { ComplexType, DataTypes, ModelType, OperationType, PropertyModel } from \"../data-model/DataTypeModel\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\nimport { ImportContainer } from \"./ImportContainer\";\n\nexport const generateModels: EntityBasedGeneratorFunction = (dataModel, sourceFile, version, options, namingHelper) => {\n const generator = new ModelGenerator(dataModel, sourceFile, version, options, namingHelper);\n return generator.generate();\n};\n\nconst DEFERRED_CONTENT = \"DeferredContent\";\n\nclass ModelGenerator {\n private importContainer!: ImportContainer;\n\n constructor(\n private dataModel: DataModel,\n private sourceFile: SourceFile,\n private version: ODataVersions,\n private options: GeneratorFunctionOptions,\n private namingHelper: NamingHelper\n ) {}\n\n public generate(): void {\n this.importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n this.generateEnums();\n this.generateModels();\n if (!this.options.skipOperations) {\n this.generateUnboundOperationParams();\n }\n }\n\n private generateEnums() {\n this.dataModel.getEnums().forEach((et) => {\n this.sourceFile.addEnum({\n name: et.name,\n isExported: true,\n members: et.members.map((mem) => ({ name: mem, initializer: `\"${mem}\"` })),\n });\n });\n }\n\n private generateModels() {\n this.dataModel.getEntityTypes().forEach((model) => {\n this.generateModel(model);\n if (!this.options.skipIdModels) {\n this.generateIdModel(model);\n }\n if (!this.options.skipEditableModels) {\n this.generateEditableModel(model);\n }\n if (!this.options.skipOperations) {\n this.generateBoundOperationParams(model.fqName);\n }\n });\n this.dataModel.getComplexTypes().forEach((model) => {\n this.generateModel(model);\n if (!this.options.skipEditableModels) {\n this.generateEditableModel(model);\n }\n });\n\n this.sourceFile.addImportDeclarations(this.importContainer.getImportDeclarations());\n }\n\n private generateModel(model: ComplexType | ModelType) {\n this.sourceFile.addInterface({\n name: model.name,\n isExported: true,\n properties: model.props.map((p) => {\n const isEntity = p.dataType == DataTypes.ModelType;\n return {\n name: p.name,\n type: this.getPropType(p),\n // props for entities or entity collections are not added in V4 if not explicitly expanded\n hasQuestionToken: this.dataModel.isV4() && isEntity,\n docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\n };\n }),\n extends: model.baseClasses.map((bc) => this.namingHelper.getModelName(bc)),\n });\n }\n\n private generatePropDoc(prop: PropertyModel, model: ComplexType | ModelType): OptionalKind<JSDocStructure> {\n const isKeyProp = (model as ModelType).keyNames?.includes(prop.odataName);\n const baseAttribs: Array<string> = [];\n if (isKeyProp) {\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\n }\n if (prop.managed) {\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\n }\n if (prop.converters?.length) {\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\n }\n\n const attributeTable: Array<[string, string]> = [\n [\"Name\", prop.odataName],\n [\"Type\", prop.odataType],\n ];\n if (prop.required) {\n attributeTable.push([\"Nullable\", \"false\"]);\n }\n\n const description =\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\n \"OData Attributes:\\n\" +\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\n\n return { kind: StructureKind.JSDoc, description };\n }\n\n private getPropType(prop: PropertyModel): string {\n const isEntity = prop.dataType == DataTypes.ModelType;\n\n // V2 entity special: deferred content\n let suffix = \"\";\n if (isEntity && this.dataModel.isV2()) {\n this.importContainer.addFromCore(DEFERRED_CONTENT);\n suffix = ` | ${DEFERRED_CONTENT}`;\n }\n // custom types which require type imports => possible via converters\n else if (prop.typeModule) {\n this.importContainer.addCustomType(prop.typeModule, prop.type);\n }\n\n // Collections\n if (prop.isCollection) {\n const type = `Array<${prop.type}>`;\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\n return `{ results: ${type} }` + suffix;\n } else {\n return type + suffix;\n }\n }\n\n // primitive, enum & complex types\n return prop.type + (prop.required ? \"\" : \" | null\") + suffix;\n }\n\n private generateIdModel(model: ModelType) {\n if (!model.generateId) {\n return;\n }\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\n const keyTypes = model.keys.map((keyProp) => `${keyProp.name}: ${this.getPropType(keyProp)}`).join(\",\");\n const type = `${singleType}{${keyTypes}}`;\n\n this.sourceFile.addTypeAlias({\n name: model.idModelName,\n isExported: true,\n type,\n });\n }\n\n private generateEditableModel(model: ComplexType) {\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\n\n const requiredProps = allProps\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\n .map((p) => `\"${p.name}\"`)\n .join(\" | \");\n const optionalProps = allProps\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\n .map((p) => `\"${p.name}\"`)\n .join(\" | \");\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\n\n const extendsClause = [\n requiredProps ? `Pick<${model.name}, ${requiredProps}>` : null,\n optionalProps ? `Partial<Pick<${model.name}, ${optionalProps}>>` : null,\n ].filter((e): e is string => !!e);\n\n this.sourceFile.addInterface({\n name: model.editableName,\n isExported: true,\n extends: extendsClause,\n properties: !complexProps\n ? undefined\n : complexProps.map((p) => {\n return {\n name: p.name,\n type: this.getEditablePropType(p),\n // optional props don't need to be specified in editable model\n // also, entities would require deep insert func => we make it optional for now\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\n };\n }),\n });\n }\n\n private getEditablePropType(prop: PropertyModel): string {\n const type =\n prop.dataType === DataTypes.ModelType\n ? this.dataModel.getEntityType(prop.fqType)!.editableName\n : prop.dataType === DataTypes.ComplexType\n ? this.dataModel.getComplexType(prop.fqType)!.editableName\n : prop.type;\n\n // Collections\n if (prop.isCollection) {\n return `Array<${type}>`;\n }\n\n // primitive, enum & complex types\n return type + (prop.required ? \"\" : \" | null\");\n }\n\n private generateUnboundOperationParams() {\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\n this.generateOperationParams(operation);\n });\n }\n\n private generateBoundOperationParams(entityName: string) {\n [\n ...this.dataModel.getEntityTypeOperations(entityName),\n ...this.dataModel.getEntitySetOperations(entityName),\n ].forEach((operation) => {\n this.generateOperationParams(operation);\n });\n }\n\n private generateOperationParams(operation: OperationType) {\n if (!operation.parameters.length) {\n return;\n }\n this.sourceFile.addInterface({\n name: operation.paramsModelName,\n isExported: true,\n properties: operation.parameters.map((p) => {\n return {\n name: p.name,\n type: this.getPropType(p),\n hasQuestionToken: !p.required,\n };\n }),\n });\n }\n}\n"]}
1
+ {"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";;;AACA,uCAAmF;AAMnF,uDAAoD;AAE7C,MAAM,cAAc,GAAiC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACpH,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,cAAc;IAGlB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,cAAS,G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AAI,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 { JSDocStructure, OptionalKind, SourceFile, StructureKind } 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.getEntityTypes().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.fqName);\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 | ModelType) {\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 docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\r\n };\r\n }),\r\n extends: model.baseClasses.map((bc) => this.namingHelper.getModelName(bc)),\r\n });\r\n }\r\n\r\n private generatePropDoc(prop: PropertyModel, model: ComplexType | ModelType): OptionalKind<JSDocStructure> {\r\n const isKeyProp = (model as ModelType).keyNames?.includes(prop.odataName);\r\n const baseAttribs: Array<string> = [];\r\n if (isKeyProp) {\r\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\r\n }\r\n if (prop.managed) {\r\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\r\n }\r\n if (prop.converters?.length) {\r\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\r\n }\r\n\r\n const attributeTable: Array<[string, string]> = [\r\n [\"Name\", prop.odataName],\r\n [\"Type\", prop.odataType],\r\n ];\r\n if (prop.required) {\r\n attributeTable.push([\"Nullable\", \"false\"]);\r\n }\r\n\r\n const description =\r\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\r\n \"OData Attributes:\\n\" +\r\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\r\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\r\n\r\n return { kind: StructureKind.JSDoc, description };\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.getEntityType(prop.fqType)!.editableName\r\n : prop.dataType === DataTypes.ComplexType\r\n ? this.dataModel.getComplexType(prop.fqType)!.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 [\r\n ...this.dataModel.getEntityTypeOperations(entityName),\r\n ...this.dataModel.getEntitySetOperations(entityName),\r\n ].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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oBACE,IAAI,EAAE,WAAW;oBACjB,UAAU,EAAE,CAAC,oBAAoB,CAAC;iBACnC;gBACD,+GAA+G;gBAC/G,GAAG,CAAC,SAAS,CAAC,IAAI,6CAA4B,IAAI,CAAC,SAAS;oBAC1D,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE,UAAU;4BAChB,UAAU,EAAE,CAAC,kCAAkC,CAAC;yBACjD;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\nimport { ODataVersions } from \"@odata2ts/odata-core\";\nimport { OptionalKind, PropertyDeclarationStructure, Scope, SourceFile, VariableDeclarationKind } from \"ts-morph\";\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport {\n ComplexType,\n DataTypes,\n ModelType,\n OperationType,\n OperationTypes,\n PropertyModel,\n} from \"../data-model/DataTypeModel\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\nimport { ImportContainer } from \"./ImportContainer\";\n\nexport const generateQueryObjects: EntityBasedGeneratorFunction = (\n dataModel,\n sourceFile,\n version,\n options,\n namingHelper\n) => {\n const generator = new QueryObjectGenerator(dataModel, sourceFile, version, options, namingHelper);\n return generator.generate();\n};\n\nclass QueryObjectGenerator {\n constructor(\n private dataModel: DataModel,\n private sourceFile: SourceFile,\n private version: ODataVersions,\n private options: GeneratorFunctionOptions,\n private namingHelper: NamingHelper\n ) {}\n\n public generate(): void {\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n this.generateModels(importContainer);\n if (!this.options.skipOperations) {\n this.generateUnboundOperations(importContainer);\n }\n\n this.sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\n }\n\n private generateModels(importContainer: ImportContainer) {\n this.dataModel.getEntityTypes().forEach((model) => {\n this.generateModel(model, importContainer);\n if (!this.options.skipIdModels) {\n this.generateIdFunction(model, importContainer);\n }\n if (!this.options.skipOperations) {\n this.generateBoundOperations(model.fqName, importContainer);\n }\n });\n this.dataModel.getComplexTypes().forEach((model) => {\n this.generateModel(model, importContainer);\n });\n\n if (this.dataModel.getEntityTypes().length || this.dataModel.getComplexTypes().length) {\n importContainer.addFromQObject(\"QueryObject\");\n }\n }\n\n private generateModel(model: ComplexType, importContainer: ImportContainer) {\n let extendsClause = \"QueryObject\";\n if (model.baseClasses.length) {\n const baseClass = model.baseClasses[0];\n const baseModel = this.dataModel.getEntityType(baseClass) || this.dataModel.getComplexType(baseClass);\n if (!baseModel) {\n throw new Error(`Entity or complex type \"${baseClass}\" from baseClass attribute not found!`);\n }\n\n extendsClause = baseModel.qName;\n }\n\n this.sourceFile.addClass({\n name: model.qName,\n isExported: true,\n extends: extendsClause,\n properties: this.generateQueryObjectProps(model.props, importContainer),\n });\n\n this.sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: firstCharLowerCase(model.qName),\n initializer: `new ${model.qName}()`,\n },\n ],\n });\n }\n\n private generateQueryObjectProps(\n props: Array<PropertyModel>,\n importContainer: ImportContainer\n ): Array<OptionalKind<PropertyDeclarationStructure>> {\n return props.map((prop) => {\n const { odataName } = prop;\n const name = this.namingHelper.getQPropName(prop.name);\n const isModelType = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\n let qPathInit: string;\n\n // factor in collections\n if (prop.isCollection) {\n const cType = `Q${isModelType ? \"Entity\" : \"\"}CollectionPath`;\n const qObject = prop.qObject;\n\n if (!qObject) {\n throw new Error(\"QObject for collection is missing!\");\n }\n\n qPathInit = `new ${cType}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\n\n importContainer.addFromQObject(cType);\n if (!isModelType) {\n importContainer.addFromQObject(qObject);\n }\n } else {\n if (isModelType) {\n qPathInit = `new ${prop.qPath}(this.withPrefix(\"${odataName}\"), () => ${prop.qObject!})`;\n } else {\n let converterStmt = this.generateConverterStmt(prop.converters, importContainer);\n qPathInit = `new ${prop.qPath}(this.withPrefix(\"${odataName}\")${converterStmt ? `, ${converterStmt}` : \"\"})`;\n }\n // add import for data type\n importContainer.addFromQObject(prop.qPath);\n }\n\n return {\n name,\n scope: Scope.Public,\n isReadonly: true,\n initializer: qPathInit,\n } as OptionalKind<PropertyDeclarationStructure>;\n });\n }\n\n private generateConverterStmt(converters: Array<ValueConverterImport> | undefined, importContainer: ImportContainer) {\n if (!converters?.length) {\n return;\n }\n converters.forEach((converter) => {\n importContainer.addCustomType(converter.package, converter.converterId);\n });\n\n if (converters.length === 1) {\n return converters[0].converterId;\n } else {\n importContainer.addCustomType(\"@odata2ts/converter-runtime\", \"createChain\");\n\n const [first, second, ...moreConverters] = converters;\n return moreConverters.reduce(\n (stmt, conv) => `${stmt}.chain(${conv.converterId})`,\n `createChain(${first.converterId}, ${second.converterId})`\n );\n }\n }\n\n private generateIdFunction(model: ModelType, importContainer: ImportContainer) {\n if (!model.generateId) {\n return;\n }\n\n const qFunc = \"QId\";\n importContainer.addFromQObject(qFunc);\n importContainer.addGeneratedModel(model.idModelName);\n\n this.sourceFile.addClass({\n name: model.qIdFunctionName,\n isExported: true,\n extends: `${qFunc}<${model.idModelName}>`,\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n initializer: this.getParamInitString(model.keys, importContainer),\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n ],\n });\n }\n\n private getParamInitString(props: Array<PropertyModel>, importContainer: ImportContainer) {\n return `[${props\n .map((prop) => {\n const isComplexParam = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\n if (prop.qParam) {\n importContainer.addFromQObject(prop.qParam);\n }\n const isMappedNameNecessary = prop.odataName !== prop.name;\n const mappedName = isMappedNameNecessary ? `\"${prop.name}\"` : prop.converters?.length ? \"undefined\" : undefined;\n const converterStmt = this.generateConverterStmt(prop.converters, importContainer);\n const mappedNameParam = mappedName ? `, ${mappedName}` : \"\";\n const complexQParam = isComplexParam ? `, new ${prop.qObject}()` : \"\";\n const converterParam = converterStmt ? `, ${converterStmt}` : \"\";\n return `new ${prop.qParam}(\"${prop.odataName}\"${complexQParam}${mappedNameParam}${converterParam})`;\n })\n .join(\",\")}]`;\n }\n\n private generateUnboundOperations(importContainer: ImportContainer) {\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\n this.generateOperation(operation, importContainer);\n });\n }\n\n private generateBoundOperations(fqEntityName: string, importContainer: ImportContainer) {\n [\n ...this.dataModel.getEntityTypeOperations(fqEntityName),\n ...this.dataModel.getEntitySetOperations(fqEntityName),\n ].forEach((operation) => {\n this.generateOperation(operation, importContainer);\n });\n }\n\n private generateOperation(operation: OperationType, importContainer: ImportContainer) {\n const isV2 = this.version === ODataVersions.V2;\n const qOperation = operation.type === OperationTypes.Action ? \"QAction\" : \"QFunction\";\n const returnType = operation.returnType;\n let returnTypeOpStmt: string = \"\";\n const hasParams = operation.parameters.length > 0;\n importContainer.addFromQObject(qOperation);\n if (hasParams) {\n importContainer.addGeneratedModel(operation.paramsModelName);\n }\n if (returnType) {\n if (returnType.dataType === DataTypes.ComplexType || returnType.dataType === DataTypes.ModelType) {\n if (returnType.qObject) {\n importContainer.addFromQObject(\"OperationReturnType\", \"ReturnTypes\", \"QComplexParam\");\n returnTypeOpStmt = `new OperationReturnType(ReturnTypes.COMPLEX${\n returnType.isCollection ? \"_COLLECTION\" : \"\"\n }, new QComplexParam(\"NONE\", new ${returnType.qObject}))`;\n }\n }\n // currently, it only makes sense to add the OperationReturnType if a converter is present\n else if (returnType.converters && returnType.qParam) {\n importContainer.addFromQObject(\"OperationReturnType\", \"ReturnTypes\", returnType.qParam);\n const rtKind = \"ReturnTypes.VALUE\" + (returnType.isCollection ? \"_COLLECTION\" : \"\");\n const converterParam = returnType.converters\n ? \", \" + this.generateConverterStmt(returnType.converters, importContainer)\n : \"\";\n returnTypeOpStmt = `new OperationReturnType(${rtKind}, new ${returnType.qParam}(\"NONE\", undefined${converterParam}))`;\n }\n }\n\n this.sourceFile.addClass({\n name: operation.qName,\n isExported: true,\n extends: qOperation + (hasParams ? `<${operation.paramsModelName}>` : \"\"),\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n type: operation.parameters?.length ? undefined : \"[]\",\n initializer: this.getParamInitString(operation.parameters, importContainer),\n },\n ],\n ctors: [\n {\n statements: [\n `super(\"${operation.odataName}\"${returnTypeOpStmt ? \", \" + returnTypeOpStmt : isV2 ? \", undefined\" : \"\"}${\n isV2 ? \", { v2Mode: true }\" : \"\"\n })`,\n ],\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n // functions without params: add an overriding buildUrl() to not force users to have to pass undefined as param\n ...(operation.type === OperationTypes.Function && !hasParams\n ? [\n {\n name: \"buildUrl\",\n statements: [\"return super.buildUrl(undefined)\"],\n },\n ]\n : []),\n ],\n });\n }\n}\n"]}
1
+ {"version":3,"file":"QueryObjectGenerator.js","sourceRoot":"","sources":["../../src/generator/QueryObjectGenerator.ts"],"names":[],"mappings":";;;AACA,qDAAqD;AACrD,uCAAkH;AAClH,sDAA2D;AAa3D,uDAAoD;AAE7C,MAAM,oBAAoB,GAAiC,CAChE,SAAS,EACT,UAAU,EACV,OAAO,EACP,OAAO,EACP,YAAY,EACZ,EAAE;IACF,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAClG,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AATW,QAAA,oBAAoB,wBAS/B;AAEF,MAAM,oBAAoB;IACxB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,cAAS,GAAT,SAAS,CAAW;QACpB,e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,CAAC;YACzE,UAAU,EAAE;gBACV;oBACE,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,gBAAK,CAAC,OAAO;oBACpB,UAAU,EAAE,IAAI;oBAChB,IAAI,EAAE,CAAA,MAAA,SAAS,CAAC,UAAU,0CAAE,MAAM,EAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;oBACrD,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,UAAU,EAAE,eAAe,CAAC;iBAC5E;aACF;YACD,KAAK,EAAE;gBACL;oBACE,UAAU,EAAE;wBACV,UAAU,SAAS,CAAC,SAAS,IAAI,gBAAgB,CAAC,CAAC,CAAC,IAAI,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GACrG,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAChC,GAAG;qBACJ;iBACF;aACF;YACD,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,WAAW;oBACjB,UAAU,EAAE,CAAC,oBAAoB,CAAC;iBACnC;gBACD,+GAA+G;gBAC/G,GAAG,CAAC,SAAS,CAAC,IAAI,6CAA4B,IAAI,CAAC,SAAS;oBAC1D,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE,UAAU;4BAChB,UAAU,EAAE,CAAC,kCAAkC,CAAC;yBACjD;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\r\nimport { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { OptionalKind, PropertyDeclarationStructure, Scope, SourceFile, VariableDeclarationKind } from \"ts-morph\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport {\r\n ComplexType,\r\n DataTypes,\r\n ModelType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n} from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nexport const generateQueryObjects: EntityBasedGeneratorFunction = (\r\n dataModel,\r\n sourceFile,\r\n version,\r\n options,\r\n namingHelper\r\n) => {\r\n const generator = new QueryObjectGenerator(dataModel, sourceFile, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nclass QueryObjectGenerator {\r\n constructor(\r\n private dataModel: DataModel,\r\n private sourceFile: SourceFile,\r\n private version: ODataVersions,\r\n private options: GeneratorFunctionOptions,\r\n private namingHelper: NamingHelper\r\n ) {}\r\n\r\n public generate(): void {\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n this.generateModels(importContainer);\r\n if (!this.options.skipOperations) {\r\n this.generateUnboundOperations(importContainer);\r\n }\r\n\r\n this.sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\r\n }\r\n\r\n private generateModels(importContainer: ImportContainer) {\r\n this.dataModel.getEntityTypes().forEach((model) => {\r\n this.generateModel(model, importContainer);\r\n if (!this.options.skipIdModels) {\r\n this.generateIdFunction(model, importContainer);\r\n }\r\n if (!this.options.skipOperations) {\r\n this.generateBoundOperations(model.fqName, importContainer);\r\n }\r\n });\r\n this.dataModel.getComplexTypes().forEach((model) => {\r\n this.generateModel(model, importContainer);\r\n });\r\n\r\n if (this.dataModel.getEntityTypes().length || this.dataModel.getComplexTypes().length) {\r\n importContainer.addFromQObject(\"QueryObject\");\r\n }\r\n }\r\n\r\n private generateModel(model: ComplexType, importContainer: ImportContainer) {\r\n let extendsClause = \"QueryObject\";\r\n if (model.baseClasses.length) {\r\n const baseClass = model.baseClasses[0];\r\n const baseModel = this.dataModel.getEntityType(baseClass) || this.dataModel.getComplexType(baseClass);\r\n if (!baseModel) {\r\n throw new Error(`Entity or complex type \"${baseClass}\" from baseClass attribute not found!`);\r\n }\r\n\r\n extendsClause = baseModel.qName;\r\n }\r\n\r\n this.sourceFile.addClass({\r\n name: model.qName,\r\n isExported: true,\r\n extends: extendsClause,\r\n properties: this.generateQueryObjectProps(model.props, importContainer),\r\n });\r\n\r\n this.sourceFile.addVariableStatement({\r\n declarationKind: VariableDeclarationKind.Const,\r\n isExported: true,\r\n declarations: [\r\n {\r\n name: firstCharLowerCase(model.qName),\r\n initializer: `new ${model.qName}()`,\r\n },\r\n ],\r\n });\r\n }\r\n\r\n private generateQueryObjectProps(\r\n props: Array<PropertyModel>,\r\n importContainer: ImportContainer\r\n ): Array<OptionalKind<PropertyDeclarationStructure>> {\r\n return props.map((prop) => {\r\n const { odataName } = prop;\r\n const name = this.namingHelper.getQPropName(prop.name);\r\n const isModelType = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\r\n let qPathInit: string;\r\n\r\n // factor in collections\r\n if (prop.isCollection) {\r\n const cType = `Q${isModelType ? \"Entity\" : \"\"}CollectionPath`;\r\n const qObject = prop.qObject;\r\n\r\n if (!qObject) {\r\n throw new Error(\"QObject for collection is missing!\");\r\n }\r\n\r\n qPathInit = `new ${cType}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\r\n\r\n importContainer.addFromQObject(cType);\r\n if (!isModelType) {\r\n importContainer.addFromQObject(qObject);\r\n }\r\n } else {\r\n if (isModelType) {\r\n qPathInit = `new ${prop.qPath}(this.withPrefix(\"${odataName}\"), () => ${prop.qObject!})`;\r\n } else {\r\n let converterStmt = this.generateConverterStmt(prop.converters, importContainer);\r\n qPathInit = `new ${prop.qPath}(this.withPrefix(\"${odataName}\")${converterStmt ? `, ${converterStmt}` : \"\"})`;\r\n }\r\n // add import for data type\r\n importContainer.addFromQObject(prop.qPath);\r\n }\r\n\r\n return {\r\n name,\r\n scope: Scope.Public,\r\n isReadonly: true,\r\n initializer: qPathInit,\r\n } as OptionalKind<PropertyDeclarationStructure>;\r\n });\r\n }\r\n\r\n private generateConverterStmt(converters: Array<ValueConverterImport> | undefined, importContainer: ImportContainer) {\r\n if (!converters?.length) {\r\n return;\r\n }\r\n converters.forEach((converter) => {\r\n importContainer.addCustomType(converter.package, converter.converterId);\r\n });\r\n\r\n if (converters.length === 1) {\r\n return converters[0].converterId;\r\n } else {\r\n importContainer.addCustomType(\"@odata2ts/converter-runtime\", \"createChain\");\r\n\r\n const [first, second, ...moreConverters] = converters;\r\n return moreConverters.reduce(\r\n (stmt, conv) => `${stmt}.chain(${conv.converterId})`,\r\n `createChain(${first.converterId}, ${second.converterId})`\r\n );\r\n }\r\n }\r\n\r\n private generateIdFunction(model: ModelType, importContainer: ImportContainer) {\r\n if (!model.generateId) {\r\n return;\r\n }\r\n\r\n const qFunc = \"QId\";\r\n importContainer.addFromQObject(qFunc);\r\n importContainer.addGeneratedModel(model.idModelName);\r\n\r\n this.sourceFile.addClass({\r\n name: model.qIdFunctionName,\r\n isExported: true,\r\n extends: `${qFunc}<${model.idModelName}>`,\r\n properties: [\r\n {\r\n name: \"params\",\r\n scope: Scope.Private,\r\n isReadonly: true,\r\n initializer: this.getParamInitString(model.keys, importContainer),\r\n },\r\n ],\r\n methods: [\r\n {\r\n name: \"getParams\",\r\n statements: [\"return this.params\"],\r\n },\r\n ],\r\n });\r\n }\r\n\r\n private getParamInitString(props: Array<PropertyModel>, importContainer: ImportContainer) {\r\n return `[${props\r\n .map((prop) => {\r\n const isComplexParam = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\r\n if (prop.qParam) {\r\n importContainer.addFromQObject(prop.qParam);\r\n }\r\n const isMappedNameNecessary = prop.odataName !== prop.name;\r\n const mappedName = isMappedNameNecessary ? `\"${prop.name}\"` : prop.converters?.length ? \"undefined\" : undefined;\r\n const converterStmt = this.generateConverterStmt(prop.converters, importContainer);\r\n const mappedNameParam = mappedName ? `, ${mappedName}` : \"\";\r\n const complexQParam = isComplexParam ? `, new ${prop.qObject}()` : \"\";\r\n const converterParam = converterStmt ? `, ${converterStmt}` : \"\";\r\n return `new ${prop.qParam}(\"${prop.odataName}\"${complexQParam}${mappedNameParam}${converterParam})`;\r\n })\r\n .join(\",\")}]`;\r\n }\r\n\r\n private generateUnboundOperations(importContainer: ImportContainer) {\r\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\r\n this.generateOperation(operation, importContainer);\r\n });\r\n }\r\n\r\n private generateBoundOperations(fqEntityName: string, importContainer: ImportContainer) {\r\n [\r\n ...this.dataModel.getEntityTypeOperations(fqEntityName),\r\n ...this.dataModel.getEntitySetOperations(fqEntityName),\r\n ].forEach((operation) => {\r\n this.generateOperation(operation, importContainer);\r\n });\r\n }\r\n\r\n private generateOperation(operation: OperationType, importContainer: ImportContainer) {\r\n const isV2 = this.version === ODataVersions.V2;\r\n const qOperation = operation.type === OperationTypes.Action ? \"QAction\" : \"QFunction\";\r\n const returnType = operation.returnType;\r\n let returnTypeOpStmt: string = \"\";\r\n const hasParams = operation.parameters.length > 0;\r\n importContainer.addFromQObject(qOperation);\r\n if (hasParams) {\r\n importContainer.addGeneratedModel(operation.paramsModelName);\r\n }\r\n if (returnType) {\r\n if (returnType.dataType === DataTypes.ComplexType || returnType.dataType === DataTypes.ModelType) {\r\n if (returnType.qObject) {\r\n importContainer.addFromQObject(\"OperationReturnType\", \"ReturnTypes\", \"QComplexParam\");\r\n returnTypeOpStmt = `new OperationReturnType(ReturnTypes.COMPLEX${\r\n returnType.isCollection ? \"_COLLECTION\" : \"\"\r\n }, new QComplexParam(\"NONE\", new ${returnType.qObject}))`;\r\n }\r\n }\r\n // currently, it only makes sense to add the OperationReturnType if a converter is present\r\n else if (returnType.converters && returnType.qParam) {\r\n importContainer.addFromQObject(\"OperationReturnType\", \"ReturnTypes\", returnType.qParam);\r\n const rtKind = \"ReturnTypes.VALUE\" + (returnType.isCollection ? \"_COLLECTION\" : \"\");\r\n const converterParam = returnType.converters\r\n ? \", \" + this.generateConverterStmt(returnType.converters, importContainer)\r\n : \"\";\r\n returnTypeOpStmt = `new OperationReturnType(${rtKind}, new ${returnType.qParam}(\"NONE\", undefined${converterParam}))`;\r\n }\r\n }\r\n\r\n this.sourceFile.addClass({\r\n name: operation.qName,\r\n isExported: true,\r\n extends: qOperation + (hasParams ? `<${operation.paramsModelName}>` : \"\"),\r\n properties: [\r\n {\r\n name: \"params\",\r\n scope: Scope.Private,\r\n isReadonly: true,\r\n type: operation.parameters?.length ? undefined : \"[]\",\r\n initializer: this.getParamInitString(operation.parameters, importContainer),\r\n },\r\n ],\r\n ctors: [\r\n {\r\n statements: [\r\n `super(\"${operation.odataName}\"${returnTypeOpStmt ? \", \" + returnTypeOpStmt : isV2 ? \", undefined\" : \"\"}${\r\n isV2 ? \", { v2Mode: true }\" : \"\"\r\n })`,\r\n ],\r\n },\r\n ],\r\n methods: [\r\n {\r\n name: \"getParams\",\r\n statements: [\"return this.params\"],\r\n },\r\n // functions without params: add an overriding buildUrl() to not force users to have to pass undefined as param\r\n ...(operation.type === OperationTypes.Function && !hasParams\r\n ? [\r\n {\r\n name: \"buildUrl\",\r\n statements: [\"return super.buildUrl(undefined)\"],\r\n },\r\n ]\r\n : []),\r\n ],\r\n });\r\n }\r\n}\r\n"]}
@@ -369,7 +369,7 @@ class ServiceGenerator {
369
369
  importContainer.addFromService(entitySetServiceType);
370
370
  importContainer.addGeneratedModel(model.idModelName);
371
371
  importContainer.addGeneratedQObject(model.qIdFunctionName);
372
- const collectionOperations = this.dataModel.getEntityTypeOperations(`Collection(${model.fqName})`);
372
+ const collectionOperations = this.dataModel.getEntitySetOperations(model.fqName);
373
373
  const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);
374
374
  serviceFile.addClass({
375
375
  isExported: true,
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceGenerator.js","sourceRoot":"","sources":["../../src/generator/ServiceGenerator.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AACrD,kEAAkC;AAClC,uCAOkB;AAClB,u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AC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK;gBACvF,GAAG,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,QAAQ,WAClD,CAAC,MAAM;oBACL,CAAC,CAAC,oBAAoB;wBACpB,aAAa,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,4BAA4B,CAAC,CAAC,CAAC,IAAI,KACpE,kBAAkB,CAAC,IACrB,wBAAwB;oBAC1B,CAAC,CAAC,SAAS,CAAC,OAAO;wBACnB,CAAC,CAAC,sFAAsF;4BACtF,wBAAwB,kBAAkB,CAAC,IAAI,wBAAwB;wBACzE,CAAC,CAAC,sBAAsB;4BACtB,YAAY,kBAAkB,CAAC,IAAI,wBACzC,GAAG;gBACH,UAAU,CAAC,CAAC,CAAC,UAAU,OAAO,6BAA6B,CAAC,CAAC,CAAC,EAAE;aACjE;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport deepmerge from \"deepmerge\";\r\nimport {\r\n ClassDeclarationStructure,\r\n MethodDeclarationStructure,\r\n OptionalKind,\r\n PropertyDeclarationStructure,\r\n Scope,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport { upperCaseFirst } from \"upper-case-first\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntityContainerModel,\r\n FunctionImportType,\r\n ModelType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { ConfigFileOptions } from \"../OptionModel\";\r\nimport { ProjectManager } from \"../project/ProjectManager\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nconst ROOT_SERVICE = \"ODataService\";\r\n\r\nconst RESPONSE_TYPES = {\r\n collection: \"ODataCollectionResponse\",\r\n model: \"ODataModelResponse\",\r\n value: \"ODataValueResponse\",\r\n};\r\n\r\nexport interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, \"properties\" | \"methods\">> {}\r\n\r\nexport interface ServiceGeneratorOptions\r\n extends Pick<ConfigFileOptions, \"enablePrimitivePropertyServices\" | \"v4BigNumberAsString\"> {}\r\n\r\nexport async function generateServices(\r\n dataModel: DataModel,\r\n project: ProjectManager,\r\n version: ODataVersions,\r\n namingHelper: NamingHelper,\r\n options?: ServiceGeneratorOptions\r\n) {\r\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper, options);\r\n return generator.generate();\r\n}\r\n\r\nclass ServiceGenerator {\r\n constructor(\r\n private dataModel: DataModel,\r\n private project: ProjectManager,\r\n private version: ODataVersions,\r\n private namingHelper: NamingHelper,\r\n private options: ServiceGeneratorOptions = {}\r\n ) {}\r\n\r\n private isV4BigNumber() {\r\n return this.options.v4BigNumberAsString && this.version === ODataVersions.V4;\r\n }\r\n\r\n public async generate(): Promise<void> {\r\n const sourceFile = await this.project.createMainServiceFile();\r\n const serviceName = this.namingHelper.getMainServiceName();\r\n const container = this.dataModel.getEntityContainer();\r\n const unboundOperations = [...Object.values(container.functions), ...Object.values(container.actions)];\r\n\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addFromService(ROOT_SERVICE);\r\n\r\n const { properties, methods }: PropsAndOps = deepmerge(\r\n this.generateMainServiceProperties(container, importContainer),\r\n this.generateMainServiceOperations(unboundOperations, importContainer)\r\n );\r\n\r\n sourceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends: `${ROOT_SERVICE}<ClientType>`,\r\n ctors: this.isV4BigNumber()\r\n ? [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n ],\r\n statements: [`super(client, basePath, true);`],\r\n },\r\n ]\r\n : [],\r\n properties,\r\n methods,\r\n });\r\n\r\n await this.generateModelServices(sourceFile, importContainer);\r\n\r\n sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\r\n }\r\n\r\n private generateMainServiceProperties(\r\n container: EntityContainerModel,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n Object.values(container.entitySets).forEach(({ name, odataName, entityType }) => {\r\n result.methods.push(this.generateRelatedServiceGetter(name, odataName, entityType, importContainer));\r\n });\r\n\r\n Object.values(container.singletons).forEach((singleton) => {\r\n result.properties.push(this.generateSingletonProp(singleton, importContainer));\r\n result.methods.push(this.generateSingletonGetter(singleton));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateMainServiceOperations(\r\n ops: Array<FunctionImportType | ActionImportType>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n ops.forEach(({ operation, name }) => {\r\n const op = this.dataModel.getUnboundOperationType(operation);\r\n if (!op) {\r\n throw new Error(`Operation \"${operation}\" not found!`);\r\n }\r\n\r\n result.properties.push(this.generateQOperationProp(op));\r\n result.methods.push(this.generateMethod(name, op, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateRelatedServiceGetter(\r\n propName: string,\r\n odataPropName: string,\r\n entityType: ModelType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const idName = entityType.idModelName;\r\n const idFunctionName = entityType.qIdFunctionName;\r\n const serviceName = this.namingHelper.getServiceName(entityType.name);\r\n const collectionName = this.namingHelper.getCollectionServiceName(entityType.name);\r\n\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addGeneratedModel(idName);\r\n importContainer.addGeneratedQObject(idFunctionName);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(propName),\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: `${idName} | undefined`,\r\n hasQuestionToken: true,\r\n },\r\n ],\r\n overloads: [\r\n {\r\n parameters: [],\r\n returnType: `${collectionName}<ClientType>`,\r\n },\r\n {\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: idName,\r\n },\r\n ],\r\n returnType: `${serviceName}<ClientType>`,\r\n },\r\n ],\r\n statements: [\r\n `const fieldName = \"${odataPropName}\";`,\r\n `const { client, path } = this.__base;`,\r\n 'return typeof id === \"undefined\" || id === null',\r\n `? new ${collectionName}(client, path, fieldName)`,\r\n `: new ${serviceName}(client, path, new ${idFunctionName}(fieldName).buildUrl(id));`,\r\n ],\r\n };\r\n }\r\n\r\n private generateSingletonProp(\r\n singleton: SingletonType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const { name, entityType } = singleton;\r\n const type = this.namingHelper.getServiceName(entityType.name);\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(name),\r\n type: `${type}<ClientType>`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateQOperationProp = (operation: OperationType) => {\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(operation.qName),\r\n type: operation.qName,\r\n hasQuestionToken: true,\r\n };\r\n };\r\n\r\n private generateSingletonGetter(singleton: SingletonType): OptionalKind<MethodDeclarationStructure> {\r\n const { name, odataName, entityType } = singleton;\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(name);\r\n const serviceType = this.namingHelper.getServiceName(entityType.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${propName} = new ${serviceType}(client, path, \"${odataName}\")`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private getVersionSuffix() {\r\n return this.version === ODataVersions.V2 ? \"V2\" : \"V4\";\r\n }\r\n\r\n private async generateEntityTypeService(\r\n model: ComplexType,\r\n serviceName: string,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entityServiceType = \"EntityTypeService\" + this.getVersionSuffix();\r\n\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n const operations = this.dataModel.getEntityTypeOperations(model.fqName);\r\n const props = [...model.baseProps, ...model.props];\r\n\r\n importContainer.addFromService(entityServiceType);\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addGeneratedModel(model.name, editableModelName);\r\n importContainer.addGeneratedQObject(model.qName, qObjectName);\r\n\r\n const { properties, methods }: PropsAndOps = deepmerge(\r\n this.generateServiceProperties(serviceName, props, importContainer),\r\n this.generateServiceOperations(operations, importContainer)\r\n );\r\n\r\n // generate EntityTypeService\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends: entityServiceType + `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [`super(client, basePath, name, ${qObjectName}${this.isV4BigNumber() ? \", true\" : \"\"});`],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private getPrimitiveServiceType() {\r\n return \"PrimitiveTypeService\" + this.getVersionSuffix();\r\n }\r\n\r\n private generateServiceProperties(\r\n serviceName: string,\r\n props: Array<PropertyModel>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const collectionServiceType = \"CollectionService\" + this.getVersionSuffix();\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n props.forEach((prop) => {\r\n if ((prop.dataType === DataTypes.ModelType && !prop.isCollection) || prop.dataType === DataTypes.ComplexType) {\r\n result.properties.push(this.generateModelProp(prop, collectionServiceType, serviceName, importContainer));\r\n result.methods.push(this.generateModelPropGetter(prop, collectionServiceType));\r\n } else if (prop.isCollection) {\r\n // collection of entity types\r\n if (prop.dataType === DataTypes.ModelType) {\r\n const entityType = this.dataModel.getEntityType(prop.fqType);\r\n if (!entityType) {\r\n throw new Error(`Entity type \"${prop.fqType}\" specified by property not found!`);\r\n }\r\n\r\n result.methods.push(\r\n this.generateRelatedServiceGetter(prop.name, prop.odataName, entityType, importContainer)\r\n );\r\n }\r\n // collection of primitive or complex types\r\n else {\r\n result.properties.push(this.generatePrimitiveCollectionProp(prop, collectionServiceType, importContainer));\r\n result.methods.push(this.generatePrimitiveCollectionGetter(prop, collectionServiceType));\r\n }\r\n } else if (this.options.enablePrimitivePropertyServices && prop.dataType === DataTypes.PrimitiveType) {\r\n result.properties.push(this.generatePrimitiveTypeProp(prop, importContainer));\r\n result.methods.push(this.generatePrimitiveTypeGetter(prop));\r\n }\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateServiceOperations(operations: Array<OperationType>, importContainer: ImportContainer): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n operations.forEach((operation) => {\r\n result.properties.push(this.generateQOperationProp(operation));\r\n result.methods.push(this.generateMethod(operation.name, operation, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateModelProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n serviceName: string,\r\n importContainer: ImportContainer\r\n ): PropertyDeclarationStructure {\r\n const complexType = this.dataModel.getComplexType(prop.fqType);\r\n const key = this.namingHelper.getServiceName(prop.type);\r\n let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;\r\n\r\n if (prop.isCollection && complexType) {\r\n const editableName = complexType.editableName;\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addGeneratedModel(complexType.name, editableName);\r\n importContainer.addGeneratedQObject(complexType.qName, firstCharLowerCase(complexType.qName));\r\n propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;\r\n } else {\r\n propModelType = `${propModelType}<ClientType>`;\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: propModelType,\r\n hasQuestionToken: true,\r\n } as PropertyDeclarationStructure;\r\n }\r\n\r\n private generatePrimitiveCollectionProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const isEnum = prop.dataType === DataTypes.EnumType;\r\n const type = isEnum ? `EnumCollection<${prop.type}>` : `${upperCaseFirst(prop.type)}Collection`;\r\n const qType = isEnum ? \"QEnumCollection\" : prop.qObject;\r\n const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;\r\n\r\n if (!prop.qObject) {\r\n throw new Error(\"Illegal State: [qObject] must be provided for Collection types!\");\r\n }\r\n\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addFromQObject(prop.qObject, firstCharLowerCase(prop.qObject));\r\n if (isEnum) {\r\n importContainer.addGeneratedModel(prop.type);\r\n importContainer.addFromQObject(\"EnumCollection\");\r\n } else {\r\n importContainer.addFromQObject(type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${collectionType}`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generatePrimitiveTypeProp(\r\n prop: PropertyModel,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const serviceType = this.getPrimitiveServiceType();\r\n importContainer.addFromService(serviceType);\r\n if (prop.typeModule) {\r\n importContainer.addCustomType(prop.typeModule, prop.type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${serviceType}<ClientType, ${prop.type}>`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateModelPropGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const complexType = this.dataModel.getComplexType(prop.fqType);\r\n const isComplexCollection = prop.isCollection && complexType;\r\n const type = isComplexCollection\r\n ? collectionServiceType\r\n : prop.isCollection\r\n ? this.namingHelper.getCollectionServiceName(prop.type)\r\n : this.namingHelper.getServiceName(prop.type);\r\n const typeWithGenerics = isComplexCollection\r\n ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`\r\n : `${type}<ClientType>`;\r\n\r\n const privateSrvProp = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n returnType: typeWithGenerics,\r\n statements: [\r\n `if(!${privateSrvProp}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${privateSrvProp} = new ${type}(client, path, \"${prop.odataName}\"${isComplexCollection ? `, ${firstCharLowerCase(complexType.qName)}`: \"\"})`,\r\n \"}\",\r\n `return ${privateSrvProp}`,\r\n ],\r\n };\r\n }\r\n\r\n private generatePrimitiveCollectionGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${propName} = new ${collectionServiceType}(client, path, \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)}${this.isV4BigNumber() ? \", true\": \"\"})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private generatePrimitiveTypeGetter(prop: PropertyModel): OptionalKind<MethodDeclarationStructure> {\r\n const serviceType = this.getPrimitiveServiceType();\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n // for V2: mapped name must be specified\r\n const useMappedName = this.version === ODataVersions.V2 && prop.name !== prop.odataName;\r\n // for V4: big number support\r\n const useBigNumber = this.isV4BigNumber();\r\n const addParamString = useMappedName ? `, \"${prop.name}\"` : useBigNumber ? \", true\" : \"\";\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path, qModel } = this.__base;`,\r\n ` ${propName} = new ${serviceType}(client, path, \"${prop.odataName}\", qModel.${prop.name}.converter${addParamString})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private async generateEntityCollectionService(\r\n model: ModelType,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entitySetServiceType = \"EntitySetService\" + this.getVersionSuffix();\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n\r\n importContainer.addFromService(entitySetServiceType);\r\n importContainer.addGeneratedModel(model.idModelName);\r\n importContainer.addGeneratedQObject(model.qIdFunctionName);\r\n\r\n const collectionOperations = this.dataModel.getEntityTypeOperations(`Collection(${model.fqName})`);\r\n\r\n const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);\r\n\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: this.namingHelper.getCollectionServiceName(model.name),\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends:\r\n entitySetServiceType +\r\n `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [\r\n `super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name)${\r\n this.isV4BigNumber() ? \", true\" : \"\"\r\n });`,\r\n ],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private async generateModelServices(serviceFile: SourceFile, importContainer: ImportContainer) {\r\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\r\n for (const model of this.dataModel.getEntityTypes()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n\r\n // entity type service\r\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n\r\n // entity collection service\r\n await this.generateEntityCollectionService(model, serviceFile, importContainer);\r\n }\r\n\r\n // build service file for complex types\r\n for (const model of this.dataModel.getComplexTypes()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n\r\n // entity type service\r\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n }\r\n }\r\n\r\n private generateMethod(\r\n name: string,\r\n operation: OperationType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const isFunc = operation.type === OperationTypes.Function;\r\n const odataType = operation.returnType?.isCollection\r\n ? RESPONSE_TYPES.collection + this.getVersionSuffix()\r\n : operation.returnType?.dataType === DataTypes.PrimitiveType\r\n ? RESPONSE_TYPES.value + this.getVersionSuffix()\r\n : RESPONSE_TYPES.model + this.getVersionSuffix();\r\n const returnType = operation.returnType;\r\n const requestConfigParam = {\r\n name: \"requestConfig\",\r\n hasQuestionToken: true,\r\n type: \"ODataHttpClientConfig<ClientType>\",\r\n };\r\n const hasParams = operation.parameters.length > 0;\r\n\r\n // importing dependencies\r\n importContainer.addFromClientApi(\"ODataHttpClientConfig\", \"ODataResponse\");\r\n importContainer.addFromCore(odataType);\r\n if (returnType?.type) {\r\n if ([DataTypes.EnumType, DataTypes.ModelType, DataTypes.ComplexType].includes(returnType.dataType)) {\r\n importContainer.addGeneratedModel(returnType.type);\r\n }\r\n }\r\n importContainer.addGeneratedQObject(operation.qName);\r\n if (hasParams) {\r\n importContainer.addGeneratedModel(operation.paramsModelName);\r\n }\r\n\r\n const qOpProp = \"this.\" + this.namingHelper.getPrivatePropName(operation.qName);\r\n\r\n return {\r\n scope: Scope.Public,\r\n isAsync: true,\r\n name,\r\n parameters: hasParams\r\n ? [{ name: \"params\", type: operation.paramsModelName }, requestConfigParam]\r\n : [requestConfigParam],\r\n returnType: `ODataResponse<${odataType}<${returnType?.type || \"void\"}>>`,\r\n statements: [\r\n `if(!${qOpProp}) {`,\r\n ` ${qOpProp} = new ${operation.qName}()`,\r\n \"}\",\r\n\r\n `const { addFullPath, client, getDefaultHeaders } = this.__base;`,\r\n `const url = addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\r\n `${returnType ? \"const response = await \" : \"return\"} client.${\r\n !isFunc\r\n ? // actions: since V4\r\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${\r\n requestConfigParam.name\r\n }, getDefaultHeaders())`\r\n : operation.usePost\r\n ? // V2 POST => BUT values are still query params, they are not part of the request body\r\n `post(url, undefined, ${requestConfigParam.name}, getDefaultHeaders())`\r\n : // functions: since V2\r\n `get(url, ${requestConfigParam.name}, getDefaultHeaders())`\r\n };`,\r\n returnType ? `return ${qOpProp}.convertResponse(response);` : \"\",\r\n ],\r\n };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ServiceGenerator.js","sourceRoot":"","sources":["../../src/generator/ServiceGenerator.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AACrD,kEAAkC;AAClC,uCAOkB;AAClB,uDAAkD;AAClD,sDAA2D;AAkB3D,uDAAoD;AAEpD,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,MAAM,cAAc,GAAG;IACrB,UAAU,EAAE,yBAAyB;IACrC,KAAK,EAAE,oBAAoB;IAC3B,KAAK,EAAE,oBAAoB;CAC5B,CAAC;AAOF,SAAsB,gBAAgB,CACpC,SAAoB,EACpB,OAAuB,EACvB,OAAsB,EACtB,YAA0B,EAC1B,OAAiC;;QAEjC,MAAM,SAAS,GAAG,I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,CAAC,sFAAsF;4BACtF,wBAAwB,kBAAkB,CAAC,IAAI,wBAAwB;wBACzE,CAAC,CAAC,sBAAsB;4BACtB,YAAY,kBAAkB,CAAC,IAAI,wBACzC,GAAG;gBACH,UAAU,CAAC,CAAC,CAAC,UAAU,OAAO,6BAA6B,CAAC,CAAC,CAAC,EAAE;aACjE;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport deepmerge from \"deepmerge\";\r\nimport {\r\n ClassDeclarationStructure,\r\n MethodDeclarationStructure,\r\n OptionalKind,\r\n PropertyDeclarationStructure,\r\n Scope,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport { upperCaseFirst } from \"upper-case-first\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntityContainerModel,\r\n FunctionImportType,\r\n ModelType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { ConfigFileOptions } from \"../OptionModel\";\r\nimport { ProjectManager } from \"../project/ProjectManager\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nconst ROOT_SERVICE = \"ODataService\";\r\n\r\nconst RESPONSE_TYPES = {\r\n collection: \"ODataCollectionResponse\",\r\n model: \"ODataModelResponse\",\r\n value: \"ODataValueResponse\",\r\n};\r\n\r\nexport interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, \"properties\" | \"methods\">> {}\r\n\r\nexport interface ServiceGeneratorOptions\r\n extends Pick<ConfigFileOptions, \"enablePrimitivePropertyServices\" | \"v4BigNumberAsString\"> {}\r\n\r\nexport async function generateServices(\r\n dataModel: DataModel,\r\n project: ProjectManager,\r\n version: ODataVersions,\r\n namingHelper: NamingHelper,\r\n options?: ServiceGeneratorOptions\r\n) {\r\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper, options);\r\n return generator.generate();\r\n}\r\n\r\nclass ServiceGenerator {\r\n constructor(\r\n private dataModel: DataModel,\r\n private project: ProjectManager,\r\n private version: ODataVersions,\r\n private namingHelper: NamingHelper,\r\n private options: ServiceGeneratorOptions = {}\r\n ) {}\r\n\r\n private isV4BigNumber() {\r\n return this.options.v4BigNumberAsString && this.version === ODataVersions.V4;\r\n }\r\n\r\n public async generate(): Promise<void> {\r\n const sourceFile = await this.project.createMainServiceFile();\r\n const serviceName = this.namingHelper.getMainServiceName();\r\n const container = this.dataModel.getEntityContainer();\r\n const unboundOperations = [...Object.values(container.functions), ...Object.values(container.actions)];\r\n\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addFromService(ROOT_SERVICE);\r\n\r\n const { properties, methods }: PropsAndOps = deepmerge(\r\n this.generateMainServiceProperties(container, importContainer),\r\n this.generateMainServiceOperations(unboundOperations, importContainer)\r\n );\r\n\r\n sourceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends: `${ROOT_SERVICE}<ClientType>`,\r\n ctors: this.isV4BigNumber()\r\n ? [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n ],\r\n statements: [`super(client, basePath, true);`],\r\n },\r\n ]\r\n : [],\r\n properties,\r\n methods,\r\n });\r\n\r\n await this.generateModelServices(sourceFile, importContainer);\r\n\r\n sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\r\n }\r\n\r\n private generateMainServiceProperties(\r\n container: EntityContainerModel,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n Object.values(container.entitySets).forEach(({ name, odataName, entityType }) => {\r\n result.methods.push(this.generateRelatedServiceGetter(name, odataName, entityType, importContainer));\r\n });\r\n\r\n Object.values(container.singletons).forEach((singleton) => {\r\n result.properties.push(this.generateSingletonProp(singleton, importContainer));\r\n result.methods.push(this.generateSingletonGetter(singleton));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateMainServiceOperations(\r\n ops: Array<FunctionImportType | ActionImportType>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n ops.forEach(({ operation, name }) => {\r\n const op = this.dataModel.getUnboundOperationType(operation);\r\n if (!op) {\r\n throw new Error(`Operation \"${operation}\" not found!`);\r\n }\r\n\r\n result.properties.push(this.generateQOperationProp(op));\r\n result.methods.push(this.generateMethod(name, op, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateRelatedServiceGetter(\r\n propName: string,\r\n odataPropName: string,\r\n entityType: ModelType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const idName = entityType.idModelName;\r\n const idFunctionName = entityType.qIdFunctionName;\r\n const serviceName = this.namingHelper.getServiceName(entityType.name);\r\n const collectionName = this.namingHelper.getCollectionServiceName(entityType.name);\r\n\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addGeneratedModel(idName);\r\n importContainer.addGeneratedQObject(idFunctionName);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(propName),\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: `${idName} | undefined`,\r\n hasQuestionToken: true,\r\n },\r\n ],\r\n overloads: [\r\n {\r\n parameters: [],\r\n returnType: `${collectionName}<ClientType>`,\r\n },\r\n {\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: idName,\r\n },\r\n ],\r\n returnType: `${serviceName}<ClientType>`,\r\n },\r\n ],\r\n statements: [\r\n `const fieldName = \"${odataPropName}\";`,\r\n `const { client, path } = this.__base;`,\r\n 'return typeof id === \"undefined\" || id === null',\r\n `? new ${collectionName}(client, path, fieldName)`,\r\n `: new ${serviceName}(client, path, new ${idFunctionName}(fieldName).buildUrl(id));`,\r\n ],\r\n };\r\n }\r\n\r\n private generateSingletonProp(\r\n singleton: SingletonType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const { name, entityType } = singleton;\r\n const type = this.namingHelper.getServiceName(entityType.name);\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(name),\r\n type: `${type}<ClientType>`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateQOperationProp = (operation: OperationType) => {\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(operation.qName),\r\n type: operation.qName,\r\n hasQuestionToken: true,\r\n };\r\n };\r\n\r\n private generateSingletonGetter(singleton: SingletonType): OptionalKind<MethodDeclarationStructure> {\r\n const { name, odataName, entityType } = singleton;\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(name);\r\n const serviceType = this.namingHelper.getServiceName(entityType.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${propName} = new ${serviceType}(client, path, \"${odataName}\")`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private getVersionSuffix() {\r\n return this.version === ODataVersions.V2 ? \"V2\" : \"V4\";\r\n }\r\n\r\n private async generateEntityTypeService(\r\n model: ComplexType,\r\n serviceName: string,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entityServiceType = \"EntityTypeService\" + this.getVersionSuffix();\r\n\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n const operations = this.dataModel.getEntityTypeOperations(model.fqName);\r\n const props = [...model.baseProps, ...model.props];\r\n\r\n importContainer.addFromService(entityServiceType);\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addGeneratedModel(model.name, editableModelName);\r\n importContainer.addGeneratedQObject(model.qName, qObjectName);\r\n\r\n const { properties, methods }: PropsAndOps = deepmerge(\r\n this.generateServiceProperties(serviceName, props, importContainer),\r\n this.generateServiceOperations(operations, importContainer)\r\n );\r\n\r\n // generate EntityTypeService\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends: entityServiceType + `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [`super(client, basePath, name, ${qObjectName}${this.isV4BigNumber() ? \", true\" : \"\"});`],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private getPrimitiveServiceType() {\r\n return \"PrimitiveTypeService\" + this.getVersionSuffix();\r\n }\r\n\r\n private generateServiceProperties(\r\n serviceName: string,\r\n props: Array<PropertyModel>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const collectionServiceType = \"CollectionService\" + this.getVersionSuffix();\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n props.forEach((prop) => {\r\n if ((prop.dataType === DataTypes.ModelType && !prop.isCollection) || prop.dataType === DataTypes.ComplexType) {\r\n result.properties.push(this.generateModelProp(prop, collectionServiceType, serviceName, importContainer));\r\n result.methods.push(this.generateModelPropGetter(prop, collectionServiceType));\r\n } else if (prop.isCollection) {\r\n // collection of entity types\r\n if (prop.dataType === DataTypes.ModelType) {\r\n const entityType = this.dataModel.getEntityType(prop.fqType);\r\n if (!entityType) {\r\n throw new Error(`Entity type \"${prop.fqType}\" specified by property not found!`);\r\n }\r\n\r\n result.methods.push(\r\n this.generateRelatedServiceGetter(prop.name, prop.odataName, entityType, importContainer)\r\n );\r\n }\r\n // collection of primitive or complex types\r\n else {\r\n result.properties.push(this.generatePrimitiveCollectionProp(prop, collectionServiceType, importContainer));\r\n result.methods.push(this.generatePrimitiveCollectionGetter(prop, collectionServiceType));\r\n }\r\n } else if (this.options.enablePrimitivePropertyServices && prop.dataType === DataTypes.PrimitiveType) {\r\n result.properties.push(this.generatePrimitiveTypeProp(prop, importContainer));\r\n result.methods.push(this.generatePrimitiveTypeGetter(prop));\r\n }\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateServiceOperations(operations: Array<OperationType>, importContainer: ImportContainer): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n operations.forEach((operation) => {\r\n result.properties.push(this.generateQOperationProp(operation));\r\n result.methods.push(this.generateMethod(operation.name, operation, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateModelProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n serviceName: string,\r\n importContainer: ImportContainer\r\n ): PropertyDeclarationStructure {\r\n const complexType = this.dataModel.getComplexType(prop.fqType);\r\n const key = this.namingHelper.getServiceName(prop.type);\r\n let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;\r\n\r\n if (prop.isCollection && complexType) {\r\n const editableName = complexType.editableName;\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addGeneratedModel(complexType.name, editableName);\r\n importContainer.addGeneratedQObject(complexType.qName, firstCharLowerCase(complexType.qName));\r\n propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;\r\n } else {\r\n propModelType = `${propModelType}<ClientType>`;\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: propModelType,\r\n hasQuestionToken: true,\r\n } as PropertyDeclarationStructure;\r\n }\r\n\r\n private generatePrimitiveCollectionProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const isEnum = prop.dataType === DataTypes.EnumType;\r\n const type = isEnum ? `EnumCollection<${prop.type}>` : `${upperCaseFirst(prop.type)}Collection`;\r\n const qType = isEnum ? \"QEnumCollection\" : prop.qObject;\r\n const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;\r\n\r\n if (!prop.qObject) {\r\n throw new Error(\"Illegal State: [qObject] must be provided for Collection types!\");\r\n }\r\n\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addFromQObject(prop.qObject, firstCharLowerCase(prop.qObject));\r\n if (isEnum) {\r\n importContainer.addGeneratedModel(prop.type);\r\n importContainer.addFromQObject(\"EnumCollection\");\r\n } else {\r\n importContainer.addFromQObject(type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${collectionType}`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generatePrimitiveTypeProp(\r\n prop: PropertyModel,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const serviceType = this.getPrimitiveServiceType();\r\n importContainer.addFromService(serviceType);\r\n if (prop.typeModule) {\r\n importContainer.addCustomType(prop.typeModule, prop.type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${serviceType}<ClientType, ${prop.type}>`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateModelPropGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const complexType = this.dataModel.getComplexType(prop.fqType);\r\n const isComplexCollection = prop.isCollection && complexType;\r\n const type = isComplexCollection\r\n ? collectionServiceType\r\n : prop.isCollection\r\n ? this.namingHelper.getCollectionServiceName(prop.type)\r\n : this.namingHelper.getServiceName(prop.type);\r\n const typeWithGenerics = isComplexCollection\r\n ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`\r\n : `${type}<ClientType>`;\r\n\r\n const privateSrvProp = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n returnType: typeWithGenerics,\r\n statements: [\r\n `if(!${privateSrvProp}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${privateSrvProp} = new ${type}(client, path, \"${prop.odataName}\"${isComplexCollection ? `, ${firstCharLowerCase(complexType.qName)}`: \"\"})`,\r\n \"}\",\r\n `return ${privateSrvProp}`,\r\n ],\r\n };\r\n }\r\n\r\n private generatePrimitiveCollectionGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path } = this.__base;`,\r\n // prettier-ignore\r\n ` ${propName} = new ${collectionServiceType}(client, path, \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)}${this.isV4BigNumber() ? \", true\": \"\"})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private generatePrimitiveTypeGetter(prop: PropertyModel): OptionalKind<MethodDeclarationStructure> {\r\n const serviceType = this.getPrimitiveServiceType();\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n // for V2: mapped name must be specified\r\n const useMappedName = this.version === ODataVersions.V2 && prop.name !== prop.odataName;\r\n // for V4: big number support\r\n const useBigNumber = this.isV4BigNumber();\r\n const addParamString = useMappedName ? `, \"${prop.name}\"` : useBigNumber ? \", true\" : \"\";\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n ` const { client, path, qModel } = this.__base;`,\r\n ` ${propName} = new ${serviceType}(client, path, \"${prop.odataName}\", qModel.${prop.name}.converter${addParamString})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private async generateEntityCollectionService(\r\n model: ModelType,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entitySetServiceType = \"EntitySetService\" + this.getVersionSuffix();\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n\r\n importContainer.addFromService(entitySetServiceType);\r\n importContainer.addGeneratedModel(model.idModelName);\r\n importContainer.addGeneratedQObject(model.qIdFunctionName);\r\n\r\n const collectionOperations = this.dataModel.getEntitySetOperations(model.fqName);\r\n\r\n const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);\r\n\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: this.namingHelper.getCollectionServiceName(model.name),\r\n typeParameters: [\"ClientType extends ODataHttpClient\"],\r\n extends:\r\n entitySetServiceType +\r\n `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [\r\n `super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name)${\r\n this.isV4BigNumber() ? \", true\" : \"\"\r\n });`,\r\n ],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private async generateModelServices(serviceFile: SourceFile, importContainer: ImportContainer) {\r\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\r\n for (const model of this.dataModel.getEntityTypes()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n\r\n // entity type service\r\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n\r\n // entity collection service\r\n await this.generateEntityCollectionService(model, serviceFile, importContainer);\r\n }\r\n\r\n // build service file for complex types\r\n for (const model of this.dataModel.getComplexTypes()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n\r\n // entity type service\r\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n }\r\n }\r\n\r\n private generateMethod(\r\n name: string,\r\n operation: OperationType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const isFunc = operation.type === OperationTypes.Function;\r\n const odataType = operation.returnType?.isCollection\r\n ? RESPONSE_TYPES.collection + this.getVersionSuffix()\r\n : operation.returnType?.dataType === DataTypes.PrimitiveType\r\n ? RESPONSE_TYPES.value + this.getVersionSuffix()\r\n : RESPONSE_TYPES.model + this.getVersionSuffix();\r\n const returnType = operation.returnType;\r\n const requestConfigParam = {\r\n name: \"requestConfig\",\r\n hasQuestionToken: true,\r\n type: \"ODataHttpClientConfig<ClientType>\",\r\n };\r\n const hasParams = operation.parameters.length > 0;\r\n\r\n // importing dependencies\r\n importContainer.addFromClientApi(\"ODataHttpClientConfig\", \"ODataResponse\");\r\n importContainer.addFromCore(odataType);\r\n if (returnType?.type) {\r\n if ([DataTypes.EnumType, DataTypes.ModelType, DataTypes.ComplexType].includes(returnType.dataType)) {\r\n importContainer.addGeneratedModel(returnType.type);\r\n }\r\n }\r\n importContainer.addGeneratedQObject(operation.qName);\r\n if (hasParams) {\r\n importContainer.addGeneratedModel(operation.paramsModelName);\r\n }\r\n\r\n const qOpProp = \"this.\" + this.namingHelper.getPrivatePropName(operation.qName);\r\n\r\n return {\r\n scope: Scope.Public,\r\n isAsync: true,\r\n name,\r\n parameters: hasParams\r\n ? [{ name: \"params\", type: operation.paramsModelName }, requestConfigParam]\r\n : [requestConfigParam],\r\n returnType: `ODataResponse<${odataType}<${returnType?.type || \"void\"}>>`,\r\n statements: [\r\n `if(!${qOpProp}) {`,\r\n ` ${qOpProp} = new ${operation.qName}()`,\r\n \"}\",\r\n\r\n `const { addFullPath, client, getDefaultHeaders } = this.__base;`,\r\n `const url = addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\r\n `${returnType ? \"const response = await \" : \"return\"} client.${\r\n !isFunc\r\n ? // actions: since V4\r\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${\r\n requestConfigParam.name\r\n }, getDefaultHeaders())`\r\n : operation.usePost\r\n ? // V2 POST => BUT values are still query params, they are not part of the request body\r\n `post(url, undefined, ${requestConfigParam.name}, getDefaultHeaders())`\r\n : // functions: since V2\r\n `get(url, ${requestConfigParam.name}, getDefaultHeaders())`\r\n };`,\r\n returnType ? `return ${qOpProp}.convertResponse(response);` : \"\",\r\n ],\r\n };\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odata2ts/odata2ts",
3
- "version": "0.31.0",
3
+ "version": "0.31.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -87,6 +87,6 @@
87
87
  "typescript": "^5.1.3"
88
88
  },
89
89
  "types": "./lib/index.d.ts",
90
- "gitHead": "cecca6ee336bcad3c9380c6c88d4c32225032981",
90
+ "gitHead": "bfe3f98e1a0df6b82d575aa398a8df4f0a02bc75",
91
91
  "readme": "README.md"
92
92
  }