How to use the @tsed/core.getDecoratorType 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 / multipartfiles / src / decorators / multipartFile.ts View on Github external
return (target: any, propertyKey: string | symbol, index: number): void => {
    const type = getDecoratorType([target, propertyKey, index], true);

    switch (type) {
      default:
        throw new Error("MultipartFile is only supported on parameters");

      case "parameter":
        const store = Store.fromMethod(target, String(propertyKey));
        const multiple = Metadata.getParamTypes(target, propertyKey)[index] === Array;
        const options = typeof name === "object" ? name : undefined;
        const added = store.has("multipartAdded");

        name = (typeof name === "object" ? undefined : name)!;

        // create endpoint metadata
        store.merge("consumes", ["multipart/form-data"]).set("multipartAdded", true);
        store
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 / swagger / src / decorators / title.ts View on Github external
return (...args: any[]) => {
    const type = getDecoratorType(args);
    switch (type) {
      case "method":
        return Operation({title})(...args);
      case "parameter":
        return BaseParameter({title})(...args);
      default:
        originalTitleDecorator(title)(...args);
    }
  };
}
github TypedProject / ts-express-decorators / packages / common / src / mvc / decorators / allow.ts View on Github external
return (...decoratorArgs: DecoratorParameters): void => {
    const metadata = getStorableMetadata(decoratorArgs);

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

    metadata.allowedRequiredValues = allowedRequiredValues;

    if (getDecoratorType(decoratorArgs, true) === "property" && allowedRequiredValues.some(e => e == null)) {
      allowNullInSchema(decoratorArgs[0], decoratorArgs[1]);
    }
  };
}
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 / method / useBeforeEach.ts View on Github external
return (...decoratorArgs: DecoratorParameters): TypedPropertyDescriptor | void => {
    switch (getDecoratorType(decoratorArgs, true)) {
      case "method":
        return UseBefore(...args)(...decoratorArgs);

      case "class":
        decorateMethodsOf(decoratorArgs[0], UseBefore(...args));
        break;

      default:
        throw new UnsupportedDecoratorType(UseBeforeEach, decoratorArgs);
    }
  };
}
github TypedProject / ts-express-decorators / src / multipartfiles / decorators / multerOptions.ts View on Github external
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
    const type = getDecoratorType([target, propertyKey, descriptor], true);

    switch (type) {
      default:
        throw new Error("MulterOptions is only supported on method");
      case "method":
        Store.fromMethod(target, propertyKey).merge(MultipartFileMiddleware, {
          options
        });

        return descriptor;
    }
  };
}
github TypedProject / ts-express-decorators / packages / di / src / decorators / inject.ts View on Github external
return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor | number): any => {
    const bindingType = getDecoratorType([target, propertyKey, descriptor], true);

    switch (bindingType) {
      case "parameter":
      case "parameter.constructor":
        if (symbol) {
          const paramTypes = Metadata.getParamTypes(target, propertyKey);

          paramTypes[descriptor as number] = symbol;
          Metadata.setParamTypes(target, propertyKey, paramTypes);
        }
        break;

      case "property":
        Store.from(target).merge("injectableProperties", {
          [propertyKey]: {
            bindingType,
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 / jsonschema / utils / decoratorSchemaFactory.ts View on Github external
return (...parameters: any[]): any => {
    let schema: JsonSchema;

    switch (getDecoratorType(parameters)) {
      case "property":
        schema = PropertyRegistry.get(parameters[0], parameters[1]).schema;
        break;
      case "class":
        schema = JsonSchemesRegistry.createIfNotExists(parameters[0]);
        break;
    }

    const result: any = fn(schema!, parameters as DecoratorParameters);
    if (typeof result === "function") {
      result(...parameters);
    }

    return parameters[2];
  };
}