|
| 1 | +/// <reference types="ses"/> |
| 2 | + |
| 3 | +import type { Rejector } from '@endo/errors/rejector.js'; |
| 4 | +import type { Passable } from '@endo/pass-style'; |
| 5 | +import type { |
| 6 | + MatcherNamespace, |
| 7 | + Pattern, |
| 8 | + GetRankCover, |
| 9 | + Kind, |
| 10 | +} from '../types.js'; |
| 11 | + |
| 12 | +/** |
| 13 | + * This factors out only the parts specific to each kind of Matcher. It is |
| 14 | + * encapsulated, and its methods can make the stated unchecked assumptions |
| 15 | + * enforced by the common calling logic. |
| 16 | + */ |
| 17 | +export type MatchHelper = { |
| 18 | + /** |
| 19 | + * Reports whether `allegedPayload` is valid as the payload of a CopyTagged |
| 20 | + * whose tag corresponds with this MatchHelper's Matchers. |
| 21 | + */ |
| 22 | + confirmIsWellFormed: (allegedPayload: Passable, reject: Rejector) => boolean; |
| 23 | + |
| 24 | + /** |
| 25 | + * Assuming validity of `matcherPayload` as the payload of a Matcher corresponding |
| 26 | + * with this MatchHelper, reports whether `specimen` is matched by that Matcher. |
| 27 | + */ |
| 28 | + confirmMatches: ( |
| 29 | + specimen: Passable, |
| 30 | + matcherPayload: Passable, |
| 31 | + reject: Rejector, |
| 32 | + ) => boolean; |
| 33 | + |
| 34 | + /** |
| 35 | + * Assumes this is the payload of a CopyTagged with the corresponding |
| 36 | + * matchTag. Return a RankCover to bound from below and above, |
| 37 | + * in rank order, all possible Passables that would match this Matcher. |
| 38 | + * The left element must be before or the same rank as any possible |
| 39 | + * matching specimen. The right element must be after or the same |
| 40 | + * rank as any possible matching specimen. |
| 41 | + */ |
| 42 | + getRankCover: GetRankCover; |
| 43 | +}; |
| 44 | + |
| 45 | +export type PatternKit = { |
| 46 | + confirmMatches: ( |
| 47 | + specimen: any, |
| 48 | + patt: Passable, |
| 49 | + reject: Rejector, |
| 50 | + label?: string | number, |
| 51 | + ) => boolean; |
| 52 | + matches: (specimen: any, patt: Pattern) => boolean; |
| 53 | + mustMatch: (specimen: any, patt: Pattern, label?: string | number) => void; |
| 54 | + assertPattern: (patt: Pattern) => void; |
| 55 | + isPattern: (patt: any) => boolean; |
| 56 | + getRankCover: GetRankCover; |
| 57 | + M: MatcherNamespace; |
| 58 | + kindOf: (specimen: Passable, reject: Rejector) => Kind | undefined; |
| 59 | +}; |
0 commit comments