# All files / framework/types models.ts

0% Statements 0/3
100% Branches 0/0
0% Functions 0/1
0% Lines 0/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46

     import { BaseModel } from '../models/BaseModel';
    import { StoreType, ShardingConfig, PinningConfig, PubSubConfig } from './framework';

    export interface ModelConfig {
      type?: StoreType;
      scope?: 'user' | 'global';
      sharding?: ShardingConfig;
      pinning?: PinningConfig;
      pubsub?: PubSubConfig;
      tableName?: string;
    }

    export interface FieldConfig {
      type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'date';
      required?: boolean;
      unique?: boolean;
      index?: boolean | 'global';
      default?: any;
      validate?: (value: any) => boolean | string;
      transform?: (value: any) => any;
    }

    export interface RelationshipConfig {
      type: 'belongsTo' | 'hasMany' | 'hasOne' | 'manyToMany';
      model: typeof BaseModel;
      foreignKey: string;
      localKey?: string;
      through?: typeof BaseModel;
      lazy?: boolean;
    }

    export interface UserMappings {
      userId: string;
      databases: Record<string, string>;
    }

    export class ValidationError extends Error {
      public errors: string[];

      constructor(errors: string[]) {
        super(`Validation failed: ${errors.join(', ')}`);
        this.errors = errors;
        this.name = 'ValidationError';
      }
    }