schema improvements - #547
Conversation
e809170 to
948e8b9
Compare
ffece02 to
7c31882
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the schema definition API, moving from EntitySchema to Entity.Schema and consolidating schema-related functionality. The changes improve the API consistency and organization by using the Entity namespace for all entity-related operations.
Key changes:
- Replace
EntitySchemafunction calls withEntity.Schemathroughout the codebase - Rename
entity.tstoschema.tsand move schema functions there - Remove direct
EntitySchemaexports and update import statements - Update documentation to reflect the new schema API and remove mapping-related content
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/hypergraph/src/entity/schema.ts | Renames EntitySchema function to Schema and updates Effect Schema imports |
| packages/hypergraph/src/index.ts | Removes EntitySchema export in favor of Entity namespace |
| packages/hypergraph/test/entity/*.test.ts | Updates test files to use Entity.Schema instead of EntitySchema |
| packages/hypergraph/src/entity/*.ts | Updates imports to reference schema.ts instead of entity.ts |
| docs/*.md | Updates documentation with new schema API and removes mapping references |
| apps/*/src/schema.ts | Updates application schemas to use new Entity.Schema syntax |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| * Type utility to transform relation fields to accept string arrays or be omitted entirely. | ||
| * This specifically targets Type.Relation fields which are arrays of objects. | ||
| */ | ||
| type RelationArrayKeys<T> = { | ||
| [K in keyof T]: T[K] extends readonly (infer U)[] | ||
| ? U extends object | ||
| ? K | ||
| // For each property K in T, check if it's an array of objects (relation fields) | ||
| [K in keyof T]: T[K] extends readonly (infer U)[] // Check for readonly arrays | ||
| ? U extends object // If array element is an object | ||
| ? K // Return the property key K | ||
| : never | ||
| : T[K] extends (infer U)[] | ||
| ? U extends object | ||
| ? K | ||
| : T[K] extends (infer U)[] // Check for mutable arrays | ||
| ? U extends object // If array element is an object | ||
| ? K // Return the property key K | ||
| : never | ||
| : never; | ||
| }[keyof T]; | ||
| : never; // Not an array of objects, so exclude | ||
| }[keyof T]; // Extract the union of all matching property keys |
There was a problem hiding this comment.
[nitpick] These comments are overly verbose and explain basic TypeScript type operations that are self-evident from the code. Consider simplifying to focus on the business logic rather than TypeScript mechanics.
| * name: "grc-20-name", | ||
| * age: "grc-20-age" | ||
| * name: "grc-20-id", | ||
| * age: "grc-20-id" |
There was a problem hiding this comment.
Both properties are mapped to the same 'grc-20-id' which is incorrect. The second property should have a unique ID like 'grc-20-age-id'.
| * age: "grc-20-id" | |
| * age: "grc-20-age-id" |
No description provided.