@odata2ts/odata2ts 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +74 -74
- package/lib/OptionModel.d.ts +4 -0
- package/lib/OptionModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +2 -1
- package/lib/data-model/DataModelDigestion.js +9 -5
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataModelDigestionV2.js +1 -1
- package/lib/data-model/DataModelDigestionV2.js.map +1 -1
- package/lib/data-model/DataModelDigestionV4.js +5 -5
- package/lib/data-model/DataModelDigestionV4.js.map +1 -1
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/project/ProjectManager.js +1 -1
- package/lib/project/ProjectManager.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.26.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.25.1...@odata2ts/odata2ts@0.26.0) (2023-07-13)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **odata2ts:** bound operations with namespace as part of the name ([#187](https://github.com/odata2ts/odata2ts/issues/187)) ([68209f2](https://github.com/odata2ts/odata2ts/commit/68209f2bb5bc16fdaa36e5a3ddef21d72ce8f273))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **odata2ts:** allow property configuration via entity ([#188](https://github.com/odata2ts/odata2ts/issues/188)) ([bdb5bef](https://github.com/odata2ts/odata2ts/commit/bdb5bef6d70827e4cc06d8a8b73c6a31edb92a2e))
|
|
15
|
+
|
|
16
|
+
## [0.25.1](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.25.0...@odata2ts/odata2ts@0.25.1) (2023-07-10)
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **odata2ts:** duplicate output paths ([#184](https://github.com/odata2ts/odata2ts/issues/184)) ([b55366d](https://github.com/odata2ts/odata2ts/commit/b55366dab8d331ace3c766b4279b5b0cc575aa03))
|
|
21
|
+
|
|
6
22
|
# [0.25.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.24.0...@odata2ts/odata2ts@0.25.0) (2023-07-10)
|
|
7
23
|
|
|
8
24
|
### Bug Fixes
|
|
@@ -12,7 +28,9 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
12
28
|
### Features
|
|
13
29
|
|
|
14
30
|
* **odata2ts:** support for multiple namespaces by merging ([#175](https://github.com/odata2ts/odata2ts/issues/175)) ([db8fd61](https://github.com/odata2ts/odata2ts/commit/db8fd6165c57ceb9e04488789a62f2a5467ecc68))
|
|
31
|
+
|
|
15
32
|
* **odata2ts:** support schema alias ([#181](https://github.com/odata2ts/odata2ts/issues/181)) ([e0c04a8](https://github.com/odata2ts/odata2ts/commit/e0c04a83e32d99187652966bb9cc32f36ead3df2))
|
|
33
|
+
|
|
16
34
|
* **odata2ts:** support TypeDefinition elements ([#183](https://github.com/odata2ts/odata2ts/issues/183)) ([d77d2cb](https://github.com/odata2ts/odata2ts/commit/d77d2cbf17383dab50d35bb7374e08a83d264db2))
|
|
17
35
|
|
|
18
36
|
# [0.24.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.23.1...@odata2ts/odata2ts@0.24.0) (2023-06-14)
|
package/README.md
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
[](https://www.npmjs.com/package/@odata2ts/odata2ts)
|
|
2
|
-
|
|
3
|
-
# odata2ts
|
|
4
|
-
|
|
5
|
-
The basic idea of `odata2ts` is to leverage the readily available metadata of any OData service
|
|
6
|
-
to generate different sorts of typed artefacts which you use in your TypeScript code.
|
|
7
|
-
This package `@odata2ts/odata2ts` realizes the generation process.
|
|
8
|
-
|
|
9
|
-
The generator is supposed to be used with a TypeScript based configuration file.
|
|
10
|
-
Then it's able to handle the generation for multiple OData services.
|
|
11
|
-
|
|
12
|
-
It comes with powerful configuration options. Some highlights:
|
|
13
|
-
- generation of TypeScript files or compiled JS / DTS files
|
|
14
|
-
- name or rename stuff
|
|
15
|
-
- naming of pretty much any aspect of the generated artefacts
|
|
16
|
-
- e.g. all types should be prefixed with an "I", Person => IPerson
|
|
17
|
-
- consistent casing (as in "camelCase" or "PascalCase") even for property names of entity types
|
|
18
|
-
- use type converters
|
|
19
|
-
|
|
20
|
-
See the [generator documentation](https://odata2ts.github.io/docs/generator/setup-and-usage) for more information.
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
npm install --save-dev @odata2ts/odata2ts
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### Implicit Dependencies
|
|
29
|
-
Most of the generated artefacts depend on other libraries. `odata2ts` lists them as peer dependencies.
|
|
30
|
-
|
|
31
|
-
Depending on your use case, you will need to add runtime dependencies matching the mentioned peer dependencies.
|
|
32
|
-
See the [Getting Started Guide](https://odata2ts.github.io/docs/category/getting-started/) of the documentation
|
|
33
|
-
for guidance.
|
|
34
|
-
|
|
35
|
-
## Documentation
|
|
36
|
-
[Generator Documentation](https://odata2ts.github.io/docs/generator/setup-and-usage)
|
|
37
|
-
|
|
38
|
-
Main documentation for the odata2ts eco system:
|
|
39
|
-
[https://odata2ts.github.io](https://odata2ts.github.io/)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## Examples
|
|
43
|
-
See [example packages](https://github.com/odata2ts/odata2ts/tree/main/examples) for examples of how to integrate `odata2ts`.
|
|
44
|
-
|
|
45
|
-
## Tests
|
|
46
|
-
See folder [test](https://github.com/odata2ts/odata2ts/tree/main/packages/odata2ts/test)
|
|
47
|
-
for unit tests.
|
|
48
|
-
|
|
49
|
-
See folder [int-test](https://github.com/odata2ts/odata2ts/tree/main/packages/odata2ts/int-test) for integration
|
|
50
|
-
tests of the CLI.
|
|
51
|
-
|
|
52
|
-
Each example package serves as integration test of the generator.
|
|
53
|
-
|
|
54
|
-
## Support, Feedback, Contributing
|
|
55
|
-
This project is open to feature requests, suggestions, bug reports, usage questions etc.
|
|
56
|
-
via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
|
|
57
|
-
|
|
58
|
-
Contributions and feedback are encouraged and always welcome.
|
|
59
|
-
|
|
60
|
-
See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
|
|
61
|
-
|
|
62
|
-
## Spirit
|
|
63
|
-
This project and this module have been created and are maintained in the following spirit:
|
|
64
|
-
|
|
65
|
-
* adhere to the **OData specification** as much as possible
|
|
66
|
-
* support any OData service implementation which conforms to the spec
|
|
67
|
-
* allow to work around faulty implementations if possible
|
|
68
|
-
* stability matters
|
|
69
|
-
* exercise Test Driven Development
|
|
70
|
-
* bomb the place with unit tests (code coverage > 95%)
|
|
71
|
-
* ensure that assumptions & understanding are correct by creating integration tests
|
|
72
|
-
|
|
73
|
-
## License
|
|
74
|
-
MIT - see [License](./LICENSE).
|
|
1
|
+
[](https://www.npmjs.com/package/@odata2ts/odata2ts)
|
|
2
|
+
|
|
3
|
+
# odata2ts
|
|
4
|
+
|
|
5
|
+
The basic idea of `odata2ts` is to leverage the readily available metadata of any OData service
|
|
6
|
+
to generate different sorts of typed artefacts which you use in your TypeScript code.
|
|
7
|
+
This package `@odata2ts/odata2ts` realizes the generation process.
|
|
8
|
+
|
|
9
|
+
The generator is supposed to be used with a TypeScript based configuration file.
|
|
10
|
+
Then it's able to handle the generation for multiple OData services.
|
|
11
|
+
|
|
12
|
+
It comes with powerful configuration options. Some highlights:
|
|
13
|
+
- generation of TypeScript files or compiled JS / DTS files
|
|
14
|
+
- name or rename stuff
|
|
15
|
+
- naming of pretty much any aspect of the generated artefacts
|
|
16
|
+
- e.g. all types should be prefixed with an "I", Person => IPerson
|
|
17
|
+
- consistent casing (as in "camelCase" or "PascalCase") even for property names of entity types
|
|
18
|
+
- use type converters
|
|
19
|
+
|
|
20
|
+
See the [generator documentation](https://odata2ts.github.io/docs/generator/setup-and-usage) for more information.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
npm install --save-dev @odata2ts/odata2ts
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Implicit Dependencies
|
|
29
|
+
Most of the generated artefacts depend on other libraries. `odata2ts` lists them as peer dependencies.
|
|
30
|
+
|
|
31
|
+
Depending on your use case, you will need to add runtime dependencies matching the mentioned peer dependencies.
|
|
32
|
+
See the [Getting Started Guide](https://odata2ts.github.io/docs/category/getting-started/) of the documentation
|
|
33
|
+
for guidance.
|
|
34
|
+
|
|
35
|
+
## Documentation
|
|
36
|
+
[Generator Documentation](https://odata2ts.github.io/docs/generator/setup-and-usage)
|
|
37
|
+
|
|
38
|
+
Main documentation for the odata2ts eco system:
|
|
39
|
+
[https://odata2ts.github.io](https://odata2ts.github.io/)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Examples
|
|
43
|
+
See [example packages](https://github.com/odata2ts/odata2ts/tree/main/examples) for examples of how to integrate `odata2ts`.
|
|
44
|
+
|
|
45
|
+
## Tests
|
|
46
|
+
See folder [test](https://github.com/odata2ts/odata2ts/tree/main/packages/odata2ts/test)
|
|
47
|
+
for unit tests.
|
|
48
|
+
|
|
49
|
+
See folder [int-test](https://github.com/odata2ts/odata2ts/tree/main/packages/odata2ts/int-test) for integration
|
|
50
|
+
tests of the CLI.
|
|
51
|
+
|
|
52
|
+
Each example package serves as integration test of the generator.
|
|
53
|
+
|
|
54
|
+
## Support, Feedback, Contributing
|
|
55
|
+
This project is open to feature requests, suggestions, bug reports, usage questions etc.
|
|
56
|
+
via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
|
|
57
|
+
|
|
58
|
+
Contributions and feedback are encouraged and always welcome.
|
|
59
|
+
|
|
60
|
+
See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
|
|
61
|
+
|
|
62
|
+
## Spirit
|
|
63
|
+
This project and this module have been created and are maintained in the following spirit:
|
|
64
|
+
|
|
65
|
+
* adhere to the **OData specification** as much as possible
|
|
66
|
+
* support any OData service implementation which conforms to the spec
|
|
67
|
+
* allow to work around faulty implementations if possible
|
|
68
|
+
* stability matters
|
|
69
|
+
* exercise Test Driven Development
|
|
70
|
+
* bomb the place with unit tests (code coverage > 95%)
|
|
71
|
+
* ensure that assumptions & understanding are correct by creating integration tests
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
MIT - see [License](./LICENSE).
|
package/lib/OptionModel.d.ts
CHANGED
|
@@ -205,6 +205,10 @@ export interface EntityGenerationOptions {
|
|
|
205
205
|
* Overwrite the key specification by naming the props by their EDMX name.
|
|
206
206
|
*/
|
|
207
207
|
keys?: Array<string>;
|
|
208
|
+
/**
|
|
209
|
+
* Configuration of individual properties.
|
|
210
|
+
*/
|
|
211
|
+
properties?: Array<PropertyGenerationOptions>;
|
|
208
212
|
}
|
|
209
213
|
/**
|
|
210
214
|
* All configuration options for properties of models.
|
package/lib/OptionModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptionModel.js","sourceRoot":"","sources":["../src/OptionModel.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACH,IAAY,KAKX;AALD,WAAY,KAAK;IACf,qCAAM,CAAA;IACN,yCAAQ,CAAA;IACR,uCAAO,CAAA;IACP,+BAAG,CAAA;AACL,CAAC,EALW,KAAK,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":";;;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,5 +1,6 @@
|
|
|
1
1
|
import { MappedConverterChains } from "@odata2ts/converter-runtime";
|
|
2
2
|
import { DigestionOptions } from "../FactoryFunctionModel";
|
|
3
|
+
import { PropertyGenerationOptions } from "../OptionModel";
|
|
3
4
|
import { DataModel } from "./DataModel";
|
|
4
5
|
import { ODataVersion, PropertyModel } from "./DataTypeModel";
|
|
5
6
|
import { ComplexType, EntityType, Property, Schema } from "./edmx/ODataEdmxModelBase";
|
|
@@ -44,5 +45,5 @@ export declare abstract class Digester<S extends Schema<ET, CT>, ET extends Enti
|
|
|
44
45
|
private postProcessModel;
|
|
45
46
|
private sortModelsByInheritance;
|
|
46
47
|
private collectBaseClassPropsAndKeys;
|
|
47
|
-
protected mapProp: (p: Property) => PropertyModel;
|
|
48
|
+
protected mapProp: (p: Property, entityPropConfig?: PropertyGenerationOptions | undefined) => PropertyModel;
|
|
48
49
|
}
|
|
@@ -11,12 +11,12 @@ class Digester {
|
|
|
11
11
|
this.options = options;
|
|
12
12
|
this.namingHelper = namingHelper;
|
|
13
13
|
this.model2Type = new Map();
|
|
14
|
-
this.mapProp = (p) => {
|
|
14
|
+
this.mapProp = (p, entityPropConfig) => {
|
|
15
15
|
if (!p.$.Type) {
|
|
16
16
|
throw new Error(`No type information given for property [${p.$.Name}]!`);
|
|
17
17
|
}
|
|
18
18
|
const configProp = this.serviceConfigHelper.findConfigPropByName(p.$.Name);
|
|
19
|
-
const name = this.namingHelper.getModelPropName((configProp === null || configProp === void 0 ? void 0 : configProp.mappedName) || p.$.Name);
|
|
19
|
+
const name = this.namingHelper.getModelPropName((entityPropConfig === null || entityPropConfig === void 0 ? void 0 : entityPropConfig.mappedName) || (configProp === null || configProp === void 0 ? void 0 : configProp.mappedName) || p.$.Name);
|
|
20
20
|
const isCollection = !!p.$.Type.match(/^Collection\(/);
|
|
21
21
|
let dataType = p.$.Type.replace(/^Collection\(([^\)]+)\)/, "$1");
|
|
22
22
|
if (this.namingHelper.includesServicePrefix(dataType)) {
|
|
@@ -27,7 +27,7 @@ class Digester {
|
|
|
27
27
|
}
|
|
28
28
|
let result;
|
|
29
29
|
// domain object known from service:
|
|
30
|
-
// EntityType, ComplexType, EnumType
|
|
30
|
+
// EntityType, ComplexType, EnumType
|
|
31
31
|
if (this.namingHelper.includesServicePrefix(dataType)) {
|
|
32
32
|
const resultDt = this.model2Type.get(dataType);
|
|
33
33
|
if (!resultDt) {
|
|
@@ -72,7 +72,7 @@ class Digester {
|
|
|
72
72
|
else {
|
|
73
73
|
throw new Error(`Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`);
|
|
74
74
|
}
|
|
75
|
-
return Object.assign({ odataName: p.$.Name, name, odataType: p.$.Type, required: p.$.Nullable === "false", isCollection: isCollection, managed: configProp === null || configProp === void 0 ? void 0 : configProp.managed }, result);
|
|
75
|
+
return Object.assign({ odataName: p.$.Name, name, odataType: p.$.Type, required: p.$.Nullable === "false", isCollection: isCollection, managed: typeof (entityPropConfig === null || entityPropConfig === void 0 ? void 0 : entityPropConfig.managed) !== "undefined" ? entityPropConfig.managed : configProp === null || configProp === void 0 ? void 0 : configProp.managed }, result);
|
|
76
76
|
};
|
|
77
77
|
this.dataModel = new DataModel_1.DataModel(version, converters);
|
|
78
78
|
this.serviceConfigHelper = new ServiceConfigHelper_1.ServiceConfigHelper(options);
|
|
@@ -146,7 +146,11 @@ class Digester {
|
|
|
146
146
|
odataName,
|
|
147
147
|
editableName,
|
|
148
148
|
baseClasses,
|
|
149
|
-
props: props.map(
|
|
149
|
+
props: props.map((p) => {
|
|
150
|
+
var _a;
|
|
151
|
+
const epConfig = (_a = entityConfig === null || entityConfig === void 0 ? void 0 : entityConfig.properties) === null || _a === void 0 ? void 0 : _a.find((ep) => ep.name === p.$.Name);
|
|
152
|
+
return this.mapProp(p, epConfig);
|
|
153
|
+
}),
|
|
150
154
|
baseProps: [], // postprocess required
|
|
151
155
|
};
|
|
152
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataModelDigestion.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestion.ts"],"names":[],"mappings":";;;;AAGA,2CAAwC;AAMxC,+DAA4D;AAS5D,MAAsB,QAAQ;IAS5B,YACY,OAAqB,EACrB,OAAiB,EACjB,OAAyB,EACzB,YAA0B,EACpC,UAAkC;QAJxB,YAAO,GAAP,OAAO,CAAc;QACrB,YAAO,GAAP,OAAO,CAAU;QACjB,YAAO,GAAP,OAAO,CAAkB;QACzB,iBAAY,GAAZ,YAAY,CAAc;QAN9B,eAAU,GAA2B,IAAI,GAAG,EAAqB,CAAC;QAmShE,YAAO,GAAG,CAAC,CAAW,EAAiB,EAAE;YACjD,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;gBACb,MAAM,IAAI,KAAK,CAAC,2CAA2C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,CAAC;gBAC5B,IAAI,YAAY,EAAE;oBAChB,YAAY,GAAG,YAAY,CAAC;oBAC5B,aAAa,GAAG,aAAa,CAAC;iBAC/B;aACF;YAED,KAAK,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,MAAA,SAAS,CAAC,QAAQ,0CAAE,MAAM,EAAE;gBAC9B,IAAI,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBACpE,YAAY,GAAG,SAAS,CAAC,WAAW,CAAC;gBACrC,aAAa,GAAG,SAAS,CAAC,eAAe,CAAC;aAC3C;YACD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;QACpD,CAAC,EACD,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAA0D,CAC1E,CAAC;IACJ,CAAC;;AAxSH,4BAyXC;AAxXkB,mBAAU,GAAG,MAAM,AAAT,CAAU;AACpB,uBAAc,GAAG,GAAG,AAAN,CAAO","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\r\n\r\nimport { DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { DataModel } from \"./DataModel\";\r\nimport { ComplexType as ComplexModelType, DataTypes, ModelType, ODataVersion, PropertyModel } from \"./DataTypeModel\";\r\nimport { ComplexType, EntityType, Property, Schema, TypeDefinition } from \"./edmx/ODataEdmxModelBase\";\r\nimport { SchemaV3 } from \"./edmx/ODataEdmxModelV3\";\r\nimport { SchemaV4 } from \"./edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./NamingHelper\";\r\nimport { ServiceConfigHelper } from \"./ServiceConfigHelper\";\r\n\r\nexport interface TypeModel {\r\n outputType: string;\r\n qPath: string;\r\n qCollection: string;\r\n qParam: string | undefined;\r\n}\r\n\r\nexport abstract class Digester<S extends Schema<ET, CT>, ET extends EntityType, CT extends ComplexType> {\r\n protected static EDM_PREFIX = \"Edm.\";\r\n protected static ROOT_OPERATION = \"/\";\r\n\r\n protected readonly dataModel: DataModel;\r\n protected readonly serviceConfigHelper: ServiceConfigHelper;\r\n\r\n private model2Type: Map<string, DataTypes> = new Map<string, DataTypes>();\r\n\r\n protected constructor(\r\n protected version: ODataVersion,\r\n protected schemas: Array<S>,\r\n protected options: DigestionOptions,\r\n protected namingHelper: NamingHelper,\r\n converters?: MappedConverterChains\r\n ) {\r\n this.dataModel = new DataModel(version, converters);\r\n this.serviceConfigHelper = new ServiceConfigHelper(options);\r\n\r\n this.collectModelTypes(schemas);\r\n }\r\n\r\n protected abstract getNavigationProps(entityType: ET | ComplexType): Array<Property>;\r\n\r\n protected abstract digestOperations(schema: SchemaV3 | SchemaV4): void;\r\n\r\n protected abstract digestEntityContainer(schema: SchemaV3 | SchemaV4): void;\r\n\r\n /**\r\n * Get essential infos about a given odata type from the version specific service variants.\r\n *\r\n * @param type\r\n * @return tuple of return type, query object, query collection object\r\n */\r\n protected abstract mapODataType(type: string): TypeModel;\r\n\r\n public async digest(): Promise<DataModel> {\r\n this.digestEntityTypesAndOperations();\r\n\r\n // delegate to version specific entity container digestion\r\n this.schemas.forEach((schema) => this.digestEntityContainer(schema));\r\n\r\n return this.dataModel;\r\n }\r\n\r\n private collectModelTypes(schemas: Array<S>) {\r\n schemas.forEach((schema) => {\r\n const servicePrefix = schema.$.Namespace + \".\";\r\n\r\n schema.EnumType?.forEach((et) => {\r\n this.model2Type.set(servicePrefix + et.$.Name, DataTypes.EnumType);\r\n });\r\n schema.ComplexType?.forEach((ct) => {\r\n this.model2Type.set(servicePrefix + ct.$.Name, DataTypes.ComplexType);\r\n });\r\n schema.EntityType?.forEach((et) => {\r\n this.model2Type.set(servicePrefix + et.$.Name, DataTypes.ModelType);\r\n });\r\n });\r\n }\r\n\r\n private digestEntityTypesAndOperations() {\r\n this.schemas.forEach((schema) => {\r\n // type definitions: alias for primitive types\r\n this.addTypeDefinition(schema.TypeDefinition);\r\n\r\n // enums\r\n if (schema.EnumType) {\r\n for (const et of schema.EnumType) {\r\n const name = et.$.Name;\r\n this.dataModel.addEnum(name, {\r\n odataName: name,\r\n name: this.namingHelper.getEnumName(name),\r\n members: et.Member.map((m) => m.$.Name),\r\n });\r\n }\r\n }\r\n\r\n // entity types\r\n this.addEntityType(schema.EntityType);\r\n // complex types\r\n this.addComplexType(schema.ComplexType);\r\n\r\n // V4 only: function & action types\r\n this.digestOperations(schema);\r\n });\r\n\r\n this.postProcessModel();\r\n }\r\n\r\n private getBaseModel(model: ComplexType) {\r\n const entityConfig = this.serviceConfigHelper.findConfigEntityByName(model.$.Name);\r\n const entityName = entityConfig?.mappedName || model.$.Name;\r\n\r\n const name = this.namingHelper.getModelName(entityName);\r\n const qName = this.namingHelper.getQName(entityName);\r\n const editableName = this.namingHelper.getEditableModelName(entityName);\r\n const odataName = model.$.Name;\r\n const bType = model.$.BaseType;\r\n const props = [...(model.Property ?? []), ...this.getNavigationProps(model)];\r\n\r\n // support for base types, i.e. extends clause of interfaces\r\n const baseClasses = [];\r\n if (bType) {\r\n baseClasses.push(this.namingHelper.getModelName(bType));\r\n }\r\n\r\n return {\r\n name,\r\n qName,\r\n odataName,\r\n editableName,\r\n baseClasses,\r\n props: props.map(this.mapProp),\r\n baseProps: [], // postprocess required\r\n };\r\n }\r\n\r\n private addTypeDefinition(types: Array<TypeDefinition> | undefined) {\r\n if (!types || !types.length) {\r\n return;\r\n }\r\n\r\n for (const t of types) {\r\n this.dataModel.addTypeDefinition(t.$.Name, t.$.UnderlyingType);\r\n }\r\n }\r\n\r\n private addComplexType(models: Array<ComplexType> | undefined) {\r\n if (!models || !models.length) {\r\n return;\r\n }\r\n\r\n for (const model of models) {\r\n const baseModel = this.getBaseModel(model);\r\n this.dataModel.addComplexType(baseModel.name, baseModel);\r\n }\r\n }\r\n\r\n private addEntityType(models: Array<ET> | undefined) {\r\n if (!models || !models.length) {\r\n return;\r\n }\r\n\r\n for (const model of models) {\r\n const baseModel = this.getBaseModel(model);\r\n const entityConfig = this.serviceConfigHelper.findConfigEntityByName(model.$.Name);\r\n const entityName = entityConfig?.mappedName || model.$.Name;\r\n\r\n // key support: we add keys from this entity,\r\n // but not keys stemming from base classes (postprocess required)\r\n const keyNames: Array<string> = [];\r\n if (entityConfig?.keys?.length) {\r\n keyNames.push(...entityConfig.keys);\r\n } else {\r\n const entity = model as EntityType;\r\n if (entity.Key && entity.Key.length && entity.Key[0].PropertyRef.length) {\r\n const propNames = entity.Key[0].PropertyRef.map((key) => key.$.Name);\r\n keyNames.push(...propNames);\r\n }\r\n }\r\n\r\n this.dataModel.addModel(baseModel.name, {\r\n ...baseModel,\r\n idModelName: this.namingHelper.getIdModelName(entityName),\r\n qIdFunctionName: this.namingHelper.getQIdFunctionName(entityName),\r\n generateId: true,\r\n keyNames: keyNames, // postprocess required to include key specs from base classes\r\n keys: [], // postprocess required to include props from base classes\r\n getKeyUnion: () => keyNames.join(\" | \"),\r\n });\r\n }\r\n }\r\n\r\n private postProcessModel() {\r\n // complex types\r\n const complexTypes = this.dataModel.getComplexTypes();\r\n complexTypes.forEach((model) => {\r\n const [baseProps] = this.collectBaseClassPropsAndKeys(model, []);\r\n model.baseProps = baseProps;\r\n });\r\n const modelTypes = this.dataModel.getModels();\r\n // entity types\r\n modelTypes.forEach((model) => {\r\n const [baseProps, baseKeys, idName, qIdName] = this.collectBaseClassPropsAndKeys(model, []);\r\n model.baseProps = baseProps;\r\n\r\n if (!model.keyNames.length && idName) {\r\n model.idModelName = idName;\r\n model.qIdFunctionName = qIdName;\r\n model.generateId = false;\r\n }\r\n model.keyNames.unshift(...baseKeys);\r\n\r\n // sanity check: entity types require key specification\r\n if (!model.keyNames.length) {\r\n throw new Error(`Key property is missing from Entity \"${model.name}\" (${model.odataName})!`);\r\n }\r\n\r\n const isSingleKey = model.keyNames.length === 1;\r\n const props = [...model.baseProps, ...model.props];\r\n model.keys = model.keyNames.map((keyName) => {\r\n const prop = props.find((p) => p.odataName === keyName);\r\n if (!prop) {\r\n throw new Error(`Key with name [${keyName}] not found in props!`);\r\n }\r\n // automatically set key prop to managed, if this is the only key of the given entity\r\n if (prop.managed === undefined) {\r\n prop.managed = !this.options.disableAutoManagedKey && isSingleKey;\r\n }\r\n return prop;\r\n });\r\n });\r\n\r\n const sortedModelTypes = this.sortModelsByInheritance<ModelType>(modelTypes);\r\n this.dataModel.setModels(sortedModelTypes);\r\n\r\n const sortedComplexTypes = this.sortModelsByInheritance<ComplexModelType>(complexTypes);\r\n this.dataModel.setComplexTypes(sortedComplexTypes);\r\n }\r\n\r\n private sortModelsByInheritance<Type extends ComplexModelType>(models: Type[]): { [name: string]: Type } {\r\n // recursively visit all models and sort them by inheritance such that base classes\r\n // are always before derived classes\r\n const sortedModels: { [name: string]: Type } = {};\r\n const visitedModels = new Set<Type>();\r\n const inProgressModels = new Set<Type>();\r\n\r\n function visit(model: Type) {\r\n if (inProgressModels.has(model)) {\r\n throw new Error(\"Cyclic dependencies detected!\");\r\n }\r\n\r\n if (!visitedModels.has(model)) {\r\n inProgressModels.add(model);\r\n\r\n for (const baseClassName of model.baseClasses) {\r\n const baseClass = models.find((e) => e.name === baseClassName);\r\n if (baseClass) {\r\n visit(baseClass);\r\n }\r\n }\r\n visitedModels.add(model);\r\n inProgressModels.delete(model);\r\n sortedModels[model.name] = model;\r\n }\r\n }\r\n\r\n for (const model of models) {\r\n visit(model);\r\n }\r\n return sortedModels;\r\n }\r\n\r\n private collectBaseClassPropsAndKeys(\r\n model: ComplexModelType,\r\n visitedModels: string[]\r\n ): [Array<PropertyModel>, Array<string>, string, string] {\r\n if (visitedModels.includes(model.name)) {\r\n throw new Error(`Cyclic inheritance detected for model ${model.name}!`);\r\n }\r\n visitedModels.push(model.name);\r\n return model.baseClasses.reduce(\r\n ([props, keys, idName, qIdName], bc) => {\r\n const baseModel = this.dataModel.getModel(bc) || this.dataModel.getComplexType(bc);\r\n if (!baseModel) {\r\n throw new Error(`BaseModel \"${bc}\" doesn't exist!`);\r\n }\r\n\r\n let idNameResult = idName;\r\n let qIdNameResult = qIdName;\r\n\r\n // recursive\r\n if (baseModel.baseClasses.length) {\r\n const [parentProps, parentKeys, parentIdName, parentQIdName] = this.collectBaseClassPropsAndKeys(\r\n baseModel,\r\n visitedModels\r\n );\r\n props.unshift(...parentProps);\r\n keys.unshift(...parentKeys);\r\n if (parentIdName) {\r\n idNameResult = parentIdName;\r\n qIdNameResult = parentQIdName;\r\n }\r\n }\r\n\r\n props.push(...baseModel.props);\r\n if (baseModel.keyNames?.length) {\r\n keys.push(...baseModel.keyNames.filter((kn) => !keys.includes(kn)));\r\n idNameResult = baseModel.idModelName;\r\n qIdNameResult = baseModel.qIdFunctionName;\r\n }\r\n return [props, keys, idNameResult, qIdNameResult];\r\n },\r\n [[], [], \"\", \"\"] as [Array<PropertyModel>, Array<string>, string, string]\r\n );\r\n }\r\n\r\n protected mapProp = (p: Property): PropertyModel => {\r\n if (!p.$.Type) {\r\n throw new Error(`No type information given for property [${p.$.Name}]!`);\r\n }\r\n\r\n const configProp = this.serviceConfigHelper.findConfigPropByName(p.$.Name);\r\n const name = this.namingHelper.getModelPropName(configProp?.mappedName || p.$.Name);\r\n const isCollection = !!p.$.Type.match(/^Collection\\(/);\r\n let dataType = p.$.Type.replace(/^Collection\\(([^\\)]+)\\)/, \"$1\");\r\n if (this.namingHelper.includesServicePrefix(dataType)) {\r\n const dtName = this.namingHelper.stripServicePrefix(dataType);\r\n if (this.dataModel.getPrimitiveType(dtName) !== undefined) {\r\n dataType = this.dataModel.getPrimitiveType(dtName)!;\r\n }\r\n }\r\n\r\n let result: Pick<PropertyModel, \"dataType\" | \"type\" | \"typeModule\" | \"qPath\" | \"qParam\" | \"qObject\" | \"converters\">;\r\n\r\n // domain object known from service:\r\n // EntityType, ComplexType, EnumType or TypeDefinition\r\n if (this.namingHelper.includesServicePrefix(dataType)) {\r\n const resultDt = this.model2Type.get(dataType);\r\n if (!resultDt) {\r\n throw new Error(`Couldn't determine model type for data type with name '${dataType}'`);\r\n }\r\n\r\n // special handling for enums\r\n if (resultDt === DataTypes.EnumType) {\r\n result = {\r\n dataType: resultDt,\r\n type: this.namingHelper.getEnumName(dataType),\r\n qPath: \"QEnumPath\",\r\n qObject: isCollection ? \"QEnumCollection\" : undefined,\r\n qParam: \"QEnumParam\",\r\n };\r\n }\r\n // handling of complex & entity types\r\n else {\r\n result = {\r\n dataType: resultDt,\r\n type: this.namingHelper.getModelName(dataType),\r\n qPath: \"QEntityPath\",\r\n qObject: this.namingHelper.getQName(dataType),\r\n qParam: \"QComplexParam\",\r\n };\r\n }\r\n }\r\n // OData built-in data types\r\n else if (dataType.startsWith(Digester.EDM_PREFIX)) {\r\n const { outputType, qPath, qParam, qCollection } = this.mapODataType(dataType);\r\n const { to, toModule: typeModule, converters } = this.dataModel.getConverter(dataType) || {};\r\n\r\n const type = !to ? outputType : to.startsWith(Digester.EDM_PREFIX) ? this.mapODataType(to).outputType : to;\r\n\r\n result = {\r\n dataType: DataTypes.PrimitiveType,\r\n type,\r\n typeModule,\r\n qPath,\r\n qParam,\r\n qObject: isCollection ? qCollection : undefined,\r\n converters,\r\n };\r\n } else {\r\n throw new Error(\r\n `Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`\r\n );\r\n }\r\n\r\n return {\r\n odataName: p.$.Name,\r\n name,\r\n odataType: p.$.Type,\r\n required: p.$.Nullable === \"false\",\r\n isCollection: isCollection,\r\n managed: configProp?.managed,\r\n ...result,\r\n };\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"DataModelDigestion.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestion.ts"],"names":[],"mappings":";;;;AAIA,2CAAwC;AAMxC,+DAA4D;AAS5D,MAAsB,QAAQ;IAS5B,YACY,OAAqB,EACrB,OAAiB,EACjB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AAC,CAAC;gBACpE,YAAY,GAAG,SAAS,CAAC,WAAW,CAAC;gBACrC,aAAa,GAAG,SAAS,CAAC,eAAe,CAAC;aAC3C;YACD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;QACpD,CAAC,EACD,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAA0D,CAC1E,CAAC;IACJ,CAAC;;AA3SH,4BA4XC;AA3XkB,mBAAU,GAAG,MAAM,AAAT,CAAU;AACpB,uBAAc,GAAG,GAAG,AAAN,CAAO","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\r\n\r\nimport { DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { PropertyGenerationOptions } from \"../OptionModel\";\r\nimport { DataModel } from \"./DataModel\";\r\nimport { ComplexType as ComplexModelType, DataTypes, ModelType, ODataVersion, PropertyModel } from \"./DataTypeModel\";\r\nimport { ComplexType, EntityType, Property, Schema, TypeDefinition } from \"./edmx/ODataEdmxModelBase\";\r\nimport { SchemaV3 } from \"./edmx/ODataEdmxModelV3\";\r\nimport { SchemaV4 } from \"./edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./NamingHelper\";\r\nimport { ServiceConfigHelper } from \"./ServiceConfigHelper\";\r\n\r\nexport interface TypeModel {\r\n outputType: string;\r\n qPath: string;\r\n qCollection: string;\r\n qParam: string | undefined;\r\n}\r\n\r\nexport abstract class Digester<S extends Schema<ET, CT>, ET extends EntityType, CT extends ComplexType> {\r\n protected static EDM_PREFIX = \"Edm.\";\r\n protected static ROOT_OPERATION = \"/\";\r\n\r\n protected readonly dataModel: DataModel;\r\n protected readonly serviceConfigHelper: ServiceConfigHelper;\r\n\r\n private model2Type: Map<string, DataTypes> = new Map<string, DataTypes>();\r\n\r\n protected constructor(\r\n protected version: ODataVersion,\r\n protected schemas: Array<S>,\r\n protected options: DigestionOptions,\r\n protected namingHelper: NamingHelper,\r\n converters?: MappedConverterChains\r\n ) {\r\n this.dataModel = new DataModel(version, converters);\r\n this.serviceConfigHelper = new ServiceConfigHelper(options);\r\n\r\n this.collectModelTypes(schemas);\r\n }\r\n\r\n protected abstract getNavigationProps(entityType: ET | ComplexType): Array<Property>;\r\n\r\n protected abstract digestOperations(schema: SchemaV3 | SchemaV4): void;\r\n\r\n protected abstract digestEntityContainer(schema: SchemaV3 | SchemaV4): void;\r\n\r\n /**\r\n * Get essential infos about a given odata type from the version specific service variants.\r\n *\r\n * @param type\r\n * @return tuple of return type, query object, query collection object\r\n */\r\n protected abstract mapODataType(type: string): TypeModel;\r\n\r\n public async digest(): Promise<DataModel> {\r\n this.digestEntityTypesAndOperations();\r\n\r\n // delegate to version specific entity container digestion\r\n this.schemas.forEach((schema) => this.digestEntityContainer(schema));\r\n\r\n return this.dataModel;\r\n }\r\n\r\n private collectModelTypes(schemas: Array<S>) {\r\n schemas.forEach((schema) => {\r\n const servicePrefix = schema.$.Namespace + \".\";\r\n\r\n schema.EnumType?.forEach((et) => {\r\n this.model2Type.set(servicePrefix + et.$.Name, DataTypes.EnumType);\r\n });\r\n schema.ComplexType?.forEach((ct) => {\r\n this.model2Type.set(servicePrefix + ct.$.Name, DataTypes.ComplexType);\r\n });\r\n schema.EntityType?.forEach((et) => {\r\n this.model2Type.set(servicePrefix + et.$.Name, DataTypes.ModelType);\r\n });\r\n });\r\n }\r\n\r\n private digestEntityTypesAndOperations() {\r\n this.schemas.forEach((schema) => {\r\n // type definitions: alias for primitive types\r\n this.addTypeDefinition(schema.TypeDefinition);\r\n\r\n // enums\r\n if (schema.EnumType) {\r\n for (const et of schema.EnumType) {\r\n const name = et.$.Name;\r\n this.dataModel.addEnum(name, {\r\n odataName: name,\r\n name: this.namingHelper.getEnumName(name),\r\n members: et.Member.map((m) => m.$.Name),\r\n });\r\n }\r\n }\r\n\r\n // entity types\r\n this.addEntityType(schema.EntityType);\r\n // complex types\r\n this.addComplexType(schema.ComplexType);\r\n\r\n // V4 only: function & action types\r\n this.digestOperations(schema);\r\n });\r\n\r\n this.postProcessModel();\r\n }\r\n\r\n private getBaseModel(model: ComplexType) {\r\n const entityConfig = this.serviceConfigHelper.findConfigEntityByName(model.$.Name);\r\n const entityName = entityConfig?.mappedName || model.$.Name;\r\n\r\n const name = this.namingHelper.getModelName(entityName);\r\n const qName = this.namingHelper.getQName(entityName);\r\n const editableName = this.namingHelper.getEditableModelName(entityName);\r\n const odataName = model.$.Name;\r\n const bType = model.$.BaseType;\r\n const props = [...(model.Property ?? []), ...this.getNavigationProps(model)];\r\n\r\n // support for base types, i.e. extends clause of interfaces\r\n const baseClasses = [];\r\n if (bType) {\r\n baseClasses.push(this.namingHelper.getModelName(bType));\r\n }\r\n\r\n return {\r\n name,\r\n qName,\r\n odataName,\r\n editableName,\r\n baseClasses,\r\n props: props.map((p) => {\r\n const epConfig = entityConfig?.properties?.find((ep) => ep.name === p.$.Name);\r\n return this.mapProp(p, epConfig);\r\n }),\r\n baseProps: [], // postprocess required\r\n };\r\n }\r\n\r\n private addTypeDefinition(types: Array<TypeDefinition> | undefined) {\r\n if (!types || !types.length) {\r\n return;\r\n }\r\n\r\n for (const t of types) {\r\n this.dataModel.addTypeDefinition(t.$.Name, t.$.UnderlyingType);\r\n }\r\n }\r\n\r\n private addComplexType(models: Array<ComplexType> | undefined) {\r\n if (!models || !models.length) {\r\n return;\r\n }\r\n\r\n for (const model of models) {\r\n const baseModel = this.getBaseModel(model);\r\n this.dataModel.addComplexType(baseModel.name, baseModel);\r\n }\r\n }\r\n\r\n private addEntityType(models: Array<ET> | undefined) {\r\n if (!models || !models.length) {\r\n return;\r\n }\r\n\r\n for (const model of models) {\r\n const baseModel = this.getBaseModel(model);\r\n const entityConfig = this.serviceConfigHelper.findConfigEntityByName(model.$.Name);\r\n const entityName = entityConfig?.mappedName || model.$.Name;\r\n\r\n // key support: we add keys from this entity,\r\n // but not keys stemming from base classes (postprocess required)\r\n const keyNames: Array<string> = [];\r\n if (entityConfig?.keys?.length) {\r\n keyNames.push(...entityConfig.keys);\r\n } else {\r\n const entity = model as EntityType;\r\n if (entity.Key && entity.Key.length && entity.Key[0].PropertyRef.length) {\r\n const propNames = entity.Key[0].PropertyRef.map((key) => key.$.Name);\r\n keyNames.push(...propNames);\r\n }\r\n }\r\n\r\n this.dataModel.addModel(baseModel.name, {\r\n ...baseModel,\r\n idModelName: this.namingHelper.getIdModelName(entityName),\r\n qIdFunctionName: this.namingHelper.getQIdFunctionName(entityName),\r\n generateId: true,\r\n keyNames: keyNames, // postprocess required to include key specs from base classes\r\n keys: [], // postprocess required to include props from base classes\r\n getKeyUnion: () => keyNames.join(\" | \"),\r\n });\r\n }\r\n }\r\n\r\n private postProcessModel() {\r\n // complex types\r\n const complexTypes = this.dataModel.getComplexTypes();\r\n complexTypes.forEach((model) => {\r\n const [baseProps] = this.collectBaseClassPropsAndKeys(model, []);\r\n model.baseProps = baseProps;\r\n });\r\n const modelTypes = this.dataModel.getModels();\r\n // entity types\r\n modelTypes.forEach((model) => {\r\n const [baseProps, baseKeys, idName, qIdName] = this.collectBaseClassPropsAndKeys(model, []);\r\n model.baseProps = baseProps;\r\n\r\n if (!model.keyNames.length && idName) {\r\n model.idModelName = idName;\r\n model.qIdFunctionName = qIdName;\r\n model.generateId = false;\r\n }\r\n model.keyNames.unshift(...baseKeys);\r\n\r\n // sanity check: entity types require key specification\r\n if (!model.keyNames.length) {\r\n throw new Error(`Key property is missing from Entity \"${model.name}\" (${model.odataName})!`);\r\n }\r\n\r\n const isSingleKey = model.keyNames.length === 1;\r\n const props = [...model.baseProps, ...model.props];\r\n model.keys = model.keyNames.map((keyName) => {\r\n const prop = props.find((p) => p.odataName === keyName);\r\n if (!prop) {\r\n throw new Error(`Key with name [${keyName}] not found in props!`);\r\n }\r\n // automatically set key prop to managed, if this is the only key of the given entity\r\n if (prop.managed === undefined) {\r\n prop.managed = !this.options.disableAutoManagedKey && isSingleKey;\r\n }\r\n return prop;\r\n });\r\n });\r\n\r\n const sortedModelTypes = this.sortModelsByInheritance<ModelType>(modelTypes);\r\n this.dataModel.setModels(sortedModelTypes);\r\n\r\n const sortedComplexTypes = this.sortModelsByInheritance<ComplexModelType>(complexTypes);\r\n this.dataModel.setComplexTypes(sortedComplexTypes);\r\n }\r\n\r\n private sortModelsByInheritance<Type extends ComplexModelType>(models: Type[]): { [name: string]: Type } {\r\n // recursively visit all models and sort them by inheritance such that base classes\r\n // are always before derived classes\r\n const sortedModels: { [name: string]: Type } = {};\r\n const visitedModels = new Set<Type>();\r\n const inProgressModels = new Set<Type>();\r\n\r\n function visit(model: Type) {\r\n if (inProgressModels.has(model)) {\r\n throw new Error(\"Cyclic dependencies detected!\");\r\n }\r\n\r\n if (!visitedModels.has(model)) {\r\n inProgressModels.add(model);\r\n\r\n for (const baseClassName of model.baseClasses) {\r\n const baseClass = models.find((e) => e.name === baseClassName);\r\n if (baseClass) {\r\n visit(baseClass);\r\n }\r\n }\r\n visitedModels.add(model);\r\n inProgressModels.delete(model);\r\n sortedModels[model.name] = model;\r\n }\r\n }\r\n\r\n for (const model of models) {\r\n visit(model);\r\n }\r\n return sortedModels;\r\n }\r\n\r\n private collectBaseClassPropsAndKeys(\r\n model: ComplexModelType,\r\n visitedModels: string[]\r\n ): [Array<PropertyModel>, Array<string>, string, string] {\r\n if (visitedModels.includes(model.name)) {\r\n throw new Error(`Cyclic inheritance detected for model ${model.name}!`);\r\n }\r\n visitedModels.push(model.name);\r\n return model.baseClasses.reduce(\r\n ([props, keys, idName, qIdName], bc) => {\r\n const baseModel = this.dataModel.getModel(bc) || this.dataModel.getComplexType(bc);\r\n if (!baseModel) {\r\n throw new Error(`BaseModel \"${bc}\" doesn't exist!`);\r\n }\r\n\r\n let idNameResult = idName;\r\n let qIdNameResult = qIdName;\r\n\r\n // recursive\r\n if (baseModel.baseClasses.length) {\r\n const [parentProps, parentKeys, parentIdName, parentQIdName] = this.collectBaseClassPropsAndKeys(\r\n baseModel,\r\n visitedModels\r\n );\r\n props.unshift(...parentProps);\r\n keys.unshift(...parentKeys);\r\n if (parentIdName) {\r\n idNameResult = parentIdName;\r\n qIdNameResult = parentQIdName;\r\n }\r\n }\r\n\r\n props.push(...baseModel.props);\r\n if (baseModel.keyNames?.length) {\r\n keys.push(...baseModel.keyNames.filter((kn) => !keys.includes(kn)));\r\n idNameResult = baseModel.idModelName;\r\n qIdNameResult = baseModel.qIdFunctionName;\r\n }\r\n return [props, keys, idNameResult, qIdNameResult];\r\n },\r\n [[], [], \"\", \"\"] as [Array<PropertyModel>, Array<string>, string, string]\r\n );\r\n }\r\n\r\n protected mapProp = (p: Property, entityPropConfig?: PropertyGenerationOptions | undefined): PropertyModel => {\r\n if (!p.$.Type) {\r\n throw new Error(`No type information given for property [${p.$.Name}]!`);\r\n }\r\n\r\n const configProp = this.serviceConfigHelper.findConfigPropByName(p.$.Name);\r\n const name = this.namingHelper.getModelPropName(entityPropConfig?.mappedName || configProp?.mappedName || p.$.Name);\r\n const isCollection = !!p.$.Type.match(/^Collection\\(/);\r\n let dataType = p.$.Type.replace(/^Collection\\(([^\\)]+)\\)/, \"$1\");\r\n if (this.namingHelper.includesServicePrefix(dataType)) {\r\n const dtName = this.namingHelper.stripServicePrefix(dataType);\r\n if (this.dataModel.getPrimitiveType(dtName) !== undefined) {\r\n dataType = this.dataModel.getPrimitiveType(dtName)!;\r\n }\r\n }\r\n\r\n let result: Pick<PropertyModel, \"dataType\" | \"type\" | \"typeModule\" | \"qPath\" | \"qParam\" | \"qObject\" | \"converters\">;\r\n\r\n // domain object known from service:\r\n // EntityType, ComplexType, EnumType\r\n if (this.namingHelper.includesServicePrefix(dataType)) {\r\n const resultDt = this.model2Type.get(dataType);\r\n if (!resultDt) {\r\n throw new Error(`Couldn't determine model type for data type with name '${dataType}'`);\r\n }\r\n\r\n // special handling for enums\r\n if (resultDt === DataTypes.EnumType) {\r\n result = {\r\n dataType: resultDt,\r\n type: this.namingHelper.getEnumName(dataType),\r\n qPath: \"QEnumPath\",\r\n qObject: isCollection ? \"QEnumCollection\" : undefined,\r\n qParam: \"QEnumParam\",\r\n };\r\n }\r\n // handling of complex & entity types\r\n else {\r\n result = {\r\n dataType: resultDt,\r\n type: this.namingHelper.getModelName(dataType),\r\n qPath: \"QEntityPath\",\r\n qObject: this.namingHelper.getQName(dataType),\r\n qParam: \"QComplexParam\",\r\n };\r\n }\r\n }\r\n // OData built-in data types\r\n else if (dataType.startsWith(Digester.EDM_PREFIX)) {\r\n const { outputType, qPath, qParam, qCollection } = this.mapODataType(dataType);\r\n const { to, toModule: typeModule, converters } = this.dataModel.getConverter(dataType) || {};\r\n\r\n const type = !to ? outputType : to.startsWith(Digester.EDM_PREFIX) ? this.mapODataType(to).outputType : to;\r\n\r\n result = {\r\n dataType: DataTypes.PrimitiveType,\r\n type,\r\n typeModule,\r\n qPath,\r\n qParam,\r\n qObject: isCollection ? qCollection : undefined,\r\n converters,\r\n };\r\n } else {\r\n throw new Error(\r\n `Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`\r\n );\r\n }\r\n\r\n return {\r\n odataName: p.$.Name,\r\n name,\r\n odataType: p.$.Type,\r\n required: p.$.Nullable === \"false\",\r\n isCollection: isCollection,\r\n managed: typeof entityPropConfig?.managed !== \"undefined\" ? entityPropConfig.managed : configProp?.managed,\r\n ...result,\r\n };\r\n };\r\n}\r\n"]}
|
|
@@ -66,7 +66,7 @@ class DigesterV3 extends DataModelDigestion_1.Digester {
|
|
|
66
66
|
var _a, _b, _c, _d;
|
|
67
67
|
const name = this.namingHelper.getFunctionName(funcImport.$.Name);
|
|
68
68
|
const usePost = ((_a = funcImport.$["m:HttpMethod"]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === "POST";
|
|
69
|
-
const parameters = (_c = (_b = funcImport.Parameter) === null || _b === void 0 ? void 0 : _b.map(this.mapProp)) !== null && _c !== void 0 ? _c : [];
|
|
69
|
+
const parameters = (_c = (_b = funcImport.Parameter) === null || _b === void 0 ? void 0 : _b.map((p) => this.mapProp(p))) !== null && _c !== void 0 ? _c : [];
|
|
70
70
|
// TODO: the spec allows for multiple ReturnType elements
|
|
71
71
|
// https://docs.microsoft.com/en-us/openspecs/windows_protocols/mc-csdl/f510f36a-36bf-47f4-ac41-4a0ff921fbfa
|
|
72
72
|
// totally unclear how the response object would look like
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataModelDigestionV2.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestionV2.ts"],"names":[],"mappings":";;;;AAAA,mEAAoF;AACpF,qDAAmE;AAGnE,6DAA2D;AAC3D,mDAA6F;AAK7F;;;;;;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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KAAK,yBAAY,CAAC,MAAM;gBACtB,OAAO;oBACL,UAAU,EAAE,QAAQ;oBACpB,KAAK,EAAE,eAAe;oBACtB,WAAW,EAAE,qBAAqB;oBAClC,MAAM,EAAE,cAAc;iBACvB,CAAC;YACJ,KAAK,yBAAY,CAAC,QAAQ;gBACxB,OAAO;oBACL,UAAU,EAAE,QAAQ;oBACpB,KAAK,EAAE,iBAAiB;oBACxB,WAAW,EAAE,uBAAuB;oBACpC,MAAM,EAAE,kBAAkB;iBAC3B,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,KAAK,yBAAY,CAAC,cAAc;gBAC9B,OAAO;oBACL,UAAU,EAAE,QAAQ;oBACpB,KAAK,EAAE,uBAAuB;oBAC9B,WAAW,EAAE,6BAA6B;oBAC1C,MAAM,EAAE,wBAAwB;iBACjC,CAAC;YACJ,KAAK,yBAAY,CAAC,MAAM;gBACtB,OAAO;oBACL,UAAU,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\";\r\nimport { ODataTypesV2, ODataVersions } from \"@odata2ts/odata-core\";\r\n\r\nimport { DigesterFunction, DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { Digester, TypeModel } from \"./DataModelDigestion\";\r\nimport { ODataVersion, OperationType, 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 schema\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 if (schema.EntityContainer && schema.EntityContainer.length) {\r\n const container = schema.EntityContainer[0];\r\n\r\n container.FunctionImport?.forEach((funcImport) => {\r\n const name = this.namingHelper.getFunctionName(funcImport.$.Name);\r\n const usePost = funcImport.$[\"m:HttpMethod\"]?.toUpperCase() === \"POST\";\r\n const parameters = funcImport.Parameter?.map(this.mapProp) ?? [];\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 const operation: OperationType = {\r\n name,\r\n odataName: funcImport.$.Name,\r\n paramsModelName: this.namingHelper.getOperationParamsModelName(funcImport.$.Name),\r\n qName: this.namingHelper.getQFunctionName(funcImport.$.Name),\r\n type: OperationTypes.Function,\r\n parameters,\r\n returnType,\r\n usePost,\r\n };\r\n this.dataModel.addOperationType(\"/\", operation);\r\n\r\n this.dataModel.addFunction(name, {\r\n name,\r\n odataName: funcImport.$.Name,\r\n // TODO: does this really match V4 model?!\r\n entitySet: funcImport.$.EntitySet!,\r\n operation: operation,\r\n });\r\n });\r\n\r\n container.EntitySet?.forEach((entitySet) => {\r\n const name = entitySet.$.Name;\r\n\r\n this.dataModel.addEntitySet(name, {\r\n name,\r\n odataName: entitySet.$.Name,\r\n entityType: this.dataModel.getModel(this.namingHelper.getModelName(entitySet.$.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
|
+
{"version":3,"file":"DataModelDigestionV2.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestionV2.ts"],"names":[],"mappings":";;;;AAAA,mEAAoF;AACpF,qDAAmE;AAGnE,6DAA2D;AAC3D,mDAA6F;AAK7F;;;;;;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,CAA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,cAAc;gBAC9B,OAAO;oBACL,UAAU,EAAE,QAAQ;oBACpB,KAAK,EAAE,uBAAuB;oBAC9B,WAAW,EAAE,6BAA6B;oBAC1C,MAAM,EAAE,wBAAwB;iBACjC,CAAC;YACJ,KAAK,yBAAY,CAAC,MAAM;gBACtB,OAAO;oBACL,UAAU,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\";\r\nimport { ODataTypesV2, ODataVersions } from \"@odata2ts/odata-core\";\r\n\r\nimport { DigesterFunction, DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { Digester, TypeModel } from \"./DataModelDigestion\";\r\nimport { ODataVersion, OperationType, 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 schema\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 if (schema.EntityContainer && schema.EntityContainer.length) {\r\n const container = schema.EntityContainer[0];\r\n\r\n container.FunctionImport?.forEach((funcImport) => {\r\n const name = this.namingHelper.getFunctionName(funcImport.$.Name);\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 const operation: OperationType = {\r\n name,\r\n odataName: funcImport.$.Name,\r\n paramsModelName: this.namingHelper.getOperationParamsModelName(funcImport.$.Name),\r\n qName: this.namingHelper.getQFunctionName(funcImport.$.Name),\r\n type: OperationTypes.Function,\r\n parameters,\r\n returnType,\r\n usePost,\r\n };\r\n this.dataModel.addOperationType(\"/\", operation);\r\n\r\n this.dataModel.addFunction(name, {\r\n name,\r\n odataName: funcImport.$.Name,\r\n // TODO: does this really match V4 model?!\r\n entitySet: funcImport.$.EntitySet!,\r\n operation: operation,\r\n });\r\n });\r\n\r\n container.EntitySet?.forEach((entitySet) => {\r\n const name = entitySet.$.Name;\r\n\r\n this.dataModel.addEntitySet(name, {\r\n name,\r\n odataName: entitySet.$.Name,\r\n entityType: this.dataModel.getModel(this.namingHelper.getModelName(entitySet.$.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"]}
|
|
@@ -21,8 +21,8 @@ class DigesterV4 extends DataModelDigestion_1.Digester {
|
|
|
21
21
|
}
|
|
22
22
|
digestOperations(schema) {
|
|
23
23
|
// functions & actions
|
|
24
|
-
this.addOperations(schema.Function, "Function" /* OperationTypes.Function */);
|
|
25
|
-
this.addOperations(schema.Action, "Action" /* OperationTypes.Action */);
|
|
24
|
+
this.addOperations(schema.$.Namespace, schema.Function, "Function" /* OperationTypes.Function */);
|
|
25
|
+
this.addOperations(schema.$.Namespace, schema.Action, "Action" /* OperationTypes.Action */);
|
|
26
26
|
}
|
|
27
27
|
digestEntityContainer(schema) {
|
|
28
28
|
var _a, _b, _c, _d;
|
|
@@ -149,13 +149,13 @@ class DigesterV4 extends DataModelDigestion_1.Digester {
|
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
-
addOperations(operations, type) {
|
|
152
|
+
addOperations(namespace, operations, type) {
|
|
153
153
|
if (!operations || !operations.length) {
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
156
|
operations.forEach((op) => {
|
|
157
157
|
var _a, _b, _c;
|
|
158
|
-
const params = (_b = (_a = op.Parameter) === null || _a === void 0 ? void 0 : _a.map(this.mapProp)) !== null && _b !== void 0 ? _b : [];
|
|
158
|
+
const params = (_b = (_a = op.Parameter) === null || _a === void 0 ? void 0 : _a.map((p) => this.mapProp(p))) !== null && _b !== void 0 ? _b : [];
|
|
159
159
|
const returnType = (_c = op.ReturnType) === null || _c === void 0 ? void 0 : _c.map((rt) => {
|
|
160
160
|
return this.mapProp(Object.assign(Object.assign({}, rt), { $: Object.assign({ Name: "NO_NAME_BECAUSE_RETURN_TYPE" }, rt.$) }));
|
|
161
161
|
})[0];
|
|
@@ -176,7 +176,7 @@ class DigesterV4 extends DataModelDigestion_1.Digester {
|
|
|
176
176
|
? this.namingHelper.getQFunctionName(op.$.Name, bindingProp)
|
|
177
177
|
: this.namingHelper.getQActionName(op.$.Name, bindingProp);
|
|
178
178
|
this.dataModel.addOperationType(binding, {
|
|
179
|
-
odataName: op.$.Name,
|
|
179
|
+
odataName: isBound ? `${namespace}.${op.$.Name}` : op.$.Name,
|
|
180
180
|
name,
|
|
181
181
|
qName,
|
|
182
182
|
paramsModelName: this.namingHelper.getOperationParamsModelName(op.$.Name, bindingProp),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataModelDigestionV4.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestionV4.ts"],"names":[],"mappings":";;;;AAAA,mEAAoF;AACpF,qDAAmE;AAGnE,6DAA2D;AAC3D,mDAA6F;AAKtF,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,UAAkC;QAElC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CAAC;YACjD,MAAM,KAAK,GACT,IAAI,6CAA4B;gBAC9B,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC;gBAC5D,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;YAC/D,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE;gBACvC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI;gBACpB,IAAI;gBACJ,KAAK;gBACL,eAAe,EAAE,IAAI,CAAC,YAAY,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC;gBACtF,IAAI,EAAE,IAAI;gBACV,UAAU,EAAE,MAAM;gBAClB,UAAU,EAAE,UAAU;aACvB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,oBAAoB,CAAC,IAAY;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,yBAAyB,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QACpF,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,2CAA2C,IAAI,GAAG,CAAC,CAAC;SACrE;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { MappedConverterChains, loadConverters } from \"@odata2ts/converter-runtime\";\r\nimport { ODataTypesV4, ODataVersions } from \"@odata2ts/odata-core\";\r\n\r\nimport { DigesterFunction, DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { Digester, TypeModel } from \"./DataModelDigestion\";\r\nimport { ODataVersion, OperationType, OperationTypes, PropertyModel } from \"./DataTypeModel\";\r\nimport { ComplexType, Property } from \"./edmx/ODataEdmxModelBase\";\r\nimport { ComplexTypeV4, EntityTypeV4, Operation, SchemaV4 } from \"./edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./NamingHelper\";\r\n\r\nexport const digest: DigesterFunction<SchemaV4> = async (schemas, options, namingHelper) => {\r\n const converters = await loadConverters(ODataVersions.V2, options.converters);\r\n\r\n const digester = new DigesterV4(schemas, options, namingHelper, converters);\r\n return digester.digest();\r\n};\r\n\r\nclass DigesterV4 extends Digester<SchemaV4, EntityTypeV4, ComplexTypeV4> {\r\n constructor(\r\n schemas: Array<SchemaV4>,\r\n options: DigestionOptions,\r\n namingHelper: NamingHelper,\r\n converters?: MappedConverterChains\r\n ) {\r\n super(ODataVersion.V4, schemas, options, namingHelper, converters);\r\n }\r\n\r\n protected getNavigationProps(entityType: ComplexType | EntityTypeV4): Array<Property> {\r\n return (entityType as EntityTypeV4).NavigationProperty || [];\r\n }\r\n\r\n protected digestOperations(schema: SchemaV4) {\r\n // functions & actions\r\n this.addOperations(schema.Function, OperationTypes.Function);\r\n this.addOperations(schema.Action, OperationTypes.Action);\r\n }\r\n\r\n protected digestEntityContainer(schema: SchemaV4) {\r\n if (schema.EntityContainer && schema.EntityContainer.length) {\r\n const container = schema.EntityContainer[0];\r\n\r\n container.ActionImport?.forEach((actionImport) => {\r\n const name = this.namingHelper.getActionName(actionImport.$.Name);\r\n const operationName = this.namingHelper.getActionName(actionImport.$.Action);\r\n\r\n this.dataModel.addAction(name, {\r\n name: name,\r\n odataName: actionImport.$.Name,\r\n operation: this.getRootOperationType(operationName),\r\n });\r\n });\r\n\r\n container.FunctionImport?.forEach((funcImport) => {\r\n const name = this.namingHelper.getFunctionName(funcImport.$.Name);\r\n const operationName = this.namingHelper.getFunctionName(funcImport.$.Function);\r\n\r\n this.dataModel.addFunction(name, {\r\n name,\r\n odataName: funcImport.$.Name,\r\n operation: this.getRootOperationType(operationName),\r\n entitySet: funcImport.$.EntitySet,\r\n });\r\n });\r\n\r\n container.Singleton?.forEach((singleton) => {\r\n const name = singleton.$.Name;\r\n const navPropBindings = singleton.NavigationPropertyBinding || [];\r\n\r\n this.dataModel.addSingleton(name, {\r\n name,\r\n odataName: singleton.$.Name,\r\n entityType: this.dataModel.getModel(this.namingHelper.getModelName(singleton.$.Type)),\r\n navPropBinding: navPropBindings.map((binding) => ({\r\n path: this.namingHelper.stripServicePrefix(binding.$.Path),\r\n target: binding.$.Target,\r\n })),\r\n });\r\n });\r\n\r\n container.EntitySet?.forEach((entitySet) => {\r\n const name = entitySet.$.Name;\r\n const navPropBindings = entitySet.NavigationPropertyBinding || [];\r\n\r\n this.dataModel.addEntitySet(name, {\r\n name,\r\n odataName: entitySet.$.Name,\r\n entityType: this.dataModel.getModel(this.namingHelper.getModelName(entitySet.$.EntityType)),\r\n navPropBinding: navPropBindings.map((binding) => ({\r\n path: this.namingHelper.stripServicePrefix(binding.$.Path),\r\n target: binding.$.Target,\r\n })),\r\n });\r\n });\r\n }\r\n }\r\n\r\n protected mapODataType(type: string): TypeModel {\r\n switch (type) {\r\n case ODataTypesV4.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 ODataTypesV4.Byte:\r\n case ODataTypesV4.SByte:\r\n case ODataTypesV4.Int16:\r\n case ODataTypesV4.Int32:\r\n case ODataTypesV4.Int64:\r\n case ODataTypesV4.Single:\r\n case ODataTypesV4.Double:\r\n case ODataTypesV4.Decimal:\r\n return {\r\n outputType: \"number\",\r\n qPath: \"QNumberPath\",\r\n qCollection: \"QNumberCollection\",\r\n qParam: \"QNumberParam\",\r\n };\r\n case ODataTypesV4.String:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringPath\",\r\n qCollection: \"QStringCollection\",\r\n qParam: \"QStringParam\",\r\n };\r\n case ODataTypesV4.Date:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QDatePath\",\r\n qCollection: \"QDateCollection\",\r\n qParam: \"QDateParam\",\r\n };\r\n case ODataTypesV4.TimeOfDay:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QTimeOfDayPath\",\r\n qCollection: \"QTimeOfDayCollection\",\r\n qParam: \"QTimeOfDayParam\",\r\n };\r\n case ODataTypesV4.DateTimeOffset:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QDateTimeOffsetPath\",\r\n qCollection: \"QDateTimeOffsetCollection\",\r\n qParam: \"QDateTimeOffsetParam\",\r\n };\r\n case ODataTypesV4.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 ODataTypesV4.Guid:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QGuidPath\",\r\n qCollection: \"QGuidCollection\",\r\n qParam: \"QGuidParam\",\r\n };\r\n default:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringPath\",\r\n qCollection: \"QStringCollection\",\r\n qParam: undefined,\r\n };\r\n }\r\n }\r\n\r\n private addOperations(operations: Array<Operation> | undefined, type: OperationTypes) {\r\n if (!operations || !operations.length) {\r\n return;\r\n }\r\n\r\n operations.forEach((op) => {\r\n const params: Array<PropertyModel> = op.Parameter?.map(this.mapProp) ?? [];\r\n const returnType: PropertyModel | undefined = op.ReturnType?.map((rt) => {\r\n return this.mapProp({ ...rt, $: { Name: \"NO_NAME_BECAUSE_RETURN_TYPE\", ...rt.$ } });\r\n })[0];\r\n const isBound = op.$.IsBound === \"true\";\r\n\r\n if (isBound && !params.length) {\r\n throw new Error(`IllegalState: Operation '${op.$.Name}' is bound, but has no parameters!`);\r\n }\r\n\r\n const bindingProp = isBound ? params.shift() : undefined;\r\n const binding = bindingProp\r\n ? bindingProp.isCollection\r\n ? `Collection(${bindingProp.type})`\r\n : bindingProp.type\r\n : DigesterV4.ROOT_OPERATION;\r\n\r\n const name =\r\n type === OperationTypes.Function\r\n ? this.namingHelper.getFunctionName(op.$.Name)\r\n : this.namingHelper.getActionName(op.$.Name);\r\n const qName =\r\n type === OperationTypes.Function\r\n ? this.namingHelper.getQFunctionName(op.$.Name, bindingProp)\r\n : this.namingHelper.getQActionName(op.$.Name, bindingProp);\r\n this.dataModel.addOperationType(binding, {\r\n odataName: op.$.Name,\r\n name,\r\n qName,\r\n paramsModelName: this.namingHelper.getOperationParamsModelName(op.$.Name, bindingProp),\r\n type: type,\r\n parameters: params,\r\n returnType: returnType,\r\n });\r\n });\r\n }\r\n\r\n private getRootOperationType(name: string): OperationType {\r\n const rootOps = this.dataModel.getOperationTypeByBinding(DigesterV4.ROOT_OPERATION);\r\n const rootOp = rootOps.find((op) => op.name === name);\r\n if (!rootOp) {\r\n throw new Error(`Couldn't find root operation with name [${name}]`);\r\n }\r\n return rootOp;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"DataModelDigestionV4.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestionV4.ts"],"names":[],"mappings":";;;;AAAA,mEAAoF;AACpF,qDAAmE;AAGnE,6DAA2D;AAC3D,mDAA6F;AAKtF,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,UAAkC;QAElC,KAAK,CAAC,4BAAY,CAAC,EAAE,EAAE,OA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converter-runtime\";\r\nimport { ODataTypesV4, ODataVersions } from \"@odata2ts/odata-core\";\r\n\r\nimport { DigesterFunction, DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { Digester, TypeModel } from \"./DataModelDigestion\";\r\nimport { ODataVersion, OperationType, OperationTypes, PropertyModel } from \"./DataTypeModel\";\r\nimport { ComplexType, Property } from \"./edmx/ODataEdmxModelBase\";\r\nimport { ComplexTypeV4, EntityTypeV4, Operation, SchemaV4 } from \"./edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./NamingHelper\";\r\n\r\nexport const digest: DigesterFunction<SchemaV4> = async (schemas, options, namingHelper) => {\r\n const converters = await loadConverters(ODataVersions.V2, options.converters);\r\n\r\n const digester = new DigesterV4(schemas, options, namingHelper, converters);\r\n return digester.digest();\r\n};\r\n\r\nclass DigesterV4 extends Digester<SchemaV4, EntityTypeV4, ComplexTypeV4> {\r\n constructor(\r\n schemas: Array<SchemaV4>,\r\n options: DigestionOptions,\r\n namingHelper: NamingHelper,\r\n converters?: MappedConverterChains\r\n ) {\r\n super(ODataVersion.V4, schemas, options, namingHelper, converters);\r\n }\r\n\r\n protected getNavigationProps(entityType: ComplexType | EntityTypeV4): Array<Property> {\r\n return (entityType as EntityTypeV4).NavigationProperty || [];\r\n }\r\n\r\n protected digestOperations(schema: SchemaV4) {\r\n // functions & actions\r\n this.addOperations(schema.$.Namespace, schema.Function, OperationTypes.Function);\r\n this.addOperations(schema.$.Namespace, schema.Action, OperationTypes.Action);\r\n }\r\n\r\n protected digestEntityContainer(schema: SchemaV4) {\r\n if (schema.EntityContainer && schema.EntityContainer.length) {\r\n const container = schema.EntityContainer[0];\r\n\r\n container.ActionImport?.forEach((actionImport) => {\r\n const name = this.namingHelper.getActionName(actionImport.$.Name);\r\n const operationName = this.namingHelper.getActionName(actionImport.$.Action);\r\n\r\n this.dataModel.addAction(name, {\r\n name: name,\r\n odataName: actionImport.$.Name,\r\n operation: this.getRootOperationType(operationName),\r\n });\r\n });\r\n\r\n container.FunctionImport?.forEach((funcImport) => {\r\n const name = this.namingHelper.getFunctionName(funcImport.$.Name);\r\n const operationName = this.namingHelper.getFunctionName(funcImport.$.Function);\r\n\r\n this.dataModel.addFunction(name, {\r\n name,\r\n odataName: funcImport.$.Name,\r\n operation: this.getRootOperationType(operationName),\r\n entitySet: funcImport.$.EntitySet,\r\n });\r\n });\r\n\r\n container.Singleton?.forEach((singleton) => {\r\n const name = singleton.$.Name;\r\n const navPropBindings = singleton.NavigationPropertyBinding || [];\r\n\r\n this.dataModel.addSingleton(name, {\r\n name,\r\n odataName: singleton.$.Name,\r\n entityType: this.dataModel.getModel(this.namingHelper.getModelName(singleton.$.Type)),\r\n navPropBinding: navPropBindings.map((binding) => ({\r\n path: this.namingHelper.stripServicePrefix(binding.$.Path),\r\n target: binding.$.Target,\r\n })),\r\n });\r\n });\r\n\r\n container.EntitySet?.forEach((entitySet) => {\r\n const name = entitySet.$.Name;\r\n const navPropBindings = entitySet.NavigationPropertyBinding || [];\r\n\r\n this.dataModel.addEntitySet(name, {\r\n name,\r\n odataName: entitySet.$.Name,\r\n entityType: this.dataModel.getModel(this.namingHelper.getModelName(entitySet.$.EntityType)),\r\n navPropBinding: navPropBindings.map((binding) => ({\r\n path: this.namingHelper.stripServicePrefix(binding.$.Path),\r\n target: binding.$.Target,\r\n })),\r\n });\r\n });\r\n }\r\n }\r\n\r\n protected mapODataType(type: string): TypeModel {\r\n switch (type) {\r\n case ODataTypesV4.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 ODataTypesV4.Byte:\r\n case ODataTypesV4.SByte:\r\n case ODataTypesV4.Int16:\r\n case ODataTypesV4.Int32:\r\n case ODataTypesV4.Int64:\r\n case ODataTypesV4.Single:\r\n case ODataTypesV4.Double:\r\n case ODataTypesV4.Decimal:\r\n return {\r\n outputType: \"number\",\r\n qPath: \"QNumberPath\",\r\n qCollection: \"QNumberCollection\",\r\n qParam: \"QNumberParam\",\r\n };\r\n case ODataTypesV4.String:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringPath\",\r\n qCollection: \"QStringCollection\",\r\n qParam: \"QStringParam\",\r\n };\r\n case ODataTypesV4.Date:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QDatePath\",\r\n qCollection: \"QDateCollection\",\r\n qParam: \"QDateParam\",\r\n };\r\n case ODataTypesV4.TimeOfDay:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QTimeOfDayPath\",\r\n qCollection: \"QTimeOfDayCollection\",\r\n qParam: \"QTimeOfDayParam\",\r\n };\r\n case ODataTypesV4.DateTimeOffset:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QDateTimeOffsetPath\",\r\n qCollection: \"QDateTimeOffsetCollection\",\r\n qParam: \"QDateTimeOffsetParam\",\r\n };\r\n case ODataTypesV4.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 ODataTypesV4.Guid:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QGuidPath\",\r\n qCollection: \"QGuidCollection\",\r\n qParam: \"QGuidParam\",\r\n };\r\n default:\r\n return {\r\n outputType: \"string\",\r\n qPath: \"QStringPath\",\r\n qCollection: \"QStringCollection\",\r\n qParam: undefined,\r\n };\r\n }\r\n }\r\n\r\n private addOperations(namespace: string, operations: Array<Operation> | undefined, type: OperationTypes) {\r\n if (!operations || !operations.length) {\r\n return;\r\n }\r\n\r\n operations.forEach((op) => {\r\n const params: Array<PropertyModel> = op.Parameter?.map((p) => this.mapProp(p)) ?? [];\r\n const returnType: PropertyModel | undefined = op.ReturnType?.map((rt) => {\r\n return this.mapProp({ ...rt, $: { Name: \"NO_NAME_BECAUSE_RETURN_TYPE\", ...rt.$ } });\r\n })[0];\r\n const isBound = op.$.IsBound === \"true\";\r\n\r\n if (isBound && !params.length) {\r\n throw new Error(`IllegalState: Operation '${op.$.Name}' is bound, but has no parameters!`);\r\n }\r\n\r\n const bindingProp = isBound ? params.shift() : undefined;\r\n const binding = bindingProp\r\n ? bindingProp.isCollection\r\n ? `Collection(${bindingProp.type})`\r\n : bindingProp.type\r\n : DigesterV4.ROOT_OPERATION;\r\n\r\n const name =\r\n type === OperationTypes.Function\r\n ? this.namingHelper.getFunctionName(op.$.Name)\r\n : this.namingHelper.getActionName(op.$.Name);\r\n const qName =\r\n type === OperationTypes.Function\r\n ? this.namingHelper.getQFunctionName(op.$.Name, bindingProp)\r\n : this.namingHelper.getQActionName(op.$.Name, bindingProp);\r\n this.dataModel.addOperationType(binding, {\r\n odataName: isBound ? `${namespace}.${op.$.Name}` : op.$.Name,\r\n name,\r\n qName,\r\n paramsModelName: this.namingHelper.getOperationParamsModelName(op.$.Name, bindingProp),\r\n type: type,\r\n parameters: params,\r\n returnType: returnType,\r\n });\r\n });\r\n }\r\n\r\n private getRootOperationType(name: string): OperationType {\r\n const rootOps = this.dataModel.getOperationTypeByBinding(DigesterV4.ROOT_OPERATION);\r\n const rootOp = rootOps.find((op) => op.name === name);\r\n if (!rootOp) {\r\n throw new Error(`Couldn't find root operation with name [${name}]`);\r\n }\r\n return rootOp;\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":";;;;AAeA,MAAa,eAAe;IAuB1B,YAAY,SAAuB;QAtB3B,YAAO,GAEX;YACF,IAAI,EAAE,EAAE,UAAU,EAAE,sBAAsB,EAAE,UAAU,EAAE,KAAK,EAAE;YAC/D,QAAQ,EAAE,EAAE,UAAU,EAAE,+BAA+B,EAAE,UAAU,EAAE,KAAK,EAAE;YAC5E,SAAS,EAAE,EAAE,UAAU,EAAE,2BAA2B,EAAE,UAAU,EAAE,KAAK,EAAE;YACzE,OAAO,EAAE,EA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,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE;gBACnD,OAAO;oBACL,YAAY,EAAE,CAAC,GAAG,MAAM,CAAC;oBACzB,eAAe,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,GAAG;iBAC7B,CAAC;YAClC,CAAC,CAAC;SACH,CAAC;IACJ,CAAC;CACF;AAnGD,0CAmGC","sourcesContent":["import { ImportDeclarationStructure } from \"ts-morph\";\n\nimport { ProjectFiles } from \"../data-model/DataModel\";\n\ntype ImportContainerType = {\n core: Set<string>;\n qobjects: Set<string>;\n clientApi: Set<string>;\n service: Set<string>;\n genModel: Set<string>;\n genQObjects: Set<string>;\n genServices: { [key: string]: Set<string> };\n customTypes: Map<string, Set<string>>;\n};\n\nexport class ImportContainer {\n private mapping: {\n [K in keyof ImportContainerType as string]: { moduleName: string; isRelative: boolean; addName?: boolean };\n } = {\n core: { moduleName: \"@odata2ts/odata-core\", isRelative: false },\n qobjects: { moduleName: \"@odata2ts/odata-query-objects\", isRelative: false },\n clientApi: { moduleName: \"@odata2ts/http-client-api\", isRelative: false },\n service: { moduleName: \"@odata2ts/odata-service\", isRelative: false },\n genModel: { moduleName: \"\", isRelative: true },\n genQObjects: { moduleName: \"\", isRelative: true },\n };\n\n private container: ImportContainerType = {\n core: new Set(),\n qobjects: new Set(),\n clientApi: new Set(),\n service: new Set(),\n genModel: new Set(),\n genQObjects: new Set(),\n genServices: {},\n customTypes: new Map(),\n };\n\n constructor(fileNames: ProjectFiles) {\n this.mapping.genModel.moduleName = fileNames.model;\n this.mapping.genQObjects.moduleName = fileNames.qObject;\n }\n\n public addFromCore(...names: Array<string>) {\n names.forEach((n) => this.container.core.add(n));\n }\n\n public addFromQObject(...names: Array<string>) {\n names.forEach((n) => this.container.qobjects.add(n));\n }\n\n public addFromClientApi(...names: Array<string>) {\n names.forEach((n) => this.container.clientApi.add(n));\n }\n\n public addFromService(...names: Array<string>) {\n names.forEach((n) => this.container.service.add(n));\n }\n\n public addGeneratedModel(...names: Array<string>) {\n names.forEach((n) => this.container.genModel.add(n));\n }\n\n public addGeneratedQObject(...names: Array<string>) {\n names.forEach((n) => this.container.genQObjects.add(n));\n }\n\n public addCustomType(moduleName: string, typeName: string) {\n let importList = this.container.customTypes.get(moduleName);\n if (!importList) {\n importList = new Set();\n this.container.customTypes.set(moduleName, importList);\n }\n importList.add(typeName);\n }\n\n public addGeneratedService(key: string, ...names: Array<string>) {\n let serv = this.container.genServices[key];\n if (!serv) {\n serv = new Set();\n this.container.genServices[key] = serv;\n }\n names.forEach((n) => serv.add(n));\n }\n\n public getImportDeclarations(fromSubPath: boolean = false): Array<ImportDeclarationStructure> {\n const { genServices, customTypes, ...standardImports } = this.container;\n\n return [\n ...[...customTypes.keys()]\n .filter((key) => !!customTypes.get(key)?.size)\n .map((key) => {\n return {\n namedImports: [...customTypes.get(key)!],\n moduleSpecifier: key,\n } as ImportDeclarationStructure;\n }),\n ...Object.entries(standardImports)\n .filter(([key, values]) => !!values.size)\n .map(([key, values]) => {\n const mapping = this.mapping[key];\n return {\n namedImports: [...values],\n moduleSpecifier: `${mapping.isRelative ? `${fromSubPath ? \"..\" : \".\"}/` : \"\"}${mapping.moduleName}`,\n } as ImportDeclarationStructure;\n }),\n ...Object.entries(genServices).map(([key, values]) => {\n return {\n namedImports: [...values],\n moduleSpecifier: (fromSubPath ? \"./\" : \"./service/\") + key,\n } as ImportDeclarationStructure;\n }),\n ];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":";;;;AAeA,MAAa,eAAe;IAuB1B,YAAY,SAAuB;QAtB3B,YAAO,GAEX;YACF,IAAI,EAAE,EAAE,UAAU,EAAE,sBAAsB,EAAE,UAAU,EAAE,KAAK,EAAE;YAC/D,QAAQ,EAAE,EAAE,UAAU,EAAE,+BAA+B,EAAE,UAAU,EAAE,KAAK,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iBACtE,CAAC;YAClC,CAAC,CAAC;YACJ,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE;gBACnD,OAAO;oBACL,YAAY,EAAE,CAAC,GAAG,MAAM,CAAC;oBACzB,eAAe,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,GAAG;iBAC7B,CAAC;YAClC,CAAC,CAAC;SACH,CAAC;IACJ,CAAC;CACF;AAnGD,0CAmGC","sourcesContent":["import { ImportDeclarationStructure } from \"ts-morph\";\r\n\r\nimport { ProjectFiles } from \"../data-model/DataModel\";\r\n\r\ntype ImportContainerType = {\r\n core: Set<string>;\r\n qobjects: Set<string>;\r\n clientApi: Set<string>;\r\n service: Set<string>;\r\n genModel: Set<string>;\r\n genQObjects: Set<string>;\r\n genServices: { [key: string]: Set<string> };\r\n customTypes: Map<string, Set<string>>;\r\n};\r\n\r\nexport class ImportContainer {\r\n private mapping: {\r\n [K in keyof ImportContainerType as string]: { moduleName: string; isRelative: boolean; addName?: boolean };\r\n } = {\r\n core: { moduleName: \"@odata2ts/odata-core\", isRelative: false },\r\n qobjects: { moduleName: \"@odata2ts/odata-query-objects\", isRelative: false },\r\n clientApi: { moduleName: \"@odata2ts/http-client-api\", isRelative: false },\r\n service: { moduleName: \"@odata2ts/odata-service\", isRelative: false },\r\n genModel: { moduleName: \"\", isRelative: true },\r\n genQObjects: { moduleName: \"\", isRelative: true },\r\n };\r\n\r\n private container: ImportContainerType = {\r\n core: new Set(),\r\n qobjects: new Set(),\r\n clientApi: new Set(),\r\n service: new Set(),\r\n genModel: new Set(),\r\n genQObjects: new Set(),\r\n genServices: {},\r\n customTypes: new Map(),\r\n };\r\n\r\n constructor(fileNames: ProjectFiles) {\r\n this.mapping.genModel.moduleName = fileNames.model;\r\n this.mapping.genQObjects.moduleName = fileNames.qObject;\r\n }\r\n\r\n public addFromCore(...names: Array<string>) {\r\n names.forEach((n) => this.container.core.add(n));\r\n }\r\n\r\n public addFromQObject(...names: Array<string>) {\r\n names.forEach((n) => this.container.qobjects.add(n));\r\n }\r\n\r\n public addFromClientApi(...names: Array<string>) {\r\n names.forEach((n) => this.container.clientApi.add(n));\r\n }\r\n\r\n public addFromService(...names: Array<string>) {\r\n names.forEach((n) => this.container.service.add(n));\r\n }\r\n\r\n public addGeneratedModel(...names: Array<string>) {\r\n names.forEach((n) => this.container.genModel.add(n));\r\n }\r\n\r\n public addGeneratedQObject(...names: Array<string>) {\r\n names.forEach((n) => this.container.genQObjects.add(n));\r\n }\r\n\r\n public addCustomType(moduleName: string, typeName: string) {\r\n let importList = this.container.customTypes.get(moduleName);\r\n if (!importList) {\r\n importList = new Set();\r\n this.container.customTypes.set(moduleName, importList);\r\n }\r\n importList.add(typeName);\r\n }\r\n\r\n public addGeneratedService(key: string, ...names: Array<string>) {\r\n let serv = this.container.genServices[key];\r\n if (!serv) {\r\n serv = new Set();\r\n this.container.genServices[key] = serv;\r\n }\r\n names.forEach((n) => serv.add(n));\r\n }\r\n\r\n public getImportDeclarations(fromSubPath: boolean = false): Array<ImportDeclarationStructure> {\r\n const { genServices, customTypes, ...standardImports } = this.container;\r\n\r\n return [\r\n ...[...customTypes.keys()]\r\n .filter((key) => !!customTypes.get(key)?.size)\r\n .map((key) => {\r\n return {\r\n namedImports: [...customTypes.get(key)!],\r\n moduleSpecifier: key,\r\n } as ImportDeclarationStructure;\r\n }),\r\n ...Object.entries(standardImports)\r\n .filter(([key, values]) => !!values.size)\r\n .map(([key, values]) => {\r\n const mapping = this.mapping[key];\r\n return {\r\n namedImports: [...values],\r\n moduleSpecifier: `${mapping.isRelative ? `${fromSubPath ? \"..\" : \".\"}/` : \"\"}${mapping.moduleName}`,\r\n } as ImportDeclarationStructure;\r\n }),\r\n ...Object.entries(genServices).map(([key, values]) => {\r\n return {\r\n namedImports: [...values],\r\n moduleSpecifier: (fromSubPath ? \"./\" : \"./service/\") + key,\r\n } as ImportDeclarationStructure;\r\n }),\r\n ];\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceGenerator.js","sourceRoot":"","sources":["../../src/generator/ServiceGenerator.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AACrD,kEAAkC;AAClC,uCAOkB;AAClB,uDAAkD;AAClD,sDAA2D;AAmB3D,uDAAoD;AAEpD,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,MAAM,cAAc,GAAG;IACrB,UAAU,EAAE,yBAAyB;IACrC,KAAK,EAAE,oBAAoB;IAC3B,KAAK,EAAE,oBAAoB;CAC5B,CAAC;AAIF,SAAsB,gBAAgB,CACpC,SAAoB,EACpB,OAAuB,EACvB,OAAsB,EACtB,YAA0B;;QAE1B,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAClF,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;CAAA;AARD,4CAQC;AAED,MAAM,gBAAgB;IACpB,YACU,SAAoB,EACpB,OAAuB,EACvB,OAAsB,EACtB,YAA0B;QAH1B,cAAS,GAAT,SAAS,CAAW;QACpB,YAAO,GAAP,OAAO,CAAgB;QACvB,YAAO,GAAP,OAAO,CAAe;QACtB,iBAAY,GAAZ,YAAY,CAAc;QA6I5B,2BAAsB,GAAG,CAAC,SAAwB,EAAE,EAAE;YAC5D,OAAO;gBACL,KAAK,EAAE,gBAAK,CAAC,OAAO;gBACpB,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,SAAS,CAAC,KAAK,CAAC;gBAC3D,IAAI,EAAE,SAAS,CAAC,KAAK;gBACrB,gBAAgB,EAAE,IAAI;aACvB,CAAC;QACJ,CAAC,CAAC;IAnJC,CAAC;IAES,QAAQ;;YACnB,MAAM,UAAU,GAAG,MAAM,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ODataVersions } from \"@odata2ts/odata-core\";\nimport deepmerge from \"deepmerge\";\nimport {\n ClassDeclarationStructure,\n MethodDeclarationStructure,\n OptionalKind,\n PropertyDeclarationStructure,\n Scope,\n SourceFile,\n} from \"ts-morph\";\nimport { upperCaseFirst } from \"upper-case-first\";\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport {\n ActionImportType,\n ComplexType,\n DataTypes,\n EntityContainerModel,\n EntitySetType,\n FunctionImportType,\n ModelType,\n OperationType,\n OperationTypes,\n PropertyModel,\n SingletonType,\n} from \"../data-model/DataTypeModel\";\nimport { EntityType } from \"../data-model/edmx/ODataEdmxModelBase\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { ProjectManager } from \"../project/ProjectManager\";\nimport { ImportContainer } from \"./ImportContainer\";\n\nconst ROOT_SERVICE = \"ODataService\";\n\nconst RESPONSE_TYPES = {\n collection: \"ODataCollectionResponse\",\n model: \"ODataModelResponse\",\n value: \"ODataValueResponse\",\n};\n\nexport interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, \"properties\" | \"methods\">> {}\n\nexport async function generateServices(\n dataModel: DataModel,\n project: ProjectManager,\n version: ODataVersions,\n namingHelper: NamingHelper\n) {\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper);\n return generator.generate();\n}\n\nclass ServiceGenerator {\n constructor(\n private dataModel: DataModel,\n private project: ProjectManager,\n private version: ODataVersions,\n private namingHelper: NamingHelper\n ) {}\n\n public async generate(): Promise<void> {\n const sourceFile = await this.project.createMainServiceFile();\n const serviceName = this.namingHelper.getMainServiceName();\n const container = this.dataModel.getEntityContainer();\n const unboundOperations = [...Object.values(container.functions), ...Object.values(container.actions)];\n\n await this.generateModelServices();\n\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\n importContainer.addFromClientApi(\"ODataHttpClient\");\n importContainer.addFromService(ROOT_SERVICE);\n\n const { properties, methods }: PropsAndOps = deepmerge(\n this.generateMainServiceProperties(container, importContainer),\n this.generateMainServiceOperations(unboundOperations, importContainer)\n );\n\n sourceFile.addClass({\n isExported: true,\n name: serviceName,\n typeParameters: [\"ClientType extends ODataHttpClient\"],\n extends: `${ROOT_SERVICE}<ClientType>`,\n properties /*: [\n {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(\"name\"),\n type: \"string\",\n initializer: `\"${this.namingHelper.getODataServiceName()}\"`,\n },\n ]*/,\n methods,\n });\n\n sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\n }\n\n private generateMainServiceProperties(\n container: EntityContainerModel,\n importContainer: ImportContainer\n ): PropsAndOps {\n const result: PropsAndOps = { properties: [], methods: [] };\n\n Object.values(container.entitySets).forEach(({ name, entityType }) => {\n result.methods.push(this.generateRelatedServiceGetter(name, entityType, importContainer));\n });\n\n Object.values(container.singletons).forEach((singleton) => {\n result.properties.push(this.generateSingletonProp(singleton, importContainer));\n result.methods.push(this.generateSingletonGetter(singleton));\n });\n\n return result;\n }\n\n private generateMainServiceOperations(\n ops: Array<FunctionImportType | ActionImportType>,\n importContainer: ImportContainer\n ): PropsAndOps {\n const result: PropsAndOps = { properties: [], methods: [] };\n\n ops.forEach(({ operation, name }) => {\n result.properties.push(this.generateQOperationProp(operation));\n result.methods.push(this.generateMethod(name, operation, importContainer));\n });\n\n return result;\n }\n\n private generateRelatedServiceGetter(\n propName: string,\n entityType: ModelType,\n importContainer: ImportContainer,\n currentServiceName?: string\n ): OptionalKind<MethodDeclarationStructure> {\n const idName = entityType.idModelName;\n const idFunctionName = entityType.qIdFunctionName;\n const serviceName = this.namingHelper.getServiceName(entityType.name);\n const collectionName = this.namingHelper.getCollectionServiceName(entityType.name);\n\n importContainer.addFromClientApi(\"ODataHttpClient\");\n importContainer.addGeneratedModel(idName);\n importContainer.addGeneratedQObject(idFunctionName);\n // make sure to not falsely import self-referential stuff\n if (!currentServiceName || currentServiceName !== serviceName) {\n importContainer.addGeneratedService(serviceName, collectionName, serviceName);\n }\n\n return {\n scope: Scope.Public,\n name: this.namingHelper.getRelatedServiceGetter(propName),\n parameters: [\n {\n name: \"id\",\n type: `${idName} | undefined`,\n hasQuestionToken: true,\n },\n ],\n overloads: [\n {\n parameters: [],\n returnType: `${collectionName}<ClientType>`,\n },\n {\n parameters: [\n {\n name: \"id\",\n type: idName,\n },\n ],\n returnType: `${serviceName}<ClientType>`,\n },\n ],\n statements: [\n `const fieldName = \"${propName}\";`,\n 'return typeof id === \"undefined\" || id === null',\n `? new ${collectionName}(this.client, this.getPath(), fieldName)`,\n `: new ${serviceName}(this.client, this.getPath(), new ${idFunctionName}(fieldName).buildUrl(id));`,\n ],\n };\n }\n\n private generateSingletonProp(\n singleton: SingletonType,\n importContainer: ImportContainer\n ): OptionalKind<PropertyDeclarationStructure> {\n const { name, entityType } = singleton;\n const type = this.namingHelper.getServiceName(entityType.name);\n\n importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), type);\n\n return {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(name),\n type: `${type}<ClientType>`,\n hasQuestionToken: true,\n };\n }\n\n private generateQOperationProp = (operation: OperationType) => {\n return {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(operation.qName),\n type: operation.qName,\n hasQuestionToken: true,\n };\n };\n\n private generateSingletonGetter(singleton: SingletonType): OptionalKind<MethodDeclarationStructure> {\n const { name, odataName, entityType } = singleton;\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(name);\n const serviceType = this.namingHelper.getServiceName(entityType.name);\n\n return {\n scope: Scope.Public,\n name: this.namingHelper.getRelatedServiceGetter(name),\n statements: [\n `if(!${propName}) {`,\n // prettier-ignore\n ` ${propName} = new ${serviceType}(this.client, this.getPath(), \"${odataName}\")`,\n \"}\",\n `return ${propName}`,\n ],\n };\n }\n\n private getVersionSuffix() {\n return this.version === ODataVersions.V2 ? \"V2\" : \"V4\";\n }\n\n private async generateEntityTypeService(\n model: ComplexType,\n serviceName: string,\n serviceFile: SourceFile,\n importContainer: ImportContainer\n ) {\n const entityServiceType = \"EntityTypeService\" + this.getVersionSuffix();\n\n const editableModelName = model.editableName;\n const qObjectName = firstCharLowerCase(model.qName);\n const operations = this.dataModel.getOperationTypeByBinding(model.name);\n const props = [...model.baseProps, ...model.props];\n\n importContainer.addFromService(entityServiceType);\n importContainer.addFromClientApi(\"ODataHttpClient\");\n importContainer.addGeneratedModel(model.name, editableModelName);\n importContainer.addGeneratedQObject(model.qName, qObjectName);\n\n const { properties, methods }: PropsAndOps = deepmerge(\n this.generateServiceProperties(serviceName, props, importContainer),\n this.generateServiceOperations(operations, importContainer)\n );\n\n // generate EntityTypeService\n serviceFile.addClass({\n isExported: true,\n name: serviceName,\n typeParameters: [\"ClientType extends ODataHttpClient\"],\n extends: entityServiceType + `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}>`,\n ctors: [\n {\n parameters: [\n { name: \"client\", type: \"ClientType\" },\n { name: \"basePath\", type: \"string\" },\n { name: \"name\", type: \"string\" },\n ],\n statements: [`super(client, basePath, name, ${qObjectName});`],\n },\n ],\n properties,\n methods,\n });\n }\n\n private generateServiceProperties(\n serviceName: string,\n props: Array<PropertyModel>,\n importContainer: ImportContainer\n ): PropsAndOps {\n const collectionServiceType = \"CollectionService\" + this.getVersionSuffix();\n const result: PropsAndOps = { properties: [], methods: [] };\n\n props.forEach((prop) => {\n if ((prop.dataType === DataTypes.ModelType && !prop.isCollection) || prop.dataType === DataTypes.ComplexType) {\n result.properties.push(this.generateModelProp(prop, collectionServiceType, serviceName, importContainer));\n result.methods.push(this.generateModelPropGetter(prop, collectionServiceType));\n } else if (prop.isCollection) {\n // collection of entity types\n if (prop.dataType === DataTypes.ModelType) {\n const entityType = this.dataModel.getModel(prop.type);\n result.methods.push(this.generateRelatedServiceGetter(prop.name, entityType, importContainer, serviceName));\n }\n // collection of primitive or complex types\n else {\n result.properties.push(this.generatePrimitiveCollectionProp(prop, collectionServiceType, importContainer));\n result.methods.push(this.generatePrimitiveCollectionGetter(prop, collectionServiceType));\n }\n }\n });\n\n return result;\n }\n\n private generateServiceOperations(operations: Array<OperationType>, importContainer: ImportContainer): PropsAndOps {\n const result: PropsAndOps = { properties: [], methods: [] };\n\n operations.forEach((operation) => {\n result.properties.push(this.generateQOperationProp(operation));\n result.methods.push(this.generateMethod(operation.name, operation, importContainer));\n });\n\n return result;\n }\n\n private generateModelProp(\n prop: PropertyModel,\n collectionServiceType: string,\n serviceName: string,\n importContainer: ImportContainer\n ): PropertyDeclarationStructure {\n const complexType = this.dataModel.getComplexType(prop.type);\n const key = this.namingHelper.getServiceName(prop.type);\n let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;\n\n if (prop.isCollection && complexType) {\n const editableName = complexType.editableName;\n importContainer.addFromService(collectionServiceType);\n importContainer.addGeneratedModel(complexType.name, editableName);\n importContainer.addGeneratedQObject(complexType.qName, firstCharLowerCase(complexType.qName));\n propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;\n } else {\n // don't include imports for this type\n if (serviceName !== key) {\n importContainer.addGeneratedService(key, propModelType);\n }\n\n propModelType = `${propModelType}<ClientType>`;\n }\n\n return {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(prop.name),\n type: propModelType,\n hasQuestionToken: true,\n } as PropertyDeclarationStructure;\n }\n\n private generatePrimitiveCollectionProp(\n prop: PropertyModel,\n collectionServiceType: string,\n importContainer: ImportContainer\n ): OptionalKind<PropertyDeclarationStructure> {\n const isEnum = prop.dataType === DataTypes.EnumType;\n const type = isEnum ? `EnumCollection<${prop.type}>` : `${upperCaseFirst(prop.type)}Collection`;\n const qType = isEnum ? \"QEnumCollection\" : `Q${type}`;\n const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;\n\n if (!prop.qObject) {\n throw new Error(\"Illegal State: [qObject] must be provided for Collection types!\");\n }\n\n importContainer.addFromService(collectionServiceType);\n importContainer.addFromQObject(prop.qObject, firstCharLowerCase(prop.qObject));\n if (isEnum) {\n importContainer.addGeneratedModel(prop.type);\n importContainer.addFromQObject(\"EnumCollection\");\n } else {\n importContainer.addFromQObject(type);\n }\n\n return {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(prop.name),\n type: `${collectionType}`,\n hasQuestionToken: true,\n };\n }\n\n private generateModelPropGetter(\n prop: PropertyModel,\n collectionServiceType: string\n ): OptionalKind<MethodDeclarationStructure> {\n const complexType = this.dataModel.getComplexType(prop.type);\n const isComplexCollection = prop.isCollection && complexType;\n const type = isComplexCollection\n ? collectionServiceType\n : prop.isCollection\n ? this.namingHelper.getCollectionServiceName(prop.type)\n : this.namingHelper.getServiceName(prop.type);\n const typeWithGenerics = isComplexCollection\n ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`\n : `${type}<ClientType>`;\n\n const privateSrvProp = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\n\n return {\n scope: Scope.Public,\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\n returnType: typeWithGenerics,\n statements: [\n `if(!${privateSrvProp}) {`,\n // prettier-ignore\n ` ${privateSrvProp} = new ${type}(this.client, this.getPath(), \"${prop.odataName}\"${isComplexCollection ? `, ${firstCharLowerCase(complexType.qName)}`: \"\"})`,\n \"}\",\n `return ${privateSrvProp}`,\n ],\n };\n }\n\n private generatePrimitiveCollectionGetter(\n prop: PropertyModel,\n collectionServiceType: string\n ): OptionalKind<MethodDeclarationStructure> {\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\n return {\n scope: Scope.Public,\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\n statements: [\n `if(!${propName}) {`,\n // prettier-ignore\n ` ${propName} = new ${collectionServiceType}(this.client, this.getPath(), \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)})`,\n \"}\",\n `return ${propName}`,\n ],\n };\n }\n\n private async generateEntityCollectionService(\n model: ModelType,\n serviceFile: SourceFile,\n importContainer: ImportContainer\n ) {\n const entitySetServiceType = \"EntitySetService\" + this.getVersionSuffix();\n const editableModelName = model.editableName;\n const qObjectName = firstCharLowerCase(model.qName);\n\n importContainer.addFromService(entitySetServiceType);\n importContainer.addGeneratedModel(model.idModelName);\n importContainer.addGeneratedQObject(model.qIdFunctionName);\n\n const collectionOperations = this.dataModel.getOperationTypeByBinding(`Collection(${model.name})`);\n\n const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);\n\n serviceFile.addClass({\n isExported: true,\n name: this.namingHelper.getCollectionServiceName(model.name),\n typeParameters: [\"ClientType extends ODataHttpClient\"],\n extends:\n entitySetServiceType +\n `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}>`,\n ctors: [\n {\n parameters: [\n { name: \"client\", type: \"ClientType\" },\n { name: \"basePath\", type: \"string\" },\n { name: \"name\", type: \"string\" },\n ],\n statements: [`super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name));`],\n },\n ],\n properties,\n methods,\n });\n }\n\n private async generateModelServices() {\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\n for (const model of this.dataModel.getModels()) {\n const serviceName = this.namingHelper.getServiceName(model.name);\n const serviceFile = await this.project.createServiceFile(serviceName);\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n // entity type service\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\n\n // entity collection service\n await this.generateEntityCollectionService(model, serviceFile, importContainer);\n\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\n }\n\n // build service file for complex types\n for (const model of this.dataModel.getComplexTypes()) {\n const serviceName = this.namingHelper.getServiceName(model.name);\n const serviceFile = await this.project.createServiceFile(serviceName);\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n // entity type service\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\n }\n }\n\n private generateMethod(\n name: string,\n operation: OperationType,\n importContainer: ImportContainer\n ): OptionalKind<MethodDeclarationStructure> {\n const isFunc = operation.type === OperationTypes.Function;\n const odataType = operation.returnType?.isCollection\n ? RESPONSE_TYPES.collection + this.getVersionSuffix()\n : operation.returnType?.dataType === DataTypes.PrimitiveType\n ? RESPONSE_TYPES.value + this.getVersionSuffix()\n : RESPONSE_TYPES.model + this.getVersionSuffix();\n const returnType = operation.returnType;\n const requestConfigParam = {\n name: \"requestConfig\",\n hasQuestionToken: true,\n type: \"ODataHttpClientConfig<ClientType>\",\n };\n const hasParams = operation.parameters.length > 0;\n\n // importing dependencies\n importContainer.addFromClientApi(\"ODataHttpClientConfig\", \"ODataResponse\");\n importContainer.addFromCore(odataType);\n if (returnType?.type) {\n if ([DataTypes.EnumType, DataTypes.ModelType, DataTypes.ComplexType].includes(returnType.dataType)) {\n importContainer.addGeneratedModel(returnType.type);\n }\n }\n importContainer.addGeneratedQObject(operation.qName);\n if (hasParams) {\n importContainer.addGeneratedModel(operation.paramsModelName);\n }\n\n const qOpProp = \"this.\" + this.namingHelper.getPrivatePropName(operation.qName);\n\n return {\n scope: Scope.Public,\n isAsync: true,\n name,\n parameters: hasParams\n ? [{ name: \"params\", type: operation.paramsModelName }, requestConfigParam]\n : [requestConfigParam],\n returnType: `ODataResponse<${odataType}<${returnType?.type || \"void\"}>>`,\n statements: [\n `if(!${qOpProp}) {`,\n ` ${qOpProp} = new ${operation.qName}()`,\n \"}\",\n\n `const url = this.addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\n `${returnType ? \"const response = await \" : \"return\"} this.client.${\n !isFunc\n ? // actions: since V4\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${requestConfigParam.name})`\n : operation.usePost\n ? // V2 POST => BUT values are still query params, they are not part of the request body\n `post(url, undefined, ${requestConfigParam.name})`\n : // functions: since V2\n `get(url, ${requestConfigParam.name})`\n };`,\n returnType ? `return ${qOpProp}.convertResponse(response);` : \"\",\n ],\n };\n }\n}\n"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AC,KAAK,CAAC,CAAC;QAEhF,OAAO;YACL,KAAK,EAAE,gBAAK,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI;YACb,IAAI;YACJ,UAAU,EAAE,SAAS;gBACnB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC,eAAe,EAAE,EAAE,kBAAkB,CAAC;gBAC3E,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACxB,UAAU,EAAE,iBAAiB,SAAS,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,KAAI,MAAM,IAAI;YACxE,UAAU,EAAE;gBACV,OAAO,OAAO,KAAK;gBACnB,KAAK,OAAO,UAAU,SAAS,CAAC,KAAK,IAAI;gBACzC,GAAG;gBAEH,gCAAgC,OAAO,aAAa,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK;gBAC5F,GAAG,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,QAAQ,gBAClD,CAAC,MAAM;oBACL,CAAC,CAAC,oBAAoB;wBACpB,aAAa,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,4BAA4B,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,CAAC,IAAI,GAAG;oBACvG,CAAC,CAAC,SAAS,CAAC,OAAO;wBACnB,CAAC,CAAC,sFAAsF;4BACtF,wBAAwB,kBAAkB,CAAC,IAAI,GAAG;wBACpD,CAAC,CAAC,sBAAsB;4BACtB,YAAY,kBAAkB,CAAC,IAAI,GACzC,GAAG;gBACH,UAAU,CAAC,CAAC,CAAC,UAAU,OAAO,6BAA6B,CAAC,CAAC,CAAC,EAAE;aACjE;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport deepmerge from \"deepmerge\";\r\nimport {\r\n ClassDeclarationStructure,\r\n MethodDeclarationStructure,\r\n OptionalKind,\r\n PropertyDeclarationStructure,\r\n Scope,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport { upperCaseFirst } from \"upper-case-first\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntityContainerModel,\r\n EntitySetType,\r\n FunctionImportType,\r\n ModelType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"../data-model/DataTypeModel\";\r\nimport { EntityType } from \"../data-model/edmx/ODataEdmxModelBase\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { ProjectManager } from \"../project/ProjectManager\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nconst ROOT_SERVICE = \"ODataService\";\r\n\r\nconst RESPONSE_TYPES = {\r\n collection: \"ODataCollectionResponse\",\r\n model: \"ODataModelResponse\",\r\n value: \"ODataValueResponse\",\r\n};\r\n\r\nexport interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, \"properties\" | \"methods\">> {}\r\n\r\nexport async function generateServices(\r\n dataModel: DataModel,\r\n project: ProjectManager,\r\n version: ODataVersions,\r\n namingHelper: NamingHelper\r\n) {\r\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper);\r\n return generator.generate();\r\n}\r\n\r\nclass ServiceGenerator {\r\n constructor(\r\n private dataModel: DataModel,\r\n private project: ProjectManager,\r\n private version: ODataVersions,\r\n private namingHelper: NamingHelper\r\n ) {}\r\n\r\n public async generate(): Promise<void> {\r\n const sourceFile = await this.project.createMainServiceFile();\r\n const serviceName = this.namingHelper.getMainServiceName();\r\n const container = this.dataModel.getEntityContainer();\r\n const unboundOperations = [...Object.values(container.functions), ...Object.values(container.actions)];\r\n\r\n await this.generateModelServices();\r\n\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n importContainer.addFromClientApi(\"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 properties /*: [\r\n {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(\"name\"),\r\n type: \"string\",\r\n initializer: `\"${this.namingHelper.getODataServiceName()}\"`,\r\n },\r\n ]*/,\r\n methods,\r\n });\r\n\r\n sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\r\n }\r\n\r\n private generateMainServiceProperties(\r\n container: EntityContainerModel,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n Object.values(container.entitySets).forEach(({ name, entityType }) => {\r\n result.methods.push(this.generateRelatedServiceGetter(name, entityType, importContainer));\r\n });\r\n\r\n Object.values(container.singletons).forEach((singleton) => {\r\n result.properties.push(this.generateSingletonProp(singleton, importContainer));\r\n result.methods.push(this.generateSingletonGetter(singleton));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateMainServiceOperations(\r\n ops: Array<FunctionImportType | ActionImportType>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n ops.forEach(({ operation, name }) => {\r\n result.properties.push(this.generateQOperationProp(operation));\r\n result.methods.push(this.generateMethod(name, operation, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateRelatedServiceGetter(\r\n propName: string,\r\n entityType: ModelType,\r\n importContainer: ImportContainer,\r\n currentServiceName?: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const idName = entityType.idModelName;\r\n const idFunctionName = entityType.qIdFunctionName;\r\n const serviceName = this.namingHelper.getServiceName(entityType.name);\r\n const collectionName = this.namingHelper.getCollectionServiceName(entityType.name);\r\n\r\n importContainer.addFromClientApi(\"ODataHttpClient\");\r\n importContainer.addGeneratedModel(idName);\r\n importContainer.addGeneratedQObject(idFunctionName);\r\n // make sure to not falsely import self-referential stuff\r\n if (!currentServiceName || currentServiceName !== serviceName) {\r\n importContainer.addGeneratedService(serviceName, collectionName, serviceName);\r\n }\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(propName),\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: `${idName} | undefined`,\r\n hasQuestionToken: true,\r\n },\r\n ],\r\n overloads: [\r\n {\r\n parameters: [],\r\n returnType: `${collectionName}<ClientType>`,\r\n },\r\n {\r\n parameters: [\r\n {\r\n name: \"id\",\r\n type: idName,\r\n },\r\n ],\r\n returnType: `${serviceName}<ClientType>`,\r\n },\r\n ],\r\n statements: [\r\n `const fieldName = \"${propName}\";`,\r\n 'return typeof id === \"undefined\" || id === null',\r\n `? new ${collectionName}(this.client, this.getPath(), fieldName)`,\r\n `: new ${serviceName}(this.client, this.getPath(), new ${idFunctionName}(fieldName).buildUrl(id));`,\r\n ],\r\n };\r\n }\r\n\r\n private generateSingletonProp(\r\n singleton: SingletonType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const { name, entityType } = singleton;\r\n const type = this.namingHelper.getServiceName(entityType.name);\r\n\r\n importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), type);\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(name),\r\n type: `${type}<ClientType>`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateQOperationProp = (operation: OperationType) => {\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(operation.qName),\r\n type: operation.qName,\r\n hasQuestionToken: true,\r\n };\r\n };\r\n\r\n private generateSingletonGetter(singleton: SingletonType): OptionalKind<MethodDeclarationStructure> {\r\n const { name, odataName, entityType } = singleton;\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(name);\r\n const serviceType = this.namingHelper.getServiceName(entityType.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n // prettier-ignore\r\n ` ${propName} = new ${serviceType}(this.client, this.getPath(), \"${odataName}\")`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private getVersionSuffix() {\r\n return this.version === ODataVersions.V2 ? \"V2\" : \"V4\";\r\n }\r\n\r\n private async generateEntityTypeService(\r\n model: ComplexType,\r\n serviceName: string,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entityServiceType = \"EntityTypeService\" + this.getVersionSuffix();\r\n\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n const operations = this.dataModel.getOperationTypeByBinding(model.name);\r\n const props = [...model.baseProps, ...model.props];\r\n\r\n importContainer.addFromService(entityServiceType);\r\n importContainer.addFromClientApi(\"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});`],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private generateServiceProperties(\r\n serviceName: string,\r\n props: Array<PropertyModel>,\r\n importContainer: ImportContainer\r\n ): PropsAndOps {\r\n const collectionServiceType = \"CollectionService\" + this.getVersionSuffix();\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n props.forEach((prop) => {\r\n if ((prop.dataType === DataTypes.ModelType && !prop.isCollection) || prop.dataType === DataTypes.ComplexType) {\r\n result.properties.push(this.generateModelProp(prop, collectionServiceType, serviceName, importContainer));\r\n result.methods.push(this.generateModelPropGetter(prop, collectionServiceType));\r\n } else if (prop.isCollection) {\r\n // collection of entity types\r\n if (prop.dataType === DataTypes.ModelType) {\r\n const entityType = this.dataModel.getModel(prop.type);\r\n result.methods.push(this.generateRelatedServiceGetter(prop.name, entityType, importContainer, serviceName));\r\n }\r\n // collection of primitive or complex types\r\n else {\r\n result.properties.push(this.generatePrimitiveCollectionProp(prop, collectionServiceType, importContainer));\r\n result.methods.push(this.generatePrimitiveCollectionGetter(prop, collectionServiceType));\r\n }\r\n }\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateServiceOperations(operations: Array<OperationType>, importContainer: ImportContainer): PropsAndOps {\r\n const result: PropsAndOps = { properties: [], methods: [] };\r\n\r\n operations.forEach((operation) => {\r\n result.properties.push(this.generateQOperationProp(operation));\r\n result.methods.push(this.generateMethod(operation.name, operation, importContainer));\r\n });\r\n\r\n return result;\r\n }\r\n\r\n private generateModelProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n serviceName: string,\r\n importContainer: ImportContainer\r\n ): PropertyDeclarationStructure {\r\n const complexType = this.dataModel.getComplexType(prop.type);\r\n const key = this.namingHelper.getServiceName(prop.type);\r\n let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;\r\n\r\n if (prop.isCollection && complexType) {\r\n const editableName = complexType.editableName;\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addGeneratedModel(complexType.name, editableName);\r\n importContainer.addGeneratedQObject(complexType.qName, firstCharLowerCase(complexType.qName));\r\n propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;\r\n } else {\r\n // don't include imports for this type\r\n if (serviceName !== key) {\r\n importContainer.addGeneratedService(key, propModelType);\r\n }\r\n\r\n propModelType = `${propModelType}<ClientType>`;\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: propModelType,\r\n hasQuestionToken: true,\r\n } as PropertyDeclarationStructure;\r\n }\r\n\r\n private generatePrimitiveCollectionProp(\r\n prop: PropertyModel,\r\n collectionServiceType: string,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure> {\r\n const isEnum = prop.dataType === DataTypes.EnumType;\r\n const type = isEnum ? `EnumCollection<${prop.type}>` : `${upperCaseFirst(prop.type)}Collection`;\r\n const qType = isEnum ? \"QEnumCollection\" : `Q${type}`;\r\n const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;\r\n\r\n if (!prop.qObject) {\r\n throw new Error(\"Illegal State: [qObject] must be provided for Collection types!\");\r\n }\r\n\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addFromQObject(prop.qObject, firstCharLowerCase(prop.qObject));\r\n if (isEnum) {\r\n importContainer.addGeneratedModel(prop.type);\r\n importContainer.addFromQObject(\"EnumCollection\");\r\n } else {\r\n importContainer.addFromQObject(type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${collectionType}`,\r\n hasQuestionToken: true,\r\n };\r\n }\r\n\r\n private generateModelPropGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const complexType = this.dataModel.getComplexType(prop.type);\r\n const isComplexCollection = prop.isCollection && complexType;\r\n const type = isComplexCollection\r\n ? collectionServiceType\r\n : prop.isCollection\r\n ? this.namingHelper.getCollectionServiceName(prop.type)\r\n : this.namingHelper.getServiceName(prop.type);\r\n const typeWithGenerics = isComplexCollection\r\n ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`\r\n : `${type}<ClientType>`;\r\n\r\n const privateSrvProp = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n returnType: typeWithGenerics,\r\n statements: [\r\n `if(!${privateSrvProp}) {`,\r\n // prettier-ignore\r\n ` ${privateSrvProp} = new ${type}(this.client, this.getPath(), \"${prop.odataName}\"${isComplexCollection ? `, ${firstCharLowerCase(complexType.qName)}`: \"\"})`,\r\n \"}\",\r\n `return ${privateSrvProp}`,\r\n ],\r\n };\r\n }\r\n\r\n private generatePrimitiveCollectionGetter(\r\n prop: PropertyModel,\r\n collectionServiceType: string\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n // prettier-ignore\r\n ` ${propName} = new ${collectionServiceType}(this.client, this.getPath(), \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n }\r\n\r\n private async generateEntityCollectionService(\r\n model: ModelType,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entitySetServiceType = \"EntitySetService\" + this.getVersionSuffix();\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n\r\n importContainer.addFromService(entitySetServiceType);\r\n importContainer.addGeneratedModel(model.idModelName);\r\n importContainer.addGeneratedQObject(model.qIdFunctionName);\r\n\r\n const collectionOperations = this.dataModel.getOperationTypeByBinding(`Collection(${model.name})`);\r\n\r\n const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);\r\n\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: this.namingHelper.getCollectionServiceName(model.name),\r\n typeParameters: [\"ClientType extends 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: [`super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name));`],\r\n },\r\n ],\r\n properties,\r\n methods,\r\n });\r\n }\r\n\r\n private async generateModelServices() {\r\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\r\n for (const model of this.dataModel.getModels()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n const serviceFile = await this.project.createServiceFile(serviceName);\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n // entity type service\r\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n\r\n // entity collection service\r\n await this.generateEntityCollectionService(model, serviceFile, importContainer);\r\n\r\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\r\n }\r\n\r\n // build service file for complex types\r\n for (const model of this.dataModel.getComplexTypes()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n const serviceFile = await this.project.createServiceFile(serviceName);\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n // entity type service\r\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\r\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\r\n }\r\n }\r\n\r\n private generateMethod(\r\n name: string,\r\n operation: OperationType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const isFunc = operation.type === OperationTypes.Function;\r\n const odataType = operation.returnType?.isCollection\r\n ? RESPONSE_TYPES.collection + this.getVersionSuffix()\r\n : operation.returnType?.dataType === DataTypes.PrimitiveType\r\n ? RESPONSE_TYPES.value + this.getVersionSuffix()\r\n : RESPONSE_TYPES.model + this.getVersionSuffix();\r\n const returnType = operation.returnType;\r\n const requestConfigParam = {\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 url = this.addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\r\n `${returnType ? \"const response = await \" : \"return\"} this.client.${\r\n !isFunc\r\n ? // actions: since V4\r\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${requestConfigParam.name})`\r\n : operation.usePost\r\n ? // V2 POST => BUT values are still query params, they are not part of the request body\r\n `post(url, undefined, ${requestConfigParam.name})`\r\n : // functions: since V2\r\n `get(url, ${requestConfigParam.name})`\r\n };`,\r\n returnType ? `return ${qOpProp}.convertResponse(response);` : \"\",\r\n ],\r\n };\r\n }\r\n}\r\n"]}
|
|
@@ -21,7 +21,7 @@ function createProjectManager(projectFiles, outputDir, emitMode, usePrettier, ts
|
|
|
21
21
|
importsNotUsedAsValues, // type is missing
|
|
22
22
|
jsx, plugins,
|
|
23
23
|
// mapped props
|
|
24
|
-
moduleResolution, lib, module, newLine, target } = _a, passThrough = tslib_1.__rest(_a, ["noEmit", "importsNotUsedAsValues", "jsx", "plugins", "moduleResolution", "lib", "module", "newLine", "target"]);
|
|
24
|
+
moduleResolution, lib, module, newLine, target, rootDir, rootDirs } = _a, passThrough = tslib_1.__rest(_a, ["noEmit", "importsNotUsedAsValues", "jsx", "plugins", "moduleResolution", "lib", "module", "newLine", "target", "rootDir", "rootDirs"]);
|
|
25
25
|
const compilerOpts = Object.assign(Object.assign({}, passThrough), { outDir: outputDir, declaration: generateDeclarations, moduleResolution: getModuleResolutionKind(moduleResolution), module: getModuleKind(module), target: getTarget(target), lib: lib, newLine: (newLine === null || newLine === void 0 ? void 0 : newLine.toLowerCase()) === "crlf"
|
|
26
26
|
? ts_morph_1.NewLineKind.CarriageReturnLineFeed
|
|
27
27
|
: (newLine === null || newLine === void 0 ? void 0 : newLine.toLowerCase()) === "lf"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectManager.js","sourceRoot":"","sources":["../../src/project/ProjectManager.ts"],"names":[],"mappings":";;;;AAAA,0CAAwC;AACxC,mDAA6B;AAE7B,uCAA4C;AAC5C,uCAQkB;AAClB,8EAAmC;AACnC,oEAA4B;AAG5B,gDAA2C;AAC3C,2CAA8C;AAG9C,SAAsB,oBAAoB,CACxC,YAA0B,EAC1B,SAAiB,EACjB,QAAmB,EACnB,WAAoB,EACpB,eAAuB,eAAe;;QAEtC,MAAM,oBAAoB,GAAG,uBAAS,CAAC,MAAM,KAAK,QAAQ,IAAI,uBAAS,CAAC,GAAG,KAAK,QAAQ,CAAC;QACzF,MAAM,IAAI,GAAG,IAAA,yBAAI,EAAC,EAAE,QAAQ,EAAE,YAAY,EAAE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CAAC;YAEjE;;gBAEI;QACN,CAAC;KAAA;IAEa,WAAW;;YACvB,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,kBAAkB,EAAE,EAAE,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;YACjH,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,CAAC,MAAM,WAAW,CAAC,CAAC;YACjD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACvF,CAAC;KAAA;CAqBF;AAjID,wCAiIC","sourcesContent":["import { writeFile } from \"fs/promises\";\r\nimport * as path from \"path\";\r\n\r\nimport { emptyDir, remove } from \"fs-extra\";\r\nimport {\r\n CompilerOptions,\r\n ModuleKind,\r\n ModuleResolutionKind,\r\n NewLineKind,\r\n Project,\r\n ScriptTarget,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport load from \"tsconfig-loader\";\r\nimport ts from \"typescript\";\r\n\r\nimport { ProjectFiles } from \"../data-model/DataModel\";\r\nimport { EmitModes } from \"../OptionModel\";\r\nimport { createFormatter } from \"./formatter\";\r\nimport { FileFormatter } from \"./formatter/FileFormatter\";\r\n\r\nexport async function createProjectManager(\r\n projectFiles: ProjectFiles,\r\n outputDir: string,\r\n emitMode: EmitModes,\r\n usePrettier: boolean,\r\n tsConfigPath: string = \"tsconfig.json\"\r\n): Promise<ProjectManager> {\r\n const generateDeclarations = EmitModes.js_dts === emitMode || EmitModes.dts === emitMode;\r\n const conf = load({ filename: tsConfigPath });\r\n const formatter = await createFormatter(outputDir, usePrettier);\r\n\r\n const {\r\n // ignored props\r\n noEmit, // we always want to emit\r\n importsNotUsedAsValues, // type is missing\r\n jsx,\r\n plugins,\r\n // mapped props\r\n moduleResolution,\r\n lib,\r\n module,\r\n newLine,\r\n target,\r\n ...passThrough\r\n } = conf?.tsConfig.compilerOptions || {};\r\n\r\n const compilerOpts: CompilerOptions = {\r\n ...passThrough,\r\n outDir: outputDir,\r\n declaration: generateDeclarations,\r\n moduleResolution: getModuleResolutionKind(moduleResolution),\r\n module: getModuleKind(module),\r\n target: getTarget(target),\r\n lib: lib as string[],\r\n newLine:\r\n newLine?.toLowerCase() === \"crlf\"\r\n ? NewLineKind.CarriageReturnLineFeed\r\n : newLine?.toLowerCase() === \"lf\"\r\n ? NewLineKind.LineFeed\r\n : undefined,\r\n };\r\n\r\n return new ProjectManager(projectFiles, outputDir, emitMode, formatter, compilerOpts);\r\n}\r\n\r\nfunction getModuleResolutionKind(\r\n moduleResolution: string | undefined | Record<string, any>\r\n): ModuleResolutionKind | undefined {\r\n const modRes =\r\n typeof moduleResolution === \"string\"\r\n ? moduleResolution.toLowerCase() === \"node\"\r\n ? \"nodejs\"\r\n : moduleResolution.toLowerCase()\r\n : undefined;\r\n const matchedKey = Object.keys(ts.ModuleResolutionKind).find(\r\n (mk): mk is keyof typeof ModuleResolutionKind => mk.toLowerCase() === modRes\r\n );\r\n return matchedKey ? (ts.ModuleResolutionKind[matchedKey] as ModuleResolutionKind) : undefined;\r\n}\r\n\r\nfunction getModuleKind(module: string | undefined | Record<string, any>): ModuleKind | undefined {\r\n const mod = typeof module === \"string\" ? module.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ModuleKind).find((mk): mk is keyof typeof ModuleKind => mk.toLowerCase() === mod);\r\n return matchedKey ? (ts.ModuleKind[matchedKey] as ModuleKind) : undefined;\r\n}\r\n\r\nfunction getTarget(target: string | undefined | Record<string, any>): ScriptTarget | undefined {\r\n const t = typeof target === \"string\" ? target.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ScriptTarget).find((st): st is keyof typeof ScriptTarget => st.toLowerCase() === t);\r\n return matchedKey ? (ts.ScriptTarget[matchedKey] as ScriptTarget) : undefined;\r\n}\r\n\r\nconst STATIC_SERVICE_DIR = \"service\";\r\n\r\nexport class ProjectManager {\r\n private project!: Project;\r\n\r\n private files: { [name: string]: SourceFile } = {};\r\n private serviceFiles: Array<SourceFile> = [];\r\n\r\n constructor(\r\n private projectFiles: ProjectFiles,\r\n private outputDir: string,\r\n private emitMode: EmitModes,\r\n private formatter: FileFormatter,\r\n compilerOptions: CompilerOptions | undefined\r\n ) {\r\n // Create ts-morph project\r\n this.project = new Project({\r\n manipulationSettings: this.formatter.getSettings(),\r\n skipAddingFilesFromTsConfig: true,\r\n compilerOptions,\r\n });\r\n }\r\n\r\n private async createFile(name: string) {\r\n const fileName = path.join(this.outputDir, `${name}.ts`);\r\n await remove(fileName);\r\n return this.project.createSourceFile(fileName);\r\n }\r\n\r\n public async createModelFile() {\r\n this.files.model = await this.createFile(this.projectFiles.model);\r\n return this.getModelFile();\r\n }\r\n\r\n public getModelFile() {\r\n return this.files.model;\r\n }\r\n\r\n public async createQObjectFile() {\r\n this.files.qobject = await this.createFile(this.projectFiles.qObject);\r\n return this.getQObjectFile();\r\n }\r\n\r\n public getQObjectFile() {\r\n return this.files.qobject;\r\n }\r\n\r\n public async createMainServiceFile() {\r\n this.files.mainService = await this.createFile(this.projectFiles.service);\r\n return this.getMainServiceFile();\r\n }\r\n\r\n public getMainServiceFile() {\r\n return this.files.mainService;\r\n }\r\n\r\n public getServiceDir() {\r\n return path.join(this.outputDir, STATIC_SERVICE_DIR);\r\n }\r\n\r\n public async cleanServiceDir() {\r\n return emptyDir(this.getServiceDir());\r\n }\r\n\r\n public async createServiceFile(name: string) {\r\n const file = await this.createFile(path.join(STATIC_SERVICE_DIR, name));\r\n this.serviceFiles.push(file);\r\n\r\n return file;\r\n }\r\n\r\n public getServiceFiles() {\r\n return this.serviceFiles;\r\n }\r\n\r\n public async writeFiles() {\r\n switch (this.emitMode) {\r\n case EmitModes.js:\r\n case EmitModes.js_dts:\r\n await this.emitJsFiles();\r\n break;\r\n case EmitModes.dts:\r\n await this.emitJsFiles(true);\r\n break;\r\n case EmitModes.ts:\r\n await this.emitTsFiles();\r\n break;\r\n default:\r\n throw new Error(`Emit mode \"${this.emitMode}\" is invalid!`);\r\n }\r\n }\r\n\r\n private async emitJsFiles(declarationOnly?: boolean) {\r\n console.log(\r\n declarationOnly\r\n ? \"Emitting declaration files\"\r\n : `Emitting JS files (${this.emitMode === EmitModes.js_dts ? \"including\" : \"without\"} declaration files)`\r\n );\r\n\r\n await this.project.emit({ emitOnlyDtsFiles: !!declarationOnly });\r\n\r\n /* for (const diagnostic of this.project.getPreEmitDiagnostics()) {\r\n console.log(diagnostic.getMessageText());\r\n } */\r\n }\r\n\r\n private async emitTsFiles() {\r\n const files = [this.getModelFile(), this.getQObjectFile(), this.getMainServiceFile(), ...this.getServiceFiles()];\r\n console.log(`Emitting ${files.length} TS files`);\r\n return Promise.all([...files.filter((file) => !!file).map(this.formatAndWriteFile)]);\r\n }\r\n\r\n private formatAndWriteFile = async (file: SourceFile) => {\r\n const fileName = file.getFilePath();\r\n const content = file.getFullText();\r\n\r\n try {\r\n const formatted = await this.formatter.format(content);\r\n\r\n try {\r\n return writeFile(fileName, formatted);\r\n } catch (writeError) {\r\n console.error(`Failed to write file [/${fileName}]`, writeError);\r\n process.exit(3);\r\n }\r\n } catch (formattingError) {\r\n console.error(\"Formatting failed\");\r\n await writeFile(\"error.log\", formattingError?.toString() || \"no error message!\");\r\n process.exit(99);\r\n }\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ProjectManager.js","sourceRoot":"","sources":["../../src/project/ProjectManager.ts"],"names":[],"mappings":";;;;AAAA,0CAAwC;AACxC,mDAA6B;AAE7B,uCAA4C;AAC5C,uCAQkB;AAClB,8EAAmC;AACnC,oEAA4B;AAG5B,gDAA2C;AAC3C,2CAA8C;AAG9C,SAAsB,oBAAoB,CACxC,YAA0B,EAC1B,SAAiB,EACjB,QAAmB,EACnB,WAAoB,E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BAAsB,IAAI,CAAC,QAAQ,KAAK,uBAAS,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,qBAAqB,CAC5G,CAAC;YAEF,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;YAEjE;;gBAEI;QACN,CAAC;KAAA;IAEa,WAAW;;YACvB,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,kBAAkB,EAAE,EAAE,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;YACjH,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,CAAC,MAAM,WAAW,CAAC,CAAC;YACjD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACvF,CAAC;KAAA;CAqBF;AAjID,wCAiIC","sourcesContent":["import { writeFile } from \"fs/promises\";\r\nimport * as path from \"path\";\r\n\r\nimport { emptyDir, remove } from \"fs-extra\";\r\nimport {\r\n CompilerOptions,\r\n ModuleKind,\r\n ModuleResolutionKind,\r\n NewLineKind,\r\n Project,\r\n ScriptTarget,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport load from \"tsconfig-loader\";\r\nimport ts from \"typescript\";\r\n\r\nimport { ProjectFiles } from \"../data-model/DataModel\";\r\nimport { EmitModes } from \"../OptionModel\";\r\nimport { createFormatter } from \"./formatter\";\r\nimport { FileFormatter } from \"./formatter/FileFormatter\";\r\n\r\nexport async function createProjectManager(\r\n projectFiles: ProjectFiles,\r\n outputDir: string,\r\n emitMode: EmitModes,\r\n usePrettier: boolean,\r\n tsConfigPath: string = \"tsconfig.json\"\r\n): Promise<ProjectManager> {\r\n const generateDeclarations = EmitModes.js_dts === emitMode || EmitModes.dts === emitMode;\r\n const conf = load({ filename: tsConfigPath });\r\n const formatter = await createFormatter(outputDir, usePrettier);\r\n\r\n const {\r\n // ignored props\r\n noEmit, // we always want to emit\r\n importsNotUsedAsValues, // type is missing\r\n jsx,\r\n plugins,\r\n // mapped props\r\n moduleResolution,\r\n lib,\r\n module,\r\n newLine,\r\n target,\r\n rootDir,\r\n rootDirs,\r\n ...passThrough\r\n } = conf?.tsConfig.compilerOptions || {};\r\n\r\n const compilerOpts: CompilerOptions = {\r\n ...passThrough,\r\n outDir: outputDir,\r\n declaration: generateDeclarations,\r\n moduleResolution: getModuleResolutionKind(moduleResolution),\r\n module: getModuleKind(module),\r\n target: getTarget(target),\r\n lib: lib as string[],\r\n newLine:\r\n newLine?.toLowerCase() === \"crlf\"\r\n ? NewLineKind.CarriageReturnLineFeed\r\n : newLine?.toLowerCase() === \"lf\"\r\n ? NewLineKind.LineFeed\r\n : undefined,\r\n };\r\n\r\n return new ProjectManager(projectFiles, outputDir, emitMode, formatter, compilerOpts);\r\n}\r\n\r\nfunction getModuleResolutionKind(\r\n moduleResolution: string | undefined | Record<string, any>\r\n): ModuleResolutionKind | undefined {\r\n const modRes =\r\n typeof moduleResolution === \"string\"\r\n ? moduleResolution.toLowerCase() === \"node\"\r\n ? \"nodejs\"\r\n : moduleResolution.toLowerCase()\r\n : undefined;\r\n const matchedKey = Object.keys(ts.ModuleResolutionKind).find(\r\n (mk): mk is keyof typeof ModuleResolutionKind => mk.toLowerCase() === modRes\r\n );\r\n return matchedKey ? (ts.ModuleResolutionKind[matchedKey] as ModuleResolutionKind) : undefined;\r\n}\r\n\r\nfunction getModuleKind(module: string | undefined | Record<string, any>): ModuleKind | undefined {\r\n const mod = typeof module === \"string\" ? module.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ModuleKind).find((mk): mk is keyof typeof ModuleKind => mk.toLowerCase() === mod);\r\n return matchedKey ? (ts.ModuleKind[matchedKey] as ModuleKind) : undefined;\r\n}\r\n\r\nfunction getTarget(target: string | undefined | Record<string, any>): ScriptTarget | undefined {\r\n const t = typeof target === \"string\" ? target.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ScriptTarget).find((st): st is keyof typeof ScriptTarget => st.toLowerCase() === t);\r\n return matchedKey ? (ts.ScriptTarget[matchedKey] as ScriptTarget) : undefined;\r\n}\r\n\r\nconst STATIC_SERVICE_DIR = \"service\";\r\n\r\nexport class ProjectManager {\r\n private project!: Project;\r\n\r\n private files: { [name: string]: SourceFile } = {};\r\n private serviceFiles: Array<SourceFile> = [];\r\n\r\n constructor(\r\n private projectFiles: ProjectFiles,\r\n private outputDir: string,\r\n private emitMode: EmitModes,\r\n private formatter: FileFormatter,\r\n compilerOptions: CompilerOptions | undefined\r\n ) {\r\n // Create ts-morph project\r\n this.project = new Project({\r\n manipulationSettings: this.formatter.getSettings(),\r\n skipAddingFilesFromTsConfig: true,\r\n compilerOptions,\r\n });\r\n }\r\n\r\n private async createFile(name: string) {\r\n const fileName = path.join(this.outputDir, `${name}.ts`);\r\n await remove(fileName);\r\n return this.project.createSourceFile(fileName);\r\n }\r\n\r\n public async createModelFile() {\r\n this.files.model = await this.createFile(this.projectFiles.model);\r\n return this.getModelFile();\r\n }\r\n\r\n public getModelFile() {\r\n return this.files.model;\r\n }\r\n\r\n public async createQObjectFile() {\r\n this.files.qobject = await this.createFile(this.projectFiles.qObject);\r\n return this.getQObjectFile();\r\n }\r\n\r\n public getQObjectFile() {\r\n return this.files.qobject;\r\n }\r\n\r\n public async createMainServiceFile() {\r\n this.files.mainService = await this.createFile(this.projectFiles.service);\r\n return this.getMainServiceFile();\r\n }\r\n\r\n public getMainServiceFile() {\r\n return this.files.mainService;\r\n }\r\n\r\n public getServiceDir() {\r\n return path.join(this.outputDir, STATIC_SERVICE_DIR);\r\n }\r\n\r\n public async cleanServiceDir() {\r\n return emptyDir(this.getServiceDir());\r\n }\r\n\r\n public async createServiceFile(name: string) {\r\n const file = await this.createFile(path.join(STATIC_SERVICE_DIR, name));\r\n this.serviceFiles.push(file);\r\n\r\n return file;\r\n }\r\n\r\n public getServiceFiles() {\r\n return this.serviceFiles;\r\n }\r\n\r\n public async writeFiles() {\r\n switch (this.emitMode) {\r\n case EmitModes.js:\r\n case EmitModes.js_dts:\r\n await this.emitJsFiles();\r\n break;\r\n case EmitModes.dts:\r\n await this.emitJsFiles(true);\r\n break;\r\n case EmitModes.ts:\r\n await this.emitTsFiles();\r\n break;\r\n default:\r\n throw new Error(`Emit mode \"${this.emitMode}\" is invalid!`);\r\n }\r\n }\r\n\r\n private async emitJsFiles(declarationOnly?: boolean) {\r\n console.log(\r\n declarationOnly\r\n ? \"Emitting declaration files\"\r\n : `Emitting JS files (${this.emitMode === EmitModes.js_dts ? \"including\" : \"without\"} declaration files)`\r\n );\r\n\r\n await this.project.emit({ emitOnlyDtsFiles: !!declarationOnly });\r\n\r\n /* for (const diagnostic of this.project.getPreEmitDiagnostics()) {\r\n console.log(diagnostic.getMessageText());\r\n } */\r\n }\r\n\r\n private async emitTsFiles() {\r\n const files = [this.getModelFile(), this.getQObjectFile(), this.getMainServiceFile(), ...this.getServiceFiles()];\r\n console.log(`Emitting ${files.length} TS files`);\r\n return Promise.all([...files.filter((file) => !!file).map(this.formatAndWriteFile)]);\r\n }\r\n\r\n private formatAndWriteFile = async (file: SourceFile) => {\r\n const fileName = file.getFilePath();\r\n const content = file.getFullText();\r\n\r\n try {\r\n const formatted = await this.formatter.format(content);\r\n\r\n try {\r\n return writeFile(fileName, formatted);\r\n } catch (writeError) {\r\n console.error(`Failed to write file [/${fileName}]`, writeError);\r\n process.exit(3);\r\n }\r\n } catch (formattingError) {\r\n console.error(\"Formatting failed\");\r\n await writeFile(\"error.log\", formattingError?.toString() || \"no error message!\");\r\n process.exit(99);\r\n }\r\n };\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odata2ts/odata2ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -86,6 +86,6 @@
|
|
|
86
86
|
"typescript": "^5.1.3"
|
|
87
87
|
},
|
|
88
88
|
"types": "./lib/index.d.ts",
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "bf7321302887f9c70c2933467fd11859360aac6d",
|
|
90
90
|
"readme": "README.md"
|
|
91
91
|
}
|