How to use the @tsed/core.applyDecorators function in @tsed/core

To help you get started, we’ve selected a few @tsed/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / examples / passport-azure-ad / packages / server / src / decorators / OAuthBearer.ts View on Github external
export function OAuthBearer(options: any = {}): Function {
  return applyDecorators(
    AuthOptions(OAuthBearerOptions as any, options), // Add this to store all options and retrieve it in verify function
    UseAuth(Passport.authenticate("oauth-bearer", {session: false, ...options}) as any),

    // Metadata for swagger
    Security("oauth", ...(options.scopes || [])),
    Operation({
      "parameters": [
        {
          "in": "header",
          "name": "Authorization",
          "type": "string",
          "required": true
        }
      ]
    }),
    Responses(401, {description: "Unauthorized"}),
github TypedProject / ts-express-decorators / packages / socketio / src / decorators / socketService.ts View on Github external
export function SocketService(namespace = "/") {
  return applyDecorators(StoreMerge("socketIO", {namespace, type: SocketProviderTypes.SERVICE}), (target: Type) => {
    registerSocketService(target);
  });
}
github TypedProject / ts-express-decorators / packages / mongoose / src / decorators / ref.ts View on Github external
export function Ref(model: string | any, type: MongooseSchemaTypes = MongooseSchemaTypes.OBJECT_ID) {
  return applyDecorators(
    Property({use: String}),
    Schema({
      type: String,
      example: "5ce7ad3028890bd71749d477",
      description: "Mongoose Ref ObjectId"
    }),
    StoreFn((store: Store) => {
      delete store.get("schema").$ref;
    }),
    StoreMerge(MONGOOSE_SCHEMA, {
      type: MongooseSchema.Types[type],
      ref: typeof model === "string" ? model : Store.from(model).get(MONGOOSE_MODEL_NAME)
    })
  );
}
github TypedProject / ts-express-decorators / packages / common / src / mvc / decorators / method / status.ts View on Github external
export function Status(code: number, options: IResponseOptions = {}) {
  const response = mapReturnedResponse(options);

  return applyDecorators(
    StoreSet("statusCode", code),
    StoreMerge("response", response),
    StoreMerge("responses", {[code]: response}),
    UseAfter((request: any, response: any, next: any) => {
      if (response.statusCode === 200) {
        response.status(code);
      }
      next();
    })
  );
}
github TypedProject / ts-express-decorators / packages / common / src / mvc / decorators / required.ts View on Github external
export function Required(...allowedRequiredValues: any[]): any {
  return applyDecorators(
    (...decoratorArgs: DecoratorParameters) => {
      const metadata = getStorableMetadata(decoratorArgs);

      if (!metadata) {
        throw new UnsupportedDecoratorType(Required, decoratorArgs);
      }

      metadata.required = true;

      if (allowedRequiredValues.length) {
        Allow(...allowedRequiredValues)(...decoratorArgs);
      }
    },
    StoreMerge("responses", {
      "400": {
        description: "BadRequest"
github TypedProject / ts-express-decorators / packages / mongoose / src / decorators / objectID.ts View on Github external
export function ObjectID(name?: string) {
  return applyDecorators(
    Property({name, use: String}),
    Schema({
      description: "Mongoose ObjectId",
      example: "5ce7ad3028890bd71749d477"
    })
  );
}
github TypedProject / ts-express-decorators / packages / common / src / mvc / decorators / method / useAuth.ts View on Github external
return (...args: DecoratorParameters): TypedPropertyDescriptor | void => {
    switch (getDecoratorType(args, true)) {
      case "method":
        return applyDecorators(
          StoreFn((store: Store) => {
            if (!store.has(guardAuth)) {
              return UseBefore(guardAuth);
            }
          }),
          AuthOptions(guardAuth, options)
        )(...args);

      case "class":
        decorateMethodsOf(args[0], UseAuth(guardAuth, options));
        break;

      default:
        throw new UnsupportedDecoratorType(UseAuth, args);
    }
  };
github TypedProject / ts-express-decorators / packages / common / src / mvc / decorators / method / responseView.ts View on Github external
export function ResponseView(viewPath: string, viewOptions?: Object): Function {
  return applyDecorators(StoreSet(ResponseViewMiddleware, {viewPath, viewOptions}), UseAfter(ResponseViewMiddleware));
}
github TypedProject / ts-express-decorators / packages / common / src / mvc / decorators / method / contentType.ts View on Github external
export function ContentType(type: string) {
  return applyDecorators(
    StoreMerge("produces", [type]),
    UseAfter((request: any, response: any, next: any) => {
      response.type(type);
      next();
    })
  );
}
github TypedProject / ts-express-decorators / packages / mongoose / src / decorators / schema.ts View on Github external
return (...parameters: any[]) => {
    switch (getDecoratorType(parameters)) {
      case "property":
        return applyDecorators(Property(), StoreMerge(MONGOOSE_SCHEMA, options))(...parameters);

      case "class":
        StoreMerge(MONGOOSE_SCHEMA, createSchema(parameters[0], options as MongooseSchemaOptions))(...parameters);
        break;
    }
  };
}