@agoric/store 0.9.3-dev-727e4af.0 → 0.9.3-dev-96c9ff5.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/store",
3
- "version": "0.9.3-dev-727e4af.0+727e4af",
3
+ "version": "0.9.3-dev-96c9ff5.0+96c9ff5",
4
4
  "description": "Wrapper for JavaScript map",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -30,14 +30,14 @@
30
30
  },
31
31
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
32
32
  "dependencies": {
33
- "@endo/exo": "^1.4.0",
34
- "@endo/marshal": "^1.4.1",
35
- "@endo/pass-style": "^1.3.1",
36
- "@endo/patterns": "^1.3.1"
33
+ "@endo/exo": "^1.5.0",
34
+ "@endo/marshal": "^1.5.0",
35
+ "@endo/pass-style": "^1.4.0",
36
+ "@endo/patterns": "^1.4.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@endo/init": "^1.1.1",
40
- "@endo/ses-ava": "^1.2.1",
39
+ "@endo/init": "^1.1.2",
40
+ "@endo/ses-ava": "^1.2.2",
41
41
  "ava": "^5.3.0"
42
42
  },
43
43
  "files": [
@@ -58,7 +58,7 @@
58
58
  "timeout": "2m"
59
59
  },
60
60
  "typeCoverage": {
61
- "atLeast": 86.34
61
+ "atLeast": 89.45
62
62
  },
63
- "gitHead": "727e4af514a8e92f400dd1671a788c5d3cbe1b8a"
63
+ "gitHead": "96c9ff577fe14cebeb5a38543ba7f8598ffcd0c7"
64
64
  }
@@ -18,7 +18,7 @@ import { makeCurrentKeysKit } from './store-utils.js';
18
18
  /**
19
19
  * @import {Passable} from '@endo/pass-style');
20
20
  * @import {Key, Pattern} from '@endo/patterns');
21
- * @import {MapStore, StoreOptions} from '../types.js';
21
+ * @import {MapStore, MapStoreMethods, StoreOptions} from '../types.js';
22
22
  */
23
23
 
24
24
  const { quote: q } = assert;
@@ -31,7 +31,7 @@ const { quote: q } = assert;
31
31
  * @param {(k: K, v: V) => void} assertKVOkToSet
32
32
  * @param {(k: K) => void} [assertKeyOkToDelete]
33
33
  * @param {string} [tag]
34
- * @returns {MapStore<K, V>}
34
+ * @returns {MapStoreMethods<K, V>}
35
35
  */
36
36
  export const makeMapStoreMethods = (
37
37
  jsmap,
@@ -133,11 +133,9 @@ export const makeMapStoreMethods = (
133
133
  * or remotables. Other storeMaps will accept, for example, copyArrays and
134
134
  * copyRecords, as keys and look them up based on equality of their contents.
135
135
  *
136
- * @template {Key} K
137
- * @template {Passable} V
138
136
  * @param {string} [tag] - the column name for the key
139
137
  * @param {StoreOptions} [options]
140
- * @returns {MapStore<K, V>}
138
+ * @returns {MapStore<any, any>}
141
139
  */
142
140
  export const makeScalarMapStore = (
143
141
  tag = 'key',
@@ -12,18 +12,18 @@ import { makeCurrentKeysKit } from './store-utils.js';
12
12
 
13
13
  /**
14
14
  * @import {Key, Pattern} from '@endo/patterns');
15
- * @import {SetStore, StoreOptions} from '../types.js';
15
+ * @import {SetStore, SetStoreMethods, StoreOptions} from '../types.js';
16
16
  */
17
17
 
18
18
  const { quote: q } = assert;
19
19
 
20
20
  /**
21
- * @template K
21
+ * @template {Key} K
22
22
  * @param {Set<K>} jsset
23
23
  * @param {(k: K) => void} assertKeyOkToAdd
24
24
  * @param {(k: K) => void} [assertKeyOkToDelete]
25
25
  * @param {string} [keyName]
26
- * @returns {SetStore<K>}
26
+ * @returns {SetStoreMethods<K>}
27
27
  */
28
28
  export const makeSetStoreMethods = (
29
29
  jsset,
@@ -6,12 +6,17 @@ import {
6
6
  isCopyMap,
7
7
  } from '@endo/patterns';
8
8
 
9
- /** @import {WeakMapStore, StoreOptions} from '../types.js'; */
9
+ /**
10
+ * @import {Key} from '@endo/patterns';
11
+ * @import {Passable, RemotableObject} from '@endo/pass-style';
12
+ * @import {WeakMapStore, StoreOptions} from '../types.js';
13
+ */
10
14
 
11
15
  const { quote: q, Fail } = assert;
12
16
 
13
17
  /**
14
- * @template K,V
18
+ * @template {Key} K
19
+ * @template {Passable} V
15
20
  * @param {WeakMap<K & object, V>} jsmap
16
21
  * @param {(k: K, v: V) => void} assertKVOkToAdd
17
22
  * @param {(k: K, v: V) => void} assertKVOkToSet
@@ -66,6 +71,7 @@ export const makeWeakMapStoreMethods = (
66
71
  addAll: entries => {
67
72
  if (typeof entries[Symbol.iterator] !== 'function') {
68
73
  if (Object.isFrozen(entries) && isCopyMap(entries)) {
74
+ // @ts-expect-error XXX
69
75
  entries = getCopyMapEntries(entries);
70
76
  } else {
71
77
  Fail`provided data source is not iterable: ${entries}`;
@@ -96,7 +102,7 @@ export const makeWeakMapStoreMethods = (
96
102
  * @template K,V
97
103
  * @param {string} [tag] - tag for debugging
98
104
  * @param {StoreOptions} [options]
99
- * @returns {WeakMapStore<K, V>}
105
+ * @returns {RemotableObject & WeakMapStore<K, V>}
100
106
  */
101
107
  export const makeScalarWeakMapStore = (
102
108
  tag = 'key',
@@ -8,15 +8,18 @@ import {
8
8
 
9
9
  const { quote: q, Fail } = assert;
10
10
 
11
- /** @import {StoreOptions, WeakSetStore} from '@agoric/store'; */
11
+ /**
12
+ * @import {Key} from '@endo/patterns';
13
+ * @import {StoreOptions, WeakSetStore, WeakSetStoreMethods} from '@agoric/store';
14
+ */
12
15
 
13
16
  /**
14
- * @template K
17
+ * @template {Key} K
15
18
  * @param {WeakSet<K & object>} jsset
16
19
  * @param {(k: K) => void} assertKeyOkToAdd
17
20
  * @param {(k: K) => void} [assertKeyOkToDelete]
18
21
  * @param {string} [keyName]
19
- * @returns {WeakSetStore<K>}
22
+ * @returns {WeakSetStoreMethods<K>}
20
23
  */
21
24
  export const makeWeakSetStoreMethods = (
22
25
  jsset,
@@ -50,6 +53,7 @@ export const makeWeakSetStoreMethods = (
50
53
  addAll: keys => {
51
54
  if (typeof keys[Symbol.iterator] !== 'function') {
52
55
  if (Object.isFrozen(keys) && isCopySet(keys)) {
56
+ // @ts-expect-error XXX
53
57
  keys = getCopySetKeys(keys);
54
58
  } else {
55
59
  Fail`provided data source is not iterable: ${keys}`;
@@ -1,14 +1,42 @@
1
1
  import { Far } from '@endo/marshal';
2
+ import { M, matches } from '@endo/patterns';
2
3
 
3
4
  /**
4
5
  * @import {RankCompare} from '@endo/marshal';
5
6
  * @import {MapStore, WeakMapStore} from '../types.js';
7
+ * @import {Passable} from '@endo/pass-style';
8
+ * @import {Key} from '@endo/patterns';
6
9
  */
7
10
 
8
11
  const { Fail, quote: q } = assert;
9
12
 
13
+ // TODO: Undate `@endo/patterns` to export the original, and delete the
14
+ // reimplementation here.
10
15
  /**
11
- * @template K,V
16
+ * Should behave identically to the one in `@endo/patterns`, but reimplemented
17
+ * for now because `@endo/patterns` forgot to export this one. This one is
18
+ * simple enough that I prefer a reimplementation to a deep import.
19
+ *
20
+ * @param {unknown} s
21
+ * @returns {s is CopySet}
22
+ */
23
+ export const isCopySet = s => matches(s, M.set());
24
+
25
+ // TODO: Undate `@endo/patterns` to export the original, and delete the
26
+ // reimplementation here.
27
+ /**
28
+ * Should behave identically to the one in `@endo/patterns`, but reimplemented
29
+ * for now because `@endo/patterns` forgot to export this one. This one is
30
+ * simple enough that I prefer a reimplementation to a deep import.
31
+ *
32
+ * @param {unknown} m
33
+ * @returns {m is CopyMap}
34
+ */
35
+ export const isCopyMap = m => matches(m, M.map());
36
+
37
+ /**
38
+ * @template {Key} K
39
+ * @template {Passable} V
12
40
  * @typedef {object} CurrentKeysKit
13
41
  * @property {(k: K, v?: V) => void} assertUpdateOnAdd
14
42
  * @property {(k: K) => void} assertUpdateOnDelete
@@ -16,7 +44,8 @@ const { Fail, quote: q } = assert;
16
44
  */
17
45
 
18
46
  /**
19
- * @template K,V
47
+ * @template {Key} K
48
+ * @template {Passable} V
20
49
  * @param {() => Iterable<K>} getRawKeys
21
50
  * @param {(k: K) => boolean} checkHas
22
51
  * @param {RankCompare} compare
@@ -91,7 +120,8 @@ harden(makeCurrentKeysKit);
91
120
  * already is one, return that. Otherwise, call `makeValue(key)`, remember it as
92
121
  * the value for that key, and return it.
93
122
  *
94
- * @template K,V
123
+ * @template {Key} K
124
+ * @template {Passable} V
95
125
  * @param {WeakMapStore<K, V>} mapStore
96
126
  * @param {K} key
97
127
  * @param {(key: K) => V} makeValue
@@ -116,8 +146,8 @@ harden(provideLazy);
116
146
  * termination to happen after the make completes and before it reaches durable
117
147
  * storage.
118
148
  *
119
- * @template K
120
- * @template V
149
+ * @template {Key} K
150
+ * @template {Passable} V
121
151
  * @param {WeakMapStore<K, V>} store
122
152
  */
123
153
  export const makeAtomicProvider = store => {
@@ -167,13 +197,14 @@ export const makeAtomicProvider = store => {
167
197
  };
168
198
  harden(makeAtomicProvider);
169
199
  /**
170
- * @template K
171
- * @template V
200
+ * @template {Key} K
201
+ * @template {Passable} V
172
202
  * @typedef {ReturnType<typeof makeAtomicProvider<K, V>>} AtomicProvider<K, V>
173
203
  */
174
204
 
175
205
  /**
176
- * @template K, V
206
+ * @template {Key} K
207
+ * @template {Passable} V
177
208
  * @param {MapStore<K, V[]>} mapStore
178
209
  * @param {K} key
179
210
  * @param {V} item
package/src/types.js CHANGED
@@ -6,7 +6,7 @@ export {};
6
6
  /**
7
7
  * Note TODO https://github.com/endojs/endo/issues/1488
8
8
  *
9
- * @import {Passable} from '@endo/pass-style'
9
+ * @import {Passable, RemotableObject} from '@endo/pass-style'
10
10
  * @import {CopySet, CopyMap, Pattern} from '@endo/patterns'
11
11
  * @import {Key} from '@endo/patterns'
12
12
  */
@@ -49,9 +49,10 @@ export {};
49
49
  * WeakStores, but with the additional query and query-update methods.
50
50
  */
51
51
 
52
+ // TODO use Key for K
52
53
  /**
53
- * @template {Key & object} [K=Key]
54
- * @typedef {object} WeakSetStore
54
+ * @template K
55
+ * @typedef {object} WeakSetStoreMethods
55
56
  * @property {(key: K) => boolean} has Check if a key exists. The key can be any
56
57
  * JavaScript value, though the answer will always be false for keys that
57
58
  * cannot be found in this store.
@@ -60,12 +61,17 @@ export {};
60
61
  * this store. For example a scalar store only allows primitives and
61
62
  * remotables.
62
63
  * @property {(key: K) => void} delete Remove the key. Throws if not found.
63
- * @property {(keys: CopySet<K> | Iterable<K>) => void} addAll
64
+ * @property {(keys: CopySet<any> | Iterable<K>) => void} addAll
65
+ */
66
+ /**
67
+ * @template K
68
+ * @typedef {RemotableObject & WeakSetStoreMethods<K>} WeakSetStore
64
69
  */
65
70
 
71
+ // TODO use Key for K
66
72
  /**
67
- * @template {Key} [K=Key]
68
- * @typedef {object} SetStore
73
+ * @template K
74
+ * @typedef {object} SetStoreMethods
69
75
  * @property {(key: K) => boolean} has Check if a key exists. The key can be any
70
76
  * JavaScript value, though the answer will always be false for keys that
71
77
  * cannot be found in this store.
@@ -74,17 +80,23 @@ export {};
74
80
  * this store. For example a scalar store only allows primitives and
75
81
  * remotables.
76
82
  * @property {(key: K) => void} delete Remove the key. Throws if not found.
77
- * @property {(keys: CopySet<K> | Iterable<K>) => void} addAll
83
+ * @property {(keys: CopySet<any> | Iterable<K>) => void} addAll
78
84
  * @property {(keyPatt?: Pattern) => Iterable<K>} keys
79
85
  * @property {(keyPatt?: Pattern) => Iterable<K>} values
80
- * @property {(keyPatt?: Pattern) => CopySet<K>} snapshot
86
+ * @property {(keyPatt?: Pattern) => CopySet<any>} snapshot
81
87
  * @property {(keyPatt?: Pattern) => number} getSize
82
88
  * @property {(keyPatt?: Pattern) => void} clear
83
89
  */
90
+ /**
91
+ * @template K
92
+ * @typedef {RemotableObject & SetStoreMethods<K>} SetStore
93
+ */
84
94
 
95
+ // TODO use Key for K
96
+ // TODO use Passable for V
85
97
  /**
86
- * @template {Key & object} [K=Key]
87
- * @template {Passable} [V=Passable]
98
+ * @template K
99
+ * @template V
88
100
  * @typedef {object} WeakMapStore
89
101
  * @property {(key: K) => boolean} has Check if a key exists. The key can be any
90
102
  * JavaScript value, though the answer will always be false for keys that
@@ -96,13 +108,15 @@ export {};
96
108
  * example a scalar store only allows primitives and remotables.
97
109
  * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
98
110
  * @property {(key: K) => void} delete Remove the key. Throws if not found.
99
- * @property {(entries: CopyMap<K, V> | Iterable<[K, V]>) => void} addAll
111
+ * @property {(entries: CopyMap<any, any> | Iterable<[K, V]>) => void} addAll
100
112
  */
101
113
 
114
+ // TODO use Key for K
115
+ // TODO use Passable for V
102
116
  /**
103
- * @template {Key} [K=Key]
104
- * @template {Passable} [V=Passable]
105
- * @typedef {object} MapStore
117
+ * @template K
118
+ * @template V
119
+ * @typedef {object} MapStoreMethods
106
120
  * @property {(key: K) => boolean} has Check if a key exists. The key can be any
107
121
  * JavaScript value, though the answer will always be false for keys that
108
122
  * cannot be found in this map
@@ -113,14 +127,22 @@ export {};
113
127
  * example a scalar store only allows primitives and remotables.
114
128
  * @property {(key: K, value: V) => void} set Set the key. Throws if not found.
115
129
  * @property {(key: K) => void} delete Remove the key. Throws if not found.
116
- * @property {(entries: CopyMap<K, V> | Iterable<[K, V]>) => void} addAll
130
+ * @property {(entries: CopyMap<any, Passable> | Iterable<[K, V]>) => void} addAll
117
131
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<K>} keys
118
132
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<V>} values
119
133
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => Iterable<[K, V]>} entries
120
- * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => CopyMap<K, V>} snapshot
134
+ * @property {(
135
+ * keyPatt?: Pattern,
136
+ * valuePatt?: Pattern,
137
+ * ) => CopyMap<any, Passable>} snapshot
121
138
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => number} getSize
122
139
  * @property {(keyPatt?: Pattern, valuePatt?: Pattern) => void} clear
123
140
  */
141
+ /**
142
+ * @template [K=any]
143
+ * @template [V=any]
144
+ * @typedef {RemotableObject & MapStoreMethods<K, V>} MapStore
145
+ */
124
146
 
125
147
  // ///////////////////////// Deprecated Legacy /////////////////////////////////
126
148