UNPKG

@wearesage/schema

Version:

A flexible schema definition and validation system for TypeScript with multi-database support

103 lines (90 loc) 2.25 kB
import { Entity, Property, Id, ManyToOne, Index, Timestamp, Auth } from '../core/decorators'; import { Space } from './Space'; @Entity() @Auth({ permissions: ['user'] }) // Users can manage context rules for spaces they own export class ContextRule { @Id() id!: string; // The space this context rule belongs to @ManyToOne({ target: () => Space, inverse: 'contextRules' }) space!: Space; @Property({ required: true }) @Index() name!: string; @Property() description?: string; // When to trigger this context rule @Property({ required: true }) conditions!: { eventTypes?: string[]; spaceStatus?: string[]; userActions?: string[]; timeConditions?: { after?: string; before?: string; recurring?: string; }; parentSpaceConditions?: { statuses?: string[]; types?: string[]; }; customLogic?: string; // JavaScript expression or function name }; // What context to inject when triggered @Property({ required: true }) injectionRules!: { includeEvents?: { types: string[]; limit: number; timeRange?: string; severity?: string[]; }; includeChildSpaces?: { statuses: string[]; depth: number; types?: string[]; }; includeParentSpaces?: { depth: number; types?: string[]; }; includeRelatedSpaces?: { relationships: string[]; depth?: number; }; includeMetadata?: { keys: string[]; transform?: string; }; customData?: string; // Function name or data source }; // How to filter and transform the injected context @Property() filters?: { severity?: string[]; timeRange?: { from?: string; to?: string; last?: string; // "1h", "24h", "7d" }; relevanceScore?: { minimum: number; algorithm?: string; }; maxItems?: number; deduplicate?: boolean; }; @Property() priority: number = 0; @Property() isActive: boolean = true; // Runtime optimization @Property() cacheResults: boolean = false; @Property() cacheTTL: number = 300; // seconds @Timestamp({ onCreate: true }) createdAt!: Date; @Timestamp({ onUpdate: true }) updatedAt!: Date; }