@odata2ts/odata2ts 0.34.0 → 0.36.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 +24 -0
- package/README.md +81 -81
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/TypeModel.js.map +1 -1
- package/lib/app.js +1 -0
- package/lib/app.js.map +1 -1
- package/lib/cli.js.map +1 -1
- package/lib/data-model/DataModel.js +20 -3
- package/lib/data-model/DataModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +15 -0
- package/lib/data-model/DataModelDigestion.js +75 -23
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +3 -0
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/edmx/ODataEdmxModelBase.d.ts +1 -1
- package/lib/data-model/edmx/ODataEdmxModelBase.js.map +1 -1
- package/lib/data-model/validation/NameClashValidator.js +12 -2
- package/lib/data-model/validation/NameClashValidator.js.map +1 -1
- package/lib/data-model/validation/NameValidator.js.map +1 -1
- package/lib/data-model/validation/NoopValidator.js.map +1 -1
- package/lib/generator/ImportContainer.d.ts +10 -8
- package/lib/generator/ImportContainer.js +93 -72
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/ImportedNameValidator.js.map +1 -1
- package/lib/generator/ModelGenerator.js +40 -15
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.js +42 -33
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.js +38 -25
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/generator/import/ImportObjects.d.ts +12 -12
- package/lib/generator/import/ImportObjects.js +12 -12
- package/lib/generator/import/ImportObjects.js.map +1 -1
- package/lib/project/FileHandler.d.ts +4 -14
- package/lib/project/FileHandler.js +14 -6
- package/lib/project/FileHandler.js.map +1 -1
- package/lib/project/ProjectManager.d.ts +1 -0
- package/lib/project/ProjectManager.js +8 -5
- package/lib/project/ProjectManager.js.map +1 -1
- package/lib/project/TsMorphHelper.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
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.36.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.35.0...@odata2ts/odata2ts@0.36.0) (2024-07-31)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **generator:** add ts-nocheck to each generated file by default ([#284](https://github.com/odata2ts/odata2ts/issues/284)) ([655a3ab](https://github.com/odata2ts/odata2ts/commit/655a3ab801c79e34841f35b1a72cf7d02064f3b8))
|
|
11
|
+
* **generator:** generate services based on API reference chain ([#275](https://github.com/odata2ts/odata2ts/issues/275)) ([8fd415b](https://github.com/odata2ts/odata2ts/commit/8fd415bd0a49144e14da08cd5e32d44e947c7f23))
|
|
12
|
+
* **generator:** support function overloads for different parameter sets ([#282](https://github.com/odata2ts/odata2ts/issues/282)) ([0b53271](https://github.com/odata2ts/odata2ts/commit/0b532710499d975155c21984a62707ecf4789439))
|
|
13
|
+
* **generator:** support type-only imports ([#290](https://github.com/odata2ts/odata2ts/issues/290)) ([dea381e](https://github.com/odata2ts/odata2ts/commit/dea381e7c31f84e03acbaafc15ede58aa9041c13))
|
|
14
|
+
* model files always get type checked (no [@ts-nocheck](https://github.com/ts-nocheck)) ([#288](https://github.com/odata2ts/odata2ts/issues/288)) ([43ca58b](https://github.com/odata2ts/odata2ts/commit/43ca58bf72bb8e783b80798eaa73d5fd19676627))
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* **generator:** generated code won't be type checked anymore. Use `debug: true` to get type checking back.
|
|
19
|
+
|
|
20
|
+
# [0.35.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.34.0...@odata2ts/odata2ts@0.35.0) (2024-05-16)
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* empty enum ([#270](https://github.com/odata2ts/odata2ts/issues/270)) ([32eeb1e](https://github.com/odata2ts/odata2ts/commit/32eeb1e587f507a138ca96d81c7ab3da4c0bdba8))
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* invariant client type ([#272](https://github.com/odata2ts/odata2ts/issues/272)) ([0ee3c94](https://github.com/odata2ts/odata2ts/commit/0ee3c94d3bf34e7774e1be8dad657ed5e64e597e))
|
|
29
|
+
|
|
6
30
|
# [0.34.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.33.2...@odata2ts/odata2ts@0.34.0) (2024-05-03)
|
|
7
31
|
|
|
8
32
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
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
|
-
|
|
14
|
-
- generation of TypeScript files or compiled JS / DTS files
|
|
15
|
-
- name or rename stuff
|
|
16
|
-
- naming of pretty much any aspect of the generated artefacts
|
|
17
|
-
- e.g. all types should be prefixed with an "I", Person => IPerson
|
|
18
|
-
- consistent casing (as in "camelCase" or "PascalCase") even for property names of entity types
|
|
19
|
-
- use type converters
|
|
20
|
-
|
|
21
|
-
See the [generator documentation](https://odata2ts.github.io/docs/generator/setup-and-usage) for more information.
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
npm install --save-dev @odata2ts/odata2ts
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Implicit Dependencies
|
|
30
|
-
|
|
31
|
-
Most of the generated artefacts depend on other libraries. `odata2ts` lists them as peer dependencies.
|
|
32
|
-
|
|
33
|
-
Depending on your use case, you will need to add runtime dependencies matching the mentioned peer dependencies.
|
|
34
|
-
See the [Getting Started Guide](https://odata2ts.github.io/docs/category/getting-started/) of the documentation
|
|
35
|
-
for guidance.
|
|
36
|
-
|
|
37
|
-
## Documentation
|
|
38
|
-
|
|
39
|
-
[Generator Documentation](https://odata2ts.github.io/docs/generator/setup-and-usage)
|
|
40
|
-
|
|
41
|
-
Main documentation for the odata2ts eco system:
|
|
42
|
-
[https://odata2ts.github.io](https://odata2ts.github.io/)
|
|
43
|
-
|
|
44
|
-
## Examples
|
|
45
|
-
|
|
46
|
-
See [example packages](https://github.com/odata2ts/odata2ts/tree/main/examples) for examples of how to integrate `odata2ts`.
|
|
47
|
-
|
|
48
|
-
## Tests
|
|
49
|
-
|
|
50
|
-
See folder [test](https://github.com/odata2ts/odata2ts/tree/main/packages/odata2ts/test)
|
|
51
|
-
for unit tests.
|
|
52
|
-
|
|
53
|
-
See folder [int-test](https://github.com/odata2ts/odata2ts/tree/main/packages/odata2ts/int-test) for integration
|
|
54
|
-
tests of the CLI.
|
|
55
|
-
|
|
56
|
-
Each example package serves as integration test of the generator.
|
|
57
|
-
|
|
58
|
-
## Support, Feedback, Contributing
|
|
59
|
-
|
|
60
|
-
This project is open to feature requests, suggestions, bug reports, usage questions etc.
|
|
61
|
-
via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
|
|
62
|
-
|
|
63
|
-
Contributions and feedback are encouraged and always welcome.
|
|
64
|
-
|
|
65
|
-
See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
|
|
66
|
-
|
|
67
|
-
## Spirit
|
|
68
|
-
|
|
69
|
-
This project and this module have been created and are maintained in the following spirit:
|
|
70
|
-
|
|
71
|
-
- adhere to the **OData specification** as much as possible
|
|
72
|
-
- support any OData service implementation which conforms to the spec
|
|
73
|
-
- allow to work around faulty implementations if possible
|
|
74
|
-
- stability matters
|
|
75
|
-
- exercise Test Driven Development
|
|
76
|
-
- bomb the place with unit tests (code coverage > 95%)
|
|
77
|
-
- ensure that assumptions & understanding are correct by creating integration tests
|
|
78
|
-
|
|
79
|
-
## License
|
|
80
|
-
|
|
81
|
-
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
|
+
|
|
14
|
+
- generation of TypeScript files or compiled JS / DTS files
|
|
15
|
+
- name or rename stuff
|
|
16
|
+
- naming of pretty much any aspect of the generated artefacts
|
|
17
|
+
- e.g. all types should be prefixed with an "I", Person => IPerson
|
|
18
|
+
- consistent casing (as in "camelCase" or "PascalCase") even for property names of entity types
|
|
19
|
+
- use type converters
|
|
20
|
+
|
|
21
|
+
See the [generator documentation](https://odata2ts.github.io/docs/generator/setup-and-usage) for more information.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
npm install --save-dev @odata2ts/odata2ts
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Implicit Dependencies
|
|
30
|
+
|
|
31
|
+
Most of the generated artefacts depend on other libraries. `odata2ts` lists them as peer dependencies.
|
|
32
|
+
|
|
33
|
+
Depending on your use case, you will need to add runtime dependencies matching the mentioned peer dependencies.
|
|
34
|
+
See the [Getting Started Guide](https://odata2ts.github.io/docs/category/getting-started/) of the documentation
|
|
35
|
+
for guidance.
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
[Generator Documentation](https://odata2ts.github.io/docs/generator/setup-and-usage)
|
|
40
|
+
|
|
41
|
+
Main documentation for the odata2ts eco system:
|
|
42
|
+
[https://odata2ts.github.io](https://odata2ts.github.io/)
|
|
43
|
+
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
See [example packages](https://github.com/odata2ts/odata2ts/tree/main/examples) for examples of how to integrate `odata2ts`.
|
|
47
|
+
|
|
48
|
+
## Tests
|
|
49
|
+
|
|
50
|
+
See folder [test](https://github.com/odata2ts/odata2ts/tree/main/packages/odata2ts/test)
|
|
51
|
+
for unit tests.
|
|
52
|
+
|
|
53
|
+
See folder [int-test](https://github.com/odata2ts/odata2ts/tree/main/packages/odata2ts/int-test) for integration
|
|
54
|
+
tests of the CLI.
|
|
55
|
+
|
|
56
|
+
Each example package serves as integration test of the generator.
|
|
57
|
+
|
|
58
|
+
## Support, Feedback, Contributing
|
|
59
|
+
|
|
60
|
+
This project is open to feature requests, suggestions, bug reports, usage questions etc.
|
|
61
|
+
via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
|
|
62
|
+
|
|
63
|
+
Contributions and feedback are encouraged and always welcome.
|
|
64
|
+
|
|
65
|
+
See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
|
|
66
|
+
|
|
67
|
+
## Spirit
|
|
68
|
+
|
|
69
|
+
This project and this module have been created and are maintained in the following spirit:
|
|
70
|
+
|
|
71
|
+
- adhere to the **OData specification** as much as possible
|
|
72
|
+
- support any OData service implementation which conforms to the spec
|
|
73
|
+
- allow to work around faulty implementations if possible
|
|
74
|
+
- stability matters
|
|
75
|
+
- exercise Test Driven Development
|
|
76
|
+
- bomb the place with unit tests (code coverage > 95%)
|
|
77
|
+
- ensure that assumptions & understanding are correct by creating integration tests
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT - see [License](./LICENSE).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FactoryFunctionModel.js","sourceRoot":"","sources":["../src/FactoryFunctionModel.ts"],"names":[],"mappings":"","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\nimport { SourceFile } from \"ts-morph\";\n\nimport { DataModel } from \"./data-model/DataModel\";\nimport { Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\nimport { NamingHelper } from \"./data-model/NamingHelper\";\nimport { RunOptions } from \"./OptionModel\";\nimport { ProjectManager } from \"./project/ProjectManager\";\n\nexport type DigestionOptions = Pick<\n RunOptions,\n | \"converters\"\n | \"disableAutoManagedKey\"\n | \"propertiesByName\"\n | \"byTypeAndName\"\n | \"v2ModelsWithExtraResultsWrapping\"\n | \"v4BigNumberAsString\"\n | \"skipEditableModels\"\n | \"skipComments\"\n | \"disableAutomaticNameClashResolution\"\n | \"bundledFileGeneration\"\n>;\n\n/**\n * Takes an EdmxSchema plus the run options and creates a DataModel.\n */\nexport type DigesterFunction<S extends Schema<any, any>> = (\n schema: Array<S>,\n options: DigestionOptions,\n namingHelper: NamingHelper\n) => Promise<DataModel>;\n\nexport type GeneratorFunctionOptions = Pick<\n RunOptions,\n \"skipEditableModels\" | \"skipIdModels\" | \"skipOperations\" | \"skipComments\" | \"v2ModelsWithExtraResultsWrapping\"\n>;\n\nexport type EntityBasedGeneratorFunction = (\n project: ProjectManager,\n dataModel: DataModel,\n version: ODataVersions,\n options: GeneratorFunctionOptions,\n namingHelper: NamingHelper\n) => Promise<void>;\n"]}
|
|
1
|
+
{"version":3,"file":"FactoryFunctionModel.js","sourceRoot":"","sources":["../src/FactoryFunctionModel.ts"],"names":[],"mappings":"","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { SourceFile } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"./data-model/DataModel\";\r\nimport { Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { RunOptions } from \"./OptionModel\";\r\nimport { ProjectManager } from \"./project/ProjectManager\";\r\n\r\nexport type DigestionOptions = Pick<\r\n RunOptions,\r\n | \"converters\"\r\n | \"disableAutoManagedKey\"\r\n | \"propertiesByName\"\r\n | \"byTypeAndName\"\r\n | \"v2ModelsWithExtraResultsWrapping\"\r\n | \"v4BigNumberAsString\"\r\n | \"skipEditableModels\"\r\n | \"skipComments\"\r\n | \"disableAutomaticNameClashResolution\"\r\n | \"bundledFileGeneration\"\r\n>;\r\n\r\n/**\r\n * Takes an EdmxSchema plus the run options and creates a DataModel.\r\n */\r\nexport type DigesterFunction<S extends Schema<any, any>> = (\r\n schema: Array<S>,\r\n options: DigestionOptions,\r\n namingHelper: NamingHelper\r\n) => Promise<DataModel>;\r\n\r\nexport type GeneratorFunctionOptions = Pick<\r\n RunOptions,\r\n \"skipEditableModels\" | \"skipIdModels\" | \"skipOperations\" | \"skipComments\" | \"v2ModelsWithExtraResultsWrapping\"\r\n>;\r\n\r\nexport type EntityBasedGeneratorFunction = (\r\n project: ProjectManager,\r\n dataModel: DataModel,\r\n version: ODataVersions,\r\n options: GeneratorFunctionOptions,\r\n namingHelper: NamingHelper\r\n) => Promise<void>;\r\n"]}
|
package/lib/TypeModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeModel.js","sourceRoot":"","sources":["../src/TypeModel.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAWX;AAXD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,oCAAuB,CAAA;IACvB,oCAAuB,CAAA;IACvB,sCAAyB,CAAA;IACzB,wCAA2B,CAAA;IAC3B,kCAAqB,CAAA;IACrB,yDAAyD;IACzD,4CAA+B,CAAA;IAC/B,mDAAmD;IACnD,wDAA2C,CAAA;AAC7C,CAAC,EAXW,SAAS,yBAAT,SAAS,QAWpB","sourcesContent":["export enum TypeModel {\n Any = \"Any\",\n EntitySet = \"EntitySet\",\n Singleton = \"Singleton\",\n EntityType = \"EntityType\",\n ComplexType = \"ComplexType\",\n EnumType = \"EnumType\",\n // Bundle Function and Action (bound or unbound; v4 only)\n OperationType = \"OperationType\",\n // Bundles ActionImport and FunctionImport elements\n OperationImportType = \"OperationImportType\",\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TypeModel.js","sourceRoot":"","sources":["../src/TypeModel.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAWX;AAXD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,oCAAuB,CAAA;IACvB,oCAAuB,CAAA;IACvB,sCAAyB,CAAA;IACzB,wCAA2B,CAAA;IAC3B,kCAAqB,CAAA;IACrB,yDAAyD;IACzD,4CAA+B,CAAA;IAC/B,mDAAmD;IACnD,wDAA2C,CAAA;AAC7C,CAAC,EAXW,SAAS,yBAAT,SAAS,QAWpB","sourcesContent":["export enum TypeModel {\r\n Any = \"Any\",\r\n EntitySet = \"EntitySet\",\r\n Singleton = \"Singleton\",\r\n EntityType = \"EntityType\",\r\n ComplexType = \"ComplexType\",\r\n EnumType = \"EnumType\",\r\n // Bundle Function and Action (bound or unbound; v4 only)\r\n OperationType = \"OperationType\",\r\n // Bundles ActionImport and FunctionImport elements\r\n OperationImportType = \"OperationImportType\",\r\n}\r\n"]}
|
package/lib/app.js
CHANGED
|
@@ -65,6 +65,7 @@ function runApp(metadataJson, options) {
|
|
|
65
65
|
usePrettier: options.prettier,
|
|
66
66
|
tsConfigPath: options.tsconfig,
|
|
67
67
|
bundledFileGeneration: options.bundledFileGeneration,
|
|
68
|
+
allowTypeChecking: options.debug,
|
|
68
69
|
});
|
|
69
70
|
// const promises: Array<Promise<void>> = [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O,EAAE,YAAY,CAAC,CAAC;QACzE,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAE9C,yBAAyB;QACzB,gDAAgD;QAChD,mJAAmJ;QACnJ,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,2FAA2F;YAC3F,MAAM,IAAA,gCAAoB,EAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YAC/E,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;SAClD;QAED,oCAAoC;QACpC,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,uFAAuF;YACvF,MAAM,IAAA,4BAAgB,EAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;YAC3E,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;SACjD;QAED,+BAA+B;QAC/B,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACxC,CAAC;CAAA;AAvED,wBAuEC","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { pascalCase } from \"pascal-case\";\r\n\r\nimport { NamespaceWithAlias } from \"./data-model/DataModel\";\r\nimport { digest as digestV2 } from \"./data-model/DataModelDigestionV2\";\r\nimport { digest as digestV4 } from \"./data-model/DataModelDigestionV4\";\r\nimport { ODataEdmxModelBase } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { SchemaV3 } from \"./data-model/edmx/ODataEdmxModelV3\";\r\nimport { SchemaV4 } from \"./data-model/edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { generateModels, generateQueryObjects, generateServices } from \"./generator\";\r\nimport { Modes, RunOptions } from \"./OptionModel\";\r\nimport { createProjectManager } from \"./project/ProjectManager\";\r\n\r\nfunction isQObjectGen(mode: Modes) {\r\n return [Modes.qobjects, Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\nfunction isServiceGen(mode: Modes) {\r\n return [Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\nfunction getServiceName(options: RunOptions, schemas: Array<SchemaV3 | SchemaV4>) {\r\n if (options.serviceName) {\r\n return options.serviceName;\r\n }\r\n\r\n // auto-detection of first namespace with defined EntityTypes\r\n // NOTE: we make use of PascalCase here to enforce valid class names\r\n const detectedSchema = schemas.find((schema) => schema.$.Namespace && schema.EntityType?.length) || schemas[0];\r\n const serviceName = detectedSchema.$.Namespace;\r\n return pascalCase(serviceName);\r\n}\r\n\r\n/**\r\n *\r\n * @param metadataJson metadata of a given OData service already parsed as JSON\r\n * @param options further options\r\n */\r\nexport async function runApp(metadataJson: ODataEdmxModelBase<any>, options: RunOptions): Promise<void> {\r\n // determine edmx edmxVersion attribute\r\n const edmxVersion = metadataJson[\"edmx:Edmx\"].$.Version;\r\n const version = edmxVersion === \"1.0\" ? ODataVersions.V2 : ODataVersions.V4;\r\n\r\n const dataService = metadataJson[\"edmx:Edmx\"][\"edmx:DataServices\"][0];\r\n const schemas = dataService.Schema as Array<SchemaV3 | SchemaV4>;\r\n\r\n const serviceName = getServiceName(options, schemas);\r\n\r\n const namespaces = schemas.map<NamespaceWithAlias>((schema) => [schema.$.Namespace, schema.$.Alias]);\r\n\r\n // encapsulate the whole naming logic\r\n const namingHelper = new NamingHelper(options, serviceName, namespaces);\r\n // parse model information from edmx into something we can really work with\r\n // => that stuff is called dataModel!\r\n const dataModel =\r\n version === ODataVersions.V2\r\n ? await digestV2(dataService.Schema as Array<SchemaV3>, options, namingHelper)\r\n : await digestV4(dataService.Schema as Array<SchemaV4>, options, namingHelper);\r\n\r\n // Validation of entity names: the same name might be used across different namespaces\r\n const validationErrors = dataModel.getNameValidation();\r\n if (validationErrors.size) {\r\n console.log(\"---\");\r\n validationErrors.forEach((errors, name) => {\r\n console.log(\r\n `Duplicate name: ${name} - Fully Qualified Names: ${errors\r\n .map((error) => error.fqName + (error.renamedTo ? ` (renamed to: ${error.renamedTo})` : \"\"))\r\n .join(\", \")}`\r\n );\r\n });\r\n\r\n if (options.disableAutomaticNameClashResolution) {\r\n throw new Error(\"Name validation failed: Multiple entities have the same name across different namespaces!\");\r\n }\r\n }\r\n\r\n // handling the overall generation project\r\n const project = await createProjectManager(options.output, options.emitMode, namingHelper, dataModel, {\r\n usePrettier: options.prettier,\r\n tsConfigPath: options.tsconfig,\r\n bundledFileGeneration: options.bundledFileGeneration,\r\n allowTypeChecking: options.debug,\r\n });\r\n\r\n // const promises: Array<Promise<void>> = [\r\n // Generate Model Interfaces\r\n // generateModels(project, dataModel, version, options, namingHelper),\r\n // ];\r\n await generateModels(project, dataModel, version, options, namingHelper);\r\n console.log(\"Successfully generated models!\");\r\n\r\n // Generate Query Objects\r\n // supported edmx types: EntityType, ComplexType\r\n // supported edmx prop types: primitive types, enum types, primitive collection (incl enum types), entity collection, entity object, complex object\r\n if (isQObjectGen(options.mode)) {\r\n // promises.push(generateQueryObjects(project, dataModel, version, options, namingHelper));\r\n await generateQueryObjects(project, dataModel, version, options, namingHelper);\r\n console.log(\"Successfully generated q-objects!\");\r\n }\r\n\r\n // Generate Individual OData-Service\r\n if (isServiceGen(options.mode)) {\r\n // promises.push(generateServices(project, dataModel, version, namingHelper, options));\r\n await generateServices(project, dataModel, version, namingHelper, options);\r\n console.log(\"Successfully generated services!\");\r\n }\r\n\r\n // await Promise.all(promises);\r\n console.log(\"Successfully finished!\");\r\n}\r\n"]}
|
package/lib/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;AAAA,+DAA8C;AAC9C,6CAA0C;AAC1C,iFAAiE;AACjE,uCAA0D;AAC1D,mCAA4C;AAE5C,+BAA+B;AAE/B,0CAA8D;AAC9D,qDAAyD;AACzD,+CAAoH;AACpH,8DAA2D;AAE3D,SAAS,SAAS,CAAC,KAAa,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B,EAAE,MAAM,CAAC,CAAC;YACnD,WAAW,GAAG,MAAM,IAAA,mBAAQ,EAAC,MAAM,CAAC,CAAC;SACtC;QAED,MAAM,YAAY,GAAG,CAAC,MAAM,IAAA,2BAAkB,EAAC,WAAW,CAAC,CAA4B,CAAC;QACxF,sDAAsD;QACtD,iEAAiE;QACjE,iFAAiF;QAEjF,sCAAsC;QACtC,IAAI;YACF,MAAM,IAAA,mBAAQ,EAAC,MAAM,CAAC,CAAC;SACxB;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,gBAAgB,MAAM,wBAAwB,EAAE,KAAK,CAAC,CAAC;YACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,cAAc;QACd,IAAI;YACF,MAAM,IAAA,YAAM,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;SACrC;QAAC,OAAO,GAAQ,EAAE;YACjB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAClB;IACH,CAAC;CAAA","sourcesContent":["import commander, { Option } from \"commander\";\nimport { cosmiconfig } from \"cosmiconfig\";\nimport { TypeScriptLoader } from \"cosmiconfig-typescript-loader\";\nimport { emptyDir, pathExists, readFile } from \"fs-extra\";\nimport { parseStringPromise } from \"xml2js\";\n\nimport { runApp } from \"./app\";\nimport { ODataEdmxModelBase } from \"./data-model/edmx/ODataEdmxModelBase\";\nimport { downloadMetadata, storeMetadata } from \"./download/\";\nimport { evaluateConfigOptions } from \"./evaluateConfig\";\nimport { CliOptions, ConfigFileOptions, EmitModes, Modes, RunOptions, UrlSourceConfiguration } from \"./OptionModel\";\nimport { logFilePath } from \"./project/logger/logFilePath\";\n\nfunction parseMode(value: string, dummyPrevious: Modes | undefined) {\n switch (value) {\n case \"models\":\n return Modes.models;\n case \"qobjects\":\n return Modes.qobjects;\n case \"service\":\n return Modes.service;\n case \"all\":\n return Modes.all;\n default:\n throw new Error(`Not a valid Mode: ${value}`);\n }\n}\n\nfunction parseEmitMode(value: string, dummyPrevious: EmitModes) {\n switch (value) {\n case \"dts\":\n return EmitModes.dts;\n case \"js\":\n return EmitModes.js;\n case \"ts\":\n return EmitModes.ts;\n case \"js_dts\":\n return EmitModes.js_dts;\n default:\n throw new Error(`Not a valid EmitMode: ${value}`);\n }\n}\n\nfunction processCliArgs() {\n const cli = new commander.Command()\n .version(\"0.3.0\")\n .description(\"CLI to generate Typescript Interfaces for models of a given OData service.\")\n .argument(\"[services...]\", \"Run the generation process only for certain services specified in config file\", [])\n .option(\"-s, --source <url or metadata.xml>\", \"Path to metadata file\")\n .option(\"-o, --output <path>\", \"Output location for generated files\")\n .option(\"-u, --source-url <sourceUrl>\", \"URL to the root of the OData service\")\n .option(\n \"-f, --refresh-file\",\n \"Download metadata again and overwrite existing file (only applies if sourceUrl is specified)\"\n )\n .addOption(\n new Option(\"-m, --mode <mode>\", \"What kind of stuff gets generated\")\n .choices(Object.values(Modes).filter((t): t is string => isNaN(Number(t))))\n .argParser<Modes>(parseMode)\n )\n .addOption(\n new Option(\n \"-e, --emit-mode <mode>\",\n \"Output TS source files, compiled JS files with/wihthout generated d.ts files\"\n )\n .choices(Object.values(EmitModes))\n .argParser<EmitModes>(parseEmitMode)\n )\n .option(\"-p, --prettier\", \"Format result with prettier (only applies if emitMode=ts)\")\n .option(\n \"-t, --tsconfig <path>\",\n \"Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)\"\n )\n .option(\"-d, --debug\", \"Verbose debug infos\")\n .option(\"-name, --service-name <serviceName>\", \"Give the service your own name\")\n .option(\n \"-n, --disable-auto-managed-key\",\n \"Don't mark single key props as managed by the server side (not editable)\"\n )\n .option(\"-r, --allow-renaming\", \"Allow that property and entity names may be changed by configured casing\")\n .parse(process.argv);\n\n const args = cli.args?.length ? { services: cli.args } : {};\n return {\n ...cli.opts(),\n ...args,\n } as CliOptions;\n}\n\nasync function processConfigFile() {\n const moduleName = \"odata2ts\";\n const explorer = cosmiconfig(moduleName, {\n searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`],\n loaders: {\n \".ts\": TypeScriptLoader(),\n },\n });\n const discoveredConfig = await explorer.search();\n\n if (discoveredConfig?.config) {\n console.log(\"Loaded config file: \", logFilePath(discoveredConfig.filepath));\n } else {\n console.log(\"No config file found.\");\n }\n\n return discoveredConfig?.config as ConfigFileOptions;\n}\n\nexport class Cli {\n async run(): Promise<void> {\n let runs;\n try {\n const cliOpts = processCliArgs();\n if (cliOpts.debug) {\n console.log(\"CLI opts:\", cliOpts);\n }\n const fileOpts = await processConfigFile();\n\n runs = evaluateConfigOptions(cliOpts, fileOpts);\n } catch (error: any) {\n console.error(\"Bad arguments!\", error?.message);\n process.exit(1);\n }\n\n for (let run of runs) {\n await startServiceGenerationRun(run);\n }\n }\n}\n\nasync function startServiceGenerationRun(options: RunOptions) {\n const { source, output, sourceUrl, refreshFile, sourceUrlConfig, debug, mode, emitMode, prettier, serviceName } =\n options;\n console.log(\"---------------------------\");\n console.log(\n `Starting generation process. Service name ${serviceName ? `\"${serviceName}\"` : \"will be detected automatically!\"}`\n );\n\n if (debug) {\n console.log(\"Resolved config:\", {\n source,\n output,\n sourceUrl,\n refreshFile,\n debug,\n mode: Modes[mode],\n emitMode,\n prettier,\n serviceName,\n });\n }\n\n // evaluate source\n const exists = await pathExists(source);\n console.log(`${exists ? \"Found\" : \"Didn't find\"} metadata file at: `, source);\n\n let metadataXml;\n // download metadata and store on disk\n if (sourceUrl && (!exists || refreshFile)) {\n try {\n metadataXml = await downloadMetadata(sourceUrl, sourceUrlConfig, debug);\n } catch (e) {\n console.error(`Failed to load metadata! Message: ${(e as Error)?.message}`);\n process.exit(10);\n }\n metadataXml = await storeMetadata(source, metadataXml, prettier);\n }\n // otherwise file must exist\n else if (!exists) {\n console.error(`Input source [${source}] doesn't exist!`);\n process.exit(2);\n }\n // read the metadata from file\n else {\n console.log(\"Reading metadata from file:\", source);\n metadataXml = await readFile(source);\n }\n\n const metadataJson = (await parseStringPromise(metadataXml)) as ODataEdmxModelBase<any>;\n // TODO find out if \"1.0\" and \"4.0\" are really correct\n // TODO exit here if no version not suitable version was detected\n // console.log(`OData version detected: ${metadataJson[\"edmx:Edmx\"].$.Version}`);\n\n // ensure that output directory exists\n try {\n await emptyDir(output);\n } catch (error) {\n console.error(`Output path [${output}] couldn't be created!`, error);\n process.exit(3);\n }\n\n // run the app\n try {\n await runApp(metadataJson, options);\n } catch (err: any) {\n console.error(\"Error while running the program\", err);\n process.exit(99);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;AAAA,+DAA8C;AAC9C,6CAA0C;AAC1C,iFAAiE;AACjE,uCAA0D;AAC1D,mCAA4C;AAE5C,+BAA+B;AAE/B,0CAA8D;AAC9D,qDAAyD;AACzD,+CAAoH;AACpH,8DAA2D;AAE3D,SAAS,SAAS,CAAC,KAAa,EAAE,aAAgC;IAChE,QAAQ,KAAK,EAAE;QACb,KAAK,QAAQ;YACX,OAAO,mBAAK,CAAC,MAAM,CAAC;QACtB,KAAK,UAAU;YACb,OAAO,mBAAK,CAAC,QAAQ,CAAC;QACxB,KAAK,SAAS;YACZ,OAAO,mBAAK,CAAC,OAAO,CAAC;QACvB,KAAK,KAAK;YACR,OAAO,mBAAK,CAAC,GAAG,CAAC;QACnB;YACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC;KACjD;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAa,EAAE,aAAwB;IAC5D,QAAQ,KAAK,EAAE;QACb,KAAK,KAAK;YACR,OAAO,uBAAS,CAAC,GAAG,CAAC;QACvB,KAAK,IAAI;YACP,OAAO,uBAAS,CAAC,EAAE,CAAC;QACtB,KAAK,IAAI;YACP,OAAO,uBAAS,CAAC,EAAE,C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;YACjB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAClB;IACH,CAAC;CAAA","sourcesContent":["import commander, { Option } from \"commander\";\r\nimport { cosmiconfig } from \"cosmiconfig\";\r\nimport { TypeScriptLoader } from \"cosmiconfig-typescript-loader\";\r\nimport { emptyDir, pathExists, readFile } from \"fs-extra\";\r\nimport { parseStringPromise } from \"xml2js\";\r\n\r\nimport { runApp } from \"./app\";\r\nimport { ODataEdmxModelBase } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { downloadMetadata, storeMetadata } from \"./download/\";\r\nimport { evaluateConfigOptions } from \"./evaluateConfig\";\r\nimport { CliOptions, ConfigFileOptions, EmitModes, Modes, RunOptions, UrlSourceConfiguration } from \"./OptionModel\";\r\nimport { logFilePath } from \"./project/logger/logFilePath\";\r\n\r\nfunction parseMode(value: string, dummyPrevious: Modes | undefined) {\r\n switch (value) {\r\n case \"models\":\r\n return Modes.models;\r\n case \"qobjects\":\r\n return Modes.qobjects;\r\n case \"service\":\r\n return Modes.service;\r\n case \"all\":\r\n return Modes.all;\r\n default:\r\n throw new Error(`Not a valid Mode: ${value}`);\r\n }\r\n}\r\n\r\nfunction parseEmitMode(value: string, dummyPrevious: EmitModes) {\r\n switch (value) {\r\n case \"dts\":\r\n return EmitModes.dts;\r\n case \"js\":\r\n return EmitModes.js;\r\n case \"ts\":\r\n return EmitModes.ts;\r\n case \"js_dts\":\r\n return EmitModes.js_dts;\r\n default:\r\n throw new Error(`Not a valid EmitMode: ${value}`);\r\n }\r\n}\r\n\r\nfunction processCliArgs() {\r\n const cli = new commander.Command()\r\n .version(\"0.3.0\")\r\n .description(\"CLI to generate Typescript Interfaces for models of a given OData service.\")\r\n .argument(\"[services...]\", \"Run the generation process only for certain services specified in config file\", [])\r\n .option(\"-s, --source <url or metadata.xml>\", \"Path to metadata file\")\r\n .option(\"-o, --output <path>\", \"Output location for generated files\")\r\n .option(\"-u, --source-url <sourceUrl>\", \"URL to the root of the OData service\")\r\n .option(\r\n \"-f, --refresh-file\",\r\n \"Download metadata again and overwrite existing file (only applies if sourceUrl is specified)\"\r\n )\r\n .addOption(\r\n new Option(\"-m, --mode <mode>\", \"What kind of stuff gets generated\")\r\n .choices(Object.values(Modes).filter((t): t is string => isNaN(Number(t))))\r\n .argParser<Modes>(parseMode)\r\n )\r\n .addOption(\r\n new Option(\r\n \"-e, --emit-mode <mode>\",\r\n \"Output TS source files, compiled JS files with/wihthout generated d.ts files\"\r\n )\r\n .choices(Object.values(EmitModes))\r\n .argParser<EmitModes>(parseEmitMode)\r\n )\r\n .option(\"-p, --prettier\", \"Format result with prettier (only applies if emitMode=ts)\")\r\n .option(\r\n \"-t, --tsconfig <path>\",\r\n \"Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)\"\r\n )\r\n .option(\"-d, --debug\", \"Verbose debug infos\")\r\n .option(\"-name, --service-name <serviceName>\", \"Give the service your own name\")\r\n .option(\r\n \"-n, --disable-auto-managed-key\",\r\n \"Don't mark single key props as managed by the server side (not editable)\"\r\n )\r\n .option(\"-r, --allow-renaming\", \"Allow that property and entity names may be changed by configured casing\")\r\n .parse(process.argv);\r\n\r\n const args = cli.args?.length ? { services: cli.args } : {};\r\n return {\r\n ...cli.opts(),\r\n ...args,\r\n } as CliOptions;\r\n}\r\n\r\nasync function processConfigFile() {\r\n const moduleName = \"odata2ts\";\r\n const explorer = cosmiconfig(moduleName, {\r\n searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`],\r\n loaders: {\r\n \".ts\": TypeScriptLoader(),\r\n },\r\n });\r\n const discoveredConfig = await explorer.search();\r\n\r\n if (discoveredConfig?.config) {\r\n console.log(\"Loaded config file: \", logFilePath(discoveredConfig.filepath));\r\n } else {\r\n console.log(\"No config file found.\");\r\n }\r\n\r\n return discoveredConfig?.config as ConfigFileOptions;\r\n}\r\n\r\nexport class Cli {\r\n async run(): Promise<void> {\r\n let runs;\r\n try {\r\n const cliOpts = processCliArgs();\r\n if (cliOpts.debug) {\r\n console.log(\"CLI opts:\", cliOpts);\r\n }\r\n const fileOpts = await processConfigFile();\r\n\r\n runs = evaluateConfigOptions(cliOpts, fileOpts);\r\n } catch (error: any) {\r\n console.error(\"Bad arguments!\", error?.message);\r\n process.exit(1);\r\n }\r\n\r\n for (let run of runs) {\r\n await startServiceGenerationRun(run);\r\n }\r\n }\r\n}\r\n\r\nasync function startServiceGenerationRun(options: RunOptions) {\r\n const { source, output, sourceUrl, refreshFile, sourceUrlConfig, debug, mode, emitMode, prettier, serviceName } =\r\n options;\r\n console.log(\"---------------------------\");\r\n console.log(\r\n `Starting generation process. Service name ${serviceName ? `\"${serviceName}\"` : \"will be detected automatically!\"}`\r\n );\r\n\r\n if (debug) {\r\n console.log(\"Resolved config:\", {\r\n source,\r\n output,\r\n sourceUrl,\r\n refreshFile,\r\n debug,\r\n mode: Modes[mode],\r\n emitMode,\r\n prettier,\r\n serviceName,\r\n });\r\n }\r\n\r\n // evaluate source\r\n const exists = await pathExists(source);\r\n console.log(`${exists ? \"Found\" : \"Didn't find\"} metadata file at: `, source);\r\n\r\n let metadataXml;\r\n // download metadata and store on disk\r\n if (sourceUrl && (!exists || refreshFile)) {\r\n try {\r\n metadataXml = await downloadMetadata(sourceUrl, sourceUrlConfig, debug);\r\n } catch (e) {\r\n console.error(`Failed to load metadata! Message: ${(e as Error)?.message}`);\r\n process.exit(10);\r\n }\r\n metadataXml = await storeMetadata(source, metadataXml, prettier);\r\n }\r\n // otherwise file must exist\r\n else if (!exists) {\r\n console.error(`Input source [${source}] doesn't exist!`);\r\n process.exit(2);\r\n }\r\n // read the metadata from file\r\n else {\r\n console.log(\"Reading metadata from file:\", source);\r\n metadataXml = await readFile(source);\r\n }\r\n\r\n const metadataJson = (await parseStringPromise(metadataXml)) as ODataEdmxModelBase<any>;\r\n // TODO find out if \"1.0\" and \"4.0\" are really correct\r\n // TODO exit here if no version not suitable version was detected\r\n // console.log(`OData version detected: ${metadataJson[\"edmx:Edmx\"].$.Version}`);\r\n\r\n // ensure that output directory exists\r\n try {\r\n await emptyDir(output);\r\n } catch (error) {\r\n console.error(`Output path [${output}] couldn't be created!`, error);\r\n process.exit(3);\r\n }\r\n\r\n // run the app\r\n try {\r\n await runApp(metadataJson, options);\r\n } catch (err: any) {\r\n console.error(\"Error while running the program\", err);\r\n process.exit(99);\r\n }\r\n}\r\n"]}
|
|
@@ -138,6 +138,14 @@ class DataModel {
|
|
|
138
138
|
return [...this.models.values()].filter((m) => m.dataType === "EnumType" /* DataTypes.EnumType */);
|
|
139
139
|
}
|
|
140
140
|
addUnboundOperationType(namespace, operationType) {
|
|
141
|
+
// supporting function overrides
|
|
142
|
+
const isFunction = operationType.type === "Function" /* OperationTypes.Function */;
|
|
143
|
+
const existingFn = isFunction ? this.unboundOperationTypes.get(operationType.fqName) : undefined;
|
|
144
|
+
if (existingFn) {
|
|
145
|
+
const params = operationType.parameters;
|
|
146
|
+
existingFn.overrides ? existingFn.overrides.push(params) : (existingFn.overrides = [params]);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
141
149
|
this.unboundOperationTypes.set(operationType.fqName, operationType);
|
|
142
150
|
this.addAlias(namespace, operationType.odataName);
|
|
143
151
|
}
|
|
@@ -150,9 +158,18 @@ class DataModel {
|
|
|
150
158
|
addBoundOperationType(namespace, bindingProp, operationType) {
|
|
151
159
|
const fqEntityType = bindingProp.fqType;
|
|
152
160
|
const store = bindingProp.isCollection ? this.entityCollectionBoundOperationTypes : this.entityBoundOperationTypes;
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
|
|
161
|
+
const boundOps = store.get(fqEntityType);
|
|
162
|
+
if (boundOps) {
|
|
163
|
+
// supporting function overrides
|
|
164
|
+
const isFunction = operationType.type === "Function" /* OperationTypes.Function */;
|
|
165
|
+
const existingFn = isFunction ? boundOps.find((bo) => bo.fqName === operationType.fqName) : undefined;
|
|
166
|
+
if (existingFn) {
|
|
167
|
+
const params = operationType.parameters;
|
|
168
|
+
existingFn.overrides ? existingFn.overrides.push(params) : (existingFn.overrides = [params]);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
boundOps.push(operationType);
|
|
172
|
+
}
|
|
156
173
|
}
|
|
157
174
|
else {
|
|
158
175
|
store.set(fqEntityType, [operationType]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../src/data-model/DataModel.ts"],"names":[],"mappings":";;;AAGA,mDAcyB;AAczB,SAAgB,aAAa,CAAC,EAAU,EAAE,IAAY;IACpD,oHAAoH;IACpH,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACrC,CAAC;AAHD,sCAGC;AAED,MAAa,SAAS;IA+BpB,YACE,UAAqC,EAC7B,OAAqB,EAC7B,aAAoC,IAAI,GAAG,EAAE;QADrC,YAAO,GAAP,OAAO,CAAc;QA7BvB,WAAM,GAAG,IAAI,GAAG,EAA+C,CAAC;QACxE;;;WAGG;QACK,0BAAqB,GAAG,IAAI,GAAG,EAAyB,CAAC;QACjE;;;;WAIG;QACK,8BAAyB,GAAG,IAAI,GAAG,EAAgC,CAAC;QAC5E;;;;WAIG;QACK,wCAAmC,GAAG,IAAI,GAAG,EAAgC,CAAC;QACtF;;;WAGG;QACK,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;QAE5C,YAAO,GAA2B,EAAE,CAAC;QACrC,cAAS,GAAyB,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAOvG,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,MAAM,CAAyB,CAAC,GAAG,E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IAAI,SAAS,EAAE;wBACb,KAAK,CAAC,SAAS,CAAC,CAAC;qBAClB;iBACF;gBACD,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAC1B,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAChC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;QACH,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,KAAK,CAAC,KAAK,CAAC,CAAC;SACd;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,iBAAiB,CAAC,GAAmC;QAC1D,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC;IAC5B,CAAC;IAEM,iBAAiB;QACtB,OAAO,IAAI,CAAC,cAAe,CAAC;IAC9B,CAAC;CACF;AAvQD,8BAuQC","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\r\nimport { ODataTypesV2, ODataTypesV4 } from \"@odata2ts/odata-core\";\r\n\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntityContainerModel,\r\n EntitySetType,\r\n EntityType,\r\n EnumType,\r\n FunctionImportType,\r\n ModelType,\r\n ODataVersion,\r\n OperationType,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"./DataTypeModel\";\r\nimport { ValidationError } from \"./validation/NameValidator\";\r\n\r\nexport interface ProjectFiles {\r\n model: string;\r\n qObject: string;\r\n service: string;\r\n}\r\n\r\n/**\r\n * Each namespace is represented as tuple: 1. the namespace 2. the alias, if any.\r\n */\r\nexport type NamespaceWithAlias = [string, string?];\r\n\r\nexport function withNamespace(ns: string, name: string) {\r\n // this supports the edge case of an empty string as namespace which isn't really valid according to spec (see CSDL)\r\n return ns ? `${ns}.${name}` : name;\r\n}\r\n\r\nexport class DataModel {\r\n private readonly converters: MappedConverterChains;\r\n private nameValidation: Map<string, ValidationError[]> | undefined;\r\n\r\n private models = new Map<string, EntityType | ComplexType | EnumType>();\r\n /**\r\n * Stores unbound operations by their fully qualified name.\r\n * @private\r\n */\r\n private unboundOperationTypes = new Map<string, OperationType>();\r\n /**\r\n * Stores operations bound to an entity type by the fully qualified name of the binding entity, e.g.\r\n * \"Trippin.Person\".\r\n * @private\r\n */\r\n private entityBoundOperationTypes = new Map<string, Array<OperationType>>();\r\n /**\r\n * Stores operations bound to an entity collection by the fully qualified name of the binding entity, e.g.\r\n * \"Trippin.Person\".\r\n * @private\r\n */\r\n private entityCollectionBoundOperationTypes = new Map<string, Array<OperationType>>();\r\n /**\r\n * Stores own type definitions which map to primitive types.\r\n * @private\r\n */\r\n private typeDefinitions = new Map<string, string>();\r\n private readonly namespace2Alias: { [ns: string]: string };\r\n private aliases: Record<string, string> = {};\r\n private container: EntityContainerModel = { entitySets: {}, singletons: {}, functions: {}, actions: {} };\r\n\r\n constructor(\r\n namespaces: Array<NamespaceWithAlias>,\r\n private version: ODataVersion,\r\n converters: MappedConverterChains = new Map()\r\n ) {\r\n this.converters = converters;\r\n this.namespace2Alias = namespaces.reduce<Record<string, string>>((col, [ns, alias]) => {\r\n if (alias) {\r\n col[ns] = alias;\r\n }\r\n return col;\r\n }, {});\r\n }\r\n\r\n /**\r\n * OData version: 2.0 or 4.0.\r\n * @returns\r\n */\r\n public getODataVersion() {\r\n return this.version;\r\n }\r\n\r\n public isV2() {\r\n return this.version === ODataVersion.V2;\r\n }\r\n\r\n public isV4() {\r\n return this.version === ODataVersion.V4;\r\n }\r\n\r\n private retrieveType<T>(fqName: string, haystack: Map<string, T>): T | undefined {\r\n return haystack.get(fqName) || (this.aliases[fqName] ? haystack.get(this.aliases[fqName]) : undefined);\r\n }\r\n\r\n private addAlias(namespace: string, name: string) {\r\n const alias = this.namespace2Alias[namespace];\r\n if (alias) {\r\n this.aliases[withNamespace(alias, name)] = withNamespace(namespace, name);\r\n }\r\n }\r\n\r\n public addTypeDefinition(namespace: string, name: string, type: string) {\r\n const fqName = withNamespace(namespace, name);\r\n this.typeDefinitions.set(fqName, type);\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n public getPrimitiveType(fqName: string): string | undefined {\r\n return this.retrieveType(fqName, this.typeDefinitions);\r\n }\r\n\r\n public getModel(fqName: string) {\r\n return this.retrieveType(fqName, this.models);\r\n }\r\n\r\n public getModelTypes(): Array<ModelType> {\r\n return [...this.models.values()];\r\n }\r\n\r\n public addEntityType(namespace: string, name: string, model: Omit<EntityType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n\r\n this.models.set(fqName, { ...model, dataType: DataTypes.ModelType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get a specific model by its fully qualified name.\r\n *\r\n * @param fqName the fully qualified name of the entity\r\n * @returns the model type\r\n */\r\n public getEntityType(fqName: string) {\r\n return this.retrieveType(fqName, this.models) as EntityType;\r\n }\r\n\r\n /**\r\n * Retrieve all known EntityType models from the EDMX model.\r\n *\r\n * @returns list of model types\r\n */\r\n public getEntityTypes() {\r\n const ets = [...this.models.values()].filter((m): m is EntityType => m.dataType === DataTypes.ModelType);\r\n return this.sortModelsByInheritance(ets);\r\n }\r\n\r\n public addComplexType(namespace: string, name: string, model: Omit<ComplexType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n\r\n this.models.set(fqName, { ...model, dataType: DataTypes.ComplexType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get a specific model by its fully qualified name.\r\n *\r\n * @param fqName the final model name that is generated\r\n * @returns the model type\r\n */\r\n public getComplexType(fqName: string) {\r\n return this.retrieveType(fqName, this.models) as ComplexType;\r\n }\r\n\r\n /**\r\n * Retrieve all known ComplexType models from the EDMX model.\r\n *\r\n * @returns list of model types\r\n */\r\n public getComplexTypes() {\r\n const types = [...this.models.values()].filter((m): m is ComplexType => m.dataType === DataTypes.ComplexType);\r\n return this.sortModelsByInheritance(types);\r\n }\r\n\r\n public addEnum(namespace: string, name: string, type: Omit<EnumType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n\r\n this.models.set(fqName, { ...type, dataType: DataTypes.EnumType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get list of all known enums, i.e. EnumType nodes from the EDMX model.\r\n * @returns list of enum types\r\n */\r\n public getEnums() {\r\n return [...this.models.values()].filter((m): m is EnumType => m.dataType === DataTypes.EnumType);\r\n }\r\n\r\n public addUnboundOperationType(namespace: string, operationType: OperationType) {\r\n this.unboundOperationTypes.set(operationType.fqName, operationType);\r\n this.addAlias(namespace, operationType.odataName);\r\n }\r\n\r\n public getUnboundOperationTypes(): Array<OperationType> {\r\n return [...this.unboundOperationTypes.values()];\r\n }\r\n\r\n public getUnboundOperationType(fqOpName: string): OperationType | undefined {\r\n return this.retrieveType(fqOpName, this.unboundOperationTypes);\r\n }\r\n\r\n public addBoundOperationType(namespace: string, bindingProp: PropertyModel, operationType: OperationType) {\r\n const fqEntityType = bindingProp.fqType;\r\n\r\n const store = bindingProp.isCollection ? this.entityCollectionBoundOperationTypes : this.entityBoundOperationTypes;\r\n const list = store.get(fqEntityType);\r\n if (list) {\r\n list.push(operationType);\r\n } else {\r\n store.set(fqEntityType, [operationType]);\r\n }\r\n }\r\n\r\n public getEntityTypeOperations(fqEntityName: string): Array<OperationType> {\r\n const operations = this.retrieveType(fqEntityName, this.entityBoundOperationTypes);\r\n return operations || [];\r\n }\r\n\r\n public getEntitySetOperations(fqEntityName: string): Array<OperationType> {\r\n const operations = this.retrieveType(fqEntityName, this.entityCollectionBoundOperationTypes);\r\n return operations || [];\r\n }\r\n\r\n public getAllEntityOperations(fqEntityName: string): Array<OperationType> {\r\n return [...this.getEntityTypeOperations(fqEntityName), ...this.getEntitySetOperations(fqEntityName)];\r\n }\r\n\r\n public addAction(fqName: string, action: ActionImportType) {\r\n this.container.actions[fqName] = action;\r\n }\r\n\r\n public addFunction(fqName: string, func: FunctionImportType) {\r\n this.container.functions[fqName] = func;\r\n }\r\n\r\n public addSingleton(fqName: string, singleton: SingletonType) {\r\n this.container.singletons[fqName] = singleton;\r\n }\r\n\r\n public addEntitySet(fqName: string, entitySet: EntitySetType) {\r\n this.container.entitySets[fqName] = entitySet;\r\n }\r\n\r\n public getEntityContainer() {\r\n return this.container;\r\n }\r\n\r\n public getConverter(dataType: ODataTypesV2 | ODataTypesV4 | string) {\r\n return this.converters.get(dataType);\r\n }\r\n\r\n private sortModelsByInheritance<Type extends Omit<ComplexType, \"dataType\">>(models: Array<Type>): Array<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 sorted: Array<Type> = [];\r\n const visitedModels = new Set<string>();\r\n const inProgressModels = new Set<string>();\r\n\r\n function visit(model: Type) {\r\n const fqName = model.fqName;\r\n if (inProgressModels.has(fqName)) {\r\n throw new Error(`Cyclic inheritance detected for model \"${fqName}\"!`);\r\n }\r\n\r\n if (!visitedModels.has(fqName)) {\r\n inProgressModels.add(fqName);\r\n\r\n for (const baseClassName of model.baseClasses) {\r\n const baseClass = models.find((e) => e.fqName === baseClassName);\r\n if (baseClass) {\r\n visit(baseClass);\r\n }\r\n }\r\n visitedModels.add(fqName);\r\n inProgressModels.delete(fqName);\r\n sorted.push(model);\r\n }\r\n }\r\n\r\n for (const model of models) {\r\n visit(model);\r\n }\r\n return sorted;\r\n }\r\n\r\n public setNameValidation(map: Map<string, ValidationError[]>) {\r\n this.nameValidation = map;\r\n }\r\n\r\n public getNameValidation() {\r\n return this.nameValidation!;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../src/data-model/DataModel.ts"],"names":[],"mappings":";;;AAGA,mDAeyB;AAczB,SAAgB,aAAa,CAAC,EAAU,EAAE,IAAY;IACpD,oHAAoH;IACpH,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACrC,CAAC;AAHD,sCAGC;AAED,MAAa,SAAS;IA+BpB,YACE,UAAqC,EAC7B,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M,CAAC,EAAE;gBAChC,MAAM,IAAI,KAAK,CAAC,0CAA0C,MAAM,IAAI,CAAC,CAAC;aACvE;YAED,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;gBAC9B,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAE7B,KAAK,MAAM,aAAa,IAAI,KAAK,CAAC,WAAW,EAAE;oBAC7C,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,aAAa,CAAC,CAAC;oBACjE,IAAI,SAAS,EAAE;wBACb,KAAK,CAAC,SAAS,CAAC,CAAC;qBAClB;iBACF;gBACD,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAC1B,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAChC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;QACH,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,KAAK,CAAC,KAAK,CAAC,CAAC;SACd;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,iBAAiB,CAAC,GAAmC;QAC1D,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC;IAC5B,CAAC;IAEM,iBAAiB;QACtB,OAAO,IAAI,CAAC,cAAe,CAAC;IAC9B,CAAC;CACF;AAxRD,8BAwRC","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\r\nimport { ODataTypesV2, ODataTypesV4 } from \"@odata2ts/odata-core\";\r\n\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntityContainerModel,\r\n EntitySetType,\r\n EntityType,\r\n EnumType,\r\n FunctionImportType,\r\n ModelType,\r\n ODataVersion,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"./DataTypeModel\";\r\nimport { ValidationError } from \"./validation/NameValidator\";\r\n\r\nexport interface ProjectFiles {\r\n model: string;\r\n qObject: string;\r\n service: string;\r\n}\r\n\r\n/**\r\n * Each namespace is represented as tuple: 1. the namespace 2. the alias, if any.\r\n */\r\nexport type NamespaceWithAlias = [string, string?];\r\n\r\nexport function withNamespace(ns: string, name: string) {\r\n // this supports the edge case of an empty string as namespace which isn't really valid according to spec (see CSDL)\r\n return ns ? `${ns}.${name}` : name;\r\n}\r\n\r\nexport class DataModel {\r\n private readonly converters: MappedConverterChains;\r\n private nameValidation: Map<string, ValidationError[]> | undefined;\r\n\r\n private models = new Map<string, EntityType | ComplexType | EnumType>();\r\n /**\r\n * Stores unbound operations by their fully qualified name.\r\n * @private\r\n */\r\n private unboundOperationTypes = new Map<string, OperationType>();\r\n /**\r\n * Stores operations bound to an entity type by the fully qualified name of the binding entity, e.g.\r\n * \"Trippin.Person\".\r\n * @private\r\n */\r\n private entityBoundOperationTypes = new Map<string, Array<OperationType>>();\r\n /**\r\n * Stores operations bound to an entity collection by the fully qualified name of the binding entity, e.g.\r\n * \"Trippin.Person\".\r\n * @private\r\n */\r\n private entityCollectionBoundOperationTypes = new Map<string, Array<OperationType>>();\r\n /**\r\n * Stores own type definitions which map to primitive types.\r\n * @private\r\n */\r\n private typeDefinitions = new Map<string, string>();\r\n private readonly namespace2Alias: { [ns: string]: string };\r\n private aliases: Record<string, string> = {};\r\n private container: EntityContainerModel = { entitySets: {}, singletons: {}, functions: {}, actions: {} };\r\n\r\n constructor(\r\n namespaces: Array<NamespaceWithAlias>,\r\n private version: ODataVersion,\r\n converters: MappedConverterChains = new Map()\r\n ) {\r\n this.converters = converters;\r\n this.namespace2Alias = namespaces.reduce<Record<string, string>>((col, [ns, alias]) => {\r\n if (alias) {\r\n col[ns] = alias;\r\n }\r\n return col;\r\n }, {});\r\n }\r\n\r\n /**\r\n * OData version: 2.0 or 4.0.\r\n * @returns\r\n */\r\n public getODataVersion() {\r\n return this.version;\r\n }\r\n\r\n public isV2() {\r\n return this.version === ODataVersion.V2;\r\n }\r\n\r\n public isV4() {\r\n return this.version === ODataVersion.V4;\r\n }\r\n\r\n private retrieveType<T>(fqName: string, haystack: Map<string, T>): T | undefined {\r\n return haystack.get(fqName) || (this.aliases[fqName] ? haystack.get(this.aliases[fqName]) : undefined);\r\n }\r\n\r\n private addAlias(namespace: string, name: string) {\r\n const alias = this.namespace2Alias[namespace];\r\n if (alias) {\r\n this.aliases[withNamespace(alias, name)] = withNamespace(namespace, name);\r\n }\r\n }\r\n\r\n public addTypeDefinition(namespace: string, name: string, type: string) {\r\n const fqName = withNamespace(namespace, name);\r\n this.typeDefinitions.set(fqName, type);\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n public getPrimitiveType(fqName: string): string | undefined {\r\n return this.retrieveType(fqName, this.typeDefinitions);\r\n }\r\n\r\n public getModel(fqName: string) {\r\n return this.retrieveType(fqName, this.models);\r\n }\r\n\r\n public getModelTypes(): Array<ModelType> {\r\n return [...this.models.values()];\r\n }\r\n\r\n public addEntityType(namespace: string, name: string, model: Omit<EntityType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n\r\n this.models.set(fqName, { ...model, dataType: DataTypes.ModelType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get a specific model by its fully qualified name.\r\n *\r\n * @param fqName the fully qualified name of the entity\r\n * @returns the model type\r\n */\r\n public getEntityType(fqName: string) {\r\n return this.retrieveType(fqName, this.models) as EntityType;\r\n }\r\n\r\n /**\r\n * Retrieve all known EntityType models from the EDMX model.\r\n *\r\n * @returns list of model types\r\n */\r\n public getEntityTypes() {\r\n const ets = [...this.models.values()].filter((m): m is EntityType => m.dataType === DataTypes.ModelType);\r\n return this.sortModelsByInheritance(ets);\r\n }\r\n\r\n public addComplexType(namespace: string, name: string, model: Omit<ComplexType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n\r\n this.models.set(fqName, { ...model, dataType: DataTypes.ComplexType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get a specific model by its fully qualified name.\r\n *\r\n * @param fqName the final model name that is generated\r\n * @returns the model type\r\n */\r\n public getComplexType(fqName: string) {\r\n return this.retrieveType(fqName, this.models) as ComplexType;\r\n }\r\n\r\n /**\r\n * Retrieve all known ComplexType models from the EDMX model.\r\n *\r\n * @returns list of model types\r\n */\r\n public getComplexTypes() {\r\n const types = [...this.models.values()].filter((m): m is ComplexType => m.dataType === DataTypes.ComplexType);\r\n return this.sortModelsByInheritance(types);\r\n }\r\n\r\n public addEnum(namespace: string, name: string, type: Omit<EnumType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n\r\n this.models.set(fqName, { ...type, dataType: DataTypes.EnumType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get list of all known enums, i.e. EnumType nodes from the EDMX model.\r\n * @returns list of enum types\r\n */\r\n public getEnums() {\r\n return [...this.models.values()].filter((m): m is EnumType => m.dataType === DataTypes.EnumType);\r\n }\r\n\r\n public addUnboundOperationType(namespace: string, operationType: OperationType) {\r\n // supporting function overrides\r\n const isFunction = operationType.type === OperationTypes.Function;\r\n const existingFn = isFunction ? this.unboundOperationTypes.get(operationType.fqName) : undefined;\r\n if (existingFn) {\r\n const params = operationType.parameters;\r\n existingFn.overrides ? existingFn.overrides.push(params) : (existingFn.overrides = [params]);\r\n return;\r\n }\r\n\r\n this.unboundOperationTypes.set(operationType.fqName, operationType);\r\n this.addAlias(namespace, operationType.odataName);\r\n }\r\n\r\n public getUnboundOperationTypes(): Array<OperationType> {\r\n return [...this.unboundOperationTypes.values()];\r\n }\r\n\r\n public getUnboundOperationType(fqOpName: string): OperationType | undefined {\r\n return this.retrieveType(fqOpName, this.unboundOperationTypes);\r\n }\r\n\r\n public addBoundOperationType(namespace: string, bindingProp: PropertyModel, operationType: OperationType) {\r\n const fqEntityType = bindingProp.fqType;\r\n const store = bindingProp.isCollection ? this.entityCollectionBoundOperationTypes : this.entityBoundOperationTypes;\r\n const boundOps = store.get(fqEntityType);\r\n\r\n if (boundOps) {\r\n // supporting function overrides\r\n const isFunction = operationType.type === OperationTypes.Function;\r\n const existingFn = isFunction ? boundOps.find((bo) => bo.fqName === operationType.fqName) : undefined;\r\n if (existingFn) {\r\n const params = operationType.parameters;\r\n existingFn.overrides ? existingFn.overrides.push(params) : (existingFn.overrides = [params]);\r\n } else {\r\n boundOps.push(operationType);\r\n }\r\n } else {\r\n store.set(fqEntityType, [operationType]);\r\n }\r\n }\r\n\r\n public getEntityTypeOperations(fqEntityName: string): Array<OperationType> {\r\n const operations = this.retrieveType(fqEntityName, this.entityBoundOperationTypes);\r\n return operations || [];\r\n }\r\n\r\n public getEntitySetOperations(fqEntityName: string): Array<OperationType> {\r\n const operations = this.retrieveType(fqEntityName, this.entityCollectionBoundOperationTypes);\r\n return operations || [];\r\n }\r\n\r\n public getAllEntityOperations(fqEntityName: string): Array<OperationType> {\r\n return [...this.getEntityTypeOperations(fqEntityName), ...this.getEntitySetOperations(fqEntityName)];\r\n }\r\n\r\n public addAction(fqName: string, action: ActionImportType) {\r\n this.container.actions[fqName] = action;\r\n }\r\n\r\n public addFunction(fqName: string, func: FunctionImportType) {\r\n this.container.functions[fqName] = func;\r\n }\r\n\r\n public addSingleton(fqName: string, singleton: SingletonType) {\r\n this.container.singletons[fqName] = singleton;\r\n }\r\n\r\n public addEntitySet(fqName: string, entitySet: EntitySetType) {\r\n this.container.entitySets[fqName] = entitySet;\r\n }\r\n\r\n public getEntityContainer() {\r\n return this.container;\r\n }\r\n\r\n public getConverter(dataType: ODataTypesV2 | ODataTypesV4 | string) {\r\n return this.converters.get(dataType);\r\n }\r\n\r\n private sortModelsByInheritance<Type extends Omit<ComplexType, \"dataType\">>(models: Array<Type>): Array<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 sorted: Array<Type> = [];\r\n const visitedModels = new Set<string>();\r\n const inProgressModels = new Set<string>();\r\n\r\n function visit(model: Type) {\r\n const fqName = model.fqName;\r\n if (inProgressModels.has(fqName)) {\r\n throw new Error(`Cyclic inheritance detected for model \"${fqName}\"!`);\r\n }\r\n\r\n if (!visitedModels.has(fqName)) {\r\n inProgressModels.add(fqName);\r\n\r\n for (const baseClassName of model.baseClasses) {\r\n const baseClass = models.find((e) => e.fqName === baseClassName);\r\n if (baseClass) {\r\n visit(baseClass);\r\n }\r\n }\r\n visitedModels.add(fqName);\r\n inProgressModels.delete(fqName);\r\n sorted.push(model);\r\n }\r\n }\r\n\r\n for (const model of models) {\r\n visit(model);\r\n }\r\n return sorted;\r\n }\r\n\r\n public setNameValidation(map: Map<string, ValidationError[]>) {\r\n this.nameValidation = map;\r\n }\r\n\r\n public getNameValidation() {\r\n return this.nameValidation!;\r\n }\r\n}\r\n"]}
|
|
@@ -24,7 +24,20 @@ export declare abstract class Digester<S extends Schema<ET, CT>, ET extends Enti
|
|
|
24
24
|
protected readonly dataModel: DataModel;
|
|
25
25
|
protected readonly serviceConfigHelper: ServiceConfigHelper;
|
|
26
26
|
protected readonly nameValidator: NameValidator;
|
|
27
|
+
/**
|
|
28
|
+
* Reverse mapping from fqName to data type: EntityType, ComplexType, EnumType, or Primitive Type.
|
|
29
|
+
*/
|
|
27
30
|
private model2Type;
|
|
31
|
+
/**
|
|
32
|
+
* Stores models (ComplexType or EntityType) by fqName that have been referenced in the API
|
|
33
|
+
* as entry point or via navProp.
|
|
34
|
+
* For these models one or two services are generated.
|
|
35
|
+
*
|
|
36
|
+
* In this way unnecessary service generation is prevented. For example, complex types that
|
|
37
|
+
* are only referenced as response of an operation do not need a generated service.
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
private serviceModels;
|
|
28
41
|
protected constructor(version: ODataVersion, schemas: Array<S>, options: DigestionOptions, namingHelper: NamingHelper, converters?: MappedConverterChains);
|
|
29
42
|
private collectModelTypes;
|
|
30
43
|
private addModel2Type;
|
|
@@ -45,6 +58,8 @@ export declare abstract class Digester<S extends Schema<ET, CT>, ET extends Enti
|
|
|
45
58
|
private addEnum;
|
|
46
59
|
private addComplexType;
|
|
47
60
|
private addEntityType;
|
|
61
|
+
private analyzeModelUsage;
|
|
62
|
+
private analyze;
|
|
48
63
|
private postProcessModel;
|
|
49
64
|
private postProcessKeys;
|
|
50
65
|
private collectBaseClassPropsAndKeys;
|