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

chore: use @loopback/core for packages consistently #5625

Merged
merged 2 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"!*/__tests__"
],
"dependencies": {
"@loopback/context": "^3.8.2",
"@loopback/core": "^2.7.1",
"@loopback/example-todo": "^3.5.0",
"@loopback/openapi-spec-builder": "^2.1.6",
"@loopback/rest": "^5.1.0",
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/context-binding/context-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Context, inject, Provider, ValueFactory} from '@loopback/context';
import {Context, inject, Provider, ValueFactory} from '@loopback/core';
import Benchmark from 'benchmark';

/**
Expand Down
2 changes: 1 addition & 1 deletion benchmark/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"path": "../examples/todo/tsconfig.json"
},
{
"path": "../packages/context/tsconfig.json"
"path": "../packages/core/tsconfig.json"
},
{
"path": "../packages/openapi-spec-builder/tsconfig.json"
Expand Down
2 changes: 1 addition & 1 deletion docs/site/BelongsTo-relation.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ The following code snippet shows how it would look like:
content="/src/repositories/order.repository.ts" %}

```ts
import {Getter, inject} from '@loopback/context';
import {Getter, inject} from '@loopback/core';
import {
BelongsToAccessor,
DefaultCrudRepository,
Expand Down
26 changes: 21 additions & 5 deletions docs/site/Binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ There are a few ways to create a binding:
- Use `Binding` constructor:

```ts
import {Context, Binding} from '@loopback/core';
const context = new Context();
const binding = new Binding('my-key');
ctx.add(binding);
Expand All @@ -40,6 +41,7 @@ There are a few ways to create a binding:
- Use `Binding.bind()`

```ts
import {Context, Binding} from '@loopback/core';
const context = new Context();
const binding = Binding.bind('my-key');
ctx.add(binding);
Expand All @@ -48,10 +50,24 @@ There are a few ways to create a binding:
- Use `context.bind()`

```ts
import {Context, Binding} from '@loopback/core';
const context = new Context();
context.bind('my-key');
```

{% include note.html content="The `@loopback/core` package re-exports all
public APIs of `@loopback/context`. For consistency, we recommend the usage of
`@loopback/core` for imports in LoopBack modules and applications unless they
depend on `@loopback/context` explicitly. The two statements below are
equivalent:

```ts
import {inject} from '@loopback/context';
import {inject} from '@loopback/core';
```

" %}

## How to set up a binding?

The `Binding` class provides a set of fluent APIs to create and configure a
Expand Down Expand Up @@ -87,7 +103,7 @@ The factory function can receive extra information about the context, binding,
and resolution options.

```ts
import {ValueFactory} from '@loopback/context';
import {ValueFactory} from '@loopback/core';

// The factory function now have access extra metadata about the resolution
const factory: ValueFactory<string> = resolutionCtx => {
Expand All @@ -113,7 +129,7 @@ An advanced form of value factory is a class that has a static `value` method
that allows parameter injection.

```ts
import {inject} from '@loopback/context';
import {inject} from '@loopback/core';

class GreetingProvider {
static value(@inject('user') user: string) {
Expand Down Expand Up @@ -458,7 +474,7 @@ match/find bindings by tag. The search criteria can be one of the followings:
filterByTag,
includesTagValue, // Match tag value as an array that includes the item
TagValueMatcher,
} from '@loopback/context';
} from '@loopback/core';
// Match a binding with a named service
ctx.find(filterByTag({name: ANY_TAG_VALUE, service: 'service'}));

Expand Down Expand Up @@ -504,7 +520,7 @@ When the class is bound, these attributes are honored to create a binding. You
can use `@bind` decorator to configure how to bind a class.

```ts
import {bind, BindingScope} from '@loopback/context';
import {bind, BindingScope} from '@loopback/core';

// @bind() accepts scope and tags
@bind({
Expand Down Expand Up @@ -538,7 +554,7 @@ export class YourController {}
Then a binding can be created by inspecting the class,

```ts
import {createBindingFromClass} from '@loopback/context';
import {createBindingFromClass} from '@loopback/core';

const ctx = new Context();
const binding = createBindingFromClass(MyService);
Expand Down
20 changes: 16 additions & 4 deletions docs/site/Context.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,26 @@ can be chained using the `parent` to form a hierarchy. For example, the code
below creates a chain of three contexts: `reqCtx -> serverCtx -> rootCtx`.

```ts
import {Context} from '@loopback/context';
import {Context} from '@loopback/core';

const rootCtx = new Context('root-ctx'); // No parent
const serverCtx = new Context(rootCtx, 'server-ctx'); // rootCtx as the parent
const reqCtx = new Context(serverCtx); // No explicit name, a UUID will be generated
```

{% include note.html content="The `@loopback/core` package re-exports all public
APIs of `@loopback/context`. For consistency, we recommend the usage of
`@loopback/core` for imports in LoopBack modules and applications unless they
depend on `@loopback/context` explicitly. The two statements below are
equivalent:

```ts
import {inject} from '@loopback/context';
import {inject} from '@loopback/core';
```

" %}

LoopBack's context system allows an unlimited amount of Context instances, each
of which may have a parent Context.

Expand Down Expand Up @@ -180,8 +193,7 @@ However, when using classes, LoopBack provides a better way to get at stuff in
the context via the `@inject` decorator:

```ts
import {inject} from '@loopback/context';
import {Application} from '@loopback/core';
import {inject, Application} from '@loopback/core';

const app = new Application();
app.bind('defaultName').to('John');
Expand Down Expand Up @@ -489,7 +501,7 @@ be used to watch a list of bindings matching certain criteria depicted by a
matched bindings.

```ts
import {Context, ContextView} from '@loopback/context';
import {Context, ContextView} from '@loopback/core';

// Set up a context chain
const appCtx = new Context('app');
Expand Down
2 changes: 1 addition & 1 deletion docs/site/Controller-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ based on the given name:
```ts
// Uncomment these imports to begin using these cool features!

// import {inject} from '@loopback/context';
// import {inject} from '@loopback/core';

export class FooController {
constructor() {}
Expand Down
6 changes: 3 additions & 3 deletions docs/site/Creating-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function called by [Context](Context.md) when another entity requests a value to
be injected.

```ts
import {Provider} from '@loopback/context';
import {Provider} from '@loopback/core';

export class MyValueProvider implements Provider<string> {
value() {
Expand Down Expand Up @@ -168,7 +168,7 @@ the list of keys reserved for the framework use.
Provider's `value()` method can be asynchronous too:

```ts
import {Provider} from '@loopback/context';
import {Provider} from '@loopback/core';
const request = require('request-promise-native');
const weatherUrl =
'http://samples.openweathermap.org/data/2.5/weather?appid=b1b15e88fa797225412429c1c50c122a1';
Expand All @@ -192,7 +192,7 @@ dependencies annotated with `@inject` keyword, so that LoopBack runtime can
resolve them automatically.

```ts
import {Provider} from '@loopback/context';
import {Provider} from '@loopback/core';
import {Request, RestBindings} from '@loopback/rest';
import {v4 as uuid} from 'uuid';

Expand Down
19 changes: 17 additions & 2 deletions docs/site/Dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ the caller specify which strategy to use.
The implementation of the `authenticate` action is shown below.

```ts
import {inject, Provider} from '@loopback/core';

export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
constructor(
// The provider is instantiated for Sequence constructor,
Expand Down Expand Up @@ -73,6 +75,19 @@ export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
}
```

{% include note.html content="The `@loopback/core` package re-exports all public
APIs of `@loopback/context`. For consistency, we recommend the usage of
`@loopback/core` for imports in LoopBack modules and applications unless they
depend on `@loopback/context` explicitly. The two statements below are
equivalent:

```ts
import {inject} from '@loopback/context';
import {inject} from '@loopback/core';
```

" %}

Dependency Injection makes the code easier to extend and customize, because the
dependencies can be easily rewired by the application developer. It makes the
code easier to test in isolation (in a pure unit test), because the test can
Expand Down Expand Up @@ -296,7 +311,7 @@ problem.
Consider the following example:

```ts
import {Context, inject} from '@loopback/context';
import {Context, inject} from '@loopback/core';

interface Developer {
// Each developer belongs to a team
Expand Down Expand Up @@ -363,7 +378,7 @@ Let's take a look at the following example:
The corresponding code is:

```ts
import {inject, Context, BindingScope} from '@loopback/context';
import {inject, Context, BindingScope} from '@loopback/core';
import {RestBindings} from '@loopback/rest';

interface Logger() {
Expand Down
2 changes: 1 addition & 1 deletion docs/site/Express-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Alternatively, we can create a subclass of
`ExpressMiddlewareInterceptorProvider`.

```ts
import {config} from '@loopback/context';
import {config} from '@loopback/core';
import {
ExpressMiddlewareInterceptorProvider,
createMiddlewareInterceptorBinding,
Expand Down
2 changes: 1 addition & 1 deletion docs/site/Extending-LoopBack-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ that the service provider can be injected into the consumer class. The code
snippet below shows the usage of `@inject` for dependency injection.

```ts
import {inject, Context} from '@loopback/context';
import {inject, Context} from '@loopback/core';

/**
* A UserController implementation that depends on UserRepository and PasswordHasher
Expand Down
4 changes: 2 additions & 2 deletions docs/site/Extension-point-and-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ decorators and functions are provided to ensure consistency and convention.
1. Inject a getter function for extensions

```ts
import {Getter} from '@loopback/context';
import {Getter} from '@loopback/core';
import {extensionPoint, extensions} from '@loopback/core';

@extensionPoint('greeters')
Expand All @@ -81,7 +81,7 @@ decorators and functions are provided to ensure consistency and convention.
2. Inject a context view for extensions

```ts
import {ContextView} from '@loopback/context';
import {ContextView} from '@loopback/core';
import {extensionPoint, extensions} from '@loopback/core';

@extensionPoint('greeters')
Expand Down
2 changes: 1 addition & 1 deletion docs/site/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ headers). This can be accomplished by injecting the `Response` object into the
controller:

```ts
import {inject} from '@loopback/context';
import {inject} from '@loopback/core';
import {get, Response, RestBindings} from '@loopback/rest';

export class PingController {
Expand Down
4 changes: 2 additions & 2 deletions docs/site/File-upload-download.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A few steps are involved to create an endpoint for file upload.
[`FileUploadController`](https://github.com/strongloop/loopback-next/blob/master/examples/file-transfer/src/controllers/file-upload.controller.ts)

```ts
import {inject} from '@loopback/context';
import {inject} from '@loopback/core';
import {
post,
Request,
Expand Down Expand Up @@ -110,7 +110,7 @@ To download files from the backend, please follow the following steps.
[`FileDownloadController`](https://github.com/strongloop/loopback-next/blob/master/examples/file-transfer/src/controllers/file-download.controller.ts)

```ts
import {inject} from '@loopback/context';
import {inject} from '@loopback/core';
import {
get,
HttpErrors,
Expand Down
4 changes: 2 additions & 2 deletions docs/site/Interceptor-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
bind,
Interceptor,
Provider,
} from '@loopback/context';
} from '@loopback/core';

/**
* This class will be bound to the application as a global `Interceptor` during
Expand Down Expand Up @@ -115,7 +115,7 @@ import {
bind,
Interceptor,
Provider,
} from '@loopback/context';
} from '@loopback/core';

/**
* This class will be bound to the application as a global `Interceptor` during
Expand Down
14 changes: 7 additions & 7 deletions docs/site/Interceptors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Controller methods decorated with `@intercept` are invoked with applied
interceptors for corresponding routes upon API requests.

```ts
import {intercept} from '@loopback/context';
import {intercept} from '@loopback/core';

@intercept(log) // `log` is an interceptor function
export class OrderController {
Expand Down Expand Up @@ -74,7 +74,7 @@ services and would like to allow repository or service methods to be
intercepted.

```ts
import {createProxyWithInterceptors} from '@loopback/context';
import {createProxyWithInterceptors} from '@loopback/core';

const proxy = createProxyWithInterceptors(controllerInstance, ctx);
const msg = await proxy.greet('John');
Expand Down Expand Up @@ -148,7 +148,7 @@ To explicitly invoke a method with interceptors, use `invokeMethod` from
`RestServer` for controller methods.

```ts
import {Context, invokeMethod} from '@loopback/context';
import {Context, invokeMethod} from '@loopback/core';

const ctx: Context = new Context();

Expand Down Expand Up @@ -336,7 +336,7 @@ Global interceptors are discovered from the `InvocationContext`. They are
registered as bindings with `globalInterceptor` tag. For example,

```ts
import {asGlobalInterceptor} from '@loopback/context';
import {asGlobalInterceptor} from '@loopback/core';

app
.bind('globalInterceptors.MetricsInterceptor')
Expand Down Expand Up @@ -747,7 +747,7 @@ Sometimes we want to apply more than one interceptors together as a whole. It
can be done by `composeInterceptors`:

```ts
import {composeInterceptors} from '@loopback/context';
import {composeInterceptors} from '@loopback/core';

const interceptor = composeInterceptors(
interceptorFn1,
Expand All @@ -768,7 +768,7 @@ is the base class that can be extended to create your own flavor of interceptors
and chains. For example,

```ts
import {GenericInvocationChain, GenericInterceptor} from '@loopback/context';
import {GenericInvocationChain, GenericInterceptor} from '@loopback/core';
import {RequestContext} from '@loopback/rest';

export interface RequestInterceptor
Expand All @@ -795,7 +795,7 @@ await chain.invokeInterceptors();
It's also possible to pass in a final handler:

```ts
import {Next} from '@loopback/context';
import {Next} from '@loopback/core';
const finalHandler: Next = async () => {
// return ...;
};
Expand Down
Loading