UNPKG

gen-jhipster

Version:

VHipster - Spring Boot + Angular/React/Vue in one handy generator

98 lines (97 loc) 5.01 kB
/** * Copyright 2013-2026 the original author or authors from the JHipster project. * * This file is part of the JHipster project, see https://www.jhipster.tech/ * for more information. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { angularReservedKeywords } from "../../generators/angular/support/reserved-keywords.js"; import { javaReservedKeywords } from "../../generators/java/support/reserved-keywords.js"; import { typescriptReservedKeywords } from "../../generators/javascript-simple-application/support/reserved-words.js"; import { cassandraReservedKeywords } from "../../generators/spring-boot/generators/data-cassandra/support/reserved-keywords.js"; import { couchbaseReservedKeywords } from "../../generators/spring-boot/generators/data-couchbase/support/reserved-keywords.js"; import { neo4jReservedKeywords } from "../../generators/spring-boot/generators/data-neo4j/support/reserved-keywords.js"; import { mssqlReservedKeywords } from "../../generators/spring-boot/generators/data-relational/support/mssql-reserved-keywords.js"; import { mysqlReservedKeywords } from "../../generators/spring-boot/generators/data-relational/support/mysql-reserved-keywords.js"; import { oracleReservedKeywords } from "../../generators/spring-boot/generators/data-relational/support/oracle-reserved-keywords.js"; import { postgresqlReservedKeywords } from "../../generators/spring-boot/generators/data-relational/support/postgresql-reserved-keywords.js"; import applicationOptions from "./application-options.js"; import JHipsterReservedKeywords from "./reserved-keywords/jhipster.js"; import PagingReservedKeywords from "./reserved-keywords/paging.js"; const clientFrameworks = applicationOptions.OptionValues[applicationOptions.OptionNames.CLIENT_FRAMEWORK]; const ReservedWords = { JHIPSTER: JHipsterReservedKeywords, ANGULAR: angularReservedKeywords, JAVA: javaReservedKeywords, TYPESCRIPT: typescriptReservedKeywords, MYSQL: mysqlReservedKeywords, MARIADB: mysqlReservedKeywords, POSTGRESQL: postgresqlReservedKeywords, PAGING: PagingReservedKeywords, CASSANDRA: cassandraReservedKeywords, COUCHBASE: couchbaseReservedKeywords, ORACLE: oracleReservedKeywords, MONGODB: ['DOCUMENT'], MSSQL: mssqlReservedKeywords, NEO4J: neo4jReservedKeywords, }; export const keywordsForType = (type) => ReservedWords[type.toUpperCase()]; export function isReserved(keyword, type) { return !!keyword && !!type && !!keywordsForType(type)?.includes(keyword.toUpperCase()); } export function isReservedClassName(keyword) { return (isReserved(keyword, 'JHIPSTER') || isReserved(keyword, 'ANGULAR') || isReserved(keyword, 'TYPESCRIPT') || isReserved(keyword, 'JAVA')); } export function isReservedTableName(keyword, databaseType) { return databaseType.toUpperCase() === 'SQL' ? isReserved(keyword, 'MYSQL') || isReserved(keyword, 'POSTGRESQL') || isReserved(keyword, 'ORACLE') || isReserved(keyword, 'MSSQL') : isReserved(keyword, databaseType); } export function isReservedPaginationWords(keyword) { return isReserved(keyword, 'PAGING'); } export function isReservedFieldName(keyword, clientFramework) { if (clientFramework) { if (clientFramework === clientFrameworks.angular) { // Angular client framework return isReserved(keyword, 'ANGULAR') || isReserved(keyword, 'TYPESCRIPT') || isReserved(keyword, 'JAVA'); } if (clientFramework === clientFrameworks.react) { // React client framework return isReserved(keyword, 'TYPESCRIPT') || isReserved(keyword, 'JAVA'); } } // If no client framework is selected // for example in JDL, entities can be used with both Angular and React, so both reserved keywords lists should be used return isReserved(keyword, 'ANGULAR') || isReserved(keyword, 'TYPESCRIPT') || isReserved(keyword, 'JAVA'); } export default { isReserved, isReservedClassName, isReservedTableName, isReservedFieldName, isReservedPaginationWords, JHIPSTER: ReservedWords.JHIPSTER, ANGULAR: ReservedWords.ANGULAR, JAVA: ReservedWords.JAVA, TYPESCRIPT: ReservedWords.TYPESCRIPT, MYSQL: ReservedWords.MYSQL, POSTGRESQL: ReservedWords.POSTGRESQL, CASSANDRA: ReservedWords.CASSANDRA, COUCHBASE: ReservedWords.COUCHBASE, ORACLE: ReservedWords.ORACLE, MONGODB: ReservedWords.MONGODB, MSSQL: ReservedWords.MSSQL, NEO4J: ReservedWords.NEO4J, };