@agoric/store 0.9.3-u14.0 → 0.9.3-u16.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/exported.js +1 -1
- package/package.json +18 -14
- package/src/index.js +14 -7
- package/src/legacy/legacyMap.js +23 -20
- package/src/legacy/legacyWeakMap.js +6 -4
- package/src/stores/scalarMapStore.js +17 -13
- package/src/stores/scalarSetStore.js +13 -8
- package/src/stores/scalarWeakMapStore.js +32 -16
- package/src/stores/scalarWeakSetStore.js +26 -12
- package/src/stores/store-utils.js +48 -40
- package/src/types.js +139 -223
- package/CHANGELOG.md +0 -722
package/README.md
CHANGED
|
@@ -22,36 +22,6 @@ Store adds some additional functionality on top of Map.
|
|
|
22
22
|
|
|
23
23
|
See `makeScalarWeakMapStore` for the wrapper around JavaScript's WeakMap abstraction.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
that are compatible with large, synchronous secondary storage that can be paged
|
|
29
|
-
in and out of local memory.
|
|
30
|
-
|
|
31
|
-
```js
|
|
32
|
-
import { makeExternalStore } from '@agoric/store';
|
|
33
|
-
|
|
34
|
-
// Here is us defining an instance store for 'hello' objects.
|
|
35
|
-
const estore = makeExternalStore((msg = 'Hello') => ({
|
|
36
|
-
hello(nickname) {
|
|
37
|
-
return `${msg}, ${nickname}!`;
|
|
38
|
-
},
|
|
39
|
-
}));
|
|
40
|
-
|
|
41
|
-
const h = estore.makeInstance('Hi');
|
|
42
|
-
h.hello('friend') === 'Hi, friend!';
|
|
43
|
-
const wm = estore.makeWeakMap('Hello object');
|
|
44
|
-
wm.init(h, 'data');
|
|
45
|
-
// ... time passes and h is paged out and reloaded.
|
|
46
|
-
wm.get(h) === 'data';
|
|
47
|
-
wm.set(h, 'new-data');
|
|
48
|
-
// ... time passes and h is paged out and reloaded.
|
|
49
|
-
map.delete(h);
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Note that when you import and use the `makeExternalStore` function, the platform
|
|
53
|
-
you are running on may rewrite your code to use a more scalable implementation
|
|
54
|
-
of that function. If it is not rewritten, then `makeExternalStore` will use
|
|
55
|
-
`makeMemoryExternalStore`, a full-featured, though in-memory-only
|
|
56
|
-
implementation. If you don't desire rewriting, then use
|
|
57
|
-
`makeMemoryExternalStore` directly.
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
Be aware that both `@agoric/base-zone` and this package `@agoric/store` will move from the agoric-sdk repository to the endo repository and likely renamed `@endo/zone` and `@endo/store`. At that time, we will first deprecate the versions here, then replace them with deprecated stubs that reexport from their new home. We hope to eventually remove even these stubs, depending on the compat cost at that time.
|
package/exported.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
// Dummy file for .d.ts twin to declare ambients
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/store",
|
|
3
|
-
"version": "0.9.3-
|
|
3
|
+
"version": "0.9.3-u16.0",
|
|
4
4
|
"description": "Wrapper for JavaScript map",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": "
|
|
8
|
+
"node": "^18.12 || ^20.9"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "exit 0",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"test:xs": "exit 0",
|
|
14
14
|
"lint-fix": "yarn lint:eslint --fix",
|
|
15
15
|
"lint": "run-s --continue-on-error lint:*",
|
|
16
|
-
"lint:types": "tsc
|
|
16
|
+
"lint:types": "tsc",
|
|
17
17
|
"lint:eslint": "eslint ."
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
@@ -30,17 +30,15 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@endo/
|
|
35
|
-
"@endo/
|
|
36
|
-
"@endo/
|
|
37
|
-
"@endo/patterns": "0.2.2"
|
|
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"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"
|
|
43
|
-
"ava": "^5.2.0"
|
|
39
|
+
"@endo/init": "^1.1.2",
|
|
40
|
+
"@endo/ses-ava": "^1.2.2",
|
|
41
|
+
"ava": "^5.3.0"
|
|
44
42
|
},
|
|
45
43
|
"files": [
|
|
46
44
|
"src/",
|
|
@@ -52,9 +50,15 @@
|
|
|
52
50
|
},
|
|
53
51
|
"ava": {
|
|
54
52
|
"files": [
|
|
55
|
-
"test
|
|
53
|
+
"test/**/*.test.*"
|
|
54
|
+
],
|
|
55
|
+
"require": [
|
|
56
|
+
"@endo/init/debug.js"
|
|
56
57
|
],
|
|
57
58
|
"timeout": "2m"
|
|
58
59
|
},
|
|
59
|
-
"
|
|
60
|
+
"typeCoverage": {
|
|
61
|
+
"atLeast": 89.45
|
|
62
|
+
},
|
|
63
|
+
"gitHead": "bbdf652c3f413381cb352a8a360db1063974fafd"
|
|
60
64
|
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export { makeScalarWeakSetStore } from './stores/scalarWeakSetStore.js';
|
|
2
|
+
export { makeScalarSetStore } from './stores/scalarSetStore.js';
|
|
3
|
+
export { makeScalarWeakMapStore } from './stores/scalarWeakMapStore.js';
|
|
4
|
+
export { makeScalarMapStore } from './stores/scalarMapStore.js';
|
|
5
|
+
|
|
6
|
+
export { provideLazy } from './stores/store-utils.js';
|
|
7
|
+
|
|
8
|
+
// /////////////////////// Deprecated Re-exports ///////////////////////////////
|
|
9
|
+
// Importers should import directly from the packages shown below
|
|
10
|
+
|
|
1
11
|
export {
|
|
2
12
|
isKey,
|
|
3
13
|
assertKey,
|
|
@@ -42,6 +52,8 @@ export {
|
|
|
42
52
|
assertPattern,
|
|
43
53
|
matches,
|
|
44
54
|
mustMatch,
|
|
55
|
+
isCopySet,
|
|
56
|
+
isCopyMap,
|
|
45
57
|
} from '@endo/patterns';
|
|
46
58
|
|
|
47
59
|
export {
|
|
@@ -51,14 +63,9 @@ export {
|
|
|
51
63
|
makeExo,
|
|
52
64
|
} from '@endo/exo';
|
|
53
65
|
|
|
54
|
-
export { makeScalarWeakSetStore } from './stores/scalarWeakSetStore.js';
|
|
55
|
-
export { makeScalarSetStore } from './stores/scalarSetStore.js';
|
|
56
|
-
export { makeScalarWeakMapStore } from './stores/scalarWeakMapStore.js';
|
|
57
|
-
export { makeScalarMapStore } from './stores/scalarMapStore.js';
|
|
58
|
-
|
|
59
|
-
export { provideLazy } from './stores/store-utils.js';
|
|
60
|
-
|
|
61
66
|
// /////////////////////// Deprecated Legacy ///////////////////////////////////
|
|
62
67
|
|
|
63
68
|
export { makeLegacyMap } from './legacy/legacyMap.js';
|
|
64
69
|
export { makeLegacyWeakMap } from './legacy/legacyWeakMap.js';
|
|
70
|
+
// eslint-disable-next-line import/export
|
|
71
|
+
export * from './types.js';
|
package/src/legacy/legacyMap.js
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
/** @import {LegacyMap, LegacyWeakMap} from '../types.js'; */
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
// TODO, once migrated to endo, import from @endo/errors instead
|
|
4
|
+
const { Fail, quote: q } = assert;
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
* This module and its fraternal sibling legacyWeakMap exist only to
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* can be used as values.
|
|
7
|
+
* This module and its fraternal sibling legacyWeakMap exist only to ease a
|
|
8
|
+
* transition to the modern `store` system, are deprecated, and will eventually
|
|
9
|
+
* disappear. They are needed for now to support some of the uses of the old
|
|
10
|
+
* behavior that are not compatible with the new. The constraint imposed by the
|
|
11
|
+
* new is that only passables can be used as values, and only keys (roughly,
|
|
12
|
+
* structures, aka comparables) can be used as values.
|
|
13
13
|
*
|
|
14
14
|
* See https://github.com/Agoric/agoric-sdk/pull/3567
|
|
15
|
+
*
|
|
15
16
|
* TODO Once that PR is merged, link to the documents rather than the PRs.
|
|
16
17
|
*
|
|
17
18
|
* Each of these non-conforming uses should be marked with a
|
|
19
|
+
*
|
|
18
20
|
* ```js
|
|
19
21
|
* // Legacy because...
|
|
20
22
|
* ```
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
23
|
+
*
|
|
24
|
+
* comment explaining the problem inhibiting conversion to the new system. Some
|
|
25
|
+
* of these problems as of this writing:
|
|
26
|
+
*
|
|
27
|
+
* - A promiseKit used as a value, even though a promiseKit is not a passable.
|
|
28
|
+
* Solutions are to make it a passable, or to convert the container back to a
|
|
29
|
+
* conventional JavaScript Map.
|
|
30
|
+
* - A mutable array used as a value, that is subsequently mutated. Freezing the
|
|
31
|
+
* array wouldn't work of course because it would break the subsequent
|
|
32
|
+
* mutation. Using a far object wrapping an array would likely work fine.
|
|
30
33
|
*
|
|
31
34
|
* @deprecated switch to ScalarMap if possible, Map otherwise
|
|
32
35
|
* @template K,V
|
|
33
|
-
* @param {string} [tag
|
|
34
|
-
* @returns {LegacyMap<K,V>}
|
|
36
|
+
* @param {string} [tag] - tag for debugging
|
|
37
|
+
* @returns {LegacyMap<K, V>}
|
|
35
38
|
*/
|
|
36
39
|
export const makeLegacyMap = (tag = 'key') => {
|
|
37
40
|
const m = new Map();
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
/** @import {LegacyWeakMap} from '../types.js'; */
|
|
2
|
+
|
|
3
|
+
// TODO, once migrated to endo, import from @endo/errors instead
|
|
4
|
+
const { Fail, quote: q } = assert;
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* See doccomment in the closely related `legacyMap.js` module.
|
|
6
8
|
*
|
|
7
9
|
* @deprecated switch to ScalarWeakMap if possible, WeakMap otherwise
|
|
8
10
|
* @template K,V
|
|
9
|
-
* @param {string} [tag
|
|
10
|
-
* @returns {LegacyWeakMap<K,V>}
|
|
11
|
+
* @param {string} [tag] - tag for debugging
|
|
12
|
+
* @returns {LegacyWeakMap<K, V>}
|
|
11
13
|
*/
|
|
12
14
|
export const makeLegacyWeakMap = (tag = 'key') => {
|
|
13
15
|
/** @type {WeakMap<K & object, V>} */
|
|
@@ -15,17 +15,23 @@ import {
|
|
|
15
15
|
import { makeWeakMapStoreMethods } from './scalarWeakMapStore.js';
|
|
16
16
|
import { makeCurrentKeysKit } from './store-utils.js';
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @import {Passable} from '@endo/pass-style');
|
|
20
|
+
* @import {Key, Pattern} from '@endo/patterns');
|
|
21
|
+
* @import {MapStore, MapStoreMethods, StoreOptions} from '../types.js';
|
|
22
|
+
*/
|
|
23
|
+
|
|
18
24
|
const { quote: q } = assert;
|
|
19
25
|
|
|
20
26
|
/**
|
|
21
27
|
* @template {Key} K
|
|
22
28
|
* @template {Passable} V
|
|
23
|
-
* @param {Map<K,V>} jsmap
|
|
29
|
+
* @param {Map<K, V>} jsmap
|
|
24
30
|
* @param {(k: K, v: V) => void} assertKVOkToAdd
|
|
25
31
|
* @param {(k: K, v: V) => void} assertKVOkToSet
|
|
26
|
-
* @param {(
|
|
32
|
+
* @param {(k: K) => void} [assertKeyOkToDelete]
|
|
27
33
|
* @param {string} [tag]
|
|
28
|
-
* @returns {
|
|
34
|
+
* @returns {MapStoreMethods<K, V>}
|
|
29
35
|
*/
|
|
30
36
|
export const makeMapStoreMethods = (
|
|
31
37
|
jsmap,
|
|
@@ -77,7 +83,7 @@ export const makeMapStoreMethods = (
|
|
|
77
83
|
/**
|
|
78
84
|
* @param {Pattern} [keyPatt]
|
|
79
85
|
* @param {Pattern} [valuePatt]
|
|
80
|
-
* @returns {Iterable<[K,V]>}
|
|
86
|
+
* @returns {Iterable<[K, V]>}
|
|
81
87
|
*/
|
|
82
88
|
const entries = (keyPatt = undefined, valuePatt = undefined) =>
|
|
83
89
|
mapIterable(keys(keyPatt, valuePatt), k => [
|
|
@@ -117,21 +123,19 @@ export const makeMapStoreMethods = (
|
|
|
117
123
|
};
|
|
118
124
|
|
|
119
125
|
/**
|
|
120
|
-
* Distinguishes between adding a new key (init) and updating or
|
|
121
|
-
*
|
|
126
|
+
* Distinguishes between adding a new key (init) and updating or referencing a
|
|
127
|
+
* key (get, set, delete).
|
|
122
128
|
*
|
|
123
|
-
* `init` is only allowed if the key does not already exist. `Get`,
|
|
124
|
-
* `
|
|
129
|
+
* `init` is only allowed if the key does not already exist. `Get`, `set` and
|
|
130
|
+
* `delete` are only allowed if the key does already exist.
|
|
125
131
|
*
|
|
126
|
-
* This is a
|
|
132
|
+
* This is a _scalar_ map in that the keys can only be atomic values, primitives
|
|
127
133
|
* or remotables. Other storeMaps will accept, for example, copyArrays and
|
|
128
134
|
* copyRecords, as keys and look them up based on equality of their contents.
|
|
129
135
|
*
|
|
130
|
-
* @
|
|
131
|
-
* @template {Passable} V
|
|
132
|
-
* @param {string} [tag='key'] - the column name for the key
|
|
136
|
+
* @param {string} [tag] - the column name for the key
|
|
133
137
|
* @param {StoreOptions} [options]
|
|
134
|
-
* @returns {MapStore<
|
|
138
|
+
* @returns {MapStore<any, any>}
|
|
135
139
|
*/
|
|
136
140
|
export const makeScalarMapStore = (
|
|
137
141
|
tag = 'key',
|
|
@@ -10,15 +10,20 @@ import {
|
|
|
10
10
|
import { makeWeakSetStoreMethods } from './scalarWeakSetStore.js';
|
|
11
11
|
import { makeCurrentKeysKit } from './store-utils.js';
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @import {Key, Pattern} from '@endo/patterns');
|
|
15
|
+
* @import {SetStore, SetStoreMethods, StoreOptions} from '../types.js';
|
|
16
|
+
*/
|
|
17
|
+
|
|
13
18
|
const { quote: q } = assert;
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
|
-
* @template K
|
|
21
|
+
* @template {Key} K
|
|
17
22
|
* @param {Set<K>} jsset
|
|
18
23
|
* @param {(k: K) => void} assertKeyOkToAdd
|
|
19
24
|
* @param {(k: K) => void} [assertKeyOkToDelete]
|
|
20
25
|
* @param {string} [keyName]
|
|
21
|
-
* @returns {
|
|
26
|
+
* @returns {SetStoreMethods<K>}
|
|
22
27
|
*/
|
|
23
28
|
export const makeSetStoreMethods = (
|
|
24
29
|
jsset,
|
|
@@ -74,18 +79,18 @@ export const makeSetStoreMethods = (
|
|
|
74
79
|
};
|
|
75
80
|
|
|
76
81
|
/**
|
|
77
|
-
* Distinguishes between adding a new key (init) and updating or
|
|
78
|
-
*
|
|
82
|
+
* Distinguishes between adding a new key (init) and updating or referencing a
|
|
83
|
+
* key (get, set, delete).
|
|
79
84
|
*
|
|
80
|
-
* `init` is only allowed if the key does not already exist. `Get`,
|
|
81
|
-
* `
|
|
85
|
+
* `init` is only allowed if the key does not already exist. `Get`, `set` and
|
|
86
|
+
* `delete` are only allowed if the key does already exist.
|
|
82
87
|
*
|
|
83
|
-
* This is a
|
|
88
|
+
* This is a _scalar_ set in that the keys can only be atomic values, primitives
|
|
84
89
|
* or remotables. Other storeSets will accept, for example, copyArrays and
|
|
85
90
|
* copyRecords, as keys and look them up based on equality of their contents.
|
|
86
91
|
*
|
|
87
92
|
* @template K
|
|
88
|
-
* @param {string} [tag
|
|
93
|
+
* @param {string} [tag] - tag for debugging
|
|
89
94
|
* @param {StoreOptions} [options]
|
|
90
95
|
* @returns {SetStore<K>}
|
|
91
96
|
*/
|
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
import { Far, assertPassable, passStyleOf } from '@endo/pass-style';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
getCopyMapEntries,
|
|
4
|
+
mustMatch,
|
|
5
|
+
assertPattern,
|
|
6
|
+
isCopyMap,
|
|
7
|
+
} from '@endo/patterns';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @import {Key} from '@endo/patterns';
|
|
11
|
+
* @import {Passable, RemotableObject} from '@endo/pass-style';
|
|
12
|
+
* @import {WeakMapStore, StoreOptions} from '../types.js';
|
|
13
|
+
*/
|
|
4
14
|
|
|
5
15
|
const { quote: q, Fail } = assert;
|
|
6
16
|
|
|
7
17
|
/**
|
|
8
|
-
* @template K
|
|
18
|
+
* @template {Key} K
|
|
19
|
+
* @template {Passable} V
|
|
9
20
|
* @param {WeakMap<K & object, V>} jsmap
|
|
10
21
|
* @param {(k: K, v: V) => void} assertKVOkToAdd
|
|
11
22
|
* @param {(k: K, v: V) => void} assertKVOkToSet
|
|
12
23
|
* @param {(k: K) => void} [assertKeyOkToDelete]
|
|
13
24
|
* @param {string} [keyName]
|
|
14
|
-
* @returns {WeakMapStore<K,V>}
|
|
25
|
+
* @returns {WeakMapStore<K, V>}
|
|
15
26
|
*/
|
|
16
27
|
export const makeWeakMapStoreMethods = (
|
|
17
28
|
jsmap,
|
|
@@ -58,8 +69,13 @@ export const makeWeakMapStoreMethods = (
|
|
|
58
69
|
},
|
|
59
70
|
|
|
60
71
|
addAll: entries => {
|
|
61
|
-
if (
|
|
62
|
-
entries
|
|
72
|
+
if (typeof entries[Symbol.iterator] !== 'function') {
|
|
73
|
+
if (Object.isFrozen(entries) && isCopyMap(entries)) {
|
|
74
|
+
// @ts-expect-error XXX
|
|
75
|
+
entries = getCopyMapEntries(entries);
|
|
76
|
+
} else {
|
|
77
|
+
Fail`provided data source is not iterable: ${entries}`;
|
|
78
|
+
}
|
|
63
79
|
}
|
|
64
80
|
for (const [key, value] of /** @type {Iterable<[K, V]>} */ (entries)) {
|
|
65
81
|
// Don't assert that the key either does or does not exist.
|
|
@@ -71,22 +87,22 @@ export const makeWeakMapStoreMethods = (
|
|
|
71
87
|
};
|
|
72
88
|
|
|
73
89
|
/**
|
|
74
|
-
* This is a
|
|
75
|
-
* primitives or remotables.
|
|
76
|
-
*
|
|
77
|
-
*
|
|
90
|
+
* This is a _scalar_ mapStore in that the keys can only be atomic values:
|
|
91
|
+
* primitives or remotables. Other mapStores will accept, for example,
|
|
92
|
+
* copyArrays and copyRecords as keys and look them up based on equality of
|
|
93
|
+
* their contents.
|
|
78
94
|
*
|
|
79
95
|
* TODO For now, this scalarWeakMap accepts only remotables, reflecting the
|
|
80
|
-
* constraints of the underlying JavaScript WeakMap it uses internally. But
|
|
81
|
-
*
|
|
96
|
+
* constraints of the underlying JavaScript WeakMap it uses internally. But it
|
|
97
|
+
* should accept the primitives as well, storing them in a separate internal
|
|
82
98
|
* map. What makes it "weak" is that it provides no API for enumerating what's
|
|
83
|
-
* there. Though note that this would only enables collection of the
|
|
84
|
-
*
|
|
99
|
+
* there. Though note that this would only enables collection of the remotables,
|
|
100
|
+
* since the other primitives may always reappear.
|
|
85
101
|
*
|
|
86
102
|
* @template K,V
|
|
87
|
-
* @param {string} [tag
|
|
103
|
+
* @param {string} [tag] - tag for debugging
|
|
88
104
|
* @param {StoreOptions} [options]
|
|
89
|
-
* @returns {WeakMapStore<K,V>}
|
|
105
|
+
* @returns {RemotableObject & WeakMapStore<K, V>}
|
|
90
106
|
*/
|
|
91
107
|
export const makeScalarWeakMapStore = (
|
|
92
108
|
tag = 'key',
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import { Far, passStyleOf } from '@endo/pass-style';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
getCopySetKeys,
|
|
4
|
+
mustMatch,
|
|
5
|
+
assertPattern,
|
|
6
|
+
isCopySet,
|
|
7
|
+
} from '@endo/patterns';
|
|
4
8
|
|
|
5
9
|
const { quote: q, Fail } = assert;
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
|
-
* @
|
|
12
|
+
* @import {Key} from '@endo/patterns';
|
|
13
|
+
* @import {StoreOptions, WeakSetStore, WeakSetStoreMethods} from '@agoric/store';
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @template {Key} K
|
|
9
18
|
* @param {WeakSet<K & object>} jsset
|
|
10
19
|
* @param {(k: K) => void} assertKeyOkToAdd
|
|
11
20
|
* @param {(k: K) => void} [assertKeyOkToDelete]
|
|
12
21
|
* @param {string} [keyName]
|
|
13
|
-
* @returns {
|
|
22
|
+
* @returns {WeakSetStoreMethods<K>}
|
|
14
23
|
*/
|
|
15
24
|
export const makeWeakSetStoreMethods = (
|
|
16
25
|
jsset,
|
|
@@ -42,8 +51,13 @@ export const makeWeakSetStoreMethods = (
|
|
|
42
51
|
},
|
|
43
52
|
|
|
44
53
|
addAll: keys => {
|
|
45
|
-
if (
|
|
46
|
-
keys
|
|
54
|
+
if (typeof keys[Symbol.iterator] !== 'function') {
|
|
55
|
+
if (Object.isFrozen(keys) && isCopySet(keys)) {
|
|
56
|
+
// @ts-expect-error XXX
|
|
57
|
+
keys = getCopySetKeys(keys);
|
|
58
|
+
} else {
|
|
59
|
+
Fail`provided data source is not iterable: ${keys}`;
|
|
60
|
+
}
|
|
47
61
|
}
|
|
48
62
|
for (const key of /** @type {Iterable<K>} */ (keys)) {
|
|
49
63
|
assertKeyOkToAdd(key);
|
|
@@ -54,19 +68,19 @@ export const makeWeakSetStoreMethods = (
|
|
|
54
68
|
};
|
|
55
69
|
|
|
56
70
|
/**
|
|
57
|
-
* This is a
|
|
71
|
+
* This is a _scalar_ set in that the keys can only be atomic values, primitives
|
|
58
72
|
* or remotables. Other storeSets will accept, for example, copyArrays and
|
|
59
73
|
* copyRecords, as keys and look them up based on equality of their contents.
|
|
60
74
|
*
|
|
61
75
|
* TODO For now, this scalarWeakSet accepts only remotables, reflecting the
|
|
62
|
-
* constraints of the underlying JavaScript WeakSet it uses internally. But
|
|
63
|
-
*
|
|
76
|
+
* constraints of the underlying JavaScript WeakSet it uses internally. But it
|
|
77
|
+
* should accept the primitives as well, storing them in a separate internal
|
|
64
78
|
* set. What makes it "weak" is that it provides no API for enumerating what's
|
|
65
|
-
* there. Though note that this would only enables collection of the
|
|
66
|
-
*
|
|
79
|
+
* there. Though note that this would only enables collection of the remotables,
|
|
80
|
+
* since the other primitives may always appear.
|
|
67
81
|
*
|
|
68
82
|
* @template K
|
|
69
|
-
* @param {string} [tag
|
|
83
|
+
* @param {string} [tag] - tag for debugging
|
|
70
84
|
* @param {StoreOptions} [options]
|
|
71
85
|
* @returns {WeakSetStore<K>}
|
|
72
86
|
*/
|