File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
packages/hypergraph/src/entity Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -10,21 +10,23 @@ import { findOne } from './findOne.js';
10
10
import type { DocumentContent , DocumentRelation , Entity } from './types.js' ;
11
11
12
12
/**
13
- * Type utility to transform relation fields to accept string arrays instead of their typed values
14
- * This specifically targets Type.Relation fields which are arrays of objects
15
- * Relations can be provided as string arrays or left out completely (optional)
13
+ * Type utility to transform relation fields to accept string arrays or be omitted entirely.
14
+ * This specifically targets Type.Relation fields which are arrays of objects.
16
15
*/
17
- type WithRelationsAsStringArrays < T > = {
16
+ type RelationArrayKeys < T > = {
18
17
[ K in keyof T ] : T [ K ] extends readonly ( infer U ) [ ]
19
18
? U extends object
20
- ? string [ ] | undefined
21
- : T [ K ]
19
+ ? K
20
+ : never
22
21
: T [ K ] extends ( infer U ) [ ]
23
22
? U extends object
24
- ? string [ ] | undefined
25
- : T [ K ]
26
- : T [ K ] ;
27
- } ;
23
+ ? K
24
+ : never
25
+ : never ;
26
+ } [ keyof T ] ;
27
+
28
+ type WithRelationsAsStringArrays < T > = Omit < T , RelationArrayKeys < T > > &
29
+ Partial < Record < RelationArrayKeys < T > , string [ ] | undefined > > ;
28
30
29
31
export const create = < const S extends Schema . Schema . AnyNoContext > ( handle : DocHandle < DocumentContent > , type : S ) => {
30
32
return ( data : Readonly < WithRelationsAsStringArrays < Schema . Schema . Type < S > > > ) : Entity < S > => {
You can’t perform that action at this time.
0 commit comments