How to use the io-ts.literal 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 elastic / kibana / x-pack / legacy / plugins / fleet / server / repositories / agent_events / types.ts View on Github external
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,
github witnet / sheikah / app / common / runtimeTypes / ipc / address.ts View on Github external
requestedAmount: t.number,
    expirationDate: t.number,
  }),
], "GenerateAddressParams")
export type GenerateAddressParams = t.TypeOf

export const GenerateAddressSuccess = t.type({
  kind: t.literal("SUCCESS"),
  finalKey: ExternalFinalKey,
}, "GenerateAddressSuccess")
export type GenerateAddressSuccess = t.TypeOf

export const generateAddressErrors = {
  WRONG_PARAMS: t.literal("WRONG_PARAMS"),
  NO_UNLOCKED_WALLET: t.literal("NO_UNLOCKED_WALLET"),
  WRONG_ACCOUNT: t.literal("WRONG_ACCOUNT"),
  NON_POSITIVE_AMOUNT: t.literal("NON_POSITIVE_AMOUNT"),
  PAST_EXPIRATION_DATE: t.literal("PAST_EXPIRATION_DATE"),
  TOO_FAR_EXPIRATION_DATE: t.literal("TOO_FAR_EXPIRATION_DATE"),
  WALLET_UPDATE_FAILURE: t.literal("WALLET_UPDATE_FAILURE"),
  WALLET_STORE_FAILURE: t.literal("WALLET_STORE_FAILURE"),
  ADDRESS_GENERATION_FAILURE: t.literal("ADDRESS_GENERATION_FAILURE"),
  GENERIC_IPC_ERROR,
}

export const generateAddressErrorMessages = {
  WRONG_PARAMS: "Wrong parameters",
  NO_UNLOCKED_WALLET: "No unlocked wallet",
  WRONG_ACCOUNT: "Wrong account",
  NON_POSITIVE_AMOUNT: "A non-positive amount is forbidden",
  PAST_EXPIRATION_DATE: "Past expiration date is forbidden",
  TOO_FAR_EXPIRATION_DATE: "Expiration date is too far",
github devexperts / swagger-codegen-ts / src / swagger.ts View on Github external
const BaseParameterObjectProps = {
	name: t.string,
	description: stringOption,
};
(): t.Type => t.type(BaseParameterObjectProps); //tslint:disable-line no-unused-expression (integrity check)

//#region Path Parameter Object

export type TBasePathParameterObjectProps = TBaseParameterObjectProps & {
	in: 'path';
	required: true;
	format: Option;
};
const BasePathParameterObjectProps = {
	...BaseParameterObjectProps,
	in: t.literal('path'),
	required: t.literal(true),
	format: stringOption,
};
(): t.Type => t.type(BasePathParameterObjectProps); //tslint:disable-line no-unused-expression (integrity check)

export type TStringPathParameterObject = TBasePathParameterObjectProps & {
	type: 'string';
};
const StringPathParameterObject: t.Tagged<'type', TStringPathParameterObject, mixed> = t.type({
	...BasePathParameterObjectProps,
	type: t.literal('string'),
});

export type TNumberPathParameterObject = TBasePathParameterObjectProps & {
	type: 'number';
};
github tangdrew / fhir-ts / packages / fhir-types / src / R4 / Contributor.ts View on Github external
() =>
    t.intersection([
      t.type({
        /** author | editor | reviewer | endorser */
        type: primitives.R4.code,
        /** Who contributed the content */
        name: primitives.R4.string
      }),
      t.partial({
        /** The type of resource */
        resourceType: t.literal("Contributor"),
        /** Unique id for inter-element referencing */
        id: primitives.R4.string,
        /** Extension of id element */
        _id: Element,
        /** Additional content defined by implementations */
        extension: t.array(Extension),
        /** Extension of type element */
        _type: Element,
        /** Extension of name element */
        _name: Element,
        /** Contact details of the contributor */
        contact: t.array(ContactDetail)
      })
    ])
);
github tangdrew / fhir-ts / packages / fhir-types / src / R4 / EventDefinition.ts View on Github external
>("EventDefinition", () =>
  t.intersection([
    t.type({
      /** draft | active | retired | unknown */
      status: primitives.R4.code,
      /** "when" the event occurs (multiple = 'or') */
      trigger: t.array(TriggerDefinition)
    }),
    t.partial({
      /** The type of resource */
      resourceType: t.literal("EventDefinition"),
      /** Logical id of this artifact */
      id: primitives.R4.id,
      /** Extension of id element */
      _id: Element,
      /** Metadata about the resource */
      meta: Meta,
      /** A set of rules under which this content was created */
      implicitRules: primitives.R4.uri,
      /** Extension of implicitRules element */
      _implicitRules: Element,
      /** Language of the resource content */
      language: primitives.R4.code,
      /** Extension of language element */
      _language: Element,
      /** Text summary of the resource, for human interpretation */
      text: Narrative,
github elastic / kibana / x-pack / legacy / plugins / ingest / common / types / domain_data.ts View on Github external
last_checkin?: Date;
  event_rate?: string;
  tags: string[];
  metadata?: {};
  name?: string;
  last_updated: number;
}

export const RuntimeAgentEvent = t.interface(
  {
    type: t.union([t.literal('STATE'), t.literal('ERROR')]),
    beat: t.union([t.undefined, t.string]),
    timestamp: DateFromString,
    event: t.type({
      type: t.union([
        t.literal('RUNNING'),
        t.literal('STARTING'),
        t.literal('IN_PROGRESS'),
        t.literal('CONFIG'),
        t.literal('FAILED'),
        t.literal('STOPPED'),
      ]),
      message: t.string,
      uuid: t.union([t.undefined, t.string]),
    }),
  },
  'AgentEvent'
);
export interface AgentEvent
  extends Pick<
    t.TypeOf,
    Exclude, 'timestamp'>
github elastic / kibana / x-pack / legacy / plugins / fleet / server / repositories / agents / types.ts View on Github external
import {
  AGENT_TYPE_EPHEMERAL,
  AGENT_TYPE_PERMANENT,
  AGENT_TYPE_TEMPORARY,
} from '../../../common/constants';
import { FrameworkUser } from '../../adapters/framework/adapter_types';
import { RuntimeAgentEvent } from '../agent_events/types';

export const RuntimeAgentType = t.union([
  t.literal(AGENT_TYPE_PERMANENT),
  t.literal(AGENT_TYPE_EPHEMERAL),
  t.literal(AGENT_TYPE_TEMPORARY),
]);

const RuntimeAgentActionType = t.union([
  t.literal('POLICY_CHANGE'),
  t.literal('DATA_DUMP'),
  t.literal('RESUME'),
  t.literal('PAUSE'),
]);

export type AgentActionType = t.TypeOf;

export const RuntimeAgentActionData = t.interface(
  {
    type: RuntimeAgentActionType,
  },
  'AgentActionData'
);

export const RuntimeAgentAction = t.intersection([
  RuntimeAgentActionData,
github elastic / kibana / x-pack / legacy / plugins / fleet / server / repositories / policies / types.ts View on Github external
}

export interface PoliciesRepository {
  getPolicyOutputByIDs(user: FrameworkUser, ids: string[]): Promise;
  get(user: FrameworkUser, id: string): Promise;
}

export const RuntimeAgentPolicy = t.interface({
  outputs: t.record(
    t.string,
    t.intersection([
      t.type({
        id: t.string,
        type: t.union([
          t.literal('etc'),
          t.literal('log'),
          t.literal('metric/docker'),
          t.literal('metric/system'),
        ]),
      }),
      t.partial({
        url: t.string,
        api_token: t.string,
        username: t.string,
        pass: t.string,
        index_name: t.string,
        ingest_pipeline: t.string,
      }),
      t.UnknownRecord,
    ])
  ),
  streams: t.array(
github tangdrew / fhir-ts / packages / fhir-types / src / R4 / SubstanceReferenceInformation.ts View on Github external
() =>
    t.intersection([
      t.type({}),
      t.partial({
        /** The type of resource */
        resourceType: t.literal("SubstanceReferenceInformation"),
        /** Logical id of this artifact */
        id: primitives.R4.id,
        /** Extension of id element */
        _id: Element,
        /** Metadata about the resource */
        meta: Meta,
        /** A set of rules under which this content was created */
        implicitRules: primitives.R4.uri,
        /** Extension of implicitRules element */
        _implicitRules: Element,
        /** Language of the resource content */
        language: primitives.R4.code,
        /** Extension of language element */
        _language: Element,
        /** Text summary of the resource, for human interpretation */
        text: Narrative,
github tangdrew / fhir-ts / packages / fhir-types / src / R4 / DeviceDefinition.ts View on Github external
>("DeviceDefinition", () =>
  t.intersection([
    t.type({}),
    t.partial({
      /** The type of resource */
      resourceType: t.literal("DeviceDefinition"),
      /** Logical id of this artifact */
      id: primitives.R4.id,
      /** Extension of id element */
      _id: Element,
      /** Metadata about the resource */
      meta: Meta,
      /** A set of rules under which this content was created */
      implicitRules: primitives.R4.uri,
      /** Extension of implicitRules element */
      _implicitRules: Element,
      /** Language of the resource content */
      language: primitives.R4.code,
      /** Extension of language element */
      _language: Element,
      /** Text summary of the resource, for human interpretation */
      text: Narrative,