From 3045779c554197f6d271c65f8149d1a4f8265bb3 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Sat, 14 Oct 2023 19:30:40 -0700 Subject: [PATCH] feat(patterns): export kindOf --- packages/patterns/index.js | 1 + packages/patterns/src/patterns/internal-types.js | 13 +++++++++++++ packages/patterns/src/patterns/patternMatchers.js | 13 ++----------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/patterns/index.js b/packages/patterns/index.js index 7b3d6ff1ab..e06fcf2520 100644 --- a/packages/patterns/index.js +++ b/packages/patterns/index.js @@ -66,6 +66,7 @@ export { getInterfaceMethodKeys, assertInterfaceGuard, getInterfaceGuardPayload, + kindOf, } from './src/patterns/patternMatchers.js'; // ////////////////// Temporary, until these find their proper home //////////// diff --git a/packages/patterns/src/patterns/internal-types.js b/packages/patterns/src/patterns/internal-types.js index 072cac4fe7..f7da7a5e50 100644 --- a/packages/patterns/src/patterns/internal-types.js +++ b/packages/patterns/src/patterns/internal-types.js @@ -42,6 +42,18 @@ /** @typedef {import('../types').AllLimits} AllLimits */ /** @typedef {import('../types').GetRankCover} GetRankCover */ +/** + * @typedef {Exclude | + * 'copySet' | 'copyBag' | 'copyMap' | + * `match:${any}` | `guard:${any}` + * } Kind + * It is either a PassStyle other than 'tagged', or, if the underlying + * PassStyle is 'tagged', then the `getTag` value for tags that are + * recognized at the @endo/patterns level of abstraction. For each of those + * tags, a tagged record only has that kind if it satisfies the invariants + * that the @endo/patterns level associates with that kind. + */ + /** * @typedef {object} MatchHelper * This factors out only the parts specific to each kind of Matcher. It is @@ -83,4 +95,5 @@ * @property {(patt: Passable) => boolean} isPattern * @property {GetRankCover} getRankCover * @property {MatcherNamespace} M + * @property {(specimen: Passable, check?: Checker) => Kind | undefined} kindOf */ diff --git a/packages/patterns/src/patterns/patternMatchers.js b/packages/patterns/src/patterns/patternMatchers.js index 2a22fa6744..e1df21f29c 100644 --- a/packages/patterns/src/patterns/patternMatchers.js +++ b/packages/patterns/src/patterns/patternMatchers.js @@ -174,17 +174,6 @@ const makePatternKit = () => { // eslint-disable-next-line no-use-before-define GuardPayloadShapes[tag]; - /** - * @typedef {Exclude | - * 'copySet' | 'copyBag' | 'copyMap' | keyof HelpersByMatchTag - * } Kind - * It is either a PassStyle other than 'tagged', or, if the underlying - * PassStyle is 'tagged', then the `getTag` value for tags that are - * recognized at the store level of abstraction. For each of those - * tags, a tagged record only has that kind if it satisfies the invariants - * that the store level associates with that kind. - */ - /** @type {Map} */ const singletonKinds = new Map([ ['null', null], @@ -1716,6 +1705,7 @@ const makePatternKit = () => { isPattern, getRankCover, M, + kindOf, }); }; @@ -1733,6 +1723,7 @@ export const { isPattern, getRankCover, M, + kindOf, } = makePatternKit(); MM = M;