|
1 | 1 | import Model from '@ember-data/model';
|
2 | 2 | import EmberArray from '@ember/array';
|
3 | 3 | import ComputedProperty from '@ember/object/computed';
|
| 4 | +import Fragment from 'ember-data-model-fragments/fragment'; |
4 | 5 | import FragmentRegistry from 'ember-data-model-fragments/types/registries/fragment';
|
5 |
| -import FragmentAttributesRegistry from 'ember-data-model-fragments/types/registries/fragment-attributes'; |
6 | 6 | // eslint-disable-next-line ember/use-ember-data-rfc-395-imports
|
7 | 7 | import TransformRegistry from 'ember-data/types/registries/transform';
|
8 | 8 |
|
9 |
| -interface FragmentArray<FragmentType extends keyof FragmentRegistry> extends EmberArray<FragmentType> { |
10 |
| - addFragment(fragment: FragmentRegistry[FragmentType]): FragmentRegistry[FragmentType]; |
11 |
| - removeFragment(fragment: FragmentRegistry[FragmentType]): FragmentRegistry[FragmentType]; |
12 |
| - createFragment(attributes: FragmentAttributesRegistry[FragmentType]): FragmentRegistry[FragmentType]; |
| 9 | +interface FragmentArray<T extends Fragment> extends EmberArray<T> { |
| 10 | + addFragment(fragment: T): T; |
| 11 | + removeFragment(fragment: T): T; |
| 12 | + createFragment(attributes?: Partial<T>): T; |
13 | 13 | }
|
14 | 14 |
|
15 |
| -interface FragmentOptions<FragmentType extends keyof FragmentRegistry> { |
| 15 | +interface FragmentOptions<K extends keyof FragmentRegistry> { |
16 | 16 | polymorphic?: boolean;
|
17 |
| - typeKey?: string | ((data: FragmentAttributesRegistry[FragmentType], owner: Model) => string); |
18 |
| - defaultValue?: () => FragmentAttributesRegistry[FragmentType] | FragmentAttributesRegistry[FragmentType]; |
| 17 | + typeKey?: string | ((data: FragmentRegistry[K], owner: Model) => string); |
| 18 | + defaultValue?: Partial<FragmentRegistry[K]> | (() => Partial<FragmentRegistry[K]>); |
19 | 19 | }
|
20 | 20 |
|
21 |
| -type TransformType<FragmentType extends keyof TransformRegistry> = ReturnType< |
22 |
| - TransformRegistry[FragmentType]['deserialize'] |
| 21 | +type TransformType<K extends keyof TransformRegistry> = ReturnType< |
| 22 | + TransformRegistry[K]['deserialize'] |
23 | 23 | >;
|
24 | 24 |
|
25 |
| -export function fragment<FragmentType extends keyof FragmentRegistry>( |
26 |
| - type: FragmentType, |
27 |
| - options?: FragmentOptions<FragmentType>, |
28 |
| -): ComputedProperty<FragmentRegistry[FragmentType]>; |
29 |
| -export function fragmentArray<FragmentType extends keyof FragmentRegistry>( |
30 |
| - type: FragmentType, |
31 |
| - options?: FragmentOptions<FragmentType>, |
32 |
| -): ComputedProperty<FragmentArray<FragmentType>>; |
33 |
| -export function array<FragmentType extends keyof TransformRegistry>(): ComputedProperty<TransformRegistry[FragmentType]>; |
| 25 | +export function fragment<K extends keyof FragmentRegistry>( |
| 26 | + type: K, |
| 27 | + options?: FragmentOptions<K>, |
| 28 | +): ComputedProperty<FragmentRegistry[K]>; |
| 29 | +export function fragmentArray<K extends keyof FragmentRegistry>( |
| 30 | + type: K, |
| 31 | + options?: FragmentOptions<K>, |
| 32 | +): ComputedProperty<FragmentArray<FragmentRegistry[K]>>; |
| 33 | +export function array<T extends keyof TransformRegistry>(): ComputedProperty<TransformRegistry[T]>; |
34 | 34 |
|
35 | 35 | export function fragmentOwner(): ComputedProperty<Model>;
|
0 commit comments