Skip to content

Commit 8eb8e19

Browse files
authored
Merge pull request #33 from dolittle/event-horizons-builder
Fix builder public API to match .NET SDK
2 parents ab1ea7e + 3ce9705 commit 8eb8e19

28 files changed

Lines changed: 764 additions & 673 deletions

Samples/Basic/index.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,11 @@ import { PartitionedFilterResult } from '@dolittle/sdk.events.filtering';
77

88
import { MyEvent } from './MyEvent';
99
import { MyEventHandler } from './MyEventHandler';
10-
import { Version } from '@dolittle/sdk.execution';
1110

1211
const client = Client
13-
.create()
14-
.forEnvironment('test')
15-
.withLogging(logBuilder => {
16-
logBuilder
17-
.useWinston(winston => {
18-
winston.level = 'debug';
19-
});
20-
})
21-
.forMicroservice('7a6155dd-9109-4488-8f6f-c57fe4b65bfb', microservice => {
22-
microservice.withVersion(Version.first);
23-
})
12+
.forMicroservice('7a6155dd-9109-4488-8f6f-c57fe4b65bfb')
13+
.withVersion(1, 0, 2)
14+
.withEnvironment('test')
2415
.withEventTypes(eventTypes =>
2516
eventTypes.register(MyEvent))
2617
.withEventHandlers(eventHandlers =>
@@ -29,10 +20,12 @@ const client = Client
2920
.withFilters(filterBuilder =>
3021
filterBuilder
3122
.createPrivateFilter('79e12ab3-2751-47e1-b959-d898dc4d6ee8', fb =>
32-
fb.handle((event: any, context: EventContext) => {
33-
return new Promise((resolve, reject) => {
34-
console.log('Filtering event', event);
35-
});
23+
fb
24+
.unpartitioned()
25+
.handle((event: any, context: EventContext) => {
26+
return new Promise((resolve, reject) => {
27+
console.log('Filtering event', event);
28+
});
3629
})
3730
)
3831
.createPublicFilter('2c087657-b318-40b1-ae92-a400de44e507', fb =>

Samples/Container/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import { MyEventHandler } from './MyEventHandler';
1010

1111

1212
const client = Client
13-
.create()
1413
.forMicroservice('7a6155dd-9109-4488-8f6f-c57fe4b65bfb')
1514
.withContainer(Container)
16-
.withLogging(_ => _.useWinston(_ => _.level = 'debug'))
1715
.withEventTypes(eventTypes =>
1816
eventTypes.register(MyEvent))
1917
.withEventHandlers(eventHandlers =>

Samples/EventHorizon/index.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,28 @@ import { Client } from '@dolittle/sdk';
55

66
import { MyEventHandler } from './MyEventHandler';
77
import { MyEvent } from './MyEvent';
8+
import { PartitionId } from '@dolittle/sdk.events';
89

910
const client = Client
10-
.create()
1111
.forMicroservice('a14bb24e-51f3-4d83-9eba-44c4cffe6bb9')
1212
.connectToRuntime('localhost', 50055)
13-
.withLogging(_ => _.useWinston(_ => _.level = 'debug'))
1413
.withEventTypes(eventTypes =>
1514
eventTypes.register(MyEvent))
1615
.withEventHandlers(eventHandlers =>
1716
eventHandlers.register(MyEventHandler))
1817
.withEventHorizons(_ => {
1918
_.forTenant('900893e7-c4cc-4873-8032-884e965e4b97', ts => {
20-
ts.forProducerMicroservice('7a6155dd-9109-4488-8f6f-c57fe4b65bfb', sb => {
21-
sb
22-
.fromProducerTenant('900893e7-c4cc-4873-8032-884e965e4b97')
23-
.fromProducerStream('2c087657-b318-40b1-ae92-a400de44e507')
24-
.toScope('406d6473-7cc9-44a6-a55f-775c1021d957')
25-
.onSuccess((t, s, sr) => console.log('Subscription: Success'))
26-
.onFailure((t, s, sr) => console.log(`Subscription: Failed - ${sr.failure?.reason}`))
27-
.onCompleted((t, s, sr) => console.log(`Subscription: Completed`));
28-
})
29-
.onSuccess((t, s, sr) => console.log('Tenant: Success'))
30-
.onFailure((t, s, sr) => console.log(`Tenant: Failed - ${sr.failure?.reason}`))
31-
.onCompleted((t, s, sr) => console.log(`Tenant: Completed`));
19+
ts.fromProducerMicroservice('7a6155dd-9109-4488-8f6f-c57fe4b65bfb')
20+
.fromProducerTenant('900893e7-c4cc-4873-8032-884e965e4b97')
21+
.fromProducerStream('2c087657-b318-40b1-ae92-a400de44e507')
22+
.fromProducerPartition(PartitionId.unspecified.value)
23+
.toScope('406d6473-7cc9-44a6-a55f-775c1021d957')
24+
.onSuccess((t, s, sr) => console.log('Subscription: Success'))
25+
.onFailure((t, s, sr) => console.log(`Subscription: Failed - ${sr.failure?.reason}`))
26+
.onCompleted((t, s, sr) => console.log(`Subscription: Completed`));
27+
ts.onSuccess((t, s, sr) => console.log('Tenant: Success'));
28+
ts.onFailure((t, s, sr) => console.log(`Tenant: Failed - ${sr.failure?.reason}`));
29+
ts.onCompleted((t, s, sr) => console.log(`Tenant: Completed`));
3230
})
3331
.onSuccess((t, s, sr) => console.log('EventHorizons: Success'))
3432
.onFailure((t, s, sr) => console.log(`EventHorizons: Failed - ${sr.failure?.reason}`))

Source/eventHorizon/MissingScopeForSubscription.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

Source/eventHorizon/MissingStreamForSubscription.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

Source/eventHorizon/MissingTenantForSubscription.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

Source/eventHorizon/SubscriptionBuilder.ts

Lines changed: 0 additions & 150 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Dolittle. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
5+
import { StreamId, PartitionId, ScopeId } from '@dolittle/sdk.events';
6+
import { MicroserviceId, TenantId } from '@dolittle/sdk.execution';
7+
8+
import { Subscription } from './Subscription';
9+
import { SubscriptionCallbacks, SubscriptionCompleted, SubscriptionFailed, SubscriptionSucceeded } from './SubscriptionCallbacks';
10+
11+
/**
12+
* Represents the builder for building subscriptions on a tenant.
13+
*/
14+
export class SubscriptionBuilderForConsumerScope {
15+
16+
private readonly _callbacks: SubscriptionCallbacks = new SubscriptionCallbacks();
17+
/**
18+
* Initializes a new instance of {@link SubscriptionBuilderForConsumerScope}.
19+
* @param {MicroserviceId} _producerMicroserviceId The microservice the subscriptions are for.
20+
* @param {Observable<SubscriptionCallbackArguments>} responsesSource The source of responses.
21+
*/
22+
constructor(
23+
private readonly _producerMicroserviceId: MicroserviceId,
24+
private readonly _producerTenantId: TenantId,
25+
private readonly _producerStreamId: StreamId,
26+
private readonly _producerPartitionId: PartitionId,
27+
private readonly _consumerScopeId: ScopeId) {
28+
}
29+
30+
/**
31+
* Sets the {@link SubscriptionCompleted} callback for all subscriptions on the event horizon
32+
* @param {SubscriptionCompleted} completed The callback method.
33+
* @returns {SubscriptionBuilderForConsumerScope}
34+
* @summary The callback will be called on each subscription.
35+
*/
36+
onCompleted(completed: SubscriptionCompleted): SubscriptionBuilderForConsumerScope {
37+
this._callbacks.onCompleted(completed);
38+
return this;
39+
}
40+
41+
/**
42+
* Sets the {@link SubscriptionSucceeded} callback for all subscriptions on the event horizon
43+
* @param {SubscriptionSucceeded} succeeded The callback method.
44+
* @returns {SubscriptionBuilderForConsumerScope}
45+
* @summary The callback will be called on each subscription.
46+
*/
47+
onSuccess(succeeded: SubscriptionSucceeded): SubscriptionBuilderForConsumerScope {
48+
this._callbacks.onSucceeded(succeeded);
49+
return this;
50+
}
51+
52+
/**
53+
* Sets the {@link SubscriptionFailed} callback for all subscriptions on the event horizon
54+
* @param {SubscriptionFailed} failed The callback method.
55+
* @returns {SubscriptionBuilderForConsumerScope}
56+
* @summary The callback will be called on each subscription.
57+
*/
58+
onFailure(failed: SubscriptionFailed): SubscriptionBuilderForConsumerScope {
59+
this._callbacks.onFailed(failed);
60+
return this;
61+
}
62+
63+
/**
64+
* Builds the subscription.
65+
* @param {Observable<SubscriptionCallbackArguments} callbackArgumentsSource The observable source of responses.
66+
* @returns {Subscription}
67+
*/
68+
build(): Subscription {
69+
return new Subscription(this._consumerScopeId, this._producerMicroserviceId, this._producerTenantId, this._producerStreamId, this._producerPartitionId, this._callbacks);
70+
}
71+
}

0 commit comments

Comments
 (0)