@data-client/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +71 -0
- package/dist/index.js +1643 -0
- package/dist/index.umd.min.js +1 -0
- package/dist/next.js +461 -0
- package/dist/package.json +1 -0
- package/legacy/actionTypes.js +12 -0
- package/legacy/compatibleActions.js +2 -0
- package/legacy/controller/BaseController.js +289 -0
- package/legacy/controller/Controller.js +20 -0
- package/legacy/controller/createFetch.js +42 -0
- package/legacy/controller/createInvalidate.js +12 -0
- package/legacy/controller/createInvalidateAll.js +8 -0
- package/legacy/controller/createOptimistic.js +33 -0
- package/legacy/controller/createReceive.js +36 -0
- package/legacy/controller/createReset.js +8 -0
- package/legacy/controller/createSubscription.js +30 -0
- package/legacy/controller/types.js +2 -0
- package/legacy/endpoint/index.js +2 -0
- package/legacy/endpoint/shapes.js +2 -0
- package/legacy/endpoint/types.js +2 -0
- package/legacy/fsa.js +2 -0
- package/legacy/index.js +22 -0
- package/legacy/internal.js +4 -0
- package/legacy/legacyActions.js +2 -0
- package/legacy/manager/ConnectionListener.js +2 -0
- package/legacy/manager/DefaultConnectionListener.js +40 -0
- package/legacy/manager/DevtoolsManager.js +73 -0
- package/legacy/manager/LogoutManager.js +34 -0
- package/legacy/manager/NetworkManager.js +291 -0
- package/legacy/manager/PollingSubscription.js +159 -0
- package/legacy/manager/SubscriptionManager.js +117 -0
- package/legacy/manager/applyManager.js +23 -0
- package/legacy/manager/devtoolsTypes.js +2 -0
- package/legacy/manager/index.js +6 -0
- package/legacy/middlewareTypes.js +2 -0
- package/legacy/newActions.js +2 -0
- package/legacy/next/Controller.js +24 -0
- package/legacy/next/index.js +3 -0
- package/legacy/previousActions.js +2 -0
- package/legacy/state/RIC.js +3 -0
- package/legacy/state/applyUpdatersToResults.js +4 -0
- package/legacy/state/legacy-actions/createFetch.js +62 -0
- package/legacy/state/legacy-actions/createReceive.js +37 -0
- package/legacy/state/legacy-actions/createReceiveError.js +28 -0
- package/legacy/state/legacy-actions/index.js +4 -0
- package/legacy/state/reducer/createReducer.js +54 -0
- package/legacy/state/reducer/fetchReducer.js +32 -0
- package/legacy/state/reducer/invalidateReducer.js +28 -0
- package/legacy/state/reducer/setReducer.js +113 -0
- package/legacy/state/reducerInstance.js +9 -0
- package/legacy/state/selectMeta.js +4 -0
- package/legacy/types.js +8 -0
- package/lib/actionTypes.d.ts +11 -0
- package/lib/actionTypes.d.ts.map +1 -0
- package/lib/actionTypes.js +12 -0
- package/lib/compatibleActions.d.ts +47 -0
- package/lib/compatibleActions.d.ts.map +1 -0
- package/lib/compatibleActions.js +2 -0
- package/lib/controller/BaseController.d.ts +128 -0
- package/lib/controller/BaseController.d.ts.map +1 -0
- package/lib/controller/BaseController.js +289 -0
- package/lib/controller/Controller.d.ts +14 -0
- package/lib/controller/Controller.d.ts.map +1 -0
- package/lib/controller/Controller.js +20 -0
- package/lib/controller/createFetch.d.ts +12 -0
- package/lib/controller/createFetch.d.ts.map +1 -0
- package/lib/controller/createFetch.js +42 -0
- package/lib/controller/createInvalidate.d.ts +6 -0
- package/lib/controller/createInvalidate.d.ts.map +1 -0
- package/lib/controller/createInvalidate.js +12 -0
- package/lib/controller/createInvalidateAll.d.ts +3 -0
- package/lib/controller/createInvalidateAll.d.ts.map +1 -0
- package/lib/controller/createInvalidateAll.js +8 -0
- package/lib/controller/createOptimistic.d.ts +10 -0
- package/lib/controller/createOptimistic.d.ts.map +1 -0
- package/lib/controller/createOptimistic.js +33 -0
- package/lib/controller/createReceive.d.ts +20 -0
- package/lib/controller/createReceive.d.ts.map +1 -0
- package/lib/controller/createReceive.js +36 -0
- package/lib/controller/createReset.d.ts +3 -0
- package/lib/controller/createReset.d.ts.map +1 -0
- package/lib/controller/createReset.js +8 -0
- package/lib/controller/createSubscription.d.ts +9 -0
- package/lib/controller/createSubscription.d.ts.map +1 -0
- package/lib/controller/createSubscription.js +30 -0
- package/lib/controller/types.d.ts +6 -0
- package/lib/controller/types.d.ts.map +1 -0
- package/lib/controller/types.js +2 -0
- package/lib/endpoint/index.d.ts +3 -0
- package/lib/endpoint/index.d.ts.map +1 -0
- package/lib/endpoint/index.js +2 -0
- package/lib/endpoint/shapes.d.ts +25 -0
- package/lib/endpoint/shapes.d.ts.map +1 -0
- package/lib/endpoint/shapes.js +2 -0
- package/lib/endpoint/types.d.ts +45 -0
- package/lib/endpoint/types.d.ts.map +1 -0
- package/lib/endpoint/types.js +2 -0
- package/lib/fsa.d.ts +41 -0
- package/lib/fsa.d.ts.map +1 -0
- package/lib/fsa.js +2 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +22 -0
- package/lib/internal.d.ts +4 -0
- package/lib/internal.d.ts.map +1 -0
- package/lib/internal.js +4 -0
- package/lib/legacyActions.d.ts +92 -0
- package/lib/legacyActions.d.ts.map +1 -0
- package/lib/legacyActions.js +2 -0
- package/lib/manager/ConnectionListener.d.ts +8 -0
- package/lib/manager/ConnectionListener.d.ts.map +1 -0
- package/lib/manager/ConnectionListener.js +2 -0
- package/lib/manager/DefaultConnectionListener.d.ts +20 -0
- package/lib/manager/DefaultConnectionListener.d.ts.map +1 -0
- package/lib/manager/DefaultConnectionListener.js +40 -0
- package/lib/manager/DevtoolsManager.d.ts +24 -0
- package/lib/manager/DevtoolsManager.d.ts.map +1 -0
- package/lib/manager/DevtoolsManager.js +74 -0
- package/lib/manager/LogoutManager.d.ts +25 -0
- package/lib/manager/LogoutManager.d.ts.map +1 -0
- package/lib/manager/LogoutManager.js +34 -0
- package/lib/manager/NetworkManager.d.ts +82 -0
- package/lib/manager/NetworkManager.d.ts.map +1 -0
- package/lib/manager/NetworkManager.js +295 -0
- package/lib/manager/PollingSubscription.d.ts +45 -0
- package/lib/manager/PollingSubscription.d.ts.map +1 -0
- package/lib/manager/PollingSubscription.js +159 -0
- package/lib/manager/SubscriptionManager.d.ts +55 -0
- package/lib/manager/SubscriptionManager.d.ts.map +1 -0
- package/lib/manager/SubscriptionManager.js +117 -0
- package/lib/manager/applyManager.d.ts +10 -0
- package/lib/manager/applyManager.d.ts.map +1 -0
- package/lib/manager/applyManager.js +23 -0
- package/lib/manager/devtoolsTypes.d.ts +205 -0
- package/lib/manager/devtoolsTypes.d.ts.map +1 -0
- package/lib/manager/devtoolsTypes.js +2 -0
- package/lib/manager/index.d.ts +8 -0
- package/lib/manager/index.d.ts.map +1 -0
- package/lib/manager/index.js +6 -0
- package/lib/middlewareTypes.d.ts +18 -0
- package/lib/middlewareTypes.d.ts.map +1 -0
- package/lib/middlewareTypes.js +2 -0
- package/lib/newActions.d.ts +85 -0
- package/lib/newActions.d.ts.map +1 -0
- package/lib/newActions.js +2 -0
- package/lib/next/Controller.d.ts +14 -0
- package/lib/next/Controller.d.ts.map +1 -0
- package/lib/next/Controller.js +24 -0
- package/lib/next/index.d.ts +3 -0
- package/lib/next/index.d.ts.map +1 -0
- package/lib/next/index.js +3 -0
- package/lib/previousActions.d.ts +91 -0
- package/lib/previousActions.d.ts.map +1 -0
- package/lib/previousActions.js +2 -0
- package/lib/state/RIC.d.ts +2 -0
- package/lib/state/RIC.js +3 -0
- package/lib/state/applyUpdatersToResults.d.ts +13 -0
- package/lib/state/applyUpdatersToResults.d.ts.map +1 -0
- package/lib/state/applyUpdatersToResults.js +7 -0
- package/lib/state/legacy-actions/createFetch.d.ts +19 -0
- package/lib/state/legacy-actions/createFetch.d.ts.map +1 -0
- package/lib/state/legacy-actions/createFetch.js +62 -0
- package/lib/state/legacy-actions/createReceive.d.ts +14 -0
- package/lib/state/legacy-actions/createReceive.d.ts.map +1 -0
- package/lib/state/legacy-actions/createReceive.js +37 -0
- package/lib/state/legacy-actions/createReceiveError.d.ts +9 -0
- package/lib/state/legacy-actions/createReceiveError.d.ts.map +1 -0
- package/lib/state/legacy-actions/createReceiveError.js +28 -0
- package/lib/state/legacy-actions/index.d.ts +4 -0
- package/lib/state/legacy-actions/index.d.ts.map +1 -0
- package/lib/state/legacy-actions/index.js +4 -0
- package/lib/state/reducer/createReducer.d.ts +7 -0
- package/lib/state/reducer/createReducer.d.ts.map +1 -0
- package/lib/state/reducer/createReducer.js +55 -0
- package/lib/state/reducer/fetchReducer.d.ts +4 -0
- package/lib/state/reducer/fetchReducer.d.ts.map +1 -0
- package/lib/state/reducer/fetchReducer.js +34 -0
- package/lib/state/reducer/invalidateReducer.d.ts +37 -0
- package/lib/state/reducer/invalidateReducer.d.ts.map +1 -0
- package/lib/state/reducer/invalidateReducer.js +34 -0
- package/lib/state/reducer/setReducer.d.ts +40 -0
- package/lib/state/reducer/setReducer.d.ts.map +1 -0
- package/lib/state/reducer/setReducer.js +119 -0
- package/lib/state/reducerInstance.d.ts +7 -0
- package/lib/state/reducerInstance.d.ts.map +1 -0
- package/lib/state/reducerInstance.js +9 -0
- package/lib/state/selectMeta.d.ts +3 -0
- package/lib/state/selectMeta.d.ts.map +1 -0
- package/lib/state/selectMeta.js +4 -0
- package/lib/types.d.ts +71 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +8 -0
- package/node.mjs +1 -0
- package/package.json +127 -0
- package/src/actionTypes.ts +11 -0
- package/src/compatibleActions.ts +96 -0
- package/src/controller/BaseController.ts +508 -0
- package/src/controller/Controller.ts +32 -0
- package/src/controller/__tests__/Controller.ts +29 -0
- package/src/controller/__tests__/__snapshots__/getResponse.ts.snap +35 -0
- package/src/controller/__tests__/getResponse.ts +182 -0
- package/src/controller/createFetch.ts +54 -0
- package/src/controller/createInvalidate.ts +16 -0
- package/src/controller/createInvalidateAll.ts +11 -0
- package/src/controller/createOptimistic.ts +47 -0
- package/src/controller/createReceive.ts +85 -0
- package/src/controller/createReset.ts +9 -0
- package/src/controller/createSubscription.ts +39 -0
- package/src/controller/types.ts +22 -0
- package/src/endpoint/index.ts +14 -0
- package/src/endpoint/shapes.ts +53 -0
- package/src/endpoint/types.ts +72 -0
- package/src/fsa.ts +99 -0
- package/src/index.ts +61 -0
- package/src/internal.ts +3 -0
- package/src/legacyActions.ts +163 -0
- package/src/manager/ConnectionListener.ts +7 -0
- package/src/manager/DefaultConnectionListener.ts +54 -0
- package/src/manager/DevtoolsManager.ts +99 -0
- package/src/manager/LogoutManager.ts +57 -0
- package/src/manager/NetworkManager.ts +346 -0
- package/src/manager/PollingSubscription.ts +190 -0
- package/src/manager/SubscriptionManager.ts +156 -0
- package/src/manager/__tests__/__snapshots__/pollingSubscription-endpoint.ts.snap +49 -0
- package/src/manager/__tests__/__snapshots__/pollingSubscription.ts.snap +43 -0
- package/src/manager/__tests__/logoutManager.ts +112 -0
- package/src/manager/__tests__/manager.ts +44 -0
- package/src/manager/__tests__/networkManager-legacy.ts +394 -0
- package/src/manager/__tests__/networkManager.ts +426 -0
- package/src/manager/__tests__/pollingSubscription-endpoint.ts +423 -0
- package/src/manager/__tests__/pollingSubscription.ts +313 -0
- package/src/manager/__tests__/subscriptionManager.ts +208 -0
- package/src/manager/applyManager.ts +33 -0
- package/src/manager/devtoolsTypes.ts +210 -0
- package/src/manager/index.ts +7 -0
- package/src/middlewareTypes.ts +49 -0
- package/src/newActions.ts +140 -0
- package/src/next/Controller.ts +39 -0
- package/src/next/index.ts +2 -0
- package/src/package.json +1 -0
- package/src/previousActions.ts +159 -0
- package/src/state/RIC.d.ts +2 -0
- package/src/state/RIC.js +5 -0
- package/src/state/__tests__/RIC.web.ts +16 -0
- package/src/state/__tests__/__snapshots__/reducer.ts.snap +56 -0
- package/src/state/__tests__/applyUpdatersToResults.ts +40 -0
- package/src/state/__tests__/reducer.ts +868 -0
- package/src/state/applyUpdatersToResults.ts +29 -0
- package/src/state/legacy-actions/createFetch.ts +95 -0
- package/src/state/legacy-actions/createReceive.ts +68 -0
- package/src/state/legacy-actions/createReceiveError.ts +43 -0
- package/src/state/legacy-actions/index.ts +3 -0
- package/src/state/reducer/createReducer.ts +80 -0
- package/src/state/reducer/fetchReducer.ts +48 -0
- package/src/state/reducer/invalidateReducer.ts +39 -0
- package/src/state/reducer/setReducer.ts +157 -0
- package/src/state/reducerInstance.ts +14 -0
- package/src/state/selectMeta.ts +8 -0
- package/src/types.ts +125 -0
- package/ts3.4/actionTypes.d.ts +11 -0
- package/ts3.4/compatibleActions.d.ts +47 -0
- package/ts3.4/controller/BaseController.d.ts +170 -0
- package/ts3.4/controller/Controller.d.ts +14 -0
- package/ts3.4/controller/createFetch.d.ts +14 -0
- package/ts3.4/controller/createInvalidate.d.ts +8 -0
- package/ts3.4/controller/createInvalidateAll.d.ts +3 -0
- package/ts3.4/controller/createOptimistic.d.ts +12 -0
- package/ts3.4/controller/createReceive.d.ts +24 -0
- package/ts3.4/controller/createReset.d.ts +3 -0
- package/ts3.4/controller/createSubscription.d.ts +13 -0
- package/ts3.4/controller/types.d.ts +6 -0
- package/ts3.4/endpoint/index.d.ts +3 -0
- package/ts3.4/endpoint/shapes.d.ts +25 -0
- package/ts3.4/endpoint/types.d.ts +45 -0
- package/ts3.4/fsa.d.ts +41 -0
- package/ts3.4/index.d.ts +22 -0
- package/ts3.4/internal.d.ts +4 -0
- package/ts3.4/legacyActions.d.ts +95 -0
- package/ts3.4/manager/ConnectionListener.d.ts +8 -0
- package/ts3.4/manager/DefaultConnectionListener.d.ts +20 -0
- package/ts3.4/manager/DevtoolsManager.d.ts +24 -0
- package/ts3.4/manager/LogoutManager.d.ts +25 -0
- package/ts3.4/manager/NetworkManager.d.ts +82 -0
- package/ts3.4/manager/PollingSubscription.d.ts +45 -0
- package/ts3.4/manager/SubscriptionManager.d.ts +55 -0
- package/ts3.4/manager/applyManager.d.ts +10 -0
- package/ts3.4/manager/devtoolsTypes.d.ts +205 -0
- package/ts3.4/manager/index.d.ts +8 -0
- package/ts3.4/middlewareTypes.d.ts +18 -0
- package/ts3.4/newActions.d.ts +88 -0
- package/ts3.4/next/Controller.d.ts +14 -0
- package/ts3.4/next/index.d.ts +3 -0
- package/ts3.4/previousActions.d.ts +94 -0
- package/ts3.4/state/RIC.d.ts +2 -0
- package/ts3.4/state/applyUpdatersToResults.d.ts +13 -0
- package/ts3.4/state/legacy-actions/createFetch.d.ts +19 -0
- package/ts3.4/state/legacy-actions/createReceive.d.ts +14 -0
- package/ts3.4/state/legacy-actions/createReceiveError.d.ts +9 -0
- package/ts3.4/state/legacy-actions/index.d.ts +4 -0
- package/ts3.4/state/reducer/createReducer.d.ts +7 -0
- package/ts3.4/state/reducer/fetchReducer.d.ts +4 -0
- package/ts3.4/state/reducer/invalidateReducer.d.ts +37 -0
- package/ts3.4/state/reducer/setReducer.d.ts +40 -0
- package/ts3.4/state/reducerInstance.d.ts +7 -0
- package/ts3.4/state/selectMeta.d.ts +3 -0
- package/ts3.4/types.d.ts +73 -0
- package/typescript.svg +8 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EndpointInterface,
|
|
3
|
+
NormalizedIndex,
|
|
4
|
+
Schema,
|
|
5
|
+
} from '@data-client/normalizr';
|
|
6
|
+
import type {
|
|
7
|
+
UpdateFunction,
|
|
8
|
+
AbstractInstanceType,
|
|
9
|
+
} from '@data-client/normalizr';
|
|
10
|
+
import type { ErrorTypes } from '@data-client/normalizr';
|
|
11
|
+
|
|
12
|
+
import { RECEIVE_TYPE } from './actionTypes.js';
|
|
13
|
+
import {
|
|
14
|
+
CompatibleFetchAction,
|
|
15
|
+
CompatibleReceiveAction,
|
|
16
|
+
CompatibleSubscribeAction,
|
|
17
|
+
CompatibleUnsubscribeAction,
|
|
18
|
+
} from './compatibleActions.js';
|
|
19
|
+
import { EndpointUpdateFunction } from './controller/types.js';
|
|
20
|
+
import * as legacyActions from './legacyActions.js';
|
|
21
|
+
import { Dispatch, Middleware, MiddlewareAPI } from './middlewareTypes.js';
|
|
22
|
+
import * as newActions from './newActions.js';
|
|
23
|
+
import * as previousActions from './previousActions.js';
|
|
24
|
+
|
|
25
|
+
export type { AbstractInstanceType, UpdateFunction };
|
|
26
|
+
|
|
27
|
+
export type ReceiveTypes = typeof RECEIVE_TYPE;
|
|
28
|
+
|
|
29
|
+
export type PK = string;
|
|
30
|
+
|
|
31
|
+
export interface State<T> {
|
|
32
|
+
readonly entities: {
|
|
33
|
+
readonly [entityKey: string]: { readonly [pk: string]: T } | undefined;
|
|
34
|
+
};
|
|
35
|
+
readonly indexes: NormalizedIndex;
|
|
36
|
+
readonly results: { readonly [key: string]: unknown | PK[] | PK | undefined };
|
|
37
|
+
readonly meta: {
|
|
38
|
+
readonly [key: string]: {
|
|
39
|
+
readonly date: number;
|
|
40
|
+
readonly error?: ErrorTypes;
|
|
41
|
+
readonly expiresAt: number;
|
|
42
|
+
readonly prevExpiresAt?: number;
|
|
43
|
+
readonly invalidated?: boolean;
|
|
44
|
+
readonly errorPolicy?: 'hard' | 'soft' | undefined;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
readonly entityMeta: {
|
|
48
|
+
readonly [entityKey: string]: {
|
|
49
|
+
readonly [pk: string]: {
|
|
50
|
+
readonly date: number;
|
|
51
|
+
readonly expiresAt: number;
|
|
52
|
+
readonly fetchedAt: number;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
readonly optimistic: (
|
|
57
|
+
| previousActions.ReceiveAction
|
|
58
|
+
| previousActions.OptimisticAction
|
|
59
|
+
)[];
|
|
60
|
+
readonly lastReset: Date | number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export * as legacyActions from './legacyActions.js';
|
|
64
|
+
export * as newActions from './newActions.js';
|
|
65
|
+
export type { SetAction } from './newActions.js';
|
|
66
|
+
|
|
67
|
+
/* maintain backwards compatibility */
|
|
68
|
+
/* TODO: switch to only include newActions in future */
|
|
69
|
+
export type OptimisticAction<
|
|
70
|
+
E extends EndpointInterface & {
|
|
71
|
+
update?: EndpointUpdateFunction<E>;
|
|
72
|
+
} = EndpointInterface & {
|
|
73
|
+
update?: EndpointUpdateFunction<EndpointInterface>;
|
|
74
|
+
},
|
|
75
|
+
> = newActions.OptimisticAction<E>;
|
|
76
|
+
export type InvalidateAction = newActions.InvalidateAction;
|
|
77
|
+
export type ResetAction = newActions.ResetAction | legacyActions.ResetAction;
|
|
78
|
+
export type GCAction = newActions.GCAction;
|
|
79
|
+
export type FetchAction<
|
|
80
|
+
Payload extends object | string | number | null =
|
|
81
|
+
| object
|
|
82
|
+
| string
|
|
83
|
+
| number
|
|
84
|
+
| null,
|
|
85
|
+
S extends Schema | undefined = any,
|
|
86
|
+
> = CompatibleFetchAction | legacyActions.FetchAction<Payload, S>;
|
|
87
|
+
export type ReceiveAction<
|
|
88
|
+
Payload extends object | string | number | null =
|
|
89
|
+
| object
|
|
90
|
+
| string
|
|
91
|
+
| number
|
|
92
|
+
| null,
|
|
93
|
+
S extends Schema | undefined = any,
|
|
94
|
+
> = CompatibleReceiveAction | legacyActions.ReceiveAction<Payload, S>;
|
|
95
|
+
export type SubscribeAction =
|
|
96
|
+
| CompatibleSubscribeAction
|
|
97
|
+
| legacyActions.SubscribeAction;
|
|
98
|
+
export type UnsubscribeAction =
|
|
99
|
+
| CompatibleUnsubscribeAction
|
|
100
|
+
| legacyActions.UnsubscribeAction;
|
|
101
|
+
|
|
102
|
+
export type ResponseActions = ReceiveAction;
|
|
103
|
+
|
|
104
|
+
// put other actions here in union
|
|
105
|
+
export type OldActionTypes = previousActions.ActionTypes;
|
|
106
|
+
|
|
107
|
+
export type CombinedActionTypes =
|
|
108
|
+
| OptimisticAction
|
|
109
|
+
| InvalidateAction
|
|
110
|
+
| ResetAction
|
|
111
|
+
| GCAction
|
|
112
|
+
| FetchAction
|
|
113
|
+
| ReceiveAction
|
|
114
|
+
| SubscribeAction
|
|
115
|
+
| UnsubscribeAction;
|
|
116
|
+
|
|
117
|
+
export type ActionTypes = CombinedActionTypes;
|
|
118
|
+
|
|
119
|
+
export interface Manager<Actions = CombinedActionTypes> {
|
|
120
|
+
getMiddleware(): Middleware<Actions>;
|
|
121
|
+
cleanup(): void;
|
|
122
|
+
init?: (state: State<any>) => void;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type { Dispatch, Middleware, MiddlewareAPI };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const FETCH_TYPE: "rest-hooks/fetch";
|
|
2
|
+
export declare const RECEIVE_TYPE: "rest-hooks/receive";
|
|
3
|
+
export declare const SET_TYPE: "rest-hooks/receive";
|
|
4
|
+
export declare const OPTIMISTIC_TYPE: "rest-hooks/optimistic";
|
|
5
|
+
export declare const RESET_TYPE: "rest-hooks/reset";
|
|
6
|
+
export declare const SUBSCRIBE_TYPE: "rest-hooks/subscribe";
|
|
7
|
+
export declare const UNSUBSCRIBE_TYPE: "rest-hook/unsubscribe";
|
|
8
|
+
export declare const INVALIDATE_TYPE: "rest-hooks/invalidate";
|
|
9
|
+
export declare const INVALIDATEALL_TYPE: "rest-hooks/invalidateall";
|
|
10
|
+
export declare const GC_TYPE: "rest-hooks/gc";
|
|
11
|
+
//# sourceMappingURL=actionTypes.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { EndpointExtraOptions, EndpointInterface, Schema } from '@data-client/normalizr';
|
|
2
|
+
import { FetchAction, FetchMeta, GCAction, InvalidateAction, OptimisticAction, ReceiveActionError, ReceiveActionSuccess, ReceiveMeta, ResetAction, SubscribeAction, UnsubscribeAction } from './newActions.js';
|
|
3
|
+
export interface CompatibleFetchMeta extends FetchMeta {
|
|
4
|
+
key: string;
|
|
5
|
+
schema?: Schema;
|
|
6
|
+
type: 'mutate' | 'read';
|
|
7
|
+
update?: (result: any, ...args: any) => Record<string, (...args: any) => any>;
|
|
8
|
+
options?: EndpointExtraOptions;
|
|
9
|
+
optimisticResponse?: {};
|
|
10
|
+
}
|
|
11
|
+
export interface CompatibleFetchAction<E extends EndpointInterface = EndpointInterface> extends FetchAction<E> {
|
|
12
|
+
meta: CompatibleFetchMeta;
|
|
13
|
+
}
|
|
14
|
+
export interface CompatibleReceiveMeta extends ReceiveMeta {
|
|
15
|
+
key: string;
|
|
16
|
+
schema?: any;
|
|
17
|
+
update?: (result: any, ...args: any) => Record<string, (...args: any) => any>;
|
|
18
|
+
errorPolicy?: (error: any) => 'hard' | 'soft' | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface CompatibleReceiveActionSuccess<E extends EndpointInterface = EndpointInterface> extends ReceiveActionSuccess<E> {
|
|
21
|
+
meta: CompatibleReceiveMeta;
|
|
22
|
+
payload: any;
|
|
23
|
+
}
|
|
24
|
+
export interface CompatibleReceiveActionError<E extends EndpointInterface = EndpointInterface> extends ReceiveActionError<E> {
|
|
25
|
+
meta: CompatibleReceiveMeta;
|
|
26
|
+
payload: any;
|
|
27
|
+
}
|
|
28
|
+
export type CompatibleReceiveAction<E extends EndpointInterface = EndpointInterface> = CompatibleReceiveActionSuccess<E> | CompatibleReceiveActionError<E>;
|
|
29
|
+
export interface CompatibleSubscribeAction<E extends EndpointInterface = EndpointInterface> extends SubscribeAction<E> {
|
|
30
|
+
meta: {
|
|
31
|
+
args: readonly any[];
|
|
32
|
+
schema: Schema | undefined;
|
|
33
|
+
fetch: () => Promise<any>;
|
|
34
|
+
key: string;
|
|
35
|
+
options: EndpointExtraOptions | undefined;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface CompatibleUnsubscribeAction<E extends EndpointInterface = EndpointInterface> extends UnsubscribeAction<E> {
|
|
39
|
+
meta: {
|
|
40
|
+
args: readonly any[];
|
|
41
|
+
key: string;
|
|
42
|
+
options: EndpointExtraOptions | undefined;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export { OptimisticAction, InvalidateAction, ResetAction, GCAction, } from './newActions.js';
|
|
46
|
+
export type CompatibleActionTypes = CompatibleFetchAction | OptimisticAction | CompatibleReceiveAction | CompatibleSubscribeAction | CompatibleUnsubscribeAction | InvalidateAction | ResetAction | GCAction;
|
|
47
|
+
//# sourceMappingURL=compatibleActions.d.ts.map
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { ErrorTypes, SnapshotInterface, DenormalizeCache, Schema } from '@data-client/normalizr';
|
|
2
|
+
import { ExpiryStatus, EndpointInterface, FetchFunction, DenormalizeNullable } from '@data-client/normalizr';
|
|
3
|
+
import { EndpointUpdateFunction } from './types.js';
|
|
4
|
+
import { CombinedActionTypes, State } from '../types.js';
|
|
5
|
+
export type GenericDispatch = (value: any) => Promise<void>;
|
|
6
|
+
export type CompatibleDispatch = (value: CombinedActionTypes) => Promise<void>;
|
|
7
|
+
interface ConstructorProps<D extends GenericDispatch = CompatibleDispatch> {
|
|
8
|
+
dispatch?: D;
|
|
9
|
+
getState?: () => State<unknown>;
|
|
10
|
+
globalCache?: DenormalizeCache;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Imperative control of Rest Hooks store
|
|
14
|
+
* @see https://resthooks.io/docs/api/Controller
|
|
15
|
+
*/
|
|
16
|
+
export default class Controller<D extends GenericDispatch = CompatibleDispatch> {
|
|
17
|
+
/**
|
|
18
|
+
* Dispatches an action to Rest Hooks reducer.
|
|
19
|
+
*
|
|
20
|
+
* @see https://resthooks.io/docs/api/Controller#dispatch
|
|
21
|
+
*/
|
|
22
|
+
readonly dispatch: D;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the latest state snapshot that is fully committed.
|
|
25
|
+
*
|
|
26
|
+
* This can be useful for imperative use-cases like event handlers.
|
|
27
|
+
* This should *not* be used to render; instead useSuspense() or useCache()
|
|
28
|
+
* @see https://resthooks.io/docs/api/Controller#getState
|
|
29
|
+
*/
|
|
30
|
+
readonly getState: () => State<unknown>;
|
|
31
|
+
readonly globalCache: DenormalizeCache;
|
|
32
|
+
constructor({ dispatch, getState, globalCache, }?: ConstructorProps<D>);
|
|
33
|
+
/*************** Action Dispatchers ***************/
|
|
34
|
+
/**
|
|
35
|
+
* Forces refetching and suspense on useSuspense with the same Endpoint and parameters.
|
|
36
|
+
* @see https://resthooks.io/docs/api/Controller#invalidate
|
|
37
|
+
*/
|
|
38
|
+
invalidate: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined>>(endpoint: E, ...args: readonly [
|
|
39
|
+
...Parameters<E>
|
|
40
|
+
] | readonly [
|
|
41
|
+
null
|
|
42
|
+
]) => Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Forces refetching and suspense on useSuspense on all matching endpoint result keys.
|
|
45
|
+
* @see https://resthooks.io/docs/api/Controller#invalidateAll
|
|
46
|
+
*/
|
|
47
|
+
invalidateAll: (options: {
|
|
48
|
+
testKey: (key: string) => boolean;
|
|
49
|
+
}) => Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Resets the entire Rest Hooks cache. All inflight requests will not resolve.
|
|
52
|
+
* @see https://resthooks.io/docs/api/Controller#resetEntireStore
|
|
53
|
+
*/
|
|
54
|
+
resetEntireStore: () => Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Stores response in cache for given Endpoint and args.
|
|
57
|
+
* @see https://resthooks.io/docs/api/Controller#set
|
|
58
|
+
*/
|
|
59
|
+
setResponse: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
|
|
60
|
+
update?: EndpointUpdateFunction<E> | undefined;
|
|
61
|
+
}>(endpoint: E, ...rest: readonly [
|
|
62
|
+
...Parameters<E>,
|
|
63
|
+
any
|
|
64
|
+
]) => Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Another name for setResponse
|
|
67
|
+
* @see https://resthooks.io/docs/api/Controller#setResponse
|
|
68
|
+
*/
|
|
69
|
+
receive: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
|
|
70
|
+
update?: EndpointUpdateFunction<E> | undefined;
|
|
71
|
+
}>(endpoint: E, ...rest: readonly [
|
|
72
|
+
...Parameters<E>,
|
|
73
|
+
any
|
|
74
|
+
]) => Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Stores the result of Endpoint and args as the error provided.
|
|
77
|
+
* @see https://resthooks.io/docs/api/Controller#setError
|
|
78
|
+
*/
|
|
79
|
+
setError: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
|
|
80
|
+
update?: EndpointUpdateFunction<E> | undefined;
|
|
81
|
+
}>(endpoint: E, ...rest: readonly [
|
|
82
|
+
...Parameters<E>,
|
|
83
|
+
Error
|
|
84
|
+
]) => Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Another name for setError
|
|
87
|
+
* @see https://resthooks.io/docs/api/Controller#setError
|
|
88
|
+
*/
|
|
89
|
+
receiveError: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
|
|
90
|
+
update?: EndpointUpdateFunction<E> | undefined;
|
|
91
|
+
}>(endpoint: E, ...rest: readonly [
|
|
92
|
+
...Parameters<E>,
|
|
93
|
+
Error
|
|
94
|
+
]) => Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Resolves an inflight fetch. `fetchedAt` should `fetch`'s `createdAt`
|
|
97
|
+
* @see https://resthooks.io/docs/api/Controller#resolve
|
|
98
|
+
*/
|
|
99
|
+
resolve: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
|
|
100
|
+
update?: EndpointUpdateFunction<E> | undefined;
|
|
101
|
+
}>(endpoint: E, meta: {
|
|
102
|
+
args: readonly [
|
|
103
|
+
...Parameters<E>
|
|
104
|
+
];
|
|
105
|
+
response: Error;
|
|
106
|
+
fetchedAt: number;
|
|
107
|
+
error: true;
|
|
108
|
+
} | {
|
|
109
|
+
args: readonly [
|
|
110
|
+
...Parameters<E>
|
|
111
|
+
];
|
|
112
|
+
response: any;
|
|
113
|
+
fetchedAt: number;
|
|
114
|
+
error?: false | undefined;
|
|
115
|
+
}) => Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Marks a new subscription to a given Endpoint.
|
|
118
|
+
* @see https://resthooks.io/docs/api/Controller#subscribe
|
|
119
|
+
*/
|
|
120
|
+
subscribe: <E extends EndpointInterface<FetchFunction, Schema | undefined, false | undefined>>(endpoint: E, ...args: readonly [
|
|
121
|
+
null
|
|
122
|
+
] | readonly [
|
|
123
|
+
...Parameters<E>
|
|
124
|
+
]) => Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Marks completion of subscription to a given Endpoint.
|
|
127
|
+
* @see https://resthooks.io/docs/api/Controller#unsubscribe
|
|
128
|
+
*/
|
|
129
|
+
unsubscribe: <E extends EndpointInterface<FetchFunction, Schema | undefined, false | undefined>>(endpoint: E, ...args: readonly [
|
|
130
|
+
null
|
|
131
|
+
] | readonly [
|
|
132
|
+
...Parameters<E>
|
|
133
|
+
]) => Promise<void>;
|
|
134
|
+
/*************** More ***************/
|
|
135
|
+
/**
|
|
136
|
+
* Gets a snapshot (https://resthooks.io/docs/api/Snapshot)
|
|
137
|
+
* @see https://resthooks.io/docs/api/Controller#snapshot
|
|
138
|
+
*/
|
|
139
|
+
snapshot: (state: State<unknown>, fetchedAt?: number) => SnapshotInterface;
|
|
140
|
+
/**
|
|
141
|
+
* Gets the error, if any, for a given endpoint. Returns undefined for no errors.
|
|
142
|
+
* @see https://resthooks.io/docs/api/Controller#getError
|
|
143
|
+
*/
|
|
144
|
+
getError: <E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined>, "key">, Args extends readonly [
|
|
145
|
+
null
|
|
146
|
+
] | readonly [
|
|
147
|
+
...Parameters<E["key"]>
|
|
148
|
+
]>(endpoint: E, ...rest: [
|
|
149
|
+
...Args,
|
|
150
|
+
State<unknown>
|
|
151
|
+
]) => ErrorTypes | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
|
|
154
|
+
* @see https://resthooks.io/docs/api/Controller#getResponse
|
|
155
|
+
*/
|
|
156
|
+
getResponse: <E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined>, "schema" | "key" | "invalidIfStale">, Args extends readonly [
|
|
157
|
+
null
|
|
158
|
+
] | readonly [
|
|
159
|
+
...Parameters<E["key"]>
|
|
160
|
+
]>(endpoint: E, ...rest: [
|
|
161
|
+
...Args,
|
|
162
|
+
State<unknown>
|
|
163
|
+
]) => {
|
|
164
|
+
data: DenormalizeNullable<E["schema"]>;
|
|
165
|
+
expiryStatus: ExpiryStatus;
|
|
166
|
+
expiresAt: number;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
export { ErrorTypes };
|
|
170
|
+
//# sourceMappingURL=BaseController.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EndpointInterface } from '@data-client/normalizr';
|
|
2
|
+
import BaseController, { CompatibleDispatch, GenericDispatch } from './BaseController.js';
|
|
3
|
+
import { EndpointUpdateFunction } from './types.js';
|
|
4
|
+
export default class Controller<D extends GenericDispatch = CompatibleDispatch> extends BaseController<D> {
|
|
5
|
+
/**
|
|
6
|
+
* Fetches the endpoint with given args, updating the Rest Hooks cache with the response or error upon completion.
|
|
7
|
+
* @see https://resthooks.io/docs/api/Controller#fetch
|
|
8
|
+
*/
|
|
9
|
+
fetch: <E extends EndpointInterface<import("@data-client/normalizr").FetchFunction, import("@data-client/normalizr").Schema | undefined, boolean | undefined> & {
|
|
10
|
+
update?: EndpointUpdateFunction<E> | undefined;
|
|
11
|
+
}>(endpoint: E, ...args_0: Parameters<E>) => ReturnType<E>;
|
|
12
|
+
}
|
|
13
|
+
export * from './BaseController.js';
|
|
14
|
+
//# sourceMappingURL=Controller.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EndpointInterface } from '@data-client/normalizr';
|
|
2
|
+
import { EndpointUpdateFunction } from './types.js';
|
|
3
|
+
import { CompatibleFetchAction } from '../compatibleActions.js';
|
|
4
|
+
/**
|
|
5
|
+
* Requesting a fetch to begin
|
|
6
|
+
*/
|
|
7
|
+
export default function createFetch<E extends EndpointInterface & {
|
|
8
|
+
update?: EndpointUpdateFunction<E>;
|
|
9
|
+
}>(endpoint: E, { args }: {
|
|
10
|
+
args: readonly [
|
|
11
|
+
...Parameters<E>
|
|
12
|
+
];
|
|
13
|
+
}): CompatibleFetchAction<E>;
|
|
14
|
+
//# sourceMappingURL=createFetch.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EndpointInterface } from '@data-client/normalizr';
|
|
2
|
+
import { InvalidateAction } from '../newActions.js';
|
|
3
|
+
export default function createInvalidate<E extends EndpointInterface>(endpoint: E, { args }: {
|
|
4
|
+
args: readonly [
|
|
5
|
+
...Parameters<E>
|
|
6
|
+
];
|
|
7
|
+
}): InvalidateAction;
|
|
8
|
+
//# sourceMappingURL=createInvalidate.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EndpointInterface } from '@data-client/normalizr';
|
|
2
|
+
import { EndpointUpdateFunction } from './types.js';
|
|
3
|
+
import { OptimisticAction } from '../newActions.js';
|
|
4
|
+
export default function createOptimistic<E extends EndpointInterface & {
|
|
5
|
+
update?: EndpointUpdateFunction<E>;
|
|
6
|
+
}>(endpoint: E, { args, fetchedAt, }: {
|
|
7
|
+
args: readonly [
|
|
8
|
+
...Parameters<E>
|
|
9
|
+
];
|
|
10
|
+
fetchedAt: number;
|
|
11
|
+
}): OptimisticAction<E>;
|
|
12
|
+
//# sourceMappingURL=createOptimistic.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EndpointInterface, ResolveType } from '@data-client/normalizr';
|
|
2
|
+
import { EndpointUpdateFunction } from './types.js';
|
|
3
|
+
import { CompatibleReceiveAction } from '../compatibleActions.js';
|
|
4
|
+
export default function createReceive<E extends EndpointInterface & {
|
|
5
|
+
update?: EndpointUpdateFunction<E>;
|
|
6
|
+
}>(endpoint: E, options: {
|
|
7
|
+
args: readonly [
|
|
8
|
+
...Parameters<E>
|
|
9
|
+
];
|
|
10
|
+
response: Error;
|
|
11
|
+
fetchedAt?: number;
|
|
12
|
+
error: true;
|
|
13
|
+
}): CompatibleReceiveAction<E>;
|
|
14
|
+
export default function createReceive<E extends EndpointInterface & {
|
|
15
|
+
update?: EndpointUpdateFunction<E>;
|
|
16
|
+
}>(endpoint: E, options: {
|
|
17
|
+
args: readonly [
|
|
18
|
+
...Parameters<E>
|
|
19
|
+
];
|
|
20
|
+
response: ResolveType<E>;
|
|
21
|
+
fetchedAt?: number;
|
|
22
|
+
error?: false;
|
|
23
|
+
}): CompatibleReceiveAction<E>;
|
|
24
|
+
//# sourceMappingURL=createReceive.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EndpointInterface } from '@data-client/normalizr';
|
|
2
|
+
import { CompatibleSubscribeAction, CompatibleUnsubscribeAction } from '../compatibleActions.js';
|
|
3
|
+
export declare function createSubscription<E extends EndpointInterface>(endpoint: E, { args }: {
|
|
4
|
+
args: readonly [
|
|
5
|
+
...Parameters<E>
|
|
6
|
+
];
|
|
7
|
+
}): CompatibleSubscribeAction<E>;
|
|
8
|
+
export declare function createUnsubscription<E extends EndpointInterface>(endpoint: E, { args }: {
|
|
9
|
+
args: readonly [
|
|
10
|
+
...Parameters<E>
|
|
11
|
+
];
|
|
12
|
+
}): CompatibleUnsubscribeAction<E>;
|
|
13
|
+
//# sourceMappingURL=createSubscription.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Normalize, EndpointInterface, ResolveType } from '@data-client/normalizr';
|
|
2
|
+
export type ResultEntry<E extends EndpointInterface> = E['schema'] extends undefined | null ? ResolveType<E> : Normalize<E['schema']>;
|
|
3
|
+
export type EndpointUpdateFunction<Source extends EndpointInterface, Updaters extends Record<string, any> = Record<string, any>> = (source: ResultEntry<Source>, ...args: any) => {
|
|
4
|
+
[K in keyof Updaters]: (result: Updaters[K]) => Updaters[K];
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Schema, EndpointExtraOptions as FetchOptions } from '@data-client/normalizr';
|
|
2
|
+
/** Defines the shape of a network request */
|
|
3
|
+
export interface FetchShape<S extends Schema | undefined, Params extends Readonly<object> = Readonly<object>, Body extends Readonly<object | string> | void | unknown = Readonly<object | string> | undefined, Response = any> {
|
|
4
|
+
readonly type: 'read' | 'mutate' | 'delete';
|
|
5
|
+
fetch(params: Params, body?: Body): Promise<Response>;
|
|
6
|
+
getFetchKey(params: Params): string;
|
|
7
|
+
readonly schema: S;
|
|
8
|
+
readonly options?: FetchOptions;
|
|
9
|
+
}
|
|
10
|
+
/** To change values on the server */
|
|
11
|
+
export interface MutateShape<S extends Schema | undefined, Params extends Readonly<object> = Readonly<object>, Body extends Readonly<object | string> | void | unknown = Readonly<object | string> | undefined, Response extends object | string | number | boolean | null = any> extends FetchShape<S, Params, Body, Response> {
|
|
12
|
+
readonly type: 'mutate';
|
|
13
|
+
fetch(params: Params, body: Body): Promise<Response>;
|
|
14
|
+
}
|
|
15
|
+
/** Removes entities */
|
|
16
|
+
export interface DeleteShape<S extends Schema | undefined, Params extends Readonly<object> = Readonly<object>, Response extends object | string | number | boolean | null = any> extends FetchShape<S, Params, undefined, Response> {
|
|
17
|
+
readonly type: 'mutate';
|
|
18
|
+
fetch(params: Params, ...args: any): Promise<Response>;
|
|
19
|
+
}
|
|
20
|
+
/** For retrieval requests */
|
|
21
|
+
export interface ReadShape<S extends Schema | undefined, Params extends Readonly<object> = Readonly<object>, Response extends object | string | number | boolean | null = any> extends FetchShape<S, Params, undefined, Response> {
|
|
22
|
+
readonly type: 'read';
|
|
23
|
+
fetch(params: Params): Promise<Response>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=shapes.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Schema } from '@data-client/normalizr';
|
|
2
|
+
import { Denormalize } from '@data-client/normalizr';
|
|
3
|
+
import { FetchShape } from './shapes.js';
|
|
4
|
+
import { UpdateFunction } from '../types.js';
|
|
5
|
+
export type ResultShape<RS> = RS extends {
|
|
6
|
+
schema: infer U;
|
|
7
|
+
} ? U : never;
|
|
8
|
+
export type SelectReturn<RS> = RS extends {
|
|
9
|
+
select: (...args: any[]) => infer U;
|
|
10
|
+
} ? U : never;
|
|
11
|
+
export type AlwaysSelect<RS> = NonNullable<SelectReturn<RS>>;
|
|
12
|
+
export type ParamArg<RS> = RS extends {
|
|
13
|
+
getFetchKey: (params: infer U) => any;
|
|
14
|
+
} ? U : never;
|
|
15
|
+
export type BodyArg<RS> = RS extends {
|
|
16
|
+
fetch: (url: any, body: infer U) => any;
|
|
17
|
+
} ? U : never;
|
|
18
|
+
/** Sets a FetchShape's Param type.
|
|
19
|
+
* Useful to constrain acceptable params (second arg) in hooks like useResource().
|
|
20
|
+
*
|
|
21
|
+
* @param [Shape] FetchShape to act upon
|
|
22
|
+
* @param [Params] what to set the Params to
|
|
23
|
+
*/
|
|
24
|
+
export type SetShapeParams<Shape extends FetchShape<any, any, any>, Params extends Readonly<object>> = {
|
|
25
|
+
[K in keyof Shape]: Shape[K];
|
|
26
|
+
} & (Shape['fetch'] extends (first: any, ...rest: infer Args) => infer Return ? {
|
|
27
|
+
fetch: (first: Params, ...rest: Args) => Return;
|
|
28
|
+
} : never);
|
|
29
|
+
/** Get the Params type for a given Shape */
|
|
30
|
+
export type ParamsFromShape<S> = S extends {
|
|
31
|
+
fetch: (first: infer A, ...rest: any) => any;
|
|
32
|
+
} ? A : S extends {
|
|
33
|
+
getFetchKey: (first: infer A, ...rest: any) => any;
|
|
34
|
+
} ? A : never;
|
|
35
|
+
/** Get the Schema type for a given Shape */
|
|
36
|
+
export type SchemaFromShape<F extends FetchShape<Schema | undefined, any, any>> = F['schema'];
|
|
37
|
+
/** Get the Body type for a given Shape */
|
|
38
|
+
export type BodyFromShape<F extends FetchShape<any, any, any>> = Parameters<F['fetch']>[1];
|
|
39
|
+
export type OptimisticUpdateParams<SourceSchema extends Schema | undefined, DestShape extends FetchShape<any, any, any>> = [
|
|
40
|
+
DestShape,
|
|
41
|
+
ParamsFromShape<DestShape>,
|
|
42
|
+
UpdateFunction<SourceSchema, SchemaFromShape<DestShape>>
|
|
43
|
+
];
|
|
44
|
+
export type ReturnFromShape<S extends FetchShape<any, any, any>> = ReturnType<S['fetch']> extends unknown ? Promise<Denormalize<S['schema']>> : ReturnType<S['fetch']>;
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
package/ts3.4/fsa.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ErrorFluxStandardActionWithPayloadAndMeta, ErrorFluxStandardActionWithPayload, FSA } from 'flux-standard-action';
|
|
2
|
+
export type ErrorableFSAWithPayloadAndMeta<Type extends string = string, Payload = undefined, Meta = undefined, CustomError extends Error = Error> = ErrorFluxStandardActionWithPayloadAndMeta<Type, CustomError, Meta> | NoErrorFluxStandardActionWithPayloadAndMeta<Type, Payload, Meta>;
|
|
3
|
+
export type ErrorableFSAWithMeta<Type extends string = string, Payload = undefined, Meta = undefined, CustomError extends Error = Error> = ErrorFluxStandardActionWithPayloadAndMeta<Type, CustomError, Meta> | NoErrorFluxStandardActionWithMeta<Type, Payload, Meta>;
|
|
4
|
+
export type ErrorableFSAWithPayload<Type extends string = string, Payload = undefined, Meta = undefined, CustomError extends Error = Error> = ErrorFluxStandardActionWithPayload<Type, CustomError, Meta> | NoErrorFluxStandardActionWithPayload<Type, Payload, Meta>;
|
|
5
|
+
export interface NoErrorFluxStandardAction<Type extends string = string, Payload = undefined, Meta = undefined> extends FSA<Type, Payload, Meta> {
|
|
6
|
+
error?: false;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A Flux Standard action with a required payload property.
|
|
10
|
+
*/
|
|
11
|
+
export interface NoErrorFluxStandardActionWithPayload<Type extends string = string, Payload = undefined, Meta = undefined> extends NoErrorFluxStandardAction<Type, Payload, Meta> {
|
|
12
|
+
/**
|
|
13
|
+
* The required `payload` property MAY be any type of value.
|
|
14
|
+
* It represents the payload of the action.
|
|
15
|
+
* Any information about the action that is not the type or status of the action should be part of the `payload` field.
|
|
16
|
+
* By convention, if `error` is `true`, the `payload` SHOULD be an error object.
|
|
17
|
+
* This is akin to rejecting a promise with an error object.
|
|
18
|
+
*/
|
|
19
|
+
payload: Payload;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A Flux Standard action with a required metadata property.
|
|
23
|
+
*/
|
|
24
|
+
export interface NoErrorFluxStandardActionWithMeta<Type extends string = string, Payload = undefined, Meta = undefined> extends NoErrorFluxStandardAction<Type, Payload, Meta> {
|
|
25
|
+
/**
|
|
26
|
+
* The required `meta` property MAY be any type of value.
|
|
27
|
+
* It is intended for any extra information that is not part of the payload.
|
|
28
|
+
*/
|
|
29
|
+
meta: Meta;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A Flux Standard action with required payload and metadata properties.
|
|
33
|
+
*/
|
|
34
|
+
export type NoErrorFluxStandardActionWithPayloadAndMeta<Type extends string = string, Payload = undefined, Meta = undefined> = NoErrorFluxStandardActionWithPayload<Type, Payload, Meta> & NoErrorFluxStandardActionWithMeta<Type, Payload, Meta>;
|
|
35
|
+
/**
|
|
36
|
+
* A Flux Standard action with inferred requirements for the payload and metadata properties.
|
|
37
|
+
* The `payload` and `meta` properties will be required if the corresponding type argument
|
|
38
|
+
* if not the `undefined` type.
|
|
39
|
+
*/
|
|
40
|
+
export type NoErrorFluxStandardActionAuto<Type extends string = string, Payload = undefined, Meta = undefined> = Payload extends undefined ? Meta extends undefined ? NoErrorFluxStandardAction<Type, Payload, Meta> : NoErrorFluxStandardActionWithMeta<Type, Payload, Meta> : Meta extends undefined ? NoErrorFluxStandardActionWithPayload<Type, Payload, Meta> : NoErrorFluxStandardActionWithPayloadAndMeta<Type, Payload, Meta>;
|
|
41
|
+
//# sourceMappingURL=fsa.d.ts.map
|
package/ts3.4/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as __INTERNAL__1 from './internal.js';
|
|
2
|
+
export { __INTERNAL__1 as __INTERNAL__ };
|
|
3
|
+
export { NetworkError, UnknownError, ErrorTypes, Schema, EndpointInterface, EntityInterface, ResolveType, DenormalizeCache, DenormalizeNullable, Denormalize, Normalize, NormalizeNullable, FetchFunction, EndpointExtraOptions, } from '@data-client/normalizr';
|
|
4
|
+
export { ExpiryStatus } from '@data-client/normalizr';
|
|
5
|
+
export { default as NetworkManager, ResetError, } from './manager/NetworkManager.js';
|
|
6
|
+
export { default as createReducer, initialState, } from './state/reducer/createReducer.js';
|
|
7
|
+
export { default as reducer } from './state/reducerInstance.js';
|
|
8
|
+
export { default as applyManager } from './manager/applyManager.js';
|
|
9
|
+
export { default as Controller } from './controller/Controller.js';
|
|
10
|
+
export { CompatibleDispatch, GenericDispatch, } from './controller/Controller.js';
|
|
11
|
+
export { default as createFetch } from './controller/createFetch.js';
|
|
12
|
+
export { default as createReceive } from './controller/createReceive.js';
|
|
13
|
+
export * from './controller/types.js';
|
|
14
|
+
import * as legacyActions_1 from './state/legacy-actions/index.js';
|
|
15
|
+
export { legacyActions_1 as legacyActions };
|
|
16
|
+
import * as actionTypes_1 from './actionTypes.js';
|
|
17
|
+
export { actionTypes_1 as actionTypes };
|
|
18
|
+
export * from './types.js';
|
|
19
|
+
export { FetchShape, ReadShape, MutateShape, DeleteShape, } from './endpoint/shapes.js';
|
|
20
|
+
export { SetShapeParams, ParamsFromShape, BodyFromShape, ReturnFromShape, } from './endpoint/types.js';
|
|
21
|
+
export * from './manager/index.js';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|