@wearesage/schema
Version:
A flexible schema definition and validation system for TypeScript with multi-database support
103 lines (90 loc) • 2.25 kB
text/typescript
import { Entity, Property, Id, ManyToOne, Index, Timestamp, Auth } from '../core/decorators';
import { Space } from './Space';
()
({ permissions: ['user'] }) // Users can manage context rules for spaces they own
export class ContextRule {
()
id!: string;
// The space this context rule belongs to
({ target: () => Space, inverse: 'contextRules' })
space!: Space;
({ required: true })
()
name!: string;
()
description?: string;
// When to trigger this context rule
({ 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
({ 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
()
filters?: {
severity?: string[];
timeRange?: {
from?: string;
to?: string;
last?: string; // "1h", "24h", "7d"
};
relevanceScore?: {
minimum: number;
algorithm?: string;
};
maxItems?: number;
deduplicate?: boolean;
};
()
priority: number = 0;
()
isActive: boolean = true;
// Runtime optimization
()
cacheResults: boolean = false;
()
cacheTTL: number = 300; // seconds
({ onCreate: true })
createdAt!: Date;
({ onUpdate: true })
updatedAt!: Date;
}