tsdf 8.0.0-beta.1 → 8.0.0-beta.11

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.
Files changed (57) hide show
  1. package/dist/main.cjs +1860 -0
  2. package/dist/main.d.ts +291 -0
  3. package/dist/main.js +1825 -0
  4. package/package.json +6 -2
  5. package/.eslintignore +0 -3
  6. package/.eslintrc.cjs +0 -119
  7. package/.gitattributes +0 -22
  8. package/.prettierrc +0 -6
  9. package/.vscode/settings.json +0 -3
  10. package/.vscode/tasks.json +0 -35
  11. package/fetch-orquestrator-scenarios.excalidraw +0 -10115
  12. package/scripts/check-if-is-sync.sh +0 -6
  13. package/src/collectionFetchOrquestrator.ts +0 -23
  14. package/src/collectionStore.ts +0 -608
  15. package/src/documentStore.ts +0 -272
  16. package/src/fetchOrquestrator.ts +0 -335
  17. package/src/listQueryStore.ts +0 -1190
  18. package/src/main.ts +0 -22
  19. package/src/storeShared.ts +0 -5
  20. package/src/useEnsureIsLoaded.ts +0 -50
  21. package/src/utils/filterAndMap.ts +0 -20
  22. package/src/utils/getCacheId.ts +0 -19
  23. package/src/utils/hooks.ts +0 -110
  24. package/src/utils/isObject.ts +0 -3
  25. package/src/utils/math.ts +0 -7
  26. package/src/utils/serializableClone.ts +0 -3
  27. package/src/utils/useLatestValue.ts +0 -16
  28. package/test/__snapshots__/listQueryStore.test.ts.snap +0 -146
  29. package/test/__snapshots__/listQueryStoreHooks.test.ts.snap +0 -9
  30. package/test/collectionStore.test.ts +0 -523
  31. package/test/collectionStoreHooks.test.tsx +0 -651
  32. package/test/documentStore.test.ts +0 -183
  33. package/test/documentStoreHooks.test.tsx +0 -857
  34. package/test/fetchOrquestrator.test.ts +0 -913
  35. package/test/listQueryStore.test.ts +0 -1158
  36. package/test/listQueryStoreHooks.test.tsx +0 -662
  37. package/test/listQueryStoreHooks2.test.tsx +0 -483
  38. package/test/listQueryStoreHooksMutations.test.tsx +0 -764
  39. package/test/mocks/fetchMock.ts +0 -296
  40. package/test/mocks/fetchOrquestratorEnv.ts +0 -370
  41. package/test/setup/setup.ts +0 -109
  42. package/test/testHelpers.test.ts +0 -88
  43. package/test/utils/RenderObjValues.tsx +0 -23
  44. package/test/utils/arrayUtils.ts +0 -13
  45. package/test/utils/createDefaultListQueryStore.ts +0 -275
  46. package/test/utils/createOrVariations.ts +0 -48
  47. package/test/utils/dedent.ts +0 -50
  48. package/test/utils/delayCall.ts +0 -25
  49. package/test/utils/math.ts +0 -3
  50. package/test/utils/objectUtils.ts +0 -18
  51. package/test/utils/range.ts +0 -19
  52. package/test/utils/sleep.ts +0 -3
  53. package/test/utils/storeUtils.ts +0 -460
  54. package/tsconfig.json +0 -24
  55. package/tsconfig.prod.json +0 -9
  56. package/tsup.config.ts +0 -12
  57. package/vitest.config.ts +0 -10
@@ -1,183 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import {
3
- newTSDFDocumentStore,
4
- TSDFDocumentStoreState,
5
- } from '../src/documentStore';
6
- import { mockServerResource } from './mocks/fetchMock';
7
- import { sleep } from './utils/sleep';
8
- import {
9
- createDefaultDocumentStore,
10
- normalizeError,
11
- StoreError,
12
- } from './utils/storeUtils';
13
-
14
- type DocumentStoreState = TSDFDocumentStoreState<any, StoreError>;
15
-
16
- describe('fetch lifecicle', () => {
17
- const { serverMock, store: documentStore } = createDefaultDocumentStore();
18
-
19
- test('fetch resource', async () => {
20
- expect(documentStore.store.state).toEqual<DocumentStoreState>({
21
- data: null,
22
- error: null,
23
- refetchOnMount: false,
24
- status: 'idle',
25
- });
26
-
27
- documentStore.scheduleFetch('lowPriority');
28
-
29
- expect(documentStore.store.state).toEqual<DocumentStoreState>({
30
- data: null,
31
- error: null,
32
- refetchOnMount: false,
33
- status: 'loading',
34
- });
35
-
36
- await sleep(serverMock.fetchDuration + 5);
37
-
38
- expect(documentStore.store.state).toEqual<DocumentStoreState>({
39
- data: {
40
- hello: 'world',
41
- },
42
- error: null,
43
- refetchOnMount: false,
44
- status: 'success',
45
- });
46
- });
47
-
48
- test('refetch resource with new data', async () => {
49
- serverMock.mutateData({ hello: 'new data' });
50
-
51
- documentStore.scheduleFetch('highPriority');
52
-
53
- expect(documentStore.store.state).toEqual<DocumentStoreState>({
54
- data: {
55
- hello: 'world',
56
- },
57
- error: null,
58
- refetchOnMount: false,
59
- status: 'refetching',
60
- });
61
-
62
- await sleep(serverMock.fetchDuration + 5);
63
-
64
- expect(documentStore.store.state).toEqual<DocumentStoreState>({
65
- data: {
66
- hello: 'new data',
67
- },
68
- error: null,
69
- refetchOnMount: false,
70
- status: 'success',
71
- });
72
-
73
- expect(serverMock.fetchsCount).toBe(2);
74
- });
75
-
76
- test('refetch resource with error', async () => {
77
- serverMock.setFetchError('error');
78
-
79
- documentStore.scheduleFetch('highPriority');
80
-
81
- await sleep(serverMock.fetchDuration + 5);
82
-
83
- expect(documentStore.store.state).toEqual<DocumentStoreState>({
84
- data: {
85
- hello: 'new data',
86
- },
87
- error: {
88
- message: 'error',
89
- },
90
- refetchOnMount: false,
91
- status: 'error',
92
- });
93
- });
94
- });
95
-
96
- test.concurrent('start with initialized data', () => {
97
- const serverMock = mockServerResource<any>({
98
- initialData: null,
99
- });
100
-
101
- const documentStore = newTSDFDocumentStore({
102
- fetchFn: serverMock.fetchWitoutSelector,
103
- initialData: { hello: 'initial data' },
104
- errorNormalizer: normalizeError,
105
- });
106
-
107
- expect(documentStore.store.state).toEqual<DocumentStoreState>({
108
- data: {
109
- hello: 'initial data',
110
- },
111
- error: null,
112
- refetchOnMount: false,
113
- status: 'success',
114
- });
115
- });
116
-
117
- test.concurrent(
118
- 'multiple low priority fetchs at same time trigger only one fetch',
119
- async () => {
120
- const serverMock = mockServerResource<any>({
121
- initialData: { hello: 'new data' },
122
- });
123
-
124
- const documentStore = newTSDFDocumentStore({
125
- fetchFn: serverMock.fetchWitoutSelector,
126
- initialData: { hello: 'world' },
127
- errorNormalizer: normalizeError,
128
- });
129
-
130
- documentStore.scheduleFetch('lowPriority');
131
- documentStore.scheduleFetch('lowPriority');
132
- documentStore.scheduleFetch('lowPriority');
133
- documentStore.scheduleFetch('lowPriority');
134
-
135
- expect(documentStore.store.state).toEqual<DocumentStoreState>({
136
- data: { hello: 'world' },
137
- error: null,
138
- refetchOnMount: false,
139
- status: 'refetching',
140
- });
141
-
142
- await sleep(serverMock.fetchDuration + 5);
143
-
144
- expect(serverMock.fetchsCount).toBe(1);
145
-
146
- expect(documentStore.store.state).toEqual<DocumentStoreState>({
147
- data: { hello: 'new data' },
148
- error: null,
149
- refetchOnMount: false,
150
- status: 'success',
151
- });
152
- },
153
- );
154
-
155
- test.concurrent('await fetch', async () => {
156
- const { serverMock, store: documentStore } = createDefaultDocumentStore({
157
- useLoadedSnapshot: true,
158
- });
159
-
160
- serverMock.mutateData({ hello: 'new data' });
161
-
162
- expect(documentStore.store.state).toMatchObject({
163
- data: {
164
- hello: 'world',
165
- },
166
- });
167
-
168
- expect(await documentStore.awaitFetch()).toEqual({
169
- data: {
170
- hello: 'new data',
171
- },
172
- error: null,
173
- });
174
-
175
- serverMock.setFetchError('error');
176
-
177
- expect(await documentStore.awaitFetch()).toEqual({
178
- data: null,
179
- error: {
180
- message: 'error',
181
- },
182
- });
183
- });