How to use the tcomb.struct function in tcomb

To help you get started, we’ve selected a few tcomb 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 goodmind / cycle-telegram / lib / runtime-types / inline-types.js View on Github external
var BaseInlineQuery = function (props, name) {
    if (name === void 0) { name = 'Unknown'; }
    return t.struct(Object.assign({}, {
        type: t.String,
        id: t.String,
        reply_markup: t.maybe(k.InlineKeyboardMarkup),
        input_message_content: t.maybe(exports.InputMessageContent)
    }, props), name);
};
exports.InlineQueryResultCachedAudio = BaseInlineQuery({
github gcanti / tom / lib / Response.js View on Github external
'use strict';

var t = require('tcomb');

var Response = t.struct({
  redirect: t.Func,
  render: t.Func
}, 'Response');

module.exports = Response;
github goodmind / cycle-telegram / src / runtime-types / inline-types.ts View on Github external
const BaseInlineQuery = function (props: any, name: string = 'Unknown') {
  return t.struct(
    Object.assign(
      {},
      {
        type: t.String,
        id: t.String,
        reply_markup: t.maybe(k.InlineKeyboardMarkup),
        input_message_content: t.maybe(InputMessageContent)
      },
      props),
    name)
}
export interface BaseInlineQueryResult {
github gcanti / tom / lib / ParallelEffect.js View on Github external
var t = require('tcomb');
var Rx = require('rx');

var ParallelEffect = t.struct({
  effects: t.list(t.Any)
}, 'ParallelEffect');

ParallelEffect.prototype.toObservable = function(store) {
  return Rx.Observable.merge(this.effects.map(function (effect) {
    return effect.toObservable(store);
  }));
};

module.exports = ParallelEffect;
github gcanti / tom / lib / SequenceEffect.js View on Github external
var t = require('tcomb');
var Rx = require('rx');

var SequenceEffect = t.struct({
  effects: t.list(t.Any)
}, 'SequenceEffect');

SequenceEffect.prototype.toObservable = function(store) {
  return Rx.Observable.concat(this.effects.map(function (effect) {
    return effect.toObservable(store);
  }));
};

module.exports = SequenceEffect;
github gcanti / tom / lib / Session.js View on Github external
function getDeafultPatch(State) {
  debug('using default `Patch` constructor');
  return t.struct({
    token: t.maybe(State),
    spec: t.Obj
  }, 'Patch');
}
github zerkalica / immutable-di / src / validate / tcomb / createTcombValidator.js View on Github external
export default function createTcombValidator(schemas) {
    const rawSchema = {}
    Object.keys(schemas).forEach(key => {
        rawSchema[key] = schemas[key] || Obj
    })
    const schema = struct(rawSchema, 'State')
    return function _validate(data) {
        return formatErrors(validate(data, schema).errors)
    }
}
github goodmind / cycle-telegram / src / runtime-types / types.ts View on Github external
'administrator',
    'member',
    'left',
    'kicked'
  ])
})
export interface TcombChatMember {
  user: TcombUser,
  status: 'creator' |
          'administrator' |
          'member' |
          'left' |
          'kicked'
}

export const Chat = t.struct({
  id: t.Number,
  type: t.enums.of(['private', 'group', 'supergroup', 'channel']),
  title: t.maybe(t.String),
  username: t.maybe(t.String),
  first_name: t.maybe(t.String),
  last_name: t.maybe(t.String),
  all_members_are_administrators: t.maybe(t.Boolean)
})
export interface TcombChat {
  id: number
  type: 'private' | 'group' | 'supergroup' | 'channel',
  title?: string
  username?: string
  first_name?: string
  last_name?: string,
  all_members_are_administrators: boolean
github gcanti / tom / lib / create.js View on Github external
function create(Model, Event, Effect, initialState) {
  if (process.env.NODE_ENV !== 'production') {
    t.assert(t.isType(Effect), function () {
      return 'Invalid argument Effect ' + t.stringify(Effect) + ' supplied to create(Model, Event, Effect, initialState) (expected a type)';
    });
  }

  var State = t.struct({
    model: Model,
    effect: t.maybe(Effect)
  }, 'State');

  var reducer = createReducer(State, Event);

  var store = createStore(reducer, State(initialState));

  store.types = {
    State: State,
    Model: Model,
    Event: Event,
    Effect: Effect
  };

  //
github gcanti / tcomb-validation / index.js View on Github external
'use strict';

var t = require('tcomb');
var stringify = t.stringify;

var noobj = {};

var ValidationError = t.struct({
  message: t.Any,
  actual: t.Any,
  expected: t.Any,
  path: t.list(t.union([t.String, t.Number]))
}, 'ValidationError');

function getDefaultValidationErrorMessage(actual, expected, path) {
  var expectedName = t.getTypeName(expected);
  var to = path.length ? '/' + path.join('/') + ': ' + expectedName : expectedName;
  return 'Invalid value ' + stringify(actual) + ' supplied to ' + to;
}

function getValidationErrorMessage(actual, expected, path, context) {
  if (t.Function.is(expected.getValidationErrorMessage)) {
    return expected.getValidationErrorMessage(actual, path, context);
  }

tcomb

Type checking and DDD for JavaScript

MIT
Latest version published 6 years ago

Package Health Score

61 / 100
Full package analysis

Popular tcomb functions