Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add integration for service-oriented backends #1119

Merged
merged 1 commit into from
May 3, 2018

Conversation

raymondfeng
Copy link
Contributor

@raymondfeng raymondfeng commented Mar 12, 2018

The PR adds basic integration for service oriented backends such as REST and SOAP web services using legacy connectors.

Implements #1069

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Related API Documentation was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in packages/example-* were updated

@raymondfeng
Copy link
Contributor Author

#1267

@raymondfeng raymondfeng force-pushed the service-proxy branch 3 times, most recently from 96c5aca to 83fa5ac Compare April 27, 2018 17:39
@raymondfeng raymondfeng changed the title [WIP - PoC] feat: add integration for service-oriented backends [WIP] feat: add integration for service-oriented backends Apr 30, 2018
@raymondfeng raymondfeng force-pushed the service-proxy branch 2 times, most recently from 25eec64 to e77f7f3 Compare April 30, 2018 21:57
@raymondfeng raymondfeng removed the request for review from kjdelisle May 1, 2018 04:46
@raymondfeng raymondfeng changed the title [WIP] feat: add integration for service-oriented backends feat: add integration for service-oriented backends May 1, 2018
/**
* DataSource instance properties/operations
*/
export class DataSource {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this type definition shared with @loopback/repository? Can we move commonly-used type definitions directly into loopback-datasource-juggler please?

My understanding is that we need to create index.d.ts file alongside existing index.js and place all type definitions there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's on my plate to move TS type definitions into loopback-datasource-juggler. Let's deal it in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@@ -0,0 +1,25 @@
Copyright (c) IBM Corp. 2018. All Rights Reserved.
Node module: @loopback/service
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a more descriptive name than @loopback/service please. For example, I would expect @loopback/service to provide functionality for building services.

Few proposals:

  • @loopback/service-client
  • @loopback/service-integration
  • @loopback/service-proxy
  • @loopback/service-repository

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must have

Please update the main documentation too, see e.g. https://github.com/strongloop/loopback-next/blob/d2daf382fc38e16abbb2087354ce75b5b8efe215/docs/site/Calling-other-APIs-and-Web-Services.md

Perhaps you should move the content from README to the docs, so that README contains only a link to our docs site?

A discussion

I am confused about the invocation proxy part as I don't see how to use it together with DataSource-backed services.

Additionally, I am concerned about performance impacts of using ES6 Services in our codebase. While there have been performance improvements made towards the end of 2017 (see this blog post), these speed ups did not make it into Node.js 8.x LTS.

Additionally, Proxies still introduce performance overhead:

Converting NamedNodeMap to use Proxy increased processing time by

  • 1.9 s on V8 6.0 (Node v8.4.0)
  • 0.5 s on V8 6.3 (Node v9.0.0-v8-canary-20170910)

Can we remove the proxy part from this initial pull request?


**NOTE**: Once we start to support declarative datasources with `@loopback/boot`,
the datasource configuration files can be dropped into `src/datasources` to be
discovered and bound automatically.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a link to the GitHub issue tracking the task of adding support for data-sources to @loopback/boot.

export class MyController {

@serviceProxy('geoService')
private geoService: GeoService;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all users required to write service interfaces manually? Shouldn't there be a type-unsafe interface allowing a simpler usage?

Something along the following lines:

// provided by us
interface GenericService {
  [method: string]: Function
}


// usage
@serviceProxy('geoService')
private geoService: GenericService;

Or maybe it's our intention to force LB4 users to always write the service interface, to prevent them from being lazy and losing type safety?


export class MyController {

@serviceProxy('geoService')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a proxy? Have you considered other names like @serviceClient?

'datasources.' + meta.dataSourceName,
);
return getService(ds);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if neither dataSource nor dataSourceName is set?

Please throw a descriptive error in such case.

@raymondfeng
Copy link
Contributor Author

@bajtos Your comments are addressed. PTAL.

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please consider addressing the last two comments below (Use vs. Usage, juggler namespace).

No further review is needed from my side.


{% include content/tbd.html %}
```
$ npm install --save @loopback/service-proxy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, --save is no longer needed with the npm version shipped in Node.js 8.x LTS, at least AFAIK. If you decide to change this line, then please check other places in this pull request that are using --save argument.

$ npm install --save @loopback/service-proxy
```

## Usage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Basic use, see http://loopback.io/doc/en/contrib/README-guidelines.html

This section is often titled “Usage,” but we prefer “Use” because it is a shorter and more common word, and means the same thing.

```ts
import {DataSourceConstructor, juggler} from '@loopback/service-proxy';

const ds: juggler.DataSource = new DataSourceConstructor({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be outside of this pull request, but it would be great if consumers of @loopback/service-proxy did not need to know about juggler namespace.

import {DataSourceConstructor, DataSource} from '@loopback/service-proxy';
const ds: DataSource = new DataSourceConstructor({
  // ...
});

Ideally, we should not need two type entities (DataSource + DataSourceConstructor) and have a single entity behaving like a proper ES6 class:

import {DataSource} from '@loopback/service-proxy';
const ds = new DataSource({
  // ...
});

@raymondfeng
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants