How to use the decoders.guard function in decoders

To help you get started, we’ve selected a few decoders 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 facebookarchive / atom-ide-ui / modules / atom-ide-ui / pkg / atom-ide-terminal / lib / createTerminal.js View on Github external
} from './config';

export type Terminal = TerminalClass;
declare class TerminalClass extends XTerminal {
  proposeGeometry: () => {rows: number, cols: number};
  fit: () => void;
  webLinksInit: (handler?: (event: Event, link: string) => void) => void;

  // TODO: Update xterm types?
  linkifier: any;
  buffer: any;
  selectionManager: any;
  dispose: () => void;
}

const assertTerminalOptionsInFeatureConfig = guard(
  object({
    cursorBlink: boolean,
    cursorStyle: either3(
      constant('block'),
      constant('underline'),
      constant('bar'),
    ),
    scrollback: number,
    fontFamily: string,
    fontSize: number,
    lineHeight: number,
    macOptionIsMeta: boolean,
    allowTransparency: boolean,
    experimentalCharAtlas: either3(
      constant('none'),
      constant('static'),
github nvie / decoders / src / types / typescript-tests.ts View on Github external
url,
} from 'decoders';

const rect = object({ type: constant('rect') });
const circle = object({ type: constant('circle') });
const shape = dispatch(field('type', string), type => {
    switch (type) {
        case 'rect':
            return rect;
        case 'circle':
            return circle;
    }
    return fail('Must be a valid shape');
});

guard(
    object({
        a0: string,
        a1: number,
        a2: optional(nullable(either4(string, email, regex(/x/, 'Must be x'), url()))),
        a3: fail('foo'),
        a4: maybe(mixed),
        a5: either3(constant('foo'), constant('bar'), constant('qux')),
        a6: exact({ c: array(poja), d: pojo }),
        a7: tuple6(hardcoded('foo'), mixed, null_, undefined_, unknown, truthy),
        a8: tuple4(integer, number, positiveInteger, positiveNumber),
        a9: either(boolean, numericBoolean),
        b0: map(
            compose(
                string,
                predicate(s => s.startsWith('x'), 'Must start with x')
            ),
github purecloudlabs / iframe-coordinator / src / workers / worker-manager.ts View on Github external
/**
 * Handler for messages received from workers which should be handled by the host
 */
export type WorkerToHostMessageHandler = (event: WorkerToHost) => void;

/**
 * Configuration options for the WorkerManager
 */
export interface WorkerManagerConfig
  extends ErrorWindowConfig,
    WorkerTerminateConfig {
  onWorkerToHostMessage?: WorkerToHostMessageHandler;
}

const validateWorkerManagerConfig: Guard = guard(
  object({
    errorWindowMillis: optional(integer),
    errorWindowCountThreshold: optional(integer),
    notifyBeforeTerminate: optional(boolean),
    terminateReadyWaitMillis: optional(integer)
  })
);

const DEFAULT_ERROR_WINDOW_CONFIG: ErrorWindowConfig = {
  errorWindowMillis: 30000,
  errorWindowCountThreshold: 10
};

/**
 * Minimum number of millis that can be set to allow a worker (spawn or spawned)
 * to terminate.
github purecloudlabs / iframe-coordinator / src / messages / HostToClient.ts View on Github external
export function validate(msg: any): HostToClient {
  return guard(
    dispatch('msgType', { publish: publicationDecoder, env_init: envDecoder })
  )(msg);
}
github purecloudlabs / iframe-coordinator / src / workers / worker-manager.ts View on Github external
* Uses WorkerManager settings if unspecied
   */
  terminateReadyWaitMillis?: number;
}

/**
 * WorkerClient registration config.
 */
export interface WorkerClientConfig
  extends ErrorWindowConfig,
    WorkerTerminateConfig {
  /** Hosted location of the worker to load */
  url: string;
}

const validateWorkerClientConfig: Guard = guard(
  object({
    url: string,
    errorWindowMillis: optional(integer),
    errorWindowCountThreshold: optional(integer),
    notifyBeforeTerminate: optional(boolean),
    terminateReadyWaitMillis: optional(integer)
  })
);

/**
 * A map from worker client identifiers to configuration describing
 * where the worker client app is hosted, options on how it should run, etc.
 */
export interface WorkerMap {
  [key: string]: WorkerClientConfig;
}
github purecloudlabs / iframe-coordinator / src / messages / ClientToHost.ts View on Github external
export function validate(msg: any): ClientToHost {
  return guard(
    dispatch('msgType', {
      publish: publicationDecoder,
      registeredKeyFired: keyDownDecoder,
      client_started: startedDecoder,
      navRequest: navRequestDecoder,
      toastRequest: toastDecoder
    })
  )(msg);
}