@odata2ts/odata2ts 0.26.1 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md 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.27.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.26.1...@odata2ts/odata2ts@0.27.0) (2023-07-20)
7
+
8
+ ### Features
9
+
10
+ * **odata2ts:** metadata download ([#191](https://github.com/odata2ts/odata2ts/issues/191)) ([718058d](https://github.com/odata2ts/odata2ts/commit/718058d4fa93884212ca7e3fe12ac5385a36fecb))
11
+
6
12
  ## [0.26.1](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.26.0...@odata2ts/odata2ts@0.26.1) (2023-07-13)
7
13
 
8
14
  ### Bug Fixes
@@ -1,4 +1,5 @@
1
1
  import { TypeConverterConfig } from "@odata2ts/converter-runtime";
2
+ import { AxiosRequestConfig } from "axios";
2
3
  import { NameSettings, OverridableNamingOptions } from "./NamingModel";
3
4
  /**
4
5
  * Generation mode, by default "all".
@@ -23,7 +24,25 @@ export declare enum EmitModes {
23
24
  */
24
25
  export interface CliOptions {
25
26
  /**
26
- * The source file to use. Must be an EDMX compliant XML file.
27
+ * The URL to the root of your OData service. The URL might end in a slash or not, it might also end
28
+ * in $metadata, but we usually add this for you.
29
+ *
30
+ * Specifying the URL is a convenience feature to download the metadata file from the given URL.
31
+ * You can configure this request via `sourceConfig` option.
32
+ *
33
+ * The `source` option must still be specified as it is used to store the downloaded file on your disk.
34
+ * By default, the file is used once it has been downloaded.
35
+ */
36
+ sourceUrl?: string;
37
+ /**
38
+ * Downloads the metadata file and overwrites the existing one, if any.
39
+ *
40
+ * Only takes effect, if option `sourceUrl` is specified.
41
+ */
42
+ refreshFile?: boolean;
43
+ /**
44
+ * The source is the file to use (must be an EDMX compliant XML file) or the URL to the
45
+ * metadata (ROOT_SERVICE/$metadata).
27
46
  *
28
47
  * If not specified, at least one service must be configured in config file.
29
48
  */
@@ -102,14 +121,44 @@ export interface CliOptions {
102
121
  * Available options for the actual generation run.
103
122
  * Every property is required, except the overriding service name.
104
123
  */
105
- export interface RunOptions extends Required<Omit<ServiceGenerationOptions, "serviceName">> {
106
- serviceName?: string;
124
+ export interface RunOptions extends Required<Omit<ServiceGenerationOptions, "serviceName" | "sourceUrl" | "sourceUrlConfig" | "refreshFile">>, Pick<ServiceGenerationOptions, "serviceName" | "sourceUrl" | "sourceUrlConfig" | "refreshFile"> {
107
125
  naming: NameSettings;
108
126
  }
127
+ /**
128
+ * Configuration options of the request to retrieve the metadata.
129
+ * Only takes effect if `source` is a URL.
130
+ */
131
+ export interface UrlSourceConfiguration {
132
+ /**
133
+ * Basic auth credentials: the username.
134
+ * Only takes effect if `password` has also been set.
135
+ */
136
+ username?: string;
137
+ /**
138
+ * Basic auth credentials: the password.
139
+ * Only takes effect if `username` has also been set.
140
+ */
141
+ password?: string;
142
+ /**
143
+ * Custom request configuration.
144
+ * URL and method `GET` are set by default, but can be overwritten.
145
+ */
146
+ custom?: AxiosRequestConfig;
147
+ }
109
148
  /**
110
149
  * Available options for configuration files, i.e. odata2ts.config.ts.
111
150
  */
112
- export interface ConfigFileOptions extends Omit<CliOptions, "source" | "output" | "services"> {
151
+ export interface ConfigFileOptions extends Omit<CliOptions, "sourceUrl" | "source" | "output" | "services"> {
152
+ /**
153
+ * Configuration options of the request to retrieve the metadata.
154
+ * Only takes effect if `sourceUrl` is a URL.
155
+ */
156
+ sourceUrlConfig?: UrlSourceConfiguration;
157
+ /**
158
+ * Configuration of each service.
159
+ *
160
+ * @example { services: { trippin: { source: "...", ... } }}
161
+ */
113
162
  services?: {
114
163
  [serviceName: string]: ServiceGenerationOptions;
115
164
  };
@@ -175,7 +224,7 @@ export interface ConfigFileOptions extends Omit<CliOptions, "source" | "output"
175
224
  /**
176
225
  * Custom generation options which are dependent on a specific odata service.
177
226
  */
178
- export interface ServiceGenerationOptions extends Required<Pick<CliOptions, "source" | "output">>, Omit<ConfigFileOptions, "services"> {
227
+ export interface ServiceGenerationOptions extends Required<Pick<CliOptions, "source" | "output">>, Pick<CliOptions, "sourceUrl" | "refreshFile">, Omit<ConfigFileOptions, "services"> {
179
228
  /**
180
229
  * Configure generation process for EntityTypes and ComplexTypes including their keys and properties.
181
230
  */
@@ -1 +1 @@
1
- {"version":3,"file":"OptionModel.js","sourceRoot":"","sources":["../src/OptionModel.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACH,IAAY,KAKX;AALD,WAAY,KAAK;IACf,qCAAM,CAAA;IACN,yCAAQ,CAAA;IACR,uCAAO,CAAA;IACP,+BAAG,CAAA;AACL,CAAC,EALW,KAAK,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\n\r\nimport { NameSettings, OverridableNamingOptions } from \"./NamingModel\";\r\n\r\n/**\r\n * Generation mode, by default \"all\".\r\n */\r\nexport enum Modes {\r\n models,\r\n qobjects,\r\n service,\r\n all,\r\n}\r\n\r\n/**\r\n * What kind of stuff to emit: Either raw TS or TS that has been compiled to JS / DTS.\r\n */\r\nexport enum EmitModes {\r\n ts = \"ts\",\r\n js = \"js\",\r\n dts = \"dts\",\r\n js_dts = \"js_dts\",\r\n}\r\n\r\n/**\r\n * Config options for CLI.\r\n */\r\nexport interface CliOptions {\r\n /**\r\n * The source file to use. Must be an EDMX compliant XML file.\r\n *\r\n * If not specified, at least one service must be configured in config file.\r\n */\r\n source?: string;\r\n /**\r\n * Specifies the output directory for the generated stuff.\r\n *\r\n * If not specified, at least one service must be configured in config file.\r\n */\r\n output?: string;\r\n /**\r\n * Only generates the specified services.\r\n * Relies on an existing config file where these service names are maintained.\r\n */\r\n services?: Array<string>;\r\n /**\r\n * Specifies what to generate:\r\n * - {@code Modes.models} will only generate TS interfaces\r\n * - {@code Modes.qobjects} will generate functional units used in QueryBuilder and for functions and actions\r\n * - {@code Modes.service} will generate one main OData service client and one per each entity\r\n * - {@code Modes.all} the same as {@code Modes.service}\r\n *\r\n * QObjects will also generate models, and generating the service client will also generate models and QObjects.\r\n * Defaults to {@code Modes.all}\r\n */\r\n mode?: Modes;\r\n /**\r\n * Specifies the type of the output files: TypeScript, JS, DTS only, JS with DTS.\r\n * Defaults to {@code EmitModes.js_dts}\r\n */\r\n emitMode?: EmitModes;\r\n /**\r\n * Uses prettier with your local configuration to pretty print TypeScript files.\r\n * Only applies if mode is set to {@code EmitModes.ts}.\r\n */\r\n prettier?: boolean;\r\n /**\r\n * When compiling TypeScript to JS, \"tsconfig.json\" is used by default to add compilerOptions.\r\n * This option allows to specify an alternative file.\r\n *\r\n * Only takes effect, when mode is set to anything else than {@code EmitModes.ts}.\r\n */\r\n tsconfig?: string;\r\n /**\r\n * Verbose debugging information.\r\n */\r\n debug?: boolean;\r\n /**\r\n * Overrides the service name found in the source file.\r\n *\r\n * The service name is the basis for all file names and the name of the main OData client service\r\n * that serves as entry point for the user.\r\n */\r\n serviceName?: string;\r\n /**\r\n * odata2ts will automatically decide if a key prop is managed on the server side.\r\n * If managed, the property will not be editable (create, update, patch).\r\n * The following rule applies:\r\n * If a property is the only key prop of an entity, then the prop is deemed to be managed;\r\n * in ony other case the prop is unmanaged.\r\n */\r\n disableAutoManagedKey?: boolean;\r\n /**\r\n * By default, odata2ts doesn't change param, operation, property or model names.\r\n * The generated models and their properties are named exactly as advertised by the server.\r\n *\r\n * By allowing odata2ts to change these names, certain predefined formatting strategies are used:\r\n * Model / class names are formatted with PascalCase; property, param, and operation names with camelCase.\r\n *\r\n * The naming configuration allows to control this and other naming related settings.\r\n * Note: Even if renaming is disabled, model prefixing / suffing still applies.\r\n */\r\n allowRenaming?: boolean;\r\n}\r\n\r\n/**\r\n * Available options for the actual generation run.\r\n * Every property is required, except the overriding service name.\r\n */\r\nexport interface RunOptions extends Required<Omit<ServiceGenerationOptions, \"serviceName\">> {\r\n serviceName?: string;\r\n naming: NameSettings;\r\n}\r\n\r\n/**\r\n * Available options for configuration files, i.e. odata2ts.config.ts.\r\n */\r\nexport interface ConfigFileOptions extends Omit<CliOptions, \"source\" | \"output\" | \"services\"> {\r\n services?: { [serviceName: string]: ServiceGenerationOptions };\r\n\r\n /**\r\n * Specify which converters to use by their package name, e.g. \"@odata2ts/converter-v2-to-v4\".\r\n * Each converter knows which data type to map.\r\n *\r\n * To only use specific converters, the object syntax must be used, where supported converters\r\n * must be listed by their ids.\r\n */\r\n converters?: Array<string | TypeConverterConfig>;\r\n\r\n /**\r\n * For each model an editable version is generated which represents the model definition for\r\n * create, update and patch actions.\r\n *\r\n * You can skip the generation altogether, not generating editable model variants,\r\n * if the generation mode is {@code Mode.model} or {@code Mode.qobject}.\r\n */\r\n skipEditableModels?: boolean;\r\n\r\n /**\r\n * ID models are generated from entity id parameters.\r\n * The generation for one entity entails one model interface representing the id parameters and\r\n * one QId function which allows to format the parameters for URL usage and to parse parameters\r\n * from a URL string.\r\n *\r\n * You can skip the generation altogether, not generating models and QId objects, if the\r\n * generation mode is {@code Mode.model} or {@code Mode.qobject}.\r\n */\r\n skipIdModels?: boolean;\r\n /**\r\n * Operations are functions and actions of the OData service.\r\n * The generation for one operation entails one parameter model interface\r\n * and one QFunction / QAction class.\r\n *\r\n * You can skip the generation altogether, neither generating model nor query object,\r\n * if the generation mode is {@code Mode.model} or {@code Mode.qobject}.\r\n */\r\n skipOperations?: boolean;\r\n /**\r\n * 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 /**\r\n * The naming options regarding the generated artefacts.\r\n */\r\n naming?: OverridableNamingOptions;\r\n\r\n /**\r\n * Some OData V2 services generate an extra wrapping for entity collection attributes:\r\n * <code>trips: {results: [...]}</code>. So instead of directly returning an array of entities\r\n * an object with the property \"results\" is wrapped around the entity collection.\r\n *\r\n * If you're using the odata client then there's a build-in workaround in place which transforms\r\n * the results to remove this extra mapping. However, if you're only interested in the types, then\r\n * the generated models will not match that extra wrapping.\r\n *\r\n * Setting this configuration option to <code>true</code> (default: false) will add this extra\r\n * wrapping to the generated models. But this option is only valid if the generation mode is set\r\n * to <code>models</code>; it is ignored otherwise.\r\n */\r\n v2ModelsWithExtraResultsWrapping?: boolean;\r\n}\r\n\r\n/**\r\n * Custom generation options which are dependent on a specific odata service.\r\n */\r\nexport interface ServiceGenerationOptions\r\n extends Required<Pick<CliOptions, \"source\" | \"output\">>,\r\n Omit<ConfigFileOptions, \"services\"> {\r\n /**\r\n * Configure generation process for EntityTypes and ComplexTypes including their keys and properties.\r\n */\r\n entitiesByName?: Array<EntityGenerationOptions>;\r\n /**\r\n * Configure generation process for individual properties based on their name.\r\n */\r\n propertiesByName?: Array<PropertyGenerationOptions>;\r\n}\r\n\r\n/**\r\n * Configuration options for EntityTypes and ComplexTypes.\r\n * This config applies if the name matches the name of an EntityType or ComplexType as it is specified\r\n * in the metadata (e.g. in EDMX <EntityType name=\"Test\" ...)\r\n */\r\nexport interface EntityGenerationOptions {\r\n /**\r\n * Name of the EntityType or ComplexType, e.g. \"Person\".\r\n * Must match exactly or can be a regular expression.\r\n */\r\n name: string | RegExp;\r\n /**\r\n * Use a different name.\r\n * If name is a regular expression, mappedName allows to specify captured groups (via $1, $2, ...).\r\n */\r\n mappedName?: string;\r\n /**\r\n * Overwrite the key specification by naming the props by their EDMX name.\r\n */\r\n keys?: Array<string>;\r\n /**\r\n * Configuration of individual properties.\r\n */\r\n properties?: Array<PropertyGenerationOptions>;\r\n\r\n // converter: string | Array<string>\r\n\r\n /**\r\n * Whether the generated service should allow for querying this model.\r\n * True by default.\r\n */\r\n // queryable?: boolean;\r\n /**\r\n * Whether the generated service should allow for creating new models (POST).\r\n * True by default.\r\n */\r\n // creatable?: boolean;\r\n /**\r\n * Whether the generated service should allow for updates (PUT).\r\n * True by default.\r\n */\r\n // updatable?: boolean;\r\n /**\r\n * Whether the generated service should allow for partial updates (PATCH).\r\n * True by default.\r\n */\r\n // patchable?: boolean;\r\n /**\r\n * Whether the generated service should allow for deletion.\r\n * True by default.\r\n */\r\n // deletable?: boolean;\r\n}\r\n\r\n/**\r\n * All configuration options for properties of models.\r\n */\r\nexport interface PropertyGenerationOptions {\r\n /**\r\n * Name of the property to match.\r\n * Must match exactly or can be a regular expression.\r\n */\r\n name: string | RegExp;\r\n /**\r\n * Use a different name.\r\n * If name is a regular expression, mappedName allows to specify captured groups (via $1, $2, ...).\r\n */\r\n mappedName?: string;\r\n /**\r\n * Managed attributes - i.e. managed by the server - cannot be created or updated.\r\n * Hence, they are left out of the editable model versions.\r\n */\r\n managed?: boolean;\r\n\r\n /**\r\n * TODO\r\n *\r\n * Each converter must specify its package name, e.g. \"@odata2ts/converter-v2-to-v4\",\r\n * as well it's i\r\n * and their ids, e.g. \"timeToDurationConverter\".\r\n *\r\n * To only use specific converters, the object syntax must be used, where supported converters\r\n * must be listed by their ids.\r\n */\r\n // converters?: Array<Required<TypeConverterConfig>>;\r\n}\r\n"]}
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 / suffing still applies.\r\n */\r\n allowRenaming?: boolean;\r\n}\r\n\r\n/**\r\n * Available options for the actual generation run.\r\n * Every property is required, except the overriding service name.\r\n */\r\nexport interface RunOptions\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 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 /**\r\n * The naming options regarding the generated artefacts.\r\n */\r\n naming?: OverridableNamingOptions;\r\n\r\n /**\r\n * Some OData V2 services generate an extra wrapping for entity collection attributes:\r\n * <code>trips: {results: [...]}</code>. So instead of directly returning an array of entities\r\n * an object with the property \"results\" is wrapped around the entity collection.\r\n *\r\n * If you're using the odata client then there's a build-in workaround in place which transforms\r\n * the results to remove this extra mapping. However, if you're only interested in the types, then\r\n * the generated models will not match that extra wrapping.\r\n *\r\n * Setting this configuration option to <code>true</code> (default: false) will add this extra\r\n * wrapping to the generated models. But this option is only valid if the generation mode is set\r\n * to <code>models</code>; it is ignored otherwise.\r\n */\r\n v2ModelsWithExtraResultsWrapping?: boolean;\r\n}\r\n\r\n/**\r\n * Custom generation options which are dependent on a specific odata service.\r\n */\r\nexport interface ServiceGenerationOptions\r\n extends Required<Pick<CliOptions, \"source\" | \"output\">>,\r\n 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\r\n/**\r\n * Configuration options for EntityTypes and ComplexTypes.\r\n * This config applies if the name matches the name of an EntityType or ComplexType as it is specified\r\n * in the metadata (e.g. in EDMX <EntityType name=\"Test\" ...)\r\n */\r\nexport interface EntityGenerationOptions {\r\n /**\r\n * Name of the EntityType or ComplexType, e.g. \"Person\".\r\n * Must match exactly or can be a regular expression.\r\n */\r\n name: string | RegExp;\r\n /**\r\n * Use a different name.\r\n * If name is a regular expression, mappedName allows to specify captured groups (via $1, $2, ...).\r\n */\r\n mappedName?: string;\r\n /**\r\n * Overwrite the key specification by naming the props by their EDMX name.\r\n */\r\n keys?: Array<string>;\r\n /**\r\n * Configuration of individual properties.\r\n */\r\n properties?: Array<PropertyGenerationOptions>;\r\n\r\n // converter: string | Array<string>\r\n\r\n /**\r\n * Whether the generated service should allow for querying this model.\r\n * True by default.\r\n */\r\n // queryable?: boolean;\r\n /**\r\n * Whether the generated service should allow for creating new models (POST).\r\n * True by default.\r\n */\r\n // creatable?: boolean;\r\n /**\r\n * Whether the generated service should allow for updates (PUT).\r\n * True by default.\r\n */\r\n // updatable?: boolean;\r\n /**\r\n * Whether the generated service should allow for partial updates (PATCH).\r\n * True by default.\r\n */\r\n // patchable?: boolean;\r\n /**\r\n * Whether the generated service should allow for deletion.\r\n * True by default.\r\n */\r\n // deletable?: boolean;\r\n}\r\n\r\n/**\r\n * All configuration options for properties of models.\r\n */\r\nexport interface PropertyGenerationOptions {\r\n /**\r\n * Name of the property to match.\r\n * Must match exactly or can be a regular expression.\r\n */\r\n name: string | RegExp;\r\n /**\r\n * Use a different name.\r\n * If name is a regular expression, mappedName allows to specify captured groups (via $1, $2, ...).\r\n */\r\n mappedName?: string;\r\n /**\r\n * Managed attributes - i.e. managed by the server - cannot be created or updated.\r\n * Hence, they are left out of the editable model versions.\r\n */\r\n managed?: boolean;\r\n\r\n /**\r\n * TODO\r\n *\r\n * Each converter must specify its package name, e.g. \"@odata2ts/converter-v2-to-v4\",\r\n * as well it's i\r\n * and their ids, e.g. \"timeToDurationConverter\".\r\n *\r\n * To only use specific converters, the object syntax must be used, where supported converters\r\n * must be listed by their ids.\r\n */\r\n // converters?: Array<Required<TypeConverterConfig>>;\r\n}\r\n"]}
package/lib/cli.js CHANGED
@@ -8,6 +8,7 @@ const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader")
8
8
  const fs_extra_1 = require("fs-extra");
9
9
  const xml2js_1 = require("xml2js");
10
10
  const app_1 = require("./app");
11
+ const download_1 = require("./download/");
11
12
  const evaluateConfig_1 = require("./evaluateConfig");
12
13
  const OptionModel_1 = require("./OptionModel");
13
14
  const logFilePath_1 = require("./project/logger/logFilePath");
@@ -45,8 +46,10 @@ function processCliArgs() {
45
46
  .version("0.3.0")
46
47
  .description("CLI to generate Typescript Interfaces for models of a given OData service.")
47
48
  .argument("[services...]", "Run the generation process only for certain services specified in config file", [])
48
- .option("-s, --source <metadata.xml>", "Metadata file describing the OData service")
49
+ .option("-s, --source <url or metadata.xml>", "Path to metadata file")
49
50
  .option("-o, --output <path>", "Output location for generated files")
51
+ .option("-u, --source-url <sourceUrl>", "URL to the root of the OData service")
52
+ .option("-f, --refresh-file", "Download metadata again and overwrite existing file (only applies if sourceUrl is specified)")
50
53
  .addOption(new commander_1.Option("-m, --mode <mode>", "What kind of stuff gets generated")
51
54
  .choices(Object.values(OptionModel_1.Modes).filter((t) => isNaN(Number(t))))
52
55
  .argParser(parseMode))
@@ -57,8 +60,8 @@ function processCliArgs() {
57
60
  .option("-t, --tsconfig <path>", "Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)")
58
61
  .option("-d, --debug", "Verbose debug infos")
59
62
  .option("-name, --service-name <serviceName>", "Give the service your own name")
60
- .option("-n, --disable-auto-managed-key", "Give the service your own name")
61
- .option("-r, --allow-renaming ", "Give the service your own name")
63
+ .option("-n, --disable-auto-managed-key", "Don't mark single key props as managed by the server side (not editable)")
64
+ .option("-r, --allow-renaming", "Allow that property and entity names may be changed by configured casing")
62
65
  .parse(process.argv);
63
66
  const args = ((_a = cli.args) === null || _a === void 0 ? void 0 : _a.length) ? { services: cli.args } : {};
64
67
  return Object.assign(Object.assign({}, cli.opts()), args);
@@ -107,13 +110,15 @@ class Cli {
107
110
  exports.Cli = Cli;
108
111
  function startServiceGenerationRun(options) {
109
112
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
110
- const { source, output, debug, mode, emitMode, prettier, serviceName } = options;
113
+ const { source, output, sourceUrl, refreshFile, sourceUrlConfig, debug, mode, emitMode, prettier, serviceName } = options;
111
114
  console.log("---------------------------");
112
115
  console.log("Starting generation process");
113
116
  if (debug) {
114
117
  console.log("Resolved config:", {
115
118
  source,
116
119
  output,
120
+ sourceUrl,
121
+ refreshFile,
117
122
  debug,
118
123
  mode: OptionModel_1.Modes[mode],
119
124
  emitMode,
@@ -121,14 +126,31 @@ function startServiceGenerationRun(options) {
121
126
  serviceName,
122
127
  });
123
128
  }
124
- console.log("Reading file:", source);
129
+ // evaluate source
125
130
  const exists = yield (0, fs_extra_1.pathExists)(source);
126
- if (!exists) {
131
+ console.log(`${exists ? "Found" : "Didn't find"} metadata file at: `, source);
132
+ let metadataXml;
133
+ // download metadata and store on disk
134
+ if (sourceUrl && (!exists || refreshFile)) {
135
+ try {
136
+ metadataXml = yield (0, download_1.downloadMetadata)(sourceUrl, sourceUrlConfig, debug);
137
+ }
138
+ catch (e) {
139
+ console.error(`Failed to load metadata! Message: ${e === null || e === void 0 ? void 0 : e.message}`);
140
+ process.exit(10);
141
+ }
142
+ metadataXml = yield (0, download_1.storeMetadata)(source, metadataXml, prettier);
143
+ }
144
+ // otherwise file must exist
145
+ else if (!exists) {
127
146
  console.error(`Input source [${source}] doesn't exist!`);
128
147
  process.exit(2);
129
148
  }
130
- // read metadata file and convert to JSON
131
- const metadataXml = yield (0, fs_extra_1.readFile)(source);
149
+ // read the metadata from file
150
+ else {
151
+ console.log("Reading metadata from file:", source);
152
+ metadataXml = yield (0, fs_extra_1.readFile)(source);
153
+ }
132
154
  const metadataJson = (yield (0, xml2js_1.parseStringPromise)(metadataXml));
133
155
  // TODO find out if "1.0" and "4.0" are really correct
134
156
  // TODO exit here if no version not suitable version was detected
package/lib/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":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,CAAC,CAAC;SAClB;IACH,CAAC;CAAA","sourcesContent":["import commander, { Option } from \"commander\";\r\nimport { cosmiconfig } from \"cosmiconfig\";\r\nimport { TypeScriptLoader } from \"cosmiconfig-typescript-loader\";\r\nimport { emptyDir, pathExists, readFile } from \"fs-extra\";\r\nimport { parseStringPromise } from \"xml2js\";\r\n\r\nimport { runApp } from \"./app\";\r\nimport { ODataEdmxModelBase } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { evaluateConfigOptions } from \"./evaluateConfig\";\r\nimport { CliOptions, ConfigFileOptions, EmitModes, Modes, RunOptions } from \"./OptionModel\";\r\nimport { logFilePath } from \"./project/logger/logFilePath\";\r\n\r\nfunction parseMode(value: string, dummyPrevious: Modes | undefined) {\r\n switch (value) {\r\n case \"models\":\r\n return Modes.models;\r\n case \"qobjects\":\r\n return Modes.qobjects;\r\n case \"service\":\r\n return Modes.service;\r\n case \"all\":\r\n return Modes.all;\r\n default:\r\n throw new Error(`Not a valid Mode: ${value}`);\r\n }\r\n}\r\n\r\nfunction parseEmitMode(value: string, dummyPrevious: EmitModes) {\r\n switch (value) {\r\n case \"dts\":\r\n return EmitModes.dts;\r\n case \"js\":\r\n return EmitModes.js;\r\n case \"ts\":\r\n return EmitModes.ts;\r\n case \"js_dts\":\r\n return EmitModes.js_dts;\r\n default:\r\n throw new Error(`Not a valid EmitMode: ${value}`);\r\n }\r\n}\r\n\r\nfunction processCliArgs() {\r\n const cli = new commander.Command()\r\n .version(\"0.3.0\")\r\n .description(\"CLI to generate Typescript Interfaces for models of a given OData service.\")\r\n .argument(\"[services...]\", \"Run the generation process only for certain services specified in config file\", [])\r\n .option(\"-s, --source <metadata.xml>\", \"Metadata file describing the OData service\")\r\n .option(\"-o, --output <path>\", \"Output location for generated files\")\r\n .addOption(\r\n new Option(\"-m, --mode <mode>\", \"What kind of stuff gets generated\")\r\n .choices(Object.values(Modes).filter((t): t is string => isNaN(Number(t))))\r\n .argParser<Modes>(parseMode)\r\n )\r\n .addOption(\r\n new Option(\r\n \"-e, --emit-mode <mode>\",\r\n \"Output TS source files, compiled JS files with/wihthout generated d.ts files\"\r\n )\r\n .choices(Object.values(EmitModes))\r\n .argParser<EmitModes>(parseEmitMode)\r\n )\r\n .option(\"-p, --prettier\", \"Format result with prettier (only applies if emitMode=ts)\")\r\n .option(\r\n \"-t, --tsconfig <path>\",\r\n \"Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)\"\r\n )\r\n .option(\"-d, --debug\", \"Verbose debug infos\")\r\n .option(\"-name, --service-name <serviceName>\", \"Give the service your own name\")\r\n .option(\"-n, --disable-auto-managed-key\", \"Give the service your own name\")\r\n .option(\"-r, --allow-renaming \", \"Give the service your own name\")\r\n .parse(process.argv);\r\n\r\n const args = cli.args?.length ? { services: cli.args } : {};\r\n return {\r\n ...cli.opts(),\r\n ...args,\r\n } as CliOptions;\r\n}\r\n\r\nasync function processConfigFile() {\r\n const moduleName = \"odata2ts\";\r\n const explorer = cosmiconfig(moduleName, {\r\n searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`],\r\n loaders: {\r\n \".ts\": TypeScriptLoader(),\r\n },\r\n });\r\n const discoveredConfig = await explorer.search();\r\n\r\n if (discoveredConfig?.config) {\r\n console.log(\"Loaded config file: \", logFilePath(discoveredConfig.filepath));\r\n } else {\r\n console.log(\"No config file found.\");\r\n }\r\n\r\n return discoveredConfig?.config as ConfigFileOptions;\r\n}\r\n\r\nexport class Cli {\r\n async run(): Promise<void> {\r\n let runs;\r\n try {\r\n const cliOpts = processCliArgs();\r\n if (cliOpts.debug) {\r\n console.log(\"CLI opts:\", cliOpts);\r\n }\r\n const fileOpts = await processConfigFile();\r\n\r\n runs = evaluateConfigOptions(cliOpts, fileOpts);\r\n } catch (error: any) {\r\n console.error(\"Bad arguments!\", error?.message);\r\n process.exit(1);\r\n }\r\n\r\n for (let run of runs) {\r\n await startServiceGenerationRun(run);\r\n }\r\n }\r\n}\r\n\r\nasync function startServiceGenerationRun(options: RunOptions) {\r\n const { source, output, debug, mode, emitMode, prettier, serviceName } = options;\r\n console.log(\"---------------------------\");\r\n console.log(\"Starting generation process\");\r\n\r\n if (debug) {\r\n console.log(\"Resolved config:\", {\r\n source,\r\n output,\r\n debug,\r\n mode: Modes[mode],\r\n emitMode,\r\n prettier,\r\n serviceName,\r\n });\r\n }\r\n\r\n console.log(\"Reading file:\", source);\r\n const exists = await pathExists(source);\r\n if (!exists) {\r\n console.error(`Input source [${source}] doesn't exist!`);\r\n process.exit(2);\r\n }\r\n\r\n // read metadata file and convert to JSON\r\n const metadataXml = await readFile(source);\r\n const metadataJson = (await parseStringPromise(metadataXml)) as ODataEdmxModelBase<any>;\r\n // TODO find out if \"1.0\" and \"4.0\" are really correct\r\n // TODO exit here if no version not suitable version was detected\r\n // console.log(`OData version detected: ${metadataJson[\"edmx:Edmx\"].$.Version}`);\r\n\r\n // ensure that output directory exists\r\n try {\r\n await emptyDir(output);\r\n } catch (error) {\r\n console.error(`Output path [${output}] couldn't be created!`, error);\r\n process.exit(3);\r\n }\r\n\r\n // run the app\r\n try {\r\n await runApp(metadataJson, options);\r\n } catch (err: any) {\r\n console.error(\"Error while running the program\", err);\r\n process.exit(99);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;AAAA,+DAA8C;AAC9C,6CAA0C;AAC1C,iFAAiE;AACjE,uCAA0D;AAC1D,mCAA4C;AAE5C,+BAA+B;AAE/B,0CAA8D;AAC9D,qDAAyD;AACzD,+CAAoH;AACpH,8DAA2D;AAE3D,SAAS,SAAS,CAAC,KAAa,EAAE,aAAgC;IAChE,QAAQ,KAAK,EAAE;QACb,KAAK,QAAQ;YACX,OAAO,mBAAK,CAAC,MAAM,CAAC;QACtB,KAAK,UAAU;YACb,OAAO,mBAAK,CAAC,QAAQ,CAAC;QACxB,KAAK,SAAS;YACZ,OAAO,mBAAK,C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AAA,mBAAQ,EAAC,MAAM,CAAC,CAAC;SACxB;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,gBAAgB,MAAM,wBAAwB,EAAE,KAAK,CAAC,CAAC;YACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,cAAc;QACd,IAAI;YACF,MAAM,IAAA,YAAM,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;SACrC;QAAC,OAAO,GAAQ,EAAE;YACjB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAClB;IACH,CAAC;CAAA","sourcesContent":["import commander, { Option } from \"commander\";\r\nimport { cosmiconfig } from \"cosmiconfig\";\r\nimport { TypeScriptLoader } from \"cosmiconfig-typescript-loader\";\r\nimport { emptyDir, pathExists, readFile } from \"fs-extra\";\r\nimport { parseStringPromise } from \"xml2js\";\r\n\r\nimport { runApp } from \"./app\";\r\nimport { ODataEdmxModelBase } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { downloadMetadata, storeMetadata } from \"./download/\";\r\nimport { evaluateConfigOptions } from \"./evaluateConfig\";\r\nimport { CliOptions, ConfigFileOptions, EmitModes, Modes, RunOptions, UrlSourceConfiguration } from \"./OptionModel\";\r\nimport { logFilePath } from \"./project/logger/logFilePath\";\r\n\r\nfunction parseMode(value: string, dummyPrevious: Modes | undefined) {\r\n switch (value) {\r\n case \"models\":\r\n return Modes.models;\r\n case \"qobjects\":\r\n return Modes.qobjects;\r\n case \"service\":\r\n return Modes.service;\r\n case \"all\":\r\n return Modes.all;\r\n default:\r\n throw new Error(`Not a valid Mode: ${value}`);\r\n }\r\n}\r\n\r\nfunction parseEmitMode(value: string, dummyPrevious: EmitModes) {\r\n switch (value) {\r\n case \"dts\":\r\n return EmitModes.dts;\r\n case \"js\":\r\n return EmitModes.js;\r\n case \"ts\":\r\n return EmitModes.ts;\r\n case \"js_dts\":\r\n return EmitModes.js_dts;\r\n default:\r\n throw new Error(`Not a valid EmitMode: ${value}`);\r\n }\r\n}\r\n\r\nfunction processCliArgs() {\r\n const cli = new commander.Command()\r\n .version(\"0.3.0\")\r\n .description(\"CLI to generate Typescript Interfaces for models of a given OData service.\")\r\n .argument(\"[services...]\", \"Run the generation process only for certain services specified in config file\", [])\r\n .option(\"-s, --source <url or metadata.xml>\", \"Path to metadata file\")\r\n .option(\"-o, --output <path>\", \"Output location for generated files\")\r\n .option(\"-u, --source-url <sourceUrl>\", \"URL to the root of the OData service\")\r\n .option(\r\n \"-f, --refresh-file\",\r\n \"Download metadata again and overwrite existing file (only applies if sourceUrl is specified)\"\r\n )\r\n .addOption(\r\n new Option(\"-m, --mode <mode>\", \"What kind of stuff gets generated\")\r\n .choices(Object.values(Modes).filter((t): t is string => isNaN(Number(t))))\r\n .argParser<Modes>(parseMode)\r\n )\r\n .addOption(\r\n new Option(\r\n \"-e, --emit-mode <mode>\",\r\n \"Output TS source files, compiled JS files with/wihthout generated d.ts files\"\r\n )\r\n .choices(Object.values(EmitModes))\r\n .argParser<EmitModes>(parseEmitMode)\r\n )\r\n .option(\"-p, --prettier\", \"Format result with prettier (only applies if emitMode=ts)\")\r\n .option(\r\n \"-t, --tsconfig <path>\",\r\n \"Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)\"\r\n )\r\n .option(\"-d, --debug\", \"Verbose debug infos\")\r\n .option(\"-name, --service-name <serviceName>\", \"Give the service your own name\")\r\n .option(\r\n \"-n, --disable-auto-managed-key\",\r\n \"Don't mark single key props as managed by the server side (not editable)\"\r\n )\r\n .option(\"-r, --allow-renaming\", \"Allow that property and entity names may be changed by configured casing\")\r\n .parse(process.argv);\r\n\r\n const args = cli.args?.length ? { services: cli.args } : {};\r\n return {\r\n ...cli.opts(),\r\n ...args,\r\n } as CliOptions;\r\n}\r\n\r\nasync function processConfigFile() {\r\n const moduleName = \"odata2ts\";\r\n const explorer = cosmiconfig(moduleName, {\r\n searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`],\r\n loaders: {\r\n \".ts\": TypeScriptLoader(),\r\n },\r\n });\r\n const discoveredConfig = await explorer.search();\r\n\r\n if (discoveredConfig?.config) {\r\n console.log(\"Loaded config file: \", logFilePath(discoveredConfig.filepath));\r\n } else {\r\n console.log(\"No config file found.\");\r\n }\r\n\r\n return discoveredConfig?.config as ConfigFileOptions;\r\n}\r\n\r\nexport class Cli {\r\n async run(): Promise<void> {\r\n let runs;\r\n try {\r\n const cliOpts = processCliArgs();\r\n if (cliOpts.debug) {\r\n console.log(\"CLI opts:\", cliOpts);\r\n }\r\n const fileOpts = await processConfigFile();\r\n\r\n runs = evaluateConfigOptions(cliOpts, fileOpts);\r\n } catch (error: any) {\r\n console.error(\"Bad arguments!\", error?.message);\r\n process.exit(1);\r\n }\r\n\r\n for (let run of runs) {\r\n await startServiceGenerationRun(run);\r\n }\r\n }\r\n}\r\n\r\nasync function startServiceGenerationRun(options: RunOptions) {\r\n const { source, output, sourceUrl, refreshFile, sourceUrlConfig, debug, mode, emitMode, prettier, serviceName } =\r\n options;\r\n console.log(\"---------------------------\");\r\n console.log(\"Starting generation process\");\r\n\r\n if (debug) {\r\n console.log(\"Resolved config:\", {\r\n source,\r\n output,\r\n sourceUrl,\r\n refreshFile,\r\n debug,\r\n mode: Modes[mode],\r\n emitMode,\r\n prettier,\r\n serviceName,\r\n });\r\n }\r\n\r\n // evaluate source\r\n const exists = await pathExists(source);\r\n console.log(`${exists ? \"Found\" : \"Didn't find\"} metadata file at: `, source);\r\n\r\n let metadataXml;\r\n // download metadata and store on disk\r\n if (sourceUrl && (!exists || refreshFile)) {\r\n try {\r\n metadataXml = await downloadMetadata(sourceUrl, sourceUrlConfig, debug);\r\n } catch (e) {\r\n console.error(`Failed to load metadata! Message: ${(e as Error)?.message}`);\r\n process.exit(10);\r\n }\r\n metadataXml = await storeMetadata(source, metadataXml, prettier);\r\n }\r\n // otherwise file must exist\r\n else if (!exists) {\r\n console.error(`Input source [${source}] doesn't exist!`);\r\n process.exit(2);\r\n }\r\n // read the metadata from file\r\n else {\r\n console.log(\"Reading metadata from file:\", source);\r\n metadataXml = await readFile(source);\r\n }\r\n\r\n const metadataJson = (await parseStringPromise(metadataXml)) as ODataEdmxModelBase<any>;\r\n // TODO find out if \"1.0\" and \"4.0\" are really correct\r\n // TODO exit here if no version not suitable version was detected\r\n // console.log(`OData version detected: ${metadataJson[\"edmx:Edmx\"].$.Version}`);\r\n\r\n // ensure that output directory exists\r\n try {\r\n await emptyDir(output);\r\n } catch (error) {\r\n console.error(`Output path [${output}] couldn't be created!`, error);\r\n process.exit(3);\r\n }\r\n\r\n // run the app\r\n try {\r\n await runApp(metadataJson, options);\r\n } catch (err: any) {\r\n console.error(\"Error while running the program\", err);\r\n process.exit(99);\r\n }\r\n}\r\n"]}
@@ -1,9 +1,10 @@
1
1
  import { RunOptions } from "./OptionModel";
2
+ export type DefaultConfiguration = Omit<RunOptions, "sourceUrl" | "source" | "output" | "serviceName">;
2
3
  /**
3
4
  * Creates a defensive copy of the default config.
4
5
  */
5
- export declare function getDefaultConfig(): Omit<RunOptions, "source" | "output">;
6
+ export declare function getDefaultConfig(): DefaultConfiguration;
6
7
  /**
7
8
  * Creates a defensive copy of the minimal config: minimal in respect to naming.
8
9
  */
9
- export declare function getMinimalConfig(): Omit<RunOptions, "source" | "output">;
10
+ export declare function getMinimalConfig(): DefaultConfiguration;
@@ -9,6 +9,8 @@ const OptionModel_1 = require("./OptionModel");
9
9
  * The default configuration.
10
10
  */
11
11
  const defaultConfig = {
12
+ sourceUrlConfig: {},
13
+ refreshFile: false,
12
14
  mode: OptionModel_1.Modes.all,
13
15
  emitMode: OptionModel_1.EmitModes.js_dts,
14
16
  debug: false,
@@ -1 +1 @@
1
- {"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.ts"],"names":[],"mappings":";;;;AAA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AAqB,aAAa,EAA7B,WAAW,kBAAK,aAAa,EAA1C,UAA0B,CAAgB,CAAC;IACjD,OAAO,IAAA,mBAAS,EAAC,WAAW,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;AACjE,CAAC;AAHD,4CAGC","sourcesContent":["import deepmerge from \"deepmerge\";\r\n\r\nimport { NameSettings, NamingStrategies } from \"./NamingModel\";\r\nimport { EmitModes, Modes, RunOptions } from \"./OptionModel\";\r\n\r\n/**\r\n * The default configuration.\r\n */\r\nconst defaultConfig: Omit<RunOptions, \"source\" | \"output\"> = {\r\n mode: Modes.all,\r\n emitMode: EmitModes.js_dts,\r\n debug: false,\r\n prettier: false,\r\n tsconfig: \"tsconfig.json\",\r\n converters: [],\r\n skipEditableModels: false,\r\n skipIdModels: false,\r\n skipOperations: false,\r\n skipComments: false,\r\n disableAutoManagedKey: false,\r\n allowRenaming: false,\r\n v2ModelsWithExtraResultsWrapping: false,\r\n naming: {\r\n models: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n editableModels: {\r\n prefix: \"Editable\",\r\n suffix: \"\",\r\n applyModelNaming: true,\r\n },\r\n idModels: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n applyModelNaming: true,\r\n },\r\n operationParamModels: {\r\n prefix: \"\",\r\n suffix: \"Params\",\r\n applyModelNaming: true,\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"\",\r\n suffix: \"Model\",\r\n },\r\n },\r\n queryObjects: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n idFunctions: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n },\r\n },\r\n services: {\r\n prefix: \"\",\r\n suffix: \"Service\",\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n prefix: \"\",\r\n suffix: \"Collection\",\r\n applyServiceNaming: true,\r\n },\r\n operations: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n },\r\n relatedServiceGetter: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"\",\r\n suffix: \"\",\r\n },\r\n privateProps: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"_\",\r\n suffix: \"\",\r\n },\r\n },\r\n },\r\n propertiesByName: [],\r\n entitiesByName: [],\r\n};\r\n\r\nconst { models, queryObjects, services } = defaultConfig.naming;\r\nconst minimalNamingConfig: NameSettings = {\r\n models: {\r\n fileName: {\r\n prefix: models.fileName.prefix,\r\n suffix: models.fileName.suffix,\r\n },\r\n idModels: {\r\n applyModelNaming: true,\r\n prefix: models.idModels.prefix,\r\n suffix: models.idModels.suffix,\r\n },\r\n editableModels: {\r\n applyModelNaming: true,\r\n prefix: models.editableModels.prefix,\r\n suffix: models.editableModels.suffix,\r\n },\r\n operationParamModels: {\r\n applyModelNaming: true,\r\n prefix: models.operationParamModels.prefix,\r\n suffix: models.operationParamModels.suffix,\r\n },\r\n },\r\n queryObjects: {\r\n prefix: queryObjects.prefix,\r\n suffix: queryObjects.suffix,\r\n fileName: {\r\n prefix: queryObjects.fileName.prefix,\r\n suffix: queryObjects.fileName.suffix,\r\n },\r\n idFunctions: {\r\n prefix: queryObjects.idFunctions.prefix,\r\n suffix: queryObjects.idFunctions.suffix,\r\n },\r\n },\r\n services: {\r\n prefix: services.prefix,\r\n suffix: services.suffix,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n applyServiceNaming: true,\r\n prefix: services.collection.prefix,\r\n suffix: services.collection.suffix,\r\n },\r\n privateProps: {\r\n prefix: services.privateProps.prefix,\r\n suffix: services.privateProps.suffix,\r\n },\r\n relatedServiceGetter: {\r\n prefix: services.relatedServiceGetter.prefix,\r\n suffix: services.relatedServiceGetter.suffix,\r\n },\r\n },\r\n};\r\n\r\n/**\r\n * Creates a defensive copy of the default config.\r\n */\r\nexport function getDefaultConfig(): Omit<RunOptions, \"source\" | \"output\"> {\r\n return deepmerge(defaultConfig, {});\r\n}\r\n\r\n/**\r\n * Creates a defensive copy of the minimal config: minimal in respect to naming.\r\n */\r\nexport function getMinimalConfig(): Omit<RunOptions, \"source\" | \"output\"> {\r\n const { naming, ...passThrough } = defaultConfig;\r\n return deepmerge(passThrough, { naming: minimalNamingConfig });\r\n}\r\n"]}
1
+ {"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,kBAAkB,EAAE,KAAK;IACzB,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,KAAK;IACrB,YAAY,EAAE,KAAK;IACnB,qBAAqB,EAAE,KAAK;IAC5B,aAAa,EAAE,KAAK;IACpB,gCAAgC,EAAE,KAAK;IACvC,MAAM,EAAE;QACN,MAAM,EAAE;YACN,cAAc,EAAE,8BAAgB,CAAC,WAAW;YAC5C,kBAAkB,EAAE,8BAAgB,CAAC,UAAU;YAC/C,cAAc,EAAE;gBACd,MAAM,EAAE,UAAU;gBAClB,MAAM,EAAE,EAAE;gBACV,gBAAgB,EAAE,IAAI;aACvB;YACD,QAAQ,EAAE;gBACR,MAAM,EAAE,EAAE;g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M,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM;YAClC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM;SACnC;QACD,YAAY,EAAE;YACZ,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,MAAM;YACpC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,MAAM;SACrC;QACD,oBAAoB,EAAE;YACpB,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,MAAM;YAC5C,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,MAAM;SAC7C;KACF;CACF,CAAC;AAEF;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,mBAAS,EAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAFD,4CAEC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,MAAM,EAAE,MAAM,KAAqB,aAAa,EAA7B,WAAW,kBAAK,aAAa,EAA1C,UAA0B,CAAgB,CAAC;IACjD,OAAO,IAAA,mBAAS,EAAC,WAAW,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;AACjE,CAAC;AAHD,4CAGC","sourcesContent":["import deepmerge from \"deepmerge\";\r\n\r\nimport { NameSettings, NamingStrategies } from \"./NamingModel\";\r\nimport { EmitModes, Modes, RunOptions } from \"./OptionModel\";\r\n\r\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 disableAutoManagedKey: false,\r\n allowRenaming: false,\r\n v2ModelsWithExtraResultsWrapping: false,\r\n naming: {\r\n models: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n editableModels: {\r\n prefix: \"Editable\",\r\n suffix: \"\",\r\n applyModelNaming: true,\r\n },\r\n idModels: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n applyModelNaming: true,\r\n },\r\n operationParamModels: {\r\n prefix: \"\",\r\n suffix: \"Params\",\r\n applyModelNaming: true,\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"\",\r\n suffix: \"Model\",\r\n },\r\n },\r\n queryObjects: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n idFunctions: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n },\r\n },\r\n services: {\r\n prefix: \"\",\r\n suffix: \"Service\",\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n prefix: \"\",\r\n suffix: \"Collection\",\r\n applyServiceNaming: true,\r\n },\r\n operations: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n },\r\n relatedServiceGetter: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"\",\r\n suffix: \"\",\r\n },\r\n privateProps: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"_\",\r\n suffix: \"\",\r\n },\r\n },\r\n },\r\n propertiesByName: [],\r\n entitiesByName: [],\r\n};\r\n\r\nconst { models, queryObjects, services } = defaultConfig.naming;\r\nconst minimalNamingConfig: NameSettings = {\r\n models: {\r\n fileName: {\r\n prefix: models.fileName.prefix,\r\n suffix: models.fileName.suffix,\r\n },\r\n idModels: {\r\n applyModelNaming: true,\r\n prefix: models.idModels.prefix,\r\n suffix: models.idModels.suffix,\r\n },\r\n editableModels: {\r\n applyModelNaming: true,\r\n prefix: models.editableModels.prefix,\r\n suffix: models.editableModels.suffix,\r\n },\r\n operationParamModels: {\r\n applyModelNaming: true,\r\n prefix: models.operationParamModels.prefix,\r\n suffix: models.operationParamModels.suffix,\r\n },\r\n },\r\n queryObjects: {\r\n prefix: queryObjects.prefix,\r\n suffix: queryObjects.suffix,\r\n fileName: {\r\n prefix: queryObjects.fileName.prefix,\r\n suffix: queryObjects.fileName.suffix,\r\n },\r\n idFunctions: {\r\n prefix: queryObjects.idFunctions.prefix,\r\n suffix: queryObjects.idFunctions.suffix,\r\n },\r\n },\r\n services: {\r\n prefix: services.prefix,\r\n suffix: services.suffix,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n applyServiceNaming: true,\r\n prefix: services.collection.prefix,\r\n suffix: services.collection.suffix,\r\n },\r\n privateProps: {\r\n prefix: services.privateProps.prefix,\r\n suffix: services.privateProps.suffix,\r\n },\r\n relatedServiceGetter: {\r\n prefix: services.relatedServiceGetter.prefix,\r\n suffix: services.relatedServiceGetter.suffix,\r\n },\r\n },\r\n};\r\n\r\n/**\r\n * Creates a defensive copy of the default config.\r\n */\r\nexport function getDefaultConfig(): 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"]}
@@ -0,0 +1,12 @@
1
+ import { UrlSourceConfiguration } from "../OptionModel";
2
+ /**
3
+ * Retrieves the metadata from the given URL using the given configuration.
4
+ *
5
+ * Failure handling must be implemented by consumer.
6
+ * Exception is thrown for failed requests (400, 401, ...).
7
+ *
8
+ * @param sourceUrl
9
+ * @param sourceConfig
10
+ * @param debug
11
+ */
12
+ export declare function downloadMetadata(sourceUrl: string, sourceConfig?: UrlSourceConfiguration, debug?: boolean): Promise<string>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadMetadata = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const axios_1 = tslib_1.__importDefault(require("axios"));
6
+ const METADATA_PATH = "$metadata";
7
+ const PWD_BLIND_TEXT = { password: "xxx hidden xxx" };
8
+ function evaluateRequestConfig(url, config) {
9
+ const defaultReqConfig = { url: url, method: "GET" };
10
+ const reqConfig = config.custom
11
+ ? config.custom
12
+ : typeof config.username === "string" && typeof (config === null || config === void 0 ? void 0 : config.password) === "string"
13
+ ? { auth: { username: config.username, password: config.password } }
14
+ : {};
15
+ return Object.assign(Object.assign({}, defaultReqConfig), reqConfig);
16
+ }
17
+ /**
18
+ * Retrieves the metadata from the given URL using the given configuration.
19
+ *
20
+ * Failure handling must be implemented by consumer.
21
+ * Exception is thrown for failed requests (400, 401, ...).
22
+ *
23
+ * @param sourceUrl
24
+ * @param sourceConfig
25
+ * @param debug
26
+ */
27
+ function downloadMetadata(sourceUrl, sourceConfig = {}, debug = false) {
28
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
29
+ // add the $metadata suffix
30
+ const url = sourceUrl.endsWith(METADATA_PATH)
31
+ ? sourceUrl
32
+ : sourceUrl + (sourceUrl.endsWith("/") ? "" : "/") + METADATA_PATH;
33
+ console.log(`Reading metadata from URL:`, url);
34
+ // evaluate configured request config options
35
+ const config = evaluateRequestConfig(url, sourceConfig);
36
+ // log request configuration without password
37
+ if (debug) {
38
+ const { auth } = config, loggable = tslib_1.__rest(config, ["auth"]);
39
+ const safeConfig = auth ? Object.assign(Object.assign({}, loggable), { auth: Object.assign(Object.assign({}, auth), (auth.password ? PWD_BLIND_TEXT : {})) }) : loggable;
40
+ console.log(`Request configuration:`, safeConfig);
41
+ }
42
+ // execute the request & return response data
43
+ const response = yield axios_1.default.request(config);
44
+ return response.data;
45
+ });
46
+ }
47
+ exports.downloadMetadata = downloadMetadata;
48
+ //# sourceMappingURL=downloadMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"downloadMetadata.js","sourceRoot":"","sources":["../../src/download/downloadMetadata.ts"],"names":[],"mappings":";;;;AAAA,0DAAkD;AAIlD,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,cAAc,GAAG,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC;AAEtD,SAAS,qBAAqB,CAAC,GAAW,EAAE,MAA8B;IACxE,MAAM,gBAAgB,GAAuB,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACzE,MAAM,SAAS,GAAuB,MAAM,CAAC,MAAM;QACjD,CAAC,CAAC,MAAM,CAAC,MAAM;QACf,CAAC,CAAC,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,CAAA,KAAK,QAAQ;YAC7E,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE;YACpE,CAAC,CAAC,EAAE,CAAC;IACP,uCAAY,gBAAgB,GAAK,SAAS,EAAG;AAC/C,CAAC;AAED;;;;;;;;;GASG;AACH,SAAsB,gBAAgB,CACpC,SAAiB,EACjB,eAAuC,EAAE,EACzC,QAAiB,KAAK;;QAEtB,2BAA2B;QAC3B,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC;YAC3C,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,SAAS,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC;QACrE,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;QAE/C,6CAA6C;QAC7C,MAAM,MAAM,GAAG,qBAAqB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAExD,6CAA6C;QAC7C,IAAI,KAAK,EAAE;YACT,MAAM,EAAE,IAAI,KAAkB,MAAM,EAAnB,QAAQ,kBAAK,MAAM,EAA9B,QAAqB,CAAS,CAAC;YACrC,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,iCAAM,QAAQ,KAAE,IAAI,kCAAO,IAAI,GAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC;YAClH,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC;SACnD;QAED,6CAA6C;QAC7C,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7C,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CAAA;AAxBD,4CAwBC","sourcesContent":["import axios, { AxiosRequestConfig } from \"axios\";\r\n\r\nimport { UrlSourceConfiguration } from \"../OptionModel\";\r\n\r\nconst METADATA_PATH = \"$metadata\";\r\nconst PWD_BLIND_TEXT = { password: \"xxx hidden xxx\" };\r\n\r\nfunction evaluateRequestConfig(url: string, config: UrlSourceConfiguration): AxiosRequestConfig {\r\n const defaultReqConfig: AxiosRequestConfig = { url: url, method: \"GET\" };\r\n const reqConfig: AxiosRequestConfig = config.custom\r\n ? config.custom\r\n : typeof config.username === \"string\" && typeof config?.password === \"string\"\r\n ? { auth: { username: config.username, password: config.password } }\r\n : {};\r\n return { ...defaultReqConfig, ...reqConfig };\r\n}\r\n\r\n/**\r\n * Retrieves the metadata from the given URL using the given configuration.\r\n *\r\n * Failure handling must be implemented by consumer.\r\n * Exception is thrown for failed requests (400, 401, ...).\r\n *\r\n * @param sourceUrl\r\n * @param sourceConfig\r\n * @param debug\r\n */\r\nexport async function downloadMetadata(\r\n sourceUrl: string,\r\n sourceConfig: UrlSourceConfiguration = {},\r\n debug: boolean = false\r\n): Promise<string> {\r\n // add the $metadata suffix\r\n const url = sourceUrl.endsWith(METADATA_PATH)\r\n ? sourceUrl\r\n : sourceUrl + (sourceUrl.endsWith(\"/\") ? \"\" : \"/\") + METADATA_PATH;\r\n console.log(`Reading metadata from URL:`, url);\r\n\r\n // evaluate configured request config options\r\n const config = evaluateRequestConfig(url, sourceConfig);\r\n\r\n // log request configuration without password\r\n if (debug) {\r\n const { auth, ...loggable } = config;\r\n const safeConfig = auth ? { ...loggable, auth: { ...auth, ...(auth.password ? PWD_BLIND_TEXT : {}) } } : loggable;\r\n console.log(`Request configuration:`, safeConfig);\r\n }\r\n\r\n // execute the request & return response data\r\n const response = await axios.request(config);\r\n return response.data;\r\n}\r\n"]}
@@ -0,0 +1,2 @@
1
+ export { downloadMetadata } from "./downloadMetadata";
2
+ export { storeMetadata } from "./storeMetadata";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.storeMetadata = exports.downloadMetadata = void 0;
4
+ var downloadMetadata_1 = require("./downloadMetadata");
5
+ Object.defineProperty(exports, "downloadMetadata", { enumerable: true, get: function () { return downloadMetadata_1.downloadMetadata; } });
6
+ var storeMetadata_1 = require("./storeMetadata");
7
+ Object.defineProperty(exports, "storeMetadata", { enumerable: true, get: function () { return storeMetadata_1.storeMetadata; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/download/index.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA","sourcesContent":["export { downloadMetadata } from \"./downloadMetadata\";\r\nexport { storeMetadata } from \"./storeMetadata\";\r\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Write (prettified) data to disk.
3
+ *
4
+ * @param filePath
5
+ * @param metadataXml
6
+ * @param prettify
7
+ */
8
+ export declare function storeMetadata(filePath: string, metadataXml: string, prettify: boolean): Promise<string>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.storeMetadata = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const fs_extra_1 = require("fs-extra");
7
+ const prettier_1 = tslib_1.__importDefault(require("prettier"));
8
+ /**
9
+ * Write (prettified) data to disk.
10
+ *
11
+ * @param filePath
12
+ * @param metadataXml
13
+ * @param prettify
14
+ */
15
+ function storeMetadata(filePath, metadataXml, prettify) {
16
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
17
+ const outDir = path_1.default.dirname(filePath);
18
+ const prettierConfig = yield prettier_1.default.resolveConfig(outDir);
19
+ const prettified = prettify
20
+ ? prettier_1.default.format(metadataXml, Object.assign(Object.assign({ xmlWhitespaceSensitivity: "ignore" }, prettierConfig), { parser: "xml", plugins: ["@prettier/plugin-xml"] }))
21
+ : metadataXml;
22
+ yield (0, fs_extra_1.ensureDir)(outDir);
23
+ yield (0, fs_extra_1.writeFile)(filePath, prettified);
24
+ return prettified;
25
+ });
26
+ }
27
+ exports.storeMetadata = storeMetadata;
28
+ //# sourceMappingURL=storeMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storeMetadata.js","sourceRoot":"","sources":["../../src/download/storeMetadata.ts"],"names":[],"mappings":";;;;AAAA,wDAAwB;AAExB,uCAAgD;AAChD,gEAAgC;AAEhC;;;;;;GAMG;AACH,SAAsB,aAAa,CAAC,QAAgB,EAAE,WAAmB,EAAE,QAAiB;;QAC1F,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAEtC,MAAM,cAAc,GAAG,MAAM,kBAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC5D,MAAM,UAAU,GAAG,QAAQ;YACzB,CAAC,CAAC,kBAAQ,CAAC,MAAM,CACb,WAAW,gCAET,wBAAwB,EAAE,QAAQ,IAAK,cAAc,KAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,sBAAsB,CAAC,IAC1G;YACH,CAAC,CAAC,WAAW,CAAC;QAEhB,MAAM,IAAA,oBAAS,EAAC,MAAM,CAAC,CAAC;QACxB,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAEtC,OAAO,UAAU,CAAC;IACpB,CAAC;CAAA;AAhBD,sCAgBC","sourcesContent":["import path from \"path\";\r\n\r\nimport { ensureDir, writeFile } from \"fs-extra\";\r\nimport prettier from \"prettier\";\r\n\r\n/**\r\n * Write (prettified) data to disk.\r\n *\r\n * @param filePath\r\n * @param metadataXml\r\n * @param prettify\r\n */\r\nexport async function storeMetadata(filePath: string, metadataXml: string, prettify: boolean) {\r\n const outDir = path.dirname(filePath);\r\n\r\n const prettierConfig = await prettier.resolveConfig(outDir);\r\n const prettified = prettify\r\n ? prettier.format(\r\n metadataXml,\r\n // @ts-ignore: xmlWhitespaceSensitivity is an option of the plugin\r\n { xmlWhitespaceSensitivity: \"ignore\", ...prettierConfig, parser: \"xml\", plugins: [\"@prettier/plugin-xml\"] }\r\n )\r\n : metadataXml;\r\n\r\n await ensureDir(outDir);\r\n await writeFile(filePath, prettified);\r\n\r\n return prettified;\r\n}\r\n"]}
@@ -25,8 +25,10 @@ class PrettierFormatter extends BaseFormatter_1.BaseFormatter {
25
25
  useTrailingCommas: this.options.trailingComma === "none" ? false : true,
26
26
  };
27
27
  }
28
- else
28
+ else {
29
29
  this.settings = {};
30
+ }
31
+ ;
30
32
  return this;
31
33
  });
32
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrettierFormatter.js","sourceRoot":"","sources":["../../../src/project/formatter/PrettierFormatter.ts"],"names":[],"mappings":";;;;AAAA,gE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G,CAAC;QAExC,QAAQ,QAAQ,EAAE;YAChB,KAAK,CAAC;gBACJ,OAAO,0BAAe,CAAC,SAAS,CAAC;YACnC,KAAK,CAAC;gBACJ,OAAO,0BAAe,CAAC,UAAU,CAAC;YACpC,KAAK,CAAC;gBACJ,OAAO,0BAAe,CAAC,WAAW,CAAC;YACrC;gBACE,OAAO,0BAAe,CAAC,SAAS,CAAC;SACpC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,cAAc,CAAC,GAAuB;QAC5C,QAAQ,GAAG,EAAE;YACX,KAAK,IAAI;gBACP,OAAO,sBAAW,CAAC,QAAQ,CAAC;YAC9B,KAAK,MAAM;gBACT,OAAO,sBAAW,CAAC,sBAAsB,CAAC;YAC5C,KAAK,IAAI;gBACP,OAAO,sBAAW,CAAC,sBAAsB,CAAC;YAC5C,KAAK,MAAM;gBACT,OAAO,sBAAW,CAAC,QAAQ,CAAC;YAC9B;gBACE,OAAO,sBAAW,CAAC,QAAQ,CAAC;SAC/B;IACH,CAAC;CACF;AA/FD,8CA+FC","sourcesContent":["import prettier from \"prettier\";\r\nimport { IndentationText, NewLineKind, QuoteKind } from \"ts-morph\";\r\nimport { BaseFormatter } from \"./BaseFormatter\";\r\n\r\nexport class PrettierFormatter extends BaseFormatter {\r\n /**\r\n * Prettier options found in the project.\r\n *\r\n * @private\r\n * @type {prettier.Options}\r\n * @memberof PrettierFormatter\r\n */\r\n private options!: prettier.Options;\r\n\r\n /**\r\n * Initializes the formatter.\r\n *\r\n * @returns {Promise<PrettierFormatter>} Initialized formatter\r\n * @memberof PrettierFormatter\r\n */\r\n public async init(): Promise<PrettierFormatter> {\r\n const options = await prettier.resolveConfig(this.output);\r\n\r\n if (options) {\r\n this.options = options;\r\n this.settings = {\r\n indentationText: this.convertIndentation(this.options.useTabs, this.options.tabWidth),\r\n insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces:\r\n this.options.bracketSpacing !== undefined ? this.options.bracketSpacing : true,\r\n newLineKind: this.convertNewline(this.options.endOfLine),\r\n quoteKind: this.options.singleQuote ? QuoteKind.Single : QuoteKind.Double,\r\n useTrailingCommas: this.options.trailingComma === \"none\" ? false : true,\r\n };\r\n } else this.settings = {};\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Formats a given source code.\r\n *\r\n * @abstract\r\n * @param {string} source Source code to format\r\n * @returns {string} Formatted source code\r\n * @memberof Formatter\r\n */\r\n public async format(source: string): Promise<string> {\r\n return prettier.format(source, {\r\n parser: \"typescript\",\r\n ...this.options,\r\n });\r\n }\r\n\r\n /**\r\n * Converts prettier indentation config to ts-morph settings.\r\n *\r\n * @private\r\n * @param {boolean | undefined} useTabs Flag, whether to use tabs or not\r\n * @param {number | undefined} tabWidth Width of a simulated tab, each number represents a space\r\n * @returns {IndentationText} Converted indentation text\r\n * @memberof PrettierFormatter\r\n */\r\n private convertIndentation(useTabs: boolean | undefined, tabWidth: number | undefined): IndentationText {\r\n if (useTabs) return IndentationText.Tab;\r\n\r\n switch (tabWidth) {\r\n case 2:\r\n return IndentationText.TwoSpaces;\r\n case 4:\r\n return IndentationText.FourSpaces;\r\n case 8:\r\n return IndentationText.EightSpaces;\r\n default:\r\n return IndentationText.TwoSpaces;\r\n }\r\n }\r\n\r\n /**\r\n * Converts prettier newline config to ts-morph settings.\r\n *\r\n * @private\r\n * @param {string | undefined} eol prettier end-of-line config\r\n * @returns {NewLineKind | undefined} Converted new line kind\r\n * @memberof PrettierFormatter\r\n */\r\n private convertNewline(eol: string | undefined): NewLineKind | undefined {\r\n switch (eol) {\r\n case \"lf\":\r\n return NewLineKind.LineFeed;\r\n case \"crlf\":\r\n return NewLineKind.CarriageReturnLineFeed;\r\n case \"cr\":\r\n return NewLineKind.CarriageReturnLineFeed;\r\n case \"auto\":\r\n return NewLineKind.LineFeed;\r\n default:\r\n return NewLineKind.LineFeed;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"PrettierFormatter.js","sourceRoot":"","sources":["../../../src/project/formatter/PrettierFormat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,QAA4B;QACnF,IAAI,OAAO;YAAE,OAAO,0BAAe,CAAC,GAAG,CAAC;QAExC,QAAQ,QAAQ,EAAE;YAChB,KAAK,CAAC;gBACJ,OAAO,0BAAe,CAAC,SAAS,CAAC;YACnC,KAAK,CAAC;gBACJ,OAAO,0BAAe,CAAC,UAAU,CAAC;YACpC,KAAK,CAAC;gBACJ,OAAO,0BAAe,CAAC,WAAW,CAAC;YACrC;gBACE,OAAO,0BAAe,CAAC,SAAS,CAAC;SACpC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,cAAc,CAAC,GAAuB;QAC5C,QAAQ,GAAG,EAAE;YACX,KAAK,IAAI;gBACP,OAAO,sBAAW,CAAC,QAAQ,CAAC;YAC9B,KAAK,MAAM;gBACT,OAAO,sBAAW,CAAC,sBAAsB,CAAC;YAC5C,KAAK,IAAI;gBACP,OAAO,sBAAW,CAAC,sBAAsB,CAAC;YAC5C,KAAK,MAAM;gBACT,OAAO,sBAAW,CAAC,QAAQ,CAAC;YAC9B;gBACE,OAAO,sBAAW,CAAC,QAAQ,CAAC;SAC/B;IACH,CAAC;CACF;AAjGD,8CAiGC","sourcesContent":["import prettier from \"prettier\";\r\nimport { IndentationText, NewLineKind, QuoteKind } from \"ts-morph\";\r\n\r\nimport { BaseFormatter } from \"./BaseFormatter\";\r\n\r\nexport class PrettierFormatter extends BaseFormatter {\r\n /**\r\n * Prettier options found in the project.\r\n *\r\n * @private\r\n * @type {prettier.Options}\r\n * @memberof PrettierFormatter\r\n */\r\n private options!: prettier.Options;\r\n\r\n /**\r\n * Initializes the formatter.\r\n *\r\n * @returns {Promise<PrettierFormatter>} Initialized formatter\r\n * @memberof PrettierFormatter\r\n */\r\n public async init(): Promise<PrettierFormatter> {\r\n const options = await prettier.resolveConfig(this.output);\r\n\r\n if (options) {\r\n this.options = options;\r\n this.settings = {\r\n indentationText: this.convertIndentation(this.options.useTabs, this.options.tabWidth),\r\n insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces:\r\n this.options.bracketSpacing !== undefined ? this.options.bracketSpacing : true,\r\n newLineKind: this.convertNewline(this.options.endOfLine),\r\n quoteKind: this.options.singleQuote ? QuoteKind.Single : QuoteKind.Double,\r\n useTrailingCommas: this.options.trailingComma === \"none\" ? false : true,\r\n };\r\n } else {\r\n this.settings = {};\r\n };\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Formats a given source code.\r\n *\r\n * @abstract\r\n * @param {string} source Source code to format\r\n * @returns {string} Formatted source code\r\n * @memberof Formatter\r\n */\r\n public async format(source: string): Promise<string> {\r\n return prettier.format(source, {\r\n parser: \"typescript\",\r\n ...this.options,\r\n });\r\n }\r\n\r\n /**\r\n * Converts prettier indentation config to ts-morph settings.\r\n *\r\n * @private\r\n * @param {boolean | undefined} useTabs Flag, whether to use tabs or not\r\n * @param {number | undefined} tabWidth Width of a simulated tab, each number represents a space\r\n * @returns {IndentationText} Converted indentation text\r\n * @memberof PrettierFormatter\r\n */\r\n private convertIndentation(useTabs: boolean | undefined, tabWidth: number | undefined): IndentationText {\r\n if (useTabs) return IndentationText.Tab;\r\n\r\n switch (tabWidth) {\r\n case 2:\r\n return IndentationText.TwoSpaces;\r\n case 4:\r\n return IndentationText.FourSpaces;\r\n case 8:\r\n return IndentationText.EightSpaces;\r\n default:\r\n return IndentationText.TwoSpaces;\r\n }\r\n }\r\n\r\n /**\r\n * Converts prettier newline config to ts-morph settings.\r\n *\r\n * @private\r\n * @param {string | undefined} eol prettier end-of-line config\r\n * @returns {NewLineKind | undefined} Converted new line kind\r\n * @memberof PrettierFormatter\r\n */\r\n private convertNewline(eol: string | undefined): NewLineKind | undefined {\r\n switch (eol) {\r\n case \"lf\":\r\n return NewLineKind.LineFeed;\r\n case \"crlf\":\r\n return NewLineKind.CarriageReturnLineFeed;\r\n case \"cr\":\r\n return NewLineKind.CarriageReturnLineFeed;\r\n case \"auto\":\r\n return NewLineKind.LineFeed;\r\n default:\r\n return NewLineKind.LineFeed;\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.26.1",
3
+ "version": "0.27.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -52,6 +52,8 @@
52
52
  "@odata2ts/converter-api": "^0.1.2",
53
53
  "@odata2ts/converter-runtime": "^0.1.5",
54
54
  "@odata2ts/odata-core": "^0.3.8",
55
+ "@prettier/plugin-xml": "^3.1.1",
56
+ "axios": "^1.4.0",
55
57
  "camel-case": "^4.1.2",
56
58
  "commander": "^10.0.1",
57
59
  "constant-case": "^3.0.4",
@@ -86,6 +88,6 @@
86
88
  "typescript": "^5.1.3"
87
89
  },
88
90
  "types": "./lib/index.d.ts",
89
- "gitHead": "5274c12a6cac8e4d167852570b054258f325c326",
91
+ "gitHead": "3aa112edc93601c89c86c14c991534524d1d2291",
90
92
  "readme": "README.md"
91
93
  }