UNPKG

@wearesage/schema

Version:

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

261 lines (210 loc) 5.42 kB
<INTRO> You're an expert TypeScript engineer who excels at emulating patterns you see in code. You will be shown a set of TypeScript entity classes that define a schema using decorators, properties, and relationships. Then, using these patterns, you will create a brand new schema representing a Codebase (a set of files in a filesystem) with all necessary relationships and fields, including your own creative additions. Please match the style, structure, and exact usage of decorators, properties, and relationships shown in the example. </INTRO> <TYPESCRIPT_SCHEMA_ABSTRACTION_EXAMPLE> import "reflect-metadata"; import { Entity, Id, Property, OneToMany, OneToOne, ManyToOne, ManyToMany } from "../.."; // --- BEGIN EXAMPLE SCHEMA --- @Entity() export class User { @Id() id: string; @Property({ required: true }) name: string; @Property({ required: true, unique: true }) email: string; @ManyToMany({ target: () => Organization, inverse: "members", name: "MEMBER_OF", }) organizations: Organization[] = []; @ManyToOne({ target: () => Organization, inverse: "owners", name: "OWNS_ORGANIZATION", }) ownedOrganization: Organization; @OneToMany({ target: () => Task, inverse: "assignee", name: "ASSIGNED_TO", }) tasks: Task[] = []; @OneToMany({ target: () => Task, inverse: "creator", name: "CREATED_BY", }) createdTasks: Task[] = []; } @Entity() export class Organization { @Id() id: string; @Property({ required: true }) name: string; @Property() description: string; @OneToMany({ target: () => Project, inverse: "organization", name: "OWNS_PROJECT", }) projects: Project[] = []; @ManyToMany({ target: () => User, inverse: "organizations", name: "HAS_MEMBER", }) members: User[] = []; @OneToMany({ target: () => User, inverse: "ownedOrganization", name: "OWNED_BY", }) owners: User[] = []; } @Entity() export class Project { @Id() id: string; @Property({ required: true }) name: string; @Property() description: string; @ManyToOne({ target: () => Organization, inverse: "projects", name: "BELONGS_TO_ORGANIZATION", }) organization: Organization; @OneToMany({ target: () => TaskBucket, inverse: "project", name: "HAS_BUCKET", }) buckets: TaskBucket[] = []; } @Entity() export class TaskBucket { @Id() id: string; @Property({ required: true }) name: string; @Property() order: number; @ManyToOne({ target: () => Project, inverse: "buckets", name: "BELONGS_TO_PROJECT", }) project: Project; @OneToMany({ target: () => Task, inverse: "bucket", name: "CONTAINS", }) tasks: Task[] = []; } @Entity() export class Task { @Id() id: string; @Property({ required: true }) title: string; @Property() description: string; @Property() dueDate: Date; @Property() completed: boolean = false; @Property() createdAt: Date; @ManyToOne({ target: () => TaskBucket, inverse: "tasks", name: "BELONGS_TO_BUCKET", }) bucket: TaskBucket; @ManyToOne({ target: () => User, inverse: "tasks", name: "ASSIGNED_TO", }) assignee: User; @ManyToOne({ target: () => User, inverse: "createdTasks", name: "CREATED_BY", }) creator: User; @OneToMany({ target: () => Comment, inverse: "task", name: "HAS_COMMENT", }) comments: Comment[] = []; @ManyToMany({ target: () => Label, inverse: "tasks", name: "HAS_LABEL", }) labels: Label[] = []; } @Entity() export class Comment { @Id() id: string; @Property({ required: true }) content: string; @Property() createdAt: Date; @ManyToOne({ target: () => Task, inverse: "comments", name: "BELONGS_TO_TASK", }) task: Task; @ManyToOne({ target: () => User, inverse: null, name: "CREATED_BY", }) author: User; } @Entity() export class Label { @Id() id: string; @Property({ required: true }) name: string; @Property() color: string; @ManyToMany({ target: () => Task, inverse: "labels", name: "APPLIED_TO", }) tasks: Task[] = []; } // --- END EXAMPLE SCHEMA --- </TYPESCRIPT_SCHEMA_ABSTRACTION_EXAMPLE> <TASK> Using these same patterns and decorators (including @Entity, @Property, @Id, @OneToMany, @ManyToOne, @ManyToMany, etc.), create a new schema that accurately represents a Codebase on a filesystem. The top-level entity is a Codebase with the following minimal fields: - name - description - path You must also include a File entity, with fields such as: - path - full source - metadata - embeddings Beyond that, imagine we also parse the AST to discover: - variables - functions - classes - interfaces - [vue] pinia stores, refs, computed properties, lifecycle methods Please be thorough and creative in mapping out the relationships between these entities. For instance, a File may have many functions, or a Function may have many parameters. Include any other related entities or properties that you believe are useful or interesting. Each class must use at least one relationship (OneToMany, ManyToOne, ManyToMany, or OneToOne) to show how they connect. Retain consistency in naming patterns, usage of decorators, and property definitions. Your response should be a cohesive TypeScript code snippet that can be used as-is. </TASK>