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

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

      case "parameter":
        const store = Store.fromMethod(target, propertyKey);
        const multiple = Metadata.getParamTypes(target, propertyKey)[parameterIndex] === 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
          .merge("responses", {
            "400": {
              description: `  [fieldName]
                            Example: File too long file1`
            }
          })
          .set("multipartAdded", true);
github TypedProject / ts-express-decorators / packages / di / src / services / InjectorService.ts View on Github external
const provider = this.hasProvider(token) ? this.getProvider(token)! : new Provider(token);

    scope = scope || this.scopeOf(provider);
    deps = deps || provider.deps;
    imports = imports || provider.imports;

    if (provider.useValue) {
      construct = () => (isFunction(provider.useValue) ? provider.useValue() : provider.useValue);
    } else if (provider.useFactory) {
      construct = (deps: TokenProvider[]) => provider.useFactory(...deps);
    } else if (provider.useAsyncFactory) {
      construct = (deps: TokenProvider[]) => provider.useAsyncFactory(...deps);
    } else {
      // useClass
      isBindable = true;
      deps = deps || Metadata.getParamTypes(provider.useClass);
      construct = (deps: TokenProvider[]) => new provider.useClass(...deps);
    }

    return {
      token,
      scope: scope || Store.from(token).get("scope") || ProviderScope.SINGLETON,
      deps: deps! || [],
      imports: imports || [],
      isBindable,
      construct
    };
  }
}
github TypedProject / ts-express-decorators / test / units / core / class / Metadata.spec.ts View on Github external
it("should return types on constructor", () => {
      expect(Metadata.getParamTypes(Test)).to.be.an("array");
      expect(Metadata.getParamTypes(Test)[0]).to.equal(String);
    });
github TypedProject / ts-express-decorators / test / units / core / class / Metadata.spec.ts View on Github external
it("should return types on method", () => {
      expect(Metadata.getParamTypes(Test.prototype, "method")).to.be.an("array");
      expect(Metadata.getParamTypes(Test.prototype, "method")[0]).to.equal(String);
    });
  });
github TypedProject / ts-express-decorators / test / units / core / class / Metadata.spec.ts View on Github external
it("should return types on constructor", () => {
      expect(Metadata.getParamTypes(Test)).to.be.an("array");
      expect(Metadata.getParamTypes(Test)[0]).to.equal(String);
    });
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,
            propertyKey,
            useType: symbol || Metadata.getType(target, propertyKey)
          }
        });
        break;
github TypedProject / ts-express-decorators / packages / di / src / services / InjectorService.ts View on Github external
public bindMethod(instance: any, {propertyKey}: IInjectablePropertyService) {
    const target = getClass(instance);
    const originalMethod = instance[propertyKey];
    const deps = Metadata.getParamTypes(prototypeOf(target), propertyKey);

    instance[propertyKey] = () => {
      const services = deps.map((dependency: any) => this.get(dependency));

      return originalMethod.call(instance, ...services);
    };
  }
github TypedProject / ts-express-decorators / src / socketio / decorators / args.ts View on Github external
return (target: any, propertyKey: string, index: number) => {
    const store = Store.from(target);
    const type = Metadata.getParamTypes(target, propertyKey)[index];
    const param = {
      filter: SocketFilters.ARGS,
      useConverter: false
    };

    if (mapIndex !== undefined) {
      Object.assign(param, {
        mapIndex,
        useConverter: true,
        type: useType || type,
        collectionType: isCollection(type) ? type : undefined
      });
    }

    return store.merge("socketIO", {
      handlers: {