Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'io-ts' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
* ID FHIR Primitive Runtime Type
*/
import { Type, success, failure, identity, TypeOf } from "io-ts";
// TODO: This regex seems incorrect as well
const ID_REGEX = /[A-Za-z0-9\-\.]{1,64}/;
const isId = (m: unknown): m is string =>
typeof m === "string" && ID_REGEX.test(m);
/**
* Any combination of upper- or lower-case ASCII letters ('A'..'Z', and 'a'..'z', numerals ('0'..'9'),
* '-' and '.', with a length limit of 64 characters.
*/
export const id = new Type(
"id",
isId,
(m, c) => (isId(m) ? success(m) : failure(m, c)),
identity
);
export type id = TypeOf;
import * as t from 'io-ts';
import * as Units_ from 'maas-schemas-ts/core/components/units';
import * as ApiCommon_ from 'maas-schemas-ts/core/components/api-common';
type Defined =
| Record
| Array
| string
| boolean
| number
| null;
const Defined = t.union([
t.UnknownRecord,
t.UnknownArray,
t.string,
t.boolean,
t.number,
t.null,
]);
export const schemaId =
'http://maasglobal.com/maas-backend/customers/verification/initiate/request.json';
// Request
// The default export. More information at the top.
export type Request = t.Branded<
{
customerId?: Units_.IdentityId;
headers?: ApiCommon_.Headers;
identityId?: Units_.IdentityId;
payload?: {
import * as t from "io-ts";
import Knex from "knex";
import { formatBigNumberAsFixed } from "../../utils/format-big-number-as-fixed";
import { BigNumber, DisputeTokensRowWithTokenState, ReportingState, UIDisputeTokenInfo, UIDisputeTokens } 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) {
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") {
t.literal('STATE'),
t.literal('ERROR'),
t.literal('ACTION_RESULT'),
t.literal('ACTION'),
]);
export const RuntimeAgentEventSubtype = t.union([
// State
t.literal('RUNNING'),
t.literal('STARTING'),
t.literal('IN_PROGRESS'),
t.literal('CONFIG'),
t.literal('FAILED'),
t.literal('STOPPED'),
// Action results
t.literal('DATA_DUMP'),
// Actions
t.literal('ACKNOWLEDGED'),
t.literal('UNKNOWN'),
]);
export const RuntimeAgentEvent = t.intersection(
[
t.interface({
type: RuntimeAgentEventType,
subtype: RuntimeAgentEventSubtype,
timestamp: t.string,
message: t.string,
}),
t.partial({
payload: t.any,
data: t.string,
// 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
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),
!!! AUTO GENERATED BY CONVERT.TS REFRAIN FROM MANUAL EDITING !!!
*/
import * as t from 'io-ts';
import * as Fare_ from 'maas-schemas-ts/core/components/fare';
import * as Common_ from 'maas-schemas-ts/core/components/common';
type Defined =
| Record
| Array
| string
| boolean
| number
| null;
const Defined = t.union([
t.UnknownRecord,
t.UnknownArray,
t.string,
t.boolean,
t.number,
t.null,
]);
export const schemaId = 'http://maasglobal.com/core/product.json';
// Id
// The purpose of this remains a mystery
export type Id = t.Branded;
export const Id = t.brand(
t.string,
(x): x is t.Branded =>
!!! AUTO GENERATED BY CONVERT.TS REFRAIN FROM MANUAL EDITING !!!
*/
import * as t from 'io-ts';
import * as Station_ from 'maas-schemas-ts/core/components/station';
type Defined =
| Record
| Array
| string
| boolean
| number
| null;
const Defined = t.union([
t.UnknownRecord,
t.UnknownArray,
t.string,
t.boolean,
t.number,
t.null,
]);
export const schemaId = 'http://maasglobal.com/tsp/stations-list/response.json';
// Response
// The default export. More information at the top.
export type Response = t.Branded<
{
stations?: Array<
{
!!! AUTO GENERATED BY CONVERT.TS REFRAIN FROM MANUAL EDITING !!!
*/
import * as t from 'io-ts';
import * as Units_ from 'maas-schemas-ts/core/components/units';
type Defined =
| Record
| Array
| string
| boolean
| number
| null;
const Defined = t.union([
t.UnknownRecord,
t.UnknownArray,
t.string,
t.boolean,
t.number,
t.null,
]);
export const schemaId = 'http://maasglobal.com/maas-backend/tsp-auth/init/response.json';
// Response
// The default export. More information at the top.
export type Response = t.Branded<
{
authUrl?: Units_.Url;
} & {
PrivateTransitModeBrand
> => true,
'PrivateTransitMode',
);
export interface PrivateTransitModeBrand {
readonly PrivateTransitMode: unique symbol;
}
// TravelMode
// The default export. More information at the top.
export type TravelMode = t.Branded<
WaitingMode | TransferMode | PersonalMode | PublicTransitMode | PrivateTransitMode,
TravelModeBrand
>;
export const TravelMode = t.brand(
t.union([
WaitingMode,
TransferMode,
PersonalMode,
PublicTransitMode,
PrivateTransitMode,
]),
(
x,
): x is t.Branded<
WaitingMode | TransferMode | PersonalMode | PublicTransitMode | PrivateTransitMode,
TravelModeBrand
> => true,
'TravelMode',
);
export interface TravelModeBrand {
readonly TravelMode: unique symbol;