-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.d.ts
1734 lines (1488 loc) · 76.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { RequestInit, RequestCredentials } from 'whatwg-fetch';
import { Action, AnyAction, Reducer, ReducersMapObject, Store } from 'redux';
import { ThunkAction } from 'redux-thunk'
/**
* The status used when a new resource item has not yet been saved to an external API
*/
export const NEW: string;
/**
* The status used when a resource item is being edited
*/
export const EDITING: string;
/**
* The status used when a resource item or list is being synchronised with an external API
*/
export const FETCHING: string;
/**
* The status used when a new resource item is being saved to an external API for the first time
*/
export const CREATING: string;
/**
* The status used when an edited resource item is being saved to an external API
*/
export const UPDATING: string;
/**
* The status used when a resource item is being deleted on an external API
*/
export const DESTROYING: string;
/**
* The status used when a resource item failed to be deleted from an external API
*/
export const DESTROY_ERROR: string;
/**
* The generic status used when a resource item is being synced with an external API
*/
export const SYNCING: string;
/**
* The status used when a resource item or list has been successfully synchronised with an external API
*/
export const SUCCESS: string;
/**
* The status used when a resource item or list has is being uploaded or downloaded from an external API
*/
export const PROGRESS: string;
/**
* The status used when a resource item or list failed to synchronise with an external API
*/
export const ERROR: string;
/**
* The metadata type used when all of the attributes of of a resource are included
*/
export const COMPLETE: string;
/**
* The metadata type used when only the attributes necessary for a preview are included
*/
export const PREVIEW: string;
/**
* The error type when a client error has occurred when making a request. This can be a local JavaScript
* exception, or it can be a network timeout or disconnect.
*/
export const CLIENT_ERROR: string;
/**
* The key to use for items and lists when a one hasn't otherwise been specified or applies
*/
export const UNSPECIFIED_KEY: string;
/**
* One of the statuses a resource item or resource list can be in
*/
export type StatusType = string;
interface ErrorStatusRequired {
/**
* The type of the error as either CLIENT_ERROR or specified in the response body or error handler
*/
type: string;
/**
* The raw Error class when a client-side error occurs
*/
raw?: Error
}
/**
* Information about a request error
*/
export interface ErrorStatus extends ErrorStatusRequired {
[extraValues: string]: any
}
export interface ResourceStatusRequired {
/**
* The type of status of the resource item or list
*/
type: StatusType | null;
}
/**
* An object containing the status information of a particular resource item or resource list.
*/
export interface ResourceStatus extends ResourceStatusRequired {
/**
* The HTTP status code when an error occurs
*/
httpCode?: number;
/**
* Details of the errors, if status type is ERROR
*/
errors?: Array<ErrorStatus>;
/**
* The first error in errors, if status type is ERROR
*/
error?: ErrorStatus;
/**
* When the error occurred
*/
errorOccurredAt?: number;
/**
* When a request to fetch, create or update the resource item or list was last made to an external
* API
*/
requestedAt?: number;
/**
* When a response to fetch, create or update the resource item or list was last received from an
* external API
*/
syncedAt?: number;
}
export interface ResourceItemStatus<T> extends ResourceStatus {
/**
* Whether the resource item has been edited since it was last retrieved from an external API
*/
dirty?: boolean;
/**
* The original values before any local edits were done
*/
originalValues?: T
}
/**
* Information about the type of metadata the resource item or list represents
*/
export interface Metadata {
[extraValues: string]: any
}
/**
* The generic structure items and lists
*/
export interface GenericItemOrList {
/**
* The status information of the item or list
*/
status: ResourceStatus;
/**
* The metadata information of the item or list
*/
metadata: Metadata
}
/**
* The state and values of a single item of a particular resource
*/
export interface ResourcesItem<T> extends GenericItemOrList {
values: T;
/**
* The status information of the resource
*/
status: ResourceItemStatus<T>;
}
/**
* The parameters used to serialize a key to reference an item or list by
*/
export type ItemOrListParameters = object | string | number;
/**
* The unique identifier of a resource list
*/
export type ResourceListId = string;
/**
* A list of a particular resource
*/
export interface ResourcesList<T> extends GenericItemOrList {
/**
* A list of ids of resources in the order they appear in that list.
*/
positions: string[];
/**
* The list of items in the list, in the order that they appear
*/
items: Array<ResourcesItem<T>>
}
export interface ResourcesReduxState<T> {
/**
* The set of items of a particular resource type
*/
items: { [key: string]: ResourcesItem<T>; };
/**
* The set of lists of a particular resource type
*/
lists: { [key: string]: ResourcesList<T>; };
/**
* A dictionary of the resources that are currently selected.
*/
selectionMap: { [key: string]: boolean; };
/**
* The temporary key that is being used for a new resource item until it's been saved to a remote API and
* given a permanent unique identifier.
*/
newItemKey: string | null;
}
/**
* Object for building and then returning an initial resource list state that can be passed to a Redux store
* and work with the reducers returned by the resources() function
*/
export interface InitialListStateBuilder<T> {
/**
* Adds a new item to the list's initial state builder
* @param valuesOrParams Either the values of a new item to add to the initial state, outside of any
* list, or the params of the item to use to index it.
* @param optionalValues The values of the item, if the first argument was used to specify params
* @returns a new initial state builder scoped to the new item
*/
addItem: (valuesOrParams: object | T, optionalValues?: T) => InitialItemStateBuilder<T>;
/**
* Generates the initial list state the builder has been configured for, in the format suitable to
* pass to the Redux store.
* @param ResourceStatus The status to use for the list and all of its items if the list hasn't
* set its own.
* @param ResourceMetadata The metadata to use for the list and all of its items if the
* list hasn't set its own.
*/
build: ({status: ResourceStatus, metadata: Metadata}) => ResourcesList<T>;
/**
* Generates a map of items indexed by their correct key
* @param ResourceStatus The status to use for the items if the list or item hasn't set its own.
* @param ResourceMetadata The metadata for the items if the list or item hasn't set its own.
*/
buildItems: ({status: ResourceStatus, metadata: Metadata}) => { [key: string]: ResourcesItem<T>; }
/**
* Sets the status of the initial state
* @param ResourceStatusRequired The status type to set as the initial state
* @returns itself to allow for chaining method calls
*/
setStatusType: (ResourceStatusRequired) => InitialListStateBuilder<T>;
/**
* Sets the date the data was synced at
* @param date The date the data was last synced
* @returns itself to allow for chaining method calls
*/
setSyncedAt: (date) => InitialListStateBuilder<T>;
/**
* Sets the metadata of the initial state
* @param ResourceStatusRequired The metadata object to set as the initial state
* @returns itself to allow for chaining method calls
*/
setMetadata: (Metadata) => InitialListStateBuilder<T>;
}
/**
* Object for building and then returning an initial resource item state that can be passed to a Redux store
* and work with the reducers returned by the resources() function
*/
export interface InitialItemStateBuilder<T> {
/**
* Generates the initial item state the builder has been configured for, in the format suitable to pass to
* the Redux store.
* @param ResourceStatus The status to use for the item if it hasn't set its own.
* @param ResourceMetadata The metadata for the item if it hasn't set its own.
*/
build: ({status: ResourceStatus, metadata: Metadata}) => ResourcesItem<T>;
/**
* Sets the status of the initial state
* @param ResourceStatusRequired The status type to set as the initial state
* @returns itself to allow for chaining method calls
*/
setStatusType: (ResourceStatusRequired) => InitialItemStateBuilder<T>;
/**
* Sets the date the data was synced at
* @param date The date the data was last synced
* @returns itself to allow for chaining method calls
*/
setSyncedAt: (date) => InitialItemStateBuilder<T>;
/**
* Sets the metadata of the initial state
* @param ResourceStatusRequired The metadata object to set as the initial state
* @returns itself to allow for chaining method calls
*/
setMetadata: (MetadataRequired) => InitialItemStateBuilder<T>;
}
/**
* Object for building and then returning an initial state that can be passed to a Redux store and work
* with the reducers returned by the resources() function
*/
export interface InitialResourceStateBuilder<T> {
/**
* Adds a new list to the initial state builder
* @param itemsOrParams Either the params to use to index the list or the list of items that
* make up the list. If no params are specified, the default unscoped list is used.
* @param optionalItems The list of items in the list, if they were not specified as the first
* argument
* @returns a new initial state builder scoped to the new list
*/
addList: (itemsOrParams: object | Array<T>, optionalItems?: Array<T>) => InitialListStateBuilder<T>;
/**
* Adds a new item to the initial state builder
* @param paramsOrValues Either the values of a new item to add to the initial state, outside of any
* list, or the params of the item to use to index it.
* @param optionalValues The values of the item, if the first argument was used to specify params
* @returns a new initial state builder scoped to the new item
*/
addItem: (paramsOrValues: object | T, optionalValues?: T) => InitialItemStateBuilder<T>;
/**
* Generates the initial state the builder has been configured for, in the format suitable to pass to
* the Redux store.
*/
build: () => ResourcesReduxState<T>;
/**
* Sets the status of the initial state
* @param ResourceStatusRequired The status type to set as the initial state
* @returns itself to allow for chaining method calls
*/
setStatusType: (ResourceStatusRequired) => InitialResourceStateBuilder<T>;
/**
* Sets the date the data was synced at
* @param date The date the data was last synced
* @returns itself to allow for chaining method calls
*/
setSyncedAt: (date) => InitialResourceStateBuilder<T>;
/**
* Sets the metadata of the initial state
* @param ResourceStatusRequired The metadata object to set as the initial state
* @returns itself to allow for chaining method calls
*/
setMetadata: (MetadataRequired) => InitialResourceStateBuilder<T>;
}
/**
* Returns an item of a particular resource item from a Redux store, removing any structure used implicitly.
*/
export interface GetItemFunction<T> { (currentState: ResourcesReduxState<T>, params: ItemOrListParameters): ResourcesItem<T> }
export interface GetSingularResourceItemFunction<T> { (currentState: ResourcesReduxState<T>): ResourcesItem<T> }
/**
* Returns an item of a particular resource from a Redux store. If the item is not available in the store,
* an empty item is returned immediately and the fetch action creator is called to update the store and
* request the resource item from an external API.
* @param currentState The current resource Redux store state
* @param params The params to serialize to use as the key to find the resource list.
* @param actionCreatorOptions The options to pass to the fetch action creator if it's called.
* @returns The resource item if it's in the store, or an empty item.
*/
export interface GetOrFetchItemFunction<T> { (currentState: ResourcesReduxState<T>, params: ItemOrListParameters, actionCreatorOptions?: RemoteActionCreatorOptions<T>): ResourcesItem<T> }
/**
* Returns an item of a particular resource from a Redux store. If the item is not available in the store,
* an empty item is returned immediately and the fetch action creator is called to update the store and
* request the resource item from an external API.
* @param currentState The current resource Redux store state
* @param {ItemOrListParameters | Object} paramsOrValues The first argument which can either a string or object that is serialized
* and used to fill in the dynamic parameters of the resource's URL (params) or the attribute values
* to initialize the item with if it is not already in the store.
* @param {Object | ActionCreatorOptions} valuesOrActionCreatorOptions Either be the values used for initialization, or additional
* options passed to the action creator when it is called.
* @param {ActionCreatorOptions} [optionalActionCreatorOptions=undefined] The optional additional options passed to the action controller.
*/
export interface GetOrInitializeItemFunction<T> { (currentState: ResourcesReduxState<T>, paramsOrValues: ItemOrListParameters | T, valuesOrActionCreatorOptions?: T | ActionCreatorOptions<T>, optionalActionCreatorOptions?: ActionCreatorOptions<T>): ResourcesItem<T> }
export interface GetOrFetchSingularResourceItemFunction<T> { (currentState: ResourcesReduxState<T>, params?: ItemOrListParameters, actionCreatorOptions?: RemoteActionCreatorOptions<T>): ResourcesItem<T> }
/**
* Returns a list of a particular resource from a Redux store, populating it with the correct items, in
* the right order.
*/
export interface GetListFunction<T> { (currentState: ResourcesReduxState<T>, params?: ItemOrListParameters): ResourcesList<T> }
/**
* Returns an list of a particular resource from a Redux store. If the list is not available in the store,
* an empty list is returned immediately and the fetch action creator is called to update the store and
* request the resource list from an external API.
* @param currentState The current resource Redux store state
* @param params The params to serialize to use as the key to find the resource list.
* @param actionCreatorOptions The options to pass to the fetch action creator if it's called.
* @returns The resource list if it's in the store, or an empty list.
*/
export interface GetOrFetchListFunction<T> { (currentState: ResourcesReduxState<T>, params?: ItemOrListParameters, actionCreatorOptions?: FetchListActionCreatorOptions<T>): ResourcesList<T> }
/**
* The type of Redux action that is emitted when that action occurs
*/
export type ActionType = string;
export interface StandardActionDictionary {
fetchList?: string;
fetchItem?: string;
newItem?: string;
clearNewItem?: string;
editNewItem?: string;
createItem?: string;
editItem?: string;
editNewOrExistingItem?: string;
clearItemEdit?: string;
updateItem?: string;
destroyItem?: string;
clearResource?: string;
clearItem?: string;
clearList?: string;
selectItem?: string;
selectAnotherItem?: string;
deselectItem?: string;
clearSelectedItems?: string;
}
/**
* Mapping between action names and their types
*/
export interface ActionDictionary extends StandardActionDictionary {
[key: string]: ActionType;
}
/**
* Function that dispatches an AnyAction or an ThunkAction
*/
export interface ActionCreatorFunction { (...args: any[]): ThunkAction<void, any, any, AnyAction> }
/**
* A dictionary of ActionCreatorFunctions indexed by their ActionCreatorName
*/
export interface StandardResourcesActionCreatorDictionary<T> {
/**
* Redux action creator used for fetching a list or resources from an index RESTful API endpoint
* @param {ItemOrListParameters} params A string or object that is serialized and used to fill in the dynamic parameters
* of the resource's URL
* @param {FetchListActionCreatorOptions} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {ThunkAction} Function to call to dispatch an action
*/
fetchList: (params?: ItemOrListParameters, actionCreatorOptions?: FetchListActionCreatorOptions<T>) => ThunkAction<void, any, any, AnyAction>;
/**
* Redux action creator used for fetching a single resource item from a fetch RESTful API endpoint
* @param {ItemOrListParameters} params A string or object that is serialized and used to fill in the dynamic parameters
* of the resource's URL
* @param {RemoteActionCreatorOptionsWithMetadata} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {ThunkAction} Function to call to dispatch an action
*/
fetchItem: (params?: ItemOrListParameters, actionCreatorOptions?: RemoteActionCreatorOptionsWithMetadata<T>) => ThunkAction<void, any, any, AnyAction>;
/**
* Redux action creator used for adding a new resource item to the Redux store WITHOUT sending it to a remote API
* (yet). This action is used for storing a new resource item locally before actually creating it
* (which sends the new attributes to the remote API).
* @param {ItemOrListParameters | Object} paramsOrValues The first argument which can either a string or object that is serialized
* and used to fill in the dynamic parameters of the resource's URL (params) or the new attribute values
* to merge into the exist ones of the new resource item, or to use to create the resource item for the
* first time.
* @param {Object | ActionCreatorOptions} valuesOrActionCreatorOptions Either be the values used by the action creator, or addition
* options passed to the action creator when it is called.
* @param {ActionCreatorOptions} [optionalActionCreatorOptions=undefined] The optional additional options passed to the action controller.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
newItem: (paramsOrValues: ItemOrListParameters | T, valuesOrActionCreatorOptions?: T | ActionCreatorOptions<T>, optionalActionCreatorOptions?: ActionCreatorOptions<T>) => AnyAction;
/**
* Redux action creator used for clearing the new resource.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearNewItem: () => AnyAction;
/**
* Redux action creator used for editing the attributes of a new resource item (one that hasn't been saved to
* a remote API yet). This action is used for editing a resource item locally (perhaps across
* multiple stages or screens) before actually saving it (which sends the new attributes to the remote API).
* @param {ItemOrListParameters | Object} paramsOrValues The first argument which can either be a string or object
* that is serialized and used to fill in the dynamic parameters of the resource's URL (params) or the new
* attribute values to merge into the exist ones of the new resource
* @param {Object|ActionCreatorOptions} valuesOrActionCreatorOptions Either the new attribute values to merge into the exist ones
* of the new resource item, or addition options passed to the action creator when it is called.
* @param {ActionCreatorOptions} [optionalActionCreatorOptions=undefined] The optional additional options passed to the action controller.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
editNewItem: (paramsOrValues: ItemOrListParameters | T, valuesOrActionCreatorOptions?: T | ActionCreatorOptions<T>, optionalActionCreatorOptions?: ActionCreatorOptions<T>) => AnyAction;
/**
* Redux action creator used for sending a CREATE request to a RESTful API endpoint
* @param {ItemOrListParameters | Object} paramsOrValues The first argument which can either a string
* or object that is serialized and used to fill in the dynamic parameters of the resource's URL
* (params) or the attribute values to use to create the resource.
* @param {Object|CreateItemActionCreatorOptions} valuesOrActionCreatorOptions Either be the values used by the action creator, or addition
* options passed to the action creator when it is called.
* @param {CreateItemActionCreatorOptions} [optionalActionCreatorOptions=undefined] The optional additional options passed to the action controller.
* @returns {ThunkAction} Function to call to dispatch an action
*/
createItem: (paramsOrValues: ItemOrListParameters | T , valuesOrActionCreatorOptions?: T | CreateItemActionCreatorOptions<T>, optionalActionCreatorOptions?: CreateItemActionCreatorOptions<T>) => ThunkAction<void, any, any, AnyAction>;
/**
* Redux action creator used for updating the attributes of a resource item WITHOUT sending those updated
* attributes to a remote API (yet). This action is used for editing a resource item locally (perhaps across
* multiple stages or screens) before actually updating it (which sends the new attributes to the remote API).
* @param {ItemOrListParameters} params A string or object that is serialized and used to fill in
* the dynamic parameters of the resource's URL
* @param {Object} values The new attribute values to merge into the exist ones of the resource item.
* @param {ActionCreatorOptions} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
editItem: (params: ItemOrListParameters, values: T, actionCreatorOptions?: ActionCreatorOptions<T>) => AnyAction;
/**
* Redux action creator used for updating the attributes of a new or existing resource item WITHOUT sending those updated
* attributes to a remote API (yet). This action is used for editing a resource item locally (perhaps across
* multiple stages or screens) before actually updating it (which sends the new attributes to the remote API).
* @param {ItemOrListParameters} params A string or object that is serialized and used to fill in
* the dynamic parameters of the resource's URL
* @param {Object} values The new attribute values to merge into the exist ones of the resource item.
* @param {ActionCreatorOptions} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
editNewOrExistingItem: (params: ItemOrListParameters, values: T, actionCreatorOptions?: ActionCreatorOptions<T>) => AnyAction;
/**
* Redux action creator used for clearing the new resource.
* @param {ItemOrListParameters} params A string or object that is serialized and used to generate
* the index of the resource item
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearItemEdit: (params: ItemOrListParameters) => AnyAction;
/**
* Redux action creator used for sending an UPDATE request to a RESTful API endpoint
* @param {ItemOrListParameters} params A string or object that is serialized and used to fill
* in the dynamic parameters of the resource's URL
* @param {Object} values The attribute values to use to update the resource
* @param {UpdateItemActionCreatorOptions} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {ThunkAction} Function to call to dispatch an action
*/
updateItem: (params: ItemOrListParameters, values: T, actionCreatorOptions?: UpdateItemActionCreatorOptions<T>) => ThunkAction<void, any, any, AnyAction>;
/**
* Redux action creator used for destroying a resource item by making a DELETE request to a RESTful API endpoint
* @param {ItemOrListParameters} params A string or object that is serialized and used to fill in
* the dynamic parameters of the resource's URL
* @param {DestroyItemActionCreatorOptions} [actionCreatorOptions={}] The options passed to the action
* creator when it is called.
* @returns {ThunkAction} Function to call to dispatch an action
*/
destroyItem: (params: ItemOrListParameters, actionCreatorOptions?: DestroyItemActionCreatorOptions<T>) => ThunkAction<void, any, any, AnyAction>;
/**
* Redux action creator used for clearing an item from the store
* @param {ItemOrListParameters} params A string or object that is serialized and used to find
* the item to clear.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearItem: (params: ItemOrListParameters) => AnyAction;
/**
* Redux action creator used for clearing a list from the store
* @param {ItemOrListParameters} params A string or object that is serialized and used to find
* the item to clear
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearList: (params: ItemOrListParameters) => AnyAction;
/**
* Redux action creator used for resetting a resource back to empty
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearResource: () => AnyAction;
/**
* Redux action creator used for selecting a resource item and replacing any already selected items
* @param {ItemOrListParameters|ItemOrListParameters[]} params A string or object that is serialized and used to fill in
* the dynamic parameters of the resource's URL
* @param {SelectItemOptions} [actionCreatorOptions={}] The options passed to the action creator when
* it is called.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
selectItem: (params: ItemOrListParameters, actionCreatorOptions?: SelectItemOptions) => AnyAction;
/**
* Redux action creator used for selecting a resource item and adding it to those already selected
* @param {ItemOrListParameters|ItemOrListParameters[]} params A string or object that is serialized and used to fill in the dynamic parameters
* of the resource's URL
* @param {SelectItemOptions} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
selectAnotherItem: (params: ItemOrListParameters, actionCreatorOptions?: SelectItemOptions) => AnyAction;
/**
* Redux action creator used for deselecting a selected resource item
* @param {ItemOrListParameters|ItemOrListParameters[]} params A string or object that is serialized and used to fill in the dynamic parameters
* of the resource's URL
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
deselectItem: (params: ItemOrListParameters) => AnyAction;
/**
* Redux action creator used for clearing all of the selected resource items
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearSelectedItems: () => AnyAction;
}
export interface ResourcesActionCreatorDictionary<T> extends StandardResourcesActionCreatorDictionary<T> {
[key: string]: any;
}
export interface StandardSingularResourceActionCreatorDictionary<T> {
/**
* Redux action creator used for fetching a single resource item from a fetch RESTful API endpoint
* @param {ItemOrListParameters} params A string or object that is serialized and used to fill in the dynamic parameters
* of the resource's URL
* @param {RemoteActionCreatorOptionsWithMetadata} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {ThunkAction} Function to call to dispatch an action
*/
fetchItem: (params?: ItemOrListParameters, actionCreatorOptions?: RemoteActionCreatorOptionsWithMetadata<T>) => ThunkAction<void, any, any, AnyAction>;
/**
* Redux action creator used for adding a new resource item to the Redux store WITHOUT sending it to a remote API
* (yet). This action is used for storing a new resource item locally before actually creating it
* (which sends the new attributes to the remote API).
* @param {ItemOrListParameters | Object} paramsOrValues The first argument which can either a string or object that is serialized
* and used to fill in the dynamic parameters of the resource's URL (params) or the new attribute values
* to merge into the exist ones of the new resource item, or to use to create the resource item for the
* first time.
* @param {Object| ActionCreatorOptions} valuesOrActionCreatorOptions Either be the values used by the action creator, or addition
* options passed to the action creator when it is called.
* @param {Object} [optionalActionCreatorOptions=undefined] The optional additional options passed to the action controller.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
newItem: (paramsOrValues: ItemOrListParameters | T, valuesOrActionCreatorOptions?: T | ActionCreatorOptions<T>, optionalActionCreatorOptions?: ActionCreatorOptions<T>) => AnyAction;
/**
* Redux action creator used for clearing the new resource.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearNewItem: () => AnyAction;
/**
* Redux action creator used for editing the attributes of a new resource item (one that hasn't been saved to
* a remote API yet). This action is used for editing a resource item locally (perhaps across
* @param {ItemOrListParameters | Object} paramsOrValues The first argument which can either be a string or object
* that is serialized and used to fill in the dynamic parameters of the resource's URL (params) or the new
* attribute values to merge into the exist ones of the new resource* multiple stages or screens) before actually saving it (which sends the new attributes to the remote API).
* @param {Object} valuesOrActionCreatorOptions The new attribute values to merge into the exist ones of the resource item.
* @param {ActionCreatorOptions} [optionalActionCreatorOptions=undefined] The optional additional options passed to the action controller.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
editNewItem: (paramsOrValues: ItemOrListParameters | T, valuesOrActionCreatorOptions?: T | ActionCreatorOptions<T>, optionalActionCreatorOptions?: ActionCreatorOptions<T>) => AnyAction;
/**
* Redux action creator used for sending a CREATE request to a RESTful API endpoint
* @param {ItemOrListParameters | Object} paramsOrValues The first argument which can either a string
* or object that is serialized and used to fill in the dynamic parameters of the resource's URL
* (params) or the attribute values to use to create the resource.
* @param {Object|CreateItemActionCreatorOptions} valuesOrActionCreatorOptions Either be the values used by the action creator, or addition
* options passed to the action creator when it is called.
* @param {CreateItemActionCreatorOptions} [optionalActionCreatorOptions=undefined] The optional additional options passed to the action controller.
* @returns {ThunkAction} Function to call to dispatch an action
*/
createItem: (paramsOrValues: ItemOrListParameters | T, valuesOrActionCreatorOptions?: T | CreateItemActionCreatorOptions<T>, optionalActionCreatorOptions?: CreateItemActionCreatorOptions<T>) => ThunkAction<void, any, any, AnyAction>;
/**
* Redux action creator used for updating the attributes of a resource item WITHOUT sending those updated
* attributes to a remote API (yet). This action is used for editing a resource item locally (perhaps across
* multiple stages or screens) before actually updating it (which sends the new attributes to the remote API).
* @param {ItemOrListParameters} params A string or object that is serialized and used to fill in
* the dynamic parameters of the resource's URL
* @param {Object} valuesOrActionCreatorOptions The new attribute values to merge into the exist ones of the resource item.
* @param {ActionCreatorOptions} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
editItem: (paramsOrValues: ItemOrListParameters | T, valuesOrActionCreatorOptions?: T, optionalActionCreatorOptions?: ActionCreatorOptions<T>) => AnyAction;
/**
* Redux action creator used for updating the attributes of a new or existing resource item WITHOUT sending those updated
* attributes to a remote API (yet). This action is used for editing a resource item locally (perhaps across
* multiple stages or screens) before actually updating it (which sends the new attributes to the remote API).
* @param {ItemOrListParameters} paramsOrValues Either a string or object that is serialized and used to fill
* in the dynamic parameters of the resource's URL, or the new attribute values.
* @param {Object} values The new attribute values to merge into the exist ones of the resource item.
* @param {ActionCreatorOptions} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
editNewOrExistingItem: (paramsOrValues: ItemOrListParameters, valuesOrActionCreatorOptions?: T, optionalActionCreatorOptions?: ActionCreatorOptions<T>) => AnyAction;
/**
* Redux action creator used for clearing the new resource.
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearItemEdit: () => AnyAction;
/**
* Redux action creator used for sending an UPDATE request to a RESTful API endpoint
* @param {ItemOrListParameters} paramsOrValues Either a string or object that is serialized and used to
* fill in the dynamic parameters of the resource's URL, or new attribute values
* @param {Object} valuesOrActionCreatorOptions The attribute values to use to update the resource
* @param {UpdateItemActionCreatorOptions} [actionCreatorOptions={}] The options passed to the action creator when it is called.
* @returns {ThunkAction} Function to call to dispatch an action
*/
updateItem: (paramsOrValues: ItemOrListParameters, valuesOrActionCreatorOptions?: T, actionCreatorOptions?: UpdateItemActionCreatorOptions<T>) => ThunkAction<void, any, any, AnyAction>;
/**
* Redux action creator used for destroying a resource item by making a DELETE request to a RESTful API endpoint
* @param {ItemOrListParameters} paramsOrActionCreatorOptions A string or object that is serialized and used to fill in
* the dynamic parameters of the resource's URL
* @param {DestroyItemActionCreatorOptions} [actionCreatorOptions={}] The options passed to the action
* creator when it is called.
* @returns {ThunkAction} Function to call to dispatch an action
*/
destroyItem: (paramsOrActionCreatorOptions?: ItemOrListParameters | DestroyItemActionCreatorOptions<T>, actionCreatorOptions?: DestroyItemActionCreatorOptions<T>) => ThunkAction<void, any, any, AnyAction>;
/**
* Redux action creator used for clearing an item from the store
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearItem: () => AnyAction;
/**
* Redux action creator used for resetting a resource back to empty
* @returns {AnyAction} Action Object that will be passed to the reducers to update the Redux state
*/
clearResource: () => AnyAction;
}
export interface SingularResourceActionCreatorDictionary<T> extends StandardSingularResourceActionCreatorDictionary<T> {
[key: string]: any;
}
interface ActionAndActionCreatorSharedOptions<T> {
/**
* The request configuration object to be passed to the fetch method, or the new XMLHttpRequest object,
* when the progress option is used.
*/
request?: Object;
}
export interface SelectItemOptions {
/**
* The value to store with the selection. By default it's the value, true, but can be any contextually
* significant value.
*/
value?: any
}
export interface ActionCreatorOptions<T> extends ActionAndActionCreatorSharedOptions<T>{
}
export interface RemoteActionCreatorOptions<T> extends ActionCreatorOptions<T> {
/**
* Whether to ignore any outstanding requests with the same URL and make the request again, anyway
*/
forceFetch?: boolean | ((list: ResourcesList<T>) => boolean) | ((item: ResourcesItem<T>) => boolean) ;
}
export interface RemoteActionCreatorOptionsWithMetadata<T> extends RemoteActionCreatorOptions<T> {
/**
* An object of attributes and values that describe the list's metadata. It can be used for
* containing information like page numbers, limits, offsets and includes for lists and types
* for items (previews, or the complete set of attributes of an item).
*/
metadata?: Object;
}
export interface FetchListActionCreatorOptions<T> extends RemoteActionCreatorOptionsWithMetadata<T> {
/**
* Defines the metadata of each item in the list (the metadata is applied to the list).
*/
itemsMetadata?: Object
}
export interface UpdateItemActionCreatorOptions<T> extends RemoteActionCreatorOptionsWithMetadata<T> {
/**
* The values of the resource item being updated, to allow more efficiently updating associated
* items.
*/
previousValues?: T;
}
/**
* Function responsible for merging a new item into a list of existing ones by returning the list new item
* keys in the correct order
*/
export interface ListPositionsMerger<T> { (existingItems: Array<ResourcesItem<T>>, newItem: ResourcesItem<T>): string[] }
/**
* Function responsible for sorting list of existing items by returning the list's item keys in the correct
* order
*/
export interface ListPositionsSorter<T> { (existingItems: Array<ResourcesItem<T>>): string[] }
export type MergerAndListParameterTuple<T> = [Array<ItemOrListParameters>, ListPositionsMerger<T>];
export type SorterAndListParameterTuple<T> = [Array<ItemOrListParameters>, ListPositionsSorter<T>];
export interface ListOperations<T> {
/**
* A An array of list keys to push the new item to the end of.
*/
push?: Array<ItemOrListParameters>;
/**
* A An array of list keys to add the new item to the beginning of.
*/
unshift?: Array<ItemOrListParameters>;
/**
* An array of list keys for which to clear (invalidate). This is useful for when you know the item
* that was just created is likely to appear in a list, but you don't know where, so you need to
* re-retrieve the whole list from the server.
*/
invalidate?: Array<ItemOrListParameters>;
/**
* An array of tuples where the first element is an array of list keys and the second is a merger
* function that accepts an array of items in their current order, and the new item, as arguments.
*/
merge?: Array<MergerAndListParameterTuple<T>>;
/**
* An array of tuples where the first element is an array of list keys and the second is a sorter
* function that accepts an array of items in their current order.
*/
sort?: Array<SorterAndListParameterTuple<T>>;
}
export interface CreateItemActionCreatorOptions<T> extends RemoteActionCreatorOptionsWithMetadata<T>, ListOperations<T> {
}
export interface DestroyItemActionCreatorOptions<T> extends RemoteActionCreatorOptions<T> {
/**
* The values of the resource item being destroyed, to allow more efficiently updating associated
* items.
*/
previousValues?: T;
}
interface ResourceDefinitionCommon<T> {
/**
* Mapping between RESTful action names and constant Redux Action names
*/
actions: ActionDictionary;
/**
* Reducer function that will accept the resource's current state and an action and return the new
* resource state
*/
reducers: Reducer;
/**
* Function that returns the new item of a resource type
*/
getNewItem: GetSingularResourceItemFunction<T>;
/**
* Function that returns a particular item of a resource type or initializes it to the specified values
*/
getOrInitializeNewItem: GetOrInitializeItemFunction<T>;
/**
* Creates a new item if it does not exist in the store, or has a status of NEW, otherwise updates it
@param currentState The current resource Redux store state
* @param paramsOrValues The second argument which can either be a string
* or object that is serialized and used to fill in the dynamic parameters of the resource's URL
* (params), or the attribute values to use to create or update the resource.
* @param valuesOrActionCreatorOptions Either be the values used
* by the action creator, or additional options passed to the action creator when it is called.
* @param optionalActionCreatorOptions The additional options passed to the action controller.
* @returns {ThunkAction} Function to call to save or update the resource item
*/
saveItem: (currentState: ResourcesReduxState<T>, paramsOrValues: ItemOrListParameters | T, valuesOrActionCreatorOptions?: T | CreateItemActionCreatorOptions<T>, optionalActionCreatorOptions?: CreateItemActionCreatorOptions<T>) => ThunkAction<void, any, any, AnyAction>;
}
export interface ResourcesDefinition<T> extends ResourceDefinitionCommon<T>, ResourcesActionCreatorDictionary<T>{
/**
* Dictionary of ActionCreatorFunctions indexed by their ActionCreatorName
*/
actionCreators: ResourcesActionCreatorDictionary<T>;
/**
* Function that returns a particular item of a resource type or calls the fetch action creator if it's
* not available in the store
*/
getOrFetchItem: GetOrFetchItemFunction<T>;
/**
* Function that returns a particular list of a resource type or calls the fetch action creator if it's
* not available in the store
*/
getOrFetchList: GetOrFetchListFunction<T>;
/**
* Function that returns a particular list of resources
*/
getList: GetListFunction<T>;
/**
* Function that returns a particular item of a resource type
*/
getItem: GetItemFunction<T>;
/**
* First attempts to retrieve an exiting item using the provided params and then falls back to trying to
* get the new item
*/
getNewOrExistingItem: GetItemFunction<T>;
/**
* Function to build the initial resource state
*/
buildInitialState: (items: Array<T>) => InitialResourceStateBuilder<T>;
}
export interface SingularResourceDefinition<T> extends ResourceDefinitionCommon<T>, SingularResourceActionCreatorDictionary<T>{
/**
* Dictionary of ActionCreatorFunctions indexed by their ActionCreatorName
*/
actionCreators: SingularResourceActionCreatorDictionary<T>;
/**
* Function that returns a particular item of a resource type or calls the fetch action creator if it's
* not available in the store
*/
getOrFetchItem: GetOrFetchSingularResourceItemFunction<T>;
/**
* Function that returns a particular item of a resource type
*/
getItem: GetSingularResourceItemFunction<T>;
/**
* Function to build the initial resource state
*/
buildInitialState: (items: T) => InitialResourceStateBuilder<T>;
}
/**
* A Mapping between the name of an associated resource, and its definition.
*/
export type AssociationOptions<T> = {
/**
* Name of the attribute that stores the id or ids of the current resource on the associated one. If
* unspecified, the `as` attribute (or the resource's `name` value) are appended with the suffix of `id`.
*/
foreignKey?: string;
/**
* If a foreign key is not specified, this association name is used with a suffix of `id` to derive
* the foreign key
*/
as?: string;
/**
* key The key to use as the foreign key on this resource, to refer to the associated resource. If not