Skip to content

Commit 15123f3

Browse files
committed
Fix incorrect type specifications
1 parent d261d43 commit 15123f3

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/MappedDataSource.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ import { DataSourceMapping } from "./DataSourceMapping";
2424

2525
const debug = _debug("greldal:MappedDataSource");
2626

27-
type DataSourceAssociationType<T extends DataSourceMapping, K extends keyof T["associations"]> = MaybeArrayItem<
28-
ReturnType<NNil<T["associations"]>>[K]
29-
>;
27+
type AssociationsIn<T extends DataSourceMapping> = ReturnType<NNil<T["associations"]>>;
3028

31-
type AssociatedDataSource<T extends DataSourceMapping, K extends keyof T["associations"]> = ReturnType<
32-
DataSourceAssociationType<T, K>["target"]
33-
>;
29+
type FieldsIn<T extends DataSourceMapping> = ReturnType<NNil<T["fields"]>>;
30+
31+
type AssociationKeysIn<T extends DataSourceMapping> = keyof AssociationsIn<T>;
32+
33+
type FieldKeysIn<T extends DataSourceMapping> = keyof FieldsIn<T>;
34+
35+
type AssociatedDataSource<T extends DataSourceMapping, K extends AssociationKeysIn<T>> = AssociationsIn<T>[K]["target"];
3436

3537
type ShallowEntityType<T extends DataSourceMapping> = {
36-
[K in keyof ReturnType<NNil<T["fields"]>>]: t.TypeOf<ReturnType<NNil<T["fields"]>>[K]["type"]>
38+
[K in FieldKeysIn<T>]: t.TypeOf<FieldsIn<T>[K]["type"]>
3739
};
3840

3941
type NestedEntityType<T extends DataSourceMapping> = ShallowEntityType<T> &
40-
{ [K in keyof T["associations"]]: AssociatedDataSource<T, K>["EntityType"] };
42+
{ [K in AssociationKeysIn<T>]: AssociatedDataSource<T, K>["EntityType"] };
4143

4244
/**
4345
* Represents mapping between a relational data source and associated GraphQL types
@@ -365,15 +367,9 @@ export class MappedDataSource<T extends DataSourceMapping = any> {
365367
}
366368

367369
/**
368-
* Map a relational data source using specified configuration
369-
*
370-
* Refer the guide on [Mapping Data Sources](/mapping-data-sources) for detailed examples
371-
*
372-
* ## Args:
373-
* - mapping: [DataSourceMapping](api:DataSourceMapping) Mapping configuration
370+
* Used to map a relational data source using specified configuration (of type [DataSourceMapping](api:DataSourceMapping)).
374371
*
375-
* ## Returns:
376-
* - [MappedDataSource](api:MappedDataSource)
372+
* Refer the guide on [Mapping Data Sources](guide:mapping-data-sources) for detailed explanation and examples.
377373
*
378374
* @api-category PrimaryAPI
379375
*/

0 commit comments

Comments
 (0)