Skip to content

Commit 3f9002c

Browse files
committed
implement Type.optional
1 parent 73e660b commit 3f9002c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

apps/events/src/components/todos.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export const Todos = () => {
2727
const [newTodoName, setNewTodoName] = useState('');
2828
const [assignees, setAssignees] = useState<{ value: string; label: string }[]>([]);
2929

30-
console.log(todos);
31-
3230
useEffect(() => {
3331
setAssignees((prevFilteredAssignees) => {
3432
// filter out assignees that are not in the users array whenever users change

packages/hypergraph/src/entity/entity-new.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { PropertyIdSymbol, TypeIdsSymbol } from '../constants.js';
1919
* ```
2020
*/
2121
export function Entity<
22-
T extends Record<string, (propertyId: string) => Schema.Schema<any>>,
22+
T extends Record<
23+
string,
24+
(propertyId: string) => Schema.Schema<any> | Schema.PropertySignature<any, any, any, any, any, any, any>
25+
>,
2326
P extends Record<keyof T, string>,
2427
>(
2528
schemaTypes: T,
@@ -30,7 +33,8 @@ export function Entity<
3033
): Schema.Struct<{
3134
[K in keyof T]: ReturnType<T[K]> & { id: string };
3235
}> {
33-
const properties: Record<string, Schema.Schema<any>> = {};
36+
const properties: Record<string, Schema.Schema<any> | Schema.PropertySignature<any, any, any, any, any, any, any>> =
37+
{};
3438

3539
for (const [key, schemaType] of Object.entries(schemaTypes)) {
3640
const propertyId = mapping.properties[key as keyof P];

packages/hypergraph/src/entity/type-new.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ export const Relation =
4040
Schema.annotations({ [PropertyIdSymbol]: propertyId, [RelationSchemaSymbol]: schema, [RelationSymbol]: true }),
4141
);
4242
};
43+
44+
export const optional =
45+
<S extends Schema.Schema.AnyNoContext>(schemaFn: (propertyId: string) => S) =>
46+
(propertyId: string) => {
47+
const innerSchema = schemaFn(propertyId);
48+
return Schema.optional(innerSchema);
49+
};

0 commit comments

Comments
 (0)