当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript utils.isNil方法代码示例

本文整理汇总了TypeScript中@nestjs/common/utils/shared.utils.isNil方法的典型用法代码示例。如果您正苦于以下问题:TypeScript utils.isNil方法的具体用法?TypeScript utils.isNil怎么用?TypeScript utils.isNil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@nestjs/common/utils/shared.utils的用法示例。


在下文中一共展示了utils.isNil方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: isNil

  public async resolveConstructorParams<T>(
    wrapper: InstanceWrapper<T>,
    module: Module,
    inject: any[],
    callback: (args) => void,
  ) {
    let isResolved = true;
    const args = isNil(inject)
      ? this.reflectConstructorParams(wrapper.metatype)
      : inject;

    const instances = await Promise.all(
      args.map(async (param, index) => {
        const paramWrapper = await this.resolveSingleParam<T>(
          wrapper,
          param,
          { index, length: args.length },
          module,
        );
        if (!paramWrapper.isResolved && !paramWrapper.forwardRef) {
          isResolved = false;
        }
        return paramWrapper.instance;
      }),
    );
    isResolved && (await callback(instances));
  }
开发者ID:a1r0,项目名称:nest,代码行数:27,代码来源:injector.ts

示例2: _throw

 public send<TResult = any, TInput = any>(
   pattern: any,
   data: TInput,
 ): Observable<TResult> {
   if (isNil(pattern) || isNil(data)) {
     return _throw(new InvalidMessageException());
   }
   return defer(async () => await this.connect()).pipe(
     mergeMap(
       () =>
         new Observable((observer: Observer<TResult>) => {
           const callback = this.createObserver(observer);
           return this.publish({ pattern, data }, callback);
         }),
     ),
   );
 }
开发者ID:a1r0,项目名称:nest,代码行数:17,代码来源:client-proxy.ts

示例3: isNil

  public async resolveConstructorParams<T>(
    wrapper: InstanceWrapper<T>,
    module: Module,
    inject: InjectorDependency[],
    callback: (args) => void,
  ) {
    let isResolved = true;

    const dependencies = isNil(inject)
      ? this.reflectConstructorParams(wrapper.metatype)
      : inject;
    const optionalDependenciesIds = isNil(inject)
      ? this.reflectOptionalParams(wrapper.metatype)
      : [];

    const instances = await Promise.all(
      dependencies.map(async (param, index) => {
        try {
          const paramWrapper = await this.resolveSingleParam<T>(
            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 null;
        }
      }),
    );
    isResolved && (await callback(instances));
  }
开发者ID:timokae,项目名称:nest,代码行数:39,代码来源:injector.ts

示例4: UnknownDependenciesException

 public async lookupComponentInExports<T = any>(
   dependencyContext: InjectorDependencyContext,
   module: Module,
   wrapper: InstanceWrapper<T>,
 ) {
   const instanceWrapper = await this.lookupComponentInRelatedModules(
     module,
     dependencyContext.name,
   );
   if (isNil(instanceWrapper)) {
     throw new UnknownDependenciesException(wrapper.name, dependencyContext, module);
   }
   return instanceWrapper;
 }
开发者ID:SARAVANA1501,项目名称:nest,代码行数:14,代码来源:injector.ts

示例5:

  public loadPrototypeOfInstance<T>(
    { metatype, name }: InstanceWrapper<T>,
    collection: Map<string, InstanceWrapper<T>>,
  ) {
    if (!collection) return null;

    const target = collection.get(name);
    if (target.isResolved || !isNil(target.inject) || !metatype.prototype)
      return null;

    collection.set(name, {
      ...collection.get(name),
      instance: Object.create(metatype.prototype),
    });
  }
开发者ID:a1r0,项目名称:nest,代码行数:15,代码来源:injector.ts

示例6: UnknownDependenciesException

 public async lookupComponentInExports<T = any>(
   components: Map<string, any>,
   { name, index, length }: { name: any; index: number; length: number },
   module: Module,
   wrapper: InstanceWrapper<T>,
 ) {
   const instanceWrapper = await this.lookupComponentInRelatedModules(
     module,
     name,
   );
   if (isNil(instanceWrapper)) {
     throw new UnknownDependenciesException(wrapper.name, index, length);
   }
   return instanceWrapper;
 }
开发者ID:a1r0,项目名称:nest,代码行数:15,代码来源:injector.ts

示例7: metatype

 async instances => {
   if (isNil(inject)) {
     currentMetatype.instance = Object.assign(
       currentMetatype.instance,
       new metatype(...instances),
     );
   } else {
     const factoryResult = currentMetatype.metatype(...instances);
     currentMetatype.instance = await this.resolveFactoryInstance(
       factoryResult,
     );
   }
   currentMetatype.isResolved = true;
   done();
 },
开发者ID:a1r0,项目名称:nest,代码行数:15,代码来源:injector.ts

示例8:

export const UNKNOWN_DEPENDENCIES_MESSAGE = (
  type: string,
  unknownDependencyContext: InjectorDependencyContext,
  module: Module,
) => {
  const { index, dependencies, key } = unknownDependencyContext;
  let message = `Nest can't resolve dependencies of the ${type}`;

  if (isNil(index)) {
    message += `. Please make sure that the "${key}" property is available in the current context.`;
    return message;
  }
  const dependenciesName = (dependencies || []).map(getDependencyName);
  dependenciesName[index] = '?';

  message += ` (`;
  message += dependenciesName.join(', ');
  message += `). Please make sure that the argument at index [${index}] is available in the ${getModuleName(module)} context.`;
  return message;
};
开发者ID:SARAVANA1501,项目名称:nest,代码行数:20,代码来源:messages.ts

示例9: metatype

 public async instantiateClass<T = any>(
   instances: any[],
   wrapper: InstanceWrapper<any>,
   targetMetatype: InstanceWrapper<any>,
 ): Promise<T> {
   const { metatype, inject } = wrapper;
   if (isNil(inject)) {
     targetMetatype.instance = Object.assign(
       targetMetatype.instance,
       new metatype(...instances),
     );
   } else {
     const factoryResult = ((targetMetatype.metatype as any) as Function)(
       ...instances,
     );
     targetMetatype.instance = await factoryResult;
   }
   targetMetatype.isResolved = true;
   return targetMetatype.instance;
 }
开发者ID:SARAVANA1501,项目名称:nest,代码行数:20,代码来源:injector.ts

示例10: return

 public async resolveProperties<T>(
   wrapper: InstanceWrapper<T>,
   module: Module,
   inject?: InjectorDependency[],
 ): Promise<PropertyDependency[]> {
   if (!isNil(inject)) {
     return [];
   }
   const properties = this.reflectProperties(wrapper.metatype);
   const instances = await Promise.all(
     properties.map(async (item: PropertyDependency) => {
       try {
         const dependencyContext = {
           key: item.key,
           name: item.name as string,
         };
         const paramWrapper = await this.resolveSingleParam<T>(
           wrapper,
           item.name,
           dependencyContext,
           module,
         );
         return (paramWrapper && paramWrapper.instance) || undefined;
       } catch (err) {
         if (!item.isOptional) {
           throw err;
         }
         return undefined;
       }
     }),
   );
   return properties.map((item: PropertyDependency, index: number) => ({
     ...item,
     instance: instances[index],
   }));
 }
开发者ID:SARAVANA1501,项目名称:nest,代码行数:36,代码来源:injector.ts


注:本文中的@nestjs/common/utils/shared.utils.isNil方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。