Skip to content

Commit cedccc1

Browse files
authored
Merge pull request #37 from dolittle/fix-api-signatures
Fix api signatures
2 parents 0c53c1c + ceb4dbb commit cedccc1

40 files changed

Lines changed: 205 additions & 180 deletions

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
tsconfigRootDir: __dirname,
1111
},
1212
rules: {
13-
"@typescript-eslint/no-this-alias": ['error', { allowedNames: ['self']}],
13+
"@typescript-eslint/unified-signatures": 'off',
1414
"import/no-extraneous-dependencies": 'off'
1515
},
1616
overrides: [

Samples/Basic/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
import { Client } from '@dolittle/sdk';
55
import { EventContext, PartitionId } from '@dolittle/sdk.events';
66
import { PartitionedFilterResult } from '@dolittle/sdk.events.filtering';
7+
import { eventHandler } from '@dolittle/sdk.events.handling';
8+
import { TenantId } from '@dolittle/sdk.execution';
79

810
import { MyEvent } from './MyEvent';
911
import { MyEventHandler } from './MyEventHandler';
1012

1113
const client = Client
1214
.forMicroservice('7a6155dd-9109-4488-8f6f-c57fe4b65bfb')
13-
.withVersion(1, 0, 2)
14-
.withEnvironment('test')
15+
.withVersion(1, 3, 4)
16+
.withEnvironment('secret mountain lab')
1517
.withEventTypes(eventTypes =>
1618
eventTypes.register(MyEvent))
17-
.withEventHandlers(eventHandlers =>
18-
eventHandlers
19-
.register(MyEventHandler))
19+
.withEventHandlers(eventHandlers => {
20+
eventHandlers.register(MyEventHandler);
21+
})
2022
.withFilters(filterBuilder =>
2123
filterBuilder
2224
.createPrivateFilter('79e12ab3-2751-47e1-b959-d898dc4d6ee8', fb =>
@@ -36,12 +38,11 @@ const client = Client
3638
)
3739
.build();
3840

39-
4041
const event = new MyEvent();
4142
event.anInteger = 42;
4243
event.aString = 'Forty two';
4344

4445
client
4546
.eventStore
46-
.forTenant('900893e7-c4cc-4873-8032-884e965e4b97')
47+
.forTenant(TenantId.development)
4748
.commitPublic(event, 'd8cb7301-4bec-4451-a72b-2db53c6dc05d');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
import { Generation } from './Generation';
5+
6+
export type EventTypeOptions = { generation?: Generation | number };

Source/artifacts/EventTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class EventTypes implements IEventTypes {
6161
/** @inheritdoc */
6262
resolveFrom(object: any, input?: EventType | EventTypeId | Guid | string): EventType {
6363
let eventType: EventType | undefined;
64-
if (input != null) {
64+
if (input !== undefined) {
6565
eventType = input instanceof EventType ? input : new EventType(EventTypeId.from(input));
6666
} else if (object && this.hasFor(Object.getPrototypeOf(object).constructor)) {
6767
eventType = this.getFor(Object.getPrototypeOf(object).constructor);

Source/artifacts/EventTypesBuilder.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,36 @@ export class EventTypesBuilder {
2121
/**
2222
* Associate a type with an unique event type identifier and optional generation.
2323
* @param {Constructor} type Type to associate.
24-
* @param {ArtifactId} identifier Identifier to associate with.
25-
* @param {number} generation Optional generation - defaults to 1.
24+
* @param {EventType} eventType EventType to associate with.
2625
*/
2726
associate<T = any>(type: Constructor<T>, eventType: EventType): EventTypesBuilder;
28-
associate<T = any>(type: Constructor<T>, identifier: EventTypeId | Guid | string, generation?: Generation | number): EventTypesBuilder;
27+
/**
28+
* Associate a type with an unique event type identifier and optional generation.
29+
* @param {Constructor} type Type to associate.
30+
* @param {EventTypeId | Guid | string} identifier Identifier to associate with.
31+
*/
32+
associate<T = any>(type: Constructor<T>, identifier: EventTypeId | Guid | string): EventTypesBuilder;
33+
/**
34+
* Associate a type with an unique event type identifier and optional generation.
35+
* @param {Constructor} type Type to associate.
36+
* @param {EventTypeId | Guid | string} identifier Identifier to associate with.
37+
* @param {Generation | number} generation The generation to associate with.
38+
*/
39+
associate<T = any>(type: Constructor<T>, identifier: EventTypeId | Guid | string, generation: Generation | number): EventTypesBuilder;
2940
associate<T = any>(type: Constructor<T>, eventTypeOrIdentifier: EventType | EventTypeId | Guid | string, generation?: Generation | number): EventTypesBuilder {
3041
const eventType = eventTypeOrIdentifier instanceof EventType ?
3142
eventTypeOrIdentifier
3243
: new EventType(
3344
EventTypeId.from(eventTypeOrIdentifier),
34-
generation == null? Generation.first : Generation.from(generation));
45+
generation ? Generation.from(generation) : Generation.first);
3546
this._associations.push([type, eventType]);
3647
return this;
3748
}
3849

50+
/**
51+
* Register the type as an {@link EventType}.
52+
* @param type The type to register as an {@link EventType}
53+
*/
3954
register<T = any>(type: Constructor<T>): EventTypesBuilder {
4055
this.associate(type, EventTypesFromDecorators.eventTypes.getFor(type));
4156
return this;

Source/artifacts/eventTypeDecorator.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
import { Guid } from '@dolittle/rudiments';
5-
import { EventType } from './EventType';
65
import { EventTypeId } from './EventTypeId';
6+
import { EventTypeOptions } from './EventTypeOptions';
77
import { EventTypesFromDecorators } from './EventTypesFromDecorators';
88
import { Generation } from './Generation';
99

1010
/**
1111
* Decorator for associating an event with an artifact.
12+
* @param {EventTypeId | Guid | string} identifier The id to associate with this type
13+
* @param {EventTypeOptions} [options={} Options to give to the EventHandler
1214
*/
13-
export function eventType(identifier: Guid | string, generationNumber?: number) {
15+
export function eventType(identifier: EventTypeId | Guid | string, options: EventTypeOptions = {}) {
1416
return function (target: any) {
1517
EventTypesFromDecorators
1618
.associate(
1719
target.prototype.constructor,
1820
EventTypeId.from(identifier),
19-
generationNumber != null ? Generation.from(generationNumber) : Generation.first);
21+
options.generation ? Generation.from(options.generation) : Generation.first);
2022
};
2123
}

Source/eventHorizon/SubscriptionBuilderForProducerMicroservice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export class SubscriptionBuilderForProducerMicroservice {
3030

3131
/**
3232
* Specifies from which tenant we should get events from in the other microservice.
33-
* @param {Guid | string} tenantId Tenant for the subscription.
33+
* @param {TenantId | Guid | string} tenantId Tenant for the subscription.
3434
*/
35-
fromProducerTenant(tenantId: Guid | string): SubscriptionBuilderForProducerTenant {
35+
fromProducerTenant(tenantId: TenantId | Guid | string): SubscriptionBuilderForProducerTenant {
3636
this.throwIfProducerTenantIsAlreadyDefined();
3737
this._producerTenantId = TenantId.from(tenantId);
3838
this._builder = new SubscriptionBuilderForProducerTenant(this._producerMicroserviceId, this._producerTenantId);

Source/eventHorizon/SubscriptionBuilderForProducerPartition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export class SubscriptionBuilderForProducerPartition {
3434

3535
/**
3636
* Sets the producer stream to subscribe to events from.
37-
* @param {Guid | string} scopeId Stream to subscribe to events from.
37+
* @param {ScopeId | Guid | string} scopeId Stream to subscribe to events from.
3838
*/
39-
toScope(scopeId: Guid | string): SubscriptionBuilderForConsumerScope {
39+
toScope(scopeId: ScopeId | Guid | string): SubscriptionBuilderForConsumerScope {
4040
this.throwIfConsumerScopeIsAlreadyDefined();
4141
this._consumerScopeId = ScopeId.from(scopeId);
4242
this._builder = new SubscriptionBuilderForConsumerScope(

Source/eventHorizon/SubscriptionBuilderForProducerStream.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export class SubscriptionBuilderForProducerStream {
3333

3434
/**
3535
* Sets the producer stream to subscribe to events from.
36-
* @param {Guid | string} tenant Stream to subscribe to events from.
36+
* @param {PartitionId | Guid | string} tenant Stream to subscribe to events from.
3737
*/
38-
fromProducerPartition(partitionId: Guid | string): SubscriptionBuilderForProducerPartition {
38+
fromProducerPartition(partitionId: PartitionId | Guid | string): SubscriptionBuilderForProducerPartition {
3939
this.throwIfProducerPartitionIsAlreadyDefined();
4040
this._producerPartitionId = PartitionId.from(partitionId);
4141
this._builder = new SubscriptionBuilderForProducerPartition(

Source/eventHorizon/SubscriptionBuilderForProducerTenant.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export class SubscriptionBuilderForProducerTenant {
3232

3333
/**
3434
* Sets the producer stream to subscribe to events from.
35-
* @param {Guid | string} tenant Stream to subscribe to events from.
35+
* @param {StreamId | Guid | string} tenant Stream to subscribe to events from.
3636
*/
37-
fromProducerStream(streamId: Guid | string): SubscriptionBuilderForProducerStream {
37+
fromProducerStream(streamId: StreamId | Guid | string): SubscriptionBuilderForProducerStream {
3838
this.throwIfProducerStreamIsAlreadyDefined();
3939
this._producerStreamId = StreamId.from(streamId);
4040
this._builder = new SubscriptionBuilderForProducerStream(

0 commit comments

Comments
 (0)