Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const insistSeat = seat => {
const properties = Object.getOwnPropertyNames(seat);
// The `handle` is how the use object will be looked up
insist(properties.includes('handle'))`must include 'handle'`;
insist(
passStyleOf(seat.handle) === 'presence' &&
Object.entries(seat.handle).length === 0 &&
seat.handle.constructor === Object,
)`handle should be an empty object`;
insist(passStyleOf(seat) === 'copyRecord')`seat should be a record`;
return seat;
};
function allComparable(passable) {
const passStyle = passStyleOf(passable);
switch (passStyle) {
case 'null':
case 'undefined':
case 'string':
case 'boolean':
case 'number':
case 'symbol':
case 'bigint':
case 'presence':
case 'copyError': {
return passable;
}
case 'promise': {
return passable.then(nonp => allComparable(nonp));
}
case 'copyArray': {
function mustBeSameStructureInternal(left, right, message, path) {
function complain(problem) {
const template = harden([
`${message}: ${problem} at ${pathStr(path)}: (`,
') vs (',
')',
]);
insist(false)(template, left, right);
}
const leftStyle = passStyleOf(left);
const rightStyle = passStyleOf(right);
if (leftStyle === 'promise') {
complain('Promise on left');
}
if (rightStyle === 'promise') {
complain('Promise on right');
}
if (leftStyle !== rightStyle) {
complain('different passing style');
}
switch (leftStyle) {
case 'null':
case 'undefined':
case 'string':
case 'boolean':
case 'number':
function sameStructure(left, right) {
const leftStyle = passStyleOf(left);
const rightStyle = passStyleOf(right);
insist(leftStyle !== 'promise')`\
Cannot structurally compare promises: ${left}`;
insist(rightStyle !== 'promise')`\
Cannot structurally compare promises: ${right}`;
if (leftStyle !== rightStyle) {
return false;
}
switch (leftStyle) {
case 'null':
case 'undefined':
case 'string':
case 'boolean':
case 'number':
case 'symbol':
case 'bigint':
function mustBeSameStructureInternal(left, right, message, path) {
function complain(problem) {
const template = harden([
`${message}: ${problem} at ${pathStr(path)}: (`,
') vs (',
')',
]);
insist(false)(template, left, right);
}
const leftStyle = passStyleOf(left);
const rightStyle = passStyleOf(right);
if (leftStyle === 'promise') {
complain('Promise on left');
}
if (rightStyle === 'promise') {
complain('Promise on right');
}
if (leftStyle !== rightStyle) {
complain('different passing style');
}
switch (leftStyle) {
case 'null':
case 'undefined':
case 'string':
case 'boolean':
function sameStructure(left, right) {
const leftStyle = passStyleOf(left);
const rightStyle = passStyleOf(right);
insist(leftStyle !== 'promise')`\
Cannot structurally compare promises: ${left}`;
insist(rightStyle !== 'promise')`\
Cannot structurally compare promises: ${right}`;
if (leftStyle !== rightStyle) {
return false;
}
switch (leftStyle) {
case 'null':
case 'undefined':
case 'string':
case 'boolean':
case 'number':
case 'symbol':
isEmpty: list => {
insist(passStyleOf(list) === 'copyArray')`list must be an array`;
return list.length === 0;
},
includes: (whole, part) => {