@agoric/store 0.9.3-mainnet1B-dev-26244e8.0 → 0.9.3-orchestration-dev-096c4e8.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/README.md +3 -33
- package/package.json +16 -12
- package/src/index.js +12 -7
- package/src/legacy/legacyMap.js +23 -20
- package/src/legacy/legacyWeakMap.js +5 -3
- package/src/stores/scalarMapStore.js +11 -11
- package/src/stores/scalarSetStore.js +6 -6
- package/src/stores/scalarWeakMapStore.js +23 -15
- package/src/stores/scalarWeakSetStore.js +18 -10
- package/src/stores/store-utils.js +19 -45
- package/src/types.js +97 -196
- package/CHANGELOG.md +0 -706
package/src/types.js
CHANGED
|
@@ -1,170 +1,86 @@
|
|
|
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
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @typedef {Passable} Key
|
|
17
|
-
* TODO placeholder. Figure out how to import from `@endo/patterns` instead
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
3
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
4
|
+
* Note TODO https://github.com/endojs/endo/issues/1488
|
|
5
|
+
*
|
|
6
|
+
* @typedef {import('@endo/pass-style').Passable} Passable
|
|
23
7
|
*/
|
|
24
|
-
|
|
8
|
+
/** @typedef {import('@endo/pass-style').CopyTagged} CopyTagged */
|
|
9
|
+
/** @typedef {import('@endo/patterns').Pattern} Pattern */
|
|
10
|
+
/** @typedef {import('@endo/patterns').Key} Key */
|
|
25
11
|
/**
|
|
26
12
|
* @template {Key} [K=Key]
|
|
27
|
-
* @typedef {
|
|
28
|
-
* [Symbol.toStringTag]: 'copySet',
|
|
29
|
-
* payload: Array<K>,
|
|
30
|
-
* }} CopySet
|
|
31
|
-
* TODO placeholder. Figure out how to import from `@endo/patterns` instead
|
|
13
|
+
* @typedef {import('@endo/patterns').CopySet<K>} CopySet
|
|
32
14
|
*/
|
|
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
|
-
*/
|
|
42
|
-
|
|
43
15
|
/**
|
|
44
16
|
* @template {Key} [K=Key]
|
|
45
17
|
* @template {Passable} [V=Passable]
|
|
46
|
-
* @typedef {
|
|
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
|
|
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
|
|
18
|
+
* @typedef {import('@endo/patterns').CopyMap<K, V>} CopyMap
|
|
81
19
|
*/
|
|
82
20
|
|
|
83
21
|
/**
|
|
84
|
-
* @typedef {
|
|
85
|
-
*
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
*
|
|
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
|
|
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
|
|
112
32
|
* of its containing process, allowing for restart or upgrade but at the cost
|
|
113
|
-
* of forbidding storage of references to ephemeral data.
|
|
114
|
-
* @property {boolean} [fakeDurable
|
|
33
|
+
* of forbidding storage of references to ephemeral data. Defaults to false.
|
|
34
|
+
* @property {boolean} [fakeDurable] This store pretends to be a durable store
|
|
115
35
|
* but does not enforce that the things stored in it actually be themselves
|
|
116
36
|
* durable (whereas an actual durable store would forbid storage of such
|
|
117
|
-
* items).
|
|
37
|
+
* items). This is in service of allowing incremental transition to use of
|
|
118
38
|
* durable stores, to enable normal operation and testing when some stuff
|
|
119
|
-
* intended to eventually be durable has not yet been made durable.
|
|
39
|
+
* intended to eventually be durable has not yet been made durable. A store
|
|
120
40
|
* marked as fakeDurable will appear to operate normally but any attempt to
|
|
121
|
-
* upgrade its containing vat will fail with an error.
|
|
41
|
+
* upgrade its containing vat will fail with an error. Defaults to false.
|
|
122
42
|
* @property {Pattern} [keyShape]
|
|
123
43
|
* @property {Pattern} [valueShape]
|
|
124
44
|
*/
|
|
125
45
|
|
|
126
46
|
/**
|
|
127
47
|
* 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
48
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
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.
|
|
137
57
|
*/
|
|
138
58
|
|
|
139
59
|
/**
|
|
140
60
|
* @template {Key & object} [K=Key]
|
|
141
61
|
* @typedef {object} WeakSetStore
|
|
142
|
-
* @property {(key: K) => boolean} has
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* @property {(key: K) => void} add
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @property {(key: K) => void} delete
|
|
151
|
-
* Remove the key. Throws if not found.
|
|
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.
|
|
152
70
|
* @property {(keys: CopySet<K> | Iterable<K>) => void} addAll
|
|
153
71
|
*/
|
|
154
72
|
|
|
155
73
|
/**
|
|
156
74
|
* @template {Key} [K=Key]
|
|
157
75
|
* @typedef {object} SetStore
|
|
158
|
-
* @property {(key: K) => boolean} has
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* @property {(key: K) => void} add
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* @property {(key: K) => void} delete
|
|
167
|
-
* Remove the key. Throws if not found.
|
|
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.
|
|
168
84
|
* @property {(keys: CopySet<K> | Iterable<K>) => void} addAll
|
|
169
85
|
* @property {(keyPatt?: Pattern) => Iterable<K>} keys
|
|
170
86
|
* @property {(keyPatt?: Pattern) => Iterable<K>} values
|
|
@@ -177,47 +93,38 @@
|
|
|
177
93
|
* @template {Key & object} [K=Key]
|
|
178
94
|
* @template {Passable} [V=Passable]
|
|
179
95
|
* @typedef {object} WeakMapStore
|
|
180
|
-
* @property {(key: K) => boolean} has
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @property {(key: K) => V} get
|
|
184
|
-
*
|
|
185
|
-
* @property {(key: K, value: V) => void} init
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* @property {(key: K
|
|
190
|
-
*
|
|
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
|
|
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
|
|
194
107
|
*/
|
|
195
108
|
|
|
196
109
|
/**
|
|
197
110
|
* @template {Key} [K=Key]
|
|
198
111
|
* @template {Passable} [V=Passable]
|
|
199
112
|
* @typedef {object} MapStore
|
|
200
|
-
* @property {(key: K) => boolean} has
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* @property {(key: K) => V} get
|
|
204
|
-
*
|
|
205
|
-
* @property {(key: K, value: V) => void} init
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* @property {(key: K
|
|
210
|
-
*
|
|
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
|
|
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
|
|
214
124
|
* @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<K>} keys
|
|
215
125
|
* @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<V>} values
|
|
216
|
-
* @property {(
|
|
217
|
-
*
|
|
218
|
-
* valuePatt?: Pattern
|
|
219
|
-
* ) => Iterable<[K,V]>} entries
|
|
220
|
-
* @property {(keyPatt?: Pattern, valuePatt?: Pattern) => CopyMap<K,V>} snapshot
|
|
126
|
+
* @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<[K, V]>} entries
|
|
127
|
+
* @property {(keyPatt?: Pattern, valuePatt?: Pattern) => CopyMap<K, V>} snapshot
|
|
221
128
|
* @property {(keyPatt?: Pattern, valuePatt?: Pattern) => number} getSize
|
|
222
129
|
* @property {(keyPatt?: Pattern, valuePatt?: Pattern) => void} clear
|
|
223
130
|
*/
|
|
@@ -225,40 +132,34 @@
|
|
|
225
132
|
// ///////////////////////// Deprecated Legacy /////////////////////////////////
|
|
226
133
|
|
|
227
134
|
/**
|
|
228
|
-
* @template K
|
|
229
|
-
* @
|
|
230
|
-
* LegacyWeakMap is deprecated. Use WeakMapStore
|
|
231
|
-
*
|
|
232
|
-
* Check if a key exists
|
|
233
|
-
* @property {(key: K) => V} get
|
|
234
|
-
*
|
|
235
|
-
* @property {(key: K, value: V) => void} init
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* @property {(key: K
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
*
|
|
246
|
-
* @
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
* @property {(key: K
|
|
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.
|
|
135
|
+
* @template K
|
|
136
|
+
* @template V
|
|
137
|
+
* @typedef {object} LegacyWeakMap LegacyWeakMap is deprecated. Use WeakMapStore
|
|
138
|
+
* instead if possible.
|
|
139
|
+
* @property {(key: K) => boolean} has Check if a key exists
|
|
140
|
+
* @property {(key: K) => V} get Return a value for the key. Throws if not
|
|
141
|
+
* found.
|
|
142
|
+
* @property {(key: K, value: V) => void} init Initialize the key only if it
|
|
143
|
+
* doesn't already exist
|
|
144
|
+
* @property {(key: K, value: V) => void} set Set the key. Throws if not found.
|
|
145
|
+
* @property {(key: K) => void} delete Remove the key. Throws if not found.
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @template K
|
|
150
|
+
* @template V
|
|
151
|
+
* @typedef {object} LegacyMap LegacyMap is deprecated. Use MapStore instead if
|
|
152
|
+
* possible.
|
|
153
|
+
* @property {(key: K) => boolean} has Check if a key exists
|
|
154
|
+
* @property {(key: K) => V} get Return a value for the key. Throws if not
|
|
155
|
+
* found.
|
|
156
|
+
* @property {(key: K, value: V) => void} init Initialize the key only if it
|
|
157
|
+
* doesn't already exist
|
|
158
|
+
* @property {(key: K, value: V) => void} set Set the key. Throws if not found.
|
|
159
|
+
* @property {(key: K) => void} delete Remove the key. Throws if not found.
|
|
259
160
|
* @property {() => Iterable<K>} keys
|
|
260
161
|
* @property {() => Iterable<V>} values
|
|
261
|
-
* @property {() => Iterable<[K,V]>} entries
|
|
162
|
+
* @property {() => Iterable<[K, V]>} entries
|
|
262
163
|
* @property {() => number} getSize
|
|
263
164
|
* @property {() => void} clear
|
|
264
165
|
*/
|