@odata2ts/odata2ts 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
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.25.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.24.0...@odata2ts/odata2ts@0.25.0) (2023-07-10)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **odata2ts:** use qualified name for bound operations ([#182](https://github.com/odata2ts/odata2ts/issues/182)) ([120c9b8](https://github.com/odata2ts/odata2ts/commit/120c9b807ac209a8eb82b389bc7c21d7df7fe876))
11
+
12
+ ### Features
13
+
14
+ * **odata2ts:** support for multiple namespaces by merging ([#175](https://github.com/odata2ts/odata2ts/issues/175)) ([db8fd61](https://github.com/odata2ts/odata2ts/commit/db8fd6165c57ceb9e04488789a62f2a5467ecc68))
15
+ * **odata2ts:** support schema alias ([#181](https://github.com/odata2ts/odata2ts/issues/181)) ([e0c04a8](https://github.com/odata2ts/odata2ts/commit/e0c04a83e32d99187652966bb9cc32f36ead3df2))
16
+ * **odata2ts:** support TypeDefinition elements ([#183](https://github.com/odata2ts/odata2ts/issues/183)) ([d77d2cb](https://github.com/odata2ts/odata2ts/commit/d77d2cbf17383dab50d35bb7374e08a83d264db2))
17
+
6
18
  # [0.24.0](https://github.com/odata2ts/odata2ts/compare/@odata2ts/odata2ts@0.23.1...@odata2ts/odata2ts@0.24.0) (2023-06-14)
7
19
 
8
20
  ### Features
package/README.md CHANGED
@@ -1,74 +1,74 @@
1
- [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/odata2ts?style=for-the-badge)](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
+ [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/odata2ts?style=for-the-badge)](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).
@@ -8,6 +8,6 @@ export type DigestionOptions = Pick<RunOptions, "converters" | "disableAutoManag
8
8
  /**
9
9
  * Takes an EdmxSchema plus the run options and creates a DataModel.
10
10
  */
11
- export type DigesterFunction<S extends Schema<any, any>> = (schema: S, options: DigestionOptions, namingHelper: NamingHelper) => Promise<DataModel>;
11
+ export type DigesterFunction<S extends Schema<any, any>> = (schema: Array<S>, options: DigestionOptions, namingHelper: NamingHelper) => Promise<DataModel>;
12
12
  export type GeneratorFunctionOptions = Pick<RunOptions, "skipEditableModels" | "skipIdModels" | "skipOperations" | "skipComments" | "v2ModelsWithExtraResultsWrapping">;
13
13
  export type EntityBasedGeneratorFunction = (dataModel: DataModel, sourceFile: SourceFile, version: ODataVersions, options: GeneratorFunctionOptions, namingHelper: NamingHelper) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"FactoryFunctionModel.js","sourceRoot":"","sources":["../src/FactoryFunctionModel.ts"],"names":[],"mappings":"","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { SourceFile } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"./data-model/DataModel\";\r\nimport { Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { RunOptions } from \"./OptionModel\";\r\n\r\nexport type DigestionOptions = Pick<\r\n RunOptions,\r\n | \"converters\"\r\n | \"disableAutoManagedKey\"\r\n | \"propertiesByName\"\r\n | \"entitiesByName\"\r\n | \"v2ModelsWithExtraResultsWrapping\"\r\n | \"skipEditableModels\"\r\n | \"skipComments\"\r\n>;\r\n\r\n/**\r\n * Takes an EdmxSchema plus the run options and creates a DataModel.\r\n */\r\nexport type DigesterFunction<S extends Schema<any, any>> = (\r\n schema: S,\r\n options: DigestionOptions,\r\n namingHelper: NamingHelper\r\n) => Promise<DataModel>;\r\n\r\nexport type GeneratorFunctionOptions = Pick<\r\n RunOptions,\r\n \"skipEditableModels\" | \"skipIdModels\" | \"skipOperations\" | \"skipComments\" | \"v2ModelsWithExtraResultsWrapping\"\r\n>;\r\n\r\nexport type EntityBasedGeneratorFunction = (\r\n dataModel: DataModel,\r\n sourceFile: SourceFile,\r\n version: ODataVersions,\r\n options: GeneratorFunctionOptions,\r\n namingHelper: NamingHelper\r\n) => void;\r\n"]}
1
+ {"version":3,"file":"FactoryFunctionModel.js","sourceRoot":"","sources":["../src/FactoryFunctionModel.ts"],"names":[],"mappings":"","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { SourceFile } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"./data-model/DataModel\";\r\nimport { Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { RunOptions } from \"./OptionModel\";\r\n\r\nexport type DigestionOptions = Pick<\r\n RunOptions,\r\n | \"converters\"\r\n | \"disableAutoManagedKey\"\r\n | \"propertiesByName\"\r\n | \"entitiesByName\"\r\n | \"v2ModelsWithExtraResultsWrapping\"\r\n | \"skipEditableModels\"\r\n | \"skipComments\"\r\n>;\r\n\r\n/**\r\n * Takes an EdmxSchema plus the run options and creates a DataModel.\r\n */\r\nexport type DigesterFunction<S extends Schema<any, any>> = (\r\n schema: Array<S>,\r\n options: DigestionOptions,\r\n namingHelper: NamingHelper\r\n) => Promise<DataModel>;\r\n\r\nexport type GeneratorFunctionOptions = Pick<\r\n RunOptions,\r\n \"skipEditableModels\" | \"skipIdModels\" | \"skipOperations\" | \"skipComments\" | \"v2ModelsWithExtraResultsWrapping\"\r\n>;\r\n\r\nexport type EntityBasedGeneratorFunction = (\r\n dataModel: DataModel,\r\n sourceFile: SourceFile,\r\n version: ODataVersions,\r\n options: GeneratorFunctionOptions,\r\n namingHelper: NamingHelper\r\n) => void;\r\n"]}
package/lib/app.js CHANGED
@@ -21,24 +21,28 @@ function isServiceGen(mode) {
21
21
  * @param options further options
22
22
  */
23
23
  function runApp(metadataJson, options) {
24
- var _a;
25
24
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
26
25
  // determine edmx edmxVersion attribute
27
26
  const edmxVersion = metadataJson["edmx:Edmx"].$.Version;
28
27
  const version = edmxVersion === "1.0" ? odata_core_1.ODataVersions.V2 : odata_core_1.ODataVersions.V4;
29
28
  const dataService = metadataJson["edmx:Edmx"]["edmx:DataServices"][0];
30
- // handling multiple schemas => merge them
31
- const schemaRaw = dataService.Schema.reduce((collector, schema) => (Object.assign(Object.assign({}, schema), collector)), {});
32
- const detectedServiceName = dataService.Schema.length === 1
33
- ? dataService.Schema[0].$.Namespace
34
- : (_a = dataService.Schema.find((schema) => !schema.EntityContainer)) === null || _a === void 0 ? void 0 : _a.$.Namespace;
29
+ const schemas = dataService.Schema;
30
+ const detectedSchema = schemas.find((schema) => { var _a; return schema.$.Namespace && ((_a = schema.EntityType) === null || _a === void 0 ? void 0 : _a.length); }) || schemas[0];
31
+ const serviceName = options.serviceName || detectedSchema.$.Namespace;
32
+ const namespaces = [];
33
+ schemas.forEach((schema) => {
34
+ namespaces.push(schema.$.Namespace);
35
+ if (schema.$.Alias) {
36
+ namespaces.push(schema.$.Alias);
37
+ }
38
+ });
35
39
  // encapsulate the whole naming logic
36
- const namingHelper = new NamingHelper_1.NamingHelper(options, detectedServiceName, options.serviceName);
40
+ const namingHelper = new NamingHelper_1.NamingHelper(options, serviceName, namespaces);
37
41
  // parse model information from edmx into something we can really work with
38
42
  // => that stuff is called dataModel!
39
43
  const dataModel = version === odata_core_1.ODataVersions.V2
40
- ? yield (0, DataModelDigestionV2_1.digest)(schemaRaw, options, namingHelper)
41
- : yield (0, DataModelDigestionV4_1.digest)(schemaRaw, options, namingHelper);
44
+ ? yield (0, DataModelDigestionV2_1.digest)(dataService.Schema, options, namingHelper)
45
+ : yield (0, DataModelDigestionV4_1.digest)(dataService.Schema, options, namingHelper);
42
46
  // handling the overall generation project
43
47
  const project = yield (0, ProjectManager_1.createProjectManager)(namingHelper.getFileNames(), options.output, options.emitMode, options.prettier, options.tsconfig);
44
48
  // Generate Model Interfaces
package/lib/app.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AAErD,4EAAuE;AACvE,4EAAuE;AAIvE,4DAAyD;AACzD,2CAAqF;AACrF,+CAAkD;AAClD,6DAAgE;AAEhE,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,QAAQ,EAAE,mBAAK,CAAC,OAAO,EAAE,mBAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,OAAO,EAAE,mBAAK,CAAC,GAAG,CAAC,CAAC,QAAQ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,YAAY,CAAC,CAAC;QACnE,0CAA0C;QAC1C,MAAM,OAAO,GAAG,MAAM,IAAA,qCAAoB,EACxC,YAAY,CAAC,YAAY,EAAE,EAC3B,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,QAAQ,CACjB,CAAC;QAEF,4BAA4B;QAC5B,0DAA0D;QAC1D,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;QACnD,IAAA,0BAAc,EAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAEtE,yBAAyB;QACzB,gDAAgD;QAChD,mJAAmJ;QACnJ,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAChD,IAAA,gCAAoB,EAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;SACxE;QAED,oCAAoC;QACpC,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;YAChC,MAAM,IAAA,4BAAgB,EAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;SACnE;QAED,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;;CAC5B;AAzDD,wBAyDC","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\n\r\nimport { digest as digestV2 } from \"./data-model/DataModelDigestionV2\";\r\nimport { digest as digestV4 } from \"./data-model/DataModelDigestionV4\";\r\nimport { ODataEdmxModelBase, Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { SchemaV3 } from \"./data-model/edmx/ODataEdmxModelV3\";\r\nimport { SchemaV4 } from \"./data-model/edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { generateModels, generateQueryObjects, generateServices } from \"./generator\";\r\nimport { Modes, RunOptions } from \"./OptionModel\";\r\nimport { createProjectManager } from \"./project/ProjectManager\";\r\n\r\nfunction isQObjectGen(mode: Modes) {\r\n return [Modes.qobjects, Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\nfunction isServiceGen(mode: Modes) {\r\n return [Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\n/**\r\n *\r\n * @param metadataJson metadata of a given OData service already parsed as JSON\r\n * @param options further options\r\n */\r\nexport async function runApp(metadataJson: ODataEdmxModelBase<any>, options: RunOptions): Promise<void> {\r\n // determine edmx edmxVersion attribute\r\n const edmxVersion = metadataJson[\"edmx:Edmx\"].$.Version;\r\n const version = edmxVersion === \"1.0\" ? ODataVersions.V2 : ODataVersions.V4;\r\n\r\n const dataService = metadataJson[\"edmx:Edmx\"][\"edmx:DataServices\"][0];\r\n\r\n // handling multiple schemas => merge them\r\n const schemaRaw = dataService.Schema.reduce(\r\n (collector, schema) => ({\r\n ...schema,\r\n ...collector,\r\n }),\r\n {} as Schema<any, any>\r\n );\r\n const detectedServiceName =\r\n dataService.Schema.length === 1\r\n ? dataService.Schema[0].$.Namespace\r\n : dataService.Schema.find((schema) => !schema.EntityContainer)?.$.Namespace;\r\n\r\n // encapsulate the whole naming logic\r\n const namingHelper = new NamingHelper(options, detectedServiceName, options.serviceName);\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(schemaRaw as SchemaV3, options, namingHelper)\r\n : await digestV4(schemaRaw as SchemaV4, options, namingHelper);\r\n // handling the overall generation project\r\n const project = await createProjectManager(\r\n namingHelper.getFileNames(),\r\n options.output,\r\n options.emitMode,\r\n options.prettier,\r\n options.tsconfig\r\n );\r\n\r\n // Generate Model Interfaces\r\n // supported edmx types: EntityType, ComplexType, EnumType\r\n const modelsFile = await project.createModelFile();\r\n generateModels(dataModel, modelsFile, version, options, namingHelper);\r\n\r\n // Generate Query Objects\r\n // supported edmx types: EntityType, ComplexType\r\n // supported edmx prop types: primitive types, enum types, primitive collection (incl enum types), entity collection, entity object, complex object\r\n if (isQObjectGen(options.mode)) {\r\n const qFile = await project.createQObjectFile();\r\n generateQueryObjects(dataModel, qFile, version, options, namingHelper);\r\n }\r\n\r\n // Generate Individual OData-Service\r\n if (isServiceGen(options.mode)) {\r\n await project.cleanServiceDir();\r\n await generateServices(dataModel, project, version, namingHelper);\r\n }\r\n\r\n await project.writeFiles();\r\n}\r\n"]}
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AAErD,4EAAuE;AACvE,4EAAuE;AAIvE,4DAAyD;AACzD,2CAAqF;AACrF,+CAAkD;AAClD,6DAAgE;AAEhE,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,QAAQ,EAAE,mBAAK,CAAC,OAAO,EAAE,mBAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,OAAO,EAAE,mBAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnD,CAAC;AAED;;;;GAIG;AACH,SAAsB,MAAM,CAAC,YAAqC,EAAE,OAAmB;;QACrF,uCAAuC;QACvC,MAAM,WAAW,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACxD,MAAM,OAAO,GAAG,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,0BAAa,CAAC,EAAE,CAAC,CAAC,CAAC,0BAAa,CAAC,EAAE,CAAC;QAE5E,MAAM,WAAW,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;QACt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Q,CACjB,CAAC;QAEF,4BAA4B;QAC5B,0DAA0D;QAC1D,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;QACnD,IAAA,0BAAc,EAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAEtE,yBAAyB;QACzB,gDAAgD;QAChD,mJAAmJ;QACnJ,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAChD,IAAA,gCAAoB,EAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;SACxE;QAED,oCAAoC;QACpC,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;YAChC,MAAM,IAAA,4BAAgB,EAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;SACnE;QAED,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;CAAA;AAxDD,wBAwDC","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\n\r\nimport { digest as digestV2 } from \"./data-model/DataModelDigestionV2\";\r\nimport { digest as digestV4 } from \"./data-model/DataModelDigestionV4\";\r\nimport { ODataEdmxModelBase, Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { SchemaV3 } from \"./data-model/edmx/ODataEdmxModelV3\";\r\nimport { SchemaV4 } from \"./data-model/edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { generateModels, generateQueryObjects, generateServices } from \"./generator\";\r\nimport { Modes, RunOptions } from \"./OptionModel\";\r\nimport { createProjectManager } from \"./project/ProjectManager\";\r\n\r\nfunction isQObjectGen(mode: Modes) {\r\n return [Modes.qobjects, Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\nfunction isServiceGen(mode: Modes) {\r\n return [Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\n/**\r\n *\r\n * @param metadataJson metadata of a given OData service already parsed as JSON\r\n * @param options further options\r\n */\r\nexport async function runApp(metadataJson: ODataEdmxModelBase<any>, options: RunOptions): Promise<void> {\r\n // determine edmx edmxVersion attribute\r\n const edmxVersion = metadataJson[\"edmx:Edmx\"].$.Version;\r\n const version = edmxVersion === \"1.0\" ? ODataVersions.V2 : ODataVersions.V4;\r\n\r\n const dataService = metadataJson[\"edmx:Edmx\"][\"edmx:DataServices\"][0];\r\n const schemas = dataService.Schema as Array<SchemaV3 | SchemaV4>;\r\n\r\n const detectedSchema = schemas.find((schema) => schema.$.Namespace && schema.EntityType?.length) || schemas[0];\r\n const serviceName = options.serviceName || detectedSchema.$.Namespace;\r\n\r\n const namespaces: Array<string> = [];\r\n schemas.forEach((schema) => {\r\n namespaces.push(schema.$.Namespace);\r\n if (schema.$.Alias) {\r\n namespaces.push(schema.$.Alias);\r\n }\r\n });\r\n\r\n // encapsulate the whole naming logic\r\n const namingHelper = new NamingHelper(options, serviceName, namespaces);\r\n // parse model information from edmx into something we can really work with\r\n // => that stuff is called dataModel!\r\n const dataModel =\r\n version === ODataVersions.V2\r\n ? await digestV2(dataService.Schema as Array<SchemaV3>, options, namingHelper)\r\n : await digestV4(dataService.Schema as Array<SchemaV4>, options, namingHelper);\r\n // handling the overall generation project\r\n const project = await createProjectManager(\r\n namingHelper.getFileNames(),\r\n options.output,\r\n options.emitMode,\r\n options.prettier,\r\n options.tsconfig\r\n );\r\n\r\n // Generate Model Interfaces\r\n // supported edmx types: EntityType, ComplexType, EnumType\r\n const modelsFile = await project.createModelFile();\r\n generateModels(dataModel, modelsFile, version, options, namingHelper);\r\n\r\n // Generate Query Objects\r\n // supported edmx types: EntityType, ComplexType\r\n // supported edmx prop types: primitive types, enum types, primitive collection (incl enum types), entity collection, entity object, complex object\r\n if (isQObjectGen(options.mode)) {\r\n const qFile = await project.createQObjectFile();\r\n generateQueryObjects(dataModel, qFile, version, options, namingHelper);\r\n }\r\n\r\n // Generate Individual OData-Service\r\n if (isServiceGen(options.mode)) {\r\n await project.cleanServiceDir();\r\n await generateServices(dataModel, project, version, namingHelper);\r\n }\r\n\r\n await project.writeFiles();\r\n}\r\n"]}
@@ -13,6 +13,7 @@ export declare class DataModel {
13
13
  private complexTypes;
14
14
  private enumTypes;
15
15
  private operationTypes;
16
+ private typeDefinitions;
16
17
  private container;
17
18
  constructor(version: ODataVersion, converters?: MappedConverterChains);
18
19
  /**
@@ -22,6 +23,8 @@ export declare class DataModel {
22
23
  getODataVersion(): ODataVersion;
23
24
  isV2(): boolean;
24
25
  isV4(): boolean;
26
+ addTypeDefinition(name: string, type: string): void;
27
+ getPrimitiveType(name: string): string | undefined;
25
28
  addModel(name: string, model: ModelType): void;
26
29
  /**
27
30
  * Get a specific model by its name.
@@ -11,6 +11,7 @@ class DataModel {
11
11
  this.enumTypes = {};
12
12
  // combines functions & actions
13
13
  this.operationTypes = {};
14
+ this.typeDefinitions = {};
14
15
  this.container = { entitySets: {}, singletons: {}, functions: {}, actions: {} };
15
16
  this.converters = converters;
16
17
  }
@@ -27,6 +28,12 @@ class DataModel {
27
28
  isV4() {
28
29
  return this.version === DataTypeModel_1.ODataVersion.V4;
29
30
  }
31
+ addTypeDefinition(name, type) {
32
+ this.typeDefinitions[name] = type;
33
+ }
34
+ getPrimitiveType(name) {
35
+ return this.typeDefinitions[name];
36
+ }
30
37
  addModel(name, model) {
31
38
  this.modelTypes[name] = model;
32
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../src/data-model/DataModel.ts"],"names":[],"mappings":";;;AAGA,mDAWyB;AAQzB,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC,MAAa,SAAS;IAUpB,YAAoB,OAAqB,EAAE,aAAoC,IAAI,GAAG,EAAE;QAApE,YAAO,GAAP,OA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AAC;QACpE,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC;IACpC,CAAC;IAEM,SAAS,CAAC,IAAY,EAAE,MAAwB;QACrD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;IACxC,CAAC;IAEM,WAAW,CAAC,IAAY,EAAE,IAAwB;QACvD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC,CAAC;IAEM,YAAY,CAAC,IAAY,EAAE,SAAwB;QACxD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IAC9C,CAAC;IAEM,YAAY,CAAC,IAAY,EAAE,SAAwB;QACxD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IAC9C,CAAC;IAEM,kBAAkB;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEM,YAAY,CAAC,QAA8C;QAChE,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;CACF;AAzJD,8BAyJC","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 EntityContainerModel,\r\n EntitySetType,\r\n EnumType,\r\n FunctionImportType,\r\n ModelType,\r\n ODataVersion,\r\n OperationType,\r\n SingletonType,\r\n} from \"./DataTypeModel\";\r\n\r\nexport interface ProjectFiles {\r\n model: string;\r\n qObject: string;\r\n service: string;\r\n}\r\n\r\nconst ROOT_OPERATION_BINDING = \"/\";\r\n\r\nexport class DataModel {\r\n private readonly converters: MappedConverterChains;\r\n\r\n private modelTypes: { [name: string]: ModelType } = {};\r\n private complexTypes: { [name: string]: ComplexType } = {};\r\n private enumTypes: { [name: string]: EnumType } = {};\r\n // combines functions & actions\r\n private operationTypes: { [binding: string]: Array<OperationType> } = {};\r\n private container: EntityContainerModel = { entitySets: {}, singletons: {}, functions: {}, actions: {} };\r\n\r\n constructor(private version: ODataVersion, converters: MappedConverterChains = new Map()) {\r\n this.converters = converters;\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 public addModel(name: string, model: ModelType) {\r\n this.modelTypes[name] = model;\r\n }\r\n\r\n /**\r\n * Get a specific model by its name.\r\n *\r\n * @param modelName the final model name that is generated\r\n * @returns the model type\r\n */\r\n public getModel(modelName: string) {\r\n return this.modelTypes[modelName];\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 getModels() {\r\n return Object.values(this.modelTypes);\r\n }\r\n\r\n /**\r\n * Set all model entity types\r\n *\r\n * @param models new model types\r\n */\r\n public setModels(models: { [name: string]: ModelType }) {\r\n this.modelTypes = models;\r\n }\r\n\r\n public addComplexType(name: string, model: ComplexType) {\r\n this.complexTypes[name] = model;\r\n }\r\n\r\n /**\r\n * Get a specific model by its name.\r\n *\r\n * @param name the final model name that is generated\r\n * @returns the model type\r\n */\r\n public getComplexType(name: string) {\r\n return this.complexTypes[name];\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 return Object.values(this.complexTypes);\r\n }\r\n\r\n /**\r\n * Set all complex types\r\n *\r\n * @param models new complex types\r\n */\r\n public setComplexTypes(complexTypes: { [name: string]: ComplexType }) {\r\n this.complexTypes = complexTypes;\r\n }\r\n\r\n public addEnum(name: string, type: EnumType) {\r\n this.enumTypes[name] = type;\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 Object.values(this.enumTypes);\r\n }\r\n\r\n public addOperationType(binding: string, operationType: OperationType) {\r\n if (!this.operationTypes[binding]) {\r\n this.operationTypes[binding] = [];\r\n }\r\n\r\n this.operationTypes[binding].push(operationType);\r\n }\r\n\r\n public getUnboundOperationTypes(): Array<OperationType> {\r\n const operations = this.operationTypes[ROOT_OPERATION_BINDING];\r\n return !operations ? [] : [...operations];\r\n }\r\n\r\n public getOperationTypeByBinding(binding: string): Array<OperationType> {\r\n const operations = this.operationTypes[binding];\r\n return !operations ? [] : [...operations];\r\n }\r\n\r\n public getOperationTypeByEntityOrCollectionBinding(binding: string): Array<OperationType> {\r\n const entityOps = this.operationTypes[binding] || [];\r\n const collOps = this.operationTypes[`Collection(${binding})`] || [];\r\n return [...collOps, ...entityOps];\r\n }\r\n\r\n public addAction(name: string, action: ActionImportType) {\r\n this.container.actions[name] = action;\r\n }\r\n\r\n public addFunction(name: string, func: FunctionImportType) {\r\n this.container.functions[name] = func;\r\n }\r\n\r\n public addSingleton(name: string, singleton: SingletonType) {\r\n this.container.singletons[name] = singleton;\r\n }\r\n\r\n public addEntitySet(name: string, entitySet: EntitySetType) {\r\n this.container.entitySets[name] = 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"]}
1
+ {"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../src/data-model/DataModel.ts"],"names":[],"mappings":";;;AAGA,mDAWyB;AAQzB,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC,MAAa,SAAS;IAWpB,YAAoB,OAAqB,EAAE,aAAoC,IAAI,GAAG,EAAE;QAApE,YAAO,GAAP,OAAO,CAAc;QARjC,eAAU,GAAkC,EAAE,CAAC;QAC/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AEM,2CAA2C,CAAC,OAAe;QAChE,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACrD,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;QACpE,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC;IACpC,CAAC;IAEM,SAAS,CAAC,IAAY,EAAE,MAAwB;QACrD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;IACxC,CAAC;IAEM,WAAW,CAAC,IAAY,EAAE,IAAwB;QACvD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC,CAAC;IAEM,YAAY,CAAC,IAAY,EAAE,SAAwB;QACxD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IAC9C,CAAC;IAEM,YAAY,CAAC,IAAY,EAAE,SAAwB;QACxD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IAC9C,CAAC;IAEM,kBAAkB;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEM,YAAY,CAAC,QAA8C;QAChE,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;CACF;AAlKD,8BAkKC","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 EntityContainerModel,\r\n EntitySetType,\r\n EnumType,\r\n FunctionImportType,\r\n ModelType,\r\n ODataVersion,\r\n OperationType,\r\n SingletonType,\r\n} from \"./DataTypeModel\";\r\n\r\nexport interface ProjectFiles {\r\n model: string;\r\n qObject: string;\r\n service: string;\r\n}\r\n\r\nconst ROOT_OPERATION_BINDING = \"/\";\r\n\r\nexport class DataModel {\r\n private readonly converters: MappedConverterChains;\r\n\r\n private modelTypes: { [name: string]: ModelType } = {};\r\n private complexTypes: { [name: string]: ComplexType } = {};\r\n private enumTypes: { [name: string]: EnumType } = {};\r\n // combines functions & actions\r\n private operationTypes: { [binding: string]: Array<OperationType> } = {};\r\n private typeDefinitions: { [name: string]: string } = {};\r\n private container: EntityContainerModel = { entitySets: {}, singletons: {}, functions: {}, actions: {} };\r\n\r\n constructor(private version: ODataVersion, converters: MappedConverterChains = new Map()) {\r\n this.converters = converters;\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 public addTypeDefinition(name: string, type: string) {\r\n this.typeDefinitions[name] = type;\r\n }\r\n\r\n public getPrimitiveType(name: string): string | undefined {\r\n return this.typeDefinitions[name];\r\n }\r\n\r\n public addModel(name: string, model: ModelType) {\r\n this.modelTypes[name] = model;\r\n }\r\n\r\n /**\r\n * Get a specific model by its name.\r\n *\r\n * @param modelName the final model name that is generated\r\n * @returns the model type\r\n */\r\n public getModel(modelName: string) {\r\n return this.modelTypes[modelName];\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 getModels() {\r\n return Object.values(this.modelTypes);\r\n }\r\n\r\n /**\r\n * Set all model entity types\r\n *\r\n * @param models new model types\r\n */\r\n public setModels(models: { [name: string]: ModelType }) {\r\n this.modelTypes = models;\r\n }\r\n\r\n public addComplexType(name: string, model: ComplexType) {\r\n this.complexTypes[name] = model;\r\n }\r\n\r\n /**\r\n * Get a specific model by its name.\r\n *\r\n * @param name the final model name that is generated\r\n * @returns the model type\r\n */\r\n public getComplexType(name: string) {\r\n return this.complexTypes[name];\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 return Object.values(this.complexTypes);\r\n }\r\n\r\n /**\r\n * Set all complex types\r\n *\r\n * @param models new complex types\r\n */\r\n public setComplexTypes(complexTypes: { [name: string]: ComplexType }) {\r\n this.complexTypes = complexTypes;\r\n }\r\n\r\n public addEnum(name: string, type: EnumType) {\r\n this.enumTypes[name] = type;\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 Object.values(this.enumTypes);\r\n }\r\n\r\n public addOperationType(binding: string, operationType: OperationType) {\r\n if (!this.operationTypes[binding]) {\r\n this.operationTypes[binding] = [];\r\n }\r\n\r\n this.operationTypes[binding].push(operationType);\r\n }\r\n\r\n public getUnboundOperationTypes(): Array<OperationType> {\r\n const operations = this.operationTypes[ROOT_OPERATION_BINDING];\r\n return !operations ? [] : [...operations];\r\n }\r\n\r\n public getOperationTypeByBinding(binding: string): Array<OperationType> {\r\n const operations = this.operationTypes[binding];\r\n return !operations ? [] : [...operations];\r\n }\r\n\r\n public getOperationTypeByEntityOrCollectionBinding(binding: string): Array<OperationType> {\r\n const entityOps = this.operationTypes[binding] || [];\r\n const collOps = this.operationTypes[`Collection(${binding})`] || [];\r\n return [...collOps, ...entityOps];\r\n }\r\n\r\n public addAction(name: string, action: ActionImportType) {\r\n this.container.actions[name] = action;\r\n }\r\n\r\n public addFunction(name: string, func: FunctionImportType) {\r\n this.container.functions[name] = func;\r\n }\r\n\r\n public addSingleton(name: string, singleton: SingletonType) {\r\n this.container.singletons[name] = singleton;\r\n }\r\n\r\n public addEntitySet(name: string, entitySet: EntitySetType) {\r\n this.container.entitySets[name] = 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"]}
@@ -3,6 +3,8 @@ import { DigestionOptions } from "../FactoryFunctionModel";
3
3
  import { DataModel } from "./DataModel";
4
4
  import { ODataVersion, PropertyModel } from "./DataTypeModel";
5
5
  import { ComplexType, EntityType, Property, Schema } from "./edmx/ODataEdmxModelBase";
6
+ import { SchemaV3 } from "./edmx/ODataEdmxModelV3";
7
+ import { SchemaV4 } from "./edmx/ODataEdmxModelV4";
6
8
  import { NamingHelper } from "./NamingHelper";
7
9
  import { ServiceConfigHelper } from "./ServiceConfigHelper";
8
10
  export interface TypeModel {
@@ -13,7 +15,7 @@ export interface TypeModel {
13
15
  }
14
16
  export declare abstract class Digester<S extends Schema<ET, CT>, ET extends EntityType, CT extends ComplexType> {
15
17
  protected version: ODataVersion;
16
- protected schema: S;
18
+ protected schemas: Array<S>;
17
19
  protected options: DigestionOptions;
18
20
  protected namingHelper: NamingHelper;
19
21
  protected static EDM_PREFIX: string;
@@ -21,9 +23,10 @@ export declare abstract class Digester<S extends Schema<ET, CT>, ET extends Enti
21
23
  protected readonly dataModel: DataModel;
22
24
  protected readonly serviceConfigHelper: ServiceConfigHelper;
23
25
  private model2Type;
24
- protected constructor(version: ODataVersion, schema: S, options: DigestionOptions, namingHelper: NamingHelper, converters?: MappedConverterChains);
26
+ protected constructor(version: ODataVersion, schemas: Array<S>, options: DigestionOptions, namingHelper: NamingHelper, converters?: MappedConverterChains);
25
27
  protected abstract getNavigationProps(entityType: ET | ComplexType): Array<Property>;
26
- protected abstract digestEntityContainer(): void;
28
+ protected abstract digestOperations(schema: SchemaV3 | SchemaV4): void;
29
+ protected abstract digestEntityContainer(schema: SchemaV3 | SchemaV4): void;
27
30
  /**
28
31
  * Get essential infos about a given odata type from the version specific service variants.
29
32
  *
@@ -33,8 +36,9 @@ export declare abstract class Digester<S extends Schema<ET, CT>, ET extends Enti
33
36
  protected abstract mapODataType(type: string): TypeModel;
34
37
  digest(): Promise<DataModel>;
35
38
  private collectModelTypes;
36
- private digestSchema;
39
+ private digestEntityTypesAndOperations;
37
40
  private getBaseModel;
41
+ private addTypeDefinition;
38
42
  private addComplexType;
39
43
  private addEntityType;
40
44
  private postProcessModel;
@@ -5,9 +5,9 @@ const tslib_1 = require("tslib");
5
5
  const DataModel_1 = require("./DataModel");
6
6
  const ServiceConfigHelper_1 = require("./ServiceConfigHelper");
7
7
  class Digester {
8
- constructor(version, schema, options, namingHelper, converters) {
8
+ constructor(version, schemas, options, namingHelper, converters) {
9
9
  this.version = version;
10
- this.schema = schema;
10
+ this.schemas = schemas;
11
11
  this.options = options;
12
12
  this.namingHelper = namingHelper;
13
13
  this.model2Type = new Map();
@@ -15,14 +15,20 @@ class Digester {
15
15
  if (!p.$.Type) {
16
16
  throw new Error(`No type information given for property [${p.$.Name}]!`);
17
17
  }
18
- const isCollection = !!p.$.Type.match(/^Collection\(/);
19
- const dataType = p.$.Type.replace(/^Collection\(([^\)]+)\)/, "$1");
20
18
  const configProp = this.serviceConfigHelper.findConfigPropByName(p.$.Name);
21
19
  const name = this.namingHelper.getModelPropName((configProp === null || configProp === void 0 ? void 0 : configProp.mappedName) || p.$.Name);
20
+ const isCollection = !!p.$.Type.match(/^Collection\(/);
21
+ let dataType = p.$.Type.replace(/^Collection\(([^\)]+)\)/, "$1");
22
+ if (this.namingHelper.includesServicePrefix(dataType)) {
23
+ const dtName = this.namingHelper.stripServicePrefix(dataType);
24
+ if (this.dataModel.getPrimitiveType(dtName) !== undefined) {
25
+ dataType = this.dataModel.getPrimitiveType(dtName);
26
+ }
27
+ }
22
28
  let result;
23
29
  // domain object known from service:
24
- // EntityType, ComplexType or EnumType
25
- if (dataType.startsWith(this.namingHelper.getServicePrefix())) {
30
+ // EntityType, ComplexType, EnumType or TypeDefinition
31
+ if (this.namingHelper.includesServicePrefix(dataType)) {
26
32
  const resultDt = this.model2Type.get(dataType);
27
33
  if (!resultDt) {
28
34
  throw new Error(`Couldn't determine model type for data type with name '${dataType}'`);
@@ -64,52 +70,60 @@ class Digester {
64
70
  };
65
71
  }
66
72
  else {
67
- throw new Error(`Unknown type [${dataType}]: Not 'Collection(...)', not '${this.namingHelper.getServicePrefix()}*', not OData type 'Edm.*'`);
73
+ throw new Error(`Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`);
68
74
  }
69
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);
70
76
  };
71
77
  this.dataModel = new DataModel_1.DataModel(version, converters);
72
78
  this.serviceConfigHelper = new ServiceConfigHelper_1.ServiceConfigHelper(options);
73
- this.collectModelTypes(this.schema);
79
+ this.collectModelTypes(schemas);
74
80
  }
75
81
  digest() {
76
82
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
77
- this.digestSchema(this.schema);
83
+ this.digestEntityTypesAndOperations();
84
+ // delegate to version specific entity container digestion
85
+ this.schemas.forEach((schema) => this.digestEntityContainer(schema));
78
86
  return this.dataModel;
79
87
  });
80
88
  }
81
- collectModelTypes(schema) {
82
- var _a, _b, _c;
83
- const servicePrefix = this.namingHelper.getServicePrefix();
84
- (_a = schema.EnumType) === null || _a === void 0 ? void 0 : _a.forEach((et) => {
85
- this.model2Type.set(servicePrefix + et.$.Name, "EnumType" /* DataTypes.EnumType */);
86
- });
87
- (_b = schema.ComplexType) === null || _b === void 0 ? void 0 : _b.forEach((ct) => {
88
- this.model2Type.set(servicePrefix + ct.$.Name, "ComplexType" /* DataTypes.ComplexType */);
89
- });
90
- (_c = schema.EntityType) === null || _c === void 0 ? void 0 : _c.forEach((et) => {
91
- this.model2Type.set(servicePrefix + et.$.Name, "ModelType" /* DataTypes.ModelType */);
89
+ collectModelTypes(schemas) {
90
+ schemas.forEach((schema) => {
91
+ var _a, _b, _c;
92
+ const servicePrefix = schema.$.Namespace + ".";
93
+ (_a = schema.EnumType) === null || _a === void 0 ? void 0 : _a.forEach((et) => {
94
+ this.model2Type.set(servicePrefix + et.$.Name, "EnumType" /* DataTypes.EnumType */);
95
+ });
96
+ (_b = schema.ComplexType) === null || _b === void 0 ? void 0 : _b.forEach((ct) => {
97
+ this.model2Type.set(servicePrefix + ct.$.Name, "ComplexType" /* DataTypes.ComplexType */);
98
+ });
99
+ (_c = schema.EntityType) === null || _c === void 0 ? void 0 : _c.forEach((et) => {
100
+ this.model2Type.set(servicePrefix + et.$.Name, "ModelType" /* DataTypes.ModelType */);
101
+ });
92
102
  });
93
103
  }
94
- digestSchema(schema) {
95
- // enums
96
- if (schema.EnumType) {
97
- for (const et of schema.EnumType) {
98
- const name = et.$.Name;
99
- this.dataModel.addEnum(name, {
100
- odataName: name,
101
- name: this.namingHelper.getEnumName(name),
102
- members: et.Member.map((m) => m.$.Name),
103
- });
104
+ digestEntityTypesAndOperations() {
105
+ this.schemas.forEach((schema) => {
106
+ // type definitions: alias for primitive types
107
+ this.addTypeDefinition(schema.TypeDefinition);
108
+ // enums
109
+ if (schema.EnumType) {
110
+ for (const et of schema.EnumType) {
111
+ const name = et.$.Name;
112
+ this.dataModel.addEnum(name, {
113
+ odataName: name,
114
+ name: this.namingHelper.getEnumName(name),
115
+ members: et.Member.map((m) => m.$.Name),
116
+ });
117
+ }
104
118
  }
105
- }
106
- // entity types
107
- this.addEntityType(schema.EntityType);
108
- // complex types
109
- this.addComplexType(schema.ComplexType);
119
+ // entity types
120
+ this.addEntityType(schema.EntityType);
121
+ // complex types
122
+ this.addComplexType(schema.ComplexType);
123
+ // V4 only: function & action types
124
+ this.digestOperations(schema);
125
+ });
110
126
  this.postProcessModel();
111
- // delegate to concrete entity container digestion
112
- this.digestEntityContainer();
113
127
  }
114
128
  getBaseModel(model) {
115
129
  var _a;
@@ -136,6 +150,14 @@ class Digester {
136
150
  baseProps: [], // postprocess required
137
151
  };
138
152
  }
153
+ addTypeDefinition(types) {
154
+ if (!types || !types.length) {
155
+ return;
156
+ }
157
+ for (const t of types) {
158
+ this.dataModel.addTypeDefinition(t.$.Name, t.$.UnderlyingType);
159
+ }
160
+ }
139
161
  addComplexType(models) {
140
162
  if (!models || !models.length) {
141
163
  return;
@@ -247,6 +269,9 @@ class Digester {
247
269
  return model.baseClasses.reduce(([props, keys, idName, qIdName], bc) => {
248
270
  var _a;
249
271
  const baseModel = this.dataModel.getModel(bc) || this.dataModel.getComplexType(bc);
272
+ if (!baseModel) {
273
+ throw new Error(`BaseModel "${bc}" doesn't exist!`);
274
+ }
250
275
  let idNameResult = idName;
251
276
  let qIdNameResult = qIdName;
252
277
  // recursive