本文整理汇总了TypeScript中@tsed/core.nameOf函数的典型用法代码示例。如果您正苦于以下问题:TypeScript nameOf函数的具体用法?TypeScript nameOf怎么用?TypeScript nameOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nameOf函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: type
/**
*
* @param {any | JSONSchema6TypeName | JSONSchema6TypeName[]} value
*/
@Enumerable()
set type(value: any | JSONSchema6TypeName | JSONSchema6TypeName[]) {
if (value) {
this._refName = nameOf(value);
this._type = JsonSchema.getJsonType(value);
} else {
delete this._refName;
delete this._type;
}
}
示例2: nameOf
export function createModel<T>(
target: any,
schema: mongoose.Schema,
name: string = nameOf(target),
collection?: string,
skipInit?: boolean
): MongooseModel<T> {
Store.from(target).set(MONGOOSE_MODEL_NAME, name);
return mongoose.model(name, schema, collection, skipInit);
}
示例3: expect
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);
}
};
示例4: return
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();
};
示例5: constructor
constructor(target: Type<any>, propertyName: string | symbol) {
super(RequiredPropertyError.buildMessage(target, propertyName));
this.errors = [
{
dataPath: "",
keyword: "required",
message: `should have required property '${String(propertyName)}'`,
modelName: nameOf(target),
params: {
missingProperty: propertyName
},
schemaPath: "#/required"
}
];
}
示例6: from
/**
*
* @param obj
* @returns {HandlerBuilder}
*/
static from(obj: any | EndpointMetadata) {
return {
build(injector: InjectorService) {
const handlerMetadata = HandlerBuilder.resolve(obj, injector);
if (handlerMetadata.type === HandlerType.FUNCTION) {
injector.logger.debug("Return handler as function", handlerMetadata.handler.name);
return handlerMetadata.handler;
}
injector.logger.debug("Build handler", `${nameOf(handlerMetadata.target)}.${handlerMetadata.method}()`);
return new HandlerBuilder(handlerMetadata).build(injector);
}
};
}
示例7: log
/**
*
* @param {Express.Request} request
* @param o
* @returns {string}
*/
private log(request: Express.Request, o: any = {}) {
if (request.log && this.debug) {
const {target, injectable, method} = this.handlerMetadata;
request.log.debug(
{
type: this.handlerMetadata.type,
target: (target ? nameOf(target) : target.name) || "anonymous",
methodName: method,
injectable,
data: request.ctx.data,
...o
},
false
);
}
}
示例8: getHandler
/**
*
*/
private getHandler(locals: Map<string | Function, any>): Function {
const {token, method} = this.handlerMetadata;
const provider = this.injector.getProvider(token);
/* istanbul ignore next */
if (!provider) {
throw new Error(`${nameOf(token)} component not found in the injector`);
}
let instance: any;
if (provider.scope !== ProviderScope.SINGLETON) {
instance = this.injector.invoke<any>(provider.useClass, locals, undefined, true);
locals.set(token, instance);
} else {
instance = this.injector.get<any>(token);
}
return instance[method!].bind(instance);
}
示例9: buildMessage
/**
*
* @returns {string}
*/
static buildMessage(target: Type<any> | string, method: string, err: Error) {
return `Template rendering error : ${nameOf(target)}.${method}()\n` + err;
}
示例10: buildMessage
/**
*
* @returns {string}
* @param target
* @param propertyName
*/
static buildMessage(target: Type<any>, propertyName: string | symbol) {
return `Property ${propertyName as string} on class ${nameOf(target)} is required.`;
}