@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/fsa.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ErrorFluxStandardActionWithPayloadAndMeta,
|
|
3
|
+
ErrorFluxStandardActionWithPayload,
|
|
4
|
+
FSA,
|
|
5
|
+
} from 'flux-standard-action';
|
|
6
|
+
|
|
7
|
+
export type ErrorableFSAWithPayloadAndMeta<
|
|
8
|
+
Type extends string = string,
|
|
9
|
+
Payload = undefined,
|
|
10
|
+
Meta = undefined,
|
|
11
|
+
CustomError extends Error = Error,
|
|
12
|
+
> =
|
|
13
|
+
| ErrorFluxStandardActionWithPayloadAndMeta<Type, CustomError, Meta>
|
|
14
|
+
| NoErrorFluxStandardActionWithPayloadAndMeta<Type, Payload, Meta>;
|
|
15
|
+
|
|
16
|
+
export type ErrorableFSAWithMeta<
|
|
17
|
+
Type extends string = string,
|
|
18
|
+
Payload = undefined,
|
|
19
|
+
Meta = undefined,
|
|
20
|
+
CustomError extends Error = Error,
|
|
21
|
+
> =
|
|
22
|
+
| ErrorFluxStandardActionWithPayloadAndMeta<Type, CustomError, Meta>
|
|
23
|
+
| NoErrorFluxStandardActionWithMeta<Type, Payload, Meta>;
|
|
24
|
+
|
|
25
|
+
export type ErrorableFSAWithPayload<
|
|
26
|
+
Type extends string = string,
|
|
27
|
+
Payload = undefined,
|
|
28
|
+
Meta = undefined,
|
|
29
|
+
CustomError extends Error = Error,
|
|
30
|
+
> =
|
|
31
|
+
| ErrorFluxStandardActionWithPayload<Type, CustomError, Meta>
|
|
32
|
+
| NoErrorFluxStandardActionWithPayload<Type, Payload, Meta>;
|
|
33
|
+
|
|
34
|
+
export interface NoErrorFluxStandardAction<
|
|
35
|
+
Type extends string = string,
|
|
36
|
+
Payload = undefined,
|
|
37
|
+
Meta = undefined,
|
|
38
|
+
> extends FSA<Type, Payload, Meta> {
|
|
39
|
+
error?: false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A Flux Standard action with a required payload property.
|
|
44
|
+
*/
|
|
45
|
+
export interface NoErrorFluxStandardActionWithPayload<
|
|
46
|
+
Type extends string = string,
|
|
47
|
+
Payload = undefined,
|
|
48
|
+
Meta = undefined,
|
|
49
|
+
> extends NoErrorFluxStandardAction<Type, Payload, Meta> {
|
|
50
|
+
/**
|
|
51
|
+
* The required `payload` property MAY be any type of value.
|
|
52
|
+
* It represents the payload of the action.
|
|
53
|
+
* Any information about the action that is not the type or status of the action should be part of the `payload` field.
|
|
54
|
+
* By convention, if `error` is `true`, the `payload` SHOULD be an error object.
|
|
55
|
+
* This is akin to rejecting a promise with an error object.
|
|
56
|
+
*/
|
|
57
|
+
payload: Payload;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A Flux Standard action with a required metadata property.
|
|
62
|
+
*/
|
|
63
|
+
export interface NoErrorFluxStandardActionWithMeta<
|
|
64
|
+
Type extends string = string,
|
|
65
|
+
Payload = undefined,
|
|
66
|
+
Meta = undefined,
|
|
67
|
+
> extends NoErrorFluxStandardAction<Type, Payload, Meta> {
|
|
68
|
+
/**
|
|
69
|
+
* The required `meta` property MAY be any type of value.
|
|
70
|
+
* It is intended for any extra information that is not part of the payload.
|
|
71
|
+
*/
|
|
72
|
+
meta: Meta;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A Flux Standard action with required payload and metadata properties.
|
|
76
|
+
*/
|
|
77
|
+
export type NoErrorFluxStandardActionWithPayloadAndMeta<
|
|
78
|
+
Type extends string = string,
|
|
79
|
+
Payload = undefined,
|
|
80
|
+
Meta = undefined,
|
|
81
|
+
> = NoErrorFluxStandardActionWithPayload<Type, Payload, Meta> &
|
|
82
|
+
NoErrorFluxStandardActionWithMeta<Type, Payload, Meta>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A Flux Standard action with inferred requirements for the payload and metadata properties.
|
|
86
|
+
* The `payload` and `meta` properties will be required if the corresponding type argument
|
|
87
|
+
* if not the `undefined` type.
|
|
88
|
+
*/
|
|
89
|
+
export type NoErrorFluxStandardActionAuto<
|
|
90
|
+
Type extends string = string,
|
|
91
|
+
Payload = undefined,
|
|
92
|
+
Meta = undefined,
|
|
93
|
+
> = Payload extends undefined
|
|
94
|
+
? Meta extends undefined
|
|
95
|
+
? NoErrorFluxStandardAction<Type, Payload, Meta>
|
|
96
|
+
: NoErrorFluxStandardActionWithMeta<Type, Payload, Meta>
|
|
97
|
+
: Meta extends undefined
|
|
98
|
+
? NoErrorFluxStandardActionWithPayload<Type, Payload, Meta>
|
|
99
|
+
: NoErrorFluxStandardActionWithPayloadAndMeta<Type, Payload, Meta>;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Object.hasOwn =
|
|
2
|
+
Object.hasOwn ||
|
|
3
|
+
/* istanbul ignore next */ function hasOwn(it, key) {
|
|
4
|
+
return Object.prototype.hasOwnProperty.call(it, key);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export * as __INTERNAL__ from './internal.js';
|
|
8
|
+
export type {
|
|
9
|
+
NetworkError,
|
|
10
|
+
UnknownError,
|
|
11
|
+
ErrorTypes,
|
|
12
|
+
Schema,
|
|
13
|
+
EndpointInterface,
|
|
14
|
+
EntityInterface,
|
|
15
|
+
ResolveType,
|
|
16
|
+
DenormalizeCache,
|
|
17
|
+
DenormalizeNullable,
|
|
18
|
+
Denormalize,
|
|
19
|
+
Normalize,
|
|
20
|
+
NormalizeNullable,
|
|
21
|
+
FetchFunction,
|
|
22
|
+
EndpointExtraOptions,
|
|
23
|
+
} from '@data-client/normalizr';
|
|
24
|
+
export { ExpiryStatus } from '@data-client/normalizr';
|
|
25
|
+
export {
|
|
26
|
+
default as NetworkManager,
|
|
27
|
+
ResetError,
|
|
28
|
+
} from './manager/NetworkManager.js';
|
|
29
|
+
export {
|
|
30
|
+
default as createReducer,
|
|
31
|
+
initialState,
|
|
32
|
+
} from './state/reducer/createReducer.js';
|
|
33
|
+
export { default as reducer } from './state/reducerInstance.js';
|
|
34
|
+
export { default as applyManager } from './manager/applyManager.js';
|
|
35
|
+
|
|
36
|
+
export { default as Controller } from './controller/Controller.js';
|
|
37
|
+
export type {
|
|
38
|
+
CompatibleDispatch,
|
|
39
|
+
GenericDispatch,
|
|
40
|
+
} from './controller/Controller.js';
|
|
41
|
+
export { default as createFetch } from './controller/createFetch.js';
|
|
42
|
+
export { default as createReceive } from './controller/createReceive.js';
|
|
43
|
+
|
|
44
|
+
export * from './controller/types.js';
|
|
45
|
+
export * as legacyActions from './state/legacy-actions/index.js';
|
|
46
|
+
export * as actionTypes from './actionTypes.js';
|
|
47
|
+
/* istanbul ignore next */
|
|
48
|
+
export * from './types.js';
|
|
49
|
+
export type {
|
|
50
|
+
FetchShape,
|
|
51
|
+
ReadShape,
|
|
52
|
+
MutateShape,
|
|
53
|
+
DeleteShape,
|
|
54
|
+
} from './endpoint/shapes.js';
|
|
55
|
+
export type {
|
|
56
|
+
SetShapeParams,
|
|
57
|
+
ParamsFromShape,
|
|
58
|
+
BodyFromShape,
|
|
59
|
+
ReturnFromShape,
|
|
60
|
+
} from './endpoint/types.js';
|
|
61
|
+
export * from './manager/index.js';
|
package/src/internal.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
UpdateFunction,
|
|
3
|
+
Schema,
|
|
4
|
+
EndpointExtraOptions,
|
|
5
|
+
EndpointInterface,
|
|
6
|
+
} from '@data-client/normalizr';
|
|
7
|
+
import { FSAWithPayloadAndMeta, FSAWithMeta } from 'flux-standard-action';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
RECEIVE_TYPE,
|
|
11
|
+
RESET_TYPE,
|
|
12
|
+
FETCH_TYPE,
|
|
13
|
+
SUBSCRIBE_TYPE,
|
|
14
|
+
UNSUBSCRIBE_TYPE,
|
|
15
|
+
INVALIDATE_TYPE,
|
|
16
|
+
GC_TYPE,
|
|
17
|
+
OPTIMISTIC_TYPE,
|
|
18
|
+
} from './actionTypes.js';
|
|
19
|
+
import type { EndpointUpdateFunction } from './controller/types.js';
|
|
20
|
+
import { FetchShape } from './endpoint/index.js';
|
|
21
|
+
import { ErrorableFSAWithPayloadAndMeta } from './fsa.js';
|
|
22
|
+
|
|
23
|
+
export interface ReceiveMeta<S extends Schema | undefined> {
|
|
24
|
+
schema?: S;
|
|
25
|
+
key: string;
|
|
26
|
+
args?: readonly any[];
|
|
27
|
+
updaters?: Record<string, UpdateFunction<S, any>>;
|
|
28
|
+
update?: (result: any, ...args: any) => Record<string, (...args: any) => any>;
|
|
29
|
+
fetchedAt?: number;
|
|
30
|
+
date: number;
|
|
31
|
+
expiresAt: number;
|
|
32
|
+
errorPolicy?: (error: any) => 'hard' | 'soft' | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type ReceiveAction<
|
|
36
|
+
Payload extends object | string | number | null =
|
|
37
|
+
| object
|
|
38
|
+
| string
|
|
39
|
+
| number
|
|
40
|
+
| null,
|
|
41
|
+
S extends Schema | undefined = any,
|
|
42
|
+
> = ErrorableFSAWithPayloadAndMeta<
|
|
43
|
+
typeof RECEIVE_TYPE,
|
|
44
|
+
Payload,
|
|
45
|
+
ReceiveMeta<S>
|
|
46
|
+
>;
|
|
47
|
+
|
|
48
|
+
export type OptimisticAction<
|
|
49
|
+
E extends EndpointInterface & {
|
|
50
|
+
update?: EndpointUpdateFunction<E>;
|
|
51
|
+
} = EndpointInterface & {
|
|
52
|
+
update?: EndpointUpdateFunction<EndpointInterface>;
|
|
53
|
+
},
|
|
54
|
+
> = {
|
|
55
|
+
type: typeof OPTIMISTIC_TYPE;
|
|
56
|
+
meta: {
|
|
57
|
+
schema: E['schema'];
|
|
58
|
+
key: string;
|
|
59
|
+
args: readonly any[];
|
|
60
|
+
update?: (
|
|
61
|
+
result: any,
|
|
62
|
+
...args: any
|
|
63
|
+
) => Record<string, (...args: any) => any>;
|
|
64
|
+
fetchedAt: number;
|
|
65
|
+
date: number;
|
|
66
|
+
expiresAt: number;
|
|
67
|
+
errorPolicy?: (error: any) => 'hard' | 'soft' | undefined;
|
|
68
|
+
};
|
|
69
|
+
endpoint: E;
|
|
70
|
+
error?: undefined;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export interface ResetAction {
|
|
74
|
+
type: typeof RESET_TYPE;
|
|
75
|
+
date: number | Date;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface FetchMeta<
|
|
79
|
+
Payload extends object | string | number | null =
|
|
80
|
+
| object
|
|
81
|
+
| string
|
|
82
|
+
| number
|
|
83
|
+
| null,
|
|
84
|
+
S extends Schema | undefined = any,
|
|
85
|
+
> {
|
|
86
|
+
type: FetchShape<any, any>['type'];
|
|
87
|
+
schema?: S;
|
|
88
|
+
key: string;
|
|
89
|
+
args?: readonly any[];
|
|
90
|
+
updaters?: Record<string, UpdateFunction<S, any>>;
|
|
91
|
+
update?: (result: any, ...args: any) => Record<string, (...args: any) => any>;
|
|
92
|
+
options?: EndpointExtraOptions;
|
|
93
|
+
throttle: boolean;
|
|
94
|
+
resolve: (value?: any | PromiseLike<any>) => void;
|
|
95
|
+
reject: (reason?: any) => void;
|
|
96
|
+
promise: PromiseLike<any>;
|
|
97
|
+
createdAt: number | Date;
|
|
98
|
+
optimisticResponse?: Payload;
|
|
99
|
+
// indicates whether network manager processed it
|
|
100
|
+
nm?: boolean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface FetchAction<
|
|
104
|
+
Payload extends object | string | number | null =
|
|
105
|
+
| object
|
|
106
|
+
| string
|
|
107
|
+
| number
|
|
108
|
+
| null,
|
|
109
|
+
S extends Schema | undefined = any,
|
|
110
|
+
> extends FSAWithPayloadAndMeta<
|
|
111
|
+
typeof FETCH_TYPE,
|
|
112
|
+
() => Promise<Payload>,
|
|
113
|
+
FetchMeta<any, any>
|
|
114
|
+
> {
|
|
115
|
+
meta: FetchMeta<Payload, S>;
|
|
116
|
+
endpoint?: undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface SubscribeAction
|
|
120
|
+
extends FSAWithMeta<typeof SUBSCRIBE_TYPE, undefined, any> {
|
|
121
|
+
meta: {
|
|
122
|
+
args?: readonly any[];
|
|
123
|
+
schema: Schema | undefined;
|
|
124
|
+
fetch: () => Promise<any>;
|
|
125
|
+
key: string;
|
|
126
|
+
options: EndpointExtraOptions | undefined;
|
|
127
|
+
};
|
|
128
|
+
endpoint?: undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface UnsubscribeAction
|
|
132
|
+
extends FSAWithMeta<typeof UNSUBSCRIBE_TYPE, undefined, any> {
|
|
133
|
+
meta: {
|
|
134
|
+
args?: readonly any[];
|
|
135
|
+
key: string;
|
|
136
|
+
options: EndpointExtraOptions | undefined;
|
|
137
|
+
};
|
|
138
|
+
endpoint?: undefined;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface InvalidateAction
|
|
142
|
+
extends FSAWithMeta<typeof INVALIDATE_TYPE, undefined, any> {
|
|
143
|
+
meta: {
|
|
144
|
+
key: string;
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface GCAction {
|
|
149
|
+
type: typeof GC_TYPE;
|
|
150
|
+
entities: [string, string][];
|
|
151
|
+
results: string[];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// put other actions here in union
|
|
155
|
+
export type ActionTypes =
|
|
156
|
+
| FetchAction
|
|
157
|
+
| OptimisticAction
|
|
158
|
+
| ReceiveAction
|
|
159
|
+
| SubscribeAction
|
|
160
|
+
| UnsubscribeAction
|
|
161
|
+
| InvalidateAction
|
|
162
|
+
| ResetAction
|
|
163
|
+
| GCAction;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export default interface ConnectionListener {
|
|
2
|
+
isOnline: () => boolean;
|
|
3
|
+
addOnlineListener: (handler: () => void) => void;
|
|
4
|
+
removeOnlineListener: (handler: () => void) => void;
|
|
5
|
+
addOfflineListener: (handler: () => void) => void;
|
|
6
|
+
removeOfflineListener: (handler: () => void) => void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import ConnectionListener from './ConnectionListener.js';
|
|
2
|
+
|
|
3
|
+
export class BrowserConnectionListener implements ConnectionListener {
|
|
4
|
+
isOnline() {
|
|
5
|
+
if (navigator.onLine !== undefined) {
|
|
6
|
+
return navigator.onLine;
|
|
7
|
+
}
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
addOnlineListener(handler: () => void) {
|
|
12
|
+
addEventListener('online', handler);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
removeOnlineListener(handler: () => void) {
|
|
16
|
+
removeEventListener('online', handler);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
addOfflineListener(handler: () => void) {
|
|
20
|
+
addEventListener('offline', handler);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
removeOfflineListener(handler: () => void) {
|
|
24
|
+
removeEventListener('offline', handler);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class AlwaysOnlineConnectionListener implements ConnectionListener {
|
|
29
|
+
isOnline() {
|
|
30
|
+
/* istanbul ignore next */
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
addOnlineListener() {}
|
|
35
|
+
|
|
36
|
+
removeOnlineListener() {}
|
|
37
|
+
|
|
38
|
+
addOfflineListener() {}
|
|
39
|
+
|
|
40
|
+
removeOfflineListener() {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let DefaultConnectionListener: { new (): ConnectionListener };
|
|
44
|
+
/* istanbul ignore if */
|
|
45
|
+
if (
|
|
46
|
+
typeof navigator !== 'undefined' &&
|
|
47
|
+
typeof addEventListener === 'function'
|
|
48
|
+
) {
|
|
49
|
+
DefaultConnectionListener = BrowserConnectionListener;
|
|
50
|
+
} else {
|
|
51
|
+
/* istanbul ignore next */
|
|
52
|
+
DefaultConnectionListener = AlwaysOnlineConnectionListener;
|
|
53
|
+
}
|
|
54
|
+
export default DefaultConnectionListener;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { DevToolsConfig } from './devtoolsTypes.js';
|
|
2
|
+
import type { Middleware } from './LogoutManager.js';
|
|
3
|
+
import createReducer from '../state/reducer/createReducer.js';
|
|
4
|
+
import type { Manager, State, ActionTypes } from '../types.js';
|
|
5
|
+
|
|
6
|
+
export type { DevToolsConfig };
|
|
7
|
+
|
|
8
|
+
const HASINTL = typeof Intl !== 'undefined';
|
|
9
|
+
const DEFAULT_CONFIG = {
|
|
10
|
+
name: `Rest Hooks: ${globalThis.document?.title}`,
|
|
11
|
+
autoPause: true,
|
|
12
|
+
serialize: {
|
|
13
|
+
options: undefined,
|
|
14
|
+
/* istanbul ignore next */
|
|
15
|
+
replacer: HASINTL
|
|
16
|
+
? (key: string | number | symbol, value: unknown) => {
|
|
17
|
+
if (
|
|
18
|
+
typeof value === 'number' &&
|
|
19
|
+
typeof key === 'string' &&
|
|
20
|
+
isFinite(value) &&
|
|
21
|
+
(key === 'date' || key.endsWith('At'))
|
|
22
|
+
) {
|
|
23
|
+
return Intl.DateTimeFormat('en-US', {
|
|
24
|
+
hour: 'numeric',
|
|
25
|
+
minute: 'numeric',
|
|
26
|
+
second: 'numeric',
|
|
27
|
+
fractionalSecondDigits: 3,
|
|
28
|
+
}).format(value);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
: undefined,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Integrates with https://github.com/reduxjs/redux-devtools
|
|
37
|
+
*
|
|
38
|
+
* Options: https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md
|
|
39
|
+
*
|
|
40
|
+
* @see https://resthooks.io/docs/api/DevToolsManager
|
|
41
|
+
*/
|
|
42
|
+
export default class DevToolsManager implements Manager {
|
|
43
|
+
protected declare middleware: Middleware;
|
|
44
|
+
protected declare devTools: undefined | any;
|
|
45
|
+
|
|
46
|
+
constructor(
|
|
47
|
+
config?: DevToolsConfig,
|
|
48
|
+
skipLogging?: (action: ActionTypes) => boolean,
|
|
49
|
+
) {
|
|
50
|
+
/* istanbul ignore next */
|
|
51
|
+
this.devTools =
|
|
52
|
+
typeof window !== 'undefined' &&
|
|
53
|
+
(window as any).__REDUX_DEVTOOLS_EXTENSION__ &&
|
|
54
|
+
(window as any).__REDUX_DEVTOOLS_EXTENSION__.connect({
|
|
55
|
+
...DEFAULT_CONFIG,
|
|
56
|
+
config,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/* istanbul ignore if */
|
|
60
|
+
/* istanbul ignore next */
|
|
61
|
+
if (this.devTools) {
|
|
62
|
+
this.middleware = controller => {
|
|
63
|
+
const reducer = createReducer(controller as any);
|
|
64
|
+
return next => action => {
|
|
65
|
+
const ret = next(action);
|
|
66
|
+
ret.then(() => {
|
|
67
|
+
if (skipLogging?.(action)) return;
|
|
68
|
+
const state = controller.getState();
|
|
69
|
+
this.devTools.send(
|
|
70
|
+
action,
|
|
71
|
+
state.optimistic.reduce(reducer, state),
|
|
72
|
+
undefined,
|
|
73
|
+
'REST_HOOKS',
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
return ret;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
} else {
|
|
80
|
+
this.middleware = () => next => action => next(action);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Called when initial state is ready */
|
|
85
|
+
init(state: State<any>) {
|
|
86
|
+
/* istanbul ignore if */
|
|
87
|
+
if (this.devTools) this.devTools.init(state);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Ensures all subscriptions are cleaned up. */
|
|
91
|
+
cleanup() {}
|
|
92
|
+
|
|
93
|
+
/** Attaches Manager to store
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
getMiddleware() {
|
|
97
|
+
return this.middleware;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SET_TYPE } from '../actionTypes.js';
|
|
2
|
+
import Controller from '../controller/Controller.js';
|
|
3
|
+
import { UnknownError } from '../index.js';
|
|
4
|
+
import type { CombinedActionTypes } from '../types.js';
|
|
5
|
+
import { Manager } from '../types.js';
|
|
6
|
+
|
|
7
|
+
/** Handling network unauthorized indicators like HTTP 401
|
|
8
|
+
*
|
|
9
|
+
* @see https://resthooks.io/docs/api/LogoutManager
|
|
10
|
+
*/
|
|
11
|
+
export default class LogoutManager implements Manager<CombinedActionTypes> {
|
|
12
|
+
protected declare middleware: Middleware;
|
|
13
|
+
|
|
14
|
+
constructor({ handleLogout, shouldLogout }: Props = {}) {
|
|
15
|
+
if (handleLogout) this.handleLogout = handleLogout;
|
|
16
|
+
if (shouldLogout) this.shouldLogout = shouldLogout;
|
|
17
|
+
this.middleware = controller => next => async action => {
|
|
18
|
+
await next(action);
|
|
19
|
+
if (
|
|
20
|
+
action.type === SET_TYPE &&
|
|
21
|
+
action.error &&
|
|
22
|
+
this.shouldLogout(action.payload)
|
|
23
|
+
) {
|
|
24
|
+
this.handleLogout(controller);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
cleanup() {}
|
|
30
|
+
|
|
31
|
+
getMiddleware() {
|
|
32
|
+
return this.middleware;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
protected shouldLogout(error: UnknownError) {
|
|
36
|
+
// 401 indicates reauthorization is needed
|
|
37
|
+
return error.status === 401;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
handleLogout(controller: Controller<Dispatch>) {
|
|
41
|
+
controller.resetEntireStore();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type Dispatch = (value: CombinedActionTypes) => Promise<void>;
|
|
46
|
+
|
|
47
|
+
// this further restricts the types to be future compatible
|
|
48
|
+
export type Middleware = <C extends Controller<Dispatch>>(
|
|
49
|
+
controller: C,
|
|
50
|
+
) => (next: C['dispatch']) => C['dispatch'];
|
|
51
|
+
|
|
52
|
+
type HandleLogout = (controller: Controller<Dispatch>) => void;
|
|
53
|
+
|
|
54
|
+
interface Props {
|
|
55
|
+
handleLogout?: HandleLogout;
|
|
56
|
+
shouldLogout?: (error: UnknownError) => boolean;
|
|
57
|
+
}
|