本文整理汇总了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'
);
示例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;
},
示例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,
])),
}),
]),
示例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> {}
示例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
示例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;
}, {});
}
示例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);
示例8:
export const unionWithNullType = <T extends runtimeTypes.Mixed>(type: T) =>
runtimeTypes.union([type, runtimeTypes.null]);
示例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);