How to use the io-ts.union 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 maasglobal / maas-schemas / maas-schemas-ts / src / core / product.ts View on Github external
!!! 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 =>
github maasglobal / maas-schemas / maas-schemas-ts / src / tsp / stations-list / response.ts View on Github external
!!! 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<
      {
github maasglobal / maas-schemas / maas-schemas-ts / src / maas-backend / tsp-auth / init / response.ts View on Github external
!!! 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;
  } & {
github maasglobal / maas-schemas / maas-schemas-ts / src / core / components / travel-mode.ts View on Github external
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;
github maasglobal / maas-schemas / maas-schemas-ts / src / tsp / booking-options-list / request.ts View on Github external
import * as t from 'io-ts';
import * as TravelMode_ from 'maas-schemas-ts/core/components/travel-mode';
import * as Units_ from 'maas-schemas-ts/core/components/units';
import * as UnitsGeo_ from 'maas-schemas-ts/core/components/units-geo';
import * as Address_ from 'maas-schemas-ts/core/components/address';
import * as Booking_ from 'maas-schemas-ts/core/booking';
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/tsp/bookings-options-list/request.json';

// Request
// The default export. More information at the top.
export type Request = t.Branded<
  ({
    mode?: TravelMode_.TravelMode;
    startTime?: Units_.Time;
github elastic / kibana / x-pack / legacy / plugins / infra / common / inventory_models / types.ts View on Github external
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,
    })
);

export const SnapshotModelAggregationRT = rt.union([
  SnapshotModelMetricAggRT,
  SnapshotModelBucketScriptRT,
  SnapshotModelCumulativeSumRT,
  SnapshotModelDerivativeRT,
  SnapshotModelSumBucketRT,
  SnapshotTermsWithAggregationRT,
]);

export const SnapshotModelRT = rt.record(
  rt.string,
  rt.union([rt.undefined, SnapshotModelAggregationRT])
);
export type SnapshotModel = rt.TypeOf;

export const SnapshotMetricTypeRT = rt.keyof({
  count: null,
github maasglobal / maas-schemas / maas-schemas-ts / src / core / components / fare.ts View on Github external
amount: Defined;
    currency: Defined;
  },
  FareBrand
>;
export const Fare = t.brand(
  t.intersection([
    t.partial({
      amount: t.union([t.number, t.null]),
      currency: t.intersection([
        t.string,
        t.union([t.literal('WMP'), t.literal('TOKEN')]),
      ]),
      tokenId: TokenId,
      originalAmount: t.union([t.number, t.null]),
      productionAmount: t.union([t.number, t.null]),
      type: t.intersection([
        t.string,
        t.union([t.literal('charge'), t.literal('refund')]),
      ]),
    }),
    t.type({
      amount: Defined,
      currency: Defined,
    }),
  ]),
  (
    x,
  ): x is t.Branded<
    {
      amount?: number | null;
      currency?: string & ('WMP' | 'TOKEN');
github maasglobal / maas-schemas / maas-schemas-ts / src / core / customer.ts View on Github external
t.intersection([
        t.partial({
          WMP: t.intersection([
            t.partial({
              currency: t.literal('WMP'),
              amount: t.number,
            }),
            t.type({
              currency: Defined,
              amount: Defined,
            }),
          ]),
        }),
        t.record(
          t.string,
          t.union([
            t.intersection([
              t.partial({
                currency: t.literal('WMP'),
                amount: t.number,
              }),
              t.type({
                currency: Defined,
                amount: Defined,
              }),
            ]),
            t.intersection([
              t.partial({
                currency: t.literal('TOKEN'),
                tokenId: Fare_.TokenId,
                amount: t.union([t.number, t.null]),
              }),
github maasglobal / maas-schemas / maas-schemas-ts / src / core / components / configurator.ts View on Github external
{
    type?: 'oneOf' | 'someOf' | 'allOf' | 'oneOrNoneOf' | 'someOrNoneOf';
    name?: string;
    description?: string;
    choices?: Array;
  } & {
    type: Defined;
    name: Defined;
    choices: Defined;
  },
  ConfigBrand
>;
export const Config = t.brand(
  t.intersection([
    t.partial({
      type: t.union([
        t.literal('oneOf'),
        t.literal('someOf'),
        t.literal('allOf'),
        t.literal('oneOrNoneOf'),
        t.literal('someOrNoneOf'),
      ]),
      name: t.string,
      description: t.string,
      choices: t.array(Choice),
    }),
    t.type({
      type: Defined,
      name: Defined,
      choices: Defined,
    }),
  ]),
github AugurProject / augur / packages / augur-node / src / server / getters / get-reporting-history.ts View on Github external
import * as t from "io-ts";
import Knex from "knex";
import { JoinedReportsMarketsRow, SortLimitParams, UIReport } from "../../types";
import { formatBigNumberAsFixed } from "../../utils/format-big-number-as-fixed";
import { queryModifier } from "./database";

export const ReportingHistoryParamsSpecific = t.type({
  reporter: t.string,
  universe: t.union([t.string, t.null, t.undefined]),
  marketId: t.union([t.string, t.null, t.undefined]),
  disputeWindow: t.union([t.string, t.null, t.undefined]),
  earliestCreationTime: t.union([t.number, t.null, t.undefined]),
  latestCreationTime: t.union([t.number, t.null, t.undefined]),
});

export const ReportingHistoryParams = t.intersection([
  ReportingHistoryParamsSpecific,
  SortLimitParams,
]);

export interface UIReports {
  [universe: string]: {
    [marketId: string]: {
      crowdsourcers: Array>;
      initialReporter: UIReport|null;