@daffodil/core 0.94.1 → 0.95.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/fesm2022/daffodil-core-external-script-testing.mjs +42 -56
- package/fesm2022/daffodil-core-external-script-testing.mjs.map +1 -1
- package/fesm2022/daffodil-core-external-script.mjs +77 -95
- package/fesm2022/daffodil-core-external-script.mjs.map +1 -1
- package/fesm2022/daffodil-core-graphql.mjs +94 -145
- package/fesm2022/daffodil-core-graphql.mjs.map +1 -1
- package/fesm2022/daffodil-core-routing.mjs +53 -85
- package/fesm2022/daffodil-core-routing.mjs.map +1 -1
- package/fesm2022/daffodil-core-state-testing.mjs +90 -62
- package/fesm2022/daffodil-core-state-testing.mjs.map +1 -1
- package/fesm2022/daffodil-core-state.mjs +282 -456
- package/fesm2022/daffodil-core-state.mjs.map +1 -1
- package/fesm2022/daffodil-core-testing.mjs +1077 -657
- package/fesm2022/daffodil-core-testing.mjs.map +1 -1
- package/fesm2022/daffodil-core.mjs +720 -1342
- package/fesm2022/daffodil-core.mjs.map +1 -1
- package/package.json +1 -1
- package/types/daffodil-core-external-script-testing.d.ts +14 -18
- package/types/daffodil-core-external-script.d.ts +42 -47
- package/types/daffodil-core-graphql.d.ts +35 -51
- package/types/daffodil-core-routing.d.ts +40 -51
- package/types/daffodil-core-state-testing.d.ts +31 -35
- package/types/daffodil-core-state.d.ts +429 -465
- package/types/daffodil-core-testing.d.ts +220 -245
- package/types/daffodil-core.d.ts +518 -641
|
@@ -1,494 +1,320 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createEntityAdapter } from
|
|
4
|
-
import { pipe } from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
...state,
|
|
57
|
-
currentPage: 1,
|
|
58
|
-
filters: filters || {},
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Set the entire collection metadata at once.
|
|
63
|
-
*/
|
|
64
|
-
setMetadata(metadata, state) {
|
|
65
|
-
return {
|
|
66
|
-
...state,
|
|
67
|
-
ids: metadata.ids,
|
|
68
|
-
count: metadata.count,
|
|
69
|
-
currentPage: metadata.currentPage,
|
|
70
|
-
pageSize: metadata.pageSize,
|
|
71
|
-
sortOptions: metadata.sortOptions,
|
|
72
|
-
totalPages: metadata.totalPages,
|
|
73
|
-
appliedSortOption: metadata.appliedSortOption || state.appliedSortOption,
|
|
74
|
-
appliedSortDirection: metadata.appliedSortDirection || state.appliedSortDirection,
|
|
75
|
-
filters: metadata.filters || {},
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Create the adapter for the collection state.
|
|
81
|
-
*/
|
|
1
|
+
import { createSelector, defaultMemoize, select } from "@ngrx/store";
|
|
2
|
+
import { createMultiInjectionToken, createSingleInjectionToken, daffCollectionBuildMetadataFromRequest, daffComputeAppliedFilters } from "@daffodil/core";
|
|
3
|
+
import { createEntityAdapter } from "@ngrx/entity";
|
|
4
|
+
import { pipe } from "rxjs";
|
|
5
|
+
import { filter, scan } from "rxjs/operators";
|
|
6
|
+
import { Injector, inject, runInInjectionContext } from "@angular/core";
|
|
7
|
+
var DaffCollectionStateAdapter = class {
|
|
8
|
+
storeRequest(request, state) {
|
|
9
|
+
return {
|
|
10
|
+
...state,
|
|
11
|
+
...daffCollectionBuildMetadataFromRequest(request)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
setPageSize(size, state) {
|
|
15
|
+
return {
|
|
16
|
+
...state,
|
|
17
|
+
pageSize: size,
|
|
18
|
+
currentPage: 1
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
setCurrentPage(page, state) {
|
|
22
|
+
return {
|
|
23
|
+
...state,
|
|
24
|
+
currentPage: page
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
setSort(option, direction, state) {
|
|
28
|
+
return {
|
|
29
|
+
...state,
|
|
30
|
+
appliedSortOption: option,
|
|
31
|
+
appliedSortDirection: direction
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
setFilters(filters, state) {
|
|
35
|
+
return {
|
|
36
|
+
...state,
|
|
37
|
+
currentPage: 1,
|
|
38
|
+
filters: filters || {}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
setMetadata(metadata, state) {
|
|
42
|
+
return {
|
|
43
|
+
...state,
|
|
44
|
+
ids: metadata.ids,
|
|
45
|
+
count: metadata.count,
|
|
46
|
+
currentPage: metadata.currentPage,
|
|
47
|
+
pageSize: metadata.pageSize,
|
|
48
|
+
sortOptions: metadata.sortOptions,
|
|
49
|
+
totalPages: metadata.totalPages,
|
|
50
|
+
appliedSortOption: metadata.appliedSortOption || state.appliedSortOption,
|
|
51
|
+
appliedSortDirection: metadata.appliedSortDirection || state.appliedSortDirection,
|
|
52
|
+
filters: metadata.filters || {}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
82
56
|
const getCollectionStateAdapter = defaultMemoize(() => new DaffCollectionStateAdapter()).memoized;
|
|
83
|
-
|
|
84
57
|
const daffCollectionReducerInitialState = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
58
|
+
count: 0,
|
|
59
|
+
appliedSortOption: null,
|
|
60
|
+
appliedSortDirection: null,
|
|
61
|
+
currentPage: null,
|
|
62
|
+
pageSize: null,
|
|
63
|
+
totalPages: null,
|
|
64
|
+
sortOptions: {
|
|
65
|
+
default: null,
|
|
66
|
+
options: []
|
|
67
|
+
},
|
|
68
|
+
ids: [],
|
|
69
|
+
filters: {}
|
|
97
70
|
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Creates collection selectors.
|
|
101
|
-
*
|
|
102
|
-
* @param selectCollectionState A selector for the particular collection state upon which the returned selectors should operate.
|
|
103
|
-
*/
|
|
104
71
|
const daffCollectionSelectorFactory = (selectCollectionState) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
72
|
+
const selectCollectionMetadata = createSelector(selectCollectionState, (state) => state);
|
|
73
|
+
const selectCollectionRequest = createSelector(selectCollectionMetadata, (metadata) => ({
|
|
74
|
+
appliedSortOption: metadata.appliedSortOption,
|
|
75
|
+
appliedSortDirection: metadata.appliedSortDirection,
|
|
76
|
+
currentPage: metadata.currentPage,
|
|
77
|
+
pageSize: metadata.pageSize
|
|
78
|
+
}));
|
|
79
|
+
const selectCollectionCount = createSelector(selectCollectionMetadata, (state) => state.count);
|
|
80
|
+
const selectCollectionCurrentPage = createSelector(selectCollectionMetadata, (state) => state.currentPage);
|
|
81
|
+
const selectCollectionTotalPages = createSelector(selectCollectionMetadata, (state) => state.totalPages);
|
|
82
|
+
const selectCollectionPageSize = createSelector(selectCollectionMetadata, (state) => state.pageSize);
|
|
83
|
+
const selectCollectionSortOptions = createSelector(selectCollectionMetadata, (state) => state.sortOptions.options);
|
|
84
|
+
const selectCollectionAppliedSortOption = createSelector(selectCollectionMetadata, (state) => state.appliedSortOption);
|
|
85
|
+
const selectCollectionAppliedSortDirection = createSelector(selectCollectionMetadata, (state) => state.appliedSortDirection);
|
|
86
|
+
const selectCollectionIds = createSelector(selectCollectionMetadata, (state) => state.ids);
|
|
87
|
+
const selectCollectionFilters = createSelector(selectCollectionMetadata, (state) => state.filters);
|
|
88
|
+
return {
|
|
89
|
+
selectCollectionMetadata,
|
|
90
|
+
selectCollectionRequest,
|
|
91
|
+
selectCollectionCount,
|
|
92
|
+
selectCollectionCurrentPage,
|
|
93
|
+
selectCollectionTotalPages,
|
|
94
|
+
selectCollectionPageSize,
|
|
95
|
+
selectCollectionSortOptions,
|
|
96
|
+
selectCollectionAppliedSortOption,
|
|
97
|
+
selectCollectionAppliedSortDirection,
|
|
98
|
+
selectCollectionIds,
|
|
99
|
+
selectCollectionFilters,
|
|
100
|
+
selectCollectionAppliedFilters: createSelector(selectCollectionFilters, (filters) => daffComputeAppliedFilters(filters))
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
var DaffCollectionFacade = class {
|
|
104
|
+
constructor(store, selectors) {
|
|
105
|
+
this.store = store;
|
|
106
|
+
this.metadata$ = this.store.pipe(select(selectors.selectCollectionMetadata));
|
|
107
|
+
this.request$ = this.store.pipe(select(selectors.selectCollectionRequest));
|
|
108
|
+
this.count$ = this.store.pipe(select(selectors.selectCollectionCount));
|
|
109
|
+
this.currentPage$ = this.store.pipe(select(selectors.selectCollectionCurrentPage));
|
|
110
|
+
this.totalPages$ = this.store.pipe(select(selectors.selectCollectionTotalPages));
|
|
111
|
+
this.pageSize$ = this.store.pipe(select(selectors.selectCollectionPageSize));
|
|
112
|
+
this.sortOptions$ = this.store.pipe(select(selectors.selectCollectionSortOptions));
|
|
113
|
+
this.appliedSortOption$ = this.store.pipe(select(selectors.selectCollectionAppliedSortOption));
|
|
114
|
+
this.appliedSortDirection$ = this.store.pipe(select(selectors.selectCollectionAppliedSortDirection));
|
|
115
|
+
this.filters$ = this.store.pipe(select(selectors.selectCollectionFilters));
|
|
116
|
+
this.appliedFilters$ = this.store.pipe(select(selectors.selectCollectionAppliedFilters));
|
|
117
|
+
}
|
|
118
|
+
dispatch(action) {
|
|
119
|
+
this.store.dispatch(action);
|
|
120
|
+
}
|
|
136
121
|
};
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* An abstract class for a collection facade.
|
|
140
|
-
* It is configurable via its constructor parameters.
|
|
141
|
-
* The particular collection state from which
|
|
142
|
-
* this facade will read is determined by the selectors passed.
|
|
143
|
-
*
|
|
144
|
-
* @inheritdoc
|
|
145
|
-
*/
|
|
146
|
-
class DaffCollectionFacade {
|
|
147
|
-
constructor(store, selectors) {
|
|
148
|
-
this.store = store;
|
|
149
|
-
this.metadata$ = this.store.pipe(select(selectors.selectCollectionMetadata));
|
|
150
|
-
this.request$ = this.store.pipe(select(selectors.selectCollectionRequest));
|
|
151
|
-
this.count$ = this.store.pipe(select(selectors.selectCollectionCount));
|
|
152
|
-
this.currentPage$ = this.store.pipe(select(selectors.selectCollectionCurrentPage));
|
|
153
|
-
this.totalPages$ = this.store.pipe(select(selectors.selectCollectionTotalPages));
|
|
154
|
-
this.pageSize$ = this.store.pipe(select(selectors.selectCollectionPageSize));
|
|
155
|
-
this.sortOptions$ = this.store.pipe(select(selectors.selectCollectionSortOptions));
|
|
156
|
-
this.appliedSortOption$ = this.store.pipe(select(selectors.selectCollectionAppliedSortOption));
|
|
157
|
-
this.appliedSortDirection$ = this.store.pipe(select(selectors.selectCollectionAppliedSortDirection));
|
|
158
|
-
this.filters$ = this.store.pipe(select(selectors.selectCollectionFilters));
|
|
159
|
-
this.appliedFilters$ = this.store.pipe(select(selectors.selectCollectionAppliedFilters));
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Dispatches the given action.
|
|
163
|
-
*
|
|
164
|
-
* @param action action to dispatch.
|
|
165
|
-
*/
|
|
166
|
-
dispatch(action) {
|
|
167
|
-
this.store.dispatch(action);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Transforms an error instance to a state error object.
|
|
173
|
-
*/
|
|
174
122
|
function daffTransformErrorToStateError({ code, message, recoverable }) {
|
|
175
|
-
|
|
123
|
+
return {
|
|
124
|
+
code,
|
|
125
|
+
message,
|
|
126
|
+
recoverable
|
|
127
|
+
};
|
|
176
128
|
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Puts the state in a "resolving" state that correspondes to loading platform data in a GET fashion.
|
|
180
|
-
* Sets loading to `DaffState.Resolving`
|
|
181
|
-
*/
|
|
182
129
|
function daffStartResolution(state) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
130
|
+
return {
|
|
131
|
+
...state,
|
|
132
|
+
daffState: "Resolving"
|
|
133
|
+
};
|
|
187
134
|
}
|
|
188
|
-
;
|
|
189
|
-
/**
|
|
190
|
-
* Puts the state in a "mutating" state that correspondes to loading platform data in a POST or PUT fashion.
|
|
191
|
-
*/
|
|
192
135
|
function daffStartMutation(state) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
136
|
+
return {
|
|
137
|
+
...state,
|
|
138
|
+
daffState: "Updating"
|
|
139
|
+
};
|
|
197
140
|
}
|
|
198
|
-
;
|
|
199
|
-
/**
|
|
200
|
-
* Indicates a successfully completed operation.
|
|
201
|
-
* Sets loading to stable and resets errors.
|
|
202
|
-
*/
|
|
203
141
|
function daffCompleteOperation(state) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
142
|
+
return {
|
|
143
|
+
...state,
|
|
144
|
+
daffState: "Stable",
|
|
145
|
+
daffErrors: []
|
|
146
|
+
};
|
|
209
147
|
}
|
|
210
|
-
;
|
|
211
|
-
/**
|
|
212
|
-
* Indicates a failed operation.
|
|
213
|
-
* Sets loading to stable and stores errors.
|
|
214
|
-
*/
|
|
215
148
|
function daffOperationFailed(errors, state) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
149
|
+
return {
|
|
150
|
+
...state,
|
|
151
|
+
daffState: "Error",
|
|
152
|
+
daffErrors: errors
|
|
153
|
+
};
|
|
221
154
|
}
|
|
222
|
-
;
|
|
223
|
-
/**
|
|
224
|
-
* Resets errors.
|
|
225
|
-
*/
|
|
226
155
|
function daffClearErrors(state) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
156
|
+
return {
|
|
157
|
+
...state,
|
|
158
|
+
daffErrors: []
|
|
159
|
+
};
|
|
231
160
|
}
|
|
232
|
-
;
|
|
233
|
-
|
|
234
161
|
const daffOperationInitialState = {
|
|
235
|
-
|
|
236
|
-
|
|
162
|
+
daffState: "Stable",
|
|
163
|
+
daffErrors: []
|
|
237
164
|
};
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Returns whether the state is one that represents an operation in progress.
|
|
241
|
-
*/
|
|
242
165
|
function daffStateIsLoading(daffState) {
|
|
243
|
-
|
|
166
|
+
return daffStateIsMutating(daffState) || daffState === "Resolving";
|
|
244
167
|
}
|
|
245
|
-
/**
|
|
246
|
-
* Returns whether the state is one that represents a mutable operation in progress.
|
|
247
|
-
*/
|
|
248
168
|
function daffStateIsMutating(daffState) {
|
|
249
|
-
|
|
250
|
-
|| daffState === "Updating" /* DaffState.Updating */
|
|
251
|
-
|| daffState === "Deleting" /* DaffState.Deleting */;
|
|
169
|
+
return daffState === "Adding" || daffState === "Updating" || daffState === "Deleting";
|
|
252
170
|
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Creates a set of selectors for an operation state.
|
|
256
|
-
*
|
|
257
|
-
* @param selectState The feature selector for the operation state.
|
|
258
|
-
*/
|
|
259
171
|
function daffOperationStateSelectorFactory(selectState) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
};
|
|
172
|
+
const selectLoadingState = createSelector(selectState, (state) => state.daffState);
|
|
173
|
+
const selectLoading = createSelector(selectLoadingState, (loadingState) => daffStateIsLoading(loadingState));
|
|
174
|
+
const selectResolving = createSelector(selectLoadingState, (loadingState) => loadingState === "Resolving");
|
|
175
|
+
const selectMutating = createSelector(selectLoadingState, (loadingState) => daffStateIsMutating(loadingState));
|
|
176
|
+
const selectErrors = createSelector(selectState, (state) => state.daffErrors);
|
|
177
|
+
return {
|
|
178
|
+
selectLoadingState,
|
|
179
|
+
selectLoading,
|
|
180
|
+
selectResolving,
|
|
181
|
+
selectMutating,
|
|
182
|
+
selectErrors,
|
|
183
|
+
selectHasErrors: createSelector(selectErrors, (errors) => errors.length > 0)
|
|
184
|
+
};
|
|
274
185
|
}
|
|
275
|
-
;
|
|
276
|
-
|
|
277
|
-
// ngrx does not export EntitySelectors so we gotta do this nonsense
|
|
278
|
-
const giveMeType = (adapter) => adapter.getSelectors((state) => ({ ids: [], entities: {} }));
|
|
279
|
-
/**
|
|
280
|
-
* Creates a set of selectors for an entity operation state.
|
|
281
|
-
*
|
|
282
|
-
* @param selectState The feature selector for the entity operation state.
|
|
283
|
-
*/
|
|
284
186
|
function daffOperationEntityStateSelectorFactory(entitySelectors) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
...entitySelectors,
|
|
293
|
-
selectEntity,
|
|
294
|
-
selectOptimisticList,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* @inheritdoc
|
|
301
|
-
*/
|
|
302
|
-
class DaffOperationEntityStateAdapter {
|
|
303
|
-
constructor(adapter = createEntityAdapter()) {
|
|
304
|
-
this.adapter = adapter;
|
|
305
|
-
}
|
|
306
|
-
list(entities, state) {
|
|
307
|
-
return this.adapter.setAll(entities.map(entity => ({
|
|
308
|
-
daffState: "Stable" /* DaffState.Stable */,
|
|
309
|
-
...entity,
|
|
310
|
-
daffErrors: [],
|
|
311
|
-
daffTemp: false,
|
|
312
|
-
})), state);
|
|
313
|
-
}
|
|
314
|
-
preload(id, state) {
|
|
315
|
-
return this.adapter.upsertOne({
|
|
316
|
-
// TODO: allow for non identifiable entities?
|
|
317
|
-
id,
|
|
318
|
-
daffState: "Resolving" /* DaffState.Resolving */,
|
|
319
|
-
daffErrors: [],
|
|
320
|
-
daffTemp: !state.entities[id],
|
|
321
|
-
}, state);
|
|
322
|
-
}
|
|
323
|
-
load(entity, state) {
|
|
324
|
-
return this.adapter.upsertOne({
|
|
325
|
-
daffState: "Stable" /* DaffState.Stable */,
|
|
326
|
-
...entity,
|
|
327
|
-
daffErrors: [],
|
|
328
|
-
daffTemp: false,
|
|
329
|
-
}, state);
|
|
330
|
-
}
|
|
331
|
-
preadd(entity, state, placeholderId) {
|
|
332
|
-
return placeholderId
|
|
333
|
-
? this.adapter.upsertOne({
|
|
334
|
-
...entity,
|
|
335
|
-
// TODO: allow for non identifiable entities?
|
|
336
|
-
id: placeholderId,
|
|
337
|
-
daffState: "Adding" /* DaffState.Adding */,
|
|
338
|
-
daffErrors: [],
|
|
339
|
-
daffTemp: true,
|
|
340
|
-
}, state)
|
|
341
|
-
: state;
|
|
342
|
-
}
|
|
343
|
-
add(entity, state, placeholderId) {
|
|
344
|
-
return this.adapter.upsertOne({
|
|
345
|
-
daffState: "Added" /* DaffState.Added */,
|
|
346
|
-
...entity,
|
|
347
|
-
daffErrors: [],
|
|
348
|
-
daffTemp: false,
|
|
349
|
-
}, placeholderId ? this.adapter.removeOne(placeholderId, state) : state);
|
|
350
|
-
}
|
|
351
|
-
preupdate(entity, state) {
|
|
352
|
-
return this.adapter.upsertOne({
|
|
353
|
-
...state.entities[entity.id],
|
|
354
|
-
daffState: "Updating" /* DaffState.Updating */,
|
|
355
|
-
daffErrors: [],
|
|
356
|
-
}, state);
|
|
357
|
-
}
|
|
358
|
-
update(entity, state) {
|
|
359
|
-
return this.adapter.updateOne({
|
|
360
|
-
id: entity.id,
|
|
361
|
-
changes: {
|
|
362
|
-
daffState: "Updated" /* DaffState.Updated */,
|
|
363
|
-
...entity,
|
|
364
|
-
daffErrors: [],
|
|
365
|
-
daffTemp: false,
|
|
366
|
-
},
|
|
367
|
-
}, state);
|
|
368
|
-
}
|
|
369
|
-
preremove(key, state) {
|
|
370
|
-
return this.adapter.upsertOne({
|
|
371
|
-
...state.entities[key],
|
|
372
|
-
daffErrors: [],
|
|
373
|
-
daffState: "Deleting" /* DaffState.Deleting */,
|
|
374
|
-
}, state);
|
|
375
|
-
}
|
|
376
|
-
remove(key, state) {
|
|
377
|
-
return this.adapter.removeOne(key, state);
|
|
378
|
-
}
|
|
379
|
-
operationFailed(key, errors, state) {
|
|
380
|
-
return state.entities[key] ? this.adapter.upsertOne({
|
|
381
|
-
...state.entities[key],
|
|
382
|
-
daffState: "Error" /* DaffState.Error */,
|
|
383
|
-
daffErrors: errors,
|
|
384
|
-
}, state) : state;
|
|
385
|
-
}
|
|
386
|
-
resetState(key, state) {
|
|
387
|
-
return state.entities[key] ? this.adapter.upsertOne({
|
|
388
|
-
...state.entities[key],
|
|
389
|
-
daffState: "Stable" /* DaffState.Stable */,
|
|
390
|
-
}, state) : state;
|
|
391
|
-
}
|
|
392
|
-
getInitialState(state) {
|
|
393
|
-
return this.adapter.getInitialState(state);
|
|
394
|
-
}
|
|
395
|
-
getSelectors(selectState) {
|
|
396
|
-
return daffOperationEntityStateSelectorFactory(this.adapter.getSelectors(selectState));
|
|
397
|
-
}
|
|
187
|
+
const selectEntity = defaultMemoize((id) => createSelector(entitySelectors.selectEntities, (entities) => entities[id])).memoized;
|
|
188
|
+
const selectOptimisticList = createSelector(entitySelectors.selectAll, (entities) => entities.filter((entity) => !(entity.daffTemp && entity.daffErrors.length > 0)));
|
|
189
|
+
return {
|
|
190
|
+
...entitySelectors,
|
|
191
|
+
selectEntity,
|
|
192
|
+
selectOptimisticList
|
|
193
|
+
};
|
|
398
194
|
}
|
|
195
|
+
var DaffOperationEntityStateAdapter = class {
|
|
196
|
+
constructor(adapter = createEntityAdapter()) {
|
|
197
|
+
this.adapter = adapter;
|
|
198
|
+
}
|
|
199
|
+
list(entities, state) {
|
|
200
|
+
return this.adapter.setAll(entities.map((entity) => ({
|
|
201
|
+
daffState: "Stable",
|
|
202
|
+
...entity,
|
|
203
|
+
daffErrors: [],
|
|
204
|
+
daffTemp: false
|
|
205
|
+
})), state);
|
|
206
|
+
}
|
|
207
|
+
preload(id, state) {
|
|
208
|
+
return this.adapter.upsertOne({
|
|
209
|
+
id,
|
|
210
|
+
daffState: "Resolving",
|
|
211
|
+
daffErrors: [],
|
|
212
|
+
daffTemp: !state.entities[id]
|
|
213
|
+
}, state);
|
|
214
|
+
}
|
|
215
|
+
load(entity, state) {
|
|
216
|
+
return this.adapter.upsertOne({
|
|
217
|
+
daffState: "Stable",
|
|
218
|
+
...entity,
|
|
219
|
+
daffErrors: [],
|
|
220
|
+
daffTemp: false
|
|
221
|
+
}, state);
|
|
222
|
+
}
|
|
223
|
+
preadd(entity, state, placeholderId) {
|
|
224
|
+
return placeholderId ? this.adapter.upsertOne({
|
|
225
|
+
...entity,
|
|
226
|
+
id: placeholderId,
|
|
227
|
+
daffState: "Adding",
|
|
228
|
+
daffErrors: [],
|
|
229
|
+
daffTemp: true
|
|
230
|
+
}, state) : state;
|
|
231
|
+
}
|
|
232
|
+
add(entity, state, placeholderId) {
|
|
233
|
+
return this.adapter.upsertOne({
|
|
234
|
+
daffState: "Added",
|
|
235
|
+
...entity,
|
|
236
|
+
daffErrors: [],
|
|
237
|
+
daffTemp: false
|
|
238
|
+
}, placeholderId ? this.adapter.removeOne(placeholderId, state) : state);
|
|
239
|
+
}
|
|
240
|
+
preupdate(entity, state) {
|
|
241
|
+
return this.adapter.upsertOne({
|
|
242
|
+
...state.entities[entity.id],
|
|
243
|
+
daffState: "Updating",
|
|
244
|
+
daffErrors: []
|
|
245
|
+
}, state);
|
|
246
|
+
}
|
|
247
|
+
update(entity, state) {
|
|
248
|
+
return this.adapter.updateOne({
|
|
249
|
+
id: entity.id,
|
|
250
|
+
changes: {
|
|
251
|
+
daffState: "Updated",
|
|
252
|
+
...entity,
|
|
253
|
+
daffErrors: [],
|
|
254
|
+
daffTemp: false
|
|
255
|
+
}
|
|
256
|
+
}, state);
|
|
257
|
+
}
|
|
258
|
+
preremove(key, state) {
|
|
259
|
+
return this.adapter.upsertOne({
|
|
260
|
+
...state.entities[key],
|
|
261
|
+
daffErrors: [],
|
|
262
|
+
daffState: "Deleting"
|
|
263
|
+
}, state);
|
|
264
|
+
}
|
|
265
|
+
remove(key, state) {
|
|
266
|
+
return this.adapter.removeOne(key, state);
|
|
267
|
+
}
|
|
268
|
+
operationFailed(key, errors, state) {
|
|
269
|
+
return state.entities[key] ? this.adapter.upsertOne({
|
|
270
|
+
...state.entities[key],
|
|
271
|
+
daffState: "Error",
|
|
272
|
+
daffErrors: errors
|
|
273
|
+
}, state) : state;
|
|
274
|
+
}
|
|
275
|
+
resetState(key, state) {
|
|
276
|
+
return state.entities[key] ? this.adapter.upsertOne({
|
|
277
|
+
...state.entities[key],
|
|
278
|
+
daffState: "Stable"
|
|
279
|
+
}, state) : state;
|
|
280
|
+
}
|
|
281
|
+
getInitialState(state) {
|
|
282
|
+
return this.adapter.getInitialState(state);
|
|
283
|
+
}
|
|
284
|
+
getSelectors(selectState) {
|
|
285
|
+
return daffOperationEntityStateSelectorFactory(this.adapter.getSelectors(selectState));
|
|
286
|
+
}
|
|
287
|
+
};
|
|
399
288
|
function daffCreateOperationEntityStateAdapter(adapter = createEntityAdapter()) {
|
|
400
|
-
|
|
289
|
+
return new DaffOperationEntityStateAdapter(adapter);
|
|
401
290
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
* Generate a fake ID for use with placeholder entities.
|
|
405
|
-
*
|
|
406
|
-
* @param key An optional key that can augment the randomly generated ID.
|
|
407
|
-
* @returns A string cont
|
|
408
|
-
*/
|
|
409
|
-
function daffOperationEntityCreateFakeId(key = '') {
|
|
410
|
-
return `ε-${Date.now()}-${key}`;
|
|
291
|
+
function daffOperationEntityCreateFakeId(key = "") {
|
|
292
|
+
return `ε-${Date.now()}-${key}`;
|
|
411
293
|
}
|
|
412
|
-
|
|
413
|
-
const compareActionSequenceStep = (step, action) => Array.isArray(step)
|
|
414
|
-
? step.reduce((acc, type) => acc || action.type === type, false)
|
|
415
|
-
: action.type === step;
|
|
416
|
-
/**
|
|
417
|
-
* Watches for a particular stream of actions in the specified order and
|
|
418
|
-
* emits a list of those actions once all sequence steps have been matched.
|
|
419
|
-
*
|
|
420
|
-
* This will find the first occurence of the substream and not necessarily the most concise or recent substream.
|
|
421
|
-
* For example, substream([A, B]) encountering an action stream of [A1, A2, B1, B2] will emit [A1, B1].
|
|
422
|
-
* When a substream is found and emitted, the list is reset and it will continue to listen to the action stream.
|
|
423
|
-
*
|
|
424
|
-
* You can indicate that a particular step in the sequence can be matched by mutiple actions by passing an array for that step.
|
|
425
|
-
* For example, if the first step of the sequence could be action A or action B: substream([[A, B], C]).
|
|
426
|
-
* An action stream of [A1, C1] would cause substream to emit [A1, C1].
|
|
427
|
-
* An action stream of [B1, C1] would cause substream to emit [B1, C1].
|
|
428
|
-
* An action stream of [A1, B1, C1] would cause substream to emit [A1, C1].
|
|
429
|
-
*
|
|
430
|
-
* You can optionally pass a list of terminators.
|
|
431
|
-
* If a terminator is encountered in the action stream, any partially matched substream is reset.
|
|
432
|
-
* For example, substream([A, B], C) would not emit anything for an action stream of [A1, C1, B1].
|
|
433
|
-
*
|
|
434
|
-
* @param sequence The sequence of action types that define the substream to listen for.
|
|
435
|
-
* @param terminators A list of terminators, any of which interrupt and reset a partially matched substream.
|
|
436
|
-
*/
|
|
294
|
+
const compareActionSequenceStep = (step, action) => Array.isArray(step) ? step.reduce((acc, type) => acc || action.type === type, false) : action.type === step;
|
|
437
295
|
const substream = (sequence, ...terminators) => {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
...matchedSubstream,
|
|
442
|
-
action,
|
|
443
|
-
]
|
|
444
|
-
: matchedSubstream;
|
|
445
|
-
return pipe(scan((matchedSubstream, action) => terminators.indexOf(action.type) > -1
|
|
446
|
-
// terminator found, reset the list
|
|
447
|
-
? []
|
|
448
|
-
: accumulateMatchedSubstream(
|
|
449
|
-
// reset the list if fully matched
|
|
450
|
-
isFullMatch(matchedSubstream) ? [] : matchedSubstream, action), []), filter(isFullMatch));
|
|
296
|
+
const isFullMatch = (matchedSubstream) => matchedSubstream.length === sequence.length;
|
|
297
|
+
const accumulateMatchedSubstream = (matchedSubstream, action) => compareActionSequenceStep(sequence[matchedSubstream.length], action) ? [...matchedSubstream, action] : matchedSubstream;
|
|
298
|
+
return pipe(scan((matchedSubstream, action) => terminators.indexOf(action.type) > -1 ? [] : accumulateMatchedSubstream(isFullMatch(matchedSubstream) ? [] : matchedSubstream, action), []), filter(isFullMatch));
|
|
451
299
|
};
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* Creates and returns a composite reducer that invokes each of the passed reducers in turn.
|
|
455
|
-
*/
|
|
456
300
|
function daffComposeReducers(reducers) {
|
|
457
|
-
|
|
301
|
+
return (state, action) => reducers.reduce((nextState, reducer) => reducer(nextState, action), state);
|
|
458
302
|
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* A simple reducer that simply returns the passed state.
|
|
462
|
-
* This is useful for stubbing out parts of state that are not covered in an injected extra reducer map.
|
|
463
|
-
*/
|
|
464
303
|
const daffIdentityReducer = (state, action) => state;
|
|
465
|
-
|
|
466
304
|
const createInjectableReducersTokens = (feature, createReducers) => {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
}),
|
|
480
|
-
});
|
|
481
|
-
return {
|
|
482
|
-
extra,
|
|
483
|
-
reducers,
|
|
484
|
-
meta,
|
|
485
|
-
config,
|
|
486
|
-
};
|
|
305
|
+
const extra = createMultiInjectionToken(`${feature}_EXTRA_REDUCERS`);
|
|
306
|
+
const reducers = createSingleInjectionToken(`${feature}_REDUCERS`, { factory: () => daffComposeReducers([runInInjectionContext(inject(Injector), createReducers), ...inject(extra.token)]) });
|
|
307
|
+
const meta = createMultiInjectionToken(`${feature}_META_REDUCERS`);
|
|
308
|
+
return {
|
|
309
|
+
extra,
|
|
310
|
+
reducers,
|
|
311
|
+
meta,
|
|
312
|
+
config: createSingleInjectionToken(`${feature}_STORE_CONFIG`, {
|
|
313
|
+
providedIn: "any",
|
|
314
|
+
factory: () => ({ metaReducers: inject(meta.token) })
|
|
315
|
+
})
|
|
316
|
+
};
|
|
487
317
|
};
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Generated bundle index. Do not edit.
|
|
491
|
-
*/
|
|
492
|
-
|
|
493
318
|
export { DaffCollectionFacade, DaffCollectionStateAdapter, DaffOperationEntityStateAdapter, createInjectableReducersTokens, daffClearErrors, daffCollectionReducerInitialState, daffCollectionSelectorFactory, daffCompleteOperation, daffComposeReducers, daffCreateOperationEntityStateAdapter, daffIdentityReducer, daffOperationEntityCreateFakeId, daffOperationEntityStateSelectorFactory, daffOperationFailed, daffOperationInitialState, daffOperationStateSelectorFactory, daffStartMutation, daffStartResolution, daffStateIsLoading, daffStateIsMutating, daffTransformErrorToStateError, getCollectionStateAdapter, substream };
|
|
494
|
-
|
|
319
|
+
|
|
320
|
+
//# sourceMappingURL=daffodil-core-state.mjs.map
|