Skip to content

Commit 52104f6

Browse files
authored
refactor(patterns): Deprecate sloppy interface guard option (#2955)
Refs: #1831, Agoric/agoric-sdk#11931 ## Description We wish to visibly deprecate the `sloppy` option of `@endo/patterns` interface guards. To avoid an explosion of `@typedef` blocks, we migrate the `@endo/patterns` types to TypeScript and then add the minimally required `@deprecated` tags. ### Security Considerations N/A ### Scaling Considerations N/A ### Documentation Considerations N/A ### Testing Considerations This modifies the implementation of the `@endo/patterns` types, but should not modify them. Since the number of lines changed is larged, we should attempt to convince ourselves that the types are in fact the same. ### Compatibility Considerations N/A ### Upgrade Considerations Deprecates but does not remove the `sloppy` option. `NEWS.md` is updated.
2 parents 79f6428 + 3f20f4f commit 52104f6

File tree

14 files changed

+875
-722
lines changed

14 files changed

+875
-722
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ api-docs
101101
!packages/far/src/exports.d.ts
102102
!packages/lp32/types.d.ts
103103
!packages/pass-style/src/types.d.ts
104+
!packages/patterns/types-index.d.ts
104105
!packages/ses/src/reporting-types.d.ts
105106
!packages/ses/types.d.ts
106107
!packages/stream/types.d.ts

packages/patterns/NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
User-visible changes in `@endo/patterns`:
22

3+
# Next release
4+
5+
- The `sloppy` option for `@endo/patterns` interface guards is deprecated. Use `defaultGuards` instead.
6+
37
# 1.7.0 (2025-07-11)
48

59
- `@endo/marshal` introduces an environment variable config option `ENDO_RANK_STRINGS` to change the rank ordering of strings from the current (incorrect) ordering by UTF-16 code unit used by JavaScript's `<` and `.sort()` operations to (correct and OCapN-conformant) ordering by Unicode code point. It currently defaults to "utf16-code-unit-order", matching the previously-unconditional behavior.

packages/patterns/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export {
7676
} from './src/patterns/getGuardPayloads.js';
7777

7878
// eslint-disable-next-line import/export
79-
export * from './src/types.js';
79+
export * from './types-index.js';
8080

8181
// /////////////////////////// Deprecated //////////////////////////////////////
8282

packages/patterns/src/patterns/types.js

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)