@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.
@@ -1,494 +1,320 @@
1
- import { defaultMemoize, createSelector, select } from '@ngrx/store';
2
- import { daffCollectionBuildMetadataFromRequest, daffComputeAppliedFilters, createMultiInjectionToken, createSingleInjectionToken } from '@daffodil/core';
3
- import { createEntityAdapter } from '@ngrx/entity';
4
- import { pipe } from 'rxjs';
5
- import { scan, filter } from 'rxjs/operators';
6
- import { runInInjectionContext, inject, Injector } from '@angular/core';
7
-
8
- /**
9
- * Provides an abstracted way to manage a collection state.
10
- */
11
- class DaffCollectionStateAdapter {
12
- /**
13
- * Stores a collection request in state.
14
- * This is useful when you want to preemptively reduce a request before waiting for a response.
15
- */
16
- storeRequest(request, state) {
17
- return {
18
- ...state,
19
- ...daffCollectionBuildMetadataFromRequest(request),
20
- };
21
- }
22
- /**
23
- * Sets the page size.
24
- */
25
- setPageSize(size, state) {
26
- return {
27
- ...state,
28
- pageSize: size,
29
- currentPage: 1,
30
- };
31
- }
32
- /**
33
- * Sets the current page.
34
- */
35
- setCurrentPage(page, state) {
36
- return {
37
- ...state,
38
- currentPage: page,
39
- };
40
- }
41
- /**
42
- * Sets the sorting option and direction.
43
- */
44
- setSort(option, direction, state) {
45
- return {
46
- ...state,
47
- appliedSortOption: option,
48
- appliedSortDirection: direction,
49
- };
50
- }
51
- /**
52
- * Sets the collection filters.
53
- */
54
- setFilters(filters, state) {
55
- return {
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
- count: 0,
86
- appliedSortOption: null,
87
- appliedSortDirection: null,
88
- currentPage: null,
89
- pageSize: null,
90
- totalPages: null,
91
- sortOptions: {
92
- default: null,
93
- options: [],
94
- },
95
- ids: [],
96
- filters: {},
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
- const selectCollectionMetadata = createSelector(selectCollectionState, state => state);
106
- const selectCollectionRequest = createSelector(selectCollectionMetadata, metadata => ({
107
- appliedSortOption: metadata.appliedSortOption,
108
- appliedSortDirection: metadata.appliedSortDirection,
109
- currentPage: metadata.currentPage,
110
- pageSize: metadata.pageSize,
111
- }));
112
- const selectCollectionCount = createSelector(selectCollectionMetadata, state => state.count);
113
- const selectCollectionCurrentPage = createSelector(selectCollectionMetadata, state => state.currentPage);
114
- const selectCollectionTotalPages = createSelector(selectCollectionMetadata, state => state.totalPages);
115
- const selectCollectionPageSize = createSelector(selectCollectionMetadata, state => state.pageSize);
116
- const selectCollectionSortOptions = createSelector(selectCollectionMetadata, state => state.sortOptions.options);
117
- const selectCollectionAppliedSortOption = createSelector(selectCollectionMetadata, state => state.appliedSortOption);
118
- const selectCollectionAppliedSortDirection = createSelector(selectCollectionMetadata, state => state.appliedSortDirection);
119
- const selectCollectionIds = createSelector(selectCollectionMetadata, state => state.ids);
120
- const selectCollectionFilters = createSelector(selectCollectionMetadata, state => state.filters);
121
- const selectCollectionAppliedFilters = createSelector(selectCollectionFilters, filters => daffComputeAppliedFilters(filters));
122
- return {
123
- selectCollectionMetadata,
124
- selectCollectionRequest,
125
- selectCollectionCount,
126
- selectCollectionCurrentPage,
127
- selectCollectionTotalPages,
128
- selectCollectionPageSize,
129
- selectCollectionSortOptions,
130
- selectCollectionAppliedSortOption,
131
- selectCollectionAppliedSortDirection,
132
- selectCollectionIds,
133
- selectCollectionFilters,
134
- selectCollectionAppliedFilters,
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
- return { code, message, recoverable };
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
- return {
184
- ...state,
185
- daffState: "Resolving" /* DaffState.Resolving */,
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
- return {
194
- ...state,
195
- daffState: "Updating" /* DaffState.Updating */,
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
- return {
205
- ...state,
206
- daffState: "Stable" /* DaffState.Stable */,
207
- daffErrors: [],
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
- return {
217
- ...state,
218
- daffState: "Error" /* DaffState.Error */,
219
- daffErrors: errors,
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
- return {
228
- ...state,
229
- daffErrors: [],
230
- };
156
+ return {
157
+ ...state,
158
+ daffErrors: []
159
+ };
231
160
  }
232
- ;
233
-
234
161
  const daffOperationInitialState = {
235
- daffState: "Stable" /* DaffState.Stable */,
236
- daffErrors: [],
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
- return daffStateIsMutating(daffState) || daffState === "Resolving" /* DaffState.Resolving */;
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
- return daffState === "Adding" /* DaffState.Adding */
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
- const selectLoadingState = createSelector(selectState, state => state.daffState);
261
- const selectLoading = createSelector(selectLoadingState, loadingState => daffStateIsLoading(loadingState));
262
- const selectResolving = createSelector(selectLoadingState, loadingState => loadingState === "Resolving" /* DaffState.Resolving */);
263
- const selectMutating = createSelector(selectLoadingState, loadingState => daffStateIsMutating(loadingState));
264
- const selectErrors = createSelector(selectState, state => state.daffErrors);
265
- const selectHasErrors = createSelector(selectErrors, errors => errors.length > 0);
266
- return {
267
- selectLoadingState,
268
- selectLoading,
269
- selectResolving,
270
- selectMutating,
271
- selectErrors,
272
- selectHasErrors,
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
- const selectEntity = defaultMemoize((id) => createSelector(entitySelectors.selectEntities, entities => entities[id])).memoized;
286
- const selectOptimisticList = createSelector(entitySelectors.selectAll, (entities) => entities.filter(entity =>
287
- // ignore entities that are deleting
288
- // entity.daffState !== DaffState.Deleting &&
289
- // ignore placeholders with errors
290
- !(entity.daffTemp && entity.daffErrors.length > 0)));
291
- return {
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
- return new DaffOperationEntityStateAdapter(adapter);
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
- const isFullMatch = matchedSubstream => matchedSubstream.length === sequence.length;
439
- const accumulateMatchedSubstream = (matchedSubstream, action) => compareActionSequenceStep(sequence[matchedSubstream.length], action)
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
- return (state, action) => reducers.reduce((nextState, reducer) => reducer(nextState, action), state);
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
- const extra = createMultiInjectionToken(`${feature}_EXTRA_REDUCERS`);
468
- const reducers = createSingleInjectionToken(`${feature}_REDUCERS`, {
469
- factory: () => daffComposeReducers([
470
- runInInjectionContext(inject(Injector), createReducers),
471
- ...inject(extra.token),
472
- ]),
473
- });
474
- const meta = createMultiInjectionToken(`${feature}_META_REDUCERS`);
475
- const config = createSingleInjectionToken(`${feature}_STORE_CONFIG`, {
476
- providedIn: 'any',
477
- factory: () => ({
478
- metaReducers: inject(meta.token),
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
- //# sourceMappingURL=daffodil-core-state.mjs.map
319
+
320
+ //# sourceMappingURL=daffodil-core-state.mjs.map