@nx/angular 16.0.0-beta.5 → 16.0.0-beta.7
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/esm2020/index.mjs +2 -9
- package/esm2020/mf/index.mjs +2 -8
- package/esm2020/mf/mf.mjs +5 -12
- package/esm2020/mf/nx-angular-mf.mjs +2 -5
- package/esm2020/nx-angular.mjs +2 -5
- package/esm2020/src/runtime/nx/data-persistence.mjs +22 -29
- package/esm2020/testing/index.mjs +2 -7
- package/esm2020/testing/nx-angular-testing.mjs +2 -5
- package/esm2020/testing/src/testing-utils.mjs +6 -11
- package/fesm2015/nx-angular-mf.mjs +56 -4
- package/fesm2015/nx-angular-mf.mjs.map +1 -1
- package/fesm2015/nx-angular-testing.mjs +39 -4
- package/fesm2015/nx-angular-testing.mjs.map +1 -1
- package/fesm2015/nx-angular.mjs +347 -4
- package/fesm2015/nx-angular.mjs.map +1 -1
- package/fesm2020/nx-angular-mf.mjs +50 -4
- package/fesm2020/nx-angular-mf.mjs.map +1 -1
- package/fesm2020/nx-angular-testing.mjs +39 -4
- package/fesm2020/nx-angular-testing.mjs.map +1 -1
- package/fesm2020/nx-angular.mjs +347 -4
- package/fesm2020/nx-angular.mjs.map +1 -1
- package/migrations.json +12 -0
- package/package.json +10 -10
- package/src/migrations/update-16-0-0/remove-karma-defaults.d.ts +2 -0
- package/src/migrations/update-16-0-0/remove-karma-defaults.js +56 -0
- package/src/migrations/update-16-0-0/remove-karma-defaults.js.map +1 -0
- package/src/migrations/update-16-0-0/remove-protractor-defaults.d.ts +2 -0
- package/src/migrations/update-16-0-0/remove-protractor-defaults.js +56 -0
- package/src/migrations/update-16-0-0/remove-protractor-defaults.js.map +1 -0
package/fesm2020/nx-angular.mjs
CHANGED
|
@@ -1,8 +1,351 @@
|
|
|
1
|
-
|
|
1
|
+
import { ROUTER_NAVIGATION } from '@ngrx/router-store';
|
|
2
|
+
import { isObservable, of } from 'rxjs';
|
|
3
|
+
import { concatMap, groupBy, mergeMap, switchMap, filter, map, catchError } from 'rxjs/operators';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @whatItDoes Handles pessimistic updates (updating the server first).
|
|
8
|
+
*
|
|
9
|
+
* Updating the server, when implemented naively, suffers from race conditions and poor error handling.
|
|
10
|
+
*
|
|
11
|
+
* `pessimisticUpdate` addresses these problems. It runs all fetches in order, which removes race conditions
|
|
12
|
+
* and forces the developer to handle errors.
|
|
13
|
+
*
|
|
14
|
+
* ## Example:
|
|
15
|
+
*
|
|
16
|
+
* ```typescript
|
|
17
|
+
* @Injectable()
|
|
18
|
+
* class TodoEffects {
|
|
19
|
+
* updateTodo$ = createEffect(() =>
|
|
20
|
+
* this.actions$.pipe(
|
|
21
|
+
* ofType('UPDATE_TODO'),
|
|
22
|
+
* pessimisticUpdate({
|
|
23
|
+
* // provides an action
|
|
24
|
+
* run: (action: UpdateTodo) => {
|
|
25
|
+
* // update the backend first, and then dispatch an action that will
|
|
26
|
+
* // update the client side
|
|
27
|
+
* return this.backend.updateTodo(action.todo.id, action.todo).pipe(
|
|
28
|
+
* map((updated) => ({
|
|
29
|
+
* type: 'UPDATE_TODO_SUCCESS',
|
|
30
|
+
* todo: updated,
|
|
31
|
+
* }))
|
|
32
|
+
* );
|
|
33
|
+
* },
|
|
34
|
+
* onError: (action: UpdateTodo, error: any) => {
|
|
35
|
+
* // we don't need to undo the changes on the client side.
|
|
36
|
+
* // we can dispatch an error, or simply log the error here and return `null`
|
|
37
|
+
* return null;
|
|
38
|
+
* },
|
|
39
|
+
* })
|
|
40
|
+
* )
|
|
41
|
+
* );
|
|
42
|
+
*
|
|
43
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* Note that if you don't return a new action from the run callback, you must set the dispatch property
|
|
48
|
+
* of the effect to false, like this:
|
|
49
|
+
*
|
|
50
|
+
* ```typescript
|
|
51
|
+
* class TodoEffects {
|
|
52
|
+
* updateTodo$ = createEffect(() =>
|
|
53
|
+
* this.actions$.pipe(
|
|
54
|
+
* //...
|
|
55
|
+
* ), { dispatch: false }
|
|
56
|
+
* );
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param opts
|
|
61
|
+
*/
|
|
62
|
+
function pessimisticUpdate(opts) {
|
|
63
|
+
return (source) => {
|
|
64
|
+
return source.pipe(mapActionAndState(), concatMap(runWithErrorHandling(opts.run, opts.onError)));
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @whatItDoes Handles optimistic updates (updating the client first).
|
|
70
|
+
*
|
|
71
|
+
* It runs all fetches in order, which removes race conditions and forces the developer to handle errors.
|
|
72
|
+
*
|
|
73
|
+
* When using `optimisticUpdate`, in case of a failure, the developer has already updated the state locally,
|
|
74
|
+
* so the developer must provide an undo action.
|
|
75
|
+
*
|
|
76
|
+
* The error handling must be done in the callback, or by means of the undo action.
|
|
77
|
+
*
|
|
78
|
+
* ## Example:
|
|
79
|
+
*
|
|
80
|
+
* ```typescript
|
|
81
|
+
* @Injectable()
|
|
82
|
+
* class TodoEffects {
|
|
83
|
+
* updateTodo$ = createEffect(() =>
|
|
84
|
+
* this.actions$.pipe(
|
|
85
|
+
* ofType('UPDATE_TODO'),
|
|
86
|
+
* optimisticUpdate({
|
|
87
|
+
* // provides an action
|
|
88
|
+
* run: (action: UpdateTodo) => {
|
|
89
|
+
* return this.backend.updateTodo(action.todo.id, action.todo).pipe(
|
|
90
|
+
* mapTo({
|
|
91
|
+
* type: 'UPDATE_TODO_SUCCESS',
|
|
92
|
+
* })
|
|
93
|
+
* );
|
|
94
|
+
* },
|
|
95
|
+
* undoAction: (action: UpdateTodo, error: any) => {
|
|
96
|
+
* // dispatch an undo action to undo the changes in the client state
|
|
97
|
+
* return {
|
|
98
|
+
* type: 'UNDO_TODO_UPDATE',
|
|
99
|
+
* todo: action.todo,
|
|
100
|
+
* };
|
|
101
|
+
* },
|
|
102
|
+
* })
|
|
103
|
+
* )
|
|
104
|
+
* );
|
|
105
|
+
*
|
|
106
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* Note that if you don't return a new action from the run callback, you must set the dispatch property
|
|
111
|
+
* of the effect to false, like this:
|
|
112
|
+
*
|
|
113
|
+
* ```typescript
|
|
114
|
+
* class TodoEffects {
|
|
115
|
+
* updateTodo$ = createEffect(() =>
|
|
116
|
+
* this.actions$.pipe(
|
|
117
|
+
* //...
|
|
118
|
+
* ), { dispatch: false }
|
|
119
|
+
* );
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @param opts
|
|
124
|
+
*/
|
|
125
|
+
function optimisticUpdate(opts) {
|
|
126
|
+
return (source) => {
|
|
127
|
+
return source.pipe(mapActionAndState(), concatMap(runWithErrorHandling(opts.run, opts.undoAction)));
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
* @whatItDoes Handles data fetching.
|
|
133
|
+
*
|
|
134
|
+
* Data fetching implemented naively suffers from race conditions and poor error handling.
|
|
135
|
+
*
|
|
136
|
+
* `fetch` addresses these problems. It runs all fetches in order, which removes race conditions
|
|
137
|
+
* and forces the developer to handle errors.
|
|
138
|
+
*
|
|
139
|
+
* ## Example:
|
|
140
|
+
*
|
|
141
|
+
* ```typescript
|
|
142
|
+
* @Injectable()
|
|
143
|
+
* class TodoEffects {
|
|
144
|
+
* loadTodos$ = createEffect(() =>
|
|
145
|
+
* this.actions$.pipe(
|
|
146
|
+
* ofType('GET_TODOS'),
|
|
147
|
+
* fetch({
|
|
148
|
+
* // provides an action
|
|
149
|
+
* run: (a: GetTodos) => {
|
|
150
|
+
* return this.backend.getAll().pipe(
|
|
151
|
+
* map((response) => ({
|
|
152
|
+
* type: 'TODOS',
|
|
153
|
+
* todos: response.todos,
|
|
154
|
+
* }))
|
|
155
|
+
* );
|
|
156
|
+
* },
|
|
157
|
+
* onError: (action: GetTodos, error: any) => {
|
|
158
|
+
* // dispatch an undo action to undo the changes in the client state
|
|
159
|
+
* return null;
|
|
160
|
+
* },
|
|
161
|
+
* })
|
|
162
|
+
* )
|
|
163
|
+
* );
|
|
164
|
+
*
|
|
165
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* This is correct, but because it set the concurrency to 1, it may not be performant.
|
|
170
|
+
*
|
|
171
|
+
* To fix that, you can provide the `id` function, like this:
|
|
172
|
+
*
|
|
173
|
+
* ```typescript
|
|
174
|
+
* @Injectable()
|
|
175
|
+
* class TodoEffects {
|
|
176
|
+
* loadTodo$ = createEffect(() =>
|
|
177
|
+
* this.actions$.pipe(
|
|
178
|
+
* ofType('GET_TODO'),
|
|
179
|
+
* fetch({
|
|
180
|
+
* id: (todo: GetTodo) => {
|
|
181
|
+
* return todo.id;
|
|
182
|
+
* },
|
|
183
|
+
* // provides an action
|
|
184
|
+
* run: (todo: GetTodo) => {
|
|
185
|
+
* return this.backend.getTodo(todo.id).map((response) => ({
|
|
186
|
+
* type: 'LOAD_TODO_SUCCESS',
|
|
187
|
+
* todo: response.todo,
|
|
188
|
+
* }));
|
|
189
|
+
* },
|
|
190
|
+
* onError: (action: GetTodo, error: any) => {
|
|
191
|
+
* // dispatch an undo action to undo the changes in the client state
|
|
192
|
+
* return null;
|
|
193
|
+
* },
|
|
194
|
+
* })
|
|
195
|
+
* )
|
|
196
|
+
* );
|
|
197
|
+
*
|
|
198
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* With this setup, the requests for Todo 1 will run concurrently with the requests for Todo 2.
|
|
203
|
+
*
|
|
204
|
+
* In addition, if there are multiple requests for Todo 1 scheduled, it will only run the last one.
|
|
205
|
+
*
|
|
206
|
+
* @param opts
|
|
207
|
+
*/
|
|
208
|
+
function fetch(opts) {
|
|
209
|
+
return (source) => {
|
|
210
|
+
if (opts.id) {
|
|
211
|
+
const groupedFetches = source.pipe(mapActionAndState(), groupBy(([action, ...store]) => {
|
|
212
|
+
return opts.id(action, ...store);
|
|
213
|
+
}));
|
|
214
|
+
return groupedFetches.pipe(mergeMap((pairs) => pairs.pipe(switchMap(runWithErrorHandling(opts.run, opts.onError)))));
|
|
215
|
+
}
|
|
216
|
+
return source.pipe(mapActionAndState(), concatMap(runWithErrorHandling(opts.run, opts.onError)));
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* @whatItDoes Handles data fetching as part of router navigation.
|
|
221
|
+
*
|
|
222
|
+
* Data fetching implemented naively suffers from race conditions and poor error handling.
|
|
223
|
+
*
|
|
224
|
+
* `navigation` addresses these problems.
|
|
225
|
+
*
|
|
226
|
+
* It checks if an activated router state contains the passed in component type, and, if it does, runs the `run`
|
|
227
|
+
* callback. It provides the activated snapshot associated with the component and the current state. And it only runs
|
|
228
|
+
* the last request.
|
|
229
|
+
*
|
|
230
|
+
* ## Example:
|
|
231
|
+
*
|
|
232
|
+
* ```typescript
|
|
233
|
+
* @Injectable()
|
|
234
|
+
* class TodoEffects {
|
|
235
|
+
* loadTodo$ = createEffect(() =>
|
|
236
|
+
* this.actions$.pipe(
|
|
237
|
+
* // listens for the routerNavigation action from @ngrx/router-store
|
|
238
|
+
* navigation(TodoComponent, {
|
|
239
|
+
* run: (activatedRouteSnapshot: ActivatedRouteSnapshot) => {
|
|
240
|
+
* return this.backend
|
|
241
|
+
* .fetchTodo(activatedRouteSnapshot.params['id'])
|
|
242
|
+
* .pipe(
|
|
243
|
+
* map((todo) => ({
|
|
244
|
+
* type: 'LOAD_TODO_SUCCESS',
|
|
245
|
+
* todo: todo,
|
|
246
|
+
* }))
|
|
247
|
+
* );
|
|
248
|
+
* },
|
|
249
|
+
* onError: (
|
|
250
|
+
* activatedRouteSnapshot: ActivatedRouteSnapshot,
|
|
251
|
+
* error: any
|
|
252
|
+
* ) => {
|
|
253
|
+
* // we can log and error here and return null
|
|
254
|
+
* // we can also navigate back
|
|
255
|
+
* return null;
|
|
256
|
+
* },
|
|
257
|
+
* })
|
|
258
|
+
* )
|
|
259
|
+
* );
|
|
260
|
+
*
|
|
261
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
262
|
+
* }
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @param component
|
|
266
|
+
* @param opts
|
|
267
|
+
*/
|
|
268
|
+
function navigation(component, opts) {
|
|
269
|
+
return (source) => {
|
|
270
|
+
const nav = source.pipe(mapActionAndState(), filter(([action]) => isStateSnapshot(action)), map(([action, ...slices]) => {
|
|
271
|
+
if (!isStateSnapshot(action)) {
|
|
272
|
+
// Because of the above filter we'll never get here,
|
|
273
|
+
// but this properly type narrows `action`
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
return [
|
|
277
|
+
findSnapshot(component, action.payload.routerState.root),
|
|
278
|
+
...slices,
|
|
279
|
+
];
|
|
280
|
+
}), filter(([snapshot]) => !!snapshot));
|
|
281
|
+
return nav.pipe(switchMap(runWithErrorHandling(opts.run, opts.onError)));
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function isStateSnapshot(action) {
|
|
285
|
+
return action.type === ROUTER_NAVIGATION;
|
|
286
|
+
}
|
|
287
|
+
function runWithErrorHandling(run, onError) {
|
|
288
|
+
return ([action, ...slices]) => {
|
|
289
|
+
try {
|
|
290
|
+
const r = wrapIntoObservable(run(action, ...slices));
|
|
291
|
+
return r.pipe(catchError((e) => wrapIntoObservable(onError(action, e))));
|
|
292
|
+
}
|
|
293
|
+
catch (e) {
|
|
294
|
+
return wrapIntoObservable(onError(action, e));
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* @whatItDoes maps Observable<Action | [Action, State]> to
|
|
300
|
+
* Observable<[Action, State]>
|
|
301
|
+
*/
|
|
302
|
+
function mapActionAndState() {
|
|
303
|
+
return (source) => {
|
|
304
|
+
return source.pipe(map((value) => normalizeActionAndState(value)));
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* @whatItDoes Normalizes either a bare action or an array of action and slices
|
|
309
|
+
* into an array of action and slices (or undefined)
|
|
310
|
+
*/
|
|
311
|
+
function normalizeActionAndState(args) {
|
|
312
|
+
let action, slices;
|
|
313
|
+
if (args instanceof Array) {
|
|
314
|
+
[action, ...slices] = args;
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
slices = [];
|
|
318
|
+
action = args;
|
|
319
|
+
}
|
|
320
|
+
return [action, ...slices];
|
|
321
|
+
}
|
|
322
|
+
function findSnapshot(component, s) {
|
|
323
|
+
if (s.routeConfig && s.routeConfig.component === component) {
|
|
324
|
+
return s;
|
|
325
|
+
}
|
|
326
|
+
for (const c of s.children) {
|
|
327
|
+
const ss = findSnapshot(component, c);
|
|
328
|
+
if (ss) {
|
|
329
|
+
return ss;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
function wrapIntoObservable(obj) {
|
|
335
|
+
if (isObservable(obj)) {
|
|
336
|
+
return obj;
|
|
337
|
+
}
|
|
338
|
+
else if (!obj) {
|
|
339
|
+
return of();
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
return of(obj);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
2
346
|
/**
|
|
3
347
|
* Generated bundle index. Do not edit.
|
|
4
348
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
tslib_1.__exportStar(require("./index"), exports);
|
|
349
|
+
|
|
350
|
+
export { fetch, navigation, optimisticUpdate, pessimisticUpdate };
|
|
8
351
|
//# sourceMappingURL=nx-angular.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-angular.mjs","sources":["../../../../packages/angular/nx-angular.ts"],"sourcesContent":["/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";AAAA;;AAEG;;;AAEH,OAAwB,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"nx-angular.mjs","sources":["../../../../packages/angular/src/runtime/nx/data-persistence.ts","../../../../packages/angular/nx-angular.ts"],"sourcesContent":["import type { Type } from '@angular/core';\nimport type {\n ActivatedRouteSnapshot,\n RouterStateSnapshot,\n} from '@angular/router';\nimport type { RouterNavigationAction } from '@ngrx/router-store';\nimport { ROUTER_NAVIGATION } from '@ngrx/router-store';\nimport type { Action } from '@ngrx/store';\nimport type { Observable } from 'rxjs';\nimport { isObservable, of } from 'rxjs';\nimport {\n catchError,\n concatMap,\n filter,\n groupBy,\n map,\n mergeMap,\n switchMap,\n} from 'rxjs/operators';\n\nexport interface PessimisticUpdateOpts<T extends Array<unknown>, A> {\n run(a: A, ...slices: [...T]): Observable<Action> | Action | void;\n onError(a: A, e: any): Observable<any> | any;\n}\n\nexport interface OptimisticUpdateOpts<T extends Array<unknown>, A> {\n run(a: A, ...slices: [...T]): Observable<Action> | Action | void;\n undoAction(a: A, e: any): Observable<Action> | Action;\n}\n\nexport interface FetchOpts<T extends Array<unknown>, A> {\n id?(a: A, ...slices: [...T]): any;\n run(a: A, ...slices: [...T]): Observable<Action> | Action | void;\n onError?(a: A, e: any): Observable<any> | any;\n}\n\nexport interface HandleNavigationOpts<T extends Array<unknown>> {\n run(\n a: ActivatedRouteSnapshot,\n ...slices: [...T]\n ): Observable<Action> | Action | void;\n onError?(a: ActivatedRouteSnapshot, e: any): Observable<any> | any;\n}\n\nexport type ActionOrActionWithStates<T extends Array<unknown>, A> =\n | A\n | [A, ...T];\nexport type ActionOrActionWithState<T, A> = ActionOrActionWithStates<[T], A>;\nexport type ActionStatesStream<T extends Array<unknown>, A> = Observable<\n ActionOrActionWithStates<T, A>\n>;\nexport type ActionStateStream<T, A> = Observable<\n ActionOrActionWithStates<[T], A>\n>;\n\n/**\n *\n * @whatItDoes Handles pessimistic updates (updating the server first).\n *\n * Updating the server, when implemented naively, suffers from race conditions and poor error handling.\n *\n * `pessimisticUpdate` addresses these problems. It runs all fetches in order, which removes race conditions\n * and forces the developer to handle errors.\n *\n * ## Example:\n *\n * ```typescript\n * @Injectable()\n * class TodoEffects {\n * updateTodo$ = createEffect(() =>\n * this.actions$.pipe(\n * ofType('UPDATE_TODO'),\n * pessimisticUpdate({\n * // provides an action\n * run: (action: UpdateTodo) => {\n * // update the backend first, and then dispatch an action that will\n * // update the client side\n * return this.backend.updateTodo(action.todo.id, action.todo).pipe(\n * map((updated) => ({\n * type: 'UPDATE_TODO_SUCCESS',\n * todo: updated,\n * }))\n * );\n * },\n * onError: (action: UpdateTodo, error: any) => {\n * // we don't need to undo the changes on the client side.\n * // we can dispatch an error, or simply log the error here and return `null`\n * return null;\n * },\n * })\n * )\n * );\n *\n * constructor(private actions$: Actions, private backend: Backend) {}\n * }\n * ```\n *\n * Note that if you don't return a new action from the run callback, you must set the dispatch property\n * of the effect to false, like this:\n *\n * ```typescript\n * class TodoEffects {\n * updateTodo$ = createEffect(() =>\n * this.actions$.pipe(\n * //...\n * ), { dispatch: false }\n * );\n * }\n * ```\n *\n * @param opts\n */\nexport function pessimisticUpdate<T extends Array<unknown>, A extends Action>(\n opts: PessimisticUpdateOpts<T, A>\n) {\n return (source: ActionStatesStream<T, A>): Observable<Action> => {\n return source.pipe(\n mapActionAndState(),\n concatMap(runWithErrorHandling(opts.run, opts.onError))\n );\n };\n}\n\n/**\n *\n * @whatItDoes Handles optimistic updates (updating the client first).\n *\n * It runs all fetches in order, which removes race conditions and forces the developer to handle errors.\n *\n * When using `optimisticUpdate`, in case of a failure, the developer has already updated the state locally,\n * so the developer must provide an undo action.\n *\n * The error handling must be done in the callback, or by means of the undo action.\n *\n * ## Example:\n *\n * ```typescript\n * @Injectable()\n * class TodoEffects {\n * updateTodo$ = createEffect(() =>\n * this.actions$.pipe(\n * ofType('UPDATE_TODO'),\n * optimisticUpdate({\n * // provides an action\n * run: (action: UpdateTodo) => {\n * return this.backend.updateTodo(action.todo.id, action.todo).pipe(\n * mapTo({\n * type: 'UPDATE_TODO_SUCCESS',\n * })\n * );\n * },\n * undoAction: (action: UpdateTodo, error: any) => {\n * // dispatch an undo action to undo the changes in the client state\n * return {\n * type: 'UNDO_TODO_UPDATE',\n * todo: action.todo,\n * };\n * },\n * })\n * )\n * );\n *\n * constructor(private actions$: Actions, private backend: Backend) {}\n * }\n * ```\n *\n * Note that if you don't return a new action from the run callback, you must set the dispatch property\n * of the effect to false, like this:\n *\n * ```typescript\n * class TodoEffects {\n * updateTodo$ = createEffect(() =>\n * this.actions$.pipe(\n * //...\n * ), { dispatch: false }\n * );\n * }\n * ```\n *\n * @param opts\n */\nexport function optimisticUpdate<T extends Array<unknown>, A extends Action>(\n opts: OptimisticUpdateOpts<T, A>\n) {\n return (source: ActionStatesStream<T, A>): Observable<Action> => {\n return source.pipe(\n mapActionAndState(),\n concatMap(runWithErrorHandling(opts.run, opts.undoAction))\n );\n };\n}\n\n/**\n *\n * @whatItDoes Handles data fetching.\n *\n * Data fetching implemented naively suffers from race conditions and poor error handling.\n *\n * `fetch` addresses these problems. It runs all fetches in order, which removes race conditions\n * and forces the developer to handle errors.\n *\n * ## Example:\n *\n * ```typescript\n * @Injectable()\n * class TodoEffects {\n * loadTodos$ = createEffect(() =>\n * this.actions$.pipe(\n * ofType('GET_TODOS'),\n * fetch({\n * // provides an action\n * run: (a: GetTodos) => {\n * return this.backend.getAll().pipe(\n * map((response) => ({\n * type: 'TODOS',\n * todos: response.todos,\n * }))\n * );\n * },\n * onError: (action: GetTodos, error: any) => {\n * // dispatch an undo action to undo the changes in the client state\n * return null;\n * },\n * })\n * )\n * );\n *\n * constructor(private actions$: Actions, private backend: Backend) {}\n * }\n * ```\n *\n * This is correct, but because it set the concurrency to 1, it may not be performant.\n *\n * To fix that, you can provide the `id` function, like this:\n *\n * ```typescript\n * @Injectable()\n * class TodoEffects {\n * loadTodo$ = createEffect(() =>\n * this.actions$.pipe(\n * ofType('GET_TODO'),\n * fetch({\n * id: (todo: GetTodo) => {\n * return todo.id;\n * },\n * // provides an action\n * run: (todo: GetTodo) => {\n * return this.backend.getTodo(todo.id).map((response) => ({\n * type: 'LOAD_TODO_SUCCESS',\n * todo: response.todo,\n * }));\n * },\n * onError: (action: GetTodo, error: any) => {\n * // dispatch an undo action to undo the changes in the client state\n * return null;\n * },\n * })\n * )\n * );\n *\n * constructor(private actions$: Actions, private backend: Backend) {}\n * }\n * ```\n *\n * With this setup, the requests for Todo 1 will run concurrently with the requests for Todo 2.\n *\n * In addition, if there are multiple requests for Todo 1 scheduled, it will only run the last one.\n *\n * @param opts\n */\nexport function fetch<T extends Array<unknown>, A extends Action>(\n opts: FetchOpts<T, A>\n) {\n return (source: ActionStatesStream<T, A>): Observable<Action> => {\n if (opts.id) {\n const groupedFetches = source.pipe(\n mapActionAndState(),\n groupBy(([action, ...store]) => {\n return opts.id(action, ...store);\n })\n );\n\n return groupedFetches.pipe(\n mergeMap((pairs) =>\n pairs.pipe(switchMap(runWithErrorHandling(opts.run, opts.onError)))\n )\n );\n }\n\n return source.pipe(\n mapActionAndState(),\n concatMap(runWithErrorHandling(opts.run, opts.onError))\n );\n };\n}\n\n/**\n * @whatItDoes Handles data fetching as part of router navigation.\n *\n * Data fetching implemented naively suffers from race conditions and poor error handling.\n *\n * `navigation` addresses these problems.\n *\n * It checks if an activated router state contains the passed in component type, and, if it does, runs the `run`\n * callback. It provides the activated snapshot associated with the component and the current state. And it only runs\n * the last request.\n *\n * ## Example:\n *\n * ```typescript\n * @Injectable()\n * class TodoEffects {\n * loadTodo$ = createEffect(() =>\n * this.actions$.pipe(\n * // listens for the routerNavigation action from @ngrx/router-store\n * navigation(TodoComponent, {\n * run: (activatedRouteSnapshot: ActivatedRouteSnapshot) => {\n * return this.backend\n * .fetchTodo(activatedRouteSnapshot.params['id'])\n * .pipe(\n * map((todo) => ({\n * type: 'LOAD_TODO_SUCCESS',\n * todo: todo,\n * }))\n * );\n * },\n * onError: (\n * activatedRouteSnapshot: ActivatedRouteSnapshot,\n * error: any\n * ) => {\n * // we can log and error here and return null\n * // we can also navigate back\n * return null;\n * },\n * })\n * )\n * );\n *\n * constructor(private actions$: Actions, private backend: Backend) {}\n * }\n * ```\n *\n * @param component\n * @param opts\n */\nexport function navigation<T extends Array<unknown>, A extends Action>(\n component: Type<any>,\n opts: HandleNavigationOpts<T>\n) {\n return (source: ActionStatesStream<T, A>) => {\n const nav = source.pipe(\n mapActionAndState(),\n filter(([action]) => isStateSnapshot(action)),\n map(([action, ...slices]) => {\n if (!isStateSnapshot(action)) {\n // Because of the above filter we'll never get here,\n // but this properly type narrows `action`\n return;\n }\n\n return [\n findSnapshot(component, action.payload.routerState.root),\n ...slices,\n ] as [ActivatedRouteSnapshot, ...T];\n }),\n filter(([snapshot]) => !!snapshot)\n );\n\n return nav.pipe(switchMap(runWithErrorHandling(opts.run, opts.onError)));\n };\n}\n\nfunction isStateSnapshot(\n action: any\n): action is RouterNavigationAction<RouterStateSnapshot> {\n return action.type === ROUTER_NAVIGATION;\n}\n\nfunction runWithErrorHandling<T extends Array<unknown>, A, R>(\n run: (a: A, ...slices: [...T]) => Observable<R> | R | void,\n onError: any\n) {\n return ([action, ...slices]: [A, ...T]): Observable<R> => {\n try {\n const r = wrapIntoObservable(run(action, ...slices));\n return r.pipe(catchError((e) => wrapIntoObservable(onError(action, e))));\n } catch (e) {\n return wrapIntoObservable(onError(action, e));\n }\n };\n}\n\n/**\n * @whatItDoes maps Observable<Action | [Action, State]> to\n * Observable<[Action, State]>\n */\nfunction mapActionAndState<T extends Array<unknown>, A>() {\n return (source: Observable<ActionOrActionWithStates<T, A>>) => {\n return source.pipe(\n map((value) => normalizeActionAndState(value) as [A, ...T])\n );\n };\n}\n\n/**\n * @whatItDoes Normalizes either a bare action or an array of action and slices\n * into an array of action and slices (or undefined)\n */\nfunction normalizeActionAndState<T extends Array<unknown>, A>(\n args: ActionOrActionWithStates<T, A>\n): [A, ...T] {\n let action: A, slices: T;\n\n if (args instanceof Array) {\n [action, ...slices] = args;\n } else {\n slices = [] as T;\n action = args;\n }\n\n return [action, ...slices];\n}\n\nfunction findSnapshot(\n component: Type<any>,\n s: ActivatedRouteSnapshot\n): ActivatedRouteSnapshot {\n if (s.routeConfig && s.routeConfig.component === component) {\n return s;\n }\n for (const c of s.children) {\n const ss = findSnapshot(component, c);\n if (ss) {\n return ss;\n }\n }\n return null;\n}\n\nfunction wrapIntoObservable<O>(obj: Observable<O> | O | void): Observable<O> {\n if (isObservable(obj)) {\n return obj;\n } else if (!obj) {\n return of();\n } else {\n return of(obj as O);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAuDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDG;AACG,SAAU,iBAAiB,CAC/B,IAAiC,EAAA;IAEjC,OAAO,CAAC,MAAgC,KAAwB;QAC9D,OAAO,MAAM,CAAC,IAAI,CAChB,iBAAiB,EAAE,EACnB,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CACxD,CAAC;AACJ,KAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDG;AACG,SAAU,gBAAgB,CAC9B,IAAgC,EAAA;IAEhC,OAAO,CAAC,MAAgC,KAAwB;QAC9D,OAAO,MAAM,CAAC,IAAI,CAChB,iBAAiB,EAAE,EACnB,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC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package/migrations.json
CHANGED
|
@@ -176,6 +176,18 @@
|
|
|
176
176
|
"version": "16.0.0-beta.1",
|
|
177
177
|
"description": "Replace @nrwl/angular with @nx/angular",
|
|
178
178
|
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
179
|
+
},
|
|
180
|
+
"remove-protractor-defaults-from-generators": {
|
|
181
|
+
"cli": "nx",
|
|
182
|
+
"version": "16.0.0-beta.6",
|
|
183
|
+
"description": "Remove protractor as default e2eTestRunner from nxJson and project configurations",
|
|
184
|
+
"implementation": "./src/migrations/update-16-0-0/remove-protractor-defaults"
|
|
185
|
+
},
|
|
186
|
+
"remove-karma-defaults-from-generators": {
|
|
187
|
+
"cli": "nx",
|
|
188
|
+
"version": "16.0.0-beta.6",
|
|
189
|
+
"description": "Remove karma as default unitTestRunner from nxJson and project configurations",
|
|
190
|
+
"implementation": "./src/migrations/update-16-0-0/remove-karma-defaults"
|
|
179
191
|
}
|
|
180
192
|
},
|
|
181
193
|
"packageJsonUpdates": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/angular",
|
|
3
|
-
"version": "16.0.0-beta.
|
|
3
|
+
"version": "16.0.0-beta.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, and Cypress. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -72,14 +72,14 @@
|
|
|
72
72
|
"migrations": "./migrations.json"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@nrwl/angular": "16.0.0-beta.
|
|
76
|
-
"@nx/cypress": "16.0.0-beta.
|
|
77
|
-
"@nx/devkit": "16.0.0-beta.
|
|
78
|
-
"@nx/jest": "16.0.0-beta.
|
|
79
|
-
"@nx/js": "16.0.0-beta.
|
|
80
|
-
"@nx/linter": "16.0.0-beta.
|
|
81
|
-
"@nx/webpack": "16.0.0-beta.
|
|
82
|
-
"@nx/workspace": "16.0.0-beta.
|
|
75
|
+
"@nrwl/angular": "16.0.0-beta.7",
|
|
76
|
+
"@nx/cypress": "16.0.0-beta.7",
|
|
77
|
+
"@nx/devkit": "16.0.0-beta.7",
|
|
78
|
+
"@nx/jest": "16.0.0-beta.7",
|
|
79
|
+
"@nx/js": "16.0.0-beta.7",
|
|
80
|
+
"@nx/linter": "16.0.0-beta.7",
|
|
81
|
+
"@nx/webpack": "16.0.0-beta.7",
|
|
82
|
+
"@nx/workspace": "16.0.0-beta.7",
|
|
83
83
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
84
84
|
"chalk": "^4.1.0",
|
|
85
85
|
"chokidar": "^3.5.1",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"fesm2015": "fesm2015/nx-angular.mjs",
|
|
121
121
|
"typings": "index.d.ts",
|
|
122
122
|
"sideEffects": false,
|
|
123
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "eb477479bf73bca940323a66e486221f00006c0f"
|
|
124
124
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const GENERATORS = ['application', 'library', 'host', 'remote'];
|
|
6
|
+
const CANDIDATE_GENERATOR_COLLECTIONS = ['@nrwl/angular', '@nx/angular'];
|
|
7
|
+
function removeKarmaDefaults(tree) {
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
10
|
+
if (nxJson.generators) {
|
|
11
|
+
const updatedConfig = updateUnitTestRunner(nxJson.generators);
|
|
12
|
+
if (updatedConfig) {
|
|
13
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
17
|
+
for (const [projectName, projectConfig] of projects) {
|
|
18
|
+
if (projectConfig.generators) {
|
|
19
|
+
const updatedProject = updateUnitTestRunner(projectConfig.generators);
|
|
20
|
+
if (updatedProject) {
|
|
21
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
yield (0, devkit_1.formatFiles)(tree);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.default = removeKarmaDefaults;
|
|
29
|
+
function updateUnitTestRunner(generatorsConfig) {
|
|
30
|
+
const generators = Object.entries(generatorsConfig);
|
|
31
|
+
let updatedConfig = false;
|
|
32
|
+
for (const [generatorName, generatorDefaults] of generators) {
|
|
33
|
+
if (CANDIDATE_GENERATOR_COLLECTIONS.includes(generatorName)) {
|
|
34
|
+
for (const possibleGenerator of GENERATORS) {
|
|
35
|
+
if (generatorDefaults[possibleGenerator] &&
|
|
36
|
+
generatorDefaults[possibleGenerator]['unitTestRunner'] &&
|
|
37
|
+
generatorDefaults[possibleGenerator]['unitTestRunner'] === 'karma') {
|
|
38
|
+
generatorsConfig[generatorName][possibleGenerator]['unitTestRunner'] =
|
|
39
|
+
undefined;
|
|
40
|
+
updatedConfig = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!GENERATORS.map((v) => `@nrwl/angular:${v}`).includes(generatorName) &&
|
|
45
|
+
!GENERATORS.map((v) => `@nx/angular:${v}`).includes(generatorName)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (generatorDefaults['unitTestRunner'] &&
|
|
49
|
+
generatorDefaults['unitTestRunner'] === 'karma') {
|
|
50
|
+
generatorsConfig[generatorName]['unitTestRunner'] = undefined;
|
|
51
|
+
updatedConfig = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return updatedConfig;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=remove-karma-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-karma-defaults.js","sourceRoot":"","sources":["../../../../../../packages/angular/src/migrations/update-16-0-0/remove-karma-defaults.ts"],"names":[],"mappings":";;;AAKA,uCAMoB;AAEpB,MAAM,UAAU,GAAG,CAAC,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAChE,MAAM,+BAA+B,GAAG,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AAEzE,SAA8B,mBAAmB,CAAC,IAAU;;QAC1D,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC;QAEhC,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,MAAM,aAAa,GAAG,oBAAoB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAE9D,IAAI,aAAa,EAAE;gBACjB,IAAA,qBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;aAC5B;SACF;QAED,MAAM,QAAQ,GAAG,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;QAEnC,KAAK,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,IAAI,QAAQ,EAAE;YACnD,IAAI,aAAa,CAAC,UAAU,EAAE;gBAC5B,MAAM,cAAc,GAAG,oBAAoB,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;gBAEtE,IAAI,cAAc,EAAE;oBAClB,IAAA,mCAA0B,EAAC,IAAI,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;iBAC9D;aACF;SACF;QAED,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CA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2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const GENERATORS = ['application', 'host', 'remote'];
|
|
6
|
+
const CANDIDATE_GENERATOR_COLLECTIONS = ['@nrwl/angular', '@nx/angular'];
|
|
7
|
+
function removeProtractorDefaults(tree) {
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
10
|
+
if (nxJson.generators) {
|
|
11
|
+
const updatedConfig = updateE2ETestRunner(nxJson.generators);
|
|
12
|
+
if (updatedConfig) {
|
|
13
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
17
|
+
for (const [projectName, projectConfig] of projects) {
|
|
18
|
+
if (projectConfig.generators) {
|
|
19
|
+
const updatedProject = updateE2ETestRunner(projectConfig.generators);
|
|
20
|
+
if (updatedProject) {
|
|
21
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
yield (0, devkit_1.formatFiles)(tree);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.default = removeProtractorDefaults;
|
|
29
|
+
function updateE2ETestRunner(generatorsConfig) {
|
|
30
|
+
const generators = Object.entries(generatorsConfig);
|
|
31
|
+
let updatedConfig = false;
|
|
32
|
+
for (const [generatorName, generatorDefaults] of generators) {
|
|
33
|
+
if (CANDIDATE_GENERATOR_COLLECTIONS.includes(generatorName)) {
|
|
34
|
+
for (const possibleGenerator of GENERATORS) {
|
|
35
|
+
if (generatorDefaults[possibleGenerator] &&
|
|
36
|
+
generatorDefaults[possibleGenerator]['e2eTestRunner'] &&
|
|
37
|
+
generatorDefaults[possibleGenerator]['e2eTestRunner'] === 'protractor') {
|
|
38
|
+
generatorsConfig[generatorName][possibleGenerator]['e2eTestRunner'] =
|
|
39
|
+
undefined;
|
|
40
|
+
updatedConfig = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!GENERATORS.map((v) => `@nrwl/angular:${v}`).includes(generatorName) &&
|
|
45
|
+
!GENERATORS.map((v) => `@nx/angular:${v}`).includes(generatorName)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (generatorDefaults['e2eTestRunner'] &&
|
|
49
|
+
generatorDefaults['e2eTestRunner'] === 'protractor') {
|
|
50
|
+
generatorsConfig[generatorName]['e2eTestRunner'] = undefined;
|
|
51
|
+
updatedConfig = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return updatedConfig;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=remove-protractor-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-protractor-defaults.js","sourceRoot":"","sources":["../../../../../../packages/angular/src/migrations/update-16-0-0/remove-protractor-defaults.ts"],"names":[],"mappings":";;;AAKA,uCAMoB;AAEpB,MAAM,UAAU,GAAG,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AACrD,MAAM,+BAA+B,GAAG,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AAEzE,SAA8B,wBAAwB,CAAC,IAAU;;QAC/D,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC;QAEhC,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,MAAM,aAAa,GAAG,mBAAmB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAE7D,IAAI,aAAa,EAAE;gBACjB,IAAA,qBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;aAC5B;SACF;QAED,MAAM,QAAQ,GAAG,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;QAEnC,KAAK,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