import { Constructor, IContainer } from '@spinajs/di'; import { IModelDescriptor, IMigrationOptions, IRelationDescriptor, IDiscriminationEntry, ISelectQueryBuilder, IColumnDescriptor, IPrimaryKeyOptions, OrphanPolicy } from './interfaces.js'; import 'reflect-metadata'; import { ModelBase } from './model.js'; import { Relation } from './relation-objects.js'; export { MODEL_DESCTRIPTION_SYMBOL, MIGRATION_DESCRIPTION_SYMBOL } from './symbols.js'; export declare function _prepareColumnDesc(initialize: Partial): IColumnDescriptor; /** * Resolves the single column a relation joins on. A relation's PrimaryKey / ForeignKey each * name exactly one column ( the JOIN compiler emits a one-column ON predicate ), so a composite * primary key has no defensible default and must be named explicitly by the developer. */ export declare function _relationDefaultKey(descriptor: IModelDescriptor, relationName: string, optionName: string): string; export declare function extractDecoratorPropertyDescriptor(callback: (model: IModelDescriptor, target: any, propertyKey: string, indexOrDescriptor: number | PropertyDescriptor) => void): any; /** * Helper func to create model metadata */ export declare function extractDecoratorDescriptor(callback: (model: IModelDescriptor, target: any, propertyKey: symbol | string, indexOrDescriptor: number | PropertyDescriptor) => void): any; /** * Sets migration option * * @param connection - connection name, must exists in configuration file * @param options - optional migration options, eg. the environment it belongs to */ export declare function Migration(connection: string, options?: IMigrationOptions): (target: any) => void; /** * Connection model decorator, assigns connection to model * * @param name - connection name, must be avaible in db config */ export declare function Connection(name: string): any; /** * TableName model decorator, assigns table from database to model * * @param name - table name in database that is referred by this model */ export declare function Model(tableName: string): any; /** * Set create timestamps feature to model. Proper columns must be avaible in database table. * It allow to track creation times & changes to model */ export declare function CreatedAt(): any; /** * Set update timestamps feature to model. Proper columns must be avaible in database table. * It allow to track creation times & changes to model */ export declare function UpdatedAt(): any; /** * Sets soft delete feature to model. Soft delete dont delete model, but sets deletion date and hides from * select result by default. */ export declare function SoftDelete(): any; /** * Enable archive mode for model. If enabled all changes creates new instance in DB and old have set archived field * and gets attached to new model. It enabled to track changes to model in DB and also preserve data in relations. * */ export declare function Archived(): any; /** * Marks a field as part of the primary key. Applying it to more than one property of the same * model declares a composite key; the columns are ordered by decorator evaluation order. * * NOTE: @Primary() is additive across an inheritance chain. A subclass cannot *replace* a base * class's primary key, only extend it. Declare @Primary() on every key column of the concrete model. * * @param options.generated - key generation strategy, defaults to `auto` ( database identity ). */ export declare function Primary(options?: IPrimaryKeyOptions): any; /** * Marks a property as one the model NEVER hands out: `dehydrate()` and `dehydrateWithRelations()` * omit it unconditionally, and it is dropped from the model's response JSON schema * ( `descriptor.ResponseSchema` ), so generated API documentation never advertises a field the * ORM guarantees is absent. rbac's `User` hides `Password` and `Id` this way. * * Applies to RELATION properties as well as columns - rbac's `UserMetadata` hides its `User` * relation, which never appears in `Columns` at all. * * The write contract is deliberately untouched: `descriptor.Schema` still carries the property, * because hiding a value on the way out says nothing about whether a client may send it in. Use * `@Ignore()` instead for a property that is not part of the table. * * Additive down an inheritance chain, like @Primary(): a subclass starts from everything its * ancestors hide and may add to it, without writing back into their descriptors. Declaring the * same property again in a subclass is harmless - it is recorded once. * * Written at class-definition time, which is the point of the decorator: every reader * ( response schema, `@spinajs/http-swagger` ) gets the list off the class itself, with no Orm * resolved and no database reachable. */ export declare function Hidden(): any; /** * Marks columns as UUID. Column will be generated ad creation */ export declare function Ignore(): any; /** * Marks columns as UUID. Column will be generated ad creation */ export declare function Uuid(): any; export declare function JunctionTable(): any; /** * * Marks model to have discrimination map. * * @param fieldName - db field name to look for * @param discriminationMap - field - model mapping */ export declare function DiscriminationMap(fieldName: string, discriminationMap: IDiscriminationEntry[]): any; /** * Marks relation as recursive. When relation is populated it loads all to the top * */ export declare function Recursive(): any; export interface IForwardReference { forwardRef: T; } export declare const forwardRef: (fn: () => any) => IForwardReference; /** * Creates one to one relation with target model. * * @param foreignKey - foreign key name in db, defaults to lowercase property name with _id suffix eg. owner_id * @param primaryKey - primary key in related model, defaults to primary key taken from db */ export declare function BelongsTo(targetModel: Constructor | string, foreignKey?: string, primaryKey?: string): any; export declare function Virtual(virtualRelation?: Constructor, ModelBase, typeof ModelBase>>>): any; /** * * Custom relation for executing custom queries to populate data. Use it when relation data dont come from another table * but rather from combinations of many tables * * @param callback * @returns */ export declare function Query, D extends ModelBase>(callback: (data: T[]) => ISelectQueryBuilder, mapper: (owner: T, data: D[]) => D | D[]): any; /** * Creates one to one relation with target model. * * @param foreignKey - foreign key name in db, defaults to lowercase property name with _id suffix eg. owner_id * @param primaryKey - primary key in related model, defaults to primary key taken from db */ export declare function ForwardBelongsTo(forwardRef: IForwardReference, foreignKey?: string, primaryKey?: string): any; export interface IRelationDecoratorOptions { /** * Relation factory, sometimes we dont want to create standard relation object. * When creating object and specific relation is created via this factory */ factory?: (owner: ModelBase, relation: IRelationDescriptor, container: IContainer) => Relation, ModelBase, typeof ModelBase>>; /** * sometimes we dont want to create standard relation object, so we create type * that is passed in this property */ type?: Constructor, ModelBase, typeof ModelBase>>>; } export interface IHasManyToManyDecoratorOptions extends IRelationDecoratorOptions { /** * target model primary key name */ targetModelPKey?: string; /** * source model primary key name */ sourceModelPKey?: string; /** * junction table target primary key name ( foreign key for target model ) */ junctionModelTargetPk?: string; /** * junction table source primary key name ( foreign key for source model ) */ junctionModelSourcePk?: string; /** * Join mode on relation * Sometimes right side of junction relation not exists and we want to filter it out */ joinMode?: 'LeftJoin' | 'RightJoin'; /** * What `save()` does with a member removed from this relation. For many-to-many this * governs the *target* row: the junction row is always deleted. Defaults to `nullify`, * which for a junction relation means "unlink only, leave the target row alone". */ orphan?: OrphanPolicy; } export interface IHasManyDecoratorOptions extends IRelationDecoratorOptions { foreignKey?: string; primaryKey?: string; /** * What `save()` does with a child removed from this relation. Defaults to `nullify`, * escalating to `delete` when the foreign key is reflected as NOT NULL. */ orphan?: OrphanPolicy; } /** * Creates one to many relation with target model. * * @param targetModel - due to limitations of metadata reflection api in typescript target model mus be set explicitly * @param foreignKey - foreign key name in db, defaults to lowercase property name with _id suffix eg. owner_id * @param primaryKey - primary key in source table defaults to lowercase property name with _id suffix eg. owner_id * */ export declare function HasMany(targetModel: Constructor | string, options?: IHasManyDecoratorOptions): any; export declare function Historical(targetModel: Constructor): any; /** * Creates many to many relation with separate join table * * @param junctionModel - model for junction table * @param targetModel - model for related data */ export declare function HasManyToMany(junctionModel: Constructor, targetModel: Constructor | string, options?: IHasManyToManyDecoratorOptions): any; /** * Mark field as datetime type. It will ensure that conversion to & from DB is valid, eg. sqlite DB * saves datetime as TEXT and ISO8601 strings */ export declare function DateTime(): any; /** * Mark field as boolean type. * * The ORM attaches a boolean converter on its own only when the driver NAMES the column's native * type after a boolean: `Orm.reloadTableInfo` looks `DATA_TYPE` up in `__orm_db_value_converters__`, * which is keyed by `Boolean` / `bool`. MySQL reports `tinyint(1)` - its own spelling of BOOLEAN - * as `tinyint`, so the lookup misses and the column ends up with NO converter at all. Nothing then * translates it in either direction, and the two directions disagree: a SELECT leaves the driver's * `1` in a property declared `boolean`, while a create/update leaves the caller's `true` there, so * an endpoint answering with the model it just wrote returns a different JSON type than the one * answering a read. * * This decorator states the column's type explicitly instead. `BooleanValueConverter` is a lookup * key rather than an implementation - each driver binds its own (orm-sql: * `register(SqlBooleanValueConverter).as(BooleanValueConverter)`) - so the value is rendered the way * that database wants it while the property stays a real boolean. * * It also fixes the PUBLISHED type: `columnToSchema` maps `tinyint` to `{ type: 'integer' }` on the * SQL type alone, and overrides that to `{ type: 'boolean' }` when the column's declared converter * is a `BooleanValueConverter`. */ export declare function Bool(): any; /** * Converts data in db to json object. Column type in DB should be STRING. * DO not use this decorator for use of native DB JSON implementation. * ORM will detect automatically if field is native JSON DB type. */ export declare function Json(): any; /** * * Universal converter that guess whitch type to return. Usefull in tables that holds as text different values * eg. metadata table * * @param typeColumn - type column that defines final type of value */ export declare function UniversalConverter(typeColumn?: string): any; /** * Mark field as SET type. It will ensure that conversion to & from DB is valid, eg. to emulate field type SET in sqlite */ export declare function Set(): any; //# sourceMappingURL=decorators.d.ts.map