UNPKG

lakutata

Version:

An IoC-based universal application framework.

744 lines (718 loc) 23.2 kB
import { RelationType, RelationTypeInFunction, PropertyTypeFactory, EventListenerType, DeferrableType, TableType, TreeType, ClosureTreeOptions, OnDeleteType, OnUpdateType } from './TypeDef.internal.73.js'; import { RelationOptions, ColumnOptions } from './TypeDef.internal.68.js'; import { ColumnMode } from './TypeDef.internal.87.js'; import { SelectQueryBuilder } from './TypeDef.internal.38.js'; import './TypeDef.internal.30.js'; import { OrderByCondition } from './TypeDef.internal.74.js'; import { DataSource } from './TypeDef.internal.33.js'; import { EntityTarget } from './TypeDef.internal.36.js'; /** * Arguments for RelationMetadata class. */ interface RelationMetadataArgs { /** * Class to which this relation is applied. */ readonly target: Function | string; /** * In the case if this relation is without a target, targetId must be specified. * This is used for entity schemas without classes. */ /** * Class's property name to which this relation is applied. */ readonly propertyName: string; /** * Indicates if this relation will be lazily loaded. */ readonly isLazy: boolean; /** * Original (reflected) class's property type. * * todo: this can be empty for relations from entity schemas. */ /** * Type of relation. Can be one of the value of the RelationTypes class. */ readonly relationType: RelationType; /** * Type of the relation. This type is in function because of language specifics and problems with recursive * referenced classes. */ readonly type: RelationTypeInFunction; /** * Inverse side of the relation. */ readonly inverseSideProperty?: PropertyTypeFactory<any>; /** * Additional relation options. */ readonly options: RelationOptions; /** * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables. */ readonly isTreeParent?: boolean; /** * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables. */ readonly isTreeChildren?: boolean; } /** * Arguments for ColumnMetadata class. */ interface ColumnMetadataArgs { /** * Class to which column is applied. */ readonly target: Function | string; /** * Class's property name to which column is applied. */ readonly propertyName: string; /** * Column mode in which column will work. * * todo: find name better then "mode". */ readonly mode: ColumnMode; /** * Extra column options. */ readonly options: ColumnOptions; } /** * Arguments for EmbeddedMetadata class. */ interface EmbeddedMetadataArgs { /** * Class to which this column is applied. */ target: Function | string; /** * Class's property name to which this column is applied. */ propertyName: string; /** * Indicates if this embedded is array or not. */ isArray: boolean; /** * Prefix of the embedded, used instead of propertyName. * If set to empty string, then prefix is not set at all. */ prefix?: string | boolean; /** * Type of the class to be embedded. */ type: (type?: any) => Function | string; } /** * Arguments for RelationIdMetadataArgs class. */ interface RelationIdMetadataArgs { /** * Class to which this decorator is applied. */ readonly target: Function | string; /** * Class's property name to which this decorator is applied. */ readonly propertyName: string; /** * Target's relation which it should count. */ readonly relation: string | ((object: any) => any); /** * Alias of the joined (destination) table. */ readonly alias?: string; /** * Extra condition applied to "ON" section of join. */ readonly queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>; } /** * Arguments for EntityListenerMetadata class. */ interface EntityListenerMetadataArgs { /** * Class to which listener is applied. */ readonly target: Function; /** * Class's property name to which listener is applied. */ readonly propertyName: string; /** * The type of the listener. */ readonly type: EventListenerType; } /** * Arguments for UniqueMetadata class. */ interface UniqueMetadataArgs { /** * Class to which index is applied. */ target: Function | string; /** * Unique constraint name. */ name?: string; /** * Columns combination to be unique. */ columns?: ((object?: any) => any[] | { [key: string]: number; }) | string[]; /** * Indicate if unique constraints can be deferred. */ deferrable?: DeferrableType; } /** * Arguments for CheckMetadata class. */ interface CheckMetadataArgs { /** * Class to which index is applied. */ target: Function | string; /** * Check constraint name. */ name?: string; /** * Check expression. */ expression: string; } /** * Arguments for ExclusionMetadata class. */ interface ExclusionMetadataArgs { /** * Class to which index is applied. */ target: Function | string; /** * Exclusion constraint name. */ name?: string; /** * Exclusion expression. */ expression: string; } /** * Arguments for RelationCountMetadata class. */ interface RelationCountMetadataArgs { /** * Class to which this decorator is applied. */ readonly target: Function; /** * Class's property name to which this decorator is applied. */ readonly propertyName: string; /** * Target's relation which it should count. */ readonly relation: string | ((object: any) => any); /** * Alias of the joined (destination) table. */ readonly alias?: string; /** * Extra condition applied to "ON" section of join. */ readonly queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>; } /** * Arguments for IndexMetadata class. */ interface IndexMetadataArgs { /** * Class to which index is applied. */ target: Function | string; /** * Index name. */ name?: string; /** * Columns combination to be used as index. */ columns?: ((object?: any) => any[] | { [key: string]: number; }) | string[]; /** * Indicates if index must be unique or not. */ unique?: boolean; /** * The SPATIAL modifier indexes the entire column and does not allow indexed columns to contain NULL values. * Works only in MySQL. */ spatial?: boolean; /** * The FULLTEXT modifier indexes the entire column and does not allow prefixing. * Works only in MySQL. */ fulltext?: boolean; /** * NULL_FILTERED indexes are particularly useful for indexing sparse columns, where most rows contain a NULL value. * In these cases, the NULL_FILTERED index can be considerably smaller and more efficient to maintain than * a normal index that includes NULL values. * * Works only in Spanner. */ nullFiltered?: boolean; /** * Fulltext parser. * Works only in MySQL. */ parser?: string; /** * Index filter condition. */ where?: string; /** * Indicates if index must sync with database index. */ synchronize?: boolean; /** * If true, the index only references documents with the specified field. * These indexes use less space but behave differently in some situations (particularly sorts). * This option is only supported for mongodb database. */ sparse?: boolean; /** * Builds the index in the background so that building an index an does not block other database activities. * This option is only supported for mongodb database. */ background?: boolean; /** * Builds the index using the concurrently option. * This option is only supported for postgres database. */ concurrent?: boolean; /** * Specifies a time to live, in seconds. * This option is only supported for mongodb database. */ expireAfterSeconds?: number; } /** * Arguments for TableMetadata class, helps to construct an TableMetadata object. */ interface TableMetadataArgs { /** * Class to which table is applied. * Function target is a table defined in the class. * String target is a table defined in a json schema. */ target: Function | string; /** * Table's name. If name is not set then table's name will be generated from target's name. */ name?: string; /** * Table type. Tables can be abstract, closure, junction, embedded, etc. */ type: TableType; /** * Specifies a default order by used for queries from this table when no explicit order by is specified. */ orderBy?: OrderByCondition | ((object: any) => OrderByCondition | any); /** * Table's database engine type (like "InnoDB", "MyISAM", etc). */ engine?: string; /** * Database name. Used in MySql and Sql Server. */ database?: string; /** * Schema name. Used in Postgres and Sql Server. */ schema?: string; /** * Indicates if schema synchronization is enabled or disabled for this entity. * If it will be set to false then schema sync will and migrations ignore this entity. * By default schema synchronization is enabled for all entities. */ synchronize?: boolean; /** * View expression. */ expression?: string | ((connection: DataSource) => SelectQueryBuilder<any>); /** * View dependencies. */ dependsOn?: Set<Function | string>; /** * Indicates if view is materialized */ materialized?: boolean; /** * If set to 'true' this option disables Sqlite's default behaviour of secretly creating * an integer primary key column named 'rowid' on table creation. */ withoutRowid?: boolean; /** * Table comment. Not supported by all database types. */ comment?: string; } /** * Arguments for NamingStrategyMetadata class. */ interface NamingStrategyMetadataArgs { /** * Class to which this column is applied. */ readonly target: Function; /** * Strategy name. */ readonly name: string; } /** * Arguments for JoinColumnMetadata class. */ interface JoinColumnMetadataArgs { /** * Class to which this column is applied. */ target: Function | string; /** * Class's property name to which this column is applied. */ propertyName: string; /** * Name of the column. */ name?: string; /** * Name of the column in the entity to which this column is referenced. * This is column property name, not a column database name. */ referencedColumnName?: string; /** * Name of the foreign key constraint. */ foreignKeyConstraintName?: string; } /** * Arguments for JoinTableMetadata class. */ interface JoinTableMetadataArgs { /** * Class to which this column is applied. */ readonly target: Function | string; /** * Class's property name to which this column is applied. */ readonly propertyName: string; /** * Name of the table that will be created to store values of the both tables (join table). * By default is auto generated. */ readonly name?: string; /** * First column of the join table. */ readonly joinColumns?: JoinColumnMetadataArgs[]; /** * Second (inverse) column of the join table. */ readonly inverseJoinColumns?: JoinColumnMetadataArgs[]; /** * Database where join table will be created. * Works only in some databases (like mysql and mssql). */ readonly database?: string; /** * Schema where join table will be created. * Works only in some databases (like postgres and mssql). */ readonly schema?: string; /** * Indicates if schema synchronization is enabled or disabled junction table. * If it will be set to false then schema sync will and migrations ignores junction table. * By default schema synchronization is enabled. */ readonly synchronize?: boolean; } /** * Arguments for EntitySubscriberMetadata class. */ interface EntitySubscriberMetadataArgs { /** * Class to which subscriber is applied. */ readonly target: Function; } /** * Arguments for InheritanceMetadata class. */ interface InheritanceMetadataArgs { /** * Class to which inheritance is applied. */ readonly target?: Function | string; /** * Inheritance pattern. */ readonly pattern: "STI"; /** * Column used as inheritance discriminator column. */ readonly column?: ColumnOptions; } /** * DiscriminatorValue properties. */ interface DiscriminatorValueMetadataArgs { /** * Class to which discriminator name is applied. */ readonly target: Function | string; /** * Discriminator value. */ readonly value: any; } /** * Arguments for EntityRepositoryMetadata class, helps to construct an EntityRepositoryMetadata object. */ interface EntityRepositoryMetadataArgs { /** * Constructor of the custom entity repository. */ readonly target: Function; /** * Entity managed by this custom repository. */ readonly entity?: EntityTarget<any>; } /** * Used to inject transaction's entity managed into the method wrapped with @Transaction decorator. */ interface TransactionEntityMetadataArgs { /** * Target class on which decorator is used. */ readonly target: Function; /** * Method on which decorator is used. */ readonly methodName: string; /** * Index of the parameter on which decorator is used. */ readonly index: number; } /** * Used to inject transaction's repository into the method wrapped with @Transaction decorator. */ interface TransactionRepositoryMetadataArgs { /** * Target class on which decorator is used. */ readonly target: Function; /** * Method on which decorator is used. */ readonly methodName: string; /** * Index of the parameter on which decorator is used. */ readonly index: number; /** * Type of the repository class (Repository, TreeRepository or MongoRepository) or custom repository class. */ readonly repositoryType: Function; /** * Argument of generic Repository<T> class if it's not custom repository class. */ readonly entityType?: Function; } /** * Arguments for Generated decorator class. */ interface GeneratedMetadataArgs { /** * Class to which decorator is applied. */ readonly target: Function | string; /** * Class's property name to which decorator is applied. */ readonly propertyName: string; /** * Generation strategy. */ readonly strategy: "uuid" | "increment" | "rowid"; } /** * Stores metadata collected for Tree entities. */ interface TreeMetadataArgs { /** * Entity to which tree is applied. */ target: Function | string; /** * Tree type. */ type: TreeType; /** * Tree options */ options?: ClosureTreeOptions; } /** * Arguments for ForeignKeyMetadata class. */ interface ForeignKeyMetadataArgs { /** * Class to which foreign key is applied. */ readonly target: Function | string; /** * Class's property name to which this foreign key is applied. */ readonly propertyName?: string; /** * Type of the relation. This type is in function because of language specifics and problems with recursive * referenced classes. */ readonly type: RelationTypeInFunction; /** * Foreign key constraint name. */ readonly name?: string; /** * Inverse side of the relation. */ readonly inverseSide?: PropertyTypeFactory<any>; /** * Column names which included by this foreign key. */ readonly columnNames?: string[]; /** * Column names which included by this foreign key. */ readonly referencedColumnNames?: string[]; /** * "ON DELETE" of this foreign key, e.g. what action database should perform when * referenced stuff is being deleted. */ readonly onDelete?: OnDeleteType; /** * "ON UPDATE" of this foreign key, e.g. what action database should perform when * referenced stuff is being updated. */ readonly onUpdate?: OnUpdateType; /** * Set this foreign key constraint as "DEFERRABLE" e.g. check constraints at start * or at the end of a transaction */ readonly deferrable?: DeferrableType; } /** * Storage all metadatas args of all available types: tables, columns, subscribers, relations, etc. * Each metadata args represents some specifications of what it represents. * MetadataArgs used to create a real Metadata objects. */ declare class MetadataArgsStorage { readonly tables: TableMetadataArgs[]; readonly trees: TreeMetadataArgs[]; readonly entityRepositories: EntityRepositoryMetadataArgs[]; readonly transactionEntityManagers: TransactionEntityMetadataArgs[]; readonly transactionRepositories: TransactionRepositoryMetadataArgs[]; readonly namingStrategies: NamingStrategyMetadataArgs[]; readonly entitySubscribers: EntitySubscriberMetadataArgs[]; readonly indices: IndexMetadataArgs[]; readonly foreignKeys: ForeignKeyMetadataArgs[]; readonly uniques: UniqueMetadataArgs[]; readonly checks: CheckMetadataArgs[]; readonly exclusions: ExclusionMetadataArgs[]; readonly columns: ColumnMetadataArgs[]; readonly generations: GeneratedMetadataArgs[]; readonly relations: RelationMetadataArgs[]; readonly joinColumns: JoinColumnMetadataArgs[]; readonly joinTables: JoinTableMetadataArgs[]; readonly entityListeners: EntityListenerMetadataArgs[]; readonly relationCounts: RelationCountMetadataArgs[]; readonly relationIds: RelationIdMetadataArgs[]; readonly embeddeds: EmbeddedMetadataArgs[]; readonly inheritances: InheritanceMetadataArgs[]; readonly discriminatorValues: DiscriminatorValueMetadataArgs[]; filterTables(target: Function | string): TableMetadataArgs[]; filterTables(target: (Function | string)[]): TableMetadataArgs[]; filterColumns(target: Function | string): ColumnMetadataArgs[]; filterColumns(target: (Function | string)[]): ColumnMetadataArgs[]; findGenerated(target: Function | string, propertyName: string): GeneratedMetadataArgs | undefined; findGenerated(target: (Function | string)[], propertyName: string): GeneratedMetadataArgs | undefined; findTree(target: (Function | string) | (Function | string)[]): TreeMetadataArgs | undefined; filterRelations(target: Function | string): RelationMetadataArgs[]; filterRelations(target: (Function | string)[]): RelationMetadataArgs[]; filterRelationIds(target: Function | string): RelationIdMetadataArgs[]; filterRelationIds(target: (Function | string)[]): RelationIdMetadataArgs[]; filterRelationCounts(target: Function | string): RelationCountMetadataArgs[]; filterRelationCounts(target: (Function | string)[]): RelationCountMetadataArgs[]; filterIndices(target: Function | string): IndexMetadataArgs[]; filterIndices(target: (Function | string)[]): IndexMetadataArgs[]; filterForeignKeys(target: Function | string): ForeignKeyMetadataArgs[]; filterForeignKeys(target: (Function | string)[]): ForeignKeyMetadataArgs[]; filterUniques(target: Function | string): UniqueMetadataArgs[]; filterUniques(target: (Function | string)[]): UniqueMetadataArgs[]; filterChecks(target: Function | string): CheckMetadataArgs[]; filterChecks(target: (Function | string)[]): CheckMetadataArgs[]; filterExclusions(target: Function | string): ExclusionMetadataArgs[]; filterExclusions(target: (Function | string)[]): ExclusionMetadataArgs[]; filterListeners(target: Function | string): EntityListenerMetadataArgs[]; filterListeners(target: (Function | string)[]): EntityListenerMetadataArgs[]; filterEmbeddeds(target: Function | string): EmbeddedMetadataArgs[]; filterEmbeddeds(target: (Function | string)[]): EmbeddedMetadataArgs[]; findJoinTable(target: Function | string, propertyName: string): JoinTableMetadataArgs | undefined; filterJoinColumns(target: Function | string, propertyName: string): JoinColumnMetadataArgs[]; filterSubscribers(target: Function | string): EntitySubscriberMetadataArgs[]; filterSubscribers(target: (Function | string)[]): EntitySubscriberMetadataArgs[]; filterNamingStrategies(target: Function | string): NamingStrategyMetadataArgs[]; filterNamingStrategies(target: (Function | string)[]): NamingStrategyMetadataArgs[]; filterTransactionEntityManagers(target: Function | string, propertyName: string): TransactionEntityMetadataArgs[]; filterTransactionRepository(target: Function | string, propertyName: string): TransactionRepositoryMetadataArgs[]; filterSingleTableChildren(target: Function | string): TableMetadataArgs[]; findInheritanceType(target: Function | string): InheritanceMetadataArgs | undefined; findDiscriminatorValue(target: Function | string): DiscriminatorValueMetadataArgs | undefined; /** * Filters given array by a given target or targets. */ protected filterByTarget<T extends { target: Function | string; }>(array: T[], target: (Function | string) | (Function | string)[]): T[]; /** * Filters given array by a given target or targets and prevents duplicate property names. */ protected filterByTargetAndWithoutDuplicateProperties<T extends { target: Function | string; propertyName: string; }>(array: T[], target: (Function | string) | (Function | string)[]): T[]; /** * Filters given array by a given target or targets and prevents duplicate relation property names. */ protected filterByTargetAndWithoutDuplicateRelationProperties<T extends RelationMetadataArgs>(array: T[], target: (Function | string) | (Function | string)[]): T[]; /** * Filters given array by a given target or targets and prevents duplicate embedded property names. */ protected filterByTargetAndWithoutDuplicateEmbeddedProperties<T extends EmbeddedMetadataArgs>(array: T[], target: (Function | string) | (Function | string)[]): T[]; } export { MetadataArgsStorage }; export type { CheckMetadataArgs, ColumnMetadataArgs, EmbeddedMetadataArgs, EntityListenerMetadataArgs, ExclusionMetadataArgs, IndexMetadataArgs, RelationCountMetadataArgs, RelationIdMetadataArgs, RelationMetadataArgs, TableMetadataArgs, TreeMetadataArgs, UniqueMetadataArgs };