Skip to content

Commit

Permalink
fix(utils): stop importing type from non-dependent package
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 9, 2024
1 parent b22b73d commit dfa033f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/pass-style/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export {};
* if not a deemed to be a Remotable
*/

// TODO import this type from @endo/utils
/**
* @callback Checker
* Internal to a useful pattern for writing checking logic
Expand Down
41 changes: 23 additions & 18 deletions packages/utils/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import { E } from '@endo/eventual-send';
import { isPromise } from '@endo/promise-kit';

/** @typedef {import('@endo/marshal').Checker} Checker */

const {
fromEntries,
entries,
Expand All @@ -15,17 +13,31 @@ const { ownKeys } = Reflect;

const { details: X, quote: q, Fail } = assert;

// TODO migrate to proper home
// From the `agoric-sdk` monorepo. Moved here temporarily because the pattern
// code is migrated from `@agoric/store` to `@endo/patterns`, and depends on
// the functionality in this file, which is otherwise available only
// within the `agoric-sdk` monorepo.

// TODO Complete migration of Checker type from @endo/pass-style to @endo/utils
// by having @endo/pass-style, and everyone else who needs it, import it from
// @endo/utils.
/**
* TODO as long as `@endo/pass-style` remains the proper home of the
* `Checker` type, it probably makes most sense to move `identChecker`
* into `@endo/pass-style` as well.
* @callback Checker
* Internal to a useful pattern for writing checking logic
* (a "checkFoo" function) that can be used to implement a predicate
* (an "isFoo" function) or a validator (an "assertFoo" function).
*
* * A predicate ideally only returns `true` or `false` and rarely throws.
* * A validator throws an informative diagnostic when the predicate
* would have returned `false`, and simply returns `undefined` normally
* when the predicate would have returned `true`.
* * The internal checking function that they share is parameterized by a
* `Checker` that determines how to proceed with a failure condition.
* Predicates pass in an identity function as checker. Validators
* pass in `assertChecker` which is a trivial wrapper around `assert`.
*
* See the various uses for good examples.
* @param {boolean} cond
* @param {import('ses').Details} [details]
* @returns {boolean}
*/

/**
* In the `assertFoo`/`isFoo`/`checkFoo` pattern, `checkFoo` has a `check`
* parameter of type `Checker`. `assertFoo` calls `checkFoo` passes
* `assertChecker` as the `check` argument. `isFoo` passes `identChecker`
Expand Down Expand Up @@ -235,13 +247,6 @@ export const applyLabelingError = (func, args, label = undefined) => {
throwLabeled(err, label);
}
if (isPromise(result)) {
// @ts-expect-error If result is a rejected promise, this will
// return a promise with a different rejection reason. But this
// confuses TypeScript because it types that case as `Promise<never>`
// which is cool for a promise that will never fulfll.
// But TypeScript doesn't understand that this will only happen
// when `result` was a rejected promise. In only this case `R`
// should already allow `Promise<never>` as a subtype.
return E.when(result, undefined, reason => throwLabeled(reason, label));
} else {
return result;
Expand Down

0 comments on commit dfa033f

Please sign in to comment.