/** * Decorator system for \@microsoft/rayfin-core * * These decorators store metadata at runtime using TC39 Stage 3 decorator metadata. * The Rayfin CLI reads this metadata to generate DAB-compliant configuration. * Metadata is stored via Symbol.metadata for runtime introspection and validation. */ import { SimpleAction, RoleDeclarationOptions } from '../options.js'; import { EntityClass, constructor, IEntity, Scalars } from '../schema.js'; /** * Marker decorator to indicate this class should be analyzed as a DAB entity. * * Entity settings inferred from class name and conventions: * - Entity name: kebab-case class name (e.g., "Todo" → "todo") * - Source table: pluralized snake_case name (e.g., "Todo" → "todos") * - Schema: default schema for the target database dialect * * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; * } * ``` * * @param name - Optional explicit entity name; defaults to the class name. * @returns A class decorator that registers the entity. */ export declare function entity(name?: string): >(_target: T, _context: ClassDecoratorContext) => void; /** * Class-level role decorator. * * Declares permissions for the built-in `'authenticated'` role with optional * typed policy and field visibility. * * @param roleName - The role name (currently only `'authenticated'`) * @param actions - The actions this role can perform * @param options - Optional policy and field visibility configuration */ export declare function role(roleName: 'authenticated', actions: SimpleAction | SimpleAction[], options?: RoleDeclarationOptions): (target: constructor, context: ClassDecoratorContext>) => void; /** * Shorthand decorator for authenticated role. * * Equivalent to `@role('authenticated', actions, options)`. * Authenticated roles require a valid user session. * * @param actions - The actions this role can perform (default: '*' for all actions) * @param options - Optional policy and field visibility configuration * * @example * ```typescript * @entity() * @authenticated('*', { * check: (claims, item) => claims.sub.eq(item.user_id), * }) * export class Todo { * @uuid() * id!: string; * @text() * user_id!: string; * } * ``` */ export declare function authenticated(actions?: SimpleAction | SimpleAction[], options?: RoleDeclarationOptions): (target: constructor, context: ClassDecoratorContext>) => void; /** * Base field options that are common across all field types. * * @typeParam TJSType - The TypeScript type of the field (e.g., string, number, Date) */ export interface BaseFieldOptions { /** * Indicates whether the field must be unique across all records. * * When set to true, a unique constraint will be created in the database * to enforce uniqueness for this field. * * @defaultValue false */ unique?: boolean; /** * Indicates whether the field is optional (nullable). * * When set to true, the field will allow null values in the database. * Fields are required by default unless marked with optional: true. * * @defaultValue false (fields are required by default) */ optional?: boolean; /** * The default value for the field if none is provided. * */ default?: TJSType; } /** * Text field options for string fields. */ export interface TextFieldOptions extends BaseFieldOptions { /** * Maximum length of the text field. * * Specifies the maximum number of characters allowed in the text field. * If `undefined` or `-1`, defaults to the database's maximum length for string types. * * @defaultValue undefined (database default maximum length) */ max?: number; /** Minimum length of the text field. * * Specifies the minimum number of characters required in the text field. * * @defaultValue undefined (no minimum length) */ min?: number; /** * Regular expression pattern that the text field must match. * * If provided, the text field value will be validated against this regex pattern. */ regex?: RegExp; } /** * Text field decorator for long text content. * * Specifies a field as text type, mapping to database text types * (NVARCHAR(MAX), TEXT, etc. depending on dialect). * * Fields are required by default. Use `{ optional: true }` for nullable fields. * * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; * * @text() * title!: string; // Required text field (default) * * @text({ optional: true }) * description?: string; // Optional text field * * @text({ unique: true }) * slug!: string; // Unique and required text field * } * ``` * * @param options - Text field configuration options. * @returns A class field decorator. */ export declare function text(options?: TextFieldOptions): (_: T, context: ClassFieldDecoratorContext) => void; /** * UUID field options for unique identifier fields. */ export interface UUIDFieldOptions extends BaseFieldOptions { } /** * UUID field decorator for unique identifiers. * * Specifies a field as UUID/GUID type, mapping to database UUID types * (UNIQUEIDENTIFIER, UUID, etc. depending on dialect). * * Fields are required by default. Use `{ optional: true }` for nullable fields. * Fields named `id` are automatically inferred as primary keys. Use `{ unique: true }` for unique constraint. * * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; // UUID primary key (required by default) * * @uuid() * userId!: string; // UUID foreign key (required by default) * * @uuid({ optional: true }) * optionalId?: string; // Optional UUID field * * @text() * title!: string; * } * ``` * * @param options - UUID field configuration options. * @returns A class field decorator. */ export declare function uuid(options?: UUIDFieldOptions): (_: T, context: ClassFieldDecoratorContext) => void; /** * Integer field options for whole number fields. */ export interface IntFieldOptions extends BaseFieldOptions { /** * Maximum value for the integer field. */ max?: number; /** * Minimum value for the integer field. */ min?: number; } /** * Integer field decorator for whole numbers. * * Specifies a field as integer type, mapping to database integer types * (INT, INTEGER, etc. depending on dialect). * * Fields are required by default. Use `{ optional: true }` for nullable fields. * * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; * * @int() * priority!: number; // Integer field (required by default) * * @int({ optional: true }) * order?: number; // Optional integer field * } * ``` * * @param options - Integer field configuration options. * @returns A class field decorator. */ export declare function int(options?: IntFieldOptions): (_: T, context: ClassFieldDecoratorContext) => void; /** * Decimal field options for precise numeric values. */ export interface DecimalFieldOptions extends BaseFieldOptions { /** * Maximum value for the decimal field. */ max?: number; /** * Minimum value for the decimal field. */ min?: number; /** * Total number of digits (before and after the decimal point). * * Must be defined together with `scale`. * If omitted, defaults to 18. * Maximum precision is 28, limited by the Data API Builder runtime. */ precision?: number; /** * Number of digits after the decimal point. * * Must be defined together with `precision`. * If omitted, defaults to 2. * Must be between 0 and `precision` (inclusive). */ scale?: number; } /** * Decimal field decorator for precise numeric values. * * Specifies a field as decimal/numeric type, mapping to database decimal types * (DECIMAL, NUMERIC, etc. depending on dialect). * Useful for monetary values and precise numeric calculations. * * When no `precision` or `scale` is specified, defaults to `DECIMAL(18,2)` * on MSSQL and `NUMERIC(18,2)` on PostgreSQL. * If either `precision` or `scale` is provided, both must be specified. * * Fields are required by default. Use `{ optional: true }` for nullable fields. * * @example * ```typescript * @entity() * export class Product { * @uuid() * id!: string; * * @decimal() * price!: number; // DECIMAL(18,2) by default * * @decimal({ precision: 10, scale: 4 }) * weight!: number; // DECIMAL(10,4) * * @decimal({ optional: true }) * discount?: number; // Optional decimal field * } * ``` * * @param options - Decimal field configuration options. * @returns A class field decorator. */ export declare function decimal(options?: DecimalFieldOptions): (_: T, context: ClassFieldDecoratorContext) => void; /** * Email field decorator for email addresses. * * Specifies a field as email type, mapping to database string types * with email format validation hints. * * The regex pattern is similar to RFC 5322, but has some extra restrictions * to catch common mistakes. If you need full UTF-8 support or less strict validation, * use a text() field with a custom regex. * * The format hint can be used for validation and UI rendering. * Fields are required by default. Use `{ optional: true }` for nullable fields. * * @example * ```typescript * @entity() * export class User { * @uuid() * id!: string; * * @email({ unique: true }) * emailAddress!: string; // Email field with unique constraint (required by default) * * @text() * name!: string; * } * ``` * * @param options - Email field configuration options. * @returns A class field decorator. */ export declare function email(options?: TextFieldOptions): (_: T, context: ClassFieldDecoratorContext) => void; /** * Boolean field options for true/false values. */ export interface BooleanFieldOptions extends BaseFieldOptions { } /** * Boolean field decorator for true/false values. * * Specifies a field as boolean type, mapping to database boolean types * (BIT, BOOLEAN, etc. depending on dialect). * * Fields are required by default. Use `{ optional: true }` for nullable fields. * * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; * * @text() * title!: string; * * @boolean() * isCompleted!: boolean; // Boolean field (required by default) * * @boolean({ optional: true }) * isArchived?: boolean; // Optional boolean field * } * ``` * * @param options - Boolean field configuration options. * @returns A class field decorator. */ export declare function boolean(options?: BooleanFieldOptions): (_: T, context: ClassFieldDecoratorContext) => void; /** * Options for the {@link set} field decorator, which constrains a string field * to a fixed set of allowed values. * * @typeParam T - The tuple of allowed string-literal values. */ export interface SetFieldOptions extends BaseFieldOptions { /** The array of allowed string values for the field. */ enum: T; } /** * Set field decorator for constrained string values. * * Specifies a field as an set (or enum-like) type with a limited set of allowed values. * Maps to database string types (NVARCHAR, VARCHAR, etc.) with check constraints. * The set values should match the TypeScript union type annotation. * * @param values - Array of allowed string values (must have at least one value) * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; * * @text() * title!: string; * * @set('low', 'medium', 'high') * priority!: 'low' | 'medium' | 'high'; // Enum field with check constraint * } * ``` */ export declare function set(...values: T): (target: unknown, context: ClassFieldDecoratorContext) => void; /** * Set field decorator for constrained string values. * * Specifies a field as an set (or enum-like) type with a limited set of allowed values. * Maps to database string types (NVARCHAR, VARCHAR, etc.) with check constraints. * The set values should match the TypeScript union type annotation. * * @param options - Options object including the enum values * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; * * @text() * title!: string; * * @set({ enum: ['low', 'medium', 'high'] }) * priority!: 'low' | 'medium' | 'high'; // Enum field with check constraint * * @set({ enum: ['pending', 'completed'], optional: true }) * status?: 'pending' | 'completed'; // Optional enum field * } * ``` */ export declare function set(options: SetFieldOptions): (target: unknown, context: ClassFieldDecoratorContext) => void; /** * Set field decorator for constrained string values. * * Specifies a field as an set (or enum-like) type with a limited set of allowed values. * Maps to database string types (NVARCHAR, VARCHAR, etc.) with check constraints. * The set values should match the TypeScript union type annotation. * * @param options - Options object including the enum values * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; * * @text() * title!: string; * * @set({}, 'low', 'medium', 'high') * priority!: 'low' | 'medium' | 'high'; // Enum field with check constraint * * @set({ optional: true }, 'pending', 'completed') * status?: 'pending' | 'completed'; // Optional enum field * } * ``` */ export declare function set(options: Omit, 'enum'>, ...values: T): (target: unknown, context: ClassFieldDecoratorContext) => void; /** * Date field options for temporal values. */ export interface DateFieldOptions extends BaseFieldOptions { } /** * Date/datetime field decorator for temporal values. * * Specifies a field as date type, mapping to database datetime types * (DATETIME2, TIMESTAMP, etc. depending on dialect). * * Fields are required by default. Use `{ optional: true }` for nullable fields. * * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; * * @text() * title!: string; * * @date() * createdAt!: Date; // Date field (required by default) * * @date({ optional: true }) * dueDate?: Date; // Optional date field * } * ``` * * @param options - Date field configuration options. * @returns A class field decorator. */ export declare function date(options?: DateFieldOptions): (_: T, context: ClassFieldDecoratorContext) => void; /** * Storage folder decorator for blob storage management. * * Marks a class as representing a storage folder configuration. * Folder settings inferred from class name and optional parameter: * - Folder name: parameter value or kebab-case class name * - Permissions: inferred from \@role() decorators * - Visibility: inferred from permission configuration * * @param _folderName - Optional folder name (defaults to kebab-case class name) * @example * ```typescript * @blob('uploads') * @role('authenticated', '*') * export class FileModel { * @uuid() * id!: string; * * @text() * fileName!: string; * } * ``` */ export declare function blob(_folderName?: string): >(_target: T, context: ClassDecoratorContext) => void; /** * Relationship field options for entity relationships. */ export interface RelationshipFieldOptions extends Omit, 'default'> { } /** * One-to-one or many-to-one relationship decorator. * * Marks a field as a relationship to a single entity instance. * Automatically generates a foreign key column (e.g., `category_id` for a `category` field). * The target entity type should be specified in the TypeScript type annotation. * * @example * ```typescript * @entity() * export class Todo { * @uuid() * id!: string; * * @text() * title!: string; * * @one(() => Category) * category!: Category; // Many-to-one: generates category_id FK * * @one(() => User) * assignee?: User; // Optional many-to-one relationship * } * ``` * * @param target - A thunk returning the related entity class. * @param options - Relationship field configuration options. * @returns A class field decorator. */ export declare function one(target: () => U, options?: RelationshipFieldOptions): (_: T, context: ClassFieldDecoratorContext | undefined>) => void; /** * One-to-many relationship decorator. * * Marks a field as a relationship to multiple entity instances (collection). * Represents the inverse side of a many-to-one relationship. * The target entity type should be specified as an array in the TypeScript type annotation. * * @example * ```typescript * @entity() * export class Category { * @uuid() * id!: string; * * @text() * name!: string; * * @many(() => Todo) * todos!: Todo[]; // One-to-many: reverse side of Todo.category * } * * @entity() * export class User { * @uuid() * id!: string; * * @many(() => Todo) * assignedTodos!: Todo[]; // One-to-many relationship * } * ``` * * @param target - A thunk returning the related entity class. * @param options - Relationship field configuration options. * @returns A class field decorator. */ export declare function many(target: () => U, options?: RelationshipFieldOptions): (_: T, context: ClassFieldDecoratorContext> | undefined>) => void; //# sourceMappingURL=decorators.d.ts.map