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


TypeScript io-ts.union函數代碼示例

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


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

示例1:

export const createConfigurationBlockInterface = (
  configType: t.LiteralType<string> | t.UnionType<Array<t.LiteralType<string>>> = t.union(
    configBlockSchemas.map(s => t.literal(s.id))
  ),
  beatConfigInterface: t.Mixed = t.Dictionary
) =>
  t.interface(
    {
      id: t.union([t.undefined, t.string]),
      type: configType,
      description: t.union([t.undefined, t.string]),
      tag: t.string,
      config: beatConfigInterface,
      last_updated: t.union([t.undefined, t.number]),
    },
    'ConfigBlock'
  );
開發者ID:elastic,項目名稱:kibana,代碼行數:17,代碼來源:domain_types.ts

示例2: if

      (props, config) => {
        if (config.options) {
          props[config.id] = t.union(config.options.map(opt => t.literal(opt.value)));
        } else if (config.validation) {
          props[config.id] = validationMap[config.validation];
        }

        return props;
      },
開發者ID:elastic,項目名稱:kibana,代碼行數:9,代碼來源:config_block_validation.ts

示例3:

 (self) => t.intersection([
   RWebpackStatsModuleBase,
   t.type({
     // More levels of modules.
     // https://webpack.js.org/api/stats/#module-objects
     modules: t.array(t.union([
       RWebpackStatsModuleSource,
       self,
     ])),
   }),
 ]),
開發者ID:FormidableLabs,項目名稱:inspectpack,代碼行數:11,代碼來源:webpack-stats.ts

示例4: registerManagementUI

    iconName: string;
    order?: number;
  }): void;
  registerManagementUI(settings: {
    sectionId?: string;
    name: string;
    basePath: string;
    visable?: boolean;
    order?: number;
  }): void;
}

export const RuntimeFrameworkInfo = t.type({
  basePath: t.string,
  license: t.type({
    type: t.union(LICENSES.map(s => t.literal(s))),
    expired: t.boolean,
    expiry_date_in_millis: t.number,
  }),
  security: t.type({
    enabled: t.boolean,
    available: t.boolean,
  }),
  settings: t.type({
    encryptionKey: t.string,
    enrollmentTokensTtlInSeconds: t.number,
    defaultUserRoles: t.array(t.string),
  }),
});

export interface FrameworkInfo extends t.TypeOf<typeof RuntimeFrameworkInfo> {}
開發者ID:lucabelluccini,項目名稱:kibana,代碼行數:31,代碼來源:adapter_types.ts

示例5: getVolume

  amountStaked: BigNumberType;
}

export interface PlatformActivityResult {
  activeUsers: BigNumber;
  numberOfTrades: BigNumber;
  openInterest: BigNumber;
  marketsCreated: BigNumber;
  volume: BigNumber;
  amountStaked: BigNumber;
  disputedMarkets: BigNumber;
}

export const PlatformActivityStatsParams = t.type({
  universe: t.string,
  endTime: t.union([t.number, t.null]),
  startTime: t.union([t.number, t.null]),
});
export type PlatformActivityStatsParamsType = t.TypeOf<typeof PlatformActivityStatsParams>;

async function getVolume(db: Knex, startBlock: number, endBlock: number, params: PlatformActivityStatsParamsType): Promise<Knex.QueryBuilder> {
  return db
    .select("amount as volume")
    .from("trades")
    .innerJoin("markets", "markets.marketId", "trades.marketId")
    .whereBetween("trades.blockNumber", [startBlock, endBlock])
    .andWhere("markets.universe", params.universe);
}

async function getAmountStaked(db: Knex, startBlock: number, endBlock: number, params: PlatformActivityStatsParamsType): Promise<Knex.QueryBuilder> {
  return db
開發者ID:AugurProject,項目名稱:augur_node,代碼行數:31,代碼來源:get-platform-activity-stats.ts

示例6: getInitialReporters

import * as t from "io-ts";
import * as Knex from "knex";
import { formatBigNumberAsFixed } from "../../utils/format-big-number-as-fixed";
import { InitialReportersRow, UIInitialReporters } from "../../types";

export const InitialReportersParams = t.type({
  universe: t.string,
  reporter: t.string,
  redeemed: t.union([t.boolean, t.null, t.undefined]),
  withRepBalance: t.union([t.boolean, t.null, t.undefined]),
});

export async function getInitialReporters(db: Knex, augur: {}, params: t.TypeOf<typeof InitialReportersParams>) {
  const query = db("initial_reports")
    .select(["marketID", "reporter", "amountStaked", "initialReporter", "redeemed", "isDesignatedReporter", "balances.balance AS repBalance"])
    .select(["transactionHash", "initial_reports.blockNumber", "logIndex", "blocks.timestamp"])
    .join("balances", "balances.owner", "=", "initial_reports.initialReporter")
    .join("universes", "universes.reputationToken", "balances.token")
    .join("blocks", "initial_reports.blockNumber", "blocks.blockNumber")
    .where("reporter", params.reporter)
    .where("universes.universe", params.universe);
  if (params.withRepBalance) query.where("repBalance", ">", "0");
  if (params.redeemed != null) query.where("redeemed", params.redeemed);
  const initialReporters: Array<InitialReportersRow<BigNumber>> = await query;
  return initialReporters.reduce((acc: UIInitialReporters<string>, cur) => {
    acc[cur.initialReporter] = formatBigNumberAsFixed<InitialReportersRow<BigNumber>, InitialReportersRow<string>>(cur);
    return acc;
  }, {});
}
開發者ID:AugurProject,項目名稱:augur_node,代碼行數:29,代碼來源:get-initial-reporters.ts

示例7: getDisputeTokens

import * as t from "io-ts";
import * as Knex from "knex";
import { formatBigNumberAsFixed } from "../../utils/format-big-number-as-fixed";
import { ReportingState, DisputeTokensRowWithTokenState, UIDisputeTokens, UIDisputeTokenInfo } from "../../types";
import { reshapeDisputeTokensRowToUIDisputeTokenInfo } from "./database";

export const DisputeTokenState = t.keyof({
  ALL: null,
  UNCLAIMED: null,
  UNFINALIZED: null,
});

export const DisputeTokensParams = t.type({
  universe: t.string,
  account: t.string,
  stakeTokenState: t.union([DisputeTokenState, t.null, t.undefined]),
});

export async function getDisputeTokens(db: Knex, augur: {}, params: t.TypeOf<typeof DisputeTokensParams>) {
  const query: Knex.QueryBuilder = db.select(["payouts.*", "disputes.crowdsourcerId as disputeToken", "balances.balance", "market_state.reportingState"]).from("disputes");
  query.join("markets", "markets.marketId", "crowdsourcers.marketId");
  query.leftJoin("market_state", "markets.marketStateId", "market_state.marketStateId");
  query.leftJoin("blocks", "markets.creationBlockNumber", "blocks.blockNumber");
  query.join("crowdsourcers", "crowdsourcers.crowdsourcerId", "disputes.crowdsourcerId");
  query.join("payouts", "payouts.payoutId", "crowdsourcers.payoutId");
  query.join("balances", "crowdsourcers.crowdsourcerId", "balances.token");
  query.where("universe", params.universe).where("disputes.reporter", params.account).where("balances.balance", ">", 0).where("balances.owner", params.account);
  if (params.stakeTokenState == null || params.stakeTokenState === "ALL") {
    // currently, do nothing, leaving this in case we want to flavor how we group or present response
  } else if (params.stakeTokenState === "UNFINALIZED") {
    query.whereNot("market_state.reportingState", ReportingState.FINALIZED);
開發者ID:AugurProject,項目名稱:augur_node,代碼行數:31,代碼來源:get-dispute-tokens.ts

示例8:

export const unionWithNullType = <T extends runtimeTypes.Mixed>(type: T) =>
  runtimeTypes.union([type, runtimeTypes.null]);
開發者ID:,項目名稱:,代碼行數:2,代碼來源:

示例9: getMarkets

import * as t from "io-ts";
import * as Knex from "knex";
import { Address, MarketsContractAddressRow, SortLimitParams } from "../../types";
import { getMarketsWithReportingState, queryModifier } from "./database";
import { createSearchProvider } from "../../database/fts";

export const GetMarketsParamsSpecific = t.type({
  universe: t.string,
  creator: t.union([t.string, t.null, t.undefined]),
  category: t.union([t.string, t.null, t.undefined]),
  search: t.union([t.string, t.null, t.undefined]),
  reportingState: t.union([t.string, t.null, t.undefined, t.array(t.string)]), // filter markets by ReportingState. If non-empty, expected to be a ReportingState or ReportingState[]
  feeWindow: t.union([t.string, t.null, t.undefined]),
  designatedReporter: t.union([t.string, t.null, t.undefined]),
  maxFee: t.union([t.number, t.null, t.undefined]),
  hasOrders: t.union([t.boolean, t.null, t.undefined]),
});

export const GetMarketsParams = t.intersection([
  GetMarketsParamsSpecific,
  SortLimitParams,
]);

// Returning marketIds should likely be more generalized, since it is a single line change for most getters (awaiting reporting, by user, etc)
export async function getMarkets(db: Knex, augur: {}, params: t.TypeOf<typeof GetMarketsParams>) {
  const columns = ["markets.marketId", "marketStateBlock.timestamp as reportingStateUpdatedOn"];
  const query = getMarketsWithReportingState(db, columns);
  query.join("blocks as marketStateBlock", "marketStateBlock.blockNumber", "market_state.blockNumber");
  query.leftJoin("blocks as lastTradeBlock", "lastTradeBlock.blockNumber", "markets.lastTradeBlockNumber").select("lastTradeBlock.timestamp as lastTradeTime");

  if (params.universe != null) query.where("universe", params.universe);
開發者ID:AugurProject,項目名稱:augur_node,代碼行數:31,代碼來源:get-markets.ts


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