Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
MethodDecoratorFactory,
} from '@loopback/context';
import {
AUTHENTICATED,
AuthorizationMetadata,
Authorizer,
EVERYONE,
UNAUTHENTICATED,
} from '../types';
export const AUTHORIZATION_METHOD_KEY = MetadataAccessor.create<
AuthorizationMetadata,
MethodDecorator
>('authorization:method');
export const AUTHORIZATION_CLASS_KEY = MetadataAccessor.create<
AuthorizationMetadata,
ClassDecorator
>('authorization:class');
class AuthorizeClassDecoratorFactory extends ClassDecoratorFactory<
AuthorizationMetadata
> {}
export class AuthorizeMethodDecoratorFactory extends MethodDecoratorFactory<
AuthorizationMetadata
> {
protected mergeWithOwn(
ownMetadata: MetadataMap,
target: Object,
methodName?: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
import {
MetadataAccessor,
inject,
Context,
Injection,
InjectionMetadata,
} from '@loopback/context';
import {getService, juggler} from '..';
/**
* Type definition for decorators returned by `@serviceProxy` decorator factory
*/
export type ServiceProxyDecorator = PropertyDecorator | ParameterDecorator;
export const SERVICE_PROXY_KEY = MetadataAccessor.create<
string,
ServiceProxyDecorator
>('service.proxy');
/**
* Metadata for a service proxy
*/
export class ServiceProxyMetadata implements InjectionMetadata {
decorator = '@serviceProxy';
dataSourceName?: string;
dataSource?: juggler.DataSource;
constructor(dataSource: string | juggler.DataSource) {
if (typeof dataSource === 'string') {
this.dataSourceName = dataSource;
} else {
ClassDecoratorFactory,
MetadataAccessor,
MetadataInspector,
MetadataMap,
PropertyDecoratorFactory,
} from '@loopback/context';
import {
ModelDefinition,
ModelDefinitionSyntax,
PropertyDefinition,
PropertyType,
RelationDefinitionMap,
} from '../model';
import {RELATIONS_KEY} from '../relations/relation.decorator';
export const MODEL_KEY = MetadataAccessor.create<
Partial,
ClassDecorator
>('loopback:model');
export const MODEL_PROPERTIES_KEY = MetadataAccessor.create<
PropertyDefinition,
PropertyDecorator
>('loopback:model-properties');
export const MODEL_WITH_PROPERTIES_KEY = MetadataAccessor.create<
ModelDefinition,
ClassDecorator
>('loopback:model-and-properties');
export type PropertyMap = MetadataMap;
/**
* Decorator for model definitions
PropertyDecoratorFactory,
} from '@loopback/context';
import {
ModelDefinition,
ModelDefinitionSyntax,
PropertyDefinition,
PropertyType,
RelationDefinitionMap,
} from '../model';
import {RELATIONS_KEY} from '../relations/relation.decorator';
export const MODEL_KEY = MetadataAccessor.create<
Partial,
ClassDecorator
>('loopback:model');
export const MODEL_PROPERTIES_KEY = MetadataAccessor.create<
PropertyDefinition,
PropertyDecorator
>('loopback:model-properties');
export const MODEL_WITH_PROPERTIES_KEY = MetadataAccessor.create<
ModelDefinition,
ClassDecorator
>('loopback:model-and-properties');
export type PropertyMap = MetadataMap;
/**
* Decorator for model definitions
* @param definition
* @returns A class decorator for `model`
*/
export function model(definition?: Partial) {
import {
ClassDecoratorFactory,
Constructor,
MetadataAccessor,
MetadataInspector,
MethodDecoratorFactory,
inject,
} from '@loopback/context';
export interface WebSocketMetadata {
namespace?: string | RegExp;
}
export const WEBSOCKET_METADATA = MetadataAccessor.create<
WebSocketMetadata,
ClassDecorator
>('websocket');
/**
* Decorate a websocket controller class to specify the namespace
* For example,
* ```ts
* @ws({namespace: '/chats'})
* export class WebSocketController {}
* ```
* @param spec A namespace or object
*/
export function ws(spec: WebSocketMetadata | string | RegExp = {}) {
if (typeof spec === 'string' || spec instanceof RegExp) {
spec = {namespace: spec};
ModelDefinitionSyntax,
PropertyDefinition,
PropertyType,
RelationDefinitionMap,
} from '../model';
import {RELATIONS_KEY} from '../relations/relation.decorator';
export const MODEL_KEY = MetadataAccessor.create<
Partial,
ClassDecorator
>('loopback:model');
export const MODEL_PROPERTIES_KEY = MetadataAccessor.create<
PropertyDefinition,
PropertyDecorator
>('loopback:model-properties');
export const MODEL_WITH_PROPERTIES_KEY = MetadataAccessor.create<
ModelDefinition,
ClassDecorator
>('loopback:model-and-properties');
export type PropertyMap = MetadataMap;
/**
* Decorator for model definitions
* @param definition
* @returns A class decorator for `model`
*/
export function model(definition?: Partial) {
return function(target: Function & {definition?: ModelDefinition}) {
definition = definition ?? {};
const def: ModelDefinitionSyntax = Object.assign(definition, {
name: definition.name ?? target.name,
ClassDecoratorFactory,
DecoratorFactory,
MetadataAccessor,
MetadataInspector,
MetadataMap,
MethodDecoratorFactory,
} from '@loopback/context';
import {
AUTHENTICATED,
AuthorizationMetadata,
Authorizer,
EVERYONE,
UNAUTHENTICATED,
} from '../types';
export const AUTHORIZATION_METHOD_KEY = MetadataAccessor.create<
AuthorizationMetadata,
MethodDecorator
>('authorization:method');
export const AUTHORIZATION_CLASS_KEY = MetadataAccessor.create<
AuthorizationMetadata,
ClassDecorator
>('authorization:class');
class AuthorizeClassDecoratorFactory extends ClassDecoratorFactory<
AuthorizationMetadata
> {}
export class AuthorizeMethodDecoratorFactory extends MethodDecoratorFactory<
AuthorizationMetadata
> {