Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #62 from finos-plexus/db-contrib/db_contrib_develop
Browse files Browse the repository at this point in the history
Minor Typescript code generation improvements
  • Loading branch information
udalmik authored Jul 20, 2018
2 parents ef59e88 + ef14f45 commit 963e23e
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,56 +131,37 @@ class «app.name»ClientImpl extends GenericClientApiBase implements «app.name
/**
* Client API builder
*/
export class «app.name»ClientBuilder {
export class «app.name»ClientBuilder extends BaseClientApiBuilder<«app.name»Client> {

private clientDetails: ClientConnectRequest = {
applicationId: '«app.fullName»'
};

private transportConnectionProvider: () => Promise<TransportConnection>;
public constructor() {
super(new ContainerAwareClientAPIBuilder().withApplicationId('«app.fullName»'));
}

«FOR providedElement : providedServices SEPARATOR '\n' »
private «providedElement.aliasOrName.toFirstLower»Handler: «providedElement.aliasOrName.toFirstUpper»InvocationHandler;
«ENDFOR»

public withClientDetails(clientId: ClientConnectRequest): «app.name»ClientBuilder {
this.clientDetails = clientId;
return this;
}

public withAppInstanceId(appInstanceId: UniqueId): «app.name»ClientBuilder {
this.clientDetails.applicationInstanceId = appInstanceId;
return this;
}

public withAppId(appId: string): «app.name»ClientBuilder {
this.clientDetails.applicationId = appId;
return this;
}

«FOR providedMethod : providedServices SEPARATOR '\n' »
public with«providedMethod.aliasOrName.toFirstUpper»InvocationsHandler(invocationsHandler: «providedMethod.aliasOrName.toFirstUpper»InvocationHandler): «app.name»ClientBuilder {
this.«providedMethod.aliasOrName.toFirstLower»Handler = invocationsHandler;
return this;
}
«ENDFOR»

public withTransportConnectionProvider(provider: () => Promise<TransportConnection>): «app.name»ClientBuilder {
this.transportConnectionProvider = provider;
return this;
}

public connect(): Promise<«app.name»Client> {
return new ContainerAwareClientAPIBuilder()
.withTransportConnectionProvider(this.transportConnectionProvider)
.withClientDetails(this.clientDetails)
«FOR providedService : providedServices »
if (!this.«providedService.aliasOrName.toFirstLower»Handler) {
return Promise.reject('Invocation handler for «providedService.aliasOrName» is not provided');
}
«ENDFOR»
return this.genericBuilder
«FOR providedService : providedServices »
«FOR providedMethod : providedService.methods»
«invocationHandlerBuilder(providedMethod.method, providedService, genConfig)»
«ENDFOR»
«ENDFOR»
.connect()
.then((genericClient: GenericClientApi) => new «app.name»ClientImpl(
.then(genericClient => new «app.name»ClientImpl(
genericClient«IF !consumedServices.isEmpty»,«ENDIF»
«FOR consumedService : consumedServices SEPARATOR ","»
new «consumedService.aliasOrName.toFirstUpper»ProxyImpl(genericClient)
Expand Down Expand Up @@ -223,7 +204,7 @@ export class «app.name»ClientBuilder {
}
def imports(PlexusGenConfig genConfig) '''
import { MethodInvocationContext, Completion, ClientConnectRequest, StreamingInvocationClient, GenericClientApi, InvocationRequestInfo, InvocationClient, GenericRequest, GenericClientApiBase } from '@plexus-interop/client';
import { BaseClientApiBuilder, MethodInvocationContext, Completion, ClientConnectRequest, StreamingInvocationClient, GenericClientApi, InvocationRequestInfo, InvocationClient, GenericRequest, GenericClientApiBase } from '@plexus-interop/client';
import { ProvidedMethodReference, ServiceDiscoveryRequest, ServiceDiscoveryResponse, MethodDiscoveryRequest, MethodDiscoveryResponse, GenericClientApiBuilder, ValueHandler } from '@plexus-interop/client';
import { TransportConnection, UniqueId } from '@plexus-interop/transport-common';
import { Arrays, Observer } from '@plexus-interop/common';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MethodInvocationContext, Completion, ClientConnectRequest, StreamingInvocationClient, GenericClientApi, InvocationRequestInfo, InvocationClient, GenericRequest, GenericClientApiBase } from '@plexus-interop/client';
import { BaseClientApiBuilder, MethodInvocationContext, Completion, ClientConnectRequest, StreamingInvocationClient, GenericClientApi, InvocationRequestInfo, InvocationClient, GenericRequest, GenericClientApiBase } from '@plexus-interop/client';
import { ProvidedMethodReference, ServiceDiscoveryRequest, ServiceDiscoveryResponse, MethodDiscoveryRequest, MethodDiscoveryResponse, GenericClientApiBuilder, ValueHandler } from '@plexus-interop/client';
import { TransportConnection, UniqueId } from '@plexus-interop/transport-common';
import { Arrays, Observer } from '@plexus-interop/common';
Expand Down Expand Up @@ -169,33 +169,16 @@ export abstract class ExampleServiceInvocationHandler {
/**
* Client API builder
*/
export class ComponentAClientBuilder {
export class ComponentAClientBuilder extends BaseClientApiBuilder<ComponentAClient> {

private clientDetails: ClientConnectRequest = {
applicationId: 'com.db.plexus.interop.dsl.gen.test.components.ComponentA'
};

private transportConnectionProvider: () => Promise<TransportConnection>;
public constructor() {
super(new ContainerAwareClientAPIBuilder().withApplicationId('com.db.plexus.interop.dsl.gen.test.components.ComponentA'));
}

private noLaunchExampleServiceHandler: NoLaunchExampleServiceInvocationHandler;

private exampleServiceHandler: ExampleServiceInvocationHandler;

public withClientDetails(clientId: ClientConnectRequest): ComponentAClientBuilder {
this.clientDetails = clientId;
return this;
}

public withAppInstanceId(appInstanceId: UniqueId): ComponentAClientBuilder {
this.clientDetails.applicationInstanceId = appInstanceId;
return this;
}

public withAppId(appId: string): ComponentAClientBuilder {
this.clientDetails.applicationId = appId;
return this;
}

public withNoLaunchExampleServiceInvocationsHandler(invocationsHandler: NoLaunchExampleServiceInvocationHandler): ComponentAClientBuilder {
this.noLaunchExampleServiceHandler = invocationsHandler;
return this;
Expand All @@ -206,15 +189,14 @@ export class ComponentAClientBuilder {
return this;
}

public withTransportConnectionProvider(provider: () => Promise<TransportConnection>): ComponentAClientBuilder {
this.transportConnectionProvider = provider;
return this;
}

public connect(): Promise<ComponentAClient> {
return new ContainerAwareClientAPIBuilder()
.withTransportConnectionProvider(this.transportConnectionProvider)
.withClientDetails(this.clientDetails)
if (!this.noLaunchExampleServiceHandler) {
return Promise.reject('Invocation handler for NoLaunchExampleService is not provided');
}
if (!this.exampleServiceHandler) {
return Promise.reject('Invocation handler for ExampleService is not provided');
}
return this.genericBuilder
.withTypeAwareUnaryHandler({
serviceInfo: {
serviceId: 'com.db.plexus.interop.dsl.gen.test.services.ExampleService',
Expand Down Expand Up @@ -252,7 +234,7 @@ export class ComponentAClientBuilder {
handle: this.exampleServiceHandler.onBidiStreaming.bind(this.exampleServiceHandler)
}, plexus.com.db.plexus.interop.dsl.gen.test.model.Request, plexus.com.db.plexus.interop.dsl.gen.test.model.Response)
.connect()
.then((genericClient: GenericClientApi) => new ComponentAClientImpl(
.then(genericClient => new ComponentAClientImpl(
genericClient,
new ExampleServiceProxyImpl(genericClient),
new NoLaunchExampleServiceProxyImpl(genericClient)
Expand Down
36 changes: 6 additions & 30 deletions web/packages/cli/tests/approved/generated-ts-client.approved.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MethodInvocationContext, Completion, ClientConnectRequest, StreamingInvocationClient, GenericClientApi, InvocationRequestInfo, InvocationClient, GenericRequest, GenericClientApiBase } from '@plexus-interop/client';
import { BaseClientApiBuilder, MethodInvocationContext, Completion, ClientConnectRequest, StreamingInvocationClient, GenericClientApi, InvocationRequestInfo, InvocationClient, GenericRequest, GenericClientApiBase } from '@plexus-interop/client';
import { ProvidedMethodReference, ServiceDiscoveryRequest, ServiceDiscoveryResponse, MethodDiscoveryRequest, MethodDiscoveryResponse, GenericClientApiBuilder, ValueHandler } from '@plexus-interop/client';
import { TransportConnection, UniqueId } from '@plexus-interop/transport-common';
import { Arrays, Observer } from '@plexus-interop/common';
Expand Down Expand Up @@ -109,42 +109,18 @@ class GreetingClientClientImpl extends GenericClientApiBase implements GreetingC
/**
* Client API builder
*/
export class GreetingClientClientBuilder {
export class GreetingClientClientBuilder extends BaseClientApiBuilder<GreetingClientClient> {

private clientDetails: ClientConnectRequest = {
applicationId: 'interop.samples.GreetingClient'
};

private transportConnectionProvider: () => Promise<TransportConnection>;


public withClientDetails(clientId: ClientConnectRequest): GreetingClientClientBuilder {
this.clientDetails = clientId;
return this;
}

public withAppInstanceId(appInstanceId: UniqueId): GreetingClientClientBuilder {
this.clientDetails.applicationInstanceId = appInstanceId;
return this;
}

public withAppId(appId: string): GreetingClientClientBuilder {
this.clientDetails.applicationId = appId;
return this;
public constructor() {
super(new ContainerAwareClientAPIBuilder().withApplicationId('interop.samples.GreetingClient'));
}


public withTransportConnectionProvider(provider: () => Promise<TransportConnection>): GreetingClientClientBuilder {
this.transportConnectionProvider = provider;
return this;
}

public connect(): Promise<GreetingClientClient> {
return new ContainerAwareClientAPIBuilder()
.withTransportConnectionProvider(this.transportConnectionProvider)
.withClientDetails(this.clientDetails)
return this.genericBuilder
.connect()
.then((genericClient: GenericClientApi) => new GreetingClientClientImpl(
.then(genericClient => new GreetingClientClientImpl(
genericClient,
new GreetingServiceProxyImpl(genericClient)
));
Expand Down
50 changes: 50 additions & 0 deletions web/packages/client/src/client/api/generic/BaseClientApiBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2017-2018 Plexus Interop Deutsche Bank AG
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ClientApiBuilder } from './ClientApiBuilder';
import { InternalGenericClientApi } from './internal';
import { UniqueId } from '@plexus-interop/protocol';
import { GenericClientApi } from './GenericClientApi';
import { GenericClientApiBuilder } from './GenericClientApiBuilder';
import { TransportConnection } from '@plexus-interop/transport-common';

export abstract class BaseClientApiBuilder<T> implements ClientApiBuilder<T> {

public constructor(protected genericBuilder: GenericClientApiBuilder) { }

public withAppInstanceId(appInstanceId: UniqueId): ClientApiBuilder<T> {
this.genericBuilder = this.genericBuilder.withAppInstanceId(appInstanceId);
return this;
}

public withAppId(appId: string): ClientApiBuilder<T> {
this.genericBuilder = this.genericBuilder.withApplicationId(appId);
return this;
}

public withTransportConnectionProvider(provider: () => Promise<TransportConnection>): ClientApiBuilder<T> {
this.genericBuilder = this.genericBuilder.withTransportConnectionProvider(provider);
return this;
}

public withClientApiDecorator(clientApiDecorator: (client: InternalGenericClientApi) => Promise<GenericClientApi>): ClientApiBuilder<T> {
this.genericBuilder = this.genericBuilder.withClientApiDecorator(clientApiDecorator);
return this;
}

public abstract connect(): Promise<T>;

}
27 changes: 27 additions & 0 deletions web/packages/client/src/client/api/generic/ClientApiBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2017-2018 Plexus Interop Deutsche Bank AG
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { InternalGenericClientApi } from './internal';
import { GenericClientApi } from './GenericClientApi';
import { TransportConnection, UniqueId } from '@plexus-interop/transport-common';

export interface ClientApiBuilder<T> {
connect(): Promise<T>;
withClientApiDecorator(clientApiDecorator: (client: InternalGenericClientApi) => Promise<GenericClientApi>): ClientApiBuilder<T>;
withTransportConnectionProvider(provider: () => Promise<TransportConnection>): ClientApiBuilder<T>;
withAppInstanceId(appInstanceId: UniqueId): ClientApiBuilder<T>;
withAppId(appId: string): ClientApiBuilder<T>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class GenericClientApiImpl implements InternalGenericClientApi {
private readonly log: Logger = LoggerFactory.getLogger('GenericClientApi');

constructor(
private readonly genericClient: GenericClient,
private readonly marshallerProvider: MarshallerProvider,
private readonly handlersRegistry: InvocationHandlersRegistry
protected readonly genericClient: GenericClient,
protected readonly marshallerProvider: MarshallerProvider,
protected readonly handlersRegistry: InvocationHandlersRegistry
) { }

public supported(feature: Feature): boolean {
Expand All @@ -59,6 +59,10 @@ export class GenericClientApiImpl implements InternalGenericClientApi {
return this.genericClient.getConnectionId();
}

public getMarshallerProvider(): MarshallerProvider {
return this.marshallerProvider;
}

public discoverService(discoveryRequest: ServiceDiscoveryRequest): Promise<ServiceDiscoveryResponse> {
this.log.debug('Service Discovery request');
return this.genericClient.discoverService(discoveryRequest);
Expand Down
6 changes: 4 additions & 2 deletions web/packages/client/src/client/api/generic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './GenericClientApiBuilder';
export * from './ClientApiBuilder';
export * from './BaseClientApiBuilder';
export * from './GenericClientApi';
export * from './GenericClientApiImpl';
export * from './GenericClientApiBase';
export * from './GenericInvocationsHost';
export * from './GenericClientApiBuilder';
export * from './handlers';
export * from './handlers';
export * from './internal';
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
*/
import { InternalActionInvoker } from './InternalActionInvoker';
import { GenericClientApi } from '..';
import { MarshallerProvider } from '../../io/MarshallerProvider';

/**
* Extends public client with additioanal features
*/
export interface InternalGenericClientApi extends InternalActionInvoker, GenericClientApi {

getMarshallerProvider(): MarshallerProvider;
}
Loading

0 comments on commit 963e23e

Please sign in to comment.