@nx/angular 16.1.4 → 16.2.0-beta.1
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/generators.d.ts +2 -0
- package/generators.js +2 -0
- package/generators.js.map +1 -1
- package/generators.json +14 -2
- package/migrations.json +21 -0
- package/package.json +10 -11
- package/src/executors/ng-packagr-lite/ng-packagr-adjustments/ng-package/entry-point/write-package.transform.js +3 -4
- package/src/executors/ng-packagr-lite/ng-packagr-adjustments/ng-package/entry-point/write-package.transform.js.map +1 -1
- package/src/generators/application/lib/normalize-options.js +3 -2
- package/src/generators/application/lib/normalize-options.js.map +1 -1
- package/src/generators/component/lib/validate-options.js +1 -2
- package/src/generators/component/lib/validate-options.js.map +1 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +30 -28
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js.map +1 -1
- package/src/generators/directive/lib/validate-options.js +1 -2
- package/src/generators/directive/lib/validate-options.js.map +1 -1
- package/src/generators/host/host.js +1 -0
- package/src/generators/host/host.js.map +1 -1
- package/src/generators/library/files/base/package.json__tpl__ +1 -1
- package/src/generators/library/lib/create-files.js +1 -2
- package/src/generators/library/lib/create-files.js.map +1 -1
- package/src/generators/library/lib/normalize-options.js +6 -4
- package/src/generators/library/lib/normalize-options.js.map +1 -1
- package/src/generators/ng-add/migrate-from-angular-cli.d.ts +1 -1
- package/src/generators/ng-add/migrate-from-angular-cli.js +1 -2
- package/src/generators/ng-add/migrate-from-angular-cli.js.map +1 -1
- package/src/generators/ng-add/schema.d.ts +3 -1
- package/src/generators/ng-add/schema.json +1 -1
- package/src/generators/ng-add/utilities/index.d.ts +0 -1
- package/src/generators/ng-add/utilities/index.js +0 -1
- package/src/generators/ng-add/utilities/index.js.map +1 -1
- package/src/generators/ng-add/utilities/workspace.js +11 -6
- package/src/generators/ng-add/utilities/workspace.js.map +1 -1
- package/src/generators/ngrx/schema.json +1 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.actions.ts__tmpl__ +16 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.effects.spec.ts__tmpl__ +37 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.effects.ts__tmpl__ +22 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.facade.spec.ts__tmpl__ +99 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.facade.ts__tmpl__ +27 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.models.ts__tmpl__ +7 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.reducer.spec.ts__tmpl__ +37 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.reducer.ts__tmpl__ +41 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.selectors.spec.ts__tmpl__ +58 -0
- package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.selectors.ts__tmpl__ +38 -0
- package/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.effects.ts__tmpl__ +22 -0
- package/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.facade.ts__tmpl__ +27 -0
- package/src/generators/ngrx-feature-store/lib/add-exports-barrel.d.ts +3 -0
- package/src/generators/ngrx-feature-store/lib/add-exports-barrel.js +39 -0
- package/src/generators/ngrx-feature-store/lib/add-exports-barrel.js.map +1 -0
- package/src/generators/ngrx-feature-store/lib/add-imports.d.ts +3 -0
- package/src/generators/ngrx-feature-store/lib/add-imports.js +103 -0
- package/src/generators/ngrx-feature-store/lib/add-imports.js.map +1 -0
- package/src/generators/ngrx-feature-store/lib/add-ngrx-to-package-json.d.ts +3 -0
- package/src/generators/ngrx-feature-store/lib/add-ngrx-to-package-json.js +28 -0
- package/src/generators/ngrx-feature-store/lib/add-ngrx-to-package-json.js.map +1 -0
- package/src/generators/ngrx-feature-store/lib/generate-files.d.ts +3 -0
- package/src/generators/ngrx-feature-store/lib/generate-files.js +20 -0
- package/src/generators/ngrx-feature-store/lib/generate-files.js.map +1 -0
- package/src/generators/ngrx-feature-store/lib/index.d.ts +6 -0
- package/src/generators/ngrx-feature-store/lib/index.js +10 -0
- package/src/generators/ngrx-feature-store/lib/index.js.map +1 -0
- package/src/generators/ngrx-feature-store/lib/normalize-options.d.ts +7 -0
- package/src/generators/ngrx-feature-store/lib/normalize-options.js +20 -0
- package/src/generators/ngrx-feature-store/lib/normalize-options.js.map +1 -0
- package/src/generators/ngrx-feature-store/lib/validate-options.d.ts +3 -0
- package/src/generators/ngrx-feature-store/lib/validate-options.js +35 -0
- package/src/generators/ngrx-feature-store/lib/validate-options.js.map +1 -0
- package/src/generators/ngrx-feature-store/ngrx-feature-store.d.ts +5 -0
- package/src/generators/ngrx-feature-store/ngrx-feature-store.js +30 -0
- package/src/generators/ngrx-feature-store/ngrx-feature-store.js.map +1 -0
- package/src/generators/ngrx-feature-store/schema.d.ts +12 -0
- package/src/generators/ngrx-feature-store/schema.json +72 -0
- package/src/generators/ngrx-root-store/lib/add-imports.d.ts +3 -0
- package/src/generators/ngrx-root-store/lib/add-imports.js +80 -0
- package/src/generators/ngrx-root-store/lib/add-imports.js.map +1 -0
- package/src/generators/ngrx-root-store/lib/add-ngrx-to-package-json.d.ts +3 -0
- package/src/generators/ngrx-root-store/lib/add-ngrx-to-package-json.js +28 -0
- package/src/generators/ngrx-root-store/lib/add-ngrx-to-package-json.js.map +1 -0
- package/src/generators/ngrx-root-store/lib/index.d.ts +4 -0
- package/src/generators/ngrx-root-store/lib/index.js +8 -0
- package/src/generators/ngrx-root-store/lib/index.js.map +1 -0
- package/src/generators/ngrx-root-store/lib/normalize-options.d.ts +7 -0
- package/src/generators/ngrx-root-store/lib/normalize-options.js +37 -0
- package/src/generators/ngrx-root-store/lib/normalize-options.js.map +1 -0
- package/src/generators/ngrx-root-store/lib/validate-options.d.ts +3 -0
- package/src/generators/ngrx-root-store/lib/validate-options.js +33 -0
- package/src/generators/ngrx-root-store/lib/validate-options.js.map +1 -0
- package/src/generators/ngrx-root-store/ngrx-root-store.d.ts +5 -0
- package/src/generators/ngrx-root-store/ngrx-root-store.js +40 -0
- package/src/generators/ngrx-root-store/ngrx-root-store.js.map +1 -0
- package/src/generators/ngrx-root-store/schema.d.ts +10 -0
- package/src/generators/ngrx-root-store/schema.json +66 -0
- package/src/generators/pipe/lib/validate-options.js +1 -2
- package/src/generators/pipe/lib/validate-options.js.map +1 -1
- package/src/generators/remote/remote.js +1 -0
- package/src/generators/remote/remote.js.map +1 -1
- package/src/generators/scam/lib/validate-options.js +1 -2
- package/src/generators/scam/lib/validate-options.js.map +1 -1
- package/src/generators/scam-directive/lib/validate-options.js +1 -2
- package/src/generators/scam-directive/lib/validate-options.js.map +1 -1
- package/src/generators/scam-pipe/lib/validate-options.js +1 -2
- package/src/generators/scam-pipe/lib/validate-options.js.map +1 -1
- package/src/generators/setup-mf/lib/add-remote-entry.js +0 -3
- package/src/generators/setup-mf/lib/add-remote-entry.js.map +1 -1
- package/src/generators/setup-mf/lib/index.d.ts +1 -0
- package/src/generators/setup-mf/lib/index.js +1 -0
- package/src/generators/setup-mf/lib/index.js.map +1 -1
- package/src/generators/setup-mf/lib/normalize-options.d.ts +3 -0
- package/src/generators/setup-mf/lib/normalize-options.js +10 -0
- package/src/generators/setup-mf/lib/normalize-options.js.map +1 -0
- package/src/generators/setup-mf/lib/remove-dead-code-from-remote.d.ts +1 -1
- package/src/generators/setup-mf/lib/remove-dead-code-from-remote.js +9 -13
- package/src/generators/setup-mf/lib/remove-dead-code-from-remote.js.map +1 -1
- package/src/generators/setup-mf/schema.d.ts +8 -1
- package/src/generators/setup-mf/setup-mf.d.ts +1 -1
- package/src/generators/setup-mf/setup-mf.js +3 -4
- package/src/generators/setup-mf/setup-mf.js.map +1 -1
- package/src/generators/utils/path.d.ts +0 -1
- package/src/generators/utils/path.js +1 -16
- package/src/generators/utils/path.js.map +1 -1
- package/src/generators/utils/project.d.ts +3 -1
- package/src/generators/utils/project.js +17 -7
- package/src/generators/utils/project.js.map +1 -1
- package/src/generators/utils/selector.js +2 -2
- package/src/generators/utils/selector.js.map +1 -1
- package/src/generators/utils/testing.js +24 -7
- package/src/generators/utils/testing.js.map +1 -1
- package/src/generators/utils/validations.d.ts +1 -0
- package/src/generators/utils/validations.js +17 -1
- package/src/generators/utils/validations.js.map +1 -1
- package/src/migrations/update-16-1-0/extract-standalone-config-from-bootstrap.js +45 -25
- package/src/migrations/update-16-1-0/extract-standalone-config-from-bootstrap.js.map +1 -1
- package/src/migrations/update-16-2-0/switch-data-persistence-operators-imports-to-ngrx-router-store.d.ts +2 -0
- package/src/migrations/update-16-2-0/switch-data-persistence-operators-imports-to-ngrx-router-store.js +124 -0
- package/src/migrations/update-16-2-0/switch-data-persistence-operators-imports-to-ngrx-router-store.js.map +1 -0
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/src/generators/cypress-component-configuration/files/cypress/support/commands.ts__tpl__ +0 -42
- package/src/generators/cypress-component-configuration/files/cypress.config.ts__tpl__ +0 -6
- package/src/generators/ng-add/utilities/normalize-options.d.ts +0 -4
- package/src/generators/ng-add/utilities/normalize-options.js +0 -30
- package/src/generators/ng-add/utilities/normalize-options.js.map +0 -1
|
@@ -27,11 +27,12 @@ function validateWorkspace(tree) {
|
|
|
27
27
|
exports.validateWorkspace = validateWorkspace;
|
|
28
28
|
function createNxJson(tree, options, defaultProject) {
|
|
29
29
|
var _a;
|
|
30
|
-
const { npmScope } = options;
|
|
31
30
|
const targets = getWorkspaceCommonTargets(tree);
|
|
32
|
-
(0, devkit_1.writeJson)(tree, 'nx.json',
|
|
31
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', {
|
|
32
|
+
affected: {
|
|
33
33
|
defaultBase: (_a = options.defaultBase) !== null && _a !== void 0 ? _a : (0, default_base_1.deduceDefaultBase)(),
|
|
34
|
-
},
|
|
34
|
+
},
|
|
35
|
+
tasksRunnerOptions: {
|
|
35
36
|
default: {
|
|
36
37
|
runner: 'nx/tasks-runners/default',
|
|
37
38
|
options: {
|
|
@@ -43,7 +44,8 @@ function createNxJson(tree, options, defaultProject) {
|
|
|
43
44
|
].filter(Boolean),
|
|
44
45
|
},
|
|
45
46
|
},
|
|
46
|
-
},
|
|
47
|
+
},
|
|
48
|
+
namedInputs: {
|
|
47
49
|
sharedGlobals: [],
|
|
48
50
|
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
|
49
51
|
production: [
|
|
@@ -57,7 +59,8 @@ function createNxJson(tree, options, defaultProject) {
|
|
|
57
59
|
: []),
|
|
58
60
|
targets.lint ? '!{projectRoot}/.eslintrc.json' : undefined,
|
|
59
61
|
].filter(Boolean),
|
|
60
|
-
},
|
|
62
|
+
},
|
|
63
|
+
targetDefaults: {
|
|
61
64
|
build: {
|
|
62
65
|
dependsOn: ['^build'],
|
|
63
66
|
inputs: ['production', '^production'],
|
|
@@ -77,7 +80,9 @@ function createNxJson(tree, options, defaultProject) {
|
|
|
77
80
|
inputs: ['default', '^production'],
|
|
78
81
|
}
|
|
79
82
|
: undefined,
|
|
80
|
-
},
|
|
83
|
+
},
|
|
84
|
+
defaultProject,
|
|
85
|
+
});
|
|
81
86
|
}
|
|
82
87
|
exports.createNxJson = createNxJson;
|
|
83
88
|
function getWorkspaceCommonTargets(tree) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../../../../../../../packages/angular/src/generators/ng-add/utilities/workspace.ts"],"names":[],"mappings":";;;;AACA,uCASoB;AACpB,uCAAuD;AACvD,+BAGgB;AAChB,4DAA8D;AAC9D,wDAA4D;AAC5D,8DAA0D;AAC1D,sDAA0E;AAK1E,SAAgB,iBAAiB,CAAC,IAAU;IAC1C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;QAChC,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;KAC5D;IACD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;QAChC,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;KAC5D;IAED,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;QAClB,OAAO;KACR;IAED,MAAM,IAAI,KAAK,CAAC;;MAEZ,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAhBD,8CAgBC;AAED,SAAgB,YAAY,CAC1B,IAAU,EACV,OAAyB,EACzB,cAAkC;;IAElC,MAAM,
|
|
1
|
+
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../../../../../../../packages/angular/src/generators/ng-add/utilities/workspace.ts"],"names":[],"mappings":";;;;AACA,uCASoB;AACpB,uCAAuD;AACvD,+BAGgB;AAChB,4DAA8D;AAC9D,wDAA4D;AAC5D,8DAA0D;AAC1D,sDAA0E;AAK1E,SAAgB,iBAAiB,CAAC,IAAU;IAC1C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;QAChC,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;KAC5D;IACD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;QAChC,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;KAC5D;IAED,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;QAClB,OAAO;KACR;IAED,MAAM,IAAI,KAAK,CAAC;;MAEZ,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAhBD,8CAgBC;AAED,SAAgB,YAAY,CAC1B,IAAU,EACV,OAAyB,EACzB,cAAkC;;IAElC,MAAM,OAAO,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAC;IAEhD,IAAA,kBAAS,EAAsB,IAAI,EAAE,SAAS,EAAE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,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;oBAC7C,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBACtC;YACH,CAAC,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QACd,CAAC,CACF,CAAC;KACH;SAAM;QACL,IAAA,kBAAS,EAAC,IAAI,EAAE,yBAAyB,EAAE;YACzC,eAAe;SAChB,CAAC,CAAC;KACJ;AACH,CAAC;AA3BD,8EA2BC;AAED,SAAgB,iBAAiB,CAAC,IAAU;IAC1C,MAAM,QAAQ,GAAG,IAAA,0BAAW,EAAC,IAAA,iBAAQ,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC;IACtE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE;QACjC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;KAC7B;AACH,CAAC;AALD,8CAKC;AAED,SAAgB,6BAA6B,CAAC,IAAU;IACtD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE;QACpE,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;KAC9B;IACD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE;QACpE,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;KAC9B;AACH,CAAC;AAPD,sEAOC"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"$id": "NxNgrxGenerator",
|
|
4
4
|
"title": "Add NgRx support to an application or library.",
|
|
5
5
|
"description": "Adds NgRx support to an application or library.",
|
|
6
|
+
"x-deprecated": "This generator is deprecated and will be removed in a future version of Nx. Use the 'ngrx-root-store' and 'ngrx-feature-store' generators instead.",
|
|
6
7
|
"cli": "nx",
|
|
7
8
|
"type": "object",
|
|
8
9
|
"examples": [
|
package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.actions.ts__tmpl__
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createAction, props } from '@ngrx/store';
|
|
2
|
+
import { <%= className %>Entity } from './<%= fileName %>.models';
|
|
3
|
+
|
|
4
|
+
export const init<%= className %> = createAction(
|
|
5
|
+
'[<%= className %> Page] Init'
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
export const load<%= className %>Success = createAction(
|
|
9
|
+
'[<%= className %>/API] Load <%= className %> Success',
|
|
10
|
+
props<{ <%= propertyName %>: <%= className %>Entity[] }>()
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const load<%= className %>Failure = createAction(
|
|
14
|
+
'[<%= className %>/API] Load <%= className %> Failure',
|
|
15
|
+
props<{ error: any }>()
|
|
16
|
+
);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { provideMockActions } from '@ngrx/effects/testing';
|
|
3
|
+
import { Action } from '@ngrx/store';
|
|
4
|
+
import { provideMockStore } from '@ngrx/store/testing';
|
|
5
|
+
import { hot } from 'jasmine-marbles';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
7
|
+
|
|
8
|
+
import * as <%= className %>Actions from './<%= fileName %>.actions';
|
|
9
|
+
import { <%= className %>Effects } from './<%= fileName %>.effects';
|
|
10
|
+
|
|
11
|
+
describe('<%= className %>Effects', () => {
|
|
12
|
+
let actions: Observable<Action>;
|
|
13
|
+
let effects: <%= className %>Effects;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
TestBed.configureTestingModule({
|
|
17
|
+
imports: [],
|
|
18
|
+
providers: [
|
|
19
|
+
<%= className %>Effects,
|
|
20
|
+
provideMockActions(() => actions),
|
|
21
|
+
provideMockStore()
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
effects = TestBed.inject(<%= className %>Effects);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('init$', () => {
|
|
29
|
+
it('should work', () => {
|
|
30
|
+
actions = hot('-a-|', { a: <%= className %>Actions.init<%= className %>() });
|
|
31
|
+
|
|
32
|
+
const expected = hot('-a-|', { a: <%= className %>Actions.load<%= className %>Success({ <%= propertyName %>: [] }) });
|
|
33
|
+
|
|
34
|
+
expect(effects.init$).toBeObservable(expected);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.effects.ts__tmpl__
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Injectable, inject } from '@angular/core';
|
|
2
|
+
import { createEffect, Actions, ofType } from '@ngrx/effects';<% if (!importFromOperators) { %>
|
|
3
|
+
import { switchMap, catchError, of } from 'rxjs';<% } else { %>
|
|
4
|
+
import { of } from 'rxjs';
|
|
5
|
+
import { switchMap, catchError } from 'rxjs/operators';<% } %>
|
|
6
|
+
import * as <%= className %>Actions from './<%= fileName %>.actions';
|
|
7
|
+
import * as <%= className %>Feature from './<%= fileName %>.reducer';
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class <%= className %>Effects {
|
|
11
|
+
private actions$ = inject(Actions);
|
|
12
|
+
|
|
13
|
+
init$ = createEffect(() => this.actions$.pipe(
|
|
14
|
+
ofType(<%= className %>Actions.init<%= className %>),
|
|
15
|
+
switchMap(() => of(<%= className %>Actions.load<%= className %>Success({ <%= propertyName %>: [] }))),
|
|
16
|
+
catchError((error) => {
|
|
17
|
+
console.error('Error', error);
|
|
18
|
+
return of(<%= className %>Actions.load<%= className %>Failure({ error }));
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
));
|
|
22
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { TestBed } from '@angular/core/testing';
|
|
3
|
+
import { EffectsModule } from '@ngrx/effects';
|
|
4
|
+
import { StoreModule, Store } from '@ngrx/store';
|
|
5
|
+
import { readFirst } from '@nx/angular/testing';
|
|
6
|
+
|
|
7
|
+
import * as <%= className %>Actions from './<%= fileName %>.actions';
|
|
8
|
+
import { <%= className %>Effects } from './<%= fileName %>.effects';
|
|
9
|
+
import { <%= className %>Facade } from './<%= fileName %>.facade';
|
|
10
|
+
import { <%= className %>Entity } from './<%= fileName %>.models';
|
|
11
|
+
import {
|
|
12
|
+
<%= constantName %>_FEATURE_KEY,
|
|
13
|
+
<%= className %>State,
|
|
14
|
+
initial<%= className %>State,
|
|
15
|
+
<%= propertyName %>Reducer
|
|
16
|
+
} from './<%= fileName %>.reducer';
|
|
17
|
+
import * as <%= className %>Selectors from './<%= fileName %>.selectors';
|
|
18
|
+
|
|
19
|
+
interface TestSchema {
|
|
20
|
+
<%= propertyName %>: <%= className %>State;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('<%= className %>Facade', () => {
|
|
24
|
+
let facade: <%= className %>Facade;
|
|
25
|
+
let store: Store<TestSchema>;
|
|
26
|
+
const create<%= className %>Entity = (id: string, name = ''): <%= className %>Entity => ({
|
|
27
|
+
id,
|
|
28
|
+
name: name || `name-${id}`
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('used in NgModule', () => {
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
@NgModule({
|
|
34
|
+
imports: [
|
|
35
|
+
StoreModule.forFeature(<%= constantName %>_FEATURE_KEY, <%= propertyName %>Reducer),
|
|
36
|
+
EffectsModule.forFeature([<%= className %>Effects])
|
|
37
|
+
],
|
|
38
|
+
providers: [<%= className %>Facade]
|
|
39
|
+
})
|
|
40
|
+
class CustomFeatureModule {}
|
|
41
|
+
|
|
42
|
+
@NgModule({
|
|
43
|
+
imports: [
|
|
44
|
+
StoreModule.forRoot({}),
|
|
45
|
+
EffectsModule.forRoot([]),
|
|
46
|
+
CustomFeatureModule,
|
|
47
|
+
]
|
|
48
|
+
})
|
|
49
|
+
class RootModule {}
|
|
50
|
+
TestBed.configureTestingModule({ imports: [RootModule] });
|
|
51
|
+
|
|
52
|
+
store = TestBed.inject(Store);
|
|
53
|
+
facade = TestBed.inject(<%= className %>Facade);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The initially generated facade::loadAll() returns empty array
|
|
58
|
+
*/
|
|
59
|
+
it('loadAll() should return empty list with loaded == true', async () => {
|
|
60
|
+
let list = await readFirst(facade.all<%= className %>$);
|
|
61
|
+
let isLoaded = await readFirst(facade.loaded$);
|
|
62
|
+
|
|
63
|
+
expect(list.length).toBe(0);
|
|
64
|
+
expect(isLoaded).toBe(false);
|
|
65
|
+
|
|
66
|
+
facade.init();
|
|
67
|
+
|
|
68
|
+
list = await readFirst(facade.all<%= className %>$);
|
|
69
|
+
isLoaded = await readFirst(facade.loaded$);
|
|
70
|
+
|
|
71
|
+
expect(list.length).toBe(0);
|
|
72
|
+
expect(isLoaded).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Use `load<%= className %>Success` to manually update list
|
|
77
|
+
*/
|
|
78
|
+
it('all<%= className %>$ should return the loaded list; and loaded flag == true', async () => {
|
|
79
|
+
let list = await readFirst(facade.all<%= className %>$);
|
|
80
|
+
let isLoaded = await readFirst(facade.loaded$);
|
|
81
|
+
|
|
82
|
+
expect(list.length).toBe(0);
|
|
83
|
+
expect(isLoaded).toBe(false);
|
|
84
|
+
|
|
85
|
+
store.dispatch(<%= className %>Actions.load<%= className %>Success({
|
|
86
|
+
<%= propertyName %>: [
|
|
87
|
+
create<%= className %>Entity('AAA'),
|
|
88
|
+
create<%= className %>Entity('BBB')
|
|
89
|
+
]})
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
list = await readFirst(facade.all<%= className %>$);
|
|
93
|
+
isLoaded = await readFirst(facade.loaded$);
|
|
94
|
+
|
|
95
|
+
expect(list.length).toBe(2);
|
|
96
|
+
expect(isLoaded).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.facade.ts__tmpl__
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Injectable, inject } from '@angular/core';
|
|
2
|
+
import { select, Store, Action } from '@ngrx/store';
|
|
3
|
+
|
|
4
|
+
import * as <%= className %>Actions from './<%= fileName %>.actions';
|
|
5
|
+
import * as <%= className %>Feature from './<%= fileName %>.reducer';
|
|
6
|
+
import * as <%= className %>Selectors from './<%= fileName %>.selectors';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class <%= className %>Facade {
|
|
10
|
+
private readonly store = inject(Store);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Combine pieces of state using createSelector,
|
|
14
|
+
* and expose them as observables through the facade.
|
|
15
|
+
*/
|
|
16
|
+
loaded$ = this.store.pipe(select(<%= className %>Selectors.select<%= className %>Loaded));
|
|
17
|
+
all<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectAll<%= className %>));
|
|
18
|
+
selected<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectEntity));
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Use the initialization action to perform one
|
|
22
|
+
* or more tasks in your Effects.
|
|
23
|
+
*/
|
|
24
|
+
init() {
|
|
25
|
+
this.store.dispatch(<%= className %>Actions.init<%= className %>());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Action } from '@ngrx/store';
|
|
2
|
+
|
|
3
|
+
import * as <%= className %>Actions from './<%= fileName %>.actions';
|
|
4
|
+
import { <%= className %>Entity } from './<%= fileName %>.models';
|
|
5
|
+
import { <%= className %>State, initial<%= className %>State, <%= propertyName %>Reducer } from './<%= fileName %>.reducer';
|
|
6
|
+
|
|
7
|
+
describe('<%= className %> Reducer', () => {
|
|
8
|
+
const create<%= className %>Entity = (id: string, name = ''): <%= className %>Entity => ({
|
|
9
|
+
id,
|
|
10
|
+
name: name || `name-${id}`
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('valid <%= className %> actions', () => {
|
|
14
|
+
it('load<%= className %>Success should return the list of known <%= className %>', () => {
|
|
15
|
+
const <%= propertyName %> = [
|
|
16
|
+
create<%= className %>Entity('PRODUCT-AAA'),
|
|
17
|
+
create<%= className %>Entity('PRODUCT-zzz')
|
|
18
|
+
];
|
|
19
|
+
const action = <%= className %>Actions.load<%= className %>Success({ <%= propertyName %> });
|
|
20
|
+
|
|
21
|
+
const result: <%= className %>State = <%= propertyName %>Reducer(initial<%= className %>State, action);
|
|
22
|
+
|
|
23
|
+
expect(result.loaded).toBe(true);
|
|
24
|
+
expect(result.ids.length).toBe(2);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('unknown action', () => {
|
|
29
|
+
it('should return the previous state', () => {
|
|
30
|
+
const action = {} as Action;
|
|
31
|
+
|
|
32
|
+
const result = <%= propertyName %>Reducer(initial<%= className %>State, action);
|
|
33
|
+
|
|
34
|
+
expect(result).toBe(initial<%= className %>State);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.reducer.ts__tmpl__
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
|
|
2
|
+
import { createReducer, on, Action } from '@ngrx/store';
|
|
3
|
+
|
|
4
|
+
import * as <%= className %>Actions from './<%= fileName %>.actions';
|
|
5
|
+
import { <%= className %>Entity } from './<%= fileName %>.models';
|
|
6
|
+
|
|
7
|
+
export const <%= constantName %>_FEATURE_KEY = '<%= propertyName %>';
|
|
8
|
+
|
|
9
|
+
export interface <%= className %>State extends EntityState<<%= className %>Entity> {
|
|
10
|
+
selectedId?: string | number; // which <%= className %> record has been selected
|
|
11
|
+
loaded: boolean; // has the <%= className %> list been loaded
|
|
12
|
+
error?: string | null; // last known error (if any)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface <%= className %>PartialState {
|
|
16
|
+
readonly [<%= constantName %>_FEATURE_KEY]: <%= className %>State;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const <%= propertyName %>Adapter: EntityAdapter<<%= className %>Entity> = createEntityAdapter<<%= className %>Entity>();
|
|
20
|
+
|
|
21
|
+
export const initial<%= className %>State: <%= className %>State = <%= propertyName %>Adapter.getInitialState({
|
|
22
|
+
// set initial required properties
|
|
23
|
+
loaded: false
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const reducer = createReducer(
|
|
27
|
+
initial<%= className %>State,
|
|
28
|
+
on(<%= className %>Actions.init<%= className %>,
|
|
29
|
+
state => ({ ...state, loaded: false, error: null })
|
|
30
|
+
),
|
|
31
|
+
on(<%= className %>Actions.load<%= className %>Success,
|
|
32
|
+
(state, { <%= propertyName %> }) => <%= propertyName %>Adapter.setAll(<%= propertyName %>, { ...state, loaded: true })
|
|
33
|
+
),
|
|
34
|
+
on(<%= className %>Actions.load<%= className %>Failure,
|
|
35
|
+
(state, { error }) => ({ ...state, error })
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export function <%= propertyName %>Reducer(state: <%= className %>State | undefined, action: Action) {
|
|
40
|
+
return reducer(state, action);
|
|
41
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { <%= className %>Entity } from './<%= fileName %>.models';
|
|
2
|
+
import { <%= propertyName %>Adapter, <%= className %>PartialState, initial<%= className %>State } from './<%= fileName %>.reducer';
|
|
3
|
+
import * as <%= className %>Selectors from './<%= fileName %>.selectors';
|
|
4
|
+
|
|
5
|
+
describe('<%= className %> Selectors', () => {
|
|
6
|
+
const ERROR_MSG = 'No Error Available';
|
|
7
|
+
const get<%= className %>Id = (it: <%= className %>Entity) => it.id;
|
|
8
|
+
const create<%= className %>Entity = (id: string, name = '') => ({
|
|
9
|
+
id,
|
|
10
|
+
name: name || `name-${id}`
|
|
11
|
+
}) as <%= className %>Entity;
|
|
12
|
+
|
|
13
|
+
let state: <%= className %>PartialState;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
state = {
|
|
17
|
+
<%= propertyName %>: <%= propertyName %>Adapter.setAll([
|
|
18
|
+
create<%= className %>Entity('PRODUCT-AAA'),
|
|
19
|
+
create<%= className %>Entity('PRODUCT-BBB'),
|
|
20
|
+
create<%= className %>Entity('PRODUCT-CCC')
|
|
21
|
+
], {
|
|
22
|
+
...initial<%= className %>State,
|
|
23
|
+
selectedId : 'PRODUCT-BBB',
|
|
24
|
+
error: ERROR_MSG,
|
|
25
|
+
loaded: true
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('<%= className %> Selectors', () => {
|
|
31
|
+
it('selectAll<%= className %>() should return the list of <%= className %>', () => {
|
|
32
|
+
const results = <%= className %>Selectors.selectAll<%= className %>(state);
|
|
33
|
+
const selId = get<%= className %>Id(results[1]);
|
|
34
|
+
|
|
35
|
+
expect(results.length).toBe(3);
|
|
36
|
+
expect(selId).toBe('PRODUCT-BBB');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('selectEntity() should return the selected Entity', () => {
|
|
40
|
+
const result = <%= className %>Selectors.selectEntity(state) as <%= className %>Entity;
|
|
41
|
+
const selId = get<%= className %>Id(result);
|
|
42
|
+
|
|
43
|
+
expect(selId).toBe('PRODUCT-BBB');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('select<%= className %>Loaded() should return the current "loaded" status', () => {
|
|
47
|
+
const result = <%= className %>Selectors.select<%= className %>Loaded(state);
|
|
48
|
+
|
|
49
|
+
expect(result).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('select<%= className %>Error() should return the current "error" state', () => {
|
|
53
|
+
const result = <%= className %>Selectors.select<%= className %>Error(state);
|
|
54
|
+
|
|
55
|
+
expect(result).toBe(ERROR_MSG);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
package/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.selectors.ts__tmpl__
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createFeatureSelector, createSelector } from '@ngrx/store';
|
|
2
|
+
import { <%= constantName %>_FEATURE_KEY, <%= className %>State, <%= propertyName %>Adapter } from './<%= fileName %>.reducer';
|
|
3
|
+
|
|
4
|
+
// Lookup the '<%= className %>' feature state managed by NgRx
|
|
5
|
+
export const select<%= className %>State = createFeatureSelector<<%= className %>State>(<%= constantName %>_FEATURE_KEY);
|
|
6
|
+
|
|
7
|
+
const { selectAll, selectEntities } = <%= propertyName %>Adapter.getSelectors();
|
|
8
|
+
|
|
9
|
+
export const select<%= className %>Loaded = createSelector(
|
|
10
|
+
select<%= className %>State,
|
|
11
|
+
(state: <%= className %>State) => state.loaded
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const select<%= className %>Error = createSelector(
|
|
15
|
+
select<%= className %>State,
|
|
16
|
+
(state: <%= className %>State) => state.error
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const selectAll<%= className %> = createSelector(
|
|
20
|
+
select<%= className %>State,
|
|
21
|
+
(state: <%= className %>State) => selectAll(state)
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const select<%= className %>Entities = createSelector(
|
|
25
|
+
select<%= className %>State,
|
|
26
|
+
(state: <%= className %>State) => selectEntities(state)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const selectSelectedId = createSelector(
|
|
30
|
+
select<%= className %>State,
|
|
31
|
+
(state: <%= className %>State) => state.selectedId
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export const selectEntity = createSelector(
|
|
35
|
+
select<%= className %>Entities,
|
|
36
|
+
selectSelectedId,
|
|
37
|
+
(entities, selectedId) => (selectedId ? entities[selectedId] : undefined)
|
|
38
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { createEffect, Actions, ofType } from '@ngrx/effects';
|
|
3
|
+
|
|
4
|
+
import * as <%= className %>Actions from './<%= fileName %>.actions';
|
|
5
|
+
import * as <%= className %>Feature from './<%= fileName %>.reducer';
|
|
6
|
+
|
|
7
|
+
import {switchMap, catchError, of} from 'rxjs';
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class <%= className %>Effects {
|
|
11
|
+
init$ = createEffect(() => this.actions$.pipe(
|
|
12
|
+
ofType(<%= className %>Actions.init<%= className %>),
|
|
13
|
+
switchMap(() => of(<%= className %>Actions.load<%= className %>Success({ <%= propertyName %>: [] }))),
|
|
14
|
+
catchError((error) => {
|
|
15
|
+
console.error('Error', error);
|
|
16
|
+
return of(<%= className %>Actions.load<%= className %>Failure({ error }));
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
));
|
|
20
|
+
|
|
21
|
+
constructor(private readonly actions$: Actions) {}
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { select, Store, Action } from '@ngrx/store';
|
|
3
|
+
|
|
4
|
+
import * as <%= className %>Actions from './<%= fileName %>.actions';
|
|
5
|
+
import * as <%= className %>Feature from './<%= fileName %>.reducer';
|
|
6
|
+
import * as <%= className %>Selectors from './<%= fileName %>.selectors';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class <%= className %>Facade {
|
|
10
|
+
/**
|
|
11
|
+
* Combine pieces of state using createSelector,
|
|
12
|
+
* and expose them as observables through the facade.
|
|
13
|
+
*/
|
|
14
|
+
loaded$ = this.store.pipe(select(<%= className %>Selectors.select<%= className %>Loaded));
|
|
15
|
+
all<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectAll<%= className %>));
|
|
16
|
+
selected<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectEntity));
|
|
17
|
+
|
|
18
|
+
constructor(private readonly store: Store) {}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Use the initialization action to perform one
|
|
22
|
+
* or more tasks in your Effects.
|
|
23
|
+
*/
|
|
24
|
+
init() {
|
|
25
|
+
this.store.dispatch(<%= className %>Actions.init<%= className %>());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addExportsToBarrel = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
6
|
+
const js_1 = require("@nx/js");
|
|
7
|
+
let tsModule;
|
|
8
|
+
function addExportsToBarrel(tree, options) {
|
|
9
|
+
const indexFilePath = (0, devkit_1.joinPathFragments)(options.parentDirectory, '..', 'index.ts');
|
|
10
|
+
if (!tree.exists(indexFilePath)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!tsModule) {
|
|
14
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
15
|
+
}
|
|
16
|
+
const indexSourceText = tree.read(indexFilePath, 'utf-8');
|
|
17
|
+
let sourceFile = tsModule.createSourceFile(indexFilePath, indexSourceText, tsModule.ScriptTarget.Latest, true);
|
|
18
|
+
// Public API for the feature interfaces, selectors, and facade
|
|
19
|
+
const { className, fileName } = (0, devkit_1.names)(options.name);
|
|
20
|
+
const statePath = `./lib/${options.directory}/${fileName}`;
|
|
21
|
+
sourceFile = (0, js_1.addGlobal)(tree, sourceFile, indexFilePath, options.barrels
|
|
22
|
+
? `import * as ${className}Actions from '${statePath}.actions';`
|
|
23
|
+
: `export * from '${statePath}.actions';`);
|
|
24
|
+
sourceFile = (0, js_1.addGlobal)(tree, sourceFile, indexFilePath, options.barrels
|
|
25
|
+
? `import * as ${className}Feature from '${statePath}.reducer';`
|
|
26
|
+
: `export * from '${statePath}.reducer';`);
|
|
27
|
+
sourceFile = (0, js_1.addGlobal)(tree, sourceFile, indexFilePath, options.barrels
|
|
28
|
+
? `import * as ${className}Selectors from '${statePath}.selectors';`
|
|
29
|
+
: `export * from '${statePath}.selectors';`);
|
|
30
|
+
if (options.barrels) {
|
|
31
|
+
sourceFile = (0, js_1.addGlobal)(tree, sourceFile, indexFilePath, `export { ${className}Actions, ${className}Feature, ${className}Selectors };`);
|
|
32
|
+
}
|
|
33
|
+
sourceFile = (0, js_1.addGlobal)(tree, sourceFile, indexFilePath, `export * from '${statePath}.models';`);
|
|
34
|
+
if (options.facade) {
|
|
35
|
+
sourceFile = (0, js_1.addGlobal)(tree, sourceFile, indexFilePath, `export * from '${statePath}.facade';`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.addExportsToBarrel = addExportsToBarrel;
|
|
39
|
+
//# sourceMappingURL=add-exports-barrel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-exports-barrel.js","sourceRoot":"","sources":["../../../../../../../packages/angular/src/generators/ngrx-feature-store/lib/add-exports-barrel.ts"],"names":[],"mappings":";;;AACA,uCAAsD;AAEtD,qFAAiF;AAEjF,+BAAmC;AAEnC,IAAI,QAAqC,CAAC;AAE1C,SAAgB,kBAAkB,CAChC,IAAU,EACV,OAAmD;IAEnD,MAAM,aAAa,GAAG,IAAA,0BAAiB,EACrC,OAAO,CAAC,eAAe,EACvB,IAAI,EACJ,UAAU,CACX,CAAC;IACF,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;QAC/B,OAAO;KACR;IAED,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,IAAA,oCAAgB,GAAE,CAAC;KAC/B;IACD,MAAM,eAAe,GAAG,IAAI,CAAC,IA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