async resolveConstructorParams(wrapper, module, inject, callback) {
     const dependencies = shared_utils_1.isNil(inject)
         ? this.reflectConstructorParams(wrapper.metatype)
         : inject;
     const optionalDependenciesIds = shared_utils_1.isNil(inject)
         ? this.reflectOptionalParams(wrapper.metatype)
         : [];
     let isResolved = true;
     const instances = await Promise.all(dependencies.map(async (param, index) => {
         try {
             const paramWrapper = await this.resolveSingleParam(wrapper, param, { index, dependencies }, module);
             if (!paramWrapper.isResolved && !paramWrapper.forwardRef) {
                 isResolved = false;
             }
             return paramWrapper.instance;
         }
         catch (err) {
             const isOptional = optionalDependenciesIds.includes(index);
             if (!isOptional) {
                 throw err;
             }
             return undefined;
         }
     }));
     isResolved && (await callback(instances));
 }
 reply(response, body, statusCode) {
     const res = response.status(statusCode);
     if (shared_utils_1.isNil(body)) {
         return res.send();
     }
     return shared_utils_1.isObject(body) ? res.json(body) : res.send(String(body));
 }
 async lookupComponentInExports(dependencyContext, module, wrapper) {
     const instanceWrapper = await this.lookupComponentInRelatedModules(module, dependencyContext.name);
     if (shared_utils_1.isNil(instanceWrapper)) {
         throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, module);
     }
     return instanceWrapper;
 }
 loadPrototypeOfInstance({ metatype, name }, collection) {
     if (!collection) {
         return null;
     }
     const target = collection.get(name);
     if (target.isResolved || !shared_utils_1.isNil(target.inject) || !metatype.prototype) {
         return null;
     }
     collection.set(name, Object.assign({}, collection.get(name), { instance: Object.create(metatype.prototype) }));
 }
 async instantiateClass(instances, wrapper, targetMetatype) {
     const { metatype, inject } = wrapper;
     if (shared_utils_1.isNil(inject)) {
         targetMetatype.instance = wrapper.forwardRef
             ? Object.assign(targetMetatype.instance, new metatype(...instances))
             : new metatype(...instances);
     }
     else {
         const factoryResult = targetMetatype.metatype(...instances);
         targetMetatype.instance = await factoryResult;
     }
     targetMetatype.isResolved = true;
     return targetMetatype.instance;
 }
Example #6
0
 storeComponent(component, token) {
     const isCustomProvider = component && !shared_utils_1.isNil(component.provide);
     if (!isCustomProvider) {
         return this.container.addComponent(component, token);
     }
     const applyProvidersMap = this.getApplyProvidersMap();
     const providersKeys = Object.keys(applyProvidersMap);
     const type = component.provide;
     if (providersKeys.indexOf(type) < 0) {
         return this.container.addComponent(component, token);
     }
     const providerToken = random_string_generator_util_1.randomStringGenerator();
     this.applicationProvidersApplyMap.push({
         type,
         moduleKey: token,
         providerKey: providerToken,
     });
     this.container.addComponent(Object.assign({}, component, { provide: providerToken }), token);
 }
 async resolveProperties(wrapper, module, inject) {
     if (!shared_utils_1.isNil(inject)) {
         return [];
     }
     const properties = this.reflectProperties(wrapper.metatype);
     const instances = await Promise.all(properties.map(async (item) => {
         try {
             const dependencyContext = {
                 key: item.key,
                 name: item.name,
             };
             const paramWrapper = await this.resolveSingleParam(wrapper, item.name, dependencyContext, module);
             return (paramWrapper && paramWrapper.instance) || undefined;
         }
         catch (err) {
             if (!item.isOptional) {
                 throw err;
             }
             return undefined;
         }
     }));
     return properties.map((item, index) => (Object.assign({}, item, { instance: instances[index] })));
 }
 .filter(item => !shared_utils_1.isNil(item.instance))
Example #9
0
 return transform(callback(data)).pipe(operators_1.filter(response => !shared_utils_1.isNil(response)), operators_1.map(response => [response, ack]));