@agoric/store 0.9.3-dev-ecf2d8e.0 → 0.9.3-other-dev-70beeb7.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/CHANGELOG.md +690 -0
- package/package.json +12 -15
- package/src/index.js +1 -1
- package/src/legacy/legacyMap.js +18 -20
- package/src/legacy/legacyWeakMap.js +2 -2
- package/src/stores/scalarMapStore.js +11 -11
- package/src/stores/scalarSetStore.js +6 -6
- package/src/stores/scalarWeakMapStore.js +13 -17
- package/src/stores/scalarWeakSetStore.js +8 -12
- package/src/stores/store-utils.js +30 -29
- package/src/types.js +191 -90
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
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
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
|
-
|
|
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 {
|
|
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 {
|
|
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 {
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
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.
|
|
34
|
-
* @property {boolean} [fakeDurable]
|
|
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).
|
|
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.
|
|
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.
|
|
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
|
-
*
|
|
50
|
-
* -
|
|
51
|
-
* -
|
|
52
|
-
*
|
|
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
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @property {(key: K) => void} add
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
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
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* @property {(key: K) => void} add
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
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
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @property {(key: K) => V} get
|
|
100
|
-
*
|
|
101
|
-
* @property {(key: K, value: V) => void} init
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* @property {(key: K) => void}
|
|
106
|
-
*
|
|
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
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* @property {(key: K) => V} get
|
|
117
|
-
*
|
|
118
|
-
* @property {(key: K, value: V) => void} init
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* @property {(key: K) => void}
|
|
123
|
-
*
|
|
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 {(
|
|
127
|
-
*
|
|
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
|
|
137
|
-
*
|
|
138
|
-
* @property {(key: K) => boolean} has
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
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
|
|
150
|
-
*
|
|
151
|
-
* @property {(key: K) => boolean} has
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
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,
|
|
261
|
+
* @property {() => Iterable<[K,V]>} entries
|
|
161
262
|
* @property {() => number} getSize
|
|
162
263
|
* @property {() => void} clear
|
|
163
264
|
*/
|