How to use the io-ts.partial 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 AugurProject / augur / packages / augur-sdk / src / state / getter / Users.ts View on Github external
t.type({
    account: t.string,
  }),
  t.partial({
    universe: t.string,
    marketId: t.string,
    outcome: t.number,
  }),
]);

const getUserAccountParams = t.partial({
  universe: t.string,
  account: t.string,
});

const getProfitLossSummaryParams = t.partial({
  universe: t.string,
  account: t.string,
  endTime: t.number,
});

const getProfitLossParams = t.intersection([
  getProfitLossSummaryParams,
  t.partial({
    startTime: t.number,
    periodInterval: t.number,
    outcome: t.number,
  }),
]);

export interface AccountTimeRangedStatsResult {
  // Yea. The ProfitLossChanged event then
github teamdigitale / io-functions / lib / api / definitions / MessageStatus.ts View on Github external
import { MessageStatusValue } from "./MessageStatusValue";
import { Timestamp } from "./Timestamp";

/**
 *
 */

import * as t from "io-ts";
import { strictInterfaceWithOptionals } from "../../utils/types";

// required attributes
const MessageStatusR = t.interface({});

// optional attributes
const MessageStatusO = t.partial({
  status: MessageStatusValue,

  updateAt: Timestamp
});

export const MessageStatus = strictInterfaceWithOptionals(
  MessageStatusR.props,
  MessageStatusO.props,
  "MessageStatus"
);

export type MessageStatus = t.TypeOf;
github maasglobal / maas-schemas / maas-schemas-ts / src / core / components / personalDataAllowItem.ts View on Github external
import * as t from 'io-ts';

export const schemaId =
  'http://maasglobal.com/core/components/personalDataAllowItem.json';

// PersonalDataAllowItem
// The default export. More information at the top.
export type PersonalDataAllowItem = t.Branded<
  {
    type?: 'allOf' | 'anyOf';
    items?: Array;
  },
  PersonalDataAllowItemBrand
>;
export const PersonalDataAllowItem = t.brand(
  t.partial({
    type: t.union([t.literal('allOf'), t.literal('anyOf')]),
    items: t.array(t.string),
  }),
  (
    x,
  ): x is t.Branded<
    {
      type?: 'allOf' | 'anyOf';
      items?: Array;
    },
    PersonalDataAllowItemBrand
  > => true,
  'PersonalDataAllowItem',
);
export interface PersonalDataAllowItemBrand {
  readonly PersonalDataAllowItem: unique symbol;
github maasglobal / maas-schemas / maas-schemas-ts / src / maas-backend / profile / profile-favoriteLocations-add / response.ts View on Github external
import * as Profile_ from 'maas-schemas-ts/core/profile';

export const schemaId =
  'http://maasglobal.com/maas-backend/profile/profile-favoriteLocations-add/response.json';

// Response
// The default export. More information at the top.
export type Response = t.Branded<
  {
    profile?: Profile_.Profile;
    debug?: {};
  },
  ResponseBrand
>;
export const Response = t.brand(
  t.partial({
    profile: Profile_.Profile,
    debug: t.type({}),
  }),
  (
    x,
  ): x is t.Branded<
    {
      profile?: Profile_.Profile;
      debug?: {};
    },
    ResponseBrand
  > => true,
  'Response',
);
export interface ResponseBrand {
  readonly Response: unique symbol;
github maasglobal / maas-schemas / maas-schemas-ts / src / core / modes / MODE_SCOOTER.ts View on Github external
export const schemaId = 'http://maasglobal.com/core/modes/MODE_SCOOTER.json';

// MODE_SCOOTER
// The default export. More information at the top.
export type MODE_SCOOTER = t.Branded<
  {
    scooter?: {
      id?: string;
    } & {
      id: Defined;
    };
  },
  MODE_SCOOTERBrand
>;
export const MODE_SCOOTER = t.brand(
  t.partial({
    scooter: t.intersection([
      t.partial({
        id: t.string,
      }),
      t.type({
        id: Defined,
      }),
    ]),
  }),
  (
    x,
  ): x is t.Branded<
    {
      scooter?: {
        id?: string;
      } & {
github elastic / kibana / x-pack / legacy / plugins / infra / server / lib / sources / types.ts View on Github external
logAlias,
    fields: { container, host, pod, tiebreaker, timestamp },
    logColumns,
  };
};

/**
 * Static source configuration as read from the configuration file
 */

const StaticSourceConfigurationFieldsRuntimeType = runtimeTypes.partial({
  ...SavedSourceConfigurationFieldsRuntimeType.props,
  message: runtimeTypes.array(runtimeTypes.string),
});

export const StaticSourceConfigurationRuntimeType = runtimeTypes.partial({
  name: runtimeTypes.string,
  description: runtimeTypes.string,
  metricAlias: runtimeTypes.string,
  logAlias: runtimeTypes.string,
  fields: StaticSourceConfigurationFieldsRuntimeType,
  logColumns: runtimeTypes.array(SavedSourceConfigurationColumnRuntimeType),
});

export interface InfraStaticSourceConfiguration
  extends runtimeTypes.TypeOf {}

/**
 * Full source configuration type after all cleanup has been done at the edges
 */

const SourceConfigurationFieldsRuntimeType = runtimeTypes.type({
github voteflux / THE-APP / packages / lib / types / db.ts View on Github external
t.type({
        name: t.string,
        street: t.string,
        city: t.string,
        state: t.string,
        postcode: t.string,
        country: t.string,
        branch: t.string,
        ts: t.number,
        date: t.string,
        amount: t.number,
        unit: t.string,
        email: t.string,
        payment_source: t.string,
        id: t.string,
        extra_data: t.partial({
            comment: t.string,
            aud_value: t.number
        })
    }),
    t.partial({
        _id: t.string,
    })
])
export type Donation = t.TypeOf

export interface DonationsResp {donations: Donation[], totalDonations: number, pageN: number, limit: number, sortMethod: number}

export interface RoleResp {role: string, users: UserV1Object[]}

export interface RolesResp {roles: string[]}
github gql-dal / greldal / src / PaginationConfig.ts View on Github external
import * as t from "io-ts";
import * as Knex from "knex";
import { Dict, Maybe } from "./util-types";
import { has } from "lodash";
import { ColumnSelection } from "./SingleSourceQueryOperationResolver";
import { AliasHierarchyVisitor } from "./AliasHierarchyVisitor";

export const BasePaginationConfigRT = t.partial({
    pageSize: t.union([
        t.number,
        t.partial({
            max: t.number,
            default: t.number,
        }),
    ]),
});

export const AutoPaginationConfigRT = t.intersection([
    t.interface({
        cursorColumn: t.string,
    }),
    BasePaginationConfigRT,
]);
github maasglobal / maas-schemas / maas-schemas-ts / src / maas-backend / webhooks / webhooks-payments / gateway / stripe.ts View on Github external
export const Request = t.brand(
  t.intersection([
    t.partial({
      payload: t.intersection([
        t.partial({
          id: t.string,
          type: t.string,
          data: t.partial({
            object: t.partial({
              id: t.string,
              amount: t.number,
              amount_capturable: t.number,
              amount_received: t.number,
              charges: t.partial({
                data: t.array(
                  t.partial({
                    id: t.string,
                    object: t.string,
                    amount: t.number,
                    amount_refunded: t.number,
                  }),
                ),
              }),
            }),
          }),
        }),
        t.type({
          type: Defined,
          id: Defined,
          data: Defined,
        }),
      ]),
github maasglobal / maas-schemas / maas-schemas-ts / src / core / components / terms.ts View on Github external
startTimeReturn: Units_.Time,
        endTimeReturn: Units_.Time,
      }),
      t.type({
        startTime: Defined,
        endTime: Defined,
      }),
    ]),
    reusable: t.boolean,
    reconcilable: t.boolean,
    restrictions: t.partial({
      singleDevice: t.boolean,
      skipRestrictionCheck: t.boolean,
      freeTicket: t.type({}),
    }),
    surcharges: t.partial({
      midnight: Surcharge,
      pickup: Surcharge,
    }),
    cancellation: t.partial({
      cancellationFormActionUrl: Units_.Url,
      outward: Cancellation,
      return: Cancellation,
    }),
    amendment: t.partial({
      outward: Amendment,
      return: Amendment,
    }),
    fareRates: t.array(
      t.intersection([
        t.partial({
          amount: t.number,