UNPKG

@sap/cds-compiler

Version:

CDS (Core Data Services) compiler and backends

123 lines (111 loc) 4.31 kB
// Definitions for beta and deprecated options // Normal options are in ../base/optionProcessor.js (and some other files), // unfortunately partly non-grep-able (option `fooBar` is defined via `--foo-bar`) 'use strict'; /** * Object of all available beta flags that will be enabled/disabled by `--beta-mode` * through cdsc. Only intended for INTERNAL USE. * NOT to be used by umbrella, etc. * * @type {{[flag: string]: boolean}} Indicates whether it is enabled by --beta-mode or not. * @private */ const availableBetaFlags = { // enabled by --beta-mode hanaAssocRealCardinality: true, mapAssocToJoinCardinality: true, // only SAP HANA HEX engine supports it enableUniversalCsn: true, odataTerms: true, tenantVariable: true, calcAssoc: true, temporalRawProjection: true, v7preview: true, rewriteAnnotationExpressionsViaType: true, sqlServiceDummies: true, // disabled by --beta-mode nestedServices: false, }; // Used by isDeprecatedEnabled() to check if any flag ist set. const availableDeprecatedFlags = { // the old ones starting with _, : false noPersistenceJournalForGeneratedEntities: true, // since v6 downgradableErrors: true, noCompositionIncludes: true, // since v6; was an option with inverted meaning in v5 noQuasiVirtualAssocs: true, // since v6 _includesNonShadowedFirst: true, _eagerPersistenceForGeneratedEntities: true, _noKeyPropagationWithExpansions: true, ignoreSpecifiedQueryElements: true, }; // Deprecated flags that were removed in newer version and are complained about. const oldDeprecatedFlags = { includesNonShadowedFirst: true, eagerPersistenceForGeneratedEntities: true, noKeyPropagationWithExpansions: true, }; /** * Test for early-adaptor feature, stored in option `beta`(new-style) / `betaMode`(old-style) * With that, the value of `beta` is a dictionary of feature=>Boolean. * * Beta features cannot be used when `options.deprecated` is set. * * A feature always needs to be provided - otherwise false will be returned. * * Do not move this function to the "option processor" code. * * @param {object} options Options * @param {string} feature Feature to check for * @returns {boolean} */ function isBetaEnabled( options, feature ) { const beta = options.beta || options.betaMode; return beta && typeof beta === 'object' && !options.deprecated && feature && beta[feature]; } /** * Test for deprecated feature, stored in option `deprecated`. * With that, the value of `deprecated` is a dictionary of feature=>Boolean. * * If no `feature` is provided, checks if any deprecated option is set * which is not mentioned in availableDeprecatedFlags with value true. * Useful for newer functionality which might not work with some * deprecated feature turned on. * * Do not move this function to the "option processor" code. * * @param {object} options Options * @param {string|null} [feature] Feature to check for * @returns {boolean} */ function isDeprecatedEnabled( options, feature = null ) { const { deprecated } = options; if (!feature) { return !!deprecated && Object.keys( deprecated ) .some( d => !availableDeprecatedFlags[d] ); } return deprecated && typeof deprecated === 'object' && deprecated[feature]; } /** * In the current cds-compiler, we might have removed old deprecated flags. That can lead to silent * errors such as entity/view names changing. To ensure that the user is forced * to change their code, emit an error if one of such removed flags was used. * * @param {CSN.Options} options * @param error Error message function returned by makeMessageFunction(). */ function checkRemovedDeprecatedFlags( { deprecated, messages }, { error } ) { // Assume that we emitted these errors once if a message with this ID was found. if (!deprecated || messages?.some( m => m.messageId === 'api-invalid-deprecated' )) return; Object.keys( deprecated ).forEach( ( key ) => { if (deprecated[key] && oldDeprecatedFlags[key]) { // why testing the value of the option? error( 'api-invalid-deprecated', null, { name: key }, 'Deprecated flag $(NAME) has been removed in CDS compiler v6' ); } }); } module.exports = { isBetaEnabled, availableBetaFlags, isDeprecatedEnabled, checkRemovedDeprecatedFlags, };