• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript io-ts.array函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中io-ts.array函数的典型用法代码示例。如果您正苦于以下问题:TypeScript array函数的具体用法?TypeScript array怎么用?TypeScript array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: Error

export const validateConfigurationBlocks = (configurationBlocks: ConfigurationBlock[]) => {
  const validationMap = {
    isHosts: t.array(t.string),
    isString: t.string,
    isPeriod: t.string,
    isPath: t.string,
    isPaths: t.array(t.string),
    isYaml: t.string,
  };

  for (const [index, block] of configurationBlocks.entries()) {
    const blockSchema = configBlockSchemas.find(s => s.id === block.type);
    if (!blockSchema) {
      throw new Error(
        `Invalid config type of ${block.type} used in 'configuration_blocks' at index ${index}`
      );
    }

    const interfaceConfig = blockSchema.configs.reduce(
      (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;
      },
      {} as t.Props
    );

    const runtimeInterface = createConfigurationBlockInterface(
      t.literal(blockSchema.id),
      t.interface(interfaceConfig)
    );

    const validationResults = runtimeInterface.decode(block);

    if (validationResults.isLeft()) {
      throw new Error(
        `configuration_blocks validation error, configuration_blocks at index ${index} is invalid. ${
          PathReporter.report(validationResults)[0]
        }`
      );
    }
  }
};
开发者ID:elastic,项目名称:kibana,代码行数:47,代码来源:config_block_validation.ts


示例2:

 (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


示例3:

    query: t.object,
    headers: t.type({
      authorization: t.union([t.string, t.null]),
    }),
    info: t.type({
      remoteAddress: t.string,
    }),
  },
  'KibanaServerRequest'
);
export interface KibanaServerRequest extends t.TypeOf<typeof RuntimeKibanaServerRequest> {}

export const RuntimeKibanaUser = t.interface(
  {
    username: t.string,
    roles: t.array(t.string),
    full_name: t.union([t.null, t.string]),
    email: t.union([t.null, t.string]),
    enabled: t.boolean,
  },
  'KibanaUser'
);
export interface KibanaUser extends t.TypeOf<typeof RuntimeKibanaUser> {}

export interface FrameworkAuthenticatedUser<AuthDataType = any> {
  kind: 'authenticated';
  [internalAuthData]: AuthDataType;
  username: string;
  roles: string[];
  full_name: string | null;
  email: string | null;
开发者ID:njd5475,项目名称:kibana,代码行数:31,代码来源:adapter_types.ts


示例4:

  };
  options?: Array<{ value: string; text: string }>;
  validation?: 'isHosts' | 'isString' | 'isPeriod' | 'isPath' | 'isPaths' | 'isYaml';
  error: string;
  errorId: string;
  defaultValue?: string;
  required?: boolean;
  parseValidResult?: (value: any) => any;
}

export const RuntimeBeatTag = t.interface(
  {
    id: t.union([t.undefined, t.string]),
    name: t.string,
    color: t.string,
    hasConfigurationBlocksTypes: t.array(t.string),
  },
  'CMBeat'
);
export interface BeatTag
  extends Pick<
    t.TypeOf<typeof RuntimeBeatTag>,
    Exclude<keyof t.TypeOf<typeof RuntimeBeatTag>, 'id'>
  > {
  id: string;
  // Used by the UI and api when a tag exists but is an invalid option
  disabled?: boolean;
}

export const RuntimeBeatEvent = t.interface(
  {
开发者ID:elastic,项目名称:kibana,代码行数:31,代码来源:domain_types.ts


示例5: getMarketsInfo

import * as t from "io-ts";
import * as Knex from "knex";
import * as _ from "lodash";
import { BigNumber } from "bignumber.js";
import { Address, OutcomesRow, UIMarketInfo, UIMarketsInfo, UIOutcomeInfo, PayoutRow, MarketsContractAddressRow } from "../../types";
import { reshapeOutcomesRowToUIOutcomeInfo, reshapeMarketsRowToUIMarketInfo, getMarketsWithReportingState, batchAndCombine } from "./database";

export const MarketsInfoParams = t.type({
  marketIds: t.array(t.union([t.string, t.null, t.undefined])),
});

export async function getMarketsInfo(db: Knex, augur: {}, params: t.TypeOf<typeof MarketsInfoParams>): Promise<UIMarketsInfo<string>> {
  if (params.marketIds == null || ! _.isArray(params.marketIds) ) throw new Error("must include marketIds parameter");
  const marketInfoComplete: Array<UIMarketInfo<string>> = await batchAndCombine(params.marketIds, _.partial(getUIMarketsInfo, db));
  const marketsInfoByMarket = _.keyBy(marketInfoComplete, (r): string => r.id);
  return _.map(params.marketIds, (marketId: string): UIMarketInfo<string>|null => {
    return marketsInfoByMarket[marketId] || null;
  });
}

export async function getUIMarketsInfo(db: Knex, marketIds: Array<Address>): Promise<Array<UIMarketInfo<string>>> {
  const marketsQuery: Knex.QueryBuilder = getMarketsWithReportingState(db);
  const cleanedMarketIds = _.compact(marketIds);
  marketsQuery.whereIn("markets.marketId", cleanedMarketIds);
  marketsQuery.leftJoin("blocks as finalizationBlockNumber", "finalizationBlockNumber.blockNumber", "markets.finalizationBlockNumber").select("finalizationBlockNumber.timestamp as finalizationTime");
  marketsQuery.leftJoin("blocks as lastTradeBlock", "lastTradeBlock.blockNumber", "markets.lastTradeBlockNumber").select("lastTradeBlock.timestamp as lastTradeTime");
  const marketsRows = await marketsQuery;
  const outcomesRows = await db("outcomes").whereIn("marketId", cleanedMarketIds);
  const winningPayoutRows = await db("payouts").whereIn("marketId", cleanedMarketIds).where("winning", 1);
  if (!marketsRows) return [];
  const outcomesRowsByMarket = _.groupBy(outcomesRows, (r: OutcomesRow<BigNumber>): string => r.marketId);
开发者ID:AugurProject,项目名称:augur_node,代码行数:31,代码来源:get-markets-info.ts


示例6: register

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> {}

interface ManagementSection {
  register(
    sectionId: string,
    options: {
      visible: boolean;
      display: string;
      order: number;
      url: string;
    }
  ): void;
开发者ID:lucabelluccini,项目名称:kibana,代码行数:30,代码来源:adapter_types.ts


示例7:

export const Vector_IO = <RT_ITEM extends iots.Any>(Type_IO: RT_ITEM, name?: string) => (
  iots.array(Type_IO, name || ('C5TCurrent.Vector<' + Type_IO.name + '>'))
);
开发者ID:grixa,项目名称:Current,代码行数:3,代码来源:index.ts


示例8:

export const pickSavedSourceConfiguration = (value: InfraSourceConfiguration) => {
  const { container, host, pod, tiebreaker, timestamp } = value.fields;

  return {
    ...value,
    fields: { container, host, pod, tiebreaker, timestamp },
  };
};

/**
 * Static source configuration as read from the configuration file
 */

const StaticSourceConfigurationFieldsRuntimeType = runtimeTypes.partial({
  ...SavedSourceConfigurationFieldsRuntimeType.props,
  message: runtimeTypes.array(runtimeTypes.string),
});

export const StaticSourceConfigurationRuntimeType = runtimeTypes.partial({
  name: runtimeTypes.string,
  description: runtimeTypes.string,
  metricAlias: runtimeTypes.string,
  logAlias: runtimeTypes.string,
  fields: StaticSourceConfigurationFieldsRuntimeType,
});

export interface InfraStaticSourceConfiguration
  extends runtimeTypes.TypeOf<typeof StaticSourceConfigurationRuntimeType> {}

/**
 * Full source configuration type after all cleanup has been done at the edges
开发者ID:njd5475,项目名称:kibana,代码行数:31,代码来源:types.ts


示例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.array函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap