Skip to content
Closed
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
4 changes: 2 additions & 2 deletions examples/hello-world/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class HelloWorldApplication extends RestApplication {
// returns the same HTTP response: Hello World!
// Learn more about the concept of Sequence in our docs:
// http://loopback.io/doc/en/lb4/Sequence.html
this.handler((sequence, request, response) => {
sequence.send(response, 'Hello World!');
this.handler((sequence, httpCtx) => {
sequence.send(httpCtx.response, 'Hello World!');
});
}

Expand Down
8 changes: 4 additions & 4 deletions examples/log-extension/src/providers/log-action.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import {inject, Provider, Constructor, Getter} from '@loopback/context';
import {CoreBindings} from '@loopback/core';
import {OperationArgs, ParsedRequest} from '@loopback/rest';
import {getLogMetadata} from '../decorators';
import {OperationArgs, Request} from '@loopback/rest';
import {getLogMetadata} from '../decorators/log.decorator';
import {EXAMPLE_LOG_BINDINGS, LOG_LEVEL} from '../keys';
import {
LogFn,
Expand Down Expand Up @@ -35,7 +35,7 @@ export class LogActionProvider implements Provider<LogFn> {

value(): LogFn {
const fn = <LogFn>((
req: ParsedRequest,
req: Request,
args: OperationArgs,
// tslint:disable-next-line:no-any
result: any,
Expand All @@ -52,7 +52,7 @@ export class LogActionProvider implements Provider<LogFn> {
}

private async action(
req: ParsedRequest,
req: Request,
args: OperationArgs,
// tslint:disable-next-line:no-any
result: any,
Expand Down
4 changes: 2 additions & 2 deletions examples/log-extension/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

// Types and interfaces exposed by the extension go here

import {ParsedRequest, OperationArgs} from '@loopback/rest';
import {Request, OperationArgs} from '@loopback/rest';

/**
* A function to perform REST req/res logging action
*/
export interface LogFn {
(
req: ParsedRequest,
req: Request,
args: OperationArgs,
// tslint:disable-next-line:no-any
result: any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
InvokeMethod,
Send,
Reject,
ParsedRequest,
ServerResponse,
HttpContext,
} from '@loopback/rest';
import {get, param} from '@loopback/openapi-v3';
import {
Expand Down Expand Up @@ -73,7 +72,7 @@ describe('log extension acceptance test', () => {

it('logs information at DEBUG or higher', async () => {
setAppLogToDebug();
const client: Client = createClientForHandler(app.requestHandler);
const client: Client = createClientForHandler(app.requestListener);

await client.get('/nolog').expect(200, 'nolog called');
expect(spy.called).to.be.False();
Expand All @@ -99,7 +98,7 @@ describe('log extension acceptance test', () => {

it('logs information at INFO or higher', async () => {
setAppLogToInfo();
const client: Client = createClientForHandler(app.requestHandler);
const client: Client = createClientForHandler(app.requestListener);

await client.get('/nolog').expect(200, 'nolog called');
expect(spy.called).to.be.False();
Expand All @@ -125,7 +124,7 @@ describe('log extension acceptance test', () => {

it('logs information at WARN or higher', async () => {
setAppLogToWarn();
const client: Client = createClientForHandler(app.requestHandler);
const client: Client = createClientForHandler(app.requestListener);

await client.get('/nolog').expect(200, 'nolog called');
expect(spy.called).to.be.False();
Expand All @@ -151,7 +150,7 @@ describe('log extension acceptance test', () => {

it('logs information at ERROR', async () => {
setAppLogToError();
const client: Client = createClientForHandler(app.requestHandler);
const client: Client = createClientForHandler(app.requestListener);

await client.get('/nolog').expect(200, 'nolog called');
expect(spy.called).to.be.False();
Expand All @@ -177,7 +176,7 @@ describe('log extension acceptance test', () => {

it('logs no information when logLevel is set to OFF', async () => {
setAppLogToOff();
const client: Client = createClientForHandler(app.requestHandler);
const client: Client = createClientForHandler(app.requestListener);

await client.get('/nolog').expect(200, 'nolog called');
expect(spy.called).to.be.False();
Expand Down Expand Up @@ -214,7 +213,7 @@ describe('log extension acceptance test', () => {
@inject(EXAMPLE_LOG_BINDINGS.LOG_ACTION) protected logger: LogFn,
) {}

async handle(req: ParsedRequest, res: ServerResponse) {
async handle({request: req, response: res}: HttpContext) {
// tslint:disable-next-line:no-any
let args: any = [];
// tslint:disable-next-line:no-any
Expand Down
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 {sinon} from '@loopback/testlab';
import {ParsedRequest} from '@loopback/rest';
import {Request} from '@loopback/rest';
import {
LogActionProvider,
LogFn,
Expand All @@ -21,7 +21,7 @@ import {logToMemory} from '../../in-memory-logger';
describe('LogActionProvider with in-memory logger', () => {
let spy: sinon.SinonSpy;
let logger: LogFn;
const req = <ParsedRequest>{url: '/test'};
const req = <Request>{url: '/test'};

beforeEach(() => {
spy = createLogSpy();
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('LogActionProvider with in-memory logger', () => {
describe('LogActionProvider with default logger', () => {
let stub: sinon.SinonSpy;
let logger: LogFn;
const req = <ParsedRequest>{url: '/test'};
const req = <Request>{url: '/test'};

beforeEach(() => {
stub = createConsoleStub();
Expand Down
13 changes: 6 additions & 7 deletions examples/todo/src/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import {Context, inject} from '@loopback/context';
import {
FindRoute,
InvokeMethod,
ParsedRequest,
ParseParams,
Reject,
RestBindings,
Send,
SequenceHandler,
HttpContext,
} from '@loopback/rest';
import {ServerResponse} from 'http';

const SequenceActions = RestBindings.SequenceActions;

Expand All @@ -28,14 +27,14 @@ export class MySequence implements SequenceHandler {
@inject(SequenceActions.REJECT) public reject: Reject,
) {}

async handle(req: ParsedRequest, res: ServerResponse) {
async handle({request, response}: HttpContext) {
try {
const route = this.findRoute(req);
const args = await this.parseParams(req, route);
const route = this.findRoute(request);
const args = await this.parseParams(request, route);
const result = await this.invoke(route, args);
this.send(res, result);
this.send(response, result);
} catch (err) {
this.reject(res, req, err);
this.reject(response, request, err);
}
}
}
2 changes: 1 addition & 1 deletion examples/todo/test/acceptance/application.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Application', () => {
before(givenARestServer);
before(givenTodoRepository);
before(() => {
client = createClientForHandler(server.requestHandler);
client = createClientForHandler(server.requestListener);
});
after(async () => {
await app.stop();
Expand Down
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 {ParsedRequest} from '@loopback/rest';
import {Request} from '@loopback/rest';
import {inject} from '@loopback/core';
import {Provider, Getter, Setter} from '@loopback/context';
import {Strategy} from 'passport';
Expand All @@ -14,14 +14,14 @@ import {AuthenticationBindings} from '../keys';
* Passport monkey-patches Node.js' IncomingMessage prototype
* and adds extra methods like "login" and "isAuthenticated"
*/
export type PassportRequest = ParsedRequest & Express.Request;
export type PassportRequest = Request & Express.Request;

/**
* interface definition of a function which accepts a request
* and returns an authenticated user
*/
export interface AuthenticateFn {
(request: ParsedRequest): Promise<UserProfile | undefined>;
(request: Request): Promise<UserProfile | undefined>;
}

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
* The implementation of authenticate() sequence action.
* @param request Parsed Request
*/
async action(request: ParsedRequest): Promise<UserProfile | undefined> {
async action(request: Request): Promise<UserProfile | undefined> {
const strategy = await this.getStrategy();
if (!strategy) {
// The invoked operation does not require authentication.
Expand Down
6 changes: 3 additions & 3 deletions packages/authentication/src/strategy-adapter.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 {HttpErrors, ParsedRequest} from '@loopback/rest';
import {HttpErrors, Request} from '@loopback/rest';
import {Strategy} from 'passport';
import {UserProfile} from './providers/authentication.provider';

Expand All @@ -19,7 +19,7 @@ export class ShimRequest implements Express.Request {
path: string;
method: string;

constructor(request: ParsedRequest) {
constructor(request: Request) {
this.headers = request.headers;
this.query = request.query;
this.url = request.url;
Expand Down Expand Up @@ -79,7 +79,7 @@ export class StrategyAdapter {
* 3. authenticate using the strategy
* @param req {http.ServerRequest} The incoming request.
*/
authenticate(req: ParsedRequest) {
authenticate(req: Request) {
const shimReq = new ShimRequest(req);
return new Promise<UserProfile>((resolve, reject) => {
// create a prototype chain of an instance of a passport strategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import {Application} from '@loopback/core';
import {
RestBindings,
ServerResponse,
ParsedRequest,
ParseParams,
FindRoute,
InvokeMethod,
Expand All @@ -16,6 +14,7 @@ import {
SequenceHandler,
RestServer,
RestComponent,
HttpContext,
} from '@loopback/rest';
import {api, get} from '@loopback/openapi-v3';
import {Client, createClientForHandler} from '@loopback/testlab';
Expand Down Expand Up @@ -137,7 +136,7 @@ describe('Basic Authentication', () => {
protected authenticateRequest: AuthenticateFn,
) {}

async handle(req: ParsedRequest, res: ServerResponse) {
async handle({request: req, response: res}: HttpContext) {
try {
const route = this.findRoute(req);

Expand Down Expand Up @@ -188,7 +187,7 @@ describe('Basic Authentication', () => {
}

function whenIMakeRequestTo(restServer: RestServer): Client {
return createClientForHandler(restServer.requestHandler);
return createClientForHandler(restServer.requestListener);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import {expect} from '@loopback/testlab';
import {Context, instantiateClass} from '@loopback/context';
import {ParsedRequest} from '@loopback/rest';
import {Request} from '@loopback/rest';
import {
AuthenticateActionProvider,
AuthenticateFn,
Expand Down Expand Up @@ -42,14 +42,14 @@ describe('AuthenticateActionProvider', () => {
const authenticate: AuthenticateFn = await Promise.resolve(
provider.value(),
);
const request = <ParsedRequest>{};
const request = <Request>{};
const user = await authenticate(request);
expect(user).to.be.equal(mockUser);
});

it('updates current user', async () => {
const authenticate = await Promise.resolve(provider.value());
const request = <ParsedRequest>{};
const request = <Request>{};
await authenticate(request);
expect(currentUser).to.equal(mockUser);
});
Expand All @@ -61,7 +61,7 @@ describe('AuthenticateActionProvider', () => {
context
.bind(AuthenticationBindings.AUTH_ACTION)
.toProvider(AuthenticateActionProvider);
const request = <ParsedRequest>{};
const request = <Request>{};
const authenticate = await context.get<AuthenticateFn>(
AuthenticationBindings.AUTH_ACTION,
);
Expand All @@ -78,7 +78,7 @@ describe('AuthenticateActionProvider', () => {
const authenticate = await context.get<AuthenticateFn>(
AuthenticationBindings.AUTH_ACTION,
);
const request = <ParsedRequest>{};
const request = <Request>{};
let error;
try {
await authenticate(request);
Expand All @@ -97,7 +97,7 @@ describe('AuthenticateActionProvider', () => {
const authenticate = await context.get<AuthenticateFn>(
AuthenticationBindings.AUTH_ACTION,
);
const request = <ParsedRequest>{};
const request = <Request>{};
request.headers = {testState: 'fail'};
let error;
try {
Expand Down
10 changes: 5 additions & 5 deletions packages/authentication/test/unit/strategy-adapter.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import {expect} from '@loopback/testlab';
import {StrategyAdapter, UserProfile} from '../..';
import {ParsedRequest, HttpErrors} from '@loopback/rest';
import {Request, HttpErrors} from '@loopback/rest';
import {MockStrategy} from './fixtures/mock-strategy';
import {AuthenticateOptions} from 'passport';

Expand All @@ -28,7 +28,7 @@ describe('Strategy Adapter', () => {
}
const strategy = new Strategy();
const adapter = new StrategyAdapter(strategy);
const request = <ParsedRequest>{};
const request = <Request>{};
await adapter.authenticate(request);
expect(calledFlag).to.be.true();
});
Expand All @@ -37,7 +37,7 @@ describe('Strategy Adapter', () => {
const strategy = new MockStrategy();
strategy.setMockUser(mockUser);
const adapter = new StrategyAdapter(strategy);
const request = <ParsedRequest>{};
const request = <Request>{};
const user: Object = await adapter.authenticate(request);
expect(user).to.be.eql(mockUser);
});
Expand All @@ -46,7 +46,7 @@ describe('Strategy Adapter', () => {
const strategy = new MockStrategy();
strategy.setMockUser(mockUser);
const adapter = new StrategyAdapter(strategy);
const request = <ParsedRequest>{};
const request = <Request>{};
request.headers = {testState: 'fail'};
let error;
try {
Expand All @@ -61,7 +61,7 @@ describe('Strategy Adapter', () => {
const strategy = new MockStrategy();
strategy.setMockUser(mockUser);
const adapter = new StrategyAdapter(strategy);
const request = <ParsedRequest>{};
const request = <Request>{};
request.headers = {testState: 'error'};
let error;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('controller booter acceptance tests', () => {
await app.start();

const server: RestServer = await app.getServer(RestServer);
const client: Client = createClientForHandler(server.requestHandler);
const client: Client = createClientForHandler(server.requestListener);

// Default Controllers = /controllers with .controller.js ending (nested = true);
await client.get('/one').expect(200, 'ControllerOne.one()');
Expand Down
Loading