@nx/angular 21.0.0-beta.1 → 21.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/nx-angular.mjs +0 -352
- package/fesm2022/nx-angular.mjs.map +1 -1
- package/generators.json +7 -2
- package/index.d.ts +1 -1
- package/migrations.json +199 -69
- package/ng-package.json +1 -1
- package/package.json +11 -14
- package/src/builders/dev-server/dev-server.impl.js +2 -3
- package/src/builders/dev-server/lib/normalize-options.js +1 -0
- package/src/builders/dev-server/schema.d.ts +4 -0
- package/src/builders/dev-server/schema.json +10 -4
- package/src/builders/webpack-browser/schema.d.ts +1 -4
- package/src/builders/webpack-browser/schema.json +5 -0
- package/src/builders/webpack-browser/webpack-browser.impl.js +5 -5
- package/src/executors/delegate-build/delegate-build.impl.d.ts +1 -3
- package/src/executors/delegate-build/delegate-build.impl.js +0 -3
- package/src/executors/module-federation-dev-server/schema.d.ts +3 -0
- package/src/executors/module-federation-dev-server/schema.json +2 -1
- package/src/executors/module-federation-ssr-dev-server/schema.json +1 -0
- package/src/executors/package/package.impl.js +1 -4
- package/src/generators/add-linting/add-linting.js +2 -17
- package/src/generators/add-linting/lib/create-eslint-configuration.d.ts +2 -2
- package/src/generators/add-linting/lib/create-eslint-configuration.js +2 -2
- package/src/generators/add-linting/schema.d.ts +1 -0
- package/src/generators/application/application.js +20 -1
- package/src/generators/application/files/rspack-ssr/server.ts__tmpl__ +72 -0
- package/src/generators/application/lib/add-e2e.js +2 -9
- package/src/generators/application/lib/add-linting.js +2 -2
- package/src/generators/application/lib/add-serve-static-target.js +1 -0
- package/src/generators/application/lib/add-unit-test-runner.js +2 -0
- package/src/generators/application/lib/create-project.js +1 -0
- package/src/generators/application/lib/normalize-options.d.ts +1 -1
- package/src/generators/application/lib/normalize-options.js +10 -4
- package/src/generators/application/schema.d.ts +2 -2
- package/src/generators/application/schema.json +1 -7
- package/src/generators/component-test/component-test.js +1 -1
- package/src/generators/convert-to-rspack/convert-to-rspack.d.ts +4 -0
- package/src/generators/convert-to-rspack/convert-to-rspack.js +329 -0
- package/src/generators/convert-to-rspack/lib/create-config.d.ts +2 -0
- package/src/generators/convert-to-rspack/lib/create-config.js +45 -0
- package/src/generators/convert-to-rspack/lib/get-custom-webpack-config.d.ts +6 -0
- package/src/generators/convert-to-rspack/lib/get-custom-webpack-config.js +77 -0
- package/src/generators/convert-to-rspack/lib/update-tsconfig.d.ts +2 -0
- package/src/generators/convert-to-rspack/lib/update-tsconfig.js +26 -0
- package/src/generators/convert-to-rspack/lib/validate-supported-executor.d.ts +2 -0
- package/src/generators/convert-to-rspack/lib/validate-supported-executor.js +14 -0
- package/src/generators/convert-to-rspack/schema.d.ts +5 -0
- package/src/generators/convert-to-rspack/schema.json +30 -0
- package/src/generators/host/host.js +1 -1
- package/src/generators/host/schema.d.ts +0 -1
- package/src/generators/host/schema.json +0 -6
- package/src/generators/library/lib/add-project.d.ts +1 -1
- package/src/generators/library/lib/add-project.js +7 -1
- package/src/generators/library/lib/normalize-options.js +3 -4
- package/src/generators/library/lib/normalized-schema.d.ts +0 -1
- package/src/generators/library/library.js +6 -3
- package/src/generators/library/schema.d.ts +0 -1
- package/src/generators/library/schema.json +0 -6
- package/src/generators/move/move.d.ts +3 -0
- package/src/generators/move/move.js +3 -0
- package/src/generators/ng-add/migrators/projects/e2e.migrator.js +4 -4
- package/src/generators/ngrx/ngrx.d.ts +3 -0
- package/src/generators/ngrx/ngrx.js +3 -0
- package/src/generators/ngrx/schema.json +1 -1
- package/src/generators/ngrx-feature-store/schema.d.ts +1 -1
- package/src/generators/remote/remote.js +1 -1
- package/src/generators/remote/schema.d.ts +0 -1
- package/src/generators/remote/schema.json +0 -6
- package/src/generators/setup-mf/lib/setup-serve-target.js +1 -0
- package/src/generators/setup-ssr/files/v19+/application-builder/ngmodule-src/app/__rootModuleFileName__ +2 -2
- package/src/generators/setup-ssr/files/v19+/application-builder/server/__serverFileName__ +1 -1
- package/src/generators/setup-ssr/files/v19+/application-builder/standalone-src/app/app.config.server.ts__tpl__ +2 -2
- package/src/generators/setup-ssr/files/v19+/application-builder-common-engine/server/__serverFileName__ +2 -0
- package/src/generators/setup-ssr/lib/generate-files.js +12 -1
- package/src/generators/setup-ssr/lib/update-project-config.js +1 -0
- package/src/generators/stories/stories.js +2 -2
- package/src/generators/utils/add-jest.d.ts +1 -0
- package/src/generators/utils/add-jest.js +2 -2
- package/src/generators/utils/add-vitest.d.ts +1 -0
- package/src/generators/utils/add-vitest.js +1 -1
- package/src/generators/utils/ensure-angular-dependencies.js +0 -1
- package/src/generators/utils/testing.js +1 -2
- package/src/migrations/update-16-2-0/switch-data-persistence-operators-imports-to-ngrx-router-store.js +4 -4
- package/src/migrations/update-19-6-0/turn-off-dts-by-default.js +2 -2
- package/src/migrations/{update-16-1-0 → update-20-5-0}/update-angular-cli.d.ts +1 -1
- package/src/migrations/{update-16-1-0 → update-20-5-0}/update-angular-cli.js +1 -1
- package/src/migrations/{update-16-1-0/remove-ngcc-invocation.d.ts → update-21-0-0/change-data-persistence-operators-imports-to-ngrx-router-store-data-persistence.d.ts} +1 -1
- package/src/migrations/update-21-0-0/change-data-persistence-operators-imports-to-ngrx-router-store-data-persistence.js +122 -0
- package/src/migrations/update-21-0-0/set-continuous-option.d.ts +3 -0
- package/src/migrations/update-21-0-0/set-continuous-option.js +29 -0
- package/src/plugins/plugin.js +2 -0
- package/src/utils/backward-compatible-versions.js +2 -0
- package/src/utils/nx-devkit/ast-utils.d.ts +0 -8
- package/src/utils/nx-devkit/ast-utils.js +7 -12
- package/src/utils/versions.d.ts +7 -6
- package/src/utils/versions.js +8 -7
- package/fesm2022/nx-angular-testing.mjs +0 -45
- package/fesm2022/nx-angular-testing.mjs.map +0 -1
- package/src/migrations/update-16-0-0/remove-karma-defaults.d.ts +0 -2
- package/src/migrations/update-16-0-0/remove-karma-defaults.js +0 -52
- package/src/migrations/update-16-0-0/remove-library-generator-simple-module-name-option.d.ts +0 -2
- package/src/migrations/update-16-0-0/remove-library-generator-simple-module-name-option.js +0 -40
- package/src/migrations/update-16-0-0/remove-protractor-defaults.d.ts +0 -2
- package/src/migrations/update-16-0-0/remove-protractor-defaults.js +0 -52
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-1-0/extract-standalone-config-from-bootstrap.d.ts +0 -2
- package/src/migrations/update-16-1-0/extract-standalone-config-from-bootstrap.js +0 -127
- package/src/migrations/update-16-1-0/remove-ngcc-invocation.js +0 -22
- package/src/migrations/update-16-1-0/remove-render-module-platform-server-exports.d.ts +0 -2
- package/src/migrations/update-16-1-0/remove-render-module-platform-server-exports.js +0 -62
- package/src/migrations/update-16-1-0/update-server-executor-config.d.ts +0 -2
- package/src/migrations/update-16-1-0/update-server-executor-config.js +0 -26
- package/src/runtime/nx/data-persistence.d.ts +0 -276
- package/testing/index.d.ts +0 -1
- package/testing/ng-package.json +0 -6
- package/testing/src/testing-utils.d.ts +0 -33
package/fesm2022/nx-angular.mjs
CHANGED
@@ -1,356 +1,4 @@
|
|
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
|
-
* @whatItDoes Handles pessimistic updates (updating the server first).
|
7
|
-
*
|
8
|
-
* Updating the server, when implemented naively, suffers from race conditions and poor error handling.
|
9
|
-
*
|
10
|
-
* `pessimisticUpdate` addresses these problems. It runs all fetches in order, which removes race conditions
|
11
|
-
* and forces the developer to handle errors.
|
12
|
-
*
|
13
|
-
* ## Example:
|
14
|
-
*
|
15
|
-
* ```typescript
|
16
|
-
* @Injectable()
|
17
|
-
* class TodoEffects {
|
18
|
-
* updateTodo$ = createEffect(() =>
|
19
|
-
* this.actions$.pipe(
|
20
|
-
* ofType('UPDATE_TODO'),
|
21
|
-
* pessimisticUpdate({
|
22
|
-
* // provides an action
|
23
|
-
* run: (action: UpdateTodo) => {
|
24
|
-
* // update the backend first, and then dispatch an action that will
|
25
|
-
* // update the client side
|
26
|
-
* return this.backend.updateTodo(action.todo.id, action.todo).pipe(
|
27
|
-
* map((updated) => ({
|
28
|
-
* type: 'UPDATE_TODO_SUCCESS',
|
29
|
-
* todo: updated,
|
30
|
-
* }))
|
31
|
-
* );
|
32
|
-
* },
|
33
|
-
* onError: (action: UpdateTodo, error: any) => {
|
34
|
-
* // we don't need to undo the changes on the client side.
|
35
|
-
* // we can dispatch an error, or simply log the error here and return `null`
|
36
|
-
* return null;
|
37
|
-
* },
|
38
|
-
* })
|
39
|
-
* )
|
40
|
-
* );
|
41
|
-
*
|
42
|
-
* constructor(private actions$: Actions, private backend: Backend) {}
|
43
|
-
* }
|
44
|
-
* ```
|
45
|
-
*
|
46
|
-
* Note that if you don't return a new action from the run callback, you must set the dispatch property
|
47
|
-
* of the effect to false, like this:
|
48
|
-
*
|
49
|
-
* ```typescript
|
50
|
-
* class TodoEffects {
|
51
|
-
* updateTodo$ = createEffect(() =>
|
52
|
-
* this.actions$.pipe(
|
53
|
-
* //...
|
54
|
-
* ), { dispatch: false }
|
55
|
-
* );
|
56
|
-
* }
|
57
|
-
* ```
|
58
|
-
*
|
59
|
-
* @param opts
|
60
|
-
*
|
61
|
-
* @deprecated This will be removed in Nx v21. Import `pessimisticUpdate` from `@ngrx/router-store/data-persistence` instead.
|
62
|
-
*/
|
63
|
-
function pessimisticUpdate(opts) {
|
64
|
-
return (source) => {
|
65
|
-
return source.pipe(mapActionAndState(), concatMap(runWithErrorHandling(opts.run, opts.onError)));
|
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
|
-
* @deprecated This will be removed in Nx v21. Import `optimisticUpdate` from `@ngrx/router-store/data-persistence` instead.
|
126
|
-
*/
|
127
|
-
function optimisticUpdate(opts) {
|
128
|
-
return (source) => {
|
129
|
-
return source.pipe(mapActionAndState(), concatMap(runWithErrorHandling(opts.run, opts.undoAction)));
|
130
|
-
};
|
131
|
-
}
|
132
|
-
/**
|
133
|
-
* @whatItDoes Handles data fetching.
|
134
|
-
*
|
135
|
-
* Data fetching implemented naively suffers from race conditions and poor error handling.
|
136
|
-
*
|
137
|
-
* `fetch` addresses these problems. It runs all fetches in order, which removes race conditions
|
138
|
-
* and forces the developer to handle errors.
|
139
|
-
*
|
140
|
-
* ## Example:
|
141
|
-
*
|
142
|
-
* ```typescript
|
143
|
-
* @Injectable()
|
144
|
-
* class TodoEffects {
|
145
|
-
* loadTodos$ = createEffect(() =>
|
146
|
-
* this.actions$.pipe(
|
147
|
-
* ofType('GET_TODOS'),
|
148
|
-
* fetch({
|
149
|
-
* // provides an action
|
150
|
-
* run: (a: GetTodos) => {
|
151
|
-
* return this.backend.getAll().pipe(
|
152
|
-
* map((response) => ({
|
153
|
-
* type: 'TODOS',
|
154
|
-
* todos: response.todos,
|
155
|
-
* }))
|
156
|
-
* );
|
157
|
-
* },
|
158
|
-
* onError: (action: GetTodos, error: any) => {
|
159
|
-
* // dispatch an undo action to undo the changes in the client state
|
160
|
-
* return null;
|
161
|
-
* },
|
162
|
-
* })
|
163
|
-
* )
|
164
|
-
* );
|
165
|
-
*
|
166
|
-
* constructor(private actions$: Actions, private backend: Backend) {}
|
167
|
-
* }
|
168
|
-
* ```
|
169
|
-
*
|
170
|
-
* This is correct, but because it set the concurrency to 1, it may not be performant.
|
171
|
-
*
|
172
|
-
* To fix that, you can provide the `id` function, like this:
|
173
|
-
*
|
174
|
-
* ```typescript
|
175
|
-
* @Injectable()
|
176
|
-
* class TodoEffects {
|
177
|
-
* loadTodo$ = createEffect(() =>
|
178
|
-
* this.actions$.pipe(
|
179
|
-
* ofType('GET_TODO'),
|
180
|
-
* fetch({
|
181
|
-
* id: (todo: GetTodo) => {
|
182
|
-
* return todo.id;
|
183
|
-
* },
|
184
|
-
* // provides an action
|
185
|
-
* run: (todo: GetTodo) => {
|
186
|
-
* return this.backend.getTodo(todo.id).map((response) => ({
|
187
|
-
* type: 'LOAD_TODO_SUCCESS',
|
188
|
-
* todo: response.todo,
|
189
|
-
* }));
|
190
|
-
* },
|
191
|
-
* onError: (action: GetTodo, error: any) => {
|
192
|
-
* // dispatch an undo action to undo the changes in the client state
|
193
|
-
* return null;
|
194
|
-
* },
|
195
|
-
* })
|
196
|
-
* )
|
197
|
-
* );
|
198
|
-
*
|
199
|
-
* constructor(private actions$: Actions, private backend: Backend) {}
|
200
|
-
* }
|
201
|
-
* ```
|
202
|
-
*
|
203
|
-
* With this setup, the requests for Todo 1 will run concurrently with the requests for Todo 2.
|
204
|
-
*
|
205
|
-
* In addition, if there are multiple requests for Todo 1 scheduled, it will only run the last one.
|
206
|
-
*
|
207
|
-
* @param opts
|
208
|
-
*
|
209
|
-
* @deprecated This will be removed in Nx v21. Import `fetch` from `@ngrx/router-store/data-persistence` instead.
|
210
|
-
*/
|
211
|
-
function fetch(opts) {
|
212
|
-
return (source) => {
|
213
|
-
if (opts.id) {
|
214
|
-
const groupedFetches = source.pipe(mapActionAndState(), groupBy(([action, ...store]) => {
|
215
|
-
return opts.id(action, ...store);
|
216
|
-
}));
|
217
|
-
return groupedFetches.pipe(mergeMap((pairs) => pairs.pipe(switchMap(runWithErrorHandling(opts.run, opts.onError)))));
|
218
|
-
}
|
219
|
-
return source.pipe(mapActionAndState(), concatMap(runWithErrorHandling(opts.run, opts.onError)));
|
220
|
-
};
|
221
|
-
}
|
222
|
-
/**
|
223
|
-
* @whatItDoes Handles data fetching as part of router navigation.
|
224
|
-
*
|
225
|
-
* Data fetching implemented naively suffers from race conditions and poor error handling.
|
226
|
-
*
|
227
|
-
* `navigation` addresses these problems.
|
228
|
-
*
|
229
|
-
* It checks if an activated router state contains the passed in component type, and, if it does, runs the `run`
|
230
|
-
* callback. It provides the activated snapshot associated with the component and the current state. And it only runs
|
231
|
-
* the last request.
|
232
|
-
*
|
233
|
-
* ## Example:
|
234
|
-
*
|
235
|
-
* ```typescript
|
236
|
-
* @Injectable()
|
237
|
-
* class TodoEffects {
|
238
|
-
* loadTodo$ = createEffect(() =>
|
239
|
-
* this.actions$.pipe(
|
240
|
-
* // listens for the routerNavigation action from @ngrx/router-store
|
241
|
-
* navigation(TodoComponent, {
|
242
|
-
* run: (activatedRouteSnapshot: ActivatedRouteSnapshot) => {
|
243
|
-
* return this.backend
|
244
|
-
* .fetchTodo(activatedRouteSnapshot.params['id'])
|
245
|
-
* .pipe(
|
246
|
-
* map((todo) => ({
|
247
|
-
* type: 'LOAD_TODO_SUCCESS',
|
248
|
-
* todo: todo,
|
249
|
-
* }))
|
250
|
-
* );
|
251
|
-
* },
|
252
|
-
* onError: (
|
253
|
-
* activatedRouteSnapshot: ActivatedRouteSnapshot,
|
254
|
-
* error: any
|
255
|
-
* ) => {
|
256
|
-
* // we can log and error here and return null
|
257
|
-
* // we can also navigate back
|
258
|
-
* return null;
|
259
|
-
* },
|
260
|
-
* })
|
261
|
-
* )
|
262
|
-
* );
|
263
|
-
*
|
264
|
-
* constructor(private actions$: Actions, private backend: Backend) {}
|
265
|
-
* }
|
266
|
-
* ```
|
267
|
-
*
|
268
|
-
* @param component
|
269
|
-
* @param opts
|
270
|
-
*
|
271
|
-
* @deprecated This will be removed in Nx v21. Import `navigation` from `@ngrx/router-store/data-persistence` instead.
|
272
|
-
*/
|
273
|
-
function navigation(component, opts) {
|
274
|
-
return (source) => {
|
275
|
-
const nav = source.pipe(mapActionAndState(), filter(([action]) => isStateSnapshot(action)), map(([action, ...slices]) => {
|
276
|
-
if (!isStateSnapshot(action)) {
|
277
|
-
// Because of the above filter we'll never get here,
|
278
|
-
// but this properly type narrows `action`
|
279
|
-
return;
|
280
|
-
}
|
281
|
-
return [
|
282
|
-
findSnapshot(component, action.payload.routerState.root),
|
283
|
-
...slices,
|
284
|
-
];
|
285
|
-
}), filter(([snapshot]) => !!snapshot));
|
286
|
-
return nav.pipe(switchMap(runWithErrorHandling(opts.run, opts.onError)));
|
287
|
-
};
|
288
|
-
}
|
289
|
-
function isStateSnapshot(action) {
|
290
|
-
return action.type === ROUTER_NAVIGATION;
|
291
|
-
}
|
292
|
-
function runWithErrorHandling(run, onError) {
|
293
|
-
return ([action, ...slices]) => {
|
294
|
-
try {
|
295
|
-
const r = wrapIntoObservable(run(action, ...slices));
|
296
|
-
return r.pipe(catchError((e) => wrapIntoObservable(onError(action, e))));
|
297
|
-
}
|
298
|
-
catch (e) {
|
299
|
-
return wrapIntoObservable(onError(action, e));
|
300
|
-
}
|
301
|
-
};
|
302
|
-
}
|
303
|
-
/**
|
304
|
-
* @whatItDoes maps Observable<Action | [Action, State]> to
|
305
|
-
* Observable<[Action, State]>
|
306
|
-
*/
|
307
|
-
function mapActionAndState() {
|
308
|
-
return (source) => {
|
309
|
-
return source.pipe(map((value) => normalizeActionAndState(value)));
|
310
|
-
};
|
311
|
-
}
|
312
|
-
/**
|
313
|
-
* @whatItDoes Normalizes either a bare action or an array of action and slices
|
314
|
-
* into an array of action and slices (or undefined)
|
315
|
-
*/
|
316
|
-
function normalizeActionAndState(args) {
|
317
|
-
let action, slices;
|
318
|
-
if (args instanceof Array) {
|
319
|
-
[action, ...slices] = args;
|
320
|
-
}
|
321
|
-
else {
|
322
|
-
slices = [];
|
323
|
-
action = args;
|
324
|
-
}
|
325
|
-
return [action, ...slices];
|
326
|
-
}
|
327
|
-
function findSnapshot(component, s) {
|
328
|
-
if (s.routeConfig && s.routeConfig.component === component) {
|
329
|
-
return s;
|
330
|
-
}
|
331
|
-
for (const c of s.children) {
|
332
|
-
const ss = findSnapshot(component, c);
|
333
|
-
if (ss) {
|
334
|
-
return ss;
|
335
|
-
}
|
336
|
-
}
|
337
|
-
return null;
|
338
|
-
}
|
339
|
-
function wrapIntoObservable(obj) {
|
340
|
-
if (isObservable(obj)) {
|
341
|
-
return obj;
|
342
|
-
}
|
343
|
-
else if (!obj) {
|
344
|
-
return of();
|
345
|
-
}
|
346
|
-
else {
|
347
|
-
return of(obj);
|
348
|
-
}
|
349
|
-
}
|
350
|
-
|
351
1
|
/**
|
352
2
|
* Generated bundle index. Do not edit.
|
353
3
|
*/
|
354
|
-
|
355
|
-
export { fetch, navigation, optimisticUpdate, pessimisticUpdate };
|
356
4
|
//# sourceMappingURL=nx-angular.mjs.map
|
@@ -1 +1 @@
|
|
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 * @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 *\n * @deprecated This will be removed in Nx v21. Import `pessimisticUpdate` from `@ngrx/router-store/data-persistence` instead.\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 * @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 *\n * @deprecated This will be removed in Nx v21. Import `optimisticUpdate` from `@ngrx/router-store/data-persistence` instead.\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 * @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 *\n * @deprecated This will be removed in Nx v21. Import `fetch` from `@ngrx/router-store/data-persistence` instead.\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 *\n * @deprecated This will be removed in Nx v21. Import `navigation` from `@ngrx/router-store/data-persistence` instead.\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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDG;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;AACH,KAAC;AACH;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;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BAAiB,GAAA;IACxB,OAAO,CAAC,MAAkD,KAAI;AAC5D,QAAA,OAAO,MAAM,CAAC,IAAI,CAChB,GAAG,CAAC,CAAC,KAAK,KAAK,uBAAuB,CAAC,KAAK,CAAc,CAAC,CAC5D;AACH,KAAC;AACH;AAEA;;;AAGG;AACH,SAAS,uBAAuB,CAC9B,IAAoC,EAAA;IAEpC,IAAI,MAAS,EAAE,MAAS;AAExB,IAAA,IAAI,IAAI,YAAY,KAAK,EAAE;AACzB,QAAA,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI;;SACrB;QACL,MAAM,GAAG,EAAO;QAChB,MAAM,GAAG,IAAI;;AAGf,IAAA,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;AAC5B;AAEA,SAAS,YAAY,CACnB,SAAoB,EACpB,CAAyB,EAAA;AAEzB,IAAA,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,CAAC,SAAS,KAAK,SAAS,EAAE;AAC1D,QAAA,OAAO,CAAC;;AAEV,IAAA,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;QAC1B,MAAM,EAAE,GAAG,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC;QACrC,IAAI,EAAE,EAAE;AACN,YAAA,OAAO,EAAE;;;AAGb,IAAA,OAAO,IAAI;AACb;AAEA,SAAS,kBAAkB,CAAI,GAA6B,EAAA;AAC1D,IAAA,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE;AACrB,QAAA,OAAO,GAAG;;SACL,IAAI,CAAC,GAAG,EAAE;QACf,OAAO,EAAE,EAAE;;SACN;AACL,QAAA,OAAO,EAAE,CAAC,GAAQ,CAAC;;AAEvB;;ACpcA;;AAEG;;;;"}
|
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"}
|
package/generators.json
CHANGED
@@ -38,6 +38,11 @@
|
|
38
38
|
"schema": "./src/generators/convert-to-application-executor/schema.json",
|
39
39
|
"description": "Converts projects to use the `@nx/angular:application` executor or the `@angular-devkit/build-angular:application` builder."
|
40
40
|
},
|
41
|
+
"convert-to-rspack": {
|
42
|
+
"factory": "./src/generators/convert-to-rspack/convert-to-rspack",
|
43
|
+
"schema": "./src/generators/convert-to-rspack/schema.json",
|
44
|
+
"description": "Converts Angular Webpack projects to use Rspack."
|
45
|
+
},
|
41
46
|
"directive": {
|
42
47
|
"factory": "./src/generators/directive/directive",
|
43
48
|
"schema": "./src/generators/directive/schema.json",
|
@@ -81,7 +86,7 @@
|
|
81
86
|
"schema": "./src/generators/move/schema.json",
|
82
87
|
"aliases": ["mv"],
|
83
88
|
"description": "Moves an Angular application or library to another folder within the workspace and updates the project configuration.",
|
84
|
-
"x-deprecated": "Use the `@nx/workspace:move` generator instead. This generator will be removed in Nx
|
89
|
+
"x-deprecated": "Use the `@nx/workspace:move` generator instead. This generator will be removed in Nx v22."
|
85
90
|
},
|
86
91
|
"convert-to-with-mf": {
|
87
92
|
"factory": "./src/generators/convert-to-with-mf/convert-to-with-mf",
|
@@ -105,7 +110,7 @@
|
|
105
110
|
"factory": "./src/generators/ngrx/ngrx",
|
106
111
|
"schema": "./src/generators/ngrx/schema.json",
|
107
112
|
"description": "Adds NgRx support to an application or library.",
|
108
|
-
"x-deprecated": "
|
113
|
+
"x-deprecated": "Use the 'ngrx-root-store' and 'ngrx-feature-store' generators instead. It will be removed in Nx v22."
|
109
114
|
},
|
110
115
|
"ngrx-feature-store": {
|
111
116
|
"factory": "./src/generators/ngrx-feature-store/ngrx-feature-store",
|
package/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export {
|
1
|
+
export {};
|