UNPKG

@wearesage/schema

Version:

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

104 lines (86 loc) 2.4 kB
import { Entity, Property, Id, ManyToOne, Index, Timestamp, Auth } from '../core/decorators'; import { Space } from './Space'; @Entity() @Auth({ roles: ['admin'] }) // Only admins can manage affordances export class Affordance { @Id() id!: string; // The space this affordance belongs to @ManyToOne({ target: () => Space, inverse: 'availableAffordances' }) space!: Space; @Property({ required: true }) @Index() name!: string; @Property() description?: string; // What type of action this affordance represents @Property({ required: true }) @Index() actionType!: 'create_child' | 'query' | 'execute' | 'await' | 'transition' | 'explore' | 'custom'; // Icon or visual representation for UI @Property() icon?: string; // Grouping for UI organization @Property() category?: string; // What this action can create or lead to @Property() resultSpaceType?: string; // Required parameters for this action @Property() parameters!: { required?: { [key: string]: { type: 'string' | 'number' | 'boolean' | 'array' | 'object'; description: string; validation?: object; examples?: any[]; }; }; optional?: { [key: string]: { type: 'string' | 'number' | 'boolean' | 'array' | 'object'; description: string; default?: any; validation?: object; examples?: any[]; }; }; }; // Conditions that must be met for this affordance to be available @Property() preconditions!: { spaceStatus?: string[]; userPermissions?: string[]; childSpaceCount?: { min?: number; max?: number; }; parentSpaceRequired?: boolean; customLogic?: string; // JavaScript expression }; // What happens after this action is executed @Property() postActions!: { updateSpaceStatus?: string; createNotification?: boolean; triggerWebhook?: string; runScript?: string; }; // Progressive disclosure - what affordances become available after this one @Property() nextAffordances?: string[]; // IDs of other affordances @Property() priority: number = 0; @Property() isAvailable: boolean = true; // Runtime tracking @Property() usageCount: number = 0; @Property() lastUsed?: Date; @Timestamp({ onCreate: true }) createdAt!: Date; @Timestamp({ onUpdate: true }) updatedAt!: Date; }