本文整理匯總了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.`;
}