Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
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();
};
}
it("should return name when null is given", () => {
expect(nameOf(null)).to.eq("null");
});
it("should return name when undefined is given", () => {
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);
}
};
static ref(type: any): JsonSchema {
const schema = new JsonSchema();
schema.$ref = `#/definitions/${nameOf(type)}`;
return schema;
}
static buildMessage(target: Type, propertyName: string | symbol, value: any) {
return `Property ${propertyName as string} on class ${nameOf(target)} is required. Given value: ${value}`;
}
}
const tokensMessage = this.tokens.map(token => nameOf(token)).join(" > ");
(value: any) => {
if (param.isRequired(value)) {
throw new RequiredParamError(nameOf(param.service), param.expression);
}
return value;
}
);
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});
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"
}
];
}