@agoric/store 0.9.3-dev-57802f9.0 → 0.9.3-other-dev-1f26562.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/src/types.js CHANGED
@@ -1,86 +1,170 @@
1
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
+
3
15
  /**
4
- * Note TODO https://github.com/endojs/endo/issues/1488
5
- *
6
- * @typedef {import('@endo/pass-style').Passable} Passable
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
7
32
  */
8
- /** @typedef {import('@endo/pass-style').CopyTagged} CopyTagged */
9
- /** @typedef {import('@endo/patterns').Pattern} Pattern */
10
- /** @typedef {import('@endo/patterns').Key} Key */
33
+
11
34
  /**
12
35
  * @template {Key} [K=Key]
13
- * @typedef {import('@endo/patterns').CopySet<K>} CopySet
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
14
41
  */
42
+
15
43
  /**
16
44
  * @template {Key} [K=Key]
17
45
  * @template {Passable} [V=Passable]
18
- * @typedef {import('@endo/patterns').CopyMap<K, V>} CopyMap
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
62
+ *
63
+ * @property {(...argGuards: ArgGuard[]) => MethodGuardMaker} callWhen Guard an async call
64
+ *
65
+ * @property {(argGuard: ArgGuard) => ArgGuard} await Guard an await
19
66
  */
20
67
 
21
68
  /**
22
- * @typedef {object} StoreOptions Of the dimensions on which KeyedStores can
23
- * differ, we only represent a few of them as standard options. A given store
24
- * maker should document which options it supports, as well as its positions
25
- * on dimensions for which it does not support options.
26
- * @property {boolean} [longLived] Which way to optimize a weak store. True
27
- * means that we expect this weak store to outlive most of its keys, in which
28
- * case we internally may use a JavaScript `WeakMap`. Otherwise we internally
29
- * may use a JavaScript `Map`. Defaults to true, so please mark short lived
30
- * stores explicitly.
31
- * @property {boolean} [durable] The contents of this store survive termination
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
32
112
  * of its containing process, allowing for restart or upgrade but at the cost
33
- * of forbidding storage of references to ephemeral data. Defaults to false.
34
- * @property {boolean} [fakeDurable] This store pretends to be a durable store
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
35
115
  * but does not enforce that the things stored in it actually be themselves
36
116
  * durable (whereas an actual durable store would forbid storage of such
37
- * items). This is in service of allowing incremental transition to use of
117
+ * items). This is in service of allowing incremental transition to use of
38
118
  * durable stores, to enable normal operation and testing when some stuff
39
- * intended to eventually be durable has not yet been made durable. A store
119
+ * intended to eventually be durable has not yet been made durable. A store
40
120
  * marked as fakeDurable will appear to operate normally but any attempt to
41
- * upgrade its containing vat will fail with an error. Defaults to false.
121
+ * upgrade its containing vat will fail with an error.
42
122
  * @property {Pattern} [keyShape]
43
123
  * @property {Pattern} [valueShape]
44
124
  */
45
125
 
46
126
  /**
47
127
  * 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`)
48
132
  *
49
- * - lookup methods (`has`,`get`)
50
- * - update methods (`add`,`init`,`set`,`delete`,`addAll`)
51
- * - query methods (`snapshot`,`keys`,`values`,`entries`,`getSize`)
52
- * - query-update methods (`clear`)
53
- *
54
- * WeakStores have the lookup and update methods but not the query or
55
- * query-update methods. Non-weak Stores are like their corresponding
56
- * WeakStores, but with the additional query and query-update methods.
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.
57
137
  */
58
138
 
59
139
  /**
60
140
  * @template {Key & object} [K=Key]
61
141
  * @typedef {object} WeakSetStore
62
- * @property {(key: K) => boolean} has Check if a key exists. The key can be any
63
- * JavaScript value, though the answer will always be false for keys that
64
- * cannot be found in this store.
65
- * @property {(key: K) => void} add Add the key to the set if it is not already
66
- * there. Do nothing silently if already there. The key must be one allowed by
67
- * this store. For example a scalar store only allows primitives and
68
- * remotables.
69
- * @property {(key: K) => void} delete Remove the key. Throws if not found.
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.
70
152
  * @property {(keys: CopySet<K> | Iterable<K>) => void} addAll
71
153
  */
72
154
 
73
155
  /**
74
156
  * @template {Key} [K=Key]
75
157
  * @typedef {object} SetStore
76
- * @property {(key: K) => boolean} has Check if a key exists. The key can be any
77
- * JavaScript value, though the answer will always be false for keys that
78
- * cannot be found in this store.
79
- * @property {(key: K) => void} add Add the key to the set if it is not already
80
- * there. Do nothing silently if already there. The key must be one allowed by
81
- * this store. For example a scalar store only allows primitives and
82
- * remotables.
83
- * @property {(key: K) => void} delete Remove the key. Throws if not found.
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.
84
168
  * @property {(keys: CopySet<K> | Iterable<K>) => void} addAll
85
169
  * @property {(keyPatt?: Pattern) => Iterable<K>} keys
86
170
  * @property {(keyPatt?: Pattern) => Iterable<K>} values
@@ -93,38 +177,47 @@
93
177
  * @template {Key & object} [K=Key]
94
178
  * @template {Passable} [V=Passable]
95
179
  * @typedef {object} WeakMapStore
96
- * @property {(key: K) => boolean} has Check if a key exists. The key can be any
97
- * JavaScript value, though the answer will always be false for keys that
98
- * cannot be found in this store.
99
- * @property {(key: K) => V} get Return a value for the key. Throws if not
100
- * found.
101
- * @property {(key: K, value: V) => void} init Initialize the key only if it
102
- * doesn't already exist. The key must be one allowed by this store. For
103
- * example a scalar store only allows primitives and remotables.
104
- * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
105
- * @property {(key: K) => void} delete Remove the key. Throws if not found.
106
- * @property {(entries: CopyMap<K, V> | Iterable<[K, V]>) => void} addAll
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
107
194
  */
108
195
 
109
196
  /**
110
197
  * @template {Key} [K=Key]
111
198
  * @template {Passable} [V=Passable]
112
199
  * @typedef {object} MapStore
113
- * @property {(key: K) => boolean} has Check if a key exists. The key can be any
114
- * JavaScript value, though the answer will always be false for keys that
115
- * cannot be found in this map
116
- * @property {(key: K) => V} get Return a value for the key. Throws if not
117
- * found.
118
- * @property {(key: K, value: V) => void} init Initialize the key only if it
119
- * doesn't already exist. The key must be one allowed by this store. For
120
- * example a scalar store only allows primitives and remotables.
121
- * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
122
- * @property {(key: K) => void} delete Remove the key. Throws if not found.
123
- * @property {(entries: CopyMap<K, V> | Iterable<[K, V]>) => void} addAll
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
124
214
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<K>} keys
125
215
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<V>} values
126
- * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<[K, V]>} entries
127
- * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => CopyMap<K, V>} snapshot
216
+ * @property {(
217
+ * keyPatt?: Pattern,
218
+ * valuePatt?: Pattern
219
+ * ) => Iterable<[K,V]>} entries
220
+ * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => CopyMap<K,V>} snapshot
128
221
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => number} getSize
129
222
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => void} clear
130
223
  */
@@ -133,31 +226,39 @@
133
226
 
134
227
  /**
135
228
  * @template K,V
136
- * @typedef {object} LegacyWeakMap LegacyWeakMap is deprecated. Use WeakMapStore
137
- * instead if possible.
138
- * @property {(key: K) => boolean} has Check if a key exists
139
- * @property {(key: K) => V} get Return a value for the key. Throws if not
140
- * found.
141
- * @property {(key: K, value: V) => void} init Initialize the key only if it
142
- * doesn't already exist
143
- * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
144
- * @property {(key: K) => void} delete Remove the key. Throws if not found.
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.
145
242
  */
146
243
 
147
244
  /**
148
245
  * @template K,V
149
- * @typedef {object} LegacyMap LegacyMap is deprecated. Use MapStore instead if
150
- * possible.
151
- * @property {(key: K) => boolean} has Check if a key exists
152
- * @property {(key: K) => V} get Return a value for the key. Throws if not
153
- * found.
154
- * @property {(key: K, value: V) => void} init Initialize the key only if it
155
- * doesn't already exist
156
- * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
157
- * @property {(key: K) => void} delete Remove the key. Throws if not found.
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.
158
259
  * @property {() => Iterable<K>} keys
159
260
  * @property {() => Iterable<V>} values
160
- * @property {() => Iterable<[K, V]>} entries
261
+ * @property {() => Iterable<[K,V]>} entries
161
262
  * @property {() => number} getSize
162
263
  * @property {() => void} clear
163
264
  */