@agoric/internal 0.3.3-dev-43dd3ec.0 → 0.3.3-dev-6909994.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 +3 -3
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/types-index.d.ts +1 -0
- package/src/types.d.ts +24 -58
- package/src/types.d.ts.map +1 -0
- package/src/types.ts +108 -0
- /package/src/{types.js → types-index.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/internal",
|
|
3
|
-
"version": "0.3.3-dev-
|
|
3
|
+
"version": "0.3.3-dev-6909994.0+6909994",
|
|
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-
|
|
23
|
+
"@agoric/base-zone": "0.1.1-dev-6909994.0+6909994",
|
|
24
24
|
"@endo/common": "^1.2.5",
|
|
25
25
|
"@endo/errors": "^1.2.5",
|
|
26
26
|
"@endo/far": "^1.1.5",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"typeCoverage": {
|
|
60
60
|
"atLeast": 93.42
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "6909994fc7df88c73d6a476f4d10f56aea85bea5"
|
|
63
63
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from "./utils.js";
|
|
|
5
5
|
export * from "./method-tools.js";
|
|
6
6
|
export * from "./typeCheck.js";
|
|
7
7
|
export * from "./typeGuards.js";
|
|
8
|
-
export * from "./types.js";
|
|
8
|
+
export * from "./types-index.js";
|
|
9
9
|
export { objectMap } from "@endo/common/object-map.js";
|
|
10
10
|
export { objectMetaMap } from "@endo/common/object-meta-map.js";
|
|
11
11
|
export { fromUniqueEntries } from "@endo/common/from-unique-entries.js";
|
package/src/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export * from './typeCheck.js';
|
|
|
11
11
|
export * from './typeGuards.js';
|
|
12
12
|
|
|
13
13
|
// eslint-disable-next-line import/export -- just types
|
|
14
|
-
export * from './types.js';
|
|
14
|
+
export * from './types-index.js';
|
|
15
15
|
|
|
16
16
|
export { objectMap } from '@endo/common/object-map.js';
|
|
17
17
|
export { objectMetaMap } from '@endo/common/object-meta-map.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types.js';
|
package/src/types.d.ts
CHANGED
|
@@ -1,39 +1,27 @@
|
|
|
1
|
-
/* eslint-disable max-classes-per-file */
|
|
2
1
|
import type { ERef, RemotableBrand } from '@endo/eventual-send';
|
|
3
2
|
import type { Primitive } from '@endo/pass-style';
|
|
3
|
+
import type { Pattern } from '@endo/patterns';
|
|
4
4
|
import type { Callable } from './utils.js';
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* A map corresponding with a total function such that `get(key)` is assumed to
|
|
8
7
|
* always succeed.
|
|
9
8
|
*/
|
|
10
9
|
export type TotalMap<K, V> = Omit<Map<K, V>, 'get'> & {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/** Returns the element associated with the specified key in the TotalMap. */
|
|
11
|
+
get: (key: K) => V;
|
|
13
12
|
};
|
|
14
|
-
export type TotalMapFrom<M extends Map>
|
|
15
|
-
M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
|
|
16
|
-
|
|
13
|
+
export type TotalMapFrom<M extends Map<any, any>> = M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
|
|
17
14
|
export declare class Callback<I extends (...args: any[]) => any> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
public bound: unknown[];
|
|
25
|
-
|
|
26
|
-
public isSync: boolean;
|
|
15
|
+
private iface;
|
|
16
|
+
target: any;
|
|
17
|
+
methodName?: PropertyKey;
|
|
18
|
+
bound: unknown[];
|
|
19
|
+
isSync: boolean;
|
|
27
20
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
> extends Callback<I> {
|
|
32
|
-
private syncIface: I;
|
|
33
|
-
|
|
34
|
-
public isSync: true;
|
|
21
|
+
export declare class SyncCallback<I extends (...args: unknown[]) => any> extends Callback<I> {
|
|
22
|
+
private syncIface;
|
|
23
|
+
isSync: true;
|
|
35
24
|
}
|
|
36
|
-
|
|
37
25
|
/**
|
|
38
26
|
Returns a boolean for whether the given type is primitive value or primitive type.
|
|
39
27
|
|
|
@@ -50,48 +38,28 @@ IsPrimitive<Object>
|
|
|
50
38
|
```
|
|
51
39
|
*/
|
|
52
40
|
export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
|
|
53
|
-
|
|
54
41
|
/** Recursively extract the non-callable properties of T */
|
|
55
|
-
export type DataOnly<T> =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
: T extends Callable
|
|
59
|
-
? never
|
|
60
|
-
: { [P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]> };
|
|
61
|
-
|
|
42
|
+
export type DataOnly<T> = IsPrimitive<T> extends true ? T : T extends Callable ? never : {
|
|
43
|
+
[P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]>;
|
|
44
|
+
};
|
|
62
45
|
/**
|
|
63
46
|
* A type that doesn't assume its parameter is local, but is satisfied with both
|
|
64
47
|
* local and remote references. It accepts both near and marshalled references
|
|
65
48
|
* that were returned from `Remotable` or `Far`.
|
|
66
49
|
*/
|
|
67
|
-
export type Remote<Primary, Local = DataOnly<Primary>> =
|
|
68
|
-
| Primary
|
|
69
|
-
| RemotableBrand<Local, Primary>;
|
|
70
|
-
|
|
71
|
-
// TODO: Add type tests for FarRef and Remote.
|
|
50
|
+
export type Remote<Primary, Local = DataOnly<Primary>> = Primary | RemotableBrand<Local, Primary>;
|
|
72
51
|
/**
|
|
73
52
|
* Potentially remote promises or settled references.
|
|
74
53
|
*/
|
|
75
|
-
export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<
|
|
76
|
-
Remote<Primary, Local>
|
|
77
|
-
>;
|
|
78
|
-
|
|
79
|
-
/*
|
|
80
|
-
* Stop-gap until https://github.com/Agoric/agoric-sdk/issues/6160
|
|
81
|
-
* explictly specify the type that the Pattern will verify through a match.
|
|
82
|
-
*
|
|
83
|
-
* TODO move all this pattern typing stuff to @endo/patterns
|
|
84
|
-
*/
|
|
54
|
+
export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<Remote<Primary, Local>>;
|
|
85
55
|
declare const validatedType: unique symbol;
|
|
86
56
|
/**
|
|
87
57
|
* Tag a pattern with the static type it represents.
|
|
88
58
|
*/
|
|
89
|
-
export type TypedPattern<T> = Pattern & {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// TODO make Endo's mustMatch do this
|
|
59
|
+
export type TypedPattern<T> = Pattern & {
|
|
60
|
+
[validatedType]?: T;
|
|
61
|
+
};
|
|
62
|
+
export declare type PatternType<TM extends TypedPattern<any>> = TM extends TypedPattern<infer T> ? T : never;
|
|
95
63
|
/**
|
|
96
64
|
* Returning normally indicates success. Match failure is indicated by
|
|
97
65
|
* throwing.
|
|
@@ -100,8 +68,6 @@ export declare type PatternType<TM extends TypedPattern<any>> =
|
|
|
100
68
|
*
|
|
101
69
|
* @see {import('@endo/patterns').mustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
|
|
102
70
|
*/
|
|
103
|
-
export declare type MustMatch = <P extends Pattern>(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
label?: string | number,
|
|
107
|
-
) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
|
|
71
|
+
export declare type MustMatch = <P extends Pattern>(specimen: unknown, pattern: P, label?: string | number) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
|
|
72
|
+
export {};
|
|
73
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG;IACpD,6EAA6E;IAC7E,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,IAC9C,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;AAE3D,MAAM,CAAC,OAAO,OAAO,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG;IAC7D,OAAO,CAAC,KAAK,CAAI;IAEV,MAAM,EAAE,GAAG,CAAC;IAEZ,UAAU,CAAC,EAAE,WAAW,CAAC;IAEzB,KAAK,EAAE,OAAO,EAAE,CAAC;IAEjB,MAAM,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,CAAC,OAAO,OAAO,YAAY,CAC/B,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,GAAG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,MAAM,CAAC,OAAO,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS,OAAO,EAChD,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,CAAC,EACV,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KACpB,OAAO,CAAC,QAAQ,IAAI,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC"}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import type { ERef, RemotableBrand } from '@endo/eventual-send';
|
|
3
|
+
import type { Primitive } from '@endo/pass-style';
|
|
4
|
+
import type { Pattern } from '@endo/patterns';
|
|
5
|
+
import type { Callable } from './utils.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A map corresponding with a total function such that `get(key)` is assumed to
|
|
9
|
+
* always succeed.
|
|
10
|
+
*/
|
|
11
|
+
export type TotalMap<K, V> = Omit<Map<K, V>, 'get'> & {
|
|
12
|
+
/** Returns the element associated with the specified key in the TotalMap. */
|
|
13
|
+
get: (key: K) => V;
|
|
14
|
+
};
|
|
15
|
+
export type TotalMapFrom<M extends Map<any, any>> =
|
|
16
|
+
M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
|
|
17
|
+
|
|
18
|
+
export declare class Callback<I extends (...args: any[]) => any> {
|
|
19
|
+
private iface: I;
|
|
20
|
+
|
|
21
|
+
public target: any;
|
|
22
|
+
|
|
23
|
+
public methodName?: PropertyKey;
|
|
24
|
+
|
|
25
|
+
public bound: unknown[];
|
|
26
|
+
|
|
27
|
+
public isSync: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export declare class SyncCallback<
|
|
31
|
+
I extends (...args: unknown[]) => any,
|
|
32
|
+
> extends Callback<I> {
|
|
33
|
+
private syncIface: I;
|
|
34
|
+
|
|
35
|
+
public isSync: true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
Returns a boolean for whether the given type is primitive value or primitive type.
|
|
40
|
+
|
|
41
|
+
@example
|
|
42
|
+
```
|
|
43
|
+
IsPrimitive<'string'>
|
|
44
|
+
//=> true
|
|
45
|
+
|
|
46
|
+
IsPrimitive<string>
|
|
47
|
+
//=> true
|
|
48
|
+
|
|
49
|
+
IsPrimitive<Object>
|
|
50
|
+
//=> false
|
|
51
|
+
```
|
|
52
|
+
*/
|
|
53
|
+
export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
|
|
54
|
+
|
|
55
|
+
/** Recursively extract the non-callable properties of T */
|
|
56
|
+
export type DataOnly<T> =
|
|
57
|
+
IsPrimitive<T> extends true
|
|
58
|
+
? T
|
|
59
|
+
: T extends Callable
|
|
60
|
+
? never
|
|
61
|
+
: { [P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]> };
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A type that doesn't assume its parameter is local, but is satisfied with both
|
|
65
|
+
* local and remote references. It accepts both near and marshalled references
|
|
66
|
+
* that were returned from `Remotable` or `Far`.
|
|
67
|
+
*/
|
|
68
|
+
export type Remote<Primary, Local = DataOnly<Primary>> =
|
|
69
|
+
| Primary
|
|
70
|
+
| RemotableBrand<Local, Primary>;
|
|
71
|
+
|
|
72
|
+
// TODO: Add type tests for FarRef and Remote.
|
|
73
|
+
/**
|
|
74
|
+
* Potentially remote promises or settled references.
|
|
75
|
+
*/
|
|
76
|
+
export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<
|
|
77
|
+
Remote<Primary, Local>
|
|
78
|
+
>;
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
* Stop-gap until https://github.com/Agoric/agoric-sdk/issues/6160
|
|
82
|
+
* explictly specify the type that the Pattern will verify through a match.
|
|
83
|
+
*
|
|
84
|
+
* TODO move all this pattern typing stuff to @endo/patterns
|
|
85
|
+
*/
|
|
86
|
+
declare const validatedType: unique symbol;
|
|
87
|
+
/**
|
|
88
|
+
* Tag a pattern with the static type it represents.
|
|
89
|
+
*/
|
|
90
|
+
export type TypedPattern<T> = Pattern & { [validatedType]?: T };
|
|
91
|
+
|
|
92
|
+
export declare type PatternType<TM extends TypedPattern<any>> =
|
|
93
|
+
TM extends TypedPattern<infer T> ? T : never;
|
|
94
|
+
|
|
95
|
+
// TODO make Endo's mustMatch do this
|
|
96
|
+
/**
|
|
97
|
+
* Returning normally indicates success. Match failure is indicated by
|
|
98
|
+
* throwing.
|
|
99
|
+
*
|
|
100
|
+
* Note: remotables can only be matched as "remotable", not the specific kind.
|
|
101
|
+
*
|
|
102
|
+
* @see {import('@endo/patterns').mustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
|
|
103
|
+
*/
|
|
104
|
+
export declare type MustMatch = <P extends Pattern>(
|
|
105
|
+
specimen: unknown,
|
|
106
|
+
pattern: P,
|
|
107
|
+
label?: string | number,
|
|
108
|
+
) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
|
|
File without changes
|