@agoric/internal 0.3.3-dev-24528f1.0 → 0.3.3-dev-3f2cb5c.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/internal",
3
- "version": "0.3.3-dev-24528f1.0+24528f1",
3
+ "version": "0.3.3-dev-3f2cb5c.0+3f2cb5c",
4
4
  "description": "Externally unsupported utilities internal to agoric-sdk",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -20,7 +20,7 @@
20
20
  "lint:types": "tsc"
21
21
  },
22
22
  "dependencies": {
23
- "@agoric/base-zone": "0.1.1-dev-24528f1.0+24528f1",
23
+ "@agoric/base-zone": "0.1.1-dev-3f2cb5c.0+3f2cb5c",
24
24
  "@endo/common": "^1.2.2",
25
25
  "@endo/errors": "^1.2.2",
26
26
  "@endo/far": "^1.1.2",
@@ -34,6 +34,7 @@
34
34
  "jessie.js": "^0.3.4"
35
35
  },
36
36
  "devDependencies": {
37
+ "@endo/exo": "^1.5.0",
37
38
  "@endo/init": "^1.1.2",
38
39
  "ava": "^5.3.0",
39
40
  "tsd": "^0.31.1"
@@ -56,7 +57,7 @@
56
57
  "access": "public"
57
58
  },
58
59
  "typeCoverage": {
59
- "atLeast": 93.89
60
+ "atLeast": 93.78
60
61
  },
61
- "gitHead": "24528f1e377f41e13e9fe47a6f04c0f4b0c33452"
62
+ "gitHead": "3f2cb5ca05d2514ceef73764618536263ef7a835"
62
63
  }
package/src/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./debug.js";
3
3
  export * from "./errors.js";
4
4
  export * from "./utils.js";
5
5
  export * from "./method-tools.js";
6
+ export * from "./typeCheck.js";
6
7
  export * from "./typeGuards.js";
7
8
  export * from "./types.js";
8
9
  export { objectMap } from "@endo/common/object-map.js";
package/src/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './debug.js';
7
7
  export * from './errors.js';
8
8
  export * from './utils.js';
9
9
  export * from './method-tools.js';
10
+ export * from './typeCheck.js';
10
11
  export * from './typeGuards.js';
11
12
 
12
13
  // eslint-disable-next-line import/export -- just types
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @import {MustMatch, PatternType, TypedPattern} from './types.js';
3
+ */
4
+ /** @type {MustMatch} */
5
+ export const mustMatch: MustMatch;
6
+ export function cast<M>(specimen: unknown, patt: TypedPattern<M>): M;
7
+ import type { MustMatch } from './types.js';
8
+ import type { TypedPattern } from './types.js';
9
+ //# sourceMappingURL=typeCheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeCheck.d.ts","sourceRoot":"","sources":["typeCheck.js"],"names":[],"mappings":"AAGA;;GAEG;AAEH,wBAAwB;AACxB,wBADW,SAAS,CACuB;AAQpC,qBALM,CAAC,YACH,OAAO,QACP,aAAa,CAAC,CAAC,GACb,CAAC,CAQb;+BAlBsD,YAAY;kCAAZ,YAAY"}
@@ -0,0 +1,23 @@
1
+ // @ts-check
2
+ import { mustMatch as typelessMustMatch } from '@endo/patterns';
3
+
4
+ /**
5
+ * @import {MustMatch, PatternType, TypedPattern} from './types.js';
6
+ */
7
+
8
+ /** @type {MustMatch} */
9
+ export const mustMatch = typelessMustMatch;
10
+
11
+ /**
12
+ * @template M
13
+ * @param {unknown} specimen
14
+ * @param {TypedPattern<M>} patt
15
+ * @returns {M}
16
+ */
17
+ export const cast = (specimen, patt) => {
18
+ // mustMatch throws if they don't, which means that `cast` also narrows the
19
+ // type but a function can't both narrow and return a type. That is by design:
20
+ // https://github.com/microsoft/TypeScript/issues/34636#issuecomment-545025916
21
+ mustMatch(specimen, patt);
22
+ return specimen;
23
+ };
package/src/types.d.ts CHANGED
@@ -64,3 +64,33 @@ export type Remote<Primary, Local = DataOnly<Primary>> =
64
64
  export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<
65
65
  Remote<Primary, Local>
66
66
  >;
67
+
68
+ /*
69
+ * Stop-gap until https://github.com/Agoric/agoric-sdk/issues/6160
70
+ * explictly specify the type that the Pattern will verify through a match.
71
+ *
72
+ * TODO move all this pattern typing stuff to @endo/patterns
73
+ */
74
+ declare const validatedType: unique symbol;
75
+ /**
76
+ * Tag a pattern with the static type it represents.
77
+ */
78
+ export type TypedPattern<T> = Pattern & { [validatedType]?: T };
79
+
80
+ export declare type PatternType<TM extends TypedPattern<any>> =
81
+ TM extends TypedPattern<infer T> ? T : never;
82
+
83
+ // TODO make Endo's mustMatch do this
84
+ /**
85
+ * Returning normally indicates success. Match failure is indicated by
86
+ * throwing.
87
+ *
88
+ * Note: remotables can only be matched as "remotable", not the specific kind.
89
+ *
90
+ * @see {import('@endo/patterns').mustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
91
+ */
92
+ export declare type MustMatch = <P extends Pattern>(
93
+ specimen: unknown,
94
+ pattern: P,
95
+ label?: string | number,
96
+ ) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;