How to use the @tsed/core.nameOf 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 / 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 / test / units / core / utils / ObjectUtils.spec.ts View on Github external
it("should return name when null is given", () => {
      expect(nameOf(null)).to.eq("null");
    });
    it("should return name when undefined is given", () => {
github TypedProject / ts-express-decorators / test / integration / ajv / ajv.spec.ts View on Github external
const runValidation = (obj: any, targetType: any, collectionType?: any): Chai.Assertion => {
  try {
    const result = ajvService.validate(obj, targetType, collectionType);

    return expect(result);
  } catch (err) {
    if (err.name === "AJV_VALIDATION_ERROR") {
      const message = "" + new ParseExpressionError(nameOf(targetType), undefined, err);

      return expect(message.split("\n")[1]);
    }

    return expect("" + err);
  }
};
github TypedProject / ts-express-decorators / packages / common / src / jsonschema / class / JsonSchema.ts View on Github external
static ref(type: any): JsonSchema {
    const schema = new JsonSchema();
    schema.$ref = `#/definitions/${nameOf(type)}`;

    return schema;
  }
github TypedProject / ts-express-decorators / packages / common / src / converters / errors / RequiredPropertyError.ts View on Github external
static buildMessage(target: Type, propertyName: string | symbol, value: any) {
    return `Property ${propertyName as string} on class ${nameOf(target)} is required. Given value: ${value}`;
  }
}
github TypedProject / ts-express-decorators / packages / di / src / errors / InjectionError.ts View on Github external
    const tokensMessage = this.tokens.map(token => nameOf(token)).join(" > ");
github TypedProject / ts-express-decorators / packages / common / src / filters / class / FilterBuilder.ts View on Github external
(value: any) => {
        if (param.isRequired(value)) {
          throw new RequiredParamError(nameOf(param.service), param.expression);
        }

        return value;
      }
    );
github TypedProject / ts-express-decorators / packages / di / src / services / InjectorService.ts View on Github external
private resolve(target: TokenProvider, locals: Map, options: Partial> = {}): Promise {
    const {token, deps, construct, isBindable, imports} = this.mapInvokeOptions(target, options);
    const provider = this.getProvider(target);

    if (provider) {
      if (!provider.injectable && options.parent) {
        throw new InjectionError(token, `${nameOf(token)} ${provider.type} is not injectable to another provider`);
      }

      const {onInvoke} = GlobalProviders.getRegistrySettings(target);
      if (onInvoke) {
        onInvoke(provider, locals, deps);
      }
    }

    let instance: any;
    let currentDependency: any = false;

    try {
      const invokeDependency = (parent?: any) => (token: any, index: number): any => {
        currentDependency = {token, index, deps};

        return isInheritedFrom(token, Provider, 1) ? provider : this.invoke(token, locals, {parent});
github TypedProject / ts-express-decorators / packages / common / src / converters / errors / UnknownPropertyError.ts View on Github external
constructor(target: Type, propertyName: string | symbol) {
    super(UnknownPropertyError.buildMessage(target, propertyName));

    this.errors = [
      {
        dataPath: "",
        keyword: "unknown",
        message: `should not have property '${String(propertyName)}'`,
        modelName: nameOf(target),
        params: {
          missingProperty: propertyName
        },
        schemaPath: "#/unknown"
      }
    ];
  }