@agoric/store 0.9.3-u14.0 → 0.9.3-u17.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 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
- # External Store
26
-
27
- An External Store is defined by its maker function, and provides abstractions
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
- import './src/types.js';
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-u14.0",
3
+ "version": "0.9.3-u17.0",
4
4
  "description": "Wrapper for JavaScript map",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "engines": {
8
- "node": ">=14.15.0"
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 -p jsconfig.json",
16
+ "lint:types": "tsc",
17
17
  "lint:eslint": "eslint ."
18
18
  },
19
19
  "repository": {
@@ -30,17 +30,16 @@
30
30
  },
31
31
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
32
32
  "dependencies": {
33
- "@agoric/assert": "^0.6.1-u11wf.0",
34
- "@endo/exo": "0.2.2",
35
- "@endo/marshal": "0.8.5",
36
- "@endo/pass-style": "0.1.3",
37
- "@endo/patterns": "0.2.2"
33
+ "@endo/errors": "^1.2.5",
34
+ "@endo/exo": "^1.5.3",
35
+ "@endo/marshal": "^1.5.3",
36
+ "@endo/pass-style": "^1.4.3",
37
+ "@endo/patterns": "^1.4.3"
38
38
  },
39
39
  "devDependencies": {
40
- "@agoric/swingset-vat": "^0.32.3-u14.0",
41
- "@agoric/time": "^0.3.3-u14.0",
42
- "@endo/ses-ava": "0.2.40",
43
- "ava": "^5.2.0"
40
+ "@endo/init": "^1.1.4",
41
+ "@endo/ses-ava": "^1.2.5",
42
+ "ava": "^5.3.0"
44
43
  },
45
44
  "files": [
46
45
  "src/",
@@ -52,9 +51,15 @@
52
51
  },
53
52
  "ava": {
54
53
  "files": [
55
- "test/**/test-*.js"
54
+ "test/**/*.test.*"
55
+ ],
56
+ "require": [
57
+ "@endo/init/debug.js"
56
58
  ],
57
59
  "timeout": "2m"
58
60
  },
59
- "gitHead": "b3a6f3374cb3bddab39fc6d6f426429cae6c29c6"
61
+ "typeCoverage": {
62
+ "atLeast": 89.53
63
+ },
64
+ "gitHead": "515c4c0efccfc91b97da30037c10fc4b076851e2"
60
65
  }
package/src/index.js CHANGED
@@ -1,3 +1,18 @@
1
+ /**
2
+ * @import {MustMatch} from '@agoric/internal';
3
+ */
4
+ import { mustMatch as typelessMustMatch } from '@endo/patterns';
5
+
6
+ export { makeScalarWeakSetStore } from './stores/scalarWeakSetStore.js';
7
+ export { makeScalarSetStore } from './stores/scalarSetStore.js';
8
+ export { makeScalarWeakMapStore } from './stores/scalarWeakMapStore.js';
9
+ export { makeScalarMapStore } from './stores/scalarMapStore.js';
10
+
11
+ export { provideLazy } from './stores/store-utils.js';
12
+
13
+ // /////////////////////// Deprecated Re-exports ///////////////////////////////
14
+ // Importers should import directly from the packages shown below
15
+
1
16
  export {
2
17
  isKey,
3
18
  assertKey,
@@ -41,9 +56,15 @@ export {
41
56
  isPattern,
42
57
  assertPattern,
43
58
  matches,
44
- mustMatch,
59
+ isCopySet,
60
+ isCopyMap,
45
61
  } from '@endo/patterns';
46
62
 
63
+ // XXX @agoric/store should not depend on @agoric/internal
64
+ // TODO move to Endo
65
+ /** @type {MustMatch} */
66
+ export const mustMatch = typelessMustMatch;
67
+
47
68
  export {
48
69
  initEmpty,
49
70
  defineExoClass,
@@ -51,14 +72,9 @@ export {
51
72
  makeExo,
52
73
  } from '@endo/exo';
53
74
 
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
75
  // /////////////////////// Deprecated Legacy ///////////////////////////////////
62
76
 
63
77
  export { makeLegacyMap } from './legacy/legacyMap.js';
64
78
  export { makeLegacyWeakMap } from './legacy/legacyWeakMap.js';
79
+ // eslint-disable-next-line import/export
80
+ export * from './types.js';
@@ -1,37 +1,40 @@
1
- import { q, Fail } from '@agoric/assert';
1
+ /** @import {LegacyMap, LegacyWeakMap} from '../types.js'; */
2
2
 
3
- import '../types.js';
3
+ // TODO, once migrated to endo, import from @endo/errors instead
4
+ import { Fail, q } from '@endo/errors';
4
5
 
5
6
  /**
6
- * This module and its fraternal sibling legacyWeakMap exist only to
7
- * ease a transition to the modern `store` system, are deprecated,
8
- * and will eventually disappear. They are needed for now to support
9
- * some of the uses of the old behavior that are not compatible with
10
- * the new. The constraint imposed by the new is that only passables can
11
- * be used as values, and only keys (roughly, structures, aka comparables)
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
- * comment explaining the problem inhibiting conversion to the new
22
- * system. Some of these problems as of this writing:
23
- * * A promiseKit used as a value, even though a promiseKit is not
24
- * a passable. Solutions are to make it a passable, or to convert
25
- * the container back to a conventional JavaScript Map.
26
- * * A mutable array used as a value, that is subsequently mutated.
27
- * Freezing the array wouldn't work of course because it would break
28
- * the subsequent mutation. Using a far object wrapping an array would
29
- * likely work fine.
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='key'] - tag for debugging
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 { q, Fail } from '@agoric/assert';
2
- import '../types.js';
1
+ /** @import {LegacyWeakMap} from '../types.js'; */
2
+
3
+ // TODO, once migrated to endo, import from @endo/errors instead
4
+ import { Fail, q } from '@endo/errors';
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='key'] - tag for debugging
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>} */
@@ -1,3 +1,4 @@
1
+ import { q } from '@endo/errors';
1
2
  import {
2
3
  Far,
3
4
  assertPassable,
@@ -15,17 +16,21 @@ import {
15
16
  import { makeWeakMapStoreMethods } from './scalarWeakMapStore.js';
16
17
  import { makeCurrentKeysKit } from './store-utils.js';
17
18
 
18
- const { quote: q } = assert;
19
+ /**
20
+ * @import {Passable} from '@endo/pass-style';
21
+ * @import {Key, Pattern} from '@endo/patterns';
22
+ * @import {MapStore, MapStoreMethods, StoreOptions} from '../types.js';
23
+ */
19
24
 
20
25
  /**
21
26
  * @template {Key} K
22
27
  * @template {Passable} V
23
- * @param {Map<K,V>} jsmap
28
+ * @param {Map<K, V>} jsmap
24
29
  * @param {(k: K, v: V) => void} assertKVOkToAdd
25
30
  * @param {(k: K, v: V) => void} assertKVOkToSet
26
- * @param {((k: K) => void)} [assertKeyOkToDelete]
31
+ * @param {(k: K) => void} [assertKeyOkToDelete]
27
32
  * @param {string} [tag]
28
- * @returns {MapStore<K,V>}
33
+ * @returns {MapStoreMethods<K, V>}
29
34
  */
30
35
  export const makeMapStoreMethods = (
31
36
  jsmap,
@@ -77,7 +82,7 @@ export const makeMapStoreMethods = (
77
82
  /**
78
83
  * @param {Pattern} [keyPatt]
79
84
  * @param {Pattern} [valuePatt]
80
- * @returns {Iterable<[K,V]>}
85
+ * @returns {Iterable<[K, V]>}
81
86
  */
82
87
  const entries = (keyPatt = undefined, valuePatt = undefined) =>
83
88
  mapIterable(keys(keyPatt, valuePatt), k => [
@@ -117,21 +122,19 @@ export const makeMapStoreMethods = (
117
122
  };
118
123
 
119
124
  /**
120
- * Distinguishes between adding a new key (init) and updating or
121
- * referencing a key (get, set, delete).
125
+ * Distinguishes between adding a new key (init) and updating or referencing a
126
+ * key (get, set, delete).
122
127
  *
123
- * `init` is only allowed if the key does not already exist. `Get`,
124
- * `set` and `delete` are only allowed if the key does already exist.
128
+ * `init` is only allowed if the key does not already exist. `Get`, `set` and
129
+ * `delete` are only allowed if the key does already exist.
125
130
  *
126
- * This is a *scalar* map in that the keys can only be atomic values, primitives
131
+ * This is a _scalar_ map in that the keys can only be atomic values, primitives
127
132
  * or remotables. Other storeMaps will accept, for example, copyArrays and
128
133
  * copyRecords, as keys and look them up based on equality of their contents.
129
134
  *
130
- * @template {Key} K
131
- * @template {Passable} V
132
- * @param {string} [tag='key'] - the column name for the key
135
+ * @param {string} [tag] - the column name for the key
133
136
  * @param {StoreOptions} [options]
134
- * @returns {MapStore<K,V>}
137
+ * @returns {MapStore<any, any>}
135
138
  */
136
139
  export const makeScalarMapStore = (
137
140
  tag = 'key',
@@ -1,3 +1,4 @@
1
+ import { q } from '@endo/errors';
1
2
  import { Far, filterIterable } from '@endo/pass-style';
2
3
  import { compareRank } from '@endo/marshal';
3
4
  import {
@@ -10,15 +11,18 @@ import {
10
11
  import { makeWeakSetStoreMethods } from './scalarWeakSetStore.js';
11
12
  import { makeCurrentKeysKit } from './store-utils.js';
12
13
 
13
- const { quote: q } = assert;
14
+ /**
15
+ * @import {Key, Pattern} from '@endo/patterns';
16
+ * @import {SetStore, SetStoreMethods, StoreOptions} from '../types.js';
17
+ */
14
18
 
15
19
  /**
16
- * @template K
20
+ * @template {Key} K
17
21
  * @param {Set<K>} jsset
18
22
  * @param {(k: K) => void} assertKeyOkToAdd
19
23
  * @param {(k: K) => void} [assertKeyOkToDelete]
20
24
  * @param {string} [keyName]
21
- * @returns {SetStore<K>}
25
+ * @returns {SetStoreMethods<K>}
22
26
  */
23
27
  export const makeSetStoreMethods = (
24
28
  jsset,
@@ -74,18 +78,18 @@ export const makeSetStoreMethods = (
74
78
  };
75
79
 
76
80
  /**
77
- * Distinguishes between adding a new key (init) and updating or
78
- * referencing a key (get, set, delete).
81
+ * Distinguishes between adding a new key (init) and updating or referencing a
82
+ * key (get, set, delete).
79
83
  *
80
- * `init` is only allowed if the key does not already exist. `Get`,
81
- * `set` and `delete` are only allowed if the key does already exist.
84
+ * `init` is only allowed if the key does not already exist. `Get`, `set` and
85
+ * `delete` are only allowed if the key does already exist.
82
86
  *
83
- * This is a *scalar* set in that the keys can only be atomic values, primitives
87
+ * This is a _scalar_ set in that the keys can only be atomic values, primitives
84
88
  * or remotables. Other storeSets will accept, for example, copyArrays and
85
89
  * copyRecords, as keys and look them up based on equality of their contents.
86
90
  *
87
91
  * @template K
88
- * @param {string} [tag='key'] - tag for debugging
92
+ * @param {string} [tag] - tag for debugging
89
93
  * @param {StoreOptions} [options]
90
94
  * @returns {SetStore<K>}
91
95
  */
@@ -1,17 +1,27 @@
1
+ import { q, Fail } from '@endo/errors';
1
2
  import { Far, assertPassable, passStyleOf } from '@endo/pass-style';
2
- import { getCopyMapEntries, mustMatch, assertPattern } from '@endo/patterns';
3
- import { isCopyMap } from './store-utils.js';
3
+ import {
4
+ getCopyMapEntries,
5
+ mustMatch,
6
+ assertPattern,
7
+ isCopyMap,
8
+ } from '@endo/patterns';
4
9
 
5
- const { quote: q, Fail } = assert;
10
+ /**
11
+ * @import {Key} from '@endo/patterns';
12
+ * @import {Passable, RemotableObject} from '@endo/pass-style';
13
+ * @import {WeakMapStore, StoreOptions} from '../types.js';
14
+ */
6
15
 
7
16
  /**
8
- * @template K,V
17
+ * @template {Key} K
18
+ * @template {Passable} V
9
19
  * @param {WeakMap<K & object, V>} jsmap
10
20
  * @param {(k: K, v: V) => void} assertKVOkToAdd
11
21
  * @param {(k: K, v: V) => void} assertKVOkToSet
12
22
  * @param {(k: K) => void} [assertKeyOkToDelete]
13
23
  * @param {string} [keyName]
14
- * @returns {WeakMapStore<K,V>}
24
+ * @returns {WeakMapStore<K, V>}
15
25
  */
16
26
  export const makeWeakMapStoreMethods = (
17
27
  jsmap,
@@ -58,8 +68,13 @@ export const makeWeakMapStoreMethods = (
58
68
  },
59
69
 
60
70
  addAll: entries => {
61
- if (isCopyMap(entries)) {
62
- entries = getCopyMapEntries(entries);
71
+ if (typeof entries[Symbol.iterator] !== 'function') {
72
+ if (Object.isFrozen(entries) && isCopyMap(entries)) {
73
+ // @ts-expect-error XXX
74
+ entries = getCopyMapEntries(entries);
75
+ } else {
76
+ Fail`provided data source is not iterable: ${entries}`;
77
+ }
63
78
  }
64
79
  for (const [key, value] of /** @type {Iterable<[K, V]>} */ (entries)) {
65
80
  // Don't assert that the key either does or does not exist.
@@ -71,22 +86,22 @@ export const makeWeakMapStoreMethods = (
71
86
  };
72
87
 
73
88
  /**
74
- * This is a *scalar* mapStore in that the keys can only be atomic values:
75
- * primitives or remotables.
76
- * Other mapStores will accept, for example, copyArrays and
77
- * copyRecords as keys and look them up based on equality of their contents.
89
+ * This is a _scalar_ mapStore in that the keys can only be atomic values:
90
+ * primitives or remotables. Other mapStores will accept, for example,
91
+ * copyArrays and copyRecords as keys and look them up based on equality of
92
+ * their contents.
78
93
  *
79
94
  * TODO For now, this scalarWeakMap accepts only remotables, reflecting the
80
- * constraints of the underlying JavaScript WeakMap it uses internally. But
81
- * it should accept the primitives as well, storing them in a separate internal
95
+ * constraints of the underlying JavaScript WeakMap it uses internally. But it
96
+ * should accept the primitives as well, storing them in a separate internal
82
97
  * 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
- * remotables, since the other primitives may always reappear.
98
+ * there. Though note that this would only enables collection of the remotables,
99
+ * since the other primitives may always reappear.
85
100
  *
86
101
  * @template K,V
87
- * @param {string} [tag='key'] - tag for debugging
102
+ * @param {string} [tag] - tag for debugging
88
103
  * @param {StoreOptions} [options]
89
- * @returns {WeakMapStore<K,V>}
104
+ * @returns {RemotableObject & WeakMapStore<K, V>}
90
105
  */
91
106
  export const makeScalarWeakMapStore = (
92
107
  tag = 'key',
@@ -1,16 +1,24 @@
1
+ import { q, Fail } from '@endo/errors';
1
2
  import { Far, passStyleOf } from '@endo/pass-style';
2
- import { getCopySetKeys, mustMatch, assertPattern } from '@endo/patterns';
3
- import { isCopySet } from './store-utils.js';
3
+ import {
4
+ getCopySetKeys,
5
+ mustMatch,
6
+ assertPattern,
7
+ isCopySet,
8
+ } from '@endo/patterns';
4
9
 
5
- const { quote: q, Fail } = assert;
10
+ /**
11
+ * @import {Key} from '@endo/patterns';
12
+ * @import {StoreOptions, WeakSetStore, WeakSetStoreMethods} from '@agoric/store';
13
+ */
6
14
 
7
15
  /**
8
- * @template K
16
+ * @template {Key} K
9
17
  * @param {WeakSet<K & object>} jsset
10
18
  * @param {(k: K) => void} assertKeyOkToAdd
11
19
  * @param {(k: K) => void} [assertKeyOkToDelete]
12
20
  * @param {string} [keyName]
13
- * @returns {WeakSetStore<K>}
21
+ * @returns {WeakSetStoreMethods<K>}
14
22
  */
15
23
  export const makeWeakSetStoreMethods = (
16
24
  jsset,
@@ -42,8 +50,13 @@ export const makeWeakSetStoreMethods = (
42
50
  },
43
51
 
44
52
  addAll: keys => {
45
- if (isCopySet(keys)) {
46
- keys = getCopySetKeys(keys);
53
+ if (typeof keys[Symbol.iterator] !== 'function') {
54
+ if (Object.isFrozen(keys) && isCopySet(keys)) {
55
+ // @ts-expect-error XXX
56
+ keys = getCopySetKeys(keys);
57
+ } else {
58
+ Fail`provided data source is not iterable: ${keys}`;
59
+ }
47
60
  }
48
61
  for (const key of /** @type {Iterable<K>} */ (keys)) {
49
62
  assertKeyOkToAdd(key);
@@ -54,19 +67,19 @@ export const makeWeakSetStoreMethods = (
54
67
  };
55
68
 
56
69
  /**
57
- * This is a *scalar* set in that the keys can only be atomic values, primitives
70
+ * This is a _scalar_ set in that the keys can only be atomic values, primitives
58
71
  * or remotables. Other storeSets will accept, for example, copyArrays and
59
72
  * copyRecords, as keys and look them up based on equality of their contents.
60
73
  *
61
74
  * TODO For now, this scalarWeakSet accepts only remotables, reflecting the
62
- * constraints of the underlying JavaScript WeakSet it uses internally. But
63
- * it should accept the primitives as well, storing them in a separate internal
75
+ * constraints of the underlying JavaScript WeakSet it uses internally. But it
76
+ * should accept the primitives as well, storing them in a separate internal
64
77
  * 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
- * remotables, since the other primitives may always appear.
78
+ * there. Though note that this would only enables collection of the remotables,
79
+ * since the other primitives may always appear.
67
80
  *
68
81
  * @template K
69
- * @param {string} [tag='key'] - tag for debugging
82
+ * @param {string} [tag] - tag for debugging
70
83
  * @param {StoreOptions} [options]
71
84
  * @returns {WeakSetStore<K>}
72
85
  */