@data-client/core 0.9.7 → 0.11.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/README.md +24 -1
- package/dist/index.js +132 -96
- package/dist/index.umd.min.js +1 -1
- package/legacy/actionTypes.js +1 -1
- package/legacy/actions.js +1 -1
- package/legacy/controller/AbortOptimistic.js +2 -0
- package/legacy/controller/Controller.js +110 -78
- package/legacy/controller/createExpireAll.js +1 -1
- package/legacy/controller/createFetch.js +1 -1
- package/legacy/controller/createInvalidate.js +1 -1
- package/legacy/controller/createInvalidateAll.js +1 -1
- package/legacy/controller/createOptimistic.js +1 -1
- package/legacy/controller/createReset.js +1 -1
- package/legacy/controller/createSet.js +1 -1
- package/legacy/controller/createSubscription.js +1 -1
- package/legacy/controller/ensurePojo.js +2 -3
- package/legacy/controller/types.js +1 -1
- package/legacy/index.js +1 -1
- package/legacy/internal.js +2 -2
- package/legacy/manager/ConnectionListener.js +1 -1
- package/legacy/manager/DefaultConnectionListener.js +1 -1
- package/legacy/manager/DevtoolsManager.js +6 -2
- package/legacy/manager/LogoutManager.js +1 -1
- package/legacy/manager/NetworkManager.js +1 -1
- package/legacy/manager/PollingSubscription.js +1 -1
- package/legacy/manager/SubscriptionManager.js +1 -1
- package/legacy/manager/applyManager.js +1 -1
- package/legacy/manager/devtoolsTypes.js +1 -1
- package/legacy/manager/index.js +1 -1
- package/legacy/middlewareTypes.js +1 -1
- package/legacy/next/index.js +1 -1
- package/legacy/state/RIC.js +1 -1
- package/legacy/state/reducer/createReducer.js +6 -6
- package/legacy/state/reducer/expireReducer.js +1 -1
- package/legacy/state/reducer/fetchReducer.js +1 -1
- package/legacy/state/reducer/invalidateReducer.js +5 -5
- package/legacy/state/reducer/setReducer.js +7 -7
- package/legacy/state/selectMeta.js +1 -1
- package/legacy/types.js +1 -1
- package/lib/actionTypes.js +1 -1
- package/lib/actions.d.ts +1 -1
- package/lib/actions.d.ts.map +1 -1
- package/lib/actions.js +1 -1
- package/lib/controller/AbortOptimistic.d.ts +3 -0
- package/lib/controller/AbortOptimistic.d.ts.map +1 -0
- package/lib/controller/AbortOptimistic.js +2 -0
- package/lib/controller/Controller.d.ts +36 -11
- package/lib/controller/Controller.d.ts.map +1 -1
- package/lib/controller/Controller.js +110 -78
- package/lib/controller/createExpireAll.js +1 -1
- package/lib/controller/createFetch.js +1 -1
- package/lib/controller/createInvalidate.js +1 -1
- package/lib/controller/createInvalidateAll.js +1 -1
- package/lib/controller/createOptimistic.js +1 -1
- package/lib/controller/createReset.js +1 -1
- package/lib/controller/createSet.js +1 -1
- package/lib/controller/createSubscription.js +1 -1
- package/lib/controller/ensurePojo.d.ts.map +1 -1
- package/lib/controller/ensurePojo.js +2 -3
- package/lib/controller/types.d.ts.map +1 -1
- package/lib/controller/types.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/internal.d.ts +1 -1
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +2 -2
- package/lib/manager/ConnectionListener.js +1 -1
- package/lib/manager/DefaultConnectionListener.js +1 -1
- package/lib/manager/DevtoolsManager.d.ts +1 -0
- package/lib/manager/DevtoolsManager.d.ts.map +1 -1
- package/lib/manager/DevtoolsManager.js +6 -2
- package/lib/manager/LogoutManager.js +1 -1
- package/lib/manager/NetworkManager.js +1 -1
- package/lib/manager/PollingSubscription.js +1 -1
- package/lib/manager/SubscriptionManager.js +1 -1
- package/lib/manager/applyManager.js +1 -1
- package/lib/manager/devtoolsTypes.js +1 -1
- package/lib/manager/index.js +1 -1
- package/lib/middlewareTypes.d.ts.map +1 -1
- package/lib/middlewareTypes.js +1 -1
- package/lib/next/index.js +1 -1
- package/lib/state/RIC.d.ts.map +1 -1
- package/lib/state/RIC.js +1 -1
- package/lib/state/reducer/createReducer.js +6 -6
- package/lib/state/reducer/expireReducer.d.ts +1 -1
- package/lib/state/reducer/expireReducer.js +1 -1
- package/lib/state/reducer/fetchReducer.js +1 -1
- package/lib/state/reducer/invalidateReducer.d.ts +1 -1
- package/lib/state/reducer/invalidateReducer.js +6 -6
- package/lib/state/reducer/setReducer.d.ts.map +1 -1
- package/lib/state/reducer/setReducer.js +8 -8
- package/lib/state/selectMeta.js +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -1
- package/package.json +3 -3
- package/src/actions.ts +1 -1
- package/src/controller/AbortOptimistic.ts +1 -0
- package/src/controller/Controller.ts +215 -96
- package/src/controller/__tests__/Controller.ts +2 -4
- package/src/controller/__tests__/__snapshots__/get.ts.snap +120 -0
- package/src/controller/__tests__/get.ts +285 -0
- package/src/controller/__tests__/getResponse.ts +2 -2
- package/src/controller/createSet.ts +3 -2
- package/src/controller/ensurePojo.ts +6 -7
- package/src/controller/types.ts +2 -4
- package/src/index.ts +2 -1
- package/src/internal.ts +1 -1
- package/src/manager/DevtoolsManager.ts +8 -2
- package/src/manager/__tests__/subscriptionManager.ts +3 -2
- package/src/middlewareTypes.ts +4 -12
- package/src/state/RIC.ts +3 -4
- package/src/state/__tests__/__snapshots__/reducer.ts.snap +4 -4
- package/src/state/__tests__/reducer.ts +32 -34
- package/src/state/reducer/createReducer.ts +3 -3
- package/src/state/reducer/invalidateReducer.ts +4 -4
- package/src/state/reducer/setReducer.ts +10 -9
- package/src/types.ts +3 -1
- package/ts3.4/actions.d.ts +1 -1
- package/ts3.4/controller/AbortOptimistic.d.ts +3 -0
- package/ts3.4/controller/Controller.d.ts +47 -19
- package/ts3.4/index.d.ts +1 -1
- package/ts3.4/internal.d.ts +1 -1
- package/ts3.4/manager/DevtoolsManager.d.ts +1 -0
- package/ts3.4/state/reducer/expireReducer.d.ts +1 -1
- package/ts3.4/state/reducer/invalidateReducer.d.ts +1 -1
- package/ts3.4/types.d.ts +1 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { Entity, schema } from '@data-client/endpoint';
|
|
2
|
+
|
|
3
|
+
import { initialState } from '../../state/reducer/createReducer';
|
|
4
|
+
import Controller from '../Controller';
|
|
5
|
+
|
|
6
|
+
describe('Controller.get()', () => {
|
|
7
|
+
class Tacos extends Entity {
|
|
8
|
+
type = '';
|
|
9
|
+
id = '';
|
|
10
|
+
pk() {
|
|
11
|
+
return this.id;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const TacoList = new schema.Collection([Tacos]);
|
|
15
|
+
const entities = {
|
|
16
|
+
Tacos: {
|
|
17
|
+
1: { id: '1', type: 'foo' },
|
|
18
|
+
2: { id: '2', type: 'bar' },
|
|
19
|
+
},
|
|
20
|
+
[TacoList.key]: {
|
|
21
|
+
[TacoList.pk(undefined, undefined, '', [{ type: 'foo' }])]: ['1'],
|
|
22
|
+
[TacoList.pk(undefined, undefined, '', [{ type: 'bar' }])]: ['2'],
|
|
23
|
+
[TacoList.pk(undefined, undefined, '', [])]: ['1', '2'],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
it('query Entity based on pk', () => {
|
|
28
|
+
const controller = new Controller();
|
|
29
|
+
const state = {
|
|
30
|
+
...initialState,
|
|
31
|
+
entities,
|
|
32
|
+
};
|
|
33
|
+
const taco = controller.get(Tacos, { id: '1' }, state);
|
|
34
|
+
expect(taco).toBeDefined();
|
|
35
|
+
expect(taco).toBeInstanceOf(Tacos);
|
|
36
|
+
expect(taco).toMatchSnapshot();
|
|
37
|
+
const taco2 = controller.get(Tacos, { id: '2' }, state);
|
|
38
|
+
expect(taco2).toBeDefined();
|
|
39
|
+
expect(taco2).toBeInstanceOf(Tacos);
|
|
40
|
+
expect(taco2).not.toEqual(taco);
|
|
41
|
+
// should maintain referential equality
|
|
42
|
+
expect(taco).toBe(controller.get(Tacos, { id: '1' }, state));
|
|
43
|
+
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
() => controller.get(Tacos, { id: { bob: 5 } }, state);
|
|
46
|
+
// @ts-expect-error
|
|
47
|
+
expect(controller.get(Tacos, 5, state)).toBeUndefined();
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
() => controller.get(Tacos, { doesnotexist: 5 }, state);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('query Entity based on index', () => {
|
|
53
|
+
class User extends Entity {
|
|
54
|
+
id = '';
|
|
55
|
+
username = '';
|
|
56
|
+
|
|
57
|
+
pk() {
|
|
58
|
+
return this.id;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static indexes = ['username'] as const;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const controller = new Controller();
|
|
65
|
+
const state = {
|
|
66
|
+
...initialState,
|
|
67
|
+
entities: {
|
|
68
|
+
User: {
|
|
69
|
+
'1': { id: '1', username: 'bob' },
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
indexes: {
|
|
73
|
+
User: {
|
|
74
|
+
username: {
|
|
75
|
+
bob: '1',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const bob = controller.get(User, { username: 'bob' }, state);
|
|
82
|
+
expect(bob).toBeDefined();
|
|
83
|
+
expect(bob).toBeInstanceOf(User);
|
|
84
|
+
expect(bob).toMatchSnapshot();
|
|
85
|
+
// should be same as id lookup
|
|
86
|
+
expect(bob).toBe(controller.get(User, { id: '1' }, state));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('query Collection based on args', () => {
|
|
90
|
+
const controller = new Controller();
|
|
91
|
+
const state = {
|
|
92
|
+
...initialState,
|
|
93
|
+
entities,
|
|
94
|
+
};
|
|
95
|
+
const tacos = controller.get(TacoList, { type: 'foo' }, state);
|
|
96
|
+
expect(tacos).toBeDefined();
|
|
97
|
+
expect(tacos?.[0]).toBeInstanceOf(Tacos);
|
|
98
|
+
expect(tacos).toMatchSnapshot();
|
|
99
|
+
const tacosBars = controller.get(TacoList, { type: 'bar' }, state);
|
|
100
|
+
expect(tacosBars).toBeDefined();
|
|
101
|
+
expect(tacosBars?.[0]).toBeInstanceOf(Tacos);
|
|
102
|
+
expect(tacosBars).not.toEqual(tacos);
|
|
103
|
+
// should maintain referential equality
|
|
104
|
+
expect(tacos).toBe(controller.get(TacoList, { type: 'foo' }, state));
|
|
105
|
+
|
|
106
|
+
const allTacos = controller.get(TacoList, state);
|
|
107
|
+
expect(allTacos).toBeDefined();
|
|
108
|
+
expect(allTacos).toHaveLength(2);
|
|
109
|
+
expect(allTacos).toMatchSnapshot();
|
|
110
|
+
|
|
111
|
+
// @ts-expect-error
|
|
112
|
+
() => controller.get(TacoList, 5, state);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('query All', () => {
|
|
116
|
+
const controller = new Controller();
|
|
117
|
+
const state = {
|
|
118
|
+
...initialState,
|
|
119
|
+
entities,
|
|
120
|
+
};
|
|
121
|
+
const AllTacos = new schema.All(Tacos);
|
|
122
|
+
|
|
123
|
+
it('should get all entities', () => {
|
|
124
|
+
const allTacos = controller.get(AllTacos, state);
|
|
125
|
+
expect(allTacos).toBeDefined();
|
|
126
|
+
expect(allTacos).toHaveLength(2);
|
|
127
|
+
expect(allTacos).toMatchSnapshot();
|
|
128
|
+
|
|
129
|
+
// TODO: @ts-expect-error (we have a hack to make this not break other things now)
|
|
130
|
+
() => controller.get(AllTacos, 5, state);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('should maintain referential equality', () => {
|
|
134
|
+
const allTacos = controller.get(AllTacos, state);
|
|
135
|
+
expect(allTacos).toStrictEqual(controller.get(TacoList, state));
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should include new entities when added', () => {
|
|
139
|
+
controller.get(AllTacos, state);
|
|
140
|
+
const tacosWithExtra = controller.get(AllTacos, {
|
|
141
|
+
...state,
|
|
142
|
+
entities: {
|
|
143
|
+
...entities,
|
|
144
|
+
Tacos: {
|
|
145
|
+
...entities.Tacos,
|
|
146
|
+
3: { id: '3', type: 'extra' },
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
expect(tacosWithExtra).toBeDefined();
|
|
151
|
+
expect(tacosWithExtra).toHaveLength(3);
|
|
152
|
+
expect(tacosWithExtra).toMatchSnapshot();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('Query+All based on args', () => {
|
|
157
|
+
const controller = new Controller();
|
|
158
|
+
const state = {
|
|
159
|
+
...initialState,
|
|
160
|
+
entities,
|
|
161
|
+
};
|
|
162
|
+
const queryTacos = new schema.Query(
|
|
163
|
+
new schema.All(Tacos),
|
|
164
|
+
(tacos, { type }: { type?: string } = {}) => {
|
|
165
|
+
if (!type) return tacos;
|
|
166
|
+
return tacos.filter(taco => taco.type === type);
|
|
167
|
+
},
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
const tacos = controller.get(queryTacos, { type: 'foo' }, state);
|
|
171
|
+
expect(tacos).toBeDefined();
|
|
172
|
+
expect(tacos?.[0]).toBeInstanceOf(Tacos);
|
|
173
|
+
expect(tacos).toMatchSnapshot();
|
|
174
|
+
const tacosBars = controller.get(queryTacos, { type: 'bar' }, state);
|
|
175
|
+
expect(tacosBars).toBeDefined();
|
|
176
|
+
expect(tacosBars?.[0]).toBeInstanceOf(Tacos);
|
|
177
|
+
expect(tacosBars).not.toEqual(tacos);
|
|
178
|
+
// should maintain referential equality
|
|
179
|
+
expect(tacos).toBe(controller.get(queryTacos, { type: 'foo' }, state));
|
|
180
|
+
|
|
181
|
+
const allTacos = controller.get(queryTacos, state);
|
|
182
|
+
expect(allTacos).toBeDefined();
|
|
183
|
+
expect(allTacos).toHaveLength(2);
|
|
184
|
+
expect(allTacos).toMatchSnapshot();
|
|
185
|
+
|
|
186
|
+
// @ts-expect-error
|
|
187
|
+
() => controller.get(queryTacos, 5, state);
|
|
188
|
+
|
|
189
|
+
const tacosWithExtra = controller.get(
|
|
190
|
+
queryTacos,
|
|
191
|
+
{ type: 'bar' },
|
|
192
|
+
{
|
|
193
|
+
...state,
|
|
194
|
+
entities: {
|
|
195
|
+
...entities,
|
|
196
|
+
Tacos: {
|
|
197
|
+
...entities.Tacos,
|
|
198
|
+
3: { id: '3', type: 'bar', name: 'thing3' },
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
expect(tacosWithExtra).toBeDefined();
|
|
204
|
+
expect(tacosWithExtra).toHaveLength(2);
|
|
205
|
+
expect(tacosWithExtra).toMatchSnapshot();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('Query+Collection based on args', () => {
|
|
209
|
+
const controller = new Controller();
|
|
210
|
+
const state = {
|
|
211
|
+
...initialState,
|
|
212
|
+
entities,
|
|
213
|
+
};
|
|
214
|
+
const tacoCount = new schema.Query(TacoList, tacos => {
|
|
215
|
+
return tacos?.length ?? 0;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
expect(controller.get(tacoCount, { type: 'foo' }, state)).toBe(1);
|
|
219
|
+
expect(controller.get(tacoCount, { type: 'bar' }, state)).toBe(1);
|
|
220
|
+
expect(controller.get(tacoCount, state)).toBe(2);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('Union based on args', () => {
|
|
224
|
+
class IDEntity extends Entity {
|
|
225
|
+
id: string = '';
|
|
226
|
+
pk() {
|
|
227
|
+
return this.id;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
class User extends IDEntity {
|
|
231
|
+
type = 'user';
|
|
232
|
+
username: string = '';
|
|
233
|
+
}
|
|
234
|
+
class Group extends IDEntity {
|
|
235
|
+
type = 'group';
|
|
236
|
+
groupname: string = '';
|
|
237
|
+
memberCount = 0;
|
|
238
|
+
}
|
|
239
|
+
const queryPerson = new schema.Union(
|
|
240
|
+
{
|
|
241
|
+
users: User,
|
|
242
|
+
groups: Group,
|
|
243
|
+
},
|
|
244
|
+
'type',
|
|
245
|
+
);
|
|
246
|
+
const controller = new Controller();
|
|
247
|
+
const state = {
|
|
248
|
+
...initialState,
|
|
249
|
+
entities: {
|
|
250
|
+
User: {
|
|
251
|
+
'1': { id: '1', type: 'users', username: 'bob' },
|
|
252
|
+
},
|
|
253
|
+
Group: {
|
|
254
|
+
'2': { id: '2', type: 'groups', groupname: 'fast', memberCount: 5 },
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
const user = controller.get(queryPerson, { id: '1', type: 'users' }, state);
|
|
259
|
+
expect(user).toBeDefined();
|
|
260
|
+
expect(user).toBeInstanceOf(User);
|
|
261
|
+
expect(user).toMatchSnapshot();
|
|
262
|
+
const group = controller.get(
|
|
263
|
+
queryPerson,
|
|
264
|
+
{ id: '2', type: 'groups' },
|
|
265
|
+
state,
|
|
266
|
+
);
|
|
267
|
+
expect(group).toBeDefined();
|
|
268
|
+
expect(group).toBeInstanceOf(Group);
|
|
269
|
+
expect(group).toMatchSnapshot();
|
|
270
|
+
|
|
271
|
+
// should maintain referential equality
|
|
272
|
+
expect(user).toBe(
|
|
273
|
+
controller.get(queryPerson, { id: '1', type: 'users' }, state),
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
// @ts-expect-error
|
|
277
|
+
() => controller.get(queryPerson, { id: { bob: 5 } }, state);
|
|
278
|
+
// @ts-expect-error
|
|
279
|
+
expect(controller.get(queryPerson, 5, state)).toBeUndefined();
|
|
280
|
+
// @ts-expect-error
|
|
281
|
+
() => controller.get(queryPerson, { doesnotexist: 5 }, state);
|
|
282
|
+
// @ts-expect-error
|
|
283
|
+
() => controller.get(queryPerson, { id: '1', doesnotexist: 5 }, state);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
@@ -39,7 +39,7 @@ describe('Controller.getResponse()', () => {
|
|
|
39
39
|
const state = {
|
|
40
40
|
...initialState,
|
|
41
41
|
entities,
|
|
42
|
-
|
|
42
|
+
endpoints: {
|
|
43
43
|
[ep.key()]: {
|
|
44
44
|
data: ['1', '2'],
|
|
45
45
|
},
|
|
@@ -84,7 +84,7 @@ describe('Controller.getResponse()', () => {
|
|
|
84
84
|
const state = {
|
|
85
85
|
...initialState,
|
|
86
86
|
entities,
|
|
87
|
-
|
|
87
|
+
endpoints: {
|
|
88
88
|
[ep.key()]: {
|
|
89
89
|
data: ['1', '2'],
|
|
90
90
|
},
|
|
@@ -51,8 +51,9 @@ export default function createSet<
|
|
|
51
51
|
error?: boolean;
|
|
52
52
|
},
|
|
53
53
|
): SetAction<E> {
|
|
54
|
-
const expiryLength: number =
|
|
55
|
-
?
|
|
54
|
+
const expiryLength: number =
|
|
55
|
+
error ?
|
|
56
|
+
endpoint.errorExpiryLength ?? 1000
|
|
56
57
|
: endpoint.dataExpiryLength ?? 60000;
|
|
57
58
|
/* istanbul ignore next */
|
|
58
59
|
if (process.env.NODE_ENV === 'development' && expiryLength < 0) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export const ensurePojo =
|
|
2
2
|
// FormData doesn't exist in node
|
|
3
3
|
/* istanbul ignore else we don't run coverage when we test node*/
|
|
4
|
-
typeof FormData !== 'undefined'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
(body: any) => body;
|
|
4
|
+
typeof FormData !== 'undefined' ?
|
|
5
|
+
(body: any) =>
|
|
6
|
+
body instanceof FormData ?
|
|
7
|
+
Object.fromEntries((body as any).entries())
|
|
8
|
+
: body
|
|
9
|
+
: /* istanbul ignore next */ (body: any) => body;
|
|
11
10
|
export default ensurePojo;
|
package/src/controller/types.ts
CHANGED
|
@@ -4,10 +4,8 @@ import type {
|
|
|
4
4
|
ResolveType,
|
|
5
5
|
} from '@data-client/normalizr';
|
|
6
6
|
|
|
7
|
-
export type ResultEntry<E extends EndpointInterface> =
|
|
8
|
-
|
|
|
9
|
-
| null
|
|
10
|
-
? ResolveType<E>
|
|
7
|
+
export type ResultEntry<E extends EndpointInterface> =
|
|
8
|
+
E['schema'] extends undefined | null ? ResolveType<E>
|
|
11
9
|
: Normalize<E['schema']>;
|
|
12
10
|
|
|
13
11
|
export type EndpointUpdateFunction<
|
package/src/index.ts
CHANGED
|
@@ -13,13 +13,14 @@ export type {
|
|
|
13
13
|
EndpointInterface,
|
|
14
14
|
EntityInterface,
|
|
15
15
|
ResolveType,
|
|
16
|
-
DenormalizeCache,
|
|
17
16
|
DenormalizeNullable,
|
|
18
17
|
Denormalize,
|
|
19
18
|
Normalize,
|
|
20
19
|
NormalizeNullable,
|
|
21
20
|
FetchFunction,
|
|
22
21
|
EndpointExtraOptions,
|
|
22
|
+
Queryable,
|
|
23
|
+
SchemaArgs,
|
|
23
24
|
} from '@data-client/normalizr';
|
|
24
25
|
export { ExpiryStatus } from '@data-client/normalizr';
|
|
25
26
|
export {
|
package/src/internal.ts
CHANGED
|
@@ -47,8 +47,9 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
47
47
|
serialize: {
|
|
48
48
|
options: undefined,
|
|
49
49
|
/* istanbul ignore next */
|
|
50
|
-
replacer:
|
|
51
|
-
?
|
|
50
|
+
replacer:
|
|
51
|
+
HASINTL ?
|
|
52
|
+
(key: string | number | symbol, value: unknown) => {
|
|
52
53
|
if (
|
|
53
54
|
typeof value === 'number' &&
|
|
54
55
|
typeof key === 'string' &&
|
|
@@ -81,6 +82,7 @@ export default class DevToolsManager implements Manager {
|
|
|
81
82
|
protected started = false;
|
|
82
83
|
protected actions: [ActionTypes, State<unknown>][] = [];
|
|
83
84
|
protected declare controller: Controller;
|
|
85
|
+
maxBufferLength = 100;
|
|
84
86
|
|
|
85
87
|
constructor(
|
|
86
88
|
config?: DevToolsConfig,
|
|
@@ -150,6 +152,10 @@ export default class DevToolsManager implements Manager {
|
|
|
150
152
|
if (this.started) {
|
|
151
153
|
this.devTools.send(action, state, undefined, 'RDC');
|
|
152
154
|
} else {
|
|
155
|
+
// avoid this getting too big in case this is long running
|
|
156
|
+
// we cut in half so we aren't constantly reallocating
|
|
157
|
+
if (this.actions.length > this.maxBufferLength)
|
|
158
|
+
this.actions = this.actions.slice(this.maxBufferLength / 2);
|
|
153
159
|
// queue actions
|
|
154
160
|
this.actions.push([action, state]);
|
|
155
161
|
}
|
|
@@ -51,8 +51,9 @@ describe('SubscriptionManager', () => {
|
|
|
51
51
|
payload: Record<string, any>,
|
|
52
52
|
reject = false,
|
|
53
53
|
): SubscribeAction {
|
|
54
|
-
const fetch =
|
|
55
|
-
|
|
54
|
+
const fetch =
|
|
55
|
+
reject ?
|
|
56
|
+
() => Promise.reject(new Error('Failed'))
|
|
56
57
|
: () => Promise.resolve(payload);
|
|
57
58
|
return {
|
|
58
59
|
type: SUBSCRIBE_TYPE,
|
package/src/middlewareTypes.ts
CHANGED
|
@@ -25,15 +25,7 @@ export type Dispatch<R extends Reducer<any, any>> = (
|
|
|
25
25
|
) => Promise<void>;
|
|
26
26
|
|
|
27
27
|
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
|
28
|
-
export type ReducerState<R extends Reducer<any, any>> =
|
|
29
|
-
infer S,
|
|
30
|
-
|
|
31
|
-
>
|
|
32
|
-
? S
|
|
33
|
-
: never;
|
|
34
|
-
export type ReducerAction<R extends Reducer<any, any>> = R extends Reducer<
|
|
35
|
-
any,
|
|
36
|
-
infer A
|
|
37
|
-
>
|
|
38
|
-
? A
|
|
39
|
-
: never;
|
|
28
|
+
export type ReducerState<R extends Reducer<any, any>> =
|
|
29
|
+
R extends Reducer<infer S, any> ? S : never;
|
|
30
|
+
export type ReducerAction<R extends Reducer<any, any>> =
|
|
31
|
+
R extends Reducer<any, infer A> ? A : never;
|
package/src/state/RIC.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const RIC: (cb: (...args: any[]) => void, options: any) => void = (
|
|
2
|
-
typeof requestIdleCallback === 'function'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
) as any;
|
|
2
|
+
typeof requestIdleCallback === 'function' ? requestIdleCallback : (
|
|
3
|
+
(cb: any) => setTimeout(cb, 0)
|
|
4
|
+
)) as any;
|
|
6
5
|
export default RIC;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`reducer should set error in meta for "set" 1`] = `
|
|
4
4
|
{
|
|
5
|
+
"endpoints": {},
|
|
5
6
|
"entities": {},
|
|
6
7
|
"entityMeta": {},
|
|
7
8
|
"indexes": {},
|
|
@@ -15,12 +16,14 @@ exports[`reducer should set error in meta for "set" 1`] = `
|
|
|
15
16
|
},
|
|
16
17
|
},
|
|
17
18
|
"optimistic": [],
|
|
18
|
-
"results": {},
|
|
19
19
|
}
|
|
20
20
|
`;
|
|
21
21
|
|
|
22
22
|
exports[`reducer singles should update state correctly 1`] = `
|
|
23
23
|
{
|
|
24
|
+
"endpoints": {
|
|
25
|
+
"http://test.com/article/20": "20",
|
|
26
|
+
},
|
|
24
27
|
"entities": {
|
|
25
28
|
"Article": {
|
|
26
29
|
"20": {
|
|
@@ -49,8 +52,5 @@ exports[`reducer singles should update state correctly 1`] = `
|
|
|
49
52
|
},
|
|
50
53
|
},
|
|
51
54
|
"optimistic": [],
|
|
52
|
-
"results": {
|
|
53
|
-
"http://test.com/article/20": "20",
|
|
54
|
-
},
|
|
55
55
|
}
|
|
56
56
|
`;
|