How to use the io-ts.type function in io-ts

To help you get started, we’ve selected a few io-ts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wemake-services / wemake-vue-template / template / client / logic / comments / types.ts View on Github external
// This is a definition of domain model for `comments` context.

import * as ts from 'io-ts'

// Runtime type, that can be used for schema validation:
export const RawComment = ts.type({
  'id': ts.number,
  'body': ts.string,
  'email': ts.string,
})

// Static TypeScript type, that can be used as a regular `type`:
export type RawCommentType = ts.TypeOf

// We add rating only on the client (for demo purposes)
export type CommentType = RawCommentType & {
  rating: number
}

export interface CommentPayloadType {
  commentId: number
  delta: number
github nomiclabs / buidler / packages / buidler-core / src / internal / core / config / config-validation.ts View on Github external
return new t.Type(
    name,
    (u: unknown): u is TypeT | undefined => u === undefined || codec.is(u),
    (u, c) => (u === undefined ? t.success(u) : codec.validate(u, c)),
    a => (a === undefined ? undefined : codec.encode(a))
  );
}

// IMPORTANT: This t.types MUST be kept in sync with the actual types.

const BuidlerNetworkAccount = t.type({
  privateKey: t.string,
  balance: t.string
});

const BuidlerNetworkConfig = t.type({
  hardfork: optional(t.string),
  chainId: optional(t.number),
  from: optional(t.string),
  gas: optional(t.union([t.literal("auto"), t.number])),
  gasPrice: optional(t.union([t.literal("auto"), t.number])),
  gasMultiplier: optional(t.number),
  accounts: optional(t.array(BuidlerNetworkAccount)),
  blockGasLimit: optional(t.number),
  throwOnTransactionFailures: optional(t.boolean),
  throwOnCallFailures: optional(t.boolean)
});

const HDAccountsConfig = t.type({
  mnemonic: t.string,
  initialIndex: optional(t.number),
  count: optional(t.number),
github devexperts / swagger-codegen-ts / src / swagger.ts View on Github external
...BaseQueryParameterObjectProps,
	type: t.literal('number'),
});

export type TIntegerQueryParameterObject = TBaseQueryParameterObjectProps & {
	type: 'integer';
};
const IntegerQueryParameterObject: t.Tagged<'type', TIntegerQueryParameterObject, mixed> = t.type({
	...BaseQueryParameterObjectProps,
	type: t.literal('integer'),
});

export type TBooleanQueryParameterObject = TBaseQueryParameterObjectProps & {
	type: 'boolean';
};
const BooleanQueryParameterObject: t.Tagged<'type', TBooleanQueryParameterObject, mixed> = t.type({
	...BaseQueryParameterObjectProps,
	type: t.literal('boolean'),
});

export type TArrayQueryParameterObject = TBaseQueryParameterObjectProps & {
	type: 'array';
	items: TNonArrayItemsObject;
};
const ArrayQueryParameterObject: t.Tagged<'type', TArrayQueryParameterObject, mixed> = t.type({
	...BaseQueryParameterObjectProps,
	type: t.literal('array'),
	items: NonArrayItemsObject,
});

export type TQueryParameterObject =
	| TStringQueryParameterObject
github elastic / kibana / x-pack / legacy / plugins / infra / common / inventory_models / types.ts View on Github external
export const SnapshotModelCumulativeSumRT = rt.type({
  cumulative_sum: rt.type({
    buckets_path: rt.string,
  }),
});

export const SnapshotModelDerivativeRT = rt.type({
  derivative: rt.type({
    buckets_path: rt.string,
    gap_policy: rt.keyof({ skip: null, insert_zeros: null }),
    unit: rt.string,
  }),
});

export const SnapshotModelSumBucketRT = rt.type({
  sum_bucket: rt.type({
    buckets_path: rt.string,
  }),
});

interface SnapshotTermsWithAggregation {
  terms: { field: string };
  aggregations: SnapshotModel;
}

export const SnapshotTermsWithAggregationRT: rt.Type = rt.recursion(
  'SnapshotModelRT',
  () =>
    rt.type({
      terms: rt.type({ field: rt.string }),
      aggregations: SnapshotModelRT,
    })
github AugurProject / augur / packages / augur-node / src / server / getters / get-account-transfer-history.ts View on Github external
import * as t from "io-ts";
import Knex from "knex";
import { Address, Bytes32, SortLimitParams } from "../../types";
import { queryModifier } from "./database";
import { formatBigNumberAsFixed } from "../../utils/format-big-number-as-fixed";

export const AccountTransferHistoryParamsSpecific = t.type({
  account: t.string,
  token: t.union([t.string, t.null, t.undefined]),
  isInternalTransfer: t.union([t.boolean, t.null, t.undefined]),
  earliestCreationTime: t.union([t.number, t.null, t.undefined]),
  latestCreationTime: t.union([t.number, t.null, t.undefined]),
});

export const AccountTransferHistoryParams = t.intersection([
  AccountTransferHistoryParamsSpecific,
  SortLimitParams,
]);

export interface TransferRow {
  transactionHash: Bytes32;
  logIndex: number;
  blockNumber: number;
github devexperts / swagger-codegen-ts / src / swagger.ts View on Github external
export const ItemsObject: t.Type = t.recursion('ItemsObject', ItemsObject => {
	const ArrayItemsObject = t.type({
		...BaseItemsObjectProps,
		type: t.literal('array'),
		items: createOptionFromNullable(t.array(ItemsObject)),
	});
	return t.taggedUnion('type', [
		ArrayItemsObject,
		StringItemsObject,
		NumberItemsObject,
		IntegerItemsObject,
		BooleanItemsObject,
	]) as any;
});
github elastic / kibana / x-pack / legacy / plugins / infra / common / http_api / shared / time_range.ts View on Github external
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

import * as rt from 'io-ts';

export const timeRangeRT = rt.type({
  startTime: rt.number,
  endTime: rt.number,
});

export type TimeRange = rt.TypeOf;
github elastic / kibana / x-pack / legacy / plugins / infra / server / lib / adapters / log_entries / kibana_log_entries_adapter.ts View on Github external
start: bucket.from || 0,
  end: bucket.to || 0,
  topEntryKeys: bucket.top_hits_by_key.hits.hits.map(hit => ({
    tiebreaker: hit.sort[1],
    time: hit.sort[0],
  })),
});

const createQueryFilterClauses = (filterQuery: LogEntryQuery | undefined) =>
  filterQuery ? [filterQuery] : [];

const LogSummaryDateRangeBucketRuntimeType = runtimeTypes.intersection([
  runtimeTypes.type({
    doc_count: runtimeTypes.number,
    key: runtimeTypes.string,
    top_hits_by_key: runtimeTypes.type({
      hits: runtimeTypes.type({
        hits: runtimeTypes.array(
          runtimeTypes.type({
            sort: runtimeTypes.tuple([runtimeTypes.number, runtimeTypes.number]),
          })
        ),
      }),
    }),
  }),
  runtimeTypes.partial({
    from: runtimeTypes.number,
    to: runtimeTypes.number,
  }),
]);

export interface LogSummaryDateRangeBucket
github Dragory / ZeppelinBot / backend / src / plugins / Automod.ts View on Github external
match_usernames: t.boolean,
  match_nicknames: t.boolean,
  match_custom_status: t.boolean,
});
type TMatchLinksTrigger = t.TypeOf;
const defaultMatchLinksTrigger: Partial = {
  include_subdomains: true,
  match_messages: true,
  match_embeds: true,
  match_visible_names: false,
  match_usernames: false,
  match_nicknames: false,
  match_custom_status: false,
};

const BaseSpamTrigger = t.type({
  amount: t.number,
  within: t.string,
});
const BaseTextSpamTrigger = t.intersection([
  BaseSpamTrigger,
  t.type({
    per_channel: t.boolean,
  }),
]);
type TBaseTextSpamTrigger = t.TypeOf;
const defaultTextSpamTrigger: Partial> = {
  per_channel: true,
};

const MessageSpamTrigger = BaseTextSpamTrigger;
type TMessageSpamTrigger = t.TypeOf;
github witnet / sheikah / app / common / runtimeTypes / ipc / wallets.ts View on Github external
export const ImportSeedErrors = t.union(Object.values(importSeedErrors))
export type ImportSeedErrors = t.TypeOf

export const ImportSeedError = t.type({
  kind: t.literal("ERROR"),
  error: ImportSeedErrors,
})
export type ImportSeedError = t.TypeOf

export const ImportSeedResponse = t.taggedUnion("kind", [
  ImportSeedSuccess,
  ImportSeedError,
], "ImportSeedResponse")
export type ImportSeedResponse = t.TypeOf

export const GetWalletParams = t.type({
  id: t.string,
  password: t.string,
})
export type GetWalletParams = t.TypeOf

export const GetWalletSuccess = t.type({
  kind: t.literal("SUCCESS"),
  wallet: Wallet,
})
export type GetWalletSuccess = t.TypeOf

export const getWalletErrors = {
  INVALID_PARAMS_TYPE: t.literal("INVALID_PARAMS_TYPE"),
  INVALID_WALLET_TYPE: t.literal("INVALID_WALLET_TYPE"),
  CANNOT_ENCODE_WALLET: t.literal("CANNOT_ENCODE_WALLET"),
  WRONG_PASSWORD: t.literal("WRONG_PASSWORD"),