File tree Expand file tree Collapse file tree 3 files changed +43
-35
lines changed Expand file tree Collapse file tree 3 files changed +43
-35
lines changed Original file line number Diff line number Diff line change
1
+ import type { AvailableSelection } from "../src/types.js" ;
2
+
1
3
export type NestedThing = {
2
4
bool : boolean ;
3
5
string : string ;
@@ -45,34 +47,4 @@ export type TestSchema = {
45
47
} ;
46
48
} ;
47
49
48
- export type AvailableTestSchemaSelection = {
49
- num ?: boolean | null | undefined ;
50
- str ?: boolean | null | undefined ;
51
- obj ?: {
52
- test ?: boolean | null | undefined ;
53
- bool ?: boolean | null | undefined ;
54
- } ;
55
- optionalObj ?: {
56
- test ?: boolean | null | undefined ;
57
- bool ?: boolean | null | undefined ;
58
- } ;
59
- list ?: {
60
- title : boolean | null | undefined ;
61
- } ;
62
- optionalList ?: {
63
- title : boolean | null | undefined ;
64
- } ;
65
- nested ?: NestedThing ;
66
- someConnection ?: {
67
- edges ?: {
68
- node ?: {
69
- id : boolean | null | undefined ;
70
- state : boolean | null | undefined ;
71
- } ;
72
- } ;
73
- pageInfo ?: {
74
- hasNextPage ?: boolean | null | undefined ;
75
- hasPreviousPage ?: boolean | null | undefined ;
76
- } ;
77
- } ;
78
- } ;
50
+ export type AvailableTestSchemaSelection = AvailableSelection < TestSchema > ;
Original file line number Diff line number Diff line change @@ -2,14 +2,23 @@ import type { GadgetConnection } from "./GadgetConnection.js";
2
2
import type { GadgetRecord } from "./GadgetRecord.js" ;
3
3
import type { GadgetRecordList } from "./GadgetRecordList.js" ;
4
4
5
+ export type AnyModelFinderMetadata = {
6
+ operationName : string ;
7
+ modelApiIdentifier : string ;
8
+ defaultSelection : Record < string , any > ;
9
+ selectionType : any ;
10
+ optionsType : any ;
11
+ schemaType : any | null ;
12
+ } ;
13
+
5
14
/**
6
15
* Object representing one model's API in a high level way
7
16
* This is a generic interface. Concrete ones are generated by Gadget, */
8
17
export interface AnyModelManager {
9
18
connection : GadgetConnection ;
10
- findOne ( id : string , options : any ) : Promise < GadgetRecord < any > > ;
11
- maybeFindOne ( id : string , options : any ) : Promise < GadgetRecord < any > | null > ;
12
- findMany ( options : any ) : Promise < GadgetRecordList < any > > ;
13
- findFirst ( options : any ) : Promise < GadgetRecord < any > > ;
19
+ findOne : ( ( id : string , options : any ) => Promise < GadgetRecord < any > > ) & AnyModelFinderMetadata ;
20
+ findMany : ( ( options : any ) => Promise < GadgetRecordList < any > > ) & AnyModelFinderMetadata ;
21
+ findFirst : ( ( options : any ) => Promise < GadgetRecord < any > > ) & AnyModelFinderMetadata ;
14
22
maybeFindFirst ( options : any ) : Promise < GadgetRecord < any > | null > ;
23
+ maybeFindOne ( id : string , options : any ) : Promise < GadgetRecord < any > | null > ;
15
24
}
Original file line number Diff line number Diff line change @@ -697,3 +697,30 @@ export type PaginateOptions = {
697
697
last ?: number | null ;
698
698
select ?: AnySelection | InternalFieldSelection | null ;
699
699
} ;
700
+
701
+ /**
702
+ * Convert a schema type into the type that a selection of it must extend
703
+ *
704
+ * Example Schema:
705
+ *
706
+ * {
707
+ * foo: boolean;
708
+ * bar?: string;
709
+ * nested?: {
710
+ * count: number
711
+ * }
712
+ * }
713
+ *
714
+ * Example available selection:
715
+ *
716
+ * {
717
+ * foo?: boolean | null | undefined;
718
+ * bar?: boolean | null | undefined;
719
+ * nested?: {
720
+ * count: boolean | null | undefined
721
+ * }
722
+ * }
723
+ */
724
+ export type AvailableSelection < Schema > = Schema extends string | number | bigint | null | undefined
725
+ ? boolean | null | undefined
726
+ : { [ key in keyof Schema ] ?: AvailableSelection < Schema [ key ] > } ;
You can’t perform that action at this time.
0 commit comments