Skip to content

Commit

Permalink
feat(pass-style): extract passStyleOf to new pass-style package
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 14, 2023
1 parent c4b3fff commit 9f05227
Show file tree
Hide file tree
Showing 42 changed files with 283 additions and 279 deletions.
2 changes: 1 addition & 1 deletion packages/far/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"homepage": "https://github.com/endojs/endo#readme",
"dependencies": {
"@endo/eventual-send": "^0.16.9",
"@endo/marshal": "^0.8.2"
"@endo/pass-style": "^0.1.0"
},
"devDependencies": {
"@endo/init": "^0.5.53",
Expand Down
2 changes: 1 addition & 1 deletion packages/far/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { E } from '@endo/eventual-send';
export { Far, getInterfaceOf, passStyleOf } from '@endo/marshal';
export { Far, getInterfaceOf, passStyleOf } from '@endo/pass-style';

/**
* @template Primary
Expand Down
35 changes: 4 additions & 31 deletions packages/marshal/index.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
export { mapIterable, filterIterable } from './src/helpers/iter-helpers.js';
export {
PASS_STYLE,
isObject,
assertChecker,
getTag,
hasOwnPropertyOf,
} from './src/helpers/passStyle-helpers.js';

export { getErrorConstructor, toPassableError } from './src/helpers/error.js';
export { getInterfaceOf } from './src/helpers/remotable.js';

export {
nameForPassableSymbol,
passableSymbolForName,
} from './src/helpers/symbol.js';

export { passStyleOf, assertPassable } from './src/passStyleOf.js';

export { deeplyFulfilled } from './src/deeplyFulfilled.js';

export { makeTagged } from './src/makeTagged.js';
export { Remotable, Far, ToFarFunction } from './src/make-far.js';

export { QCLASS } from './src/encodeToCapData.js';
export { makeMarshal } from './src/marshal.js';
export { stringify, parse } from './src/marshal-stringify.js';

export { decodeToJustin } from './src/marshal-justin.js';

export {
assertRecord,
assertCopyArray,
assertRemotable,
isRemotable,
isRecord,
isCopyArray,
} from './src/typeGuards.js';

// eslint-disable-next-line import/export
export * from './src/types.js';

// For compatibility, but importers of these should instead import these
// directly from `@endo/pass-style` or (if applicable) `@endo/far`.
export * from '@endo/pass-style';
1 change: 1 addition & 0 deletions packages/marshal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"dependencies": {
"@endo/eventual-send": "^0.16.9",
"@endo/nat": "^4.1.24",
"@endo/pass-style": "^0.1.0",
"@endo/promise-kit": "^0.2.53"
},
"devDependencies": {
Expand Down
4 changes: 1 addition & 3 deletions packages/marshal/src/deeplyFulfilled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import { E } from '@endo/eventual-send';
import { isPromise } from '@endo/promise-kit';
import { getTag, isObject } from './helpers/passStyle-helpers.js';
import { makeTagged } from './makeTagged.js';
import { passStyleOf } from './passStyleOf.js';
import { getTag, isObject, makeTagged, passStyleOf } from '@endo/pass-style';

/** @typedef {import('./types.js').Passable} Passable */
/** @template T @typedef {import('@endo/eventual-send').ERef<T>} ERef */
Expand Down
5 changes: 1 addition & 4 deletions packages/marshal/src/dot-membrane.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
/// <reference types="ses"/>

import { E } from '@endo/eventual-send';
import { isObject } from './helpers/passStyle-helpers.js';
import { getInterfaceOf } from './helpers/remotable.js';
import { Far } from './make-far.js';
import { isObject, getInterfaceOf, Far, passStyleOf } from '@endo/pass-style';
import { makeMarshal } from './marshal.js';
import { passStyleOf } from './passStyleOf.js';

const { fromEntries } = Object;
const { ownKeys } = Reflect;
Expand Down
14 changes: 7 additions & 7 deletions packages/marshal/src/encodePassable.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable no-bitwise */
import { getTag } from './helpers/passStyle-helpers.js';
import { makeTagged } from './makeTagged.js';
import { passStyleOf } from './passStyleOf.js';
import { assertRecord } from './typeGuards.js';
import {
getTag,
makeTagged,
passStyleOf,
assertRecord,
isErrorLike,
nameForPassableSymbol,
passableSymbolForName,
} from './helpers/symbol.js';
import { ErrorHelper } from './helpers/error.js';
} from '@endo/pass-style';

/** @typedef {import('./types.js').PassStyle} PassStyle */
/** @typedef {import('./types.js').Passable} Passable */
Expand Down Expand Up @@ -305,7 +305,7 @@ export const makeEncodePassable = ({
encodeError = (err, _) => Fail`error unexpected: ${err}`,
} = {}) => {
const encodePassable = passable => {
if (ErrorHelper.canBeValid(passable)) {
if (isErrorLike(passable)) {
return encodeError(passable, encodePassable);
}
const passStyle = passStyleOf(passable);
Expand Down
13 changes: 5 additions & 8 deletions packages/marshal/src/encodeToCapData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@
// encodes to CapData, a JSON-representable data structure, and leaves it to
// the caller (`marshal.js`) to stringify it.

import { passStyleOf } from './passStyleOf.js';

import { ErrorHelper } from './helpers/error.js';
import { makeTagged } from './makeTagged.js';
import {
passStyleOf,
isErrorLike,
makeTagged,
isObject,
getTag,
hasOwnPropertyOf,
} from './helpers/passStyle-helpers.js';
import {
assertPassableSymbol,
nameForPassableSymbol,
passableSymbolForName,
} from './helpers/symbol.js';
} from '@endo/pass-style';

/** @typedef {import('./types.js').Passable} Passable */
/** @typedef {import('./types.js').Encoding} Encoding */
Expand Down Expand Up @@ -249,7 +246,7 @@ export const makeEncodeToCapData = ({
}
};
const encodeToCapData = passable => {
if (ErrorHelper.canBeValid(passable)) {
if (isErrorLike(passable)) {
// We pull out this special case to accommodate errors that are not
// valid Passables. For example, because they're not frozen.
// The special case can only ever apply at the root, and therefore
Expand Down
14 changes: 7 additions & 7 deletions packages/marshal/src/encodeToSmallcaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
// encodes to Smallcaps, a JSON-representable data structure, and leaves it to
// the caller (`marshal.js`) to stringify it.

import { passStyleOf } from './passStyleOf.js';

import { ErrorHelper } from './helpers/error.js';
import { makeTagged } from './makeTagged.js';
import { getTag, hasOwnPropertyOf } from './helpers/passStyle-helpers.js';
import {
passStyleOf,
isErrorLike,
makeTagged,
getTag,
hasOwnPropertyOf,
assertPassableSymbol,
nameForPassableSymbol,
passableSymbolForName,
} from './helpers/symbol.js';
} from '@endo/pass-style';

/** @typedef {import('./types.js').Passable} Passable */
/** @typedef {import('./types.js').Remotable} Remotable */
Expand Down Expand Up @@ -269,7 +269,7 @@ export const makeEncodeToSmallcaps = ({
}
};
const encodeToSmallcaps = passable => {
if (ErrorHelper.canBeValid(passable)) {
if (isErrorLike(passable)) {
// We pull out this special case to accommodate errors that are not
// valid Passables. For example, because they're not frozen.
// The special case can only ever apply at the root, and therefore
Expand Down
12 changes: 8 additions & 4 deletions packages/marshal/src/marshal-justin.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/// <reference types="ses"/>

import { Nat } from '@endo/nat';
import {
getErrorConstructor,
isObject,
passableSymbolForName,
} from '@endo/pass-style';
import { QCLASS } from './encodeToCapData.js';

import { getErrorConstructor } from './helpers/error.js';
import { isObject } from './helpers/passStyle-helpers.js';
import { AtAtPrefixPattern, passableSymbolForName } from './helpers/symbol.js';

/** @typedef {import('./types.js').Encoding} Encoding */
/** @template T @typedef {import('./types.js').CapData<T>} CapData */

Expand Down Expand Up @@ -112,6 +113,9 @@ const makeNoIndenter = () => {
};

const identPattern = /^[a-zA-Z]\w*$/;
harden(identPattern);
const AtAtPrefixPattern = /^@@(.*)$/;
harden(AtAtPrefixPattern);

/**
* @param {Encoding} encoding
Expand Down
14 changes: 8 additions & 6 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/// <reference types="ses"/>

import { Nat } from '@endo/nat';
import { assertPassable } from './passStyleOf.js';
import {
assertPassable,
getInterfaceOf,
getErrorConstructor,
hasOwnPropertyOf,
} from '@endo/pass-style';

import { getInterfaceOf } from './helpers/remotable.js';
import { getErrorConstructor } from './helpers/error.js';
import {
QCLASS,
makeEncodeToCapData,
Expand All @@ -14,7 +17,6 @@ import {
makeDecodeFromSmallcaps,
makeEncodeToSmallcaps,
} from './encodeToSmallcaps.js';
import { hasOwnPropertyOf } from './helpers/passStyle-helpers.js';

/** @typedef {import('./types.js').MakeMarshalOptions} MakeMarshalOptions */
/** @template Slot @typedef {import('./types.js').ConvertSlotToVal<Slot>} ConvertSlotToVal */
Expand Down Expand Up @@ -99,7 +101,7 @@ export const makeMarshal = (
* Even if an Error is not actually passable, we'd rather send
* it anyway because the diagnostic info carried by the error
* is more valuable than diagnosing why the error isn't
* passable. See comments in ErrorHelper.
* passable. See comments in isErrorLike.
*
* @param {Error} err
* @param {(p: Passable) => unknown} encodeRecur
Expand Down Expand Up @@ -156,7 +158,7 @@ export const makeMarshal = (
* Even if an Error is not actually passable, we'd rather send
* it anyway because the diagnostic info carried by the error
* is more valuable than diagnosing why the error isn't
* passable. See comments in ErrorHelper.
* passable. See comments in isErrorLike.
*
* @param {Error} err
* @param {(p: Passable) => Encoding} encodeRecur
Expand Down
4 changes: 1 addition & 3 deletions packages/marshal/src/rankOrder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { getTag } from './helpers/passStyle-helpers.js';
import { passStyleOf } from './passStyleOf.js';
import { nameForPassableSymbol } from './helpers/symbol.js';
import { getTag, passStyleOf, nameForPassableSymbol } from '@endo/pass-style';
import {
passStylePrefixes,
recordNames,
Expand Down
Loading

0 comments on commit 9f05227

Please sign in to comment.