本文整理汇总了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]
}`
);
}
}
};
示例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,
])),
}),
]),
示例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;
示例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(
{
示例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);
示例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;
示例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 + '>'))
);
示例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
示例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);