@cratis/chronicle 6.28.0 → 6.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChronicleClient.ts +1 -1
- package/ChronicleOptions.ts +14 -1
- package/EventStore.ts +6 -4
- package/dist/ChronicleClient.js +1 -1
- package/dist/ChronicleClient.js.map +1 -1
- package/dist/ChronicleOptions.d.ts +9 -0
- package/dist/ChronicleOptions.d.ts.map +1 -1
- package/dist/ChronicleOptions.js +10 -1
- package/dist/ChronicleOptions.js.map +1 -1
- package/dist/EventStore.d.ts +2 -1
- package/dist/EventStore.d.ts.map +1 -1
- package/dist/EventStore.js +4 -4
- package/dist/EventStore.js.map +1 -1
- package/dist/projections/ProjectionDefinitionCompiler.d.ts +4 -1
- package/dist/projections/ProjectionDefinitionCompiler.d.ts.map +1 -1
- package/dist/projections/ProjectionDefinitionCompiler.js +6 -2
- package/dist/projections/ProjectionDefinitionCompiler.js.map +1 -1
- package/dist/projections/Projections.d.ts +4 -1
- package/dist/projections/Projections.d.ts.map +1 -1
- package/dist/projections/Projections.js +5 -2
- package/dist/projections/Projections.js.map +1 -1
- package/dist/readModels/ReadModelNamingPolicy.d.ts +13 -0
- package/dist/readModels/ReadModelNamingPolicy.d.ts.map +1 -0
- package/dist/readModels/ReadModelNamingPolicy.js +4 -0
- package/dist/readModels/ReadModelNamingPolicy.js.map +1 -0
- package/dist/readModels/ReadModels.d.ts +3 -1
- package/dist/readModels/ReadModels.d.ts.map +1 -1
- package/dist/readModels/ReadModels.js +5 -2
- package/dist/readModels/ReadModels.js.map +1 -1
- package/dist/readModels/buildReadModelDefinition.d.ts +3 -0
- package/dist/readModels/buildReadModelDefinition.d.ts.map +1 -1
- package/dist/readModels/buildReadModelDefinition.js +1 -1
- package/dist/readModels/buildReadModelDefinition.js.map +1 -1
- package/dist/readModels/for_ReadModelNamingPolicy/given/registered_read_models.d.ts +47 -0
- package/dist/readModels/for_ReadModelNamingPolicy/given/registered_read_models.d.ts.map +1 -0
- package/dist/readModels/for_ReadModelNamingPolicy/given/registered_read_models.js +115 -0
- package/dist/readModels/for_ReadModelNamingPolicy/given/registered_read_models.js.map +1 -0
- package/dist/readModels/index.d.ts +1 -0
- package/dist/readModels/index.d.ts.map +1 -1
- package/dist/readModels/index.js.map +1 -1
- package/dist/reducers/Reducers.d.ts +6 -1
- package/dist/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +8 -2
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/projections/ProjectionDefinitionCompiler.ts +6 -2
- package/projections/Projections.ts +5 -2
- package/readModels/ReadModelNamingPolicy.ts +16 -0
- package/readModels/ReadModels.ts +5 -2
- package/readModels/buildReadModelDefinition.ts +5 -2
- package/readModels/for_ReadModelNamingPolicy/given/registered_read_models.ts +137 -0
- package/readModels/for_ReadModelNamingPolicy/when_configuring_options/with_a_naming_policy.spec.ts +96 -0
- package/readModels/for_ReadModelNamingPolicy/when_registering/a_declarative_projection.spec.ts +40 -0
- package/readModels/for_ReadModelNamingPolicy/when_registering/a_model_bound_projection.spec.ts +40 -0
- package/readModels/for_ReadModelNamingPolicy/when_registering/a_model_bound_read_model_directly.spec.ts +40 -0
- package/readModels/for_ReadModelNamingPolicy/when_registering/a_projection_directly.spec.ts +40 -0
- package/readModels/for_ReadModelNamingPolicy/when_registering/a_reducer.spec.ts +40 -0
- package/readModels/for_ReadModelNamingPolicy/when_registering/a_reducer_read_model_directly.spec.ts +40 -0
- package/readModels/index.ts +1 -0
- package/reducers/Reducers.ts +8 -2
package/readModels/for_ReadModelNamingPolicy/when_configuring_options/with_a_naming_policy.spec.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { beforeEach, chai, describe, it, vi } from 'vitest';
|
|
5
|
+
import { ChronicleClient } from '../../../ChronicleClient.js';
|
|
6
|
+
import { ChronicleOptions } from '../../../ChronicleOptions.js';
|
|
7
|
+
import { EventStore } from '../../../EventStore.js';
|
|
8
|
+
import type { IClientArtifactsProvider } from '../../../artifacts/index.js';
|
|
9
|
+
import { AccountBalance, AccountOpened, upperCasePolicy } from '../given/registered_read_models.js';
|
|
10
|
+
|
|
11
|
+
chai.should();
|
|
12
|
+
|
|
13
|
+
const transport = vi.hoisted(() => ({
|
|
14
|
+
connect: vi.fn(),
|
|
15
|
+
getVersionInfo: vi.fn(),
|
|
16
|
+
ensureEventStore: vi.fn(),
|
|
17
|
+
registerMany: vi.fn()
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
vi.mock('../../../connection/ChronicleConnection', () => ({
|
|
21
|
+
ChronicleConnection: class {
|
|
22
|
+
resetChannel = vi.fn().mockResolvedValue(undefined);
|
|
23
|
+
connect = transport.connect;
|
|
24
|
+
disconnect = vi.fn();
|
|
25
|
+
server = { getVersionInfo: transport.getVersionInfo };
|
|
26
|
+
eventStores = { ensureEventStore: transport.ensureEventStore };
|
|
27
|
+
readModels = { registerMany: transport.registerMany };
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
vi.mock('../../../connection/KernelKeepAlive', () => ({
|
|
32
|
+
KernelKeepAlive: class {
|
|
33
|
+
async start() {}
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const artifacts: IClientArtifactsProvider = {
|
|
38
|
+
eventTypes: [AccountOpened],
|
|
39
|
+
readModels: [AccountBalance],
|
|
40
|
+
reactors: [],
|
|
41
|
+
reducers: [],
|
|
42
|
+
seeders: [],
|
|
43
|
+
constraints: [],
|
|
44
|
+
projections: [],
|
|
45
|
+
webhooks: [],
|
|
46
|
+
eventTypeMigrations: [],
|
|
47
|
+
globalForHandlers: []
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const connectionString = 'chronicle://localhost:35000';
|
|
51
|
+
|
|
52
|
+
describe('when configuring options without a read model naming policy', () => {
|
|
53
|
+
it('should not carry a naming policy', () => {
|
|
54
|
+
(ChronicleOptions.fromConnectionString(connectionString).readModelNamingPolicy === undefined).should.be.true;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('when configuring options with a read model naming policy', () => {
|
|
59
|
+
it('should carry the policy from the connection string factory', () => {
|
|
60
|
+
ChronicleOptions.fromConnectionString(connectionString, { readModelNamingPolicy: upperCasePolicy })
|
|
61
|
+
.readModelNamingPolicy!.should.equal(upperCasePolicy);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should carry the policy from the development factory', () => {
|
|
65
|
+
ChronicleOptions.development({ readModelNamingPolicy: upperCasePolicy })
|
|
66
|
+
.readModelNamingPolicy!.should.equal(upperCasePolicy);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('when an event store registers read models for a client configured with a naming policy', () => {
|
|
71
|
+
let containerName: string;
|
|
72
|
+
|
|
73
|
+
beforeEach(async () => {
|
|
74
|
+
vi.clearAllMocks();
|
|
75
|
+
// Registration of every artifact kind is covered elsewhere; only the store's read-model wiring matters here.
|
|
76
|
+
vi.spyOn(EventStore.prototype, 'registerArtifacts').mockResolvedValue(undefined);
|
|
77
|
+
transport.connect.mockResolvedValue(undefined);
|
|
78
|
+
transport.getVersionInfo.mockResolvedValue({});
|
|
79
|
+
transport.ensureEventStore.mockResolvedValue({ IsSuccess: true });
|
|
80
|
+
transport.registerMany.mockResolvedValue(undefined);
|
|
81
|
+
const client = new ChronicleClient(ChronicleOptions.fromConnectionString(connectionString, {
|
|
82
|
+
discoveryPatterns: [],
|
|
83
|
+
clientArtifactsProvider: artifacts,
|
|
84
|
+
readModelNamingPolicy: upperCasePolicy
|
|
85
|
+
}));
|
|
86
|
+
try {
|
|
87
|
+
const store = await client.getEventStore('store');
|
|
88
|
+
await store.readModels.register(AccountBalance);
|
|
89
|
+
containerName = transport.registerMany.mock.calls[0][0].ReadModels[0].ContainerName;
|
|
90
|
+
} finally {
|
|
91
|
+
client.dispose();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should name the container with the policy result', () => containerName.should.equal('ACCOUNTBALANCE'));
|
|
96
|
+
});
|
package/readModels/for_ReadModelNamingPolicy/when_registering/a_declarative_projection.spec.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { classNamePolicy, registerDeclarativeProjection, upperCasePolicy, type RegisteredReadModel } from '../given/registered_read_models.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when registering a declarative projection without a naming policy', () => {
|
|
10
|
+
let registered: RegisteredReadModel;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
[registered] = await registerDeclarativeProjection();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountSummary'));
|
|
17
|
+
it('should name the container by the identifier', () => registered.containerName.should.equal('AccountSummary'));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('when registering a declarative projection with a naming policy', () => {
|
|
21
|
+
let registered: RegisteredReadModel;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
[registered] = await registerDeclarativeProjection(upperCasePolicy);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountSummary'));
|
|
28
|
+
it('should keep the display name', () => registered.displayName.should.equal('AccountSummary'));
|
|
29
|
+
it('should name the container with the policy result', () => registered.containerName.should.equal('ACCOUNTSUMMARY'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('when registering a declarative projection with a naming policy that uses the class', () => {
|
|
33
|
+
let registered: RegisteredReadModel;
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
[registered] = await registerDeclarativeProjection(classNamePolicy);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should hand the read model class to the policy', () => registered.containerName.should.equal('AccountSummary:AccountSummary'));
|
|
40
|
+
});
|
package/readModels/for_ReadModelNamingPolicy/when_registering/a_model_bound_projection.spec.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { classNamePolicy, registerModelBoundProjection, upperCasePolicy, type RegisteredReadModel } from '../given/registered_read_models.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when registering a model-bound projection without a naming policy', () => {
|
|
10
|
+
let registered: RegisteredReadModel;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
[registered] = await registerModelBoundProjection();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountBalance'));
|
|
17
|
+
it('should name the container by the identifier', () => registered.containerName.should.equal('AccountBalance'));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('when registering a model-bound projection with a naming policy', () => {
|
|
21
|
+
let registered: RegisteredReadModel;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
[registered] = await registerModelBoundProjection(upperCasePolicy);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountBalance'));
|
|
28
|
+
it('should keep the display name', () => registered.displayName.should.equal('AccountBalance'));
|
|
29
|
+
it('should name the container with the policy result', () => registered.containerName.should.equal('ACCOUNTBALANCE'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('when registering a model-bound projection with a naming policy that uses the class', () => {
|
|
33
|
+
let registered: RegisteredReadModel;
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
[registered] = await registerModelBoundProjection(classNamePolicy);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should hand the read model class to the policy', () => registered.containerName.should.equal('AccountBalance:AccountBalance'));
|
|
40
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { classNamePolicy, directModelBound, upperCasePolicy, type RegisteredReadModel } from '../given/registered_read_models.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when registering a model-bound read model directly without a naming policy', () => {
|
|
10
|
+
let registered: RegisteredReadModel;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
[registered] = await directModelBound();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountBalance'));
|
|
17
|
+
it('should name the container by the identifier', () => registered.containerName.should.equal('AccountBalance'));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('when registering a model-bound read model directly with a naming policy', () => {
|
|
21
|
+
let registered: RegisteredReadModel;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
[registered] = await directModelBound(upperCasePolicy);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountBalance'));
|
|
28
|
+
it('should keep the display name', () => registered.displayName.should.equal('AccountBalance'));
|
|
29
|
+
it('should name the container with the policy result', () => registered.containerName.should.equal('ACCOUNTBALANCE'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('when registering a model-bound read model directly with a naming policy that uses the class', () => {
|
|
33
|
+
let registered: RegisteredReadModel;
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
[registered] = await directModelBound(classNamePolicy);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should hand the read model class to the policy', () => registered.containerName.should.equal('AccountBalance:AccountBalance'));
|
|
40
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { classNamePolicy, directProjection, upperCasePolicy, type RegisteredReadModel } from '../given/registered_read_models.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when registering a projection read model directly without a naming policy', () => {
|
|
10
|
+
let registered: RegisteredReadModel;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
[registered] = await directProjection();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountSummary'));
|
|
17
|
+
it('should name the container by the identifier', () => registered.containerName.should.equal('AccountSummary'));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('when registering a projection read model directly with a naming policy', () => {
|
|
21
|
+
let registered: RegisteredReadModel;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
[registered] = await directProjection(upperCasePolicy);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountSummary'));
|
|
28
|
+
it('should keep the display name', () => registered.displayName.should.equal('AccountSummary'));
|
|
29
|
+
it('should name the container with the policy result', () => registered.containerName.should.equal('ACCOUNTSUMMARY'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('when registering a projection read model directly with a naming policy that uses the class', () => {
|
|
33
|
+
let registered: RegisteredReadModel;
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
[registered] = await directProjection(classNamePolicy);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should hand the read model class to the policy', () => registered.containerName.should.equal('AccountSummary:AccountSummary'));
|
|
40
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { classNamePolicy, registerReducer, upperCasePolicy, type RegisteredReadModel } from '../given/registered_read_models.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when registering a reducer without a naming policy', () => {
|
|
10
|
+
let registered: RegisteredReadModel;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
[registered] = await registerReducer();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountActivity'));
|
|
17
|
+
it('should name the container by the identifier', () => registered.containerName.should.equal('AccountActivity'));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('when registering a reducer with a naming policy', () => {
|
|
21
|
+
let registered: RegisteredReadModel;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
[registered] = await registerReducer(upperCasePolicy);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountActivity'));
|
|
28
|
+
it('should keep the display name', () => registered.displayName.should.equal('AccountActivity'));
|
|
29
|
+
it('should name the container with the policy result', () => registered.containerName.should.equal('ACCOUNTACTIVITY'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('when registering a reducer with a naming policy that uses the class', () => {
|
|
33
|
+
let registered: RegisteredReadModel;
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
[registered] = await registerReducer(classNamePolicy);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should hand the read model class to the policy', () => registered.containerName.should.equal('AccountActivity:AccountActivity'));
|
|
40
|
+
});
|
package/readModels/for_ReadModelNamingPolicy/when_registering/a_reducer_read_model_directly.spec.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { classNamePolicy, directReducer, upperCasePolicy, type RegisteredReadModel } from '../given/registered_read_models.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when registering a reducer read model directly without a naming policy', () => {
|
|
10
|
+
let registered: RegisteredReadModel;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
[registered] = await directReducer();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountActivity'));
|
|
17
|
+
it('should name the container by the identifier', () => registered.containerName.should.equal('AccountActivity'));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('when registering a reducer read model directly with a naming policy', () => {
|
|
21
|
+
let registered: RegisteredReadModel;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
[registered] = await directReducer(upperCasePolicy);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should keep the identifier', () => registered.identifier.should.equal('AccountActivity'));
|
|
28
|
+
it('should keep the display name', () => registered.displayName.should.equal('AccountActivity'));
|
|
29
|
+
it('should name the container with the policy result', () => registered.containerName.should.equal('ACCOUNTACTIVITY'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('when registering a reducer read model directly with a naming policy that uses the class', () => {
|
|
33
|
+
let registered: RegisteredReadModel;
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
[registered] = await directReducer(classNamePolicy);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should hand the read model class to the policy', () => registered.containerName.should.equal('AccountActivity:AccountActivity'));
|
|
40
|
+
});
|
package/readModels/index.ts
CHANGED
|
@@ -10,5 +10,6 @@ export { MaterializedReadModels } from './MaterializedReadModels.js';
|
|
|
10
10
|
export { ReadModelSubjectResolver } from './ReadModelSubjectResolver.js';
|
|
11
11
|
export type { ReadModelChangeset } from './ReadModelChangeset.js';
|
|
12
12
|
export type { ReadModelSnapshot } from './ReadModelSnapshot.js';
|
|
13
|
+
export type { ReadModelNamingPolicy } from './ReadModelNamingPolicy.js';
|
|
13
14
|
export { readModel, getReadModelMetadata, isReadModel } from './readModel.js';
|
|
14
15
|
export type { ReadModelMetadata } from './readModel.js';
|
package/reducers/Reducers.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { ReducerEventDispatcher } from './ReducerEventDispatcher.js';
|
|
|
19
19
|
import { getReadModelMetadata } from '../readModels/index.js';
|
|
20
20
|
import { getReadModelId } from '../readModels/readModel.js';
|
|
21
21
|
import { buildReadModelDefinition } from '../readModels/buildReadModelDefinition.js';
|
|
22
|
+
import type { ReadModelNamingPolicy } from '../readModels/ReadModelNamingPolicy.js';
|
|
22
23
|
import { assertUniqueReadModelIds } from '../readModels/assertUniqueReadModelIds.js';
|
|
23
24
|
import { JsonSchemaGenerator } from '../schemas/index.js';
|
|
24
25
|
import type { IEventStore } from '../IEventStore.js';
|
|
@@ -117,6 +118,9 @@ export class Reducers implements IReducers {
|
|
|
117
118
|
* @param _namespace - The namespace within the event store.
|
|
118
119
|
* @param lifecycle - The connection lifecycle used to react to disconnect events.
|
|
119
120
|
* @param _defaultSinkTypeId - The default sink type identifier used when registering read models.
|
|
121
|
+
* @param _eventStore - The event store handed to reducers that request it.
|
|
122
|
+
* @param _artifactActivator - Optional per-delivery activator.
|
|
123
|
+
* @param _readModelNamingPolicy - Optional policy naming the container of each read model.
|
|
120
124
|
*/
|
|
121
125
|
constructor(
|
|
122
126
|
private readonly _clientArtifacts: IClientArtifactsProvider,
|
|
@@ -126,7 +130,8 @@ export class Reducers implements IReducers {
|
|
|
126
130
|
lifecycle: ConnectionLifecycle,
|
|
127
131
|
private readonly _defaultSinkTypeId: string,
|
|
128
132
|
private readonly _eventStore?: IEventStore,
|
|
129
|
-
private readonly _artifactActivator?: ClientArtifactsActivator
|
|
133
|
+
private readonly _artifactActivator?: ClientArtifactsActivator,
|
|
134
|
+
private readonly _readModelNamingPolicy?: ReadModelNamingPolicy
|
|
130
135
|
) {
|
|
131
136
|
this._lifecycle = lifecycle;
|
|
132
137
|
lifecycle.onDisconnected(async () => {
|
|
@@ -190,7 +195,8 @@ export class Reducers implements IReducers {
|
|
|
190
195
|
schema: this.getReducerSchema(reducerType, readModelName),
|
|
191
196
|
sinkTypeId: this._defaultSinkTypeId,
|
|
192
197
|
observerType: ReadModelObserverType.Reducer,
|
|
193
|
-
observerIdentifier: id
|
|
198
|
+
observerIdentifier: id,
|
|
199
|
+
namingPolicy: this._readModelNamingPolicy
|
|
194
200
|
});
|
|
195
201
|
});
|
|
196
202
|
|