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


TypeScript core.Metadata類代碼示例

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


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

示例1: getOwnEndpoints

  /**
   * Return all endpoints from the given class. This method doesn't return the endpoints from the parent of the given class.
   * @param {Type<any>} target
   * @returns {any}
   */
  static getOwnEndpoints(target: Type<any>) {
    if (!this.hasEndpoints(target)) {
      Metadata.set("endpoints", [], target);
    }

    return Metadata.getOwn("endpoints", target);
  }
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:12,代碼來源:EndpointRegistry.ts

示例2: get

  /**
   * Get an endpoint.
   * @param target
   * @param method
   */
  static get(target: Type<any>, method: string): EndpointMetadata {
    if (!this.has(target, method)) {
      const endpoint = new EndpointMetadata(target, method);
      this.getOwnEndpoints(target).push(endpoint);
      Metadata.set("endpoints", endpoint, target, method);
    }

    return Metadata.getOwn("endpoints", target, method);
  }
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:14,代碼來源:EndpointRegistry.ts

示例3: set

  /**
   *
   * @param target
   * @param propertyKey
   * @param property
   */
  static set(target: Type<any>, propertyKey: string | symbol, property: PropertyMetadata): void {
    const properties = this.getOwnProperties(target);

    properties.set(propertyKey, property);

    Metadata.set(PROPERTIES_METADATA, properties, target);
  }
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:13,代碼來源:PropertyRegistry.ts

示例4: return

  return (target: any, propertyKey: string, index: number) => {
    const store = Store.from(target);
    const type = Metadata.getParamTypes(target, propertyKey)[index];
    const param = {
      filter: SocketFilters.ARGS,
      useConverter: false
    };

    if (mapIndex !== undefined) {
      Object.assign(param, {
        mapIndex,
        useConverter: true,
        type: useType || type,
        collectionType: isCollection(type) ? type : undefined
      });
    }

    return store.merge("socketIO", {
      handlers: {
        [propertyKey]: {
          parameters: {
            [index]: param
          }
        }
      }
    });
  };
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:27,代碼來源:args.ts

示例5: return

  return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any => {
    const bindingType = getDecoratorType([target, propertyKey, descriptor], true);

    switch (bindingType) {
      case "parameter":
      case "parameter.constructor":
        if (symbol) {
          const paramTypes = Metadata.getParamTypes(target, propertyKey);

          paramTypes[descriptor as number] = symbol;
          Metadata.setParamTypes(target, propertyKey, paramTypes);
        }
        break;

      case "property":
        Store.from(target).merge("injectableProperties", {
          [propertyKey]: {
            bindingType,
            propertyKey,
            useType: symbol || Metadata.getType(target, propertyKey)
          }
        });
        break;

      case "method":
        Store.from(target).merge("injectableProperties", {
          [propertyKey]: {
            bindingType,
            propertyKey
          }
        });

        return descriptor;

      default:
        throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);
    }
  };
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:38,代碼來源:inject.ts

示例6: before

    before(() => {
      this.endpointMetadata = new EndpointMetadata(Test, "method");

      this.endpointMetadata.path = "/";
      this.endpointMetadata.httpMethod = "get";
      this.endpointMetadata.beforeMiddlewares = [() => {}];
      this.endpointMetadata.middlewares = [() => {}];
      this.endpointMetadata.afterMiddlewares = [() => {}];
      this.endpointMetadata.before([() => {}]);
      this.endpointMetadata.after([() => {}]);

      EndpointRegistry.store(Test, "method").set("test", "value");

      Metadata.set("design:returntype", Object, Test, "method");

      this.store = {};
      this.endpointMetadata.store.forEach((v: any, k: any) => (this.store[k] = v));
    });
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:18,代碼來源:EndpointMetadata.spec.ts

示例7: before

  before(() => {
    class TestServer extends ServerLoader {
      $onInit() {
      }

      $onReady() {
      }

      $onMountingMiddlewares() {
      }

      $afterRoutesInit() {
      }
    }

    Metadata.set(SERVER_SETTINGS, {debug: true, port: 8000, httpsPort: 8080}, TestServer);

    this.server = new TestServer();
    this.server.settings.httpPort = 8080;
    this.server.settings.httpsPort = 8000;
    this.useStub = Sinon.stub(this.server.expressApp, "use");
    this.setStub = Sinon.stub(this.server.expressApp, "set");
    this.engineStub = Sinon.stub(this.server.expressApp, "engine");
  });
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:24,代碼來源:ServerLoader.spec.ts

示例8: has

 /**
  * Gets a value indicating whether the target object or its prototype chain has already method registered.
  * @param target
  * @param method
  */
 static has(target: Type<any>, method: string): boolean {
   return Metadata.hasOwn("endpoints", target, method);
 }
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:8,代碼來源:EndpointRegistry.ts

示例9: hasEndpoints

 /**
  * Gets a value indicating whether the target object or its prototype chain has endpoints.
  * @param {Type<any>} target
  * @returns {boolean}
  */
 static hasEndpoints(target: Type<any>) {
   return Metadata.hasOwn("endpoints", target);
 }
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:8,代碼來源:EndpointRegistry.ts

示例10: getOwnProperties

 /**
  *
  * @param {Type<any>} target
  * @returns {Map<string | symbol, PropertyMetadata>}
  */
 static getOwnProperties(target: Type<any>): Map<string | symbol, PropertyMetadata> {
   return Metadata.hasOwn(PROPERTIES_METADATA, target)
     ? Metadata.getOwn(PROPERTIES_METADATA, target)
     : new Map<string | symbol, PropertyMetadata>();
 }
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:10,代碼來源:PropertyRegistry.ts


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