@agoric/swingset-liveslots 0.10.3-dev-9f8a76e.0 → 0.10.3-dev-e68f280.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/swingset-liveslots",
3
- "version": "0.10.3-dev-9f8a76e.0+9f8a76e",
3
+ "version": "0.10.3-dev-e68f280.0+e68f280",
4
4
  "description": "SwingSet ocap support layer",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -17,10 +17,9 @@
17
17
  "lint:eslint": "eslint ."
18
18
  },
19
19
  "dependencies": {
20
- "@agoric/assert": "0.6.1-dev-9f8a76e.0+9f8a76e",
21
- "@agoric/internal": "0.3.3-dev-9f8a76e.0+9f8a76e",
22
- "@agoric/store": "0.9.3-dev-9f8a76e.0+9f8a76e",
23
- "@agoric/vat-data": "0.5.3-dev-9f8a76e.0+9f8a76e",
20
+ "@agoric/assert": "0.6.1-dev-e68f280.0+e68f280",
21
+ "@agoric/internal": "0.3.3-dev-e68f280.0+e68f280",
22
+ "@agoric/store": "0.9.3-dev-e68f280.0+e68f280",
24
23
  "@endo/eventual-send": "^0.17.3",
25
24
  "@endo/exo": "^0.2.3",
26
25
  "@endo/far": "^0.2.19",
@@ -61,5 +60,5 @@
61
60
  "publishConfig": {
62
61
  "access": "public"
63
62
  },
64
- "gitHead": "9f8a76ee66bd74f028158b689c4b437921613f63"
63
+ "gitHead": "e68f2805dde79871d1421e50c60f08e854e1851d"
65
64
  }
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/export -- types files have no named runtime exports */
1
2
  export { makeLiveSlots, makeMarshaller } from './liveslots.js';
2
3
 
3
4
  export {
@@ -8,5 +9,5 @@ export {
8
9
  insistVatSyscallResult,
9
10
  } from './message.js';
10
11
 
11
- // eslint-disable-next-line import/export -- no named exports
12
12
  export * from './types.js';
13
+ export * from './vatDataTypes.js';
@@ -0,0 +1,203 @@
1
+ /**
2
+ * @file Types for vat-data
3
+ *
4
+ * Facet is a single object with methods.
5
+ * Behavior is a description when defining a kind of what facets it will have.
6
+ * For the non-multi defineKind, there is just one facet so it doesn't have a key.
7
+ */
8
+ import type {
9
+ InterfaceGuard,
10
+ MapStore,
11
+ Pattern,
12
+ SetStore,
13
+ StoreOptions,
14
+ WeakMapStore,
15
+ WeakSetStore,
16
+ } from '@agoric/store';
17
+
18
+ export type { MapStore, Pattern };
19
+
20
+ export type Baggage = MapStore<string, unknown>;
21
+
22
+ type Tail<T extends any[]> = T extends [head: any, ...rest: infer Rest]
23
+ ? Rest
24
+ : [];
25
+
26
+ type MinusContext<
27
+ F extends (context, ...rest: any[]) => any,
28
+ P extends any[] = Parameters<F>, // P: are the parameters of F
29
+ R = ReturnType<F>, // R: the return type of F
30
+ > = (...args: Tail<P>) => R;
31
+
32
+ export type KindFacet<O> = { [K in keyof O]: MinusContext<O[K]> };
33
+
34
+ export type KindFacets<B> = {
35
+ [FacetKey in keyof B]: KindFacet<B[FacetKey]>;
36
+ };
37
+
38
+ export type KindContext<S, F> = { state: S; self: KindFacet<F> };
39
+ export type MultiKindContext<S, B> = { state: S; facets: KindFacets<B> };
40
+
41
+ export type PlusContext<C, M> = (c: C, ...args: Parameters<M>) => ReturnType<M>;
42
+ export type FunctionsPlusContext<C, O> = {
43
+ [K in keyof O]: PlusContext<C, O[K]>;
44
+ };
45
+
46
+ declare class DurableKindHandleClass {
47
+ private descriptionTag: string;
48
+ }
49
+ export type DurableKindHandle = DurableKindHandleClass;
50
+
51
+ /**
52
+ * Grab bag of options that can be provided to `defineDurableKind` and its
53
+ * siblings. Not all options are meaningful in all contexts. See the
54
+ * doc-comments on each option.
55
+ */
56
+ export type DefineKindOptions<C> = {
57
+ /**
58
+ * If provided, the `finish` function will be called after the instance is
59
+ * made and internally registered, but before it is returned. The finish
60
+ * function is to do any post-intantiation initialization that should be
61
+ * done before exposing the object to its clients.
62
+ */
63
+ finish?: (context: C) => void;
64
+
65
+ /**
66
+ * Meaningful to `makeScalarBigMapStore` and its siblings. These maker
67
+ * fuctions will make either virtual or durable stores, depending on
68
+ * this flag. Defaults to off, making virtual but not durable collections.
69
+ *
70
+ * Generally, durable collections are provided with `provideDurableMapStore`
71
+ * and its sibling, which use this flag internally. If you do not make
72
+ * durable collections by other means, you can consider this as
73
+ * intended for internal use only.
74
+ */
75
+ durable?: boolean;
76
+
77
+ /**
78
+ * If provided, it describes the shape of all state records of instances
79
+ * of this kind.
80
+ */
81
+ stateShape?: { [name: string]: Pattern };
82
+
83
+ /**
84
+ * Intended for internal use only.
85
+ * Should the raw methods receive their `context` argument as their first
86
+ * argument or as their `this` binding? For `defineDurableKind` and its
87
+ * siblings (including `prepareSingleton`), this defaults to off, meaning that
88
+ * their behavior methods receive `context` as their first argument.
89
+ * `prepareExoClass` and its siblings (including `prepareExo`) use
90
+ * this flag internally to indicate that their methods receive `context`
91
+ * as their `this` binding.
92
+ */
93
+ thisfulMethods?: boolean;
94
+
95
+ /**
96
+ * Intended for internal use only.
97
+ * If an `interfaceGuard` is provided, then the raw methods passed alongside
98
+ * it are wrapped by a function that first checks that this method's guard
99
+ * pattern is satisfied before calling the raw method.
100
+ *
101
+ * In `defineDurableKind` and its siblings, this defaults to off.
102
+ * `prepareExoClass` use this internally to protect their raw class methods
103
+ * using the provided interface.
104
+ */
105
+ interfaceGuard?: InterfaceGuard<unknown>;
106
+ };
107
+
108
+ export type VatData = {
109
+ // virtual kinds
110
+ /** @deprecated Use defineVirtualExoClass instead */
111
+ defineKind: <P, S, F>(
112
+ tag: string,
113
+ init: (...args: P) => S,
114
+ facet: F,
115
+ options?: DefineKindOptions<KindContext<S, F>>,
116
+ ) => (...args: P) => KindFacet<F>;
117
+
118
+ /** @deprecated Use defineVirtualExoClassKit instead */
119
+ defineKindMulti: <P, S, B>(
120
+ tag: string,
121
+ init: (...args: P) => S,
122
+ behavior: B,
123
+ options?: DefineKindOptions<MultiKindContext<S, B>>,
124
+ ) => (...args: P) => KindFacets<B>;
125
+
126
+ // durable kinds
127
+ makeKindHandle: (descriptionTag: string) => DurableKindHandle;
128
+
129
+ /** @deprecated Use defineDurableExoClass instead */
130
+ defineDurableKind: <P, S, F>(
131
+ kindHandle: DurableKindHandle,
132
+ init: (...args: P) => S,
133
+ facet: F,
134
+ options?: DefineKindOptions<KindContext<S, F>>,
135
+ ) => (...args: P) => KindFacet<F>;
136
+
137
+ /** @deprecated Use defineDurableExoClassKit instead */
138
+ defineDurableKindMulti: <P, S, B>(
139
+ kindHandle: DurableKindHandle,
140
+ init: (...args: P) => S,
141
+ behavior: B,
142
+ options?: DefineKindOptions<MultiKindContext<S, B>>,
143
+ ) => (...args: P) => KindFacets<B>;
144
+
145
+ providePromiseWatcher: unknown;
146
+ watchPromise: unknown;
147
+
148
+ makeScalarBigMapStore: <K, V>(
149
+ label: string,
150
+ options?: StoreOptions,
151
+ ) => MapStore<K, V>;
152
+ makeScalarBigWeakMapStore: <K, V>(
153
+ label: string,
154
+ options?: StoreOptions,
155
+ ) => WeakMapStore<K, V>;
156
+
157
+ makeScalarBigSetStore: <K>(
158
+ label: string,
159
+ options?: StoreOptions,
160
+ ) => SetStore<K>;
161
+ makeScalarBigWeakSetStore: <K>(
162
+ label: string,
163
+ options?: StoreOptions,
164
+ ) => WeakSetStore<K>;
165
+ canBeDurable: (specimen: unknown) => boolean;
166
+ };
167
+
168
+ // The JSDoc is repeated here and at the function definition so it appears
169
+ // in IDEs where it's used, regardless of type resolution.
170
+ export interface PickFacet {
171
+ /**
172
+ * When making a multi-facet kind, it's common to pick one facet to
173
+ * expose. E.g.,
174
+ *
175
+ * const makeFoo = (a, b, c, d) => makeFooBase(a, b, c, d).self;
176
+ *
177
+ * This helper reduces the duplication:
178
+ *
179
+ * const makeFoo = pickFacet(makeFooBase, 'self');
180
+ */
181
+ <M extends (...args: any[]) => any, F extends keyof ReturnType<M>>(
182
+ maker: M,
183
+ facetName: F,
184
+ ): (...args: Parameters<M>) => ReturnType<M>[F];
185
+ }
186
+
187
+ /** @deprecated Use prepareExoClass instead */
188
+ export type PrepareKind = <P, S, F>(
189
+ baggage: Baggage,
190
+ tag: string,
191
+ init: (...args: P) => S,
192
+ facet: F,
193
+ options?: DefineKindOptions<KindContext<S, F>>,
194
+ ) => (...args: P) => KindFacet<F>;
195
+
196
+ /** @deprecated Use prepareExoClassKit instead */
197
+ export type PrepareKindMulti = <P, S, B>(
198
+ baggage: Baggage,
199
+ tag: string,
200
+ init: (...args: P) => S,
201
+ behavior: B,
202
+ options?: DefineKindOptions<MultiKindContext<S, B>>,
203
+ ) => (...args: P) => KindFacets<B>;
@@ -0,0 +1,2 @@
1
+ // Empty JS file to correspond with vatDataTypes.d.ts
2
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Prepare Agoric SwingSet vat global environment for testing.
3
+ *
4
+ * Installs Hardened JS (and does lockdown), plus adds mocks for virtual objects
5
+ * and stores.
6
+ */
7
+
8
+ import '@endo/init/pre.js';
9
+
10
+ import '@agoric/internal/src/install-ses-debug.js';
11
+ import { reincarnate } from './setup-vat-data.js';
12
+
13
+ // Install the VatData globals.
14
+ reincarnate();
@@ -0,0 +1,54 @@
1
+ // @ts-check
2
+ /* global globalThis */
3
+ // This file produces the globalThis.VatData property outside of a running
4
+ // SwingSet so that it can be used by '@agoric/vat-data' (which only *consumes*
5
+ // `globalThis.VatData`) in code under test.
6
+ import { makeFakeVirtualStuff } from './fakeVirtualSupport.js';
7
+
8
+ const { WeakMap, WeakSet } = globalThis;
9
+
10
+ /** @type {ReturnType<makeFakeVirtualStuff>} */
11
+ let fakeVomKit;
12
+
13
+ globalThis.VatData = harden({
14
+ defineKind: (...args) => fakeVomKit.vom.defineKind(...args),
15
+ defineKindMulti: (...args) => fakeVomKit.vom.defineKindMulti(...args),
16
+ defineDurableKind: (...args) => fakeVomKit.vom.defineDurableKind(...args),
17
+ defineDurableKindMulti: (...args) =>
18
+ fakeVomKit.vom.defineDurableKindMulti(...args),
19
+ makeKindHandle: (...args) => fakeVomKit.vom.makeKindHandle(...args),
20
+ canBeDurable: (...args) => fakeVomKit.vom.canBeDurable(...args),
21
+ providePromiseWatcher: (...args) =>
22
+ fakeVomKit.wpm.providePromiseWatcher(...args),
23
+ watchPromise: (...args) => fakeVomKit.wpm.watchPromise(...args),
24
+ makeScalarBigMapStore: (...args) =>
25
+ fakeVomKit.cm.makeScalarBigMapStore(...args),
26
+ makeScalarBigWeakMapStore: (...args) =>
27
+ fakeVomKit.cm.makeScalarBigWeakMapStore(...args),
28
+ makeScalarBigSetStore: (...args) =>
29
+ fakeVomKit.cm.makeScalarBigSetStore(...args),
30
+ makeScalarBigWeakSetStore: (...args) =>
31
+ fakeVomKit.cm.makeScalarBigWeakSetStore(...args),
32
+ });
33
+
34
+ export const reincarnate = (options = {}) => {
35
+ const { fakeStore = new Map(), fakeVomKit: fvk } = options;
36
+
37
+ if (options.fakeVomKit) {
38
+ fvk.vom.flushStateCache();
39
+ fvk.cm.flushSchemaCache();
40
+ fvk.vrm.flushIDCounters();
41
+ }
42
+
43
+ fakeVomKit = makeFakeVirtualStuff({
44
+ ...options,
45
+ fakeStore,
46
+ WeakMap,
47
+ WeakSet,
48
+ });
49
+
50
+ globalThis.WeakMap = fakeVomKit.vom.VirtualObjectAwareWeakMap;
51
+ globalThis.WeakSet = fakeVomKit.vom.VirtualObjectAwareWeakSet;
52
+
53
+ return { ...options, fakeStore, fakeVomKit };
54
+ };