Initial commit - Event Planner application

This commit is contained in:
mberlin
2026-03-18 14:55:56 -03:00
commit 86d779eb4d
7548 changed files with 1006324 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import type { NamingStrategy } from './NamingStrategy.js';
import { type ReferenceKind } from '../enums.js';
/** Base class for naming strategies, providing default implementations for common naming conventions. */
export declare abstract class AbstractNamingStrategy implements NamingStrategy {
getClassName(file: string, separator?: string): string;
classToMigrationName(timestamp: string, customMigrationName?: string): string;
indexName(
tableName: string,
columns: string[],
type: 'primary' | 'foreign' | 'unique' | 'index' | 'sequence' | 'check' | 'default',
): string;
/**
* @inheritDoc
*/
getEntityName(tableName: string, schemaName?: string): string;
columnNameToProperty(columnName: string): string;
/**
* @inheritDoc
*/
getEnumClassName(columnName: string, tableName: string | undefined, schemaName?: string): string;
/**
* @inheritDoc
*/
getEnumTypeName(columnName: string, tableName: string | undefined, schemaName?: string): string;
/**
* @inheritDoc
*/
enumValueToEnumProperty(enumValue: string, columnName: string, tableName: string, schemaName?: string): string;
aliasName(entityName: string, index: number): string;
/**
* @inheritDoc
*/
inverseSideName(entityName: string, propertyName: string, kind: ReferenceKind): string;
/**
* @inheritDoc
*/
manyToManyPropertyName(
ownerEntityName: string,
targetEntityName: string,
pivotTableName: string,
ownerTableName: string,
schemaName?: string,
): string;
/**
* @inheritDoc
*/
discriminatorColumnName(baseName: string): string;
abstract classToTableName(entityName: string, tableName?: string): string;
abstract joinColumnName(propertyName: string): string;
abstract joinKeyColumnName(
entityName: string,
referencedColumnName?: string,
composite?: boolean,
tableName?: string,
): string;
abstract joinTableName(sourceEntity: string, targetEntity: string, propertyName?: string, tableName?: string): string;
abstract propertyToColumnName(propertyName: string, object?: boolean): string;
abstract referenceColumnName(): string;
}

View File

@@ -0,0 +1,103 @@
import { PopulatePath } from '../enums.js';
const populatePathMembers = Object.values(PopulatePath);
/** Base class for naming strategies, providing default implementations for common naming conventions. */
export class AbstractNamingStrategy {
getClassName(file, separator = '-') {
const name = file.split('.')[0];
const ret = name.replace(new RegExp(`(?:${separator})+(\\w)`, 'ug'), (_, p1) => p1.toUpperCase());
return ret.charAt(0).toUpperCase() + ret.slice(1);
}
classToMigrationName(timestamp, customMigrationName) {
let migrationName = `Migration${timestamp}`;
if (customMigrationName) {
migrationName += `_${customMigrationName}`;
}
return migrationName;
}
indexName(tableName, columns, type) {
/* v8 ignore next */
if (tableName.includes('.')) {
tableName = tableName.substring(tableName.indexOf('.') + 1);
}
if (type === 'primary') {
return `${tableName}_pkey`;
}
columns = columns.map(col => col.replace(/\./g, '_'));
if (type === 'sequence') {
return `${tableName}_${columns.join('_')}_seq`;
}
if (columns.length > 0) {
return `${tableName}_${columns.join('_')}_${type}`;
}
return `${tableName}_${type}`;
}
/**
* @inheritDoc
*/
getEntityName(tableName, schemaName) {
const name = /^[^$_\p{ID_Start}]/u.exec(tableName) ? `E_${tableName}` : tableName;
return this.getClassName(
name.replaceAll(/[^\u200C\u200D\p{ID_Continue}]+/gu, r =>
r
.split('')
.map(c => `$${c.codePointAt(0)}`)
.join(''),
),
'_',
);
}
columnNameToProperty(columnName) {
const propName = columnName.replace(/[_\- ]+(\w)/gu, (_, p1) => p1.toUpperCase());
if (populatePathMembers.includes(propName.replace(/^\${2,}/u, '$$').replace(/^\$\*$/u, '*'))) {
return `$${propName}`;
}
return propName;
}
/**
* @inheritDoc
*/
getEnumClassName(columnName, tableName, schemaName) {
return this.getEntityName(tableName ? `${tableName}_${columnName}` : columnName, schemaName);
}
/**
* @inheritDoc
*/
getEnumTypeName(columnName, tableName, schemaName) {
return 'T' + this.getEnumClassName(columnName, tableName, schemaName);
}
/**
* @inheritDoc
*/
enumValueToEnumProperty(enumValue, columnName, tableName, schemaName) {
return enumValue.toUpperCase();
}
aliasName(entityName, index) {
// Take only the first letter of the prefix to keep character counts down since some engines have character limits
return entityName.charAt(0).toLowerCase() + index;
}
/**
* @inheritDoc
*/
inverseSideName(entityName, propertyName, kind) {
if (kind === 'm:n') {
return propertyName + 'Inverse';
}
const suffix = kind === '1:m' && !entityName.endsWith('Collection') ? 'Collection' : '';
if (entityName.length === 1) {
return entityName[0].toLowerCase() + suffix;
}
return entityName[0].toLowerCase() + entityName.substring(1) + suffix;
}
/**
* @inheritDoc
*/
manyToManyPropertyName(ownerEntityName, targetEntityName, pivotTableName, ownerTableName, schemaName) {
return this.columnNameToProperty(pivotTableName.replace(new RegExp('^' + ownerTableName + '_'), ''));
}
/**
* @inheritDoc
*/
discriminatorColumnName(baseName) {
return this.propertyToColumnName(baseName + 'Type');
}
}

View File

@@ -0,0 +1,12 @@
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
/**
* This strategy keeps original entity/property names for table/column.
*/
export declare class EntityCaseNamingStrategy extends AbstractNamingStrategy {
classToTableName(entityName: string, tableName?: string): string;
joinColumnName(propertyName: string): string;
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string, tableName?: string): string;
propertyToColumnName(propertyName: string): string;
referenceColumnName(): string;
}

View File

@@ -0,0 +1,29 @@
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
/**
* This strategy keeps original entity/property names for table/column.
*/
export class EntityCaseNamingStrategy extends AbstractNamingStrategy {
classToTableName(entityName, tableName) {
return tableName ?? entityName;
}
joinColumnName(propertyName) {
return propertyName;
}
joinKeyColumnName(entityName, referencedColumnName, composite, tableName) {
entityName = this.classToTableName(entityName, tableName);
const name = entityName.substring(0, 1).toLowerCase() + entityName.substring(1);
if (composite && referencedColumnName) {
return name + '_' + referencedColumnName;
}
return name;
}
joinTableName(sourceEntity, targetEntity, propertyName, tableName) {
return this.classToTableName(sourceEntity, tableName) + '_' + this.propertyToColumnName(propertyName);
}
propertyToColumnName(propertyName) {
return propertyName;
}
referenceColumnName() {
return 'id';
}
}

View File

@@ -0,0 +1,10 @@
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
/** Naming strategy for MongoDB that uses camelCase property names and hyphenated collection names. */
export declare class MongoNamingStrategy extends AbstractNamingStrategy {
classToTableName(entityName: string, tableName?: string): string;
joinColumnName(propertyName: string): string;
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string, tableName?: string): string;
propertyToColumnName(propertyName: string): string;
referenceColumnName(): string;
}

View File

@@ -0,0 +1,22 @@
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
/** Naming strategy for MongoDB that uses camelCase property names and hyphenated collection names. */
export class MongoNamingStrategy extends AbstractNamingStrategy {
classToTableName(entityName, tableName) {
return tableName ?? entityName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
joinColumnName(propertyName) {
return propertyName;
}
joinKeyColumnName(entityName, referencedColumnName, composite, tableName) {
return tableName ?? entityName;
}
joinTableName(sourceEntity, targetEntity, propertyName, tableName) {
return this.classToTableName(sourceEntity, tableName) + '_' + this.propertyToColumnName(propertyName);
}
propertyToColumnName(propertyName) {
return propertyName;
}
referenceColumnName() {
return '_id';
}
}

View File

@@ -0,0 +1,112 @@
import type { ReferenceKind } from '../enums.js';
export interface NamingStrategy {
/**
* Return a name of the class based on its file name
*/
getClassName(file: string, separator?: string): string;
/**
* Return a table name for an entity class
*/
classToTableName(entityName: string, tableName?: string): string;
/**
* Return a migration name. This name should allow ordering.
*/
classToMigrationName(timestamp: string, customMigrationName?: string): string;
/**
* Return a column name for a property
*/
propertyToColumnName(propertyName: string, object?: boolean): string;
/**
* Get an enum class name.
*
* @param columnName The column name which has the enum.
* @param tableName The table name of the column.
* @param schemaName The schema name of the column.
*
* @return A new class name that will be used for the enum.
*/
getEnumClassName(columnName: string, tableName: string | undefined, schemaName?: string): string;
/**
* Get an enum type name. Used with `enumType: 'dictionary'` and `enumType: 'union-type'` entity generator option.
*
* @param columnName The column name which has the enum.
* @param tableName The table name of the column.
* @param schemaName The schema name of the column.
*
* @return A new type name that will be used for the enum.
*/
getEnumTypeName(columnName: string, tableName: string | undefined, schemaName?: string): string;
/**
* Get an enum option name for a given enum value.
*
* @param enumValue The enum value to generate a name for.
* @param columnName The column name which has the enum.
* @param tableName The table name of the column.
* @param schemaName The schema name of the column.
*
* @return The name of the enum property that will hold the value.
*/
enumValueToEnumProperty(enumValue: string, columnName: string, tableName: string, schemaName?: string): string;
/**
* Return a name of the entity class based on database table name (used in `EntityGenerator`).
* Default implementation ignores the schema name.
*/
getEntityName(tableName: string, schemaName?: string): string;
/**
* Return a property for a column name (used in `EntityGenerator`).
*/
columnNameToProperty(columnName: string): string;
/**
* Return the default reference column name
*/
referenceColumnName(): string;
/**
* Return a join column name for a property
*/
joinColumnName(propertyName: string): string;
/**
* Return a join table name
*/
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string, tableName?: string): string;
/**
* Return the foreign key column name for the given parameters
*/
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
/**
* Returns key/constraint name for the given type. Some drivers might not support all the types (e.g. mysql and sqlite enforce the PK name).
*/
indexName(
tableName: string,
columns: string[],
type: 'primary' | 'foreign' | 'unique' | 'index' | 'sequence' | 'check' | 'default',
): string;
/**
* Returns alias name for given entity. The alias needs to be unique across the query, which is by default
* ensured via appended index parameter. It is optional to use it as long as you ensure it will be unique.
*/
aliasName(entityName: string, index: number): string;
/**
* Returns the name of the inverse side property. Used in the `EntityGenerator` with `bidirectionalRelations` option.
*/
inverseSideName(entityName: string, propertyName: string, kind: ReferenceKind): string;
/**
* Return a property name for a many-to-many relation (used in `EntityGenerator`).
*
* @param ownerEntityName - The owner entity class name
* @param targetEntityName - The target entity class name
* @param pivotTableName - The pivot table name
* @param ownerTableName - The owner table name
* @param schemaName - The schema name (if any)
*/
manyToManyPropertyName(
ownerEntityName: string,
targetEntityName: string,
pivotTableName: string,
ownerTableName: string,
schemaName?: string,
): string;
/**
* Returns the discriminator column name for polymorphic relations.
*/
discriminatorColumnName(baseName: string): string;
}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,11 @@
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
/** Naming strategy that converts camelCase names to snake_case for table and column names. */
export declare class UnderscoreNamingStrategy extends AbstractNamingStrategy {
classToTableName(entityName: string, tableName?: string): string;
joinColumnName(propertyName: string): string;
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string, tableName?: string): string;
propertyToColumnName(propertyName: string, object?: boolean): string;
referenceColumnName(): string;
private underscore;
}

View File

@@ -0,0 +1,25 @@
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
/** Naming strategy that converts camelCase names to snake_case for table and column names. */
export class UnderscoreNamingStrategy extends AbstractNamingStrategy {
classToTableName(entityName, tableName) {
return tableName ?? this.underscore(entityName);
}
joinColumnName(propertyName) {
return this.underscore(propertyName) + '_' + this.referenceColumnName();
}
joinKeyColumnName(entityName, referencedColumnName, composite, tableName) {
return this.classToTableName(entityName, tableName) + '_' + (referencedColumnName || this.referenceColumnName());
}
joinTableName(sourceEntity, targetEntity, propertyName, tableName) {
return this.classToTableName(sourceEntity, tableName) + '_' + this.classToTableName(propertyName);
}
propertyToColumnName(propertyName, object) {
return this.underscore(propertyName);
}
referenceColumnName() {
return 'id';
}
underscore(name) {
return name.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
}
}

View File

@@ -0,0 +1,5 @@
export type * from './NamingStrategy.js';
export * from './AbstractNamingStrategy.js';
export * from './MongoNamingStrategy.js';
export * from './UnderscoreNamingStrategy.js';
export * from './EntityCaseNamingStrategy.js';

View File

@@ -0,0 +1,4 @@
export * from './AbstractNamingStrategy.js';
export * from './MongoNamingStrategy.js';
export * from './UnderscoreNamingStrategy.js';
export * from './EntityCaseNamingStrategy.js';