@agoric/store 0.9.3-other-dev-8f8782b.0 → 0.9.3-other-dev-fbe72e7.0.fbe72e7

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/src/types.js CHANGED
@@ -1,264 +1,180 @@
1
- /// <reference types="ses"/>
1
+ /// <reference types="ses" />
2
2
 
3
- /** @typedef {import('@endo/marshal').Passable} Passable */
4
- /** @typedef {import('@endo/marshal').PassStyle} PassStyle */
5
- /** @typedef {import('@endo/marshal').CopyTagged} CopyTagged */
6
- /** @template T @typedef {import('@endo/marshal').CopyRecord<T>} CopyRecord */
7
- /** @template T @typedef {import('@endo/marshal').CopyArray<T>} CopyArray */
8
- /** @typedef {import('@endo/marshal').Checker} Checker */
9
- /** @typedef {import('@endo/marshal/src/rankOrder').RankCompare} RankCompare */
10
- /** @typedef {import('@endo/marshal/src/rankOrder').RankComparison} RankComparison */
11
-
12
- // /////////////////////////////////////////////////////////////////////////////
13
- // Placeholder redundant types, to be imported from `@endo/patterns` instead.
14
-
15
- /**
16
- * @typedef {Passable} Key
17
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
18
- */
19
-
20
- /**
21
- * @typedef {Passable} Pattern
22
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
23
- */
24
-
25
- /**
26
- * @template {Key} [K=Key]
27
- * @typedef {CopyTagged & {
28
- * [Symbol.toStringTag]: 'copySet',
29
- * payload: Array<K>,
30
- * }} CopySet
31
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
32
- */
33
-
34
- /**
35
- * @template {Key} [K=Key]
36
- * @typedef {CopyTagged & {
37
- * [Symbol.toStringTag]: 'copyBag',
38
- * payload: Array<[K, bigint]>,
39
- * }} CopyBag
40
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
41
- */
3
+ // Ensure this is a module.
4
+ export {};
42
5
 
43
6
  /**
44
- * @template {Key} [K=Key]
45
- * @template {Passable} [V=Passable]
46
- * @typedef {CopyTagged & {
47
- * [Symbol.toStringTag]: 'copyMap',
48
- * payload: { keys: Array<K>, values: Array<V> },
49
- * }} CopyMap
50
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
51
- */
52
-
53
- /**
54
- * @typedef {object} GuardMakers
55
- * @property {<M extends Record<any, any>>(interfaceName: string,
56
- * methodGuards: M,
57
- * options?: {sloppy?: boolean}
58
- * ) => InterfaceGuard} interface
59
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
60
- *
61
- * @property {(...argGuards: ArgGuard[]) => MethodGuardMaker} call Guard a synchronous call
7
+ * Note TODO https://github.com/endojs/endo/issues/1488
62
8
  *
63
- * @property {(...argGuards: ArgGuard[]) => MethodGuardMaker} callWhen Guard an async call
64
- *
65
- * @property {(argGuard: ArgGuard) => ArgGuard} await Guard an await
66
- */
67
-
68
- /**
69
- * @typedef {(...args: any[]) => any} Method
70
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
71
- */
72
-
73
- /**
74
- * @typedef {{
75
- * klass: 'Interface',
76
- * interfaceName: string,
77
- * methodGuards: Record<string | symbol, MethodGuard>
78
- * sloppy?: boolean
79
- * }} InterfaceGuard
80
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
81
- */
82
-
83
- /**
84
- * @typedef {any} MethodGuardMaker
85
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
86
- */
87
-
88
- /**
89
- * @typedef {{ klass: 'methodGuard', callKind: 'sync' | 'async', returnGuard: unknown }} MethodGuard
90
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
91
- */
92
-
93
- /**
94
- * @typedef {any} ArgGuard
95
- * TODO placeholder. Figure out how to import from `@endo/patterns` instead
96
- */
97
-
98
- // /////////////////////////////////////////////////////////////////////////////
99
-
100
- /**
101
- * @typedef {object} StoreOptions
102
- * Of the dimensions on which KeyedStores can differ, we only represent a few
103
- * of them as standard options. A given store maker should document which
104
- * options it supports, as well as its positions on dimensions for which it
105
- * does not support options.
106
- * @property {boolean} [longLived=true] Which way to optimize a weak store. True means
107
- * that we expect this weak store to outlive most of its keys, in which
108
- * case we internally may use a JavaScript `WeakMap`. Otherwise we internally
109
- * may use a JavaScript `Map`.
110
- * Defaults to true, so please mark short lived stores explicitly.
111
- * @property {boolean} [durable=false] The contents of this store survive termination
9
+ * @import {Passable, RemotableObject} from '@endo/pass-style'
10
+ * @import {CopySet, CopyMap, Pattern} from '@endo/patterns'
11
+ * @import {Key} from '@endo/patterns'
12
+ */
13
+
14
+ /**
15
+ * @typedef {object} StoreOptions Of the dimensions on which KeyedStores can
16
+ * differ, we only represent a few of them as standard options. A given store
17
+ * maker should document which options it supports, as well as its positions
18
+ * on dimensions for which it does not support options.
19
+ * @property {boolean} [longLived] Which way to optimize a weak store. True
20
+ * means that we expect this weak store to outlive most of its keys, in which
21
+ * case we internally may use a JavaScript `WeakMap`. Otherwise we internally
22
+ * may use a JavaScript `Map`. Defaults to true, so please mark short lived
23
+ * stores explicitly.
24
+ * @property {boolean} [durable] The contents of this store survive termination
112
25
  * of its containing process, allowing for restart or upgrade but at the cost
113
- * of forbidding storage of references to ephemeral data. Defaults to false.
114
- * @property {boolean} [fakeDurable=false] This store pretends to be a durable store
26
+ * of forbidding storage of references to ephemeral data. Defaults to false.
27
+ * @property {boolean} [fakeDurable] This store pretends to be a durable store
115
28
  * but does not enforce that the things stored in it actually be themselves
116
29
  * durable (whereas an actual durable store would forbid storage of such
117
- * items). This is in service of allowing incremental transition to use of
30
+ * items). This is in service of allowing incremental transition to use of
118
31
  * durable stores, to enable normal operation and testing when some stuff
119
- * intended to eventually be durable has not yet been made durable. A store
32
+ * intended to eventually be durable has not yet been made durable. A store
120
33
  * marked as fakeDurable will appear to operate normally but any attempt to
121
- * upgrade its containing vat will fail with an error.
34
+ * upgrade its containing vat will fail with an error. Defaults to false.
122
35
  * @property {Pattern} [keyShape]
123
36
  * @property {Pattern} [valueShape]
124
37
  */
125
38
 
126
39
  /**
127
40
  * Most store methods are in one of three categories
128
- * * lookup methods (`has`,`get`)
129
- * * update methods (`add`,`init`,`set`,`delete`,`addAll`)
130
- * * query methods (`snapshot`,`keys`,`values`,`entries`,`getSize`)
131
- * * query-update methods (`clear`)
132
41
  *
133
- * WeakStores have the lookup and update methods but not the query
134
- * or query-update methods.
135
- * Non-weak Stores are like their corresponding WeakStores, but with the
136
- * additional query and query-update methods.
137
- */
138
-
139
- /**
140
- * @template {Key & object} [K=Key]
141
- * @typedef {object} WeakSetStore
142
- * @property {(key: K) => boolean} has
143
- * Check if a key exists. The key can be any JavaScript value, though the
144
- * answer will always be false for keys that cannot be found in this store.
145
- * @property {(key: K) => void} add
146
- * Add the key to the set if it is not already there. Do nothing silently if
147
- * already there.
148
- * The key must be one allowed by this store. For example a scalar store only
149
- * allows primitives and remotables.
150
- * @property {(key: K) => void} delete
151
- * Remove the key. Throws if not found.
152
- * @property {(keys: CopySet<K> | Iterable<K>) => void} addAll
153
- */
154
-
155
- /**
156
- * @template {Key} [K=Key]
157
- * @typedef {object} SetStore
158
- * @property {(key: K) => boolean} has
159
- * Check if a key exists. The key can be any JavaScript value, though the
160
- * answer will always be false for keys that cannot be found in this store.
161
- * @property {(key: K) => void} add
162
- * Add the key to the set if it is not already there. Do nothing silently if
163
- * already there.
164
- * The key must be one allowed by this store. For example a scalar store only
165
- * allows primitives and remotables.
166
- * @property {(key: K) => void} delete
167
- * Remove the key. Throws if not found.
168
- * @property {(keys: CopySet<K> | Iterable<K>) => void} addAll
42
+ * - lookup methods (`has`,`get`)
43
+ * - update methods (`add`,`init`,`set`,`delete`,`addAll`)
44
+ * - query methods (`snapshot`,`keys`,`values`,`entries`,`getSize`)
45
+ * - query-update methods (`clear`)
46
+ *
47
+ * WeakStores have the lookup and update methods but not the query or
48
+ * query-update methods. Non-weak Stores are like their corresponding
49
+ * WeakStores, but with the additional query and query-update methods.
50
+ */
51
+
52
+ // TODO use Key for K
53
+ /**
54
+ * @template K
55
+ * @typedef {object} WeakSetStoreMethods
56
+ * @property {(key: K) => boolean} has Check if a key exists. The key can be any
57
+ * JavaScript value, though the answer will always be false for keys that
58
+ * cannot be found in this store.
59
+ * @property {(key: K) => void} add Add the key to the set if it is not already
60
+ * there. Do nothing silently if already there. The key must be one allowed by
61
+ * this store. For example a scalar store only allows primitives and
62
+ * remotables.
63
+ * @property {(key: K) => void} delete Remove the key. Throws if not found.
64
+ * @property {(keys: CopySet<any> | Iterable<K>) => void} addAll
65
+ */
66
+ /**
67
+ * @template K
68
+ * @typedef {RemotableObject & WeakSetStoreMethods<K>} WeakSetStore
69
+ */
70
+
71
+ // TODO use Key for K
72
+ /**
73
+ * @template K
74
+ * @typedef {object} SetStoreMethods
75
+ * @property {(key: K) => boolean} has Check if a key exists. The key can be any
76
+ * JavaScript value, though the answer will always be false for keys that
77
+ * cannot be found in this store.
78
+ * @property {(key: K) => void} add Add the key to the set if it is not already
79
+ * there. Do nothing silently if already there. The key must be one allowed by
80
+ * this store. For example a scalar store only allows primitives and
81
+ * remotables.
82
+ * @property {(key: K) => void} delete Remove the key. Throws if not found.
83
+ * @property {(keys: CopySet<any> | Iterable<K>) => void} addAll
169
84
  * @property {(keyPatt?: Pattern) => Iterable<K>} keys
170
85
  * @property {(keyPatt?: Pattern) => Iterable<K>} values
171
- * @property {(keyPatt?: Pattern) => CopySet<K>} snapshot
86
+ * @property {(keyPatt?: Pattern) => CopySet<any>} snapshot
172
87
  * @property {(keyPatt?: Pattern) => number} getSize
173
88
  * @property {(keyPatt?: Pattern) => void} clear
174
89
  */
175
-
176
90
  /**
177
- * @template {Key & object} [K=Key]
178
- * @template {Passable} [V=Passable]
179
- * @typedef {object} WeakMapStore
180
- * @property {(key: K) => boolean} has
181
- * Check if a key exists. The key can be any JavaScript value, though the
182
- * answer will always be false for keys that cannot be found in this store.
183
- * @property {(key: K) => V} get
184
- * Return a value for the key. Throws if not found.
185
- * @property {(key: K, value: V) => void} init
186
- * Initialize the key only if it doesn't already exist.
187
- * The key must be one allowed by this store. For example a scalar store only
188
- * allows primitives and remotables.
189
- * @property {(key: K, value: V) => void} set
190
- * Set the key. Throws if not found.
191
- * @property {(key: K) => void} delete
192
- * Remove the key. Throws if not found.
193
- * @property {(entries: CopyMap<K,V> | Iterable<[K,V]>) => void} addAll
91
+ * @template K
92
+ * @typedef {RemotableObject & SetStoreMethods<K>} SetStore
194
93
  */
195
94
 
95
+ // TODO use Key for K
96
+ // TODO use Passable for V
196
97
  /**
197
- * @template {Key} [K=Key]
198
- * @template {Passable} [V=Passable]
199
- * @typedef {object} MapStore
200
- * @property {(key: K) => boolean} has
201
- * Check if a key exists. The key can be any JavaScript value, though the
202
- * answer will always be false for keys that cannot be found in this map
203
- * @property {(key: K) => V} get
204
- * Return a value for the key. Throws if not found.
205
- * @property {(key: K, value: V) => void} init
206
- * Initialize the key only if it doesn't already exist.
207
- * The key must be one allowed by this store. For example a scalar store only
208
- * allows primitives and remotables.
209
- * @property {(key: K, value: V) => void} set
210
- * Set the key. Throws if not found.
211
- * @property {(key: K) => void} delete
212
- * Remove the key. Throws if not found.
213
- * @property {(entries: CopyMap<K,V> | Iterable<[K,V]>) => void} addAll
98
+ * @template K
99
+ * @template V
100
+ * @typedef {object} WeakMapStore
101
+ * @property {(key: K) => boolean} has Check if a key exists. The key can be any
102
+ * JavaScript value, though the answer will always be false for keys that
103
+ * cannot be found in this store.
104
+ * @property {(key: K) => V} get Return a value for the key. Throws if not
105
+ * found.
106
+ * @property {(key: K, value: V) => void} init Initialize the key only if it
107
+ * doesn't already exist. The key must be one allowed by this store. For
108
+ * example a scalar store only allows primitives and remotables.
109
+ * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
110
+ * @property {(key: K) => void} delete Remove the key. Throws if not found.
111
+ * @property {(entries: CopyMap<any, any> | Iterable<[K, V]>) => void} addAll
112
+ */
113
+
114
+ // TODO use Key for K
115
+ // TODO use Passable for V
116
+ /**
117
+ * @template K
118
+ * @template V
119
+ * @typedef {object} MapStoreMethods
120
+ * @property {(key: K) => boolean} has Check if a key exists. The key can be any
121
+ * JavaScript value, though the answer will always be false for keys that
122
+ * cannot be found in this map
123
+ * @property {(key: K) => V} get Return a value for the key. Throws if not
124
+ * found.
125
+ * @property {(key: K, value: V) => void} init Initialize the key only if it
126
+ * doesn't already exist. The key must be one allowed by this store. For
127
+ * example a scalar store only allows primitives and remotables.
128
+ * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
129
+ * @property {(key: K) => void} delete Remove the key. Throws if not found.
130
+ * @property {(entries: CopyMap<any, Passable> | Iterable<[K, V]>) => void} addAll
214
131
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<K>} keys
215
132
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<V>} values
133
+ * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<[K, V]>} entries
216
134
  * @property {(
217
135
  * keyPatt?: Pattern,
218
- * valuePatt?: Pattern
219
- * ) => Iterable<[K,V]>} entries
220
- * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => CopyMap<K,V>} snapshot
136
+ * valuePatt?: Pattern,
137
+ * ) => CopyMap<any, Passable>} snapshot
221
138
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => number} getSize
222
139
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => void} clear
223
140
  */
224
-
225
- // ///////////////////////// Deprecated Legacy /////////////////////////////////
226
-
227
141
  /**
228
- * @template K,V
229
- * @typedef {object} LegacyWeakMap
230
- * LegacyWeakMap is deprecated. Use WeakMapStore instead if possible.
231
- * @property {(key: K) => boolean} has
232
- * Check if a key exists
233
- * @property {(key: K) => V} get
234
- * Return a value for the key. Throws if not found.
235
- * @property {(key: K, value: V) => void} init
236
- * Initialize the key only if it
237
- * doesn't already exist
238
- * @property {(key: K, value: V) => void} set
239
- * Set the key. Throws if not found.
240
- * @property {(key: K) => void} delete
241
- * Remove the key. Throws if not found.
142
+ * @template [K=any]
143
+ * @template [V=any]
144
+ * @typedef {RemotableObject & MapStoreMethods<K, V>} MapStore
242
145
  */
243
146
 
147
+ // ///////////////////////// Deprecated Legacy /////////////////////////////////
148
+
244
149
  /**
245
- * @template K,V
246
- * @typedef {object} LegacyMap
247
- * LegacyMap is deprecated. Use MapStore instead if possible.
248
- * @property {(key: K) => boolean} has
249
- * Check if a key exists
250
- * @property {(key: K) => V} get
251
- * Return a value for the key. Throws if not found.
252
- * @property {(key: K, value: V) => void} init
253
- * Initialize the key only if it
254
- * doesn't already exist
255
- * @property {(key: K, value: V) => void} set
256
- * Set the key. Throws if not found.
257
- * @property {(key: K) => void} delete
258
- * Remove the key. Throws if not found.
150
+ * @template K
151
+ * @template V
152
+ * @typedef {object} LegacyWeakMap LegacyWeakMap is deprecated. Use WeakMapStore
153
+ * instead if possible.
154
+ * @property {(key: K) => boolean} has Check if a key exists
155
+ * @property {(key: K) => V} get Return a value for the key. Throws if not
156
+ * found.
157
+ * @property {(key: K, value: V) => void} init Initialize the key only if it
158
+ * doesn't already exist
159
+ * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
160
+ * @property {(key: K) => void} delete Remove the key. Throws if not found.
161
+ */
162
+
163
+ /**
164
+ * @template K
165
+ * @template V
166
+ * @typedef {object} LegacyMap LegacyMap is deprecated. Use MapStore instead if
167
+ * possible.
168
+ * @property {(key: K) => boolean} has Check if a key exists
169
+ * @property {(key: K) => V} get Return a value for the key. Throws if not
170
+ * found.
171
+ * @property {(key: K, value: V) => void} init Initialize the key only if it
172
+ * doesn't already exist
173
+ * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
174
+ * @property {(key: K) => void} delete Remove the key. Throws if not found.
259
175
  * @property {() => Iterable<K>} keys
260
176
  * @property {() => Iterable<V>} values
261
- * @property {() => Iterable<[K,V]>} entries
177
+ * @property {() => Iterable<[K, V]>} entries
262
178
  * @property {() => number} getSize
263
179
  * @property {() => void} clear
264
180
  */