Skip to content

Commit

Permalink
chore: use explicit typing so that tsc won't emit import("<pkg>")
Browse files Browse the repository at this point in the history
Please note api-extractor does not support `import("<pkg>")`.

See microsoft/rushstack#1867

The mixins are left to be broken as there is no easy workaround.
  • Loading branch information
raymondfeng committed May 19, 2020
1 parent 0a1a94b commit 37b2185
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Binding, Component} from '@loopback/core';
import {CasbinAuthorizationProvider, getCasbinEnforcerByName} from './services';

export class CasbinAuthorizationComponent implements Component {
bindings = [
bindings: Binding[] = [
Binding.bind('casbin.enforcer.factory').to(getCasbinEnforcerByName),
Binding.bind('authorizationProviders.casbin-provider')
.toProvider(CasbinAuthorizationProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import {
CoreBindings,
inject,
} from '@loopback/core';
import {JWTAuthenticationStrategy} from './services/jwt.auth.strategy';
import {JWTService} from './services/jwt.service';
import {
TokenServiceBindings,
TokenServiceConstants,
UserServiceBindings,
} from './keys';
import {JWTAuthenticationStrategy} from './services/jwt.auth.strategy';
import {JWTService} from './services/jwt.service';
import {MyUserService} from './services/user.service';

export class JWTAuthenticationComponent implements Component {
bindings = [
bindings: Binding[] = [
Binding.bind(TokenServiceBindings.TOKEN_SECRET).to(
TokenServiceConstants.TOKEN_SECRET_VALUE,
),
Expand Down
4 changes: 2 additions & 2 deletions examples/greeter-extension/src/component.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 {createBindingFromClass} from '@loopback/context';
import {Binding, createBindingFromClass} from '@loopback/context';
import {Component} from '@loopback/core';
import {ChineseGreeter} from './greeters/greeter-cn';
import {EnglishGreeter} from './greeters/greeter-en';
Expand All @@ -15,7 +15,7 @@ import {GREETING_SERVICE} from './keys';
* extensions
*/
export class GreetingComponent implements Component {
bindings = [
bindings: Binding[] = [
createBindingFromClass(GreetingService, {
key: GREETING_SERVICE,
}),
Expand Down
9 changes: 7 additions & 2 deletions examples/multi-tenancy/src/multi-tenancy/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Component, createBindingFromClass, extensionFor} from '@loopback/core';
import {
Binding,
Component,
createBindingFromClass,
extensionFor,
} from '@loopback/core';
import {MultiTenancyActionProvider} from './actions/multi-tenancy-action.provider';
import {MultiTenancyBindings, MULTI_TENANCY_STRATEGIES} from './keys';
import {
Expand All @@ -14,7 +19,7 @@ import {
} from './strategies';

export class MultiTenancyComponent implements Component {
bindings = [
bindings: Binding[] = [
createBindingFromClass(MultiTenancyActionProvider, {
key: MultiTenancyBindings.ACTION,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {JWTAuthenticationStrategy} from './services/jwt.auth.strategy';
import {JWTService} from './services/jwt.service';

export class JWTAuthenticationComponent implements Component {
bindings = [
bindings: Binding[] = [
// token bindings
Binding.bind(TokenServiceBindings.TOKEN_SECRET).to(
TokenServiceConstants.TOKEN_SECRET_VALUE,
Expand Down
4 changes: 2 additions & 2 deletions packages/context/src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
isBindingAddress,
isBindingTagFilter,
} from './binding-filter';
import {BindingAddress} from './binding-key';
import {BindingAddress, BindingKey} from './binding-key';
import {BindingComparator} from './binding-sorter';
import {BindingCreationPolicy, Context} from './context';
import {ContextView, createViewGetter} from './context-view';
Expand Down Expand Up @@ -322,7 +322,7 @@ export namespace inject {
* @param metadata - Metadata for the injection
*/
export const binding = function injectBinding(
bindingKey?: BindingAddress,
bindingKey?: string | BindingKey<unknown>,
metadata?: InjectBindingMetadata,
) {
metadata = Object.assign({decorator: '@inject.binding'}, metadata);
Expand Down
13 changes: 11 additions & 2 deletions packages/context/src/resolution-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import {DecoratorFactory} from '@loopback/metadata';
import debugModule from 'debug';
import {Binding} from './binding';
import {BindingSelector} from './binding-filter';
import {Context} from './context';
import {Injection} from './inject';
import {Injection, InjectionMetadata} from './inject';
import {BoundValue, tryWithFinally, ValueOrPromise} from './value-promise';

const debugSession = debugModule('loopback:context:resolver:session');
Expand Down Expand Up @@ -36,6 +37,12 @@ export interface InjectionElement {
value: Readonly<Injection>;
}

export interface InjectionDescriptor {
targetName: string;
bindingSelector: BindingSelector;
metadata: InjectionMetadata;
}

/**
* Binding or injection elements tracked by resolution sessions
*/
Expand Down Expand Up @@ -156,7 +163,9 @@ export class ResolutionSession {
* Describe the injection for debugging purpose
* @param injection - Injection object
*/
static describeInjection(injection: Readonly<Injection>) {
static describeInjection(
injection: Readonly<Injection>,
): InjectionDescriptor {
const name = getTargetName(
injection.target,
injection.member,
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export namespace CoreBindings {
/**
* Binding key for application configuration
*/
export const APPLICATION_CONFIG = BindingKey.create<ApplicationConfig>(
'application.config',
);
export const APPLICATION_CONFIG: BindingKey<ApplicationConfig> = BindingKey.create<
ApplicationConfig
>('application.config');

/**
* Binding key for the content of `package.json`
Expand Down Expand Up @@ -60,9 +60,9 @@ export namespace CoreBindings {
* Binding key for the controller class resolved in the current request
* context
*/
export const CONTROLLER_CLASS = BindingKey.create<ControllerClass>(
'controller.current.ctor',
);
export const CONTROLLER_CLASS: BindingKey<ControllerClass> = BindingKey.create<
ControllerClass
>('controller.current.ctor');

/**
* Binding key for the controller method resolved in the current request
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
bind,
Binding,
BindingSpec,
BindingTagFilter,
Constructor,
filterByTag,
ValueOrPromise,
Expand Down Expand Up @@ -62,7 +63,7 @@ export function asLifeCycleObserver<T = unknown>(binding: Binding<T>) {
* Find all life cycle observer bindings. By default, a binding tagged with
* `CoreTags.LIFE_CYCLE_OBSERVER`. It's used as `BindingFilter`.
*/
export const lifeCycleObserverFilter = filterByTag(
export const lifeCycleObserverFilter: BindingTagFilter = filterByTag(
CoreTags.LIFE_CYCLE_OBSERVER,
);

Expand Down
4 changes: 2 additions & 2 deletions packages/express/src/express.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// License text available at https://opensource.org/licenses/MIT

import {Context, CoreBindings, inject, Server} from '@loopback/core';
import {HttpServer, HttpServerOptions} from '@loopback/http-server';
import {HttpOptions, HttpServer, HttpsOptions} from '@loopback/http-server';
import debugFactory from 'debug';
import express from 'express';
import {toExpressMiddleware} from './middleware';
Expand All @@ -16,7 +16,7 @@ const debug = debugFactory('loopback:middleware');
/**
* Configuration for a LoopBack based Express server
*/
export type ExpressServerConfig = HttpServerOptions & {
export type ExpressServerConfig = (HttpOptions | HttpsOptions) & {
/**
* Base path to mount the LoopBack middleware chain
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-crud/src/crud-rest.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Component, createBindingFromClass} from '@loopback/core';
import {Binding, Component, createBindingFromClass} from '@loopback/core';
import {CrudRestApiBuilder} from './crud-rest.api-builder';

export class CrudRestComponent implements Component {
bindings = [createBindingFromClass(CrudRestApiBuilder)];
bindings: Binding[] = [createBindingFromClass(CrudRestApiBuilder)];
}
8 changes: 4 additions & 4 deletions packages/rest-explorer/src/rest-explorer.keys.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 {BindingKey} from '@loopback/context';
import {BindingAddress, BindingKey} from '@loopback/context';
import {RestExplorerComponent} from './rest-explorer.component';
import {RestExplorerConfig} from './rest-explorer.types';

Expand All @@ -23,7 +23,7 @@ export namespace RestExplorerBindings {
* We recommend `ctx.configure(RestExplorerBindings.COMPONENT)` to be used
* instead of `ctx.bind(RestExplorerBindings.CONFIG)`.
*/
export const CONFIG = BindingKey.buildKeyForConfig<RestExplorerConfig>(
COMPONENT,
);
export const CONFIG: BindingAddress<RestExplorerConfig> = BindingKey.buildKeyForConfig<
RestExplorerConfig
>(COMPONENT);
}
8 changes: 7 additions & 1 deletion packages/rest/src/http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
ComponentsObject,
ControllerSpec,
PathObject,
ReferenceObject,
SchemaObject,
SchemasObject,
} from '@loopback/openapi-v3';
import {RestBindings} from './keys';
Expand Down Expand Up @@ -78,7 +80,11 @@ export class HttpHandler {
/**
* @deprecated Use `getApiComponents`
*/
getApiDefinitions() {
getApiDefinitions():
| {
[schema: string]: SchemaObject | ReferenceObject;
}
| undefined {
return this._openApiComponents?.schemas;
}

Expand Down
14 changes: 10 additions & 4 deletions packages/rest/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import https from 'https';
import {ErrorWriterOptions} from 'strong-error-handler';
import {BodyParser, RequestBodyParser} from './body-parsers';
import {HttpHandler} from './http-handler';
import {RestServer} from './rest.server';
import {RestServer, RestServerConfig} from './rest.server';
import {RestRouter, RestRouterOptions} from './router';
import {SequenceHandler} from './sequence';
import {
Expand All @@ -35,7 +35,9 @@ export namespace RestBindings {
/**
* Binding key for setting and injecting RestComponentConfig
*/
export const CONFIG = CoreBindings.APPLICATION_CONFIG.deepProperty('rest');
export const CONFIG: BindingKey<RestServerConfig> = CoreBindings.APPLICATION_CONFIG.deepProperty(
'rest',
);
/**
* Binding key for setting and injecting the host name of RestServer
*/
Expand Down Expand Up @@ -162,7 +164,9 @@ export namespace RestBindings {
/**
* Binding key for setting and injecting an OpenAPI spec
*/
export const API_SPEC = BindingKey.create<OpenApiSpec>('rest.apiSpec');
export const API_SPEC: BindingKey<OpenApiSpec> = BindingKey.create<
OpenApiSpec
>('rest.apiSpec');

/**
* Binding key for setting and injecting an OpenAPI operation spec
Expand Down Expand Up @@ -229,7 +233,9 @@ export namespace RestBindings {
/**
* Binding key for setting and injecting the http request
*/
export const REQUEST = BindingKey.create<Request>('rest.http.request');
export const REQUEST: BindingKey<Request> = BindingKey.create<Request>(
'rest.http.request',
);
/**
* Binding key for setting and injecting the http response
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/providers/parse-params.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ParseParamsProvider implements Provider<ParseParams> {
private ajvFactory?: AjvFactory,
) {}

value() {
value(): ParseParams {
return (request: Request, route: ResolvedRoute) =>
parseOperationArgs(request, route, this.requestBodyParser, {
ajvFactory: this.ajvFactory,
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/rest.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class RestComponent implements Component {
/**
* Add built-in body parsers
*/
bindings = [
bindings: Binding[] = [
// FIXME(rfeng): We now register request body parsers in TRANSIENT scope
// so that they can be bound at application or server level
Binding.bind(RestBindings.REQUEST_BODY_PARSER).toClass(RequestBodyParser),
Expand Down
7 changes: 5 additions & 2 deletions packages/rest/src/router/trie-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {inject} from '@loopback/context';
import {inspect} from 'util';
import {RestBindings} from '../keys';
import {RestRouterOptions} from './rest-router';
import {createResolvedRoute, RouteEntry} from './route-entry';
import {createResolvedRoute, ResolvedRoute, RouteEntry} from './route-entry';
import {BaseRouter} from './router-base';
import {Trie} from './trie';

Expand All @@ -32,7 +32,10 @@ export class TrieRouter extends BaseRouter {
this.trie.create(key, route);
}

protected findRouteWithPathVars(verb: string, path: string) {
protected findRouteWithPathVars(
verb: string,
path: string,
): ResolvedRoute | undefined {
const key = this.getKey(verb, path);

const found = this.trie.match(key);
Expand Down

0 comments on commit 37b2185

Please sign in to comment.