當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript shared.utils類代碼示例

本文整理匯總了TypeScript中@nestjs/common/utils/shared.utils的典型用法代碼示例。如果您正苦於以下問題:TypeScript utils類的具體用法?TypeScript utils怎麽用?TypeScript utils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了utils類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: isFunction

 .filter(prop => {
   const descriptor = Object.getOwnPropertyDescriptor(prototype, prop);
   if (descriptor.set || descriptor.get) {
     return false;
   }
   return !isConstructor(prop) && isFunction(prototype[prop]);
 })
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:7,代碼來源:metadata-scanner.ts

示例2: iterate

 public createConcreteContext<T extends any[], R extends any[]>(
   metadata: T,
 ): R {
   if (isUndefined(metadata) || isEmpty(metadata)) {
     return [] as R;
   }
   return iterate(metadata)
     .filter((guard: any) => guard && (guard.name || guard.canActivate))
     .map(guard => this.getGuardInstance(guard))
     .filter((guard: CanActivate) => guard && isFunction(guard.canActivate))
     .toArray() as R;
 }
開發者ID:a1r0,項目名稱:nest,代碼行數:12,代碼來源:guards-context-creator.ts

示例3: iterate

 public createConcreteContext<T extends any[], R extends any[]>(
   metadata: T,
 ): R {
   if (isUndefined(metadata) || isEmpty(metadata)) {
     return [] as R;
   }
   return iterate(metadata)
     .filter((pipe: any) => pipe && (pipe.name || pipe.transform))
     .map(pipe => this.getPipeInstance(pipe))
     .filter(pipe => pipe && pipe.transform && isFunction(pipe.transform))
     .map(pipe => pipe.transform.bind(pipe))
     .toArray() as R;
 }
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:13,代碼來源:pipes-context-creator.ts

示例4: RuntimeException

  public async loadInstance<T>(
    wrapper: InstanceWrapper<T>,
    collection: Map<string, InstanceWrapper<any>>,
    module: Module,
  ) {
    if (wrapper.isPending) {
      return wrapper.done$;
    }
    const done = this.applyDoneHook(wrapper);
    const { name, inject } = wrapper;

    const targetWrapper = collection.get(name);
    if (isUndefined(targetWrapper)) {
      throw new RuntimeException();
    }
    if (targetWrapper.isResolved) {
      return;
    }
    const callback = async instances => {
      const properties = await this.resolveProperties(wrapper, module, inject);
      const instance = await this.instantiateClass(
        instances,
        wrapper,
        targetWrapper,
      );
      this.applyProperties(instance, properties);
      done();
    };
    await this.resolveConstructorParams<T>(wrapper, module, inject, callback);
  }
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:30,代碼來源:injector.ts

示例5: mapRouteToRouteInfo

 public mapRouteToRouteInfo(
   route: Type<any> | RouteInfo | string,
 ): RouteInfo[] {
   if (isString(route)) {
     return [
       {
         path: this.validateRoutePath(route),
         method: RequestMethod.ALL,
       },
     ];
   }
   const routePath: string = Reflect.getMetadata(PATH_METADATA, route);
   if (this.isRouteInfo(routePath, route)) {
     return [
       {
         path: this.validateRoutePath(route.path),
         method: route.method,
       },
     ];
   }
   const paths = this.routerExplorer.scanForPaths(
     Object.create(route),
     route.prototype,
   );
   return paths.map(item => ({
     path:
       this.validateGlobalPath(routePath) + this.validateRoutePath(item.path),
     method: item.requestMethod,
   }));
 }
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:30,代碼來源:routes-mapper.ts

示例6: 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

示例7: intercept

 public async intercept(
   interceptors: NestInterceptor[],
   args: any[],
   instance: Controller,
   callback: (...args) => any,
   next: () => Promise<any>,
 ): Promise<any> {
   if (!interceptors || isEmpty(interceptors)) {
     return await await next();
   }
   const context = this.createContext(args, instance, callback);
   const start$ = defer(() => this.transformDeffered(next));
   /***
     const nextFn =  (i: number) => async () => {
     if (i <= interceptors.length) {
       return start$;
     }
     return await interceptors[i].intercept(context, nextFn(i + 1) as any);
   };
   */
   const result$ = await interceptors.reduce(
     async (stream$, interceptor) =>
       await interceptor.intercept(context, await stream$),
     Promise.resolve(start$),
   );
   return await result$.toPromise();
 }
開發者ID:timokae,項目名稱:nest,代碼行數:27,代碼來源:interceptors-consumer.ts

示例8: String

 public *scanForServerHooks(instance: NestGateway): IterableIterator<string> {
   for (const propertyKey in instance) {
     if (isFunction(propertyKey)) {
       continue;
     }
     const property = String(propertyKey);
     const isServer = Reflect.getMetadata(
       GATEWAY_SERVER_METADATA,
       instance,
       property,
     );
     if (!isUndefined(isServer)) {
       yield property;
     }
   }
 }
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:16,代碼來源:gateway-metadata-explorer.ts

示例9: UndefinedDependencyException

 public async resolveSingleParam<T>(
   wrapper: InstanceWrapper<T>,
   param: Type<any> | string | symbol | any,
   dependencyContext: InjectorDependencyContext,
   module: Module,
 ) {
   if (isUndefined(param)) {
     throw new UndefinedDependencyException(wrapper.name, dependencyContext, module);
   }
   const token = this.resolveParamToken(wrapper, param);
   return this.resolveComponentInstance<T>(
     module,
     isFunction(token) ? (token as Type<any>).name : token,
     dependencyContext,
     wrapper,
   );
 }
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:17,代碼來源:injector.ts

示例10: _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


注:本文中的@nestjs/common/utils/shared.utils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。