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