Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class VValueConverter {}
let vMeta = resources.autoRegister(container, VValueConverter);
resourceMetaType = metadata.get(metadata.resource, VValueConverter);
expect(vMeta).toBe(resourceMetaType);
@valueConverter('v')
class V {}
expect(() => resources.autoRegister(container, V)).toThrow();
// =========
class BBindingBehavior {}
let bMeta = resources.autoRegister(container, BBindingBehavior);
resourceMetaType = metadata.get(metadata.resource, BBindingBehavior);
expect(bMeta).toBe(resourceMetaType);
@bindingBehavior('b')
class B {}
expect(() => resources.autoRegister(container, B)).toThrow();
// ========
class HViewEngineHooks {
beforeCompile() {}
}
let hMeta = resources.autoRegister(container, HViewEngineHooks);
resourceMetaType = metadata.get(metadata.resource, HViewEngineHooks);
_validate(object, propertyName = null, rules = null) {
const errors = [];
if (!rules) {
rules = metadata.get(metadataKey, object);
}
if (!rules) {
// no rules defined for propertyName.
return errors;
}
rules = rules.rules;
for (let i = 0, ii = rules.length; i < ii; i++) {
const ruleInfo = rules[i];
if (propertyName !== null && ruleInfo.key !== propertyName) {
continue;
}
const { name, config } = ruleInfo.rule;
const validator = { [propertyName]: { [name]: config } };
const result = validate(object, validator);
if (result) {
errors.push(new ValidationError(ruleInfo.rule, result[propertyName][0], object, propertyName));
_validate(object, propertyName = null, rules = null) {
const errors = [];
if (!rules) {
rules = metadata.get(metadataKey, object);
}
if (!rules) {
// no rules defined for propertyName.
return errors;
}
rules = rules.rules;
for (let i = 0, ii = rules.length; i < ii; i++) {
const ruleInfo = rules[i];
if (propertyName !== null && ruleInfo.key !== propertyName) {
continue;
}
const { name, config } = ruleInfo.rule;
const validator = { [propertyName]: { [name]: config } };
const result = validate(object, validator);
if (result) {
errors.push(new ValidationError(ruleInfo.rule, result[propertyName][0], object, propertyName));
_validate(object, propertyName = null, rules = null) {
const errors = [];
if (!rules) {
rules = metadata.get(metadataKey, object);
}
if (!rules) {
return errors;
}
rules = rules.rules;
for (let i = 0, ii = rules.length; i < ii; i++) {
const ruleInfo = rules[i];
if (propertyName !== null && ruleInfo.key !== propertyName) {
continue;
}
const { name, config } = ruleInfo.rule;
const validator = { [propertyName]: { [name]: config } };
const result = validate(object, validator);
if (result) {
errors.push(new ValidationError(ruleInfo.rule, result[propertyName][0], object, propertyName));
}
function getObserver(instance, name) {
let lookup = instance.__observers__;
if (lookup === undefined) {
let ctor = Object.getPrototypeOf(instance).constructor;
let behavior = metadata.get(metadata.resource, ctor);
if (!behavior.isInitialized) {
behavior.initialize(Container.instance || new Container(), instance.constructor);
}
lookup = behavior.observerLocator.getOrCreateObserversLookup(instance);
behavior._ensurePropertiesDefined(instance, lookup);
}
return lookup[name];
}
autoRegister(key, fn) {
fn = fn === undefined ? key : fn;
if (typeof fn === 'function') {
const registration = metadata.get(metadata.registration, fn);
if (registration === undefined) {
return this.registerResolver(key, new StrategyResolver(1, fn));
}
return registration.registerResolver(this, key, fn);
}
return this.registerResolver(key, new StrategyResolver(0, fn));
}
autoRegisterAll(fns) {
autoRegister(key: any, fn?: Function): Resolver {
fn = fn === undefined ? key : fn;
if (typeof fn === 'function') {
let registration = metadata.get(metadata.registration, fn);
if (registration === undefined) {
return this.registerResolver(key, new StrategyResolver(1, fn));
}
return registration.registerResolver(this, key, fn);
}
return this.registerResolver(key, new StrategyResolver(0, fn));
}