How to use the io-ts.keyof 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 gcanti / fp-ts-routing / test / index.ts View on Github external
it('type', () => {
    const T = t.keyof({
      a: null,
      b: null
    })
    const match = pipe(
      lit('search'),
      then(type('topic', T))
    )

    assert.deepStrictEqual(match.parser.run(Route.parse('/search/a')), some([{ topic: 'a' }, Route.empty]))
    assert.deepStrictEqual(match.parser.run(Route.parse('/search/b')), some([{ topic: 'b' }, Route.empty]))
    assert.deepStrictEqual(match.parser.run(Route.parse('/search/')), none)
  })
github gcanti / io-ts-codegen / test / fixtures / expected.ts View on Github external
PLC4X: true,
  PLC4XTransform: true,
  PLC5Y: true,
  PLC5X: true,
  PLC5XTransform: true,
  PointToPoint: true,
  IAReference: true,
  'Logit-4': true,
  'Logit-5': true
})

export type ICQCalibrationType =
  | 'Full'
  | 'Adjust'

export const ICQCalibrationType = t.keyof({
  Full: true,
  Adjust: true
})

export type ICQCalibrationStatus =
  | 'NoCal'
  | 'Ok'
  | 'Failed'
  | 'Expired'
  | 'Overridden'
  | 'OverriddenLot'
  | 'PendingQC'
  | 'InProcess'

export const ICQCalibrationStatus = t.keyof({
  NoCal: true,
github AugurProject / augur / packages / augur-node / src / server / getters / get-dispute-tokens.ts View on Github external
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");
github elastic / kibana / x-pack / legacy / plugins / infra / public / containers / logs / log_analysis / api / ml_get_jobs_summary_api.ts View on Github external
})
    ),
  });
  return pipe(
    fetchJobStatusResponsePayloadRT.decode(response),
    fold(throwErrors(createPlainError), identity)
  );
};

export const fetchJobStatusRequestPayloadRT = rt.type({
  jobIds: rt.array(rt.string),
});

export type FetchJobStatusRequestPayload = rt.TypeOf;

const datafeedStateRT = rt.keyof({
  started: null,
  stopped: null,
  '': null,
});

const jobStateRT = rt.keyof({
  closed: null,
  closing: null,
  deleting: null,
  failed: null,
  opened: null,
  opening: null,
});

export const jobSummaryRT = rt.intersection([
  rt.type({
github elastic / kibana / x-pack / legacy / plugins / infra / public / containers / metrics_explorer / with_metrics_explorer_options_url_state.tsx View on Github external
function isMetricExplorerOptions(subject: any): subject is MetricsExplorerOptions {
  const MetricRequired = t.type({
    aggregation: t.string,
  });

  const MetricOptional = t.partial({
    field: t.string,
    rate: t.boolean,
    color: t.keyof(Object.fromEntries(values(MetricsExplorerColor).map(c => [c, null])) as Record<
      string,
      null
    >),
    label: t.string,
  });

  const Metric = t.intersection([MetricRequired, MetricOptional]);

  const OptionsRequired = t.type({
    aggregation: t.string,
    metrics: t.array(Metric),
  });

  const OptionsOptional = t.partial({
    limit: t.number,
    groupBy: t.string,
github elastic / kibana / x-pack / legacy / plugins / infra / common / inventory_models / types.ts View on Github external
bar: null,
});

export type InventoryVisType = rt.TypeOf;

export const InventoryFormatterTypeRT = rt.keyof({
  abbreviatedNumber: null,
  bits: null,
  bytes: null,
  number: null,
  percent: null,
});
export type InventoryFormatterType = rt.TypeOf;
export type InventoryItemType = rt.TypeOf;

export const InventoryMetricRT = rt.keyof({
  hostSystemOverview: null,
  hostCpuUsage: null,
  hostFilesystem: null,
  hostK8sOverview: null,
  hostK8sCpuCap: null,
  hostK8sDiskCap: null,
  hostK8sMemoryCap: null,
  hostK8sPodCap: null,
  hostLoad: null,
  hostMemoryUsage: null,
  hostNetworkTraffic: null,
  hostDockerOverview: null,
  hostDockerInfo: null,
  hostDockerTop5ByCpu: null,
  hostDockerTop5ByMemory: null,
  podOverview: null,
github gcanti / io-ts-types / src / boolean / BooleanFromString.ts View on Github external
import * as t from 'io-ts'

const TrueOrFalse = t.keyof({
  true: null,
  false: null
})

export class BooleanFromStringType extends t.Type {
  readonly _tag: 'BooleanFromStringType' = 'BooleanFromStringType'
  constructor() {
    super('BooleanFromString', t.boolean.is, (u, c) => TrueOrFalse.validate(u, c).map(tof => tof === 'true'), String)
  }
}

export interface BooleanFromStringC extends BooleanFromStringType {}

export const BooleanFromString: BooleanFromStringC = new BooleanFromStringType()
github elastic / kibana / x-pack / legacy / plugins / infra / common / inventory_models / types.ts View on Github external
container: null,
  awsEC2: null,
  awsS3: null,
  awsSQS: null,
  awsRDS: null,
});

export const InventoryVisTypeRT = rt.keyof({
  line: null,
  area: null,
  bar: null,
});

export type InventoryVisType = rt.TypeOf;

export const InventoryFormatterTypeRT = rt.keyof({
  abbreviatedNumber: null,
  bits: null,
  bytes: null,
  number: null,
  percent: null,
});
export type InventoryFormatterType = rt.TypeOf;
export type InventoryItemType = rt.TypeOf;

export const InventoryMetricRT = rt.keyof({
  hostSystemOverview: null,
  hostCpuUsage: null,
  hostFilesystem: null,
  hostK8sOverview: null,
  hostK8sCpuCap: null,
  hostK8sDiskCap: null,
github elastic / kibana / x-pack / legacy / plugins / infra / public / containers / metrics_explorer / with_metrics_explorer_options_url_state.tsx View on Github external
function isMetricExplorerChartOptions(subject: any): subject is MetricsExplorerChartOptions {
  const ChartOptions = t.type({
    yAxisMode: t.keyof(Object.fromEntries(
      values(MetricsExplorerYAxisMode).map(v => [v, null])
    ) as Record),
    type: t.keyof(Object.fromEntries(
      values(MetricsExplorerChartType).map(v => [v, null])
    ) as Record),
    stack: t.boolean,
  });
  const result = ChartOptions.decode(subject);

  try {
    ThrowReporter.report(result);
    return true;
  } catch (e) {
    return false;
  }
}