How to use @tsed/core - 10 common examples

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 / test / units / core / class / Metadata.spec.ts View on Github external
it("should return unique provide from property key", () => {
      Metadata.set("controller", "test", Test);
      Metadata.set("controller", "test2", Test2);
      Metadata.set("controller", "test", Test);

      const result = Metadata.getTargetsFromPropertyKey("controller");

      expect(result).to.be.an("array");
      // expect(result.length).to.equal(2);
      expect(result.indexOf(Test) > -1).to.be.true;
      expect(result.indexOf(Test2) > -1).to.be.true;

      const result2 = Metadata.getTargetsFromPropertyKey("controller2");

      expect(result2).to.be.an("array");
      expect(result2.length).to.equal(0);
    });
  });
github TypedProject / ts-express-decorators / test / units / core / class / Metadata.spec.ts View on Github external
it("should return unique provide from property key", () => {
      Metadata.set("controller", "test", Test);
      Metadata.set("controller", "test2", Test2);
      Metadata.set("controller", "test", Test);

      const result = Metadata.getTargetsFromPropertyKey("controller");

      expect(result).to.be.an("array");
      // expect(result.length).to.equal(2);
      expect(result.indexOf(Test) > -1).to.be.true;
      expect(result.indexOf(Test2) > -1).to.be.true;

      const result2 = Metadata.getTargetsFromPropertyKey("controller2");

      expect(result2).to.be.an("array");
      expect(result2.length).to.equal(0);
    });
  });
github TypedProject / ts-express-decorators / packages / swagger / src / services / SwaggerService.ts View on Github external
endpoint.pathsMethods.forEach(pathMethod => {
        /* istanbul ignore else */
        if (!!pathMethod.method) {
          const builder = new OpenApiEndpointBuilder(endpoint, endpointUrl, pathMethod, getOperationId).build();

          deepExtends(paths, builder.paths);
          deepExtends(definitions, builder.definitions);
        }
      });
    });
github TypedProject / ts-express-decorators / packages / di / src / services / InjectorService.ts View on Github external
imports.forEach(invokeDependency());

      // Inject dependencies
      const services = deps.map(invokeDependency(token));

      currentDependency = false;

      instance = construct(services);
    } catch (error) {
      InjectionError.throwInjectorError(token, currentDependency, error);
    }

    if (instance === undefined) {
      throw new InjectionError(
        token,
        `Unable to create new instance from undefined value. Check your provider declaration for ${nameOf(token)}`
      );
    }

    if (instance && isBindable) {
      this.bindInjectableProperties(instance);
    }

    return instance;
  }
github TypedProject / ts-express-decorators / packages / common / src / mvc / class / EndpointBuilder.ts View on Github external
return (request: any, response: any, next: any) => {
      const debug = injector.settings.debug;
      /* istanbul ignore else */
      if (debug) {
        request.log.debug({
          event: "bind.request",
          target: nameOf(endpoint.target),
          methodClass: endpoint.methodClassName,
          httpMethod: request.method
        });
      }

      request.ctx.endpoint = endpoint;

      next();
    };
  }
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 / converters / services / ConverterService.ts View on Github external
// if (options.type && !isPrimitiveOrPrimitiveClass(options.type)) {
      //  return this.serializeClass(obj, options);
      // }

      if (typeof obj.toJSON === "function" && !obj.toJSON.$ignore) {
        // deserialize from serialize method
        return obj.toJSON();
      }

      // Default converter
      if (!isPrimitiveOrPrimitiveClass(obj)) {
        return this.serializeClass(obj, options);
      }
    } catch (err) {
      /* istanbul ignore next */
      throw err.name === "BAD_REQUEST" ? err : new ConverterSerializationError(getClass(obj), err);
    }

    /* istanbul ignore next */
    return obj;
  }
github TypedProject / ts-express-decorators / packages / common / src / mvc / registries / ParamRegistry.ts View on Github external
description: "BadRequest"
      }
    });

    return this;
  }

  /**
   * Create a parameters decorators
   * @param token
   * @param {Partial>} options
   * @returns {Function}
   * @deprecated
   */
  // istanbul ignore next
  @Deprecated("ParamRegistry.decorate are deprecated. Use UseFilter decorator instead")
  static decorate(token: string | Type | ParamTypes, options: Partial> = {}): ParameterDecorator {
    return (target: Type, propertyKey: string | symbol, parameterIndex: number): any => {
      if (typeof parameterIndex === "number") {
        const settings = Object.assign(
          {
            target,
            propertyKey,
            parameterIndex
          },
          options
        );

        ParamRegistry.useFilter(token, settings);
      }
    };
  }
github TypedProject / ts-express-decorators / packages / common / src / jsonschema / registries / PropertyRegistry.ts View on Github external
"400": {
        description: "BadRequest"
      }
    });

    return this;
  }

  /**
   *
   * @param {(propertyMetadata: PropertyMetadata, parameters: DecoratorParameters) => void} fn
   * @returns {Function}
   * @deprecated
   */
  // istanbul ignore next
  @Deprecated("PropertyRegistry.decorate is deprecated. Use PropertyFn instead.")
  static decorate(fn: (propertyMetadata: PropertyMetadata, parameters: DecoratorParameters) => void): Function {
    return (...parameters: any[]): any => {
      const propertyMetadata = PropertyRegistry.get(parameters[0], parameters[1]);
      const result: any = fn(propertyMetadata, parameters as DecoratorParameters);
      if (typeof result === "function") {
        result(...parameters);
      }
    };
  }
}
github TypedProject / ts-express-decorators / packages / common / src / filters / services / FilterService.ts View on Github external
/**
 * @deprecated This service will be removed in a future release. Use injectorService directly.
 */
@Service()
export class FilterService extends ProxyMap | any, Provider> {
  constructor(private injectorService: InjectorService) {
    super(injectorService, {filter: {type: ProviderType.FILTER}});
  }

  /**
   *
   * @param target
   * @returns {ControllerProvider}
   */
  @Deprecated("static FilterService.get(). Removed feature.")
  /* istanbul ignore next */
  static get(target: Type): Provider | undefined {
    return FilterRegistry.get(target);
  }

  /**
   *
   * @deprecated
   * @param target
   * @param provider
   */
  @Deprecated("static FilterService.set(). Removed feature.")
  /* istanbul ignore next */
  static set(target: Type, provider: Provider) {
    FilterRegistry.set(target, provider);