{"size": 1372, "ext": "js", "max_stars_repo_path": "packages/marshal/src/helpers/tagged.js", "max_stars_repo_name": "jessysaurusrex/endo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/marshal/src/helpers/tagged.js", "max_issues_repo_name": "jessysaurusrex/endo", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/marshal/src/helpers/tagged.js", "max_forks_repo_name": "jessysaurusrex/endo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.5, "max_line_length": 77, "alphanum_fraction": 0.6698250729}
// @ts-check

// eslint-disable-next-line spaced-comment
/// <reference types="ses"/>

import {
  assertChecker,
  checkTagRecord,
  PASS_STYLE,
  checkNormalProperty,
} from './passStyle-helpers.js';

import '../types.js';
import './internal-types.js';

const { details: X } = assert;
const { ownKeys } = Reflect;
const { getPrototypeOf, prototype: objectPrototype } = Object;

/**
 *
 * @type {PassStyleHelper}
 */
export const TaggedHelper = harden({
  styleName: 'tagged',

  canBeValid: (candidate, check = x => x) =>
    checkTagRecord(candidate, 'tagged', check),

  assertValid: (candidate, passStyleOfRecur) => {
    TaggedHelper.canBeValid(candidate, assertChecker);
    assert.equal(
      getPrototypeOf(candidate),
      objectPrototype,
      X`Unexpected prototype for: ${candidate}`,
    );

    const {
      [PASS_STYLE]: _passStyle, // checkTagRecord already checked
      [Symbol.toStringTag]: _label, // checkTagRecord already checked
      payload: _payload, // value checked by recursive walk at the end
      ...rest
    } = candidate;

    assert(
      ownKeys(rest).length === 0,
      X`Unexpected properties on Remotable Proto ${ownKeys(rest)}`,
    );

    checkNormalProperty(candidate, 'payload', 'string', true, assertChecker);

    // Recursively validate that each member is passable.
    !!passStyleOfRecur(candidate.payload);
  },
});
