@odata2ts/odata2ts 0.29.1 → 0.31.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 +23 -0
- package/README.md +81 -81
- package/lib/FactoryFunctionModel.d.ts +1 -1
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/OptionModel.d.ts +54 -4
- package/lib/OptionModel.js.map +1 -1
- package/lib/app.js +1 -8
- package/lib/app.js.map +1 -1
- package/lib/data-model/DataModel.d.ts +48 -37
- package/lib/data-model/DataModel.js +130 -61
- package/lib/data-model/DataModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +2 -3
- package/lib/data-model/DataModelDigestion.js +74 -96
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataModelDigestionV2.d.ts +1 -1
- package/lib/data-model/DataModelDigestionV2.js +30 -15
- package/lib/data-model/DataModelDigestionV2.js.map +1 -1
- package/lib/data-model/DataModelDigestionV4.js +65 -43
- package/lib/data-model/DataModelDigestionV4.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +10 -1
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/NamingHelper.d.ts +6 -6
- package/lib/data-model/NamingHelper.js +14 -7
- package/lib/data-model/NamingHelper.js.map +1 -1
- package/lib/data-model/ServiceConfigHelper.d.ts +12 -3
- package/lib/data-model/ServiceConfigHelper.js +73 -11
- package/lib/data-model/ServiceConfigHelper.js.map +1 -1
- package/lib/defaultConfig.js +1 -0
- package/lib/defaultConfig.js.map +1 -1
- package/lib/generator/ImportContainer.d.ts +0 -1
- package/lib/generator/ImportContainer.js +2 -17
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/ModelGenerator.js +9 -6
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.js +12 -6
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.js +19 -27
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/project/ProjectManager.d.ts +0 -5
- package/lib/project/ProjectManager.js +1 -21
- package/lib/project/ProjectManager.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTypeModel.js","sourceRoot":"","sources":["../../src/data-model/DataTypeModel.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,0BAAU,CAAA;IACV,0BAAU,CAAA;AACZ,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\
|
|
1
|
+
{"version":3,"file":"DataTypeModel.js","sourceRoot":"","sources":["../../src/data-model/DataTypeModel.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,0BAAU,CAAA;IACV,0BAAU,CAAA;AACZ,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\n\nexport enum ODataVersion {\n V2 = \"2.0\",\n V4 = \"4.0\",\n}\n\nexport const enum DataTypes {\n PrimitiveType = \"PrimitiveType\",\n EnumType = \"EnumType\",\n ComplexType = \"ComplexType\",\n ModelType = \"ModelType\",\n}\n\nexport const enum OperationTypes {\n Function = \"Function\",\n Action = \"Action\",\n}\n\nexport interface PropertyModel {\n odataName: string;\n name: string;\n odataType: string;\n fqType: string;\n type: string;\n typeModule?: string;\n qObject?: string;\n qPath: string;\n qParam?: string;\n required: boolean;\n isCollection: boolean;\n dataType: DataTypes;\n converters?: Array<ValueConverterImport>;\n managed?: boolean;\n}\n\nexport interface ModelType extends ComplexType {\n idModelName: string;\n qIdFunctionName: string;\n generateId: boolean;\n keyNames: Array<string>;\n keys: Array<PropertyModel>;\n getKeyUnion(): string;\n}\n\nexport interface ComplexType {\n dataType: DataTypes;\n fqName: string;\n odataName: string;\n name: string;\n editableName: string;\n qName: string;\n props: Array<PropertyModel>;\n baseProps: Array<PropertyModel>;\n baseClasses: Array<string>;\n}\n\nexport interface EnumType {\n dataType: DataTypes;\n fqName: string;\n odataName: string;\n name: string;\n members: Array<string>;\n}\n\nexport interface OperationType {\n fqName: string;\n odataName: string;\n name: string;\n paramsModelName: string;\n qName: string;\n type: OperationTypes;\n parameters: Array<PropertyModel>;\n returnType?: ReturnTypeModel;\n usePost?: boolean;\n}\n\nexport interface ReturnTypeModel extends PropertyModel {}\n\nexport type EntityContainerModel = {\n entitySets: { [name: string]: EntitySetType };\n singletons: { [name: string]: SingletonType };\n functions: { [name: string]: FunctionImportType };\n actions: { [name: string]: ActionImportType };\n};\n\nexport interface SingletonType {\n fqName: string;\n odataName: string;\n name: string;\n entityType: ModelType;\n navPropBinding?: Array<NavPropBindingType>;\n}\n\nexport interface EntitySetType {\n fqName: string;\n odataName: string;\n name: string;\n entityType: ModelType;\n navPropBinding?: Array<NavPropBindingType>;\n}\n\nexport interface NavPropBindingType {\n path: string;\n target: string;\n}\n\nexport interface ActionImportType {\n fqName: string;\n odataName: string;\n name: string;\n operation: string;\n}\n\nexport interface FunctionImportType extends ActionImportType {\n entitySet: string;\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { RunOptions } from "../OptionModel";
|
|
2
|
-
import {
|
|
2
|
+
import { NamespaceWithAlias } from "./DataModel";
|
|
3
3
|
export interface NamingHelperSettings extends Pick<RunOptions, "allowRenaming" | "naming"> {
|
|
4
4
|
}
|
|
5
5
|
export declare class NamingHelper {
|
|
6
6
|
private readonly allowModelPropRenaming;
|
|
7
7
|
private readonly mainServiceName;
|
|
8
|
-
private readonly
|
|
8
|
+
private readonly namespacePrefixes;
|
|
9
9
|
private readonly options;
|
|
10
|
-
constructor(options: NamingHelperSettings, mainServiceName: string,
|
|
10
|
+
constructor(options: NamingHelperSettings, mainServiceName: string, namespaces?: Array<NamespaceWithAlias>);
|
|
11
11
|
/**
|
|
12
12
|
* The prefix used to reference model or enum types in this schema.
|
|
13
13
|
*
|
|
@@ -40,12 +40,12 @@ export declare class NamingHelper {
|
|
|
40
40
|
getEnumName(name: string): string;
|
|
41
41
|
getEditableModelName(name: string): string;
|
|
42
42
|
getIdModelName(name: string): string;
|
|
43
|
-
getOperationParamsModelName(operationName: string, boundEntity?:
|
|
43
|
+
getOperationParamsModelName(operationName: string, boundEntity?: string): string;
|
|
44
44
|
getQName(name: string): string;
|
|
45
45
|
getQPropName(name: string): string;
|
|
46
46
|
getQIdFunctionName(name: string): string;
|
|
47
|
-
getQFunctionName(operationName: string, boundEntity?:
|
|
48
|
-
getQActionName(operationName: string, boundEntity?:
|
|
47
|
+
getQFunctionName(operationName: string, boundEntity?: string): string;
|
|
48
|
+
getQActionName(operationName: string, boundEntity?: string): string;
|
|
49
49
|
getMainServiceName(): string;
|
|
50
50
|
getServiceName: (name: string) => string;
|
|
51
51
|
getCollectionServiceName: (name: string) => string;
|
|
@@ -24,7 +24,7 @@ const noopNamingFunction = (value, options) => {
|
|
|
24
24
|
return ((options === null || options === void 0 ? void 0 : options.prefix) || "") + value + ((options === null || options === void 0 ? void 0 : options.suffix) || "");
|
|
25
25
|
};
|
|
26
26
|
class NamingHelper {
|
|
27
|
-
constructor(options, mainServiceName,
|
|
27
|
+
constructor(options, mainServiceName, namespaces) {
|
|
28
28
|
var _a;
|
|
29
29
|
this.getServiceName = (name) => {
|
|
30
30
|
const opts = this.options.services;
|
|
@@ -48,13 +48,20 @@ class NamingHelper {
|
|
|
48
48
|
if (!(mainServiceName === null || mainServiceName === void 0 ? void 0 : mainServiceName.trim())) {
|
|
49
49
|
throw new Error("NamingHelper: MainServiceName must be supplied!");
|
|
50
50
|
}
|
|
51
|
-
if (!(
|
|
52
|
-
|
|
51
|
+
if (!(namespaces === null || namespaces === void 0 ? void 0 : namespaces.length)) {
|
|
52
|
+
namespaces = [[mainServiceName]];
|
|
53
53
|
}
|
|
54
54
|
this.allowModelPropRenaming = (_a = options.allowRenaming) !== null && _a !== void 0 ? _a : false;
|
|
55
55
|
this.options = options.naming;
|
|
56
56
|
this.mainServiceName = mainServiceName;
|
|
57
|
-
this.
|
|
57
|
+
this.namespacePrefixes = namespaces
|
|
58
|
+
.reduce((accu, [ns, alias]) => {
|
|
59
|
+
accu.push(ns);
|
|
60
|
+
if (alias) {
|
|
61
|
+
accu.push(alias);
|
|
62
|
+
}
|
|
63
|
+
return accu;
|
|
64
|
+
}, [])
|
|
58
65
|
.map((sn) => sn + ".")
|
|
59
66
|
.sort((a, b) => (a.length === b.length ? 0 : a.length > b.length ? -1 : 1));
|
|
60
67
|
}
|
|
@@ -64,7 +71,7 @@ class NamingHelper {
|
|
|
64
71
|
* @returns service prefix
|
|
65
72
|
*/
|
|
66
73
|
includesServicePrefix(name) {
|
|
67
|
-
for (let prefix of this.
|
|
74
|
+
for (let prefix of this.namespacePrefixes) {
|
|
68
75
|
if (name.startsWith(prefix)) {
|
|
69
76
|
return true;
|
|
70
77
|
}
|
|
@@ -95,7 +102,7 @@ class NamingHelper {
|
|
|
95
102
|
return this.getName(name, this.namingFunction(opts === null || opts === void 0 ? void 0 : opts.namingStrategy), opts);
|
|
96
103
|
}
|
|
97
104
|
stripServicePrefix(token) {
|
|
98
|
-
const found = this.
|
|
105
|
+
const found = this.namespacePrefixes.find((prefix) => token.startsWith(prefix));
|
|
99
106
|
return found ? token.replace(found, "") : token;
|
|
100
107
|
}
|
|
101
108
|
namingFunction(strategy) {
|
|
@@ -210,7 +217,7 @@ class NamingHelper {
|
|
|
210
217
|
return ((_d = opts === null || opts === void 0 ? void 0 : opts.main) === null || _d === void 0 ? void 0 : _d.applyServiceNaming) ? this.getName(result, strategy, opts) : result;
|
|
211
218
|
}
|
|
212
219
|
getPrefixedName(name, boundEntity) {
|
|
213
|
-
return
|
|
220
|
+
return boundEntity ? boundEntity + "_" + name : name;
|
|
214
221
|
}
|
|
215
222
|
getFunctionName(operationName) {
|
|
216
223
|
var _a;
|
|
@@ -1 +1 @@
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C,IAAY;;QACzC,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,0CAAE,oBAAoB,CAAC;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,CAAC,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC;CAMF;AAxOD,oCAwOC","sourcesContent":["import { camelCase } from \"camel-case\";\r\nimport { constantCase } from \"constant-case\";\r\nimport { pascalCase } from \"pascal-case\";\r\nimport { snakeCase } from \"snake-case\";\r\n\r\nimport { FileNamingStrategyOption, NameSettings, NamingStrategies, StandardNamingOptions } from \"../NamingModel\";\r\nimport { RunOptions } from \"../OptionModel\";\r\nimport { PropertyModel } from \"./DataTypeModel\";\r\n\r\nfunction getNamingStrategyImpl(strategy: NamingStrategies | undefined) {\r\n switch (strategy) {\r\n case NamingStrategies.CAMEL_CASE:\r\n return camelCase;\r\n case NamingStrategies.PASCAL_CASE:\r\n return pascalCase;\r\n case NamingStrategies.CONSTANT_CASE:\r\n return constantCase;\r\n case NamingStrategies.SNAKE_CASE:\r\n return snakeCase;\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\nconst noopNamingFunction = (value: string, options?: StandardNamingOptions) => {\r\n return (options?.prefix || \"\") + value + (options?.suffix || \"\");\r\n};\r\n\r\nexport interface NamingHelperSettings extends Pick<RunOptions, \"allowRenaming\" | \"naming\"> {}\r\n\r\nexport class NamingHelper {\r\n private readonly allowModelPropRenaming: boolean;\r\n private readonly mainServiceName: string;\r\n private readonly servicePrefixes: Array<string>;\r\n private readonly options: NameSettings;\r\n\r\n constructor(options: NamingHelperSettings, mainServiceName: string, serviceNames?: Array<string>) {\r\n if (!options) {\r\n throw new Error(\"NamingHelper: Options must be supplied!\");\r\n }\r\n if (!mainServiceName?.trim()) {\r\n throw new Error(\"NamingHelper: MainServiceName must be supplied!\");\r\n }\r\n\r\n if (!serviceNames?.length) {\r\n serviceNames = [mainServiceName];\r\n }\r\n\r\n this.allowModelPropRenaming = options.allowRenaming ?? false;\r\n this.options = options.naming;\r\n this.mainServiceName = mainServiceName;\r\n this.servicePrefixes = serviceNames\r\n .map((sn) => sn + \".\")\r\n .sort((a, b) => (a.length === b.length ? 0 : a.length > b.length ? -1 : 1));\r\n }\r\n\r\n /**\r\n * The prefix used to reference model or enum types in this schema.\r\n *\r\n * @returns service prefix\r\n */\r\n public includesServicePrefix(name: string) {\r\n for (let prefix of this.servicePrefixes) {\r\n if (name.startsWith(prefix)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * The OData service name as it was found and is used in metadata file.\r\n *\r\n * @returns\r\n */\r\n public getODataServiceName() {\r\n return this.mainServiceName;\r\n }\r\n\r\n public getFileNames() {\r\n return {\r\n model: this.getFileName(this.options.models?.fileName),\r\n qObject: this.getFileName(this.options.queryObjects?.fileName),\r\n service: this.getMainServiceName(),\r\n };\r\n }\r\n\r\n private getFileName(opts?: FileNamingStrategyOption & StandardNamingOptions) {\r\n return this.getName(this.mainServiceName, this.namingFunction(opts?.namingStrategy), opts);\r\n }\r\n\r\n public getFileNameService(name: string) {\r\n const opts = this.options.services;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n }\r\n\r\n public stripServicePrefix(token: string) {\r\n const found = this.servicePrefixes.find((prefix) => token.startsWith(prefix));\r\n return found ? token.replace(found, \"\") : token;\r\n }\r\n\r\n private namingFunction(strategy: NamingStrategies | undefined) {\r\n const strategyFn = getNamingStrategyImpl(strategy);\r\n if (!strategyFn || !this.allowModelPropRenaming) {\r\n return noopNamingFunction;\r\n }\r\n\r\n return (value: string, options?: StandardNamingOptions) => {\r\n const prefix = options?.prefix;\r\n const suffix = options?.suffix;\r\n const isPrefixSpecialChar = prefix?.startsWith(\"_\");\r\n const isSuffixSpecialChar = suffix?.endsWith(\"_\");\r\n\r\n let result = strategyFn((prefix ? prefix + \"_\" : \"\") + value + (suffix ? \"_\" + suffix : \"\"));\r\n if (isPrefixSpecialChar) {\r\n result = \"_\" + result;\r\n }\r\n if (isSuffixSpecialChar) {\r\n result = result + \"_\";\r\n }\r\n return result;\r\n };\r\n }\r\n\r\n private getName(\r\n name: string,\r\n strategy: (value: string, options?: StandardNamingOptions) => string,\r\n options?: StandardNamingOptions\r\n ) {\r\n return strategy(this.stripServicePrefix(name), options);\r\n }\r\n\r\n private getModelNamingStrategy() {\r\n return this.namingFunction(this.options.models?.namingStrategy);\r\n }\r\n\r\n private getModelPropNamingStrategy() {\r\n return this.namingFunction(this.options.models?.propNamingStrategy);\r\n }\r\n\r\n private getQObjectNamingStrategy() {\r\n return this.namingFunction(this.options.queryObjects?.namingStrategy);\r\n }\r\n\r\n private getQObjectPropNamingStrategy() {\r\n return this.namingFunction(this.options.queryObjects?.propNamingStrategy);\r\n }\r\n\r\n private getOperationNamingStrategy() {\r\n return this.namingFunction(this.options.services?.operations?.namingStrategy);\r\n }\r\n\r\n public getModelName(name: string): string {\r\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\r\n }\r\n\r\n public getModelPropName(name: string): string {\r\n return this.getName(name, this.getModelPropNamingStrategy());\r\n }\r\n\r\n public getEnumName(name: string) {\r\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\r\n }\r\n\r\n public getEditableModelName(name: string) {\r\n let options = this.options.models?.editableModels;\r\n const result = this.getName(name, this.getModelNamingStrategy(), options);\r\n return options?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n }\r\n\r\n public getIdModelName(name: string) {\r\n let options = this.options.models?.idModels;\r\n const result = this.getName(name, this.getModelNamingStrategy(), options);\r\n return options?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n }\r\n\r\n public getOperationParamsModelName(operationName: string, boundEntity?: PropertyModel | undefined) {\r\n const settings = this.options.models?.operationParamModels;\r\n const result = this.getName(operationName, this.getModelNamingStrategy(), settings);\r\n const name = settings?.applyModelNaming\r\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\r\n : result;\r\n return this.getPrefixedName(name, boundEntity);\r\n }\r\n\r\n public getQName(name: string) {\r\n return this.getName(name, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getQPropName(name: string): string {\r\n return this.getName(name, this.getQObjectPropNamingStrategy());\r\n }\r\n\r\n public getQIdFunctionName(name: string) {\r\n const opts = this.options.queryObjects?.idFunctions;\r\n const result = this.getName(name, this.getQObjectNamingStrategy(), opts);\r\n return this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n }\r\n\r\n public getQFunctionName(operationName: string, boundEntity?: PropertyModel | undefined) {\r\n const opts = this.options.queryObjects?.operations;\r\n const result = this.getName(operationName, this.getQObjectNamingStrategy(), opts?.function || opts);\r\n const name = this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n return this.getPrefixedName(name, boundEntity);\r\n }\r\n\r\n public getQActionName(operationName: string, boundEntity?: PropertyModel | undefined) {\r\n const opts = this.options.queryObjects?.operations;\r\n const result = this.getName(operationName, this.getQObjectNamingStrategy(), opts?.action || opts);\r\n const name = this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\r\n return this.getPrefixedName(name, boundEntity);\r\n }\r\n\r\n public getMainServiceName() {\r\n const name = this.getODataServiceName();\r\n const opts = this.options.services;\r\n const strategy = this.namingFunction(\r\n opts?.main?.namingStrategy ?? (opts?.main?.applyServiceNaming ? opts.namingStrategy : undefined)\r\n );\r\n const result = this.getName(name, strategy, opts?.main);\r\n return opts?.main?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\r\n }\r\n\r\n public getServiceName = (name: string) => {\r\n const opts = this.options.services;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n };\r\n\r\n public getCollectionServiceName = (name: string) => {\r\n const opts = this.options.services;\r\n const strategy = this.namingFunction(opts?.namingStrategy);\r\n const result = this.getName(name, strategy, opts?.collection);\r\n return opts?.collection?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\r\n };\r\n\r\n private getPrefixedName(name: string, boundEntity: PropertyModel | undefined) {\r\n return boundEntity?.type ? boundEntity.type + \"_\" + name : name;\r\n }\r\n\r\n public getFunctionName(operationName: string) {\r\n const opts = this.options.services?.operations;\r\n return this.getName(operationName, this.getOperationNamingStrategy(), opts?.function || opts);\r\n }\r\n\r\n public getActionName(operationName: string) {\r\n const opts = this.options.services?.operations;\r\n return this.getName(operationName, this.getOperationNamingStrategy(), opts?.action || opts);\r\n }\r\n\r\n public getRelatedServiceGetter(name: string) {\r\n const opts = this.options.services?.relatedServiceGetter;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n }\r\n\r\n public getPrivatePropName = (name: string) => {\r\n const opts = this.options.services?.privateProps;\r\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"NamingHelper.js","sourceRoot":"","sources":["../../src/data-model/NamingHelper.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,iDAA6C;AAC7C,6CAAyC;AACzC,2CAAuC;AAEvC,gDAAiH;AAKjH,SAAS,qBAAqB,CAAC,QAAsC;IACnE,QAAQ,QAAQ,EAAE;QAChB,KAAK,8BAAgB,CAAC,UAAU;YAC9B,OAAO,sBAAS,CAAC;QACnB,KAAK,8BAAgB,CAAC,WAAW;YAC/B,OAAO,wBAAU,CAAC;QACpB,KAAK,8BAAgB,CAAC,aAAa;YACjC,OAAO,4BAAY,CAAC;QACtB,KAAK,8BAAgB,CAAC,UAAU;YAC9B,OAAO,sBAAS,CAAC;QACnB;YACE,OAAO,SAAS,CAAC;KACpB;AACH,CAAC;AAED,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAE,OAA+B,EAAE,EAAE;IAC5E,OAAO,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MA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,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACxF,CAAC;IAcO,eAAe,CAAC,IAAY,EAAE,WAA+B;QACnE,OAAO,WAAW,CAAC,CAAC,CAAC,WAAW,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACvD,CAAC;IAEM,eAAe,CAAC,aAAqB;;QAC1C,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,0CAAE,UAAU,CAAC;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,KAAI,IAAI,CAAC,CAAC;IAChG,CAAC;IAEM,aAAa,CAAC,aAAqB;;QACxC,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,0CAAE,UAAU,CAAC;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,KAAI,IAAI,CAAC,CAAC;IAC9F,CAAC;IAEM,uBAAuB,CAAC,IAAY;;QACzC,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,0CAAE,oBAAoB,CAAC;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,CAAC,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC;CAMF;AA/OD,oCA+OC","sourcesContent":["import { camelCase } from \"camel-case\";\nimport { constantCase } from \"constant-case\";\nimport { pascalCase } from \"pascal-case\";\nimport { snakeCase } from \"snake-case\";\n\nimport { FileNamingStrategyOption, NameSettings, NamingStrategies, StandardNamingOptions } from \"../NamingModel\";\nimport { RunOptions } from \"../OptionModel\";\nimport { NamespaceWithAlias } from \"./DataModel\";\nimport { PropertyModel } from \"./DataTypeModel\";\n\nfunction getNamingStrategyImpl(strategy: NamingStrategies | undefined) {\n switch (strategy) {\n case NamingStrategies.CAMEL_CASE:\n return camelCase;\n case NamingStrategies.PASCAL_CASE:\n return pascalCase;\n case NamingStrategies.CONSTANT_CASE:\n return constantCase;\n case NamingStrategies.SNAKE_CASE:\n return snakeCase;\n default:\n return undefined;\n }\n}\n\nconst noopNamingFunction = (value: string, options?: StandardNamingOptions) => {\n return (options?.prefix || \"\") + value + (options?.suffix || \"\");\n};\n\nexport interface NamingHelperSettings extends Pick<RunOptions, \"allowRenaming\" | \"naming\"> {}\n\nexport class NamingHelper {\n private readonly allowModelPropRenaming: boolean;\n private readonly mainServiceName: string;\n private readonly namespacePrefixes: Array<string>;\n private readonly options: NameSettings;\n\n constructor(options: NamingHelperSettings, mainServiceName: string, namespaces?: Array<NamespaceWithAlias>) {\n if (!options) {\n throw new Error(\"NamingHelper: Options must be supplied!\");\n }\n if (!mainServiceName?.trim()) {\n throw new Error(\"NamingHelper: MainServiceName must be supplied!\");\n }\n\n if (!namespaces?.length) {\n namespaces = [[mainServiceName]];\n }\n\n this.allowModelPropRenaming = options.allowRenaming ?? false;\n this.options = options.naming;\n this.mainServiceName = mainServiceName;\n this.namespacePrefixes = namespaces\n .reduce<Array<string>>((accu, [ns, alias]) => {\n accu.push(ns);\n if (alias) {\n accu.push(alias);\n }\n return accu;\n }, [])\n .map((sn) => sn + \".\")\n .sort((a, b) => (a.length === b.length ? 0 : a.length > b.length ? -1 : 1));\n }\n\n /**\n * The prefix used to reference model or enum types in this schema.\n *\n * @returns service prefix\n */\n public includesServicePrefix(name: string) {\n for (let prefix of this.namespacePrefixes) {\n if (name.startsWith(prefix)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * The OData service name as it was found and is used in metadata file.\n *\n * @returns\n */\n public getODataServiceName() {\n return this.mainServiceName;\n }\n\n public getFileNames() {\n return {\n model: this.getFileName(this.options.models?.fileName),\n qObject: this.getFileName(this.options.queryObjects?.fileName),\n service: this.getMainServiceName(),\n };\n }\n\n private getFileName(opts?: FileNamingStrategyOption & StandardNamingOptions) {\n return this.getName(this.mainServiceName, this.namingFunction(opts?.namingStrategy), opts);\n }\n\n public getFileNameService(name: string) {\n const opts = this.options.services;\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\n }\n\n public stripServicePrefix(token: string) {\n const found = this.namespacePrefixes.find((prefix) => token.startsWith(prefix));\n return found ? token.replace(found, \"\") : token;\n }\n\n private namingFunction(strategy: NamingStrategies | undefined) {\n const strategyFn = getNamingStrategyImpl(strategy);\n if (!strategyFn || !this.allowModelPropRenaming) {\n return noopNamingFunction;\n }\n\n return (value: string, options?: StandardNamingOptions) => {\n const prefix = options?.prefix;\n const suffix = options?.suffix;\n const isPrefixSpecialChar = prefix?.startsWith(\"_\");\n const isSuffixSpecialChar = suffix?.endsWith(\"_\");\n\n let result = strategyFn((prefix ? prefix + \"_\" : \"\") + value + (suffix ? \"_\" + suffix : \"\"));\n if (isPrefixSpecialChar) {\n result = \"_\" + result;\n }\n if (isSuffixSpecialChar) {\n result = result + \"_\";\n }\n return result;\n };\n }\n\n private getName(\n name: string,\n strategy: (value: string, options?: StandardNamingOptions) => string,\n options?: StandardNamingOptions\n ) {\n return strategy(this.stripServicePrefix(name), options);\n }\n\n private getModelNamingStrategy() {\n return this.namingFunction(this.options.models?.namingStrategy);\n }\n\n private getModelPropNamingStrategy() {\n return this.namingFunction(this.options.models?.propNamingStrategy);\n }\n\n private getQObjectNamingStrategy() {\n return this.namingFunction(this.options.queryObjects?.namingStrategy);\n }\n\n private getQObjectPropNamingStrategy() {\n return this.namingFunction(this.options.queryObjects?.propNamingStrategy);\n }\n\n private getOperationNamingStrategy() {\n return this.namingFunction(this.options.services?.operations?.namingStrategy);\n }\n\n public getModelName(name: string): string {\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\n }\n\n public getModelPropName(name: string): string {\n return this.getName(name, this.getModelPropNamingStrategy());\n }\n\n public getEnumName(name: string) {\n return this.getName(name, this.getModelNamingStrategy(), this.options.models);\n }\n\n public getEditableModelName(name: string) {\n let options = this.options.models?.editableModels;\n const result = this.getName(name, this.getModelNamingStrategy(), options);\n return options?.applyModelNaming\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\n : result;\n }\n\n public getIdModelName(name: string) {\n let options = this.options.models?.idModels;\n const result = this.getName(name, this.getModelNamingStrategy(), options);\n return options?.applyModelNaming\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\n : result;\n }\n\n public getOperationParamsModelName(operationName: string, boundEntity?: string) {\n const settings = this.options.models?.operationParamModels;\n const result = this.getName(operationName, this.getModelNamingStrategy(), settings);\n const name = settings?.applyModelNaming\n ? this.getName(result, this.getModelNamingStrategy(), this.options.models)\n : result;\n return this.getPrefixedName(name, boundEntity);\n }\n\n public getQName(name: string) {\n return this.getName(name, this.getQObjectNamingStrategy(), this.options.queryObjects);\n }\n\n public getQPropName(name: string): string {\n return this.getName(name, this.getQObjectPropNamingStrategy());\n }\n\n public getQIdFunctionName(name: string) {\n const opts = this.options.queryObjects?.idFunctions;\n const result = this.getName(name, this.getQObjectNamingStrategy(), opts);\n return this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\n }\n\n public getQFunctionName(operationName: string, boundEntity?: string) {\n const opts = this.options.queryObjects?.operations;\n const result = this.getName(operationName, this.getQObjectNamingStrategy(), opts?.function || opts);\n const name = this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\n return this.getPrefixedName(name, boundEntity);\n }\n\n public getQActionName(operationName: string, boundEntity?: string) {\n const opts = this.options.queryObjects?.operations;\n const result = this.getName(operationName, this.getQObjectNamingStrategy(), opts?.action || opts);\n const name = this.getName(result, this.getQObjectNamingStrategy(), this.options.queryObjects);\n return this.getPrefixedName(name, boundEntity);\n }\n\n public getMainServiceName() {\n const name = this.getODataServiceName();\n const opts = this.options.services;\n const strategy = this.namingFunction(\n opts?.main?.namingStrategy ?? (opts?.main?.applyServiceNaming ? opts.namingStrategy : undefined)\n );\n const result = this.getName(name, strategy, opts?.main);\n return opts?.main?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\n }\n\n public getServiceName = (name: string) => {\n const opts = this.options.services;\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\n };\n\n public getCollectionServiceName = (name: string) => {\n const opts = this.options.services;\n const strategy = this.namingFunction(opts?.namingStrategy);\n const result = this.getName(name, strategy, opts?.collection);\n return opts?.collection?.applyServiceNaming ? this.getName(result, strategy, opts) : result;\n };\n\n private getPrefixedName(name: string, boundEntity: string | undefined) {\n return boundEntity ? boundEntity + \"_\" + name : name;\n }\n\n public getFunctionName(operationName: string) {\n const opts = this.options.services?.operations;\n return this.getName(operationName, this.getOperationNamingStrategy(), opts?.function || opts);\n }\n\n public getActionName(operationName: string) {\n const opts = this.options.services?.operations;\n return this.getName(operationName, this.getOperationNamingStrategy(), opts?.action || opts);\n }\n\n public getRelatedServiceGetter(name: string) {\n const opts = this.options.services?.relatedServiceGetter;\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\n }\n\n public getPrivatePropName = (name: string) => {\n const opts = this.options.services?.privateProps;\n return this.getName(name, this.namingFunction(opts?.namingStrategy), opts);\n };\n}\n"]}
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import { DigestionOptions } from "../FactoryFunctionModel";
|
|
2
|
-
import { EntityGenerationOptions, PropertyGenerationOptions } from "../OptionModel";
|
|
2
|
+
import { EntityGenerationOptions, OperationGenerationOptions, PropertyGenerationOptions } from "../OptionModel";
|
|
3
|
+
import { NamespaceWithAlias } from "./DataModel";
|
|
3
4
|
export interface ConfiguredProp extends Omit<PropertyGenerationOptions, "name"> {
|
|
4
5
|
}
|
|
5
6
|
export interface ConfiguredEntity extends Omit<EntityGenerationOptions, "name"> {
|
|
6
7
|
}
|
|
8
|
+
export interface ConfiguredOperation extends Omit<OperationGenerationOptions, "name"> {
|
|
9
|
+
}
|
|
7
10
|
export declare class ServiceConfigHelper {
|
|
8
11
|
private propMapping;
|
|
9
12
|
private entityMapping;
|
|
13
|
+
private operationMapping;
|
|
10
14
|
private propRegExps;
|
|
11
15
|
private entityRegExps;
|
|
16
|
+
private operationRegExps;
|
|
12
17
|
constructor(options: DigestionOptions);
|
|
13
18
|
private evaluateProps;
|
|
14
19
|
private getPropByName;
|
|
15
20
|
private getPropByRegExp;
|
|
16
|
-
|
|
21
|
+
findPropConfigByName: (name: string) => ConfiguredProp | undefined;
|
|
17
22
|
private evaluateEntities;
|
|
18
23
|
private getEntityByName;
|
|
19
24
|
private getEntityByRegExp;
|
|
20
|
-
|
|
25
|
+
findEntityConfigByName: (namespace: NamespaceWithAlias, name: string) => ConfiguredEntity | undefined;
|
|
26
|
+
private evaluateOperations;
|
|
27
|
+
private getOperationByName;
|
|
28
|
+
private getOperationByRegExp;
|
|
29
|
+
findOperationConfigByName: (namespace: NamespaceWithAlias, name: string) => ConfiguredOperation | undefined;
|
|
21
30
|
}
|
|
@@ -2,26 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServiceConfigHelper = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const DataModel_1 = require("./DataModel");
|
|
5
6
|
const EXCEPTION_NO_NAME = "No value for required attribute [name] specified!";
|
|
6
7
|
const EXCEPTION_WRONG_NAME_TYPE = "Wrong type for attribute [name]! You have to supply either a plain string or a RegExp.";
|
|
7
8
|
class ServiceConfigHelper {
|
|
8
9
|
constructor(options) {
|
|
9
10
|
this.propMapping = new Map();
|
|
10
11
|
this.entityMapping = new Map();
|
|
12
|
+
this.operationMapping = new Map();
|
|
11
13
|
this.propRegExps = [];
|
|
12
14
|
this.entityRegExps = [];
|
|
13
|
-
this.
|
|
15
|
+
this.operationRegExps = [];
|
|
16
|
+
this.findPropConfigByName = (name) => {
|
|
14
17
|
const stringProp = this.getPropByName(name);
|
|
15
18
|
const reProp = this.getPropByRegExp(name);
|
|
16
19
|
return stringProp && reProp ? Object.assign(Object.assign({}, reProp), stringProp) : stringProp || reProp;
|
|
17
20
|
};
|
|
18
|
-
this.
|
|
19
|
-
const stringEnt = this.getEntityByName(name);
|
|
20
|
-
const reEnt = this.getEntityByRegExp(name);
|
|
21
|
+
this.findEntityConfigByName = (namespace, name) => {
|
|
22
|
+
const stringEnt = this.getEntityByName(namespace, name);
|
|
23
|
+
const reEnt = this.getEntityByRegExp(namespace, name);
|
|
24
|
+
return stringEnt && reEnt ? Object.assign(Object.assign({}, reEnt), stringEnt) : stringEnt || reEnt;
|
|
25
|
+
};
|
|
26
|
+
this.findOperationConfigByName = (namespace, name) => {
|
|
27
|
+
const stringEnt = this.getOperationByName(namespace, name);
|
|
28
|
+
const reEnt = this.getOperationByRegExp(namespace, name);
|
|
21
29
|
return stringEnt && reEnt ? Object.assign(Object.assign({}, reEnt), stringEnt) : stringEnt || reEnt;
|
|
22
30
|
};
|
|
23
31
|
this.evaluateProps(options);
|
|
24
32
|
this.evaluateEntities(options);
|
|
33
|
+
this.evaluateOperations(options);
|
|
25
34
|
}
|
|
26
35
|
evaluateProps(options) {
|
|
27
36
|
options.propertiesByName.forEach((prop) => {
|
|
@@ -88,20 +97,73 @@ class ServiceConfigHelper {
|
|
|
88
97
|
}
|
|
89
98
|
});
|
|
90
99
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
// get entity config by name matching: simple name or fully qualified name (alias also supported)
|
|
101
|
+
getEntityByName(namespace, nameToMap) {
|
|
102
|
+
const [ns, alias] = namespace;
|
|
103
|
+
const config = this.entityMapping.get((0, DataModel_1.withNamespace)(ns, nameToMap)) ||
|
|
104
|
+
(alias ? this.entityMapping.get((0, DataModel_1.withNamespace)(alias, nameToMap)) : undefined) ||
|
|
105
|
+
this.entityMapping.get(nameToMap);
|
|
106
|
+
if (!config) {
|
|
94
107
|
return;
|
|
95
108
|
}
|
|
96
|
-
const { name } =
|
|
109
|
+
const { name } = config, attrs = tslib_1.__rest(config, ["name"]);
|
|
97
110
|
return Object.assign({}, attrs);
|
|
98
111
|
}
|
|
99
|
-
getEntityByRegExp(nameToMap) {
|
|
112
|
+
getEntityByRegExp([mainNs, alias], nameToMap) {
|
|
113
|
+
const fqName = `${mainNs}.${nameToMap}`;
|
|
100
114
|
const resultList = this.entityRegExps
|
|
101
|
-
.filter(([regExp]) => regExp.test(
|
|
115
|
+
.filter(([regExp]) => regExp.test(fqName))
|
|
102
116
|
.map((_a) => {
|
|
103
117
|
var [regExp, _b] = _a, { name, mappedName } = _b, attrs = tslib_1.__rest(_b, ["name", "mappedName"]);
|
|
104
|
-
return (Object.assign({ mappedName: mappedName ?
|
|
118
|
+
return (Object.assign({ mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined }, attrs));
|
|
119
|
+
});
|
|
120
|
+
return !resultList.length
|
|
121
|
+
? undefined
|
|
122
|
+
: resultList.reduce((result, prop) => {
|
|
123
|
+
return Object.assign(Object.assign({}, result), prop);
|
|
124
|
+
}, {});
|
|
125
|
+
}
|
|
126
|
+
evaluateOperations(options) {
|
|
127
|
+
options.operationsByName.forEach((op) => {
|
|
128
|
+
if (!op.name) {
|
|
129
|
+
throw new Error(EXCEPTION_NO_NAME);
|
|
130
|
+
}
|
|
131
|
+
switch (typeof op.name) {
|
|
132
|
+
case "string":
|
|
133
|
+
// TODO: check for existing operation name and throw?
|
|
134
|
+
this.operationMapping.set(op.name, op);
|
|
135
|
+
break;
|
|
136
|
+
case "object":
|
|
137
|
+
const { source, ignoreCase } = op.name;
|
|
138
|
+
if (!source) {
|
|
139
|
+
throw new Error(EXCEPTION_WRONG_NAME_TYPE);
|
|
140
|
+
}
|
|
141
|
+
this.operationRegExps.push([new RegExp(`^${source}$`, ignoreCase ? "i" : ""), op]);
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
throw new Error(EXCEPTION_WRONG_NAME_TYPE);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// get entity config by name matching: simple name or fully qualified name (alias also supported)
|
|
149
|
+
getOperationByName(namespace, nameToMap) {
|
|
150
|
+
const [ns, alias] = namespace;
|
|
151
|
+
const config = this.operationMapping.get((0, DataModel_1.withNamespace)(ns, nameToMap)) ||
|
|
152
|
+
(alias ? this.operationMapping.get((0, DataModel_1.withNamespace)(alias, nameToMap)) : undefined) ||
|
|
153
|
+
this.operationMapping.get(nameToMap);
|
|
154
|
+
if (!config) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const { name } = config, attrs = tslib_1.__rest(config, ["name"]);
|
|
158
|
+
return Object.assign({}, attrs);
|
|
159
|
+
}
|
|
160
|
+
getOperationByRegExp([mainNs, alias], nameToMap) {
|
|
161
|
+
const fqName = `${mainNs}.${nameToMap}`;
|
|
162
|
+
const resultList = this.operationRegExps
|
|
163
|
+
.filter(([regExp]) => regExp.test(fqName))
|
|
164
|
+
.map((_a) => {
|
|
165
|
+
var [regExp, _b] = _a, { name, mappedName } = _b, attrs = tslib_1.__rest(_b, ["name", "mappedName"]);
|
|
166
|
+
return (Object.assign({ mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined }, attrs));
|
|
105
167
|
});
|
|
106
168
|
return !resultList.length
|
|
107
169
|
? undefined
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceConfigHelper.js","sourceRoot":"","sources":["../../src/data-model/ServiceConfigHelper.ts"],"names":[],"mappings":";;;;AAMA,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;AAC9E,MAAM,yBAAyB,GAC7B,wFAAwF,CAAC;AAE3F,MAAa,mBAAmB;IAM9B,YAAY,OAAyB;QAL7B,gBAAW,GAAG,IAAI,GAAG,EAAqC,CAAC;QAC3D,kBAAa,GAAG,IAAI,GAAG,EAAmC,CAAC;QAC3D,gBAAW,GAA+C,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AAK,EAAG;IACtB,CAAC;IAEO,iBAAiB,CAAC,SAAiB;QACzC,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa;aAClC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aAC5C,GAAG,CAAC,CAAC,EAAwC,EAAE,EAAE;gBAA5C,CAAC,MAAM,UAAiC,EAA/B,EAAE,IAAI,EAAE,UAAU,OAAY,EAAP,KAAK,sBAA5B,sBAA8B,CAAF;YAAQ,OAAA,iBACjD,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,IACvE,KAAK,EACR,CAAA;SAAA,CAAC,CAAC;QAEN,OAAO,CAAC,UAAU,CAAC,MAAM;YACvB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,UAAU,CAAC,MAAM,CAAmB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;gBACnD,uCAAY,MAAM,GAAK,IAAI,EAAG;YAChC,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,CAAC;CAQF;AAtHD,kDAsHC","sourcesContent":["import { DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { EntityGenerationOptions, PropertyGenerationOptions } from \"../OptionModel\";\r\n\r\nexport interface ConfiguredProp extends Omit<PropertyGenerationOptions, \"name\"> {}\r\nexport interface ConfiguredEntity extends Omit<EntityGenerationOptions, \"name\"> {}\r\n\r\nconst EXCEPTION_NO_NAME = \"No value for required attribute [name] specified!\";\r\nconst EXCEPTION_WRONG_NAME_TYPE =\r\n \"Wrong type for attribute [name]! You have to supply either a plain string or a RegExp.\";\r\n\r\nexport class ServiceConfigHelper {\r\n private propMapping = new Map<string, PropertyGenerationOptions>();\r\n private entityMapping = new Map<string, EntityGenerationOptions>();\r\n private propRegExps: Array<[RegExp, PropertyGenerationOptions]> = [];\r\n private entityRegExps: Array<[RegExp, EntityGenerationOptions]> = [];\r\n\r\n constructor(options: DigestionOptions) {\r\n this.evaluateProps(options);\r\n this.evaluateEntities(options);\r\n }\r\n\r\n private evaluateProps(options: DigestionOptions) {\r\n options.propertiesByName.forEach((prop) => {\r\n if (!prop.name) {\r\n throw new Error(EXCEPTION_NO_NAME);\r\n }\r\n switch (typeof prop.name) {\r\n case \"string\":\r\n // TODO: check for existing prop.name and throw?\r\n this.propMapping.set(prop.name, prop);\r\n break;\r\n case \"object\":\r\n const { source, ignoreCase } = prop.name as RegExp;\r\n if (!source) {\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n this.propRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), prop]);\r\n break;\r\n default:\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n });\r\n }\r\n\r\n private getPropByName(nameToMap: string): ConfiguredProp | undefined {\r\n const stringProp = this.propMapping.get(nameToMap);\r\n if (!stringProp) {\r\n return;\r\n }\r\n const { name, ...attrs } = stringProp;\r\n return { ...attrs };\r\n }\r\n\r\n private getPropByRegExp(nameToMap: string): ConfiguredProp | undefined {\r\n const resultList = this.propRegExps\r\n .filter(([regExp]) => regExp.test(nameToMap))\r\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\r\n mappedName: mappedName ? nameToMap.replace(regExp, mappedName) : undefined,\r\n ...attrs,\r\n }));\r\n\r\n return !resultList.length\r\n ? undefined\r\n : resultList.reduce<ConfiguredProp>((result, prop) => {\r\n return { ...result, ...prop };\r\n }, {});\r\n }\r\n\r\n public findConfigPropByName = (name: string): ConfiguredProp | undefined => {\r\n const stringProp = this.getPropByName(name);\r\n const reProp = this.getPropByRegExp(name);\r\n\r\n return stringProp && reProp ? { ...reProp, ...stringProp } : stringProp || reProp;\r\n };\r\n\r\n private evaluateEntities(options: DigestionOptions) {\r\n options.entitiesByName.forEach((ent) => {\r\n if (!ent.name) {\r\n throw new Error(EXCEPTION_NO_NAME);\r\n }\r\n switch (typeof ent.name) {\r\n case \"string\":\r\n // TODO: check for existing prop.name and throw?\r\n this.entityMapping.set(ent.name, ent);\r\n break;\r\n case \"object\":\r\n const { source, ignoreCase } = ent.name as RegExp;\r\n if (!source) {\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n this.entityRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), ent]);\r\n break;\r\n default:\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n });\r\n }\r\n\r\n private getEntityByName(nameToMap: string): ConfiguredEntity | undefined {\r\n const stringProp = this.entityMapping.get(nameToMap);\r\n if (!stringProp) {\r\n return;\r\n }\r\n const { name, ...attrs } = stringProp;\r\n return { ...attrs };\r\n }\r\n\r\n private getEntityByRegExp(nameToMap: string): ConfiguredEntity | undefined {\r\n const resultList = this.entityRegExps\r\n .filter(([regExp]) => regExp.test(nameToMap))\r\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\r\n mappedName: mappedName ? nameToMap.replace(regExp, mappedName) : undefined,\r\n ...attrs,\r\n }));\r\n\r\n return !resultList.length\r\n ? undefined\r\n : resultList.reduce<ConfiguredEntity>((result, prop) => {\r\n return { ...result, ...prop };\r\n }, {});\r\n }\r\n\r\n public findConfigEntityByName = (name: string): ConfiguredEntity | undefined => {\r\n const stringEnt = this.getEntityByName(name);\r\n const reEnt = this.getEntityByRegExp(name);\r\n\r\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ServiceConfigHelper.js","sourceRoot":"","sources":["../../src/data-model/ServiceConfigHelper.ts"],"names":[],"mappings":";;;;AAEA,2CAAgE;AAMhE,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;AAC9E,MAAM,yBAAyB,GAC7B,wFAAwF,CAAC;AAE3F,MAAa,mBAAmB;IAQ9B,YAAY,OAAyB;QAP7B,gBAAW,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AU,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,IACpE,KAAK,EACR,CAAA;SAAA,CAAC,CAAC;QAEN,OAAO,CAAC,UAAU,CAAC,MAAM;YACvB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,UAAU,CAAC,MAAM,CAAmB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;gBACnD,uCAAY,MAAM,GAAK,IAAI,EAAG;YAChC,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,CAAC;CAQF;AAhMD,kDAgMC","sourcesContent":["import { DigestionOptions } from \"../FactoryFunctionModel\";\nimport { EntityGenerationOptions, OperationGenerationOptions, PropertyGenerationOptions } from \"../OptionModel\";\nimport { NamespaceWithAlias, withNamespace } from \"./DataModel\";\n\nexport interface ConfiguredProp extends Omit<PropertyGenerationOptions, \"name\"> {}\nexport interface ConfiguredEntity extends Omit<EntityGenerationOptions, \"name\"> {}\nexport interface ConfiguredOperation extends Omit<OperationGenerationOptions, \"name\"> {}\n\nconst EXCEPTION_NO_NAME = \"No value for required attribute [name] specified!\";\nconst EXCEPTION_WRONG_NAME_TYPE =\n \"Wrong type for attribute [name]! You have to supply either a plain string or a RegExp.\";\n\nexport class ServiceConfigHelper {\n private propMapping = new Map<string, PropertyGenerationOptions>();\n private entityMapping = new Map<string, EntityGenerationOptions>();\n private operationMapping = new Map<string, OperationGenerationOptions>();\n private propRegExps: Array<[RegExp, PropertyGenerationOptions]> = [];\n private entityRegExps: Array<[RegExp, EntityGenerationOptions]> = [];\n private operationRegExps: Array<[RegExp, OperationGenerationOptions]> = [];\n\n constructor(options: DigestionOptions) {\n this.evaluateProps(options);\n this.evaluateEntities(options);\n this.evaluateOperations(options);\n }\n\n private evaluateProps(options: DigestionOptions) {\n options.propertiesByName.forEach((prop) => {\n if (!prop.name) {\n throw new Error(EXCEPTION_NO_NAME);\n }\n switch (typeof prop.name) {\n case \"string\":\n // TODO: check for existing prop.name and throw?\n this.propMapping.set(prop.name, prop);\n break;\n case \"object\":\n const { source, ignoreCase } = prop.name as RegExp;\n if (!source) {\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n this.propRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), prop]);\n break;\n default:\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n });\n }\n\n private getPropByName(nameToMap: string): ConfiguredProp | undefined {\n const stringProp = this.propMapping.get(nameToMap);\n if (!stringProp) {\n return;\n }\n const { name, ...attrs } = stringProp;\n return { ...attrs };\n }\n\n private getPropByRegExp(nameToMap: string): ConfiguredProp | undefined {\n const resultList = this.propRegExps\n .filter(([regExp]) => regExp.test(nameToMap))\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\n mappedName: mappedName ? nameToMap.replace(regExp, mappedName) : undefined,\n ...attrs,\n }));\n\n return !resultList.length\n ? undefined\n : resultList.reduce<ConfiguredProp>((result, prop) => {\n return { ...result, ...prop };\n }, {});\n }\n\n public findPropConfigByName = (name: string): ConfiguredProp | undefined => {\n const stringProp = this.getPropByName(name);\n const reProp = this.getPropByRegExp(name);\n\n return stringProp && reProp ? { ...reProp, ...stringProp } : stringProp || reProp;\n };\n\n private evaluateEntities(options: DigestionOptions) {\n options.entitiesByName.forEach((ent) => {\n if (!ent.name) {\n throw new Error(EXCEPTION_NO_NAME);\n }\n switch (typeof ent.name) {\n case \"string\":\n // TODO: check for existing prop.name and throw?\n this.entityMapping.set(ent.name, ent);\n break;\n case \"object\":\n const { source, ignoreCase } = ent.name as RegExp;\n if (!source) {\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n this.entityRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), ent]);\n break;\n default:\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n });\n }\n\n // get entity config by name matching: simple name or fully qualified name (alias also supported)\n private getEntityByName(namespace: NamespaceWithAlias, nameToMap: string): ConfiguredEntity | undefined {\n const [ns, alias] = namespace;\n\n const config =\n this.entityMapping.get(withNamespace(ns, nameToMap)) ||\n (alias ? this.entityMapping.get(withNamespace(alias, nameToMap)) : undefined) ||\n this.entityMapping.get(nameToMap);\n if (!config) {\n return;\n }\n const { name, ...attrs } = config;\n return { ...attrs };\n }\n\n private getEntityByRegExp([mainNs, alias]: NamespaceWithAlias, nameToMap: string): ConfiguredEntity | undefined {\n const fqName = `${mainNs}.${nameToMap}`;\n const resultList = this.entityRegExps\n .filter(([regExp]) => regExp.test(fqName))\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\n mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined,\n ...attrs,\n }));\n\n return !resultList.length\n ? undefined\n : resultList.reduce<ConfiguredEntity>((result, prop) => {\n return { ...result, ...prop };\n }, {});\n }\n\n public findEntityConfigByName = (namespace: NamespaceWithAlias, name: string): ConfiguredEntity | undefined => {\n const stringEnt = this.getEntityByName(namespace, name);\n const reEnt = this.getEntityByRegExp(namespace, name);\n\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\n };\n\n private evaluateOperations(options: DigestionOptions) {\n options.operationsByName.forEach((op) => {\n if (!op.name) {\n throw new Error(EXCEPTION_NO_NAME);\n }\n switch (typeof op.name) {\n case \"string\":\n // TODO: check for existing operation name and throw?\n this.operationMapping.set(op.name, op);\n break;\n case \"object\":\n const { source, ignoreCase } = op.name as RegExp;\n if (!source) {\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n this.operationRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), op]);\n break;\n default:\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n });\n }\n\n // get entity config by name matching: simple name or fully qualified name (alias also supported)\n private getOperationByName(namespace: NamespaceWithAlias, nameToMap: string): ConfiguredOperation | undefined {\n const [ns, alias] = namespace;\n\n const config =\n this.operationMapping.get(withNamespace(ns, nameToMap)) ||\n (alias ? this.operationMapping.get(withNamespace(alias, nameToMap)) : undefined) ||\n this.operationMapping.get(nameToMap);\n if (!config) {\n return;\n }\n const { name, ...attrs } = config;\n return { ...attrs };\n }\n\n private getOperationByRegExp(\n [mainNs, alias]: NamespaceWithAlias,\n nameToMap: string\n ): ConfiguredOperation | undefined {\n const fqName = `${mainNs}.${nameToMap}`;\n const resultList = this.operationRegExps\n .filter(([regExp]) => regExp.test(fqName))\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\n mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined,\n ...attrs,\n }));\n\n return !resultList.length\n ? undefined\n : resultList.reduce<ConfiguredEntity>((result, prop) => {\n return { ...result, ...prop };\n }, {});\n }\n\n public findOperationConfigByName = (namespace: NamespaceWithAlias, name: string): ConfiguredOperation | undefined => {\n const stringEnt = this.getOperationByName(namespace, name);\n const reEnt = this.getOperationByRegExp(namespace, name);\n\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\n };\n}\n"]}
|
package/lib/defaultConfig.js
CHANGED
package/lib/defaultConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.ts"],"names":[],"mappings":";;;;AAAA,kEAAkC;AAElC,+CAA+D;AAC/D,+CAA6D;AAG7D;;GAEG;AACH,MAAM,aAAa,GAAyB;IAC1C,eAAe,EAAE,EAAE;IACnB,WAAW,EAAE,KAAK;IAClB,IAAI,EAAE,mBAAK,CAAC,GAAG;IACf,QAAQ,EAAE,uBAAS,CAAC,MAAM;IAC1B,KAAK,EAAE,KAAK;IACZ,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,eAAe;IACzB,UAAU,EAAE,EAAE;IACd,kBAAkB,EAAE,KAAK;IACzB,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,KAAK;IACrB,YAAY,EAAE,KAAK;IACnB,+BAA+B,EAAE,KAAK;IACtC,qBAAqB,EAAE,K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AAE,QAAQ,CAAC,UAAU,CAAC,MAAM;YAClC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM;SACnC;QACD,YAAY,EAAE;YACZ,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,MAAM;YACpC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,MAAM;SACrC;QACD,oBAAoB,EAAE;YACpB,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,MAAM;YAC5C,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,MAAM;SAC7C;KACF;CACF,CAAC;AAEF;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,mBAAS,EAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAFD,4CAEC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,MAAM,EAAE,MAAM,KAAqB,aAAa,EAA7B,WAAW,kBAAK,aAAa,EAA1C,UAA0B,CAAgB,CAAC;IACjD,OAAO,IAAA,mBAAS,EAAC,WAAW,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;AACjE,CAAC;AAHD,4CAGC","sourcesContent":["import deepmerge from \"deepmerge\";\n\nimport { NameSettings, NamingStrategies } from \"./NamingModel\";\nimport { EmitModes, Modes, RunOptions } from \"./OptionModel\";\n\nexport type DefaultConfiguration = Omit<RunOptions, \"sourceUrl\" | \"source\" | \"output\" | \"serviceName\">;\n/**\n * The default configuration.\n */\nconst defaultConfig: DefaultConfiguration = {\n sourceUrlConfig: {},\n refreshFile: false,\n mode: Modes.all,\n emitMode: EmitModes.js_dts,\n debug: false,\n prettier: false,\n tsconfig: \"tsconfig.json\",\n converters: [],\n skipEditableModels: false,\n skipIdModels: false,\n skipOperations: false,\n skipComments: false,\n enablePrimitivePropertyServices: false,\n disableAutoManagedKey: false,\n allowRenaming: false,\n v2ModelsWithExtraResultsWrapping: false,\n v4BigNumberAsString: false,\n naming: {\n models: {\n namingStrategy: NamingStrategies.PASCAL_CASE,\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\n editableModels: {\n prefix: \"Editable\",\n suffix: \"\",\n applyModelNaming: true,\n },\n idModels: {\n prefix: \"\",\n suffix: \"Id\",\n applyModelNaming: true,\n },\n operationParamModels: {\n prefix: \"\",\n suffix: \"Params\",\n applyModelNaming: true,\n },\n fileName: {\n namingStrategy: NamingStrategies.PASCAL_CASE,\n prefix: \"\",\n suffix: \"Model\",\n },\n },\n queryObjects: {\n namingStrategy: NamingStrategies.PASCAL_CASE,\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\n prefix: \"Q\",\n suffix: \"\",\n idFunctions: {\n prefix: \"\",\n suffix: \"Id\",\n },\n fileName: {\n namingStrategy: NamingStrategies.PASCAL_CASE,\n prefix: \"Q\",\n suffix: \"\",\n },\n },\n services: {\n prefix: \"\",\n suffix: \"Service\",\n namingStrategy: NamingStrategies.PASCAL_CASE,\n main: {\n applyServiceNaming: true,\n },\n collection: {\n prefix: \"\",\n suffix: \"Collection\",\n applyServiceNaming: true,\n },\n operations: {\n namingStrategy: NamingStrategies.CAMEL_CASE,\n },\n relatedServiceGetter: {\n namingStrategy: NamingStrategies.CAMEL_CASE,\n prefix: \"\",\n suffix: \"\",\n },\n privateProps: {\n namingStrategy: NamingStrategies.CAMEL_CASE,\n prefix: \"_\",\n suffix: \"\",\n },\n },\n },\n propertiesByName: [],\n entitiesByName: [],\n operationsByName: [],\n};\n\nconst { models, queryObjects, services } = defaultConfig.naming;\nconst minimalNamingConfig: NameSettings = {\n models: {\n fileName: {\n prefix: models.fileName.prefix,\n suffix: models.fileName.suffix,\n },\n idModels: {\n applyModelNaming: true,\n prefix: models.idModels.prefix,\n suffix: models.idModels.suffix,\n },\n editableModels: {\n applyModelNaming: true,\n prefix: models.editableModels.prefix,\n suffix: models.editableModels.suffix,\n },\n operationParamModels: {\n applyModelNaming: true,\n prefix: models.operationParamModels.prefix,\n suffix: models.operationParamModels.suffix,\n },\n },\n queryObjects: {\n prefix: queryObjects.prefix,\n suffix: queryObjects.suffix,\n fileName: {\n prefix: queryObjects.fileName.prefix,\n suffix: queryObjects.fileName.suffix,\n },\n idFunctions: {\n prefix: queryObjects.idFunctions.prefix,\n suffix: queryObjects.idFunctions.suffix,\n },\n },\n services: {\n prefix: services.prefix,\n suffix: services.suffix,\n main: {\n applyServiceNaming: true,\n },\n collection: {\n applyServiceNaming: true,\n prefix: services.collection.prefix,\n suffix: services.collection.suffix,\n },\n privateProps: {\n prefix: services.privateProps.prefix,\n suffix: services.privateProps.suffix,\n },\n relatedServiceGetter: {\n prefix: services.relatedServiceGetter.prefix,\n suffix: services.relatedServiceGetter.suffix,\n },\n },\n};\n\n/**\n * Creates a defensive copy of the default config.\n */\nexport function getDefaultConfig(): DefaultConfiguration {\n return deepmerge(defaultConfig, {});\n}\n\n/**\n * Creates a defensive copy of the minimal config: minimal in respect to naming.\n */\nexport function getMinimalConfig(): DefaultConfiguration {\n const { naming, ...passThrough } = defaultConfig;\n return deepmerge(passThrough, { naming: minimalNamingConfig });\n}\n"]}
|
|
@@ -11,6 +11,5 @@ export declare class ImportContainer {
|
|
|
11
11
|
addGeneratedModel(...names: Array<string>): void;
|
|
12
12
|
addGeneratedQObject(...names: Array<string>): void;
|
|
13
13
|
addCustomType(moduleName: string, typeName: string): void;
|
|
14
|
-
addGeneratedService(key: string, ...names: Array<string>): void;
|
|
15
14
|
getImportDeclarations(fromSubPath?: boolean): Array<ImportDeclarationStructure>;
|
|
16
15
|
}
|
|
@@ -19,7 +19,6 @@ class ImportContainer {
|
|
|
19
19
|
service: new Set(),
|
|
20
20
|
genModel: new Set(),
|
|
21
21
|
genQObjects: new Set(),
|
|
22
|
-
genServices: {},
|
|
23
22
|
customTypes: new Map(),
|
|
24
23
|
};
|
|
25
24
|
this.mapping.genModel.moduleName = fileNames.model;
|
|
@@ -51,16 +50,8 @@ class ImportContainer {
|
|
|
51
50
|
}
|
|
52
51
|
importList.add(typeName);
|
|
53
52
|
}
|
|
54
|
-
addGeneratedService(key, ...names) {
|
|
55
|
-
let serv = this.container.genServices[key];
|
|
56
|
-
if (!serv) {
|
|
57
|
-
serv = new Set();
|
|
58
|
-
this.container.genServices[key] = serv;
|
|
59
|
-
}
|
|
60
|
-
names.forEach((n) => serv.add(n));
|
|
61
|
-
}
|
|
62
53
|
getImportDeclarations(fromSubPath = false) {
|
|
63
|
-
const _a = this.container, {
|
|
54
|
+
const _a = this.container, { customTypes } = _a, standardImports = tslib_1.__rest(_a, ["customTypes"]);
|
|
64
55
|
return [
|
|
65
56
|
...[...customTypes.keys()]
|
|
66
57
|
.filter((key) => { var _a; return !!((_a = customTypes.get(key)) === null || _a === void 0 ? void 0 : _a.size); })
|
|
@@ -71,7 +62,7 @@ class ImportContainer {
|
|
|
71
62
|
};
|
|
72
63
|
}),
|
|
73
64
|
...Object.entries(standardImports)
|
|
74
|
-
.filter(([
|
|
65
|
+
.filter(([_, values]) => !!values.size)
|
|
75
66
|
.map(([key, values]) => {
|
|
76
67
|
const mapping = this.mapping[key];
|
|
77
68
|
return {
|
|
@@ -79,12 +70,6 @@ class ImportContainer {
|
|
|
79
70
|
moduleSpecifier: `${mapping.isRelative ? `${fromSubPath ? ".." : "."}/` : ""}${mapping.moduleName}`,
|
|
80
71
|
};
|
|
81
72
|
}),
|
|
82
|
-
...Object.entries(genServices).map(([key, values]) => {
|
|
83
|
-
return {
|
|
84
|
-
namedImports: [...values],
|
|
85
|
-
moduleSpecifier: (fromSubPath ? "./" : "./service/") + key,
|
|
86
|
-
};
|
|
87
|
-
}),
|
|
88
73
|
];
|
|
89
74
|
}
|
|
90
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":";;;;AAcA,MAAa,eAAe;IA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,OAAuC,EAAlC,eAAe,sBAAjC,eAAmC,CAAiB,CAAC;QAE3D,OAAO;YACL,GAAG,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC;iBACvB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,WAAC,OAAA,CAAC,CAAC,CAAA,MAAA,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,0CAAE,IAAI,CAAA,CAAA,EAAA,CAAC;iBAC7C,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;gBACX,OAAO;oBACL,YAAY,EAAE,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;oBACxC,eAAe,EAAE,GAAG;iBACS,CAAC;YAClC,CAAC,CAAC;YACJ,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC;iBAC/B,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;iBACtC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE;gBACrB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAClC,OAAO;oBACL,YAAY,EAAE,CAAC,GAAG,MAAM,CAAC;oBACzB,eAAe,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE;iBACtE,CAAC;YAClC,CAAC,CAAC;SACL,CAAC;IACJ,CAAC;CACF;AAnFD,0CAmFC","sourcesContent":["import { ImportDeclarationStructure } from \"ts-morph\";\r\n\r\nimport { ProjectFiles } from \"../data-model/DataModel\";\r\n\r\ntype ImportContainerType = {\r\n core: Set<string>;\r\n qobjects: Set<string>;\r\n clientApi: Set<string>;\r\n service: Set<string>;\r\n genModel: Set<string>;\r\n genQObjects: Set<string>;\r\n customTypes: Map<string, Set<string>>;\r\n};\r\n\r\nexport class ImportContainer {\r\n private mapping: {\r\n [K in keyof ImportContainerType as string]: { moduleName: string; isRelative: boolean; addName?: boolean };\r\n } = {\r\n core: { moduleName: \"@odata2ts/odata-core\", isRelative: false },\r\n qobjects: { moduleName: \"@odata2ts/odata-query-objects\", isRelative: false },\r\n clientApi: { moduleName: \"@odata2ts/http-client-api\", isRelative: false },\r\n service: { moduleName: \"@odata2ts/odata-service\", isRelative: false },\r\n genModel: { moduleName: \"\", isRelative: true },\r\n genQObjects: { moduleName: \"\", isRelative: true },\r\n };\r\n\r\n private container: ImportContainerType = {\r\n core: new Set(),\r\n qobjects: new Set(),\r\n clientApi: new Set(),\r\n service: new Set(),\r\n genModel: new Set(),\r\n genQObjects: new Set(),\r\n customTypes: new Map(),\r\n };\r\n\r\n constructor(fileNames: ProjectFiles) {\r\n this.mapping.genModel.moduleName = fileNames.model;\r\n this.mapping.genQObjects.moduleName = fileNames.qObject;\r\n }\r\n\r\n public addFromCore(...names: Array<string>) {\r\n names.forEach((n) => this.container.core.add(n));\r\n }\r\n\r\n public addFromQObject(...names: Array<string>) {\r\n names.forEach((n) => this.container.qobjects.add(n));\r\n }\r\n\r\n public addFromClientApi(...names: Array<string>) {\r\n names.forEach((n) => this.container.clientApi.add(n));\r\n }\r\n\r\n public addFromService(...names: Array<string>) {\r\n names.forEach((n) => this.container.service.add(n));\r\n }\r\n\r\n public addGeneratedModel(...names: Array<string>) {\r\n names.forEach((n) => this.container.genModel.add(n));\r\n }\r\n\r\n public addGeneratedQObject(...names: Array<string>) {\r\n names.forEach((n) => this.container.genQObjects.add(n));\r\n }\r\n\r\n public addCustomType(moduleName: string, typeName: string) {\r\n let importList = this.container.customTypes.get(moduleName);\r\n if (!importList) {\r\n importList = new Set();\r\n this.container.customTypes.set(moduleName, importList);\r\n }\r\n importList.add(typeName);\r\n }\r\n\r\n public getImportDeclarations(fromSubPath: boolean = false): Array<ImportDeclarationStructure> {\r\n const { customTypes, ...standardImports } = this.container;\r\n\r\n return [\r\n ...[...customTypes.keys()]\r\n .filter((key) => !!customTypes.get(key)?.size)\r\n .map((key) => {\r\n return {\r\n namedImports: [...customTypes.get(key)!],\r\n moduleSpecifier: key,\r\n } as ImportDeclarationStructure;\r\n }),\r\n ...Object.entries(standardImports)\r\n .filter(([_, values]) => !!values.size)\r\n .map(([key, values]) => {\r\n const mapping = this.mapping[key];\r\n return {\r\n namedImports: [...values],\r\n moduleSpecifier: `${mapping.isRelative ? `${fromSubPath ? \"..\" : \".\"}/` : \"\"}${mapping.moduleName}`,\r\n } as ImportDeclarationStructure;\r\n }),\r\n ];\r\n }\r\n}\r\n"]}
|
|
@@ -35,7 +35,7 @@ class ModelGenerator {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
generateModels() {
|
|
38
|
-
this.dataModel.
|
|
38
|
+
this.dataModel.getEntityTypes().forEach((model) => {
|
|
39
39
|
this.generateModel(model);
|
|
40
40
|
if (!this.options.skipIdModels) {
|
|
41
41
|
this.generateIdModel(model);
|
|
@@ -44,7 +44,7 @@ class ModelGenerator {
|
|
|
44
44
|
this.generateEditableModel(model);
|
|
45
45
|
}
|
|
46
46
|
if (!this.options.skipOperations) {
|
|
47
|
-
this.generateBoundOperationParams(model.
|
|
47
|
+
this.generateBoundOperationParams(model.fqName);
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
this.dataModel.getComplexTypes().forEach((model) => {
|
|
@@ -69,7 +69,7 @@ class ModelGenerator {
|
|
|
69
69
|
docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],
|
|
70
70
|
};
|
|
71
71
|
}),
|
|
72
|
-
extends: model.baseClasses,
|
|
72
|
+
extends: model.baseClasses.map((bc) => this.namingHelper.getModelName(bc)),
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
generatePropDoc(prop, model) {
|
|
@@ -171,9 +171,9 @@ class ModelGenerator {
|
|
|
171
171
|
}
|
|
172
172
|
getEditablePropType(prop) {
|
|
173
173
|
const type = prop.dataType === "ModelType" /* DataTypes.ModelType */
|
|
174
|
-
? this.dataModel.
|
|
174
|
+
? this.dataModel.getEntityType(prop.fqType).editableName
|
|
175
175
|
: prop.dataType === "ComplexType" /* DataTypes.ComplexType */
|
|
176
|
-
? this.dataModel.getComplexType(prop.
|
|
176
|
+
? this.dataModel.getComplexType(prop.fqType).editableName
|
|
177
177
|
: prop.type;
|
|
178
178
|
// Collections
|
|
179
179
|
if (prop.isCollection) {
|
|
@@ -188,7 +188,10 @@ class ModelGenerator {
|
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
generateBoundOperationParams(entityName) {
|
|
191
|
-
|
|
191
|
+
[
|
|
192
|
+
...this.dataModel.getEntityTypeOperations(entityName),
|
|
193
|
+
...this.dataModel.getEntitySetOperations(entityName),
|
|
194
|
+
].forEach((operation) => {
|
|
192
195
|
this.generateOperationParams(operation);
|
|
193
196
|
});
|
|
194
197
|
}
|