How to use the @tsed/core.StoreMerge 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 / 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 / swagger / src / decorators / operation.ts View on Github external
return (...args: DecoratorParameters) => {
    const type = getDecoratorType(args, true);

    switch (type) {
      case "method":
        return StoreMerge("operation", operation)(...args);

      case "class":
        decorateMethodsOf(args[0], Operation(operation));
        break;

      default:
        throw new UnsupportedDecoratorType(Operation, args);
    }
  };
}
github TypedProject / ts-express-decorators / packages / common / src / mvc / decorators / method / useAfter.ts View on Github external
return (...decoratorArgs: DecoratorParameters): TypedPropertyDescriptor | void => {
    switch (getDecoratorType(decoratorArgs, true)) {
      case "method":
        EndpointRegistry.useAfter(decoratorArgs[0], decoratorArgs[1]!, args);

        return decoratorArgs[2] as any;
      case "class":
        StoreMerge("middlewares", {useAfter: args})(...decoratorArgs);
        break;
      default:
        throw new UnsupportedDecoratorType(UseAfter, decoratorArgs);
    }
  };
}
github TypedProject / ts-express-decorators / packages / common / src / mvc / decorators / method / useBefore.ts View on Github external
return (...decoratorArgs: DecoratorParameters): TypedPropertyDescriptor | void => {
    switch (getDecoratorType(decoratorArgs, true)) {
      case "method":
        EndpointRegistry.useBefore(decoratorArgs[0], decoratorArgs[1]!, args);

        return decoratorArgs[2] as any;
      case "class":
        StoreMerge("middlewares", {useBefore: args})(...decoratorArgs);
        break;
      default:
        throw new UnsupportedDecoratorType(UseBefore, decoratorArgs);
    }
  };
}
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;
    }
  };
}
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 / swagger / src / decorators / responses.ts View on Github external
return (...args: DecoratorParameters) => {
    const type = getDecoratorType(args, true);

    switch (type) {
      case "method":
        return StoreMerge("responses", {[status]: response})(...args);

      case "class":
        decorateMethodsOf(args[0], Responses(status, response));
        break;

      default:
        throw new UnsupportedDecoratorType(Responses, args);
    }
  };
}
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 / 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 / method / header.ts View on Github external
export function Header(headerName: string | number | IHeadersOptions, headerValue?: string | number | IResponseHeader): Function {
  if (headerValue !== undefined) {
    headerName = {[headerName as string]: headerValue};
  }
  const headers: IResponseHeaders = mapHeaders(headerName as IHeadersOptions);

  return applyDecorators(
    StoreMerge("response", {headers}),
    UseAfter((request: any, response: any, next: any) => {
      Object.keys(headers).forEach(key => {
        response.set(key, headers[key].value);
      });
      next();
    })
  );
}