How to use the decoders.constant 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 purecloudlabs / iframe-coordinator / src / messages / LabeledMsg.ts View on Github external
export function labeledDecoder(
  typeDecoder: Decoder,
  msgDecoder: Decoder
): Decoder> {
  return object({
    // TODO: in 4.0.0 make protocol and verison fields mandatory
    protocol: either(
      constant<'iframe-coordinator'>(API_PROTOCOL),
      hardcoded<'iframe-coordinator'>(API_PROTOCOL)
    ),
    version: either(string, hardcoded('unknown')),
    msgType: typeDecoder,
    msg: msgDecoder
  });
}
github facebookarchive / atom-ide-ui / modules / atom-ide-ui / pkg / atom-ide-terminal / lib / createTerminal.js View on Github external
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'),
      constant('dynamic'),
    ),
    rendererType: either(constant('canvas'), constant('dom')),
  }),
github purecloudlabs / iframe-coordinator / src / messages / Lifecycle.ts View on Github external
/**
 * Initial setup message where environmental data
 * is sent to the client.
 * @external
 */
export interface LabeledEnvInit extends LabeledMsg {
  /** Message identifier */
  msgType: 'env_init';
  /** Environment data */
  msg: SetupData;
}

/* @external */
const envDecoder: Decoder = object({
  msgType: constant<'env_init'>('env_init'),
  msg: object({
    locale: string,
    hostRootUrl: string,
    assignedRoute: string,
    registeredKeys: optional(
      array(
        object({
          key: string,
          altKey: optional(boolean),
          ctrlKey: optional(boolean),
          metaKey: optional(boolean),
          shiftKey: optional(boolean)
        })
      )
    ),
    custom: mixed
github facebookarchive / atom-ide-ui / modules / atom-ide-ui / pkg / atom-ide-terminal / lib / createTerminal.js View on Github external
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'),
      constant('dynamic'),
    ),
    rendererType: either(constant('canvas'), constant('dom')),
  }),
);
github nvie / decoders / src / types / typescript-tests.ts View on Github external
pojo,
    positiveInteger,
    positiveNumber,
    predicate,
    regex,
    string,
    truthy,
    tuple4,
    tuple6,
    undefined_,
    field,
    unknown,
    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()))),
github nvie / decoders / src / types / typescript-tests.ts View on Github external
positiveInteger,
    positiveNumber,
    predicate,
    regex,
    string,
    truthy,
    tuple4,
    tuple6,
    undefined_,
    field,
    unknown,
    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'),
github purecloudlabs / iframe-coordinator / src / messages / Publication.ts View on Github external
/**
 * A message used to publish a generic messages
 * between the clients and the host application.
 * @external
 */
export interface LabeledPublication extends LabeledMsg {
  /** Message identifier */
  msgType: 'publish';
  /** Details of the data to publish */
  msg: Publication;
}

/** @external */
const decoder: Decoder = object({
  msgType: constant<'publish'>('publish'),
  msg: object({
    topic: string,
    payload: mixed,
    clientId: optional(string)
  })
});

export { decoder };
github purecloudlabs / iframe-coordinator / src / messages / Toast.ts View on Github external
/**
 * A message used to request toasts to display
 * in the host application.
 * @external
 */
export interface LabeledToast extends LabeledMsg {
  /** Message identifier */
  msgType: 'toastRequest';
  /** Toast details */
  msg: Toast;
}

/** @external */
const decoder: Decoder = object({
  msgType: constant<'toastRequest'>('toastRequest'),
  msg: object({
    title: optional(string),
    message: string,
    custom: mixed
  })
});

export { decoder };
github purecloudlabs / iframe-coordinator / src / messages / NavRequest.ts View on Github external
/**
 * A message used to request the host navigate to another
 * URI.
 * @external
 */
export interface LabeledNavRequest extends LabeledMsg {
  /** Message identifier */
  msgType: 'navRequest';
  /** Navigation request details */
  msg: NavRequest;
}

/** @external */
const decoder: Decoder = object({
  msgType: constant<'navRequest'>('navRequest'),
  msg: object({
    url: string
  })
});

export { decoder };