@sap-ux/odata-vocabularies
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -11,8 +11,9 @@ import type { EnumTypeBase } from '@sap-ux/vocabularies/CSDL'; | ||
/** | ||
* Loads vocbulary information. | ||
* Loads vocabulary information. | ||
* | ||
* @param includeCds Flag indicating if CDS vocabularies should be loaded | ||
* @param includeCdsAnalytics flag indicating if additional vocabularies for CDS analytics should be loaded | ||
* @returns Vocabularies | ||
*/ | ||
export declare const loadVocabulariesInformation: (includeCds?: boolean) => VocabulariesInformation; | ||
export declare const loadVocabulariesInformation: (includeCds?: boolean, includeCdsAnalytics?: boolean) => VocabulariesInformation; | ||
//# sourceMappingURL=loader.d.ts.map |
@@ -55,3 +55,5 @@ "use strict"; | ||
'com.sap.vocabularies.UI.v1', | ||
'com.sap.vocabularies.HTML5.v1' | ||
'com.sap.vocabularies.HTML5.v1', | ||
'com.sap.cds.vocabularies.ObjectModel', | ||
'com.sap.cds.vocabularies.AnalyticsDetails' | ||
]); | ||
@@ -355,2 +357,11 @@ const vocabulariesInformationStatic = new Map(); | ||
/** | ||
* Finds out if namespace belongs to cds analytics. | ||
* | ||
* @param namespace | ||
* @returns boolean value | ||
*/ | ||
function isCdsAnalyticsNamespace(namespace) { | ||
return namespace.startsWith('com.sap.cds.vocabularies'); | ||
} | ||
/** | ||
* Appends name and property name to the given uppercase names map. | ||
@@ -492,6 +503,8 @@ * | ||
* @param maps.upperCaseNameMap map with names in upperCase representation | ||
* @param includeCds flag indicating if CDS vocabularies should be loaded | ||
* @param options options object | ||
* @param options.includeCds flag indicating if CDS vocabularies should be loaded | ||
* @param options.includeCdsAnalytics flag indicating if additional vocabularies for CDS analytics should be loaded | ||
* @returns loader function | ||
*/ | ||
const getVocabularyLoader = (maps, includeCds) => | ||
const getVocabularyLoader = (maps, options) => | ||
/** | ||
@@ -503,6 +516,11 @@ * Vocabulary data loader for a specific namespace. | ||
(namespace) => { | ||
const { includeCds, includeCdsAnalytics } = options; | ||
const { supportedVocabularies } = maps; | ||
if (!includeCds && namespace === types_1.CDS_VOCABULARY_NAMESPACE) { | ||
const isCdsAnalyticsNs = isCdsAnalyticsNamespace(namespace); | ||
if (!includeCds && (namespace === types_1.CDS_VOCABULARY_NAMESPACE || isCdsAnalyticsNs)) { | ||
return; | ||
} | ||
if (!includeCdsAnalytics && isCdsAnalyticsNs) { | ||
return; | ||
} | ||
const alias = resources_1.NAMESPACE_TO_ALIAS.get(namespace); | ||
@@ -512,3 +530,3 @@ if (!alias) { | ||
} | ||
const document = resources_1.default[alias]; | ||
const document = resources_1.default[namespace]; | ||
if (!document) { | ||
@@ -536,10 +554,14 @@ return; | ||
/** | ||
* Loads vocbulary information. | ||
* Loads vocabulary information. | ||
* | ||
* @param includeCds Flag indicating if CDS vocabularies should be loaded | ||
* @param includeCdsAnalytics flag indicating if additional vocabularies for CDS analytics should be loaded | ||
* @returns Vocabularies | ||
*/ | ||
const loadVocabulariesInformation = (includeCds) => { | ||
const loadVocabulariesInformation = (includeCds, includeCdsAnalytics) => { | ||
// try to use cache | ||
const cacheKey = includeCds ? 'withCDS' : ''; | ||
let cacheKey = includeCds ? 'withCDS' : ''; | ||
if (includeCds && includeCdsAnalytics) { | ||
cacheKey += 'IncludingAnalytics'; | ||
} | ||
const cachedData = vocabulariesInformationStatic.get(cacheKey); | ||
@@ -556,5 +578,9 @@ if (cachedData) { | ||
resources_1.NAMESPACE_TO_ALIAS.forEach((alias, namespace) => { | ||
if (!includeCds && alias === types_1.CDS_VOCABULARY_ALIAS) { | ||
const isCdsNs = isCdsAnalyticsNamespace(namespace); | ||
if (!includeCds && (alias === types_1.CDS_VOCABULARY_ALIAS || isCdsNs)) { | ||
return; | ||
} | ||
if (!includeCdsAnalytics && isCdsNs) { | ||
return; | ||
} | ||
addToUpperCaseNameMap(upperCaseNameMap, alias); | ||
@@ -564,3 +590,3 @@ addToUpperCaseNameMap(upperCaseNameMap, namespace); | ||
}); | ||
const vocabularyLoader = getVocabularyLoader({ byTarget, derivedTypesPerType, dictionary, supportedVocabularies, upperCaseNameMap }, includeCds); | ||
const vocabularyLoader = getVocabularyLoader({ byTarget, derivedTypesPerType, dictionary, supportedVocabularies, upperCaseNameMap }, { includeCds, includeCdsAnalytics }); | ||
for (const namespace of SUPPORTED_VOCABULARY_NAMESPACES) { | ||
@@ -567,0 +593,0 @@ vocabularyLoader(namespace); |
import type { CSDL } from '@sap-ux/vocabularies/CSDL'; | ||
export type CdsVocabularyNamespace = 'com.sap.cds.vocabularies.ObjectModel' | 'com.sap.cds.vocabularies.AnalyticsDetails'; | ||
export type SapVocabularyNamespace = 'com.sap.vocabularies.Analytics.v1' | 'com.sap.vocabularies.CDS.v1' | 'com.sap.vocabularies.CodeList.v1' | 'com.sap.vocabularies.Common.v1' | 'com.sap.vocabularies.Communication.v1' | 'com.sap.vocabularies.DataIntegration.v1' | 'com.sap.vocabularies.DirectEdit.v1' | 'com.sap.vocabularies.Graph.v1' | 'com.sap.vocabularies.Hierarchy.v1' | 'com.sap.vocabularies.ODM.v1' | 'com.sap.vocabularies.PDF.v1' | 'com.sap.vocabularies.PersonalData.v1' | 'com.sap.vocabularies.Session.v1' | 'com.sap.vocabularies.UI.v1' | 'com.sap.vocabularies.HTML5.v1'; | ||
@@ -6,4 +7,5 @@ export type SapVocabularyAlias = 'Analytics' | 'CDS' | 'CodeList' | 'Common' | 'Communication' | 'DataIntegration' | 'DirectEdit' | 'Graph' | 'Hierarchy' | 'ODM' | 'PDF' | 'PersonalData' | 'Session' | 'UI' | 'HTML5'; | ||
export type OasisVocabularyAlias = 'Aggregation' | 'Auth' | 'Capabilities' | 'Core' | 'Measures' | 'Repeatability' | 'Temporal' | 'Validation' | 'ODataJSON'; | ||
export type VocabularyNamespace = SapVocabularyNamespace | OasisVocabularyNamespace; | ||
export type VocabularyAlias = SapVocabularyAlias | OasisVocabularyAlias; | ||
export type CdsVocabularyAlias = 'ObjectModel' | 'AnalyticsDetails'; | ||
export type VocabularyNamespace = SapVocabularyNamespace | OasisVocabularyNamespace | CdsVocabularyNamespace; | ||
export type VocabularyAlias = SapVocabularyAlias | OasisVocabularyAlias | CdsVocabularyAlias; | ||
export declare const NAMESPACE_TO_ALIAS: Map<VocabularyNamespace, VocabularyAlias>; | ||
@@ -10,0 +12,0 @@ export declare const ALIAS_TO_NAMESPACE: Map<VocabularyAlias, VocabularyNamespace>; |
@@ -31,2 +31,4 @@ "use strict"; | ||
const com_sap_vocabularies_HTML5_v1_1 = __importDefault(require("./com.sap.vocabularies.HTML5.v1")); | ||
const com_sap_cds_vocabularies_ObjectModel_1 = __importDefault(require("./com.sap.cds.vocabularies.ObjectModel")); | ||
const com_sap_cds_vocabularies_AnalyticsDetails_1 = __importDefault(require("./com.sap.cds.vocabularies.AnalyticsDetails")); | ||
exports.NAMESPACE_TO_ALIAS = new Map([ | ||
@@ -56,3 +58,5 @@ ['Org.OData.Aggregation.V1', 'Aggregation'], | ||
['com.sap.vocabularies.UI.v1', 'UI'], | ||
['com.sap.vocabularies.HTML5.v1', 'HTML5'] | ||
['com.sap.vocabularies.HTML5.v1', 'HTML5'], | ||
['com.sap.cds.vocabularies.ObjectModel', 'ObjectModel'], | ||
['com.sap.cds.vocabularies.AnalyticsDetails', 'AnalyticsDetails'] | ||
]); | ||
@@ -83,31 +87,35 @@ exports.ALIAS_TO_NAMESPACE = new Map([ | ||
['UI', 'com.sap.vocabularies.UI.v1'], | ||
['HTML5', 'com.sap.vocabularies.HTML5.v1'] | ||
['HTML5', 'com.sap.vocabularies.HTML5.v1'], | ||
['ObjectModel', 'com.sap.cds.vocabularies.ObjectModel'], | ||
['AnalyticsDetails', 'com.sap.cds.vocabularies.AnalyticsDetails'] | ||
]); | ||
const vocabularies = { | ||
Aggregation: Org_OData_Aggregation_V1_1.default, | ||
Auth: Org_OData_Authorization_V1_1.default, | ||
Capabilities: Org_OData_Capabilities_V1_1.default, | ||
Core: Org_OData_Core_V1_1.default, | ||
Measures: Org_OData_Measures_V1_1.default, | ||
Repeatability: Org_OData_Repeatability_V1_1.default, | ||
Temporal: Org_OData_Temporal_V1_1.default, | ||
Validation: Org_OData_Validation_V1_1.default, | ||
ODataJSON: Org_OData_JSON_V1_1.default, | ||
Analytics: com_sap_vocabularies_Analytics_v1_1.default, | ||
CDS: com_sap_vocabularies_CDS_v1_1.default, | ||
CodeList: com_sap_vocabularies_CodeList_v1_1.default, | ||
Common: com_sap_vocabularies_Common_v1_1.default, | ||
Communication: com_sap_vocabularies_Communication_v1_1.default, | ||
DataIntegration: com_sap_vocabularies_DataIntegration_v1_1.default, | ||
DirectEdit: com_sap_vocabularies_DirectEdit_v1_1.default, | ||
Graph: com_sap_vocabularies_Graph_v1_1.default, | ||
Hierarchy: com_sap_vocabularies_Hierarchy_v1_1.default, | ||
ODM: com_sap_vocabularies_ODM_v1_1.default, | ||
PDF: com_sap_vocabularies_PDF_v1_1.default, | ||
PersonalData: com_sap_vocabularies_PersonalData_v1_1.default, | ||
Session: com_sap_vocabularies_Session_v1_1.default, | ||
UI: com_sap_vocabularies_UI_v1_1.default, | ||
HTML5: com_sap_vocabularies_HTML5_v1_1.default | ||
'Org.OData.Aggregation.V1': Org_OData_Aggregation_V1_1.default, | ||
'Org.OData.Authorization.V1': Org_OData_Authorization_V1_1.default, | ||
'Org.OData.Capabilities.V1': Org_OData_Capabilities_V1_1.default, | ||
'Org.OData.Core.V1': Org_OData_Core_V1_1.default, | ||
'Org.OData.Measures.V1': Org_OData_Measures_V1_1.default, | ||
'Org.OData.Repeatability.V1': Org_OData_Repeatability_V1_1.default, | ||
'Org.OData.Temporal.V1': Org_OData_Temporal_V1_1.default, | ||
'Org.OData.Validation.V1': Org_OData_Validation_V1_1.default, | ||
'Org.OData.JSON.V1': Org_OData_JSON_V1_1.default, | ||
'com.sap.vocabularies.Analytics.v1': com_sap_vocabularies_Analytics_v1_1.default, | ||
'com.sap.vocabularies.CDS.v1': com_sap_vocabularies_CDS_v1_1.default, | ||
'com.sap.vocabularies.CodeList.v1': com_sap_vocabularies_CodeList_v1_1.default, | ||
'com.sap.vocabularies.Common.v1': com_sap_vocabularies_Common_v1_1.default, | ||
'com.sap.vocabularies.Communication.v1': com_sap_vocabularies_Communication_v1_1.default, | ||
'com.sap.vocabularies.DataIntegration.v1': com_sap_vocabularies_DataIntegration_v1_1.default, | ||
'com.sap.vocabularies.DirectEdit.v1': com_sap_vocabularies_DirectEdit_v1_1.default, | ||
'com.sap.vocabularies.Graph.v1': com_sap_vocabularies_Graph_v1_1.default, | ||
'com.sap.vocabularies.Hierarchy.v1': com_sap_vocabularies_Hierarchy_v1_1.default, | ||
'com.sap.vocabularies.ODM.v1': com_sap_vocabularies_ODM_v1_1.default, | ||
'com.sap.vocabularies.PDF.v1': com_sap_vocabularies_PDF_v1_1.default, | ||
'com.sap.vocabularies.PersonalData.v1': com_sap_vocabularies_PersonalData_v1_1.default, | ||
'com.sap.vocabularies.Session.v1': com_sap_vocabularies_Session_v1_1.default, | ||
'com.sap.vocabularies.UI.v1': com_sap_vocabularies_UI_v1_1.default, | ||
'com.sap.vocabularies.HTML5.v1': com_sap_vocabularies_HTML5_v1_1.default, | ||
'com.sap.cds.vocabularies.ObjectModel': com_sap_cds_vocabularies_ObjectModel_1.default, | ||
'com.sap.cds.vocabularies.AnalyticsDetails': com_sap_cds_vocabularies_AnalyticsDetails_1.default | ||
}; | ||
exports.default = vocabularies; | ||
//# sourceMappingURL=index.js.map |
@@ -44,5 +44,6 @@ import type { ComplexType, ExpandedComplexType, MarkdownString, ComplexTypeProperty, Term, Vocabulary, VocabularyObject, VocabularyType, EnumValue, CdsVocabulary, TypeDefinition, EnumType } from './types/vocabulary-service'; | ||
* @param includeCds Flag indicating if CDS vocabulary be loaded | ||
* @param includeCdsAnalytics (for includeCds=true only) Flag indicating if additional vocabularies for CDS analytics should be loaded | ||
* @returns Vocabulary service instance | ||
*/ | ||
constructor(includeCds?: boolean); | ||
constructor(includeCds?: boolean, includeCdsAnalytics?: boolean); | ||
/** | ||
@@ -49,0 +50,0 @@ * Add CDS specific annotation terms. |
@@ -83,6 +83,10 @@ "use strict"; | ||
* @param includeCds Flag indicating if CDS vocabulary be loaded | ||
* @param includeCdsAnalytics (for includeCds=true only) Flag indicating if additional vocabularies for CDS analytics should be loaded | ||
* @returns Vocabulary service instance | ||
*/ | ||
constructor(includeCds) { | ||
let vocabularyInformation = (0, loader_1.loadVocabulariesInformation)(includeCds); | ||
constructor(includeCds, includeCdsAnalytics) { | ||
if (!includeCds && includeCdsAnalytics) { | ||
throw new Error('Vocabulary service instantiation: invalid parameterization includeCds=false and includeCdsAnalytics=true'); | ||
} | ||
let vocabularyInformation = (0, loader_1.loadVocabulariesInformation)(includeCds, includeCdsAnalytics); | ||
// add cds specific annotations (TextArrangement and Capabilities) on fly | ||
@@ -89,0 +93,0 @@ vocabularyInformation = includeCds |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"license": "Apache-2.0", | ||
@@ -31,6 +31,5 @@ "author": "@SAP/ux-tools-team", | ||
"scripts": { | ||
"compile": "tsc --build ./tsconfig.build.json", | ||
"compile": "tsc --build", | ||
"build": "npm-run-all clean compile", | ||
"clean:dist": "rimraf ./dist *.tsbuildinfo", | ||
"clean": "rimraf ./reports", | ||
"clean": "rimraf --glob ./coverage ./dist *.tsbuildinfo", | ||
"format:fix": "prettier --write --loglevel silent --ignore-path ../../../.prettierignore", | ||
@@ -45,5 +44,5 @@ "format:fix:all": "prettier --write '**/*.{css,scss,html,js,json,ts,tsx,yaml,yml}' '!**/{out,dist,typings,node_modules}/**' '!**/*.{svg,png,xml}' --ignore-path ../../../.prettierignore", | ||
"test": "jest --maxWorkers=1 --ci --forceExit --detectOpenHandles", | ||
"updateVocabularies": "ts-node --cwdMode tools/run-update.ts", | ||
"update:vocabularies": "ts-node --project tsconfig.eslint.json --cwdMode tools/run-update.ts", | ||
"watch": "tsc --build ./ -watch" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
863588
131
12082