How to use the io-ts.intersection 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 / leg.ts View on Github external
// TransferLeg
// The purpose of this remains a mystery
export type TransferLeg = t.Branded<
  {
    startTime?: Units_.Time;
    endTime?: Units_.Time;
    mode?: TravelMode_.TransferMode;
  } & {
    mode: Defined;
    startTime: Defined;
    endTime: Defined;
  },
  TransferLegBrand
>;
export const TransferLeg = t.brand(
  t.intersection([
    t.partial({
      startTime: Units_.Time,
      endTime: Units_.Time,
      mode: TravelMode_.TransferMode,
    }),
    t.type({
      mode: Defined,
      startTime: Defined,
      endTime: Defined,
    }),
  ]),
  (
    x,
  ): x is t.Branded<
    {
      startTime?: Units_.Time;
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;
    },
  };
}

// Look up a user's reporting history (i.e., all reports submitted by a given reporter); should take reporter (address) as a required parameter and take market, universe, and disputeWindow all as optional parameters. For reporting windows that are complete, should also include the consensus outcome, whether the user's report matched the consensus, how much REP the user gained or lost from redistribution, and how much the user earned in reporting fees.
export async function getReportingHistory(db: Knex, augur: {}, params: t.TypeOf): Promise> {
  if (params.universe == null && params.marketId == null && params.disputeWindow == null) throw new Error("Must provide reference to universe, specify universe, marketId, or disputeWindow");
github maasglobal / maas-schemas / maas-schemas-ts / src / maas-backend / bookings / bookings-create / response.ts View on Github external
export const schemaId =
  'http://maasglobal.com/maas-backend/bookings/bookings-create/response.json';

// Response
// The default export. More information at the top.
export type Response = t.Branded<
  {
    booking?: Booking_.Booking;
    debug?: {};
  } & {
    booking: Defined;
  },
  ResponseBrand
>;
export const Response = t.brand(
  t.intersection([
    t.partial({
      booking: Booking_.Booking,
      debug: t.type({}),
    }),
    t.type({
      booking: Defined,
    }),
  ]),
  (
    x,
  ): x is t.Branded<
    {
      booking?: Booking_.Booking;
      debug?: {};
    } & {
      booking: Defined;
github maasglobal / maas-schemas / maas-schemas-ts / src / tsp / booking-options-list / response.ts View on Github external
// Response
// The default export. More information at the top.
export type Response = t.Branded<
  {
    options?: Array;
    additional?: {
      bikeStations?: Array;
    };
  } & {
    options: Defined;
  },
  ResponseBrand
>;
export const Response = t.brand(
  t.intersection([
    t.partial({
      options: t.array(BookingOption_.BookingOption),
      additional: t.partial({
        bikeStations: t.array(BikeStation_.BikeStation),
      }),
    }),
    t.type({
      options: Defined,
    }),
  ]),
  (
    x,
  ): x is t.Branded<
    {
      options?: Array;
      additional?: {
github nikersify / jay / source / moduler.ts View on Github external
function _resolve(id: string): Resolved {
		// 1. Resolve local relative modules
		if (isLocalModuleId(id)) {
			return {
				location: 'relative',
				// We let this throw normally
				filepath: resolve.sync(id, {
					basedir: process.cwd()
				})
			}
		}

		const strippedId = stripVersion(id)

		const Pkg = t.type({
			package: t.intersection([
				t.type({
					name: t.string,
					version: t.string
				}),
				t.record(t.string, t.unknown)
			]),
			path: t.string
		})

		const decodePkg = (filepath: string) =>
			Pkg.decode(readPkgUp.sync({
				cwd: path.dirname(filepath)
			})).getOrElseL(() => {
				throw new Error(`\`${id}\` has an invalid \`package.json\` file`)
			})
github elastic / kibana / x-pack / legacy / plugins / fleet / server / repositories / agents / types.ts View on Github external
version: t.string,
  enrolled_at: t.string,
  user_provided_metadata: t.dictionary(t.string, t.string),
  local_metadata: t.dictionary(t.string, t.string),
  shared_id: t.string,
  access_api_key_id: t.string,
  access_api_key: t.string,
  policy_id: t.string,
});

export const NewRuntimeAgent = t.intersection([
  t.interface(newAgentProperties),
  newAgentOptionalProperties,
]);

export const RuntimeAgent = t.intersection([
  t.interface({
    ...newAgentProperties,
    id: t.string,
    actions: t.array(RuntimeAgentAction),
    current_error_events: t.array(RuntimeAgentEvent),
  }),
  t.partial({
    last_updated: t.string,
    last_checkin: t.string,
  }),
  newAgentOptionalProperties,
]);

export const RuntimeSavedObjectAgentAttributes = t.intersection([
  t.partial({
    shared_id: t.string,
github devexperts / swagger-codegen-ts / src / schema / asyncapi-2.0.0 / schema-object.ts View on Github external
readonly type: 'number';
}
const NumberSchemaObjectCodec: Codec = intersection(
	[
		BaseNumericSchemaObjectCodec,
		type({
			type: literal('number'),
		}),
	],
	'NumberSchemaObject',
);

export interface IntegerSchemaObject extends BaseNumericSchemaObject {
	readonly type: 'integer';
}
const IntegerSchemaObjectCodec: Codec = intersection(
	[
		BaseNumericSchemaObjectCodec,
		type({
			type: literal('integer'),
		}),
	],
	'IntegerSchemaObject',
);

export interface StringSchemaObject extends BasePrimitiveSchemaObject {
	readonly type: 'string';
	readonly maxLength: Option;
	readonly minLength: Option;
	readonly pattern: Option;
}
const StringSchemaObjectCodec: Codec = intersection(
github devexperts / swagger-codegen-ts / src / schema / asyncapi-2.0.0 / schema-object.ts View on Github external
BasePrimitiveSchemaObjectCodec,
		type({
			type: literal('boolean'),
		}),
	],
	'BooleanSchemaObject',
);

export interface BaseNumericSchemaObject extends BasePrimitiveSchemaObject {
	readonly multipleOf: Option;
	readonly maximum: Option;
	readonly exclusiveMaximum: Option;
	readonly minimum: Option;
	readonly exclusiveMinimum: Option;
}
const BaseNumericSchemaObjectCodec: Codec = intersection(
	[
		BasePrimitiveSchemaObjectCodec,
		type({
			multipleOf: optionFromNullable(positive),
			maximum: optionFromNullable(number),
			exclusiveMaximum: optionFromNullable(number),
			minimum: optionFromNullable(number),
			exclusiveMinimum: optionFromNullable(number),
		}),
	],
	'BaseNumericSchemaObject',
);

export interface NumberSchemaObject extends BaseNumericSchemaObject {
	readonly type: 'number';
}
github devexperts / swagger-codegen-ts / src / schema / asyncapi-2.0.0 / schema-object.ts View on Github external
BasePrimitiveSchemaObjectCodec,
		type({
			multipleOf: optionFromNullable(positive),
			maximum: optionFromNullable(number),
			exclusiveMaximum: optionFromNullable(number),
			minimum: optionFromNullable(number),
			exclusiveMinimum: optionFromNullable(number),
		}),
	],
	'BaseNumericSchemaObject',
);

export interface NumberSchemaObject extends BaseNumericSchemaObject {
	readonly type: 'number';
}
const NumberSchemaObjectCodec: Codec = intersection(
	[
		BaseNumericSchemaObjectCodec,
		type({
			type: literal('number'),
		}),
	],
	'NumberSchemaObject',
);

export interface IntegerSchemaObject extends BaseNumericSchemaObject {
	readonly type: 'integer';
}
const IntegerSchemaObjectCodec: Codec = intersection(
	[
		BaseNumericSchemaObjectCodec,
		type({
github maasglobal / maas-schemas / maas-schemas-ts / src / maas-backend / products / provider.ts View on Github external
>;
export const Provider = t.brand(
  t.intersection([
    t.partial({
      name: t.string,
      agencyId: Common_.AgencyId,
      groupId: t.string,
      hidden: t.boolean,
      branding: t.partial({
        primaryColor: t.string,
        secondaryColor: t.string,
        icon: Units_.Url,
        logoSolidColor: Units_.Url,
        logoFullColor: Units_.Url,
      }),
      features: t.intersection([
        t.partial({
          ticket: t.boolean,
          stationsList: t.boolean,
          stationsRetrieve: t.boolean,
        }),
        t.type({
          ticket: Defined,
          stationsList: Defined,
          stationsRetrieve: Defined,
        }),
      ]),
      extra: t.partial({
        radius: t.intersection([
          t.partial({
            fixedFareAmount: t.number,
            fixedFareCurrency: t.union([