Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Node module: @loopback/v3compat
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {inject} from '@loopback/core';
import {OperationArgs, Request, Response, RestBindings} from '@loopback/rest';
import * as debugFactory from 'debug';
import {SharedMethod} from './shared-method';
const debug = debugFactory('loopback:v3compat:rest-adapter');
export class Lb3ModelController {
@inject(RestBindings.Http.REQUEST)
protected request: Request;
@inject(RestBindings.Http.RESPONSE)
protected response: Response;
// TODO: a property for strong-remoting's HttpContext
[key: string]: Function | Request | Response;
protected buildMethodArguments(
sharedMethod: SharedMethod,
inputArgs: OperationArgs,
) {
const finalArgs: OperationArgs = [];
for (const argSpec of sharedMethod.accepts) {
const source = argSpec.http && argSpec.http.source;
switch (source) {
case 'req':
finalArgs.push(this.request);
constructor(
@inject(PasswordHasherBindings.ROUNDS)
private readonly rounds: number,
) {}
constructor(
@inject(AuthorizationBindings.CONFIG)
private readonly config?: AuthorizationConfig,
) {
this.providers = {
[AuthorizationBindings.AUTHORIZE_ACTION.key]: AuthorizeActionProvider,
[AuthorizationBindings.METADATA.key]: AuthorizationMetadataProvider,
[AuthorizationBindings.USER_PERMISSIONS.key]: UserPermissionsProvider,
};
if (
config &&
config.allowAlwaysPaths &&
config.allowAlwaysPaths.length > 0
) {
this.bindings = [
Binding.bind(AuthorizationBindings.PATHS_TO_ALLOW_ALWAYS).to(
config.allowAlwaysPaths,
constructor(
@inject(CoreBindings.APPLICATION_INSTANCE)
public app: RestApplication,
@inject(BootBindings.PROJECT_ROOT)
public projectRoot: string,
@inject(`${BootBindings.BOOT_OPTIONS}#lb3app`)
options: Partial = {},
) {
this.options = Object.assign({}, DefaultOptions, options);
if (typeof app.mountExpressRouter !== 'function') {
throw new Error(
'Lb3AppBooter requires RestApplication with mountExpressRouter API',
);
}
}
constructor(
@inject(JWTAuthenticationBindings.SERVICE)
public jwt_authentication_service: JWTAuthenticationService,
@inject(JWTAuthenticationBindings.SECRET)
public jwt_secret: string,
) {}
async authenticate(request: Request): Promise {
constructor(
@inject('datasources.mongo') protected datasource: juggler.DataSource,
) {
super(Order, datasource);
}
}
function setupCrudRepository(
entityClass: typeof Entity & {prototype: Entity},
modelConfig: ModelCrudRestApiConfig,
): Class> {
const repositoryClass = defineRepositoryClass(entityClass);
inject(`datasources.${modelConfig.dataSource}`)(
repositoryClass,
undefined,
0,
);
return repositoryClass;
}
constructor(
@inject('datasources.mongo') protected datasource: juggler.DataSource,
@repository(OrderRepository) protected orderRepository: OrderRepository,
@repository.getter('UserCredentialsRepository')
protected userCredentialsRepositoryGetter: Getter<
UserCredentialsRepository
>,
) {
super(User, datasource);
this.userCredentials = this.createHasOneRepositoryFactoryFor(
'userCredentials',
userCredentialsRepositoryGetter,
);
this.orders = this.createHasManyRepositoryFactoryFor(
'orders',
async () => orderRepository,
);
}