@agoric/cache 0.3.3-other-dev-8f8782b.0 → 0.3.3-other-dev-fbe72e7.0.fbe72e7
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 +0 -8
- package/package.json +23 -17
- package/src/cache.js +8 -3
- package/src/main.js +1 -0
- package/src/state.js +1 -1
- package/src/store.js +20 -16
- package/src/types.js +7 -3
- package/test/{test-storage.js → storage.test.js} +11 -10
- package/{jsconfig.json → tsconfig.json} +1 -0
- /package/test/{test-mvp.js → mvp.test.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,14 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
### [0.3.3-u11.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.3.2...@agoric/cache@0.3.3-u11.0) (2023-08-24)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @agoric/cache
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
6
|
### [0.3.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.3.1...@agoric/cache@0.3.2) (2023-06-02)
|
|
15
7
|
|
|
16
8
|
**Note:** Version bump only for package @agoric/cache
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/cache",
|
|
3
|
-
"version": "0.3.3-other-dev-
|
|
3
|
+
"version": "0.3.3-other-dev-fbe72e7.0.fbe72e7",
|
|
4
4
|
"description": "Agoric's simple cache interface",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/main.js",
|
|
@@ -8,40 +8,46 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "exit 0",
|
|
10
10
|
"test": "ava",
|
|
11
|
-
"test:c8": "c8 $C8_OPTIONS ava
|
|
11
|
+
"test:c8": "c8 --all ${C8_OPTIONS:-} ava",
|
|
12
12
|
"test:xs": "exit 0",
|
|
13
13
|
"lint-fix": "yarn lint:eslint --fix",
|
|
14
|
-
"lint": "run-s --continue-on-error lint:*",
|
|
15
|
-
"lint:types": "
|
|
16
|
-
"lint:eslint": "
|
|
14
|
+
"lint": "yarn run -T run-s --continue-on-error 'lint:*'",
|
|
15
|
+
"lint:types": "yarn run -T tsc",
|
|
16
|
+
"lint:eslint": "yarn run -T eslint ."
|
|
17
17
|
},
|
|
18
18
|
"keywords": [],
|
|
19
19
|
"author": "Agoric",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@agoric/internal": "0.3.3-other-dev-
|
|
23
|
-
"@agoric/notifier": "0.6.3-other-dev-
|
|
24
|
-
"@agoric/store": "0.9.3-other-dev-
|
|
25
|
-
"@agoric/vat-data": "0.5.3-other-dev-
|
|
26
|
-
"@endo/far": "
|
|
27
|
-
"@endo/marshal": "
|
|
22
|
+
"@agoric/internal": "0.3.3-other-dev-fbe72e7.0.fbe72e7",
|
|
23
|
+
"@agoric/notifier": "0.6.3-other-dev-fbe72e7.0.fbe72e7",
|
|
24
|
+
"@agoric/store": "0.9.3-other-dev-fbe72e7.0.fbe72e7",
|
|
25
|
+
"@agoric/vat-data": "0.5.3-other-dev-fbe72e7.0.fbe72e7",
|
|
26
|
+
"@endo/far": "^1.1.14",
|
|
27
|
+
"@endo/marshal": "^1.8.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@agoric/zoe": "0.26.3-other-dev-
|
|
31
|
-
"ava": "^5.
|
|
32
|
-
"c8": "^
|
|
30
|
+
"@agoric/zoe": "0.26.3-other-dev-fbe72e7.0.fbe72e7",
|
|
31
|
+
"ava": "^5.3.0",
|
|
32
|
+
"c8": "^10.1.3"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
|
-
"node": "
|
|
38
|
+
"node": "^20.9 || ^22.11"
|
|
39
39
|
},
|
|
40
40
|
"ava": {
|
|
41
41
|
"files": [
|
|
42
|
-
"test
|
|
42
|
+
"test/**/*.test.*"
|
|
43
|
+
],
|
|
44
|
+
"require": [
|
|
45
|
+
"@endo/init/debug.js"
|
|
43
46
|
],
|
|
44
47
|
"timeout": "20m"
|
|
45
48
|
},
|
|
46
|
-
"
|
|
49
|
+
"typeCoverage": {
|
|
50
|
+
"atLeast": 94.13
|
|
51
|
+
},
|
|
52
|
+
"gitHead": "fbe72e72107f9997f788674e668c660d92ec4492"
|
|
47
53
|
}
|
package/src/cache.js
CHANGED
|
@@ -4,22 +4,27 @@ import { E, Far } from '@endo/far';
|
|
|
4
4
|
|
|
5
5
|
import { makeScalarStoreCoordinator } from './store.js';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @import {Passable, RemotableObject} from '@endo/pass-style';
|
|
9
|
+
* @import {Key, Pattern} from '@endo/patterns';
|
|
10
|
+
*/
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* @typedef {{ [x: PropertyKey]: any } | string | symbol | bigint | null |
|
|
9
|
-
* undefined | number | ((oldValue: any) => ERef<
|
|
14
|
+
* undefined | number | ((oldValue: any) => ERef<Passable>)} Update a `newValue`
|
|
10
15
|
* to update to. If a function, then it should take an oldValue and return a
|
|
11
16
|
* `newValue` or promise for `newValue`
|
|
12
17
|
*/
|
|
13
18
|
|
|
14
19
|
/**
|
|
15
|
-
* @param {ERef<import('./types').Coordinator>} [coordinator]
|
|
20
|
+
* @param {ERef<import('./types.js').Coordinator>} [coordinator]
|
|
16
21
|
*/
|
|
17
22
|
export const makeCache = (coordinator = makeScalarStoreCoordinator()) => {
|
|
18
23
|
/**
|
|
19
24
|
* The ground state for a cache key value is `undefined`. It is impossible to
|
|
20
25
|
* distinguish a set value of `undefined` from an unset key
|
|
21
26
|
*
|
|
22
|
-
* @param {
|
|
27
|
+
* @param {Passable} key the cache key (any key type acceptable to the cache)
|
|
23
28
|
* @param {[] | [Update] | [Update, Pattern]} optUpdateGuardPattern an optional
|
|
24
29
|
*/
|
|
25
30
|
const cache = (key, ...optUpdateGuardPattern) => {
|
package/src/main.js
CHANGED
package/src/state.js
CHANGED
|
@@ -30,7 +30,7 @@ export const makeState = (value, priorState = GROUND_STATE) =>
|
|
|
30
30
|
/**
|
|
31
31
|
* Wrap a state store to have a default value using the GROUND_STATE
|
|
32
32
|
*
|
|
33
|
-
* @param {MapStore<string, import('./state').State>} stateStore
|
|
33
|
+
* @param {MapStore<string, import('./state.js').State>} stateStore
|
|
34
34
|
*/
|
|
35
35
|
export const withGroundState = stateStore => ({
|
|
36
36
|
...stateStore,
|
package/src/store.js
CHANGED
|
@@ -5,10 +5,13 @@ import { makeScalarBigMapStore } from '@agoric/vat-data';
|
|
|
5
5
|
import { untilTrue } from '@agoric/internal';
|
|
6
6
|
import { withGroundState, makeState } from './state.js';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @import {Passable, RemotableObject} from '@endo/pass-style';
|
|
10
|
+
* @import {Key, Pattern} from '@endo/patterns';
|
|
11
|
+
*/
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
|
-
* @param {(obj:
|
|
14
|
+
* @param {(obj: Passable) => Passable} [sanitize]
|
|
12
15
|
* @returns {(key: Passable) => Promise<string>}
|
|
13
16
|
*/
|
|
14
17
|
const makeKeyToString = (sanitize = obj => obj) => {
|
|
@@ -37,16 +40,16 @@ const makeKeyToString = (sanitize = obj => obj) => {
|
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* @param {string} keyStr
|
|
40
|
-
* @param {(oldValue:
|
|
43
|
+
* @param {(oldValue: Passable) => Passable} txn
|
|
41
44
|
* @param {Pattern} guardPattern
|
|
42
|
-
* @param {(obj:
|
|
45
|
+
* @param {(obj: Passable) => Passable} sanitize Process keys and values with
|
|
43
46
|
* this function before storing them
|
|
44
47
|
* @param {{
|
|
45
|
-
* get(key: string): import('./state').State;
|
|
46
|
-
* set(key: string, value: import('./state').State): void;
|
|
47
|
-
* init(key: string, value: import('./state').State): void;
|
|
48
|
+
* get(key: string): import('./state.js').State;
|
|
49
|
+
* set(key: string, value: import('./state.js').State): void;
|
|
50
|
+
* init(key: string, value: import('./state.js').State): void;
|
|
48
51
|
* }} stateStore
|
|
49
|
-
* @returns {Promise<
|
|
52
|
+
* @returns {Promise<Passable>} the value of the updated state
|
|
50
53
|
*/
|
|
51
54
|
const applyCacheTransaction = async (
|
|
52
55
|
keyStr,
|
|
@@ -58,8 +61,8 @@ const applyCacheTransaction = async (
|
|
|
58
61
|
/**
|
|
59
62
|
* Retrieve a potential updated state from the transaction.
|
|
60
63
|
*
|
|
61
|
-
* @param {import('./state').State} basisState
|
|
62
|
-
* @returns {Promise<import('./state').State | null>} the updated state, or null if no longer applicable
|
|
64
|
+
* @param {import('./state.js').State} basisState
|
|
65
|
+
* @returns {Promise<import('./state.js').State | null>} the updated state, or null if no longer applicable
|
|
63
66
|
*/
|
|
64
67
|
const getUpdatedState = async basisState => {
|
|
65
68
|
const { value } = basisState;
|
|
@@ -108,11 +111,12 @@ const applyCacheTransaction = async (
|
|
|
108
111
|
};
|
|
109
112
|
|
|
110
113
|
/**
|
|
111
|
-
* @param {MapStore<string, import('./state').State>} stateStore
|
|
114
|
+
* @param {MapStore<string, import('./state.js').State>} stateStore
|
|
112
115
|
* @param {ERef<Marshaller>} marshaller
|
|
113
116
|
* @returns {Promise<string>}
|
|
114
117
|
*/
|
|
115
118
|
const stringifyStateStore = async (stateStore, marshaller) => {
|
|
119
|
+
/** @type {Passable} */
|
|
116
120
|
const obj = {};
|
|
117
121
|
for (const [key, value] of stateStore.entries()) {
|
|
118
122
|
obj[key] = E(marshaller).toCapData(value);
|
|
@@ -126,8 +130,8 @@ const stringifyStateStore = async (stateStore, marshaller) => {
|
|
|
126
130
|
* Make a cache coordinator backed by a MapStore. This coordinator doesn't
|
|
127
131
|
* currently enforce any cache eviction, but that would be a useful feature.
|
|
128
132
|
*
|
|
129
|
-
* @param {MapStore<string, import('./state').State>} [stateStore]
|
|
130
|
-
* @param {(obj:
|
|
133
|
+
* @param {MapStore<string, import('./state.js').State>} [stateStore]
|
|
134
|
+
* @param {(obj: Passable) => Passable} [sanitize] Process keys and values with
|
|
131
135
|
* this function before storing them. Defaults to deeplyFulfilled.
|
|
132
136
|
*/
|
|
133
137
|
export const makeScalarStoreCoordinator = (
|
|
@@ -138,7 +142,7 @@ export const makeScalarStoreCoordinator = (
|
|
|
138
142
|
|
|
139
143
|
const defaultStateStore = withGroundState(stateStore);
|
|
140
144
|
|
|
141
|
-
/** @type {import('./types').Coordinator} */
|
|
145
|
+
/** @type {import('./types.js').Coordinator} */
|
|
142
146
|
const coord = Far('store cache coordinator', {
|
|
143
147
|
getRecentValue: async key => {
|
|
144
148
|
const keyStr = await serializePassable(key);
|
|
@@ -171,7 +175,7 @@ export const makeScalarStoreCoordinator = (
|
|
|
171
175
|
/**
|
|
172
176
|
* Don't write any marshalled value that's older than what's already pushed
|
|
173
177
|
*
|
|
174
|
-
* @param {MapStore<string, import('./state').State>} stateStore
|
|
178
|
+
* @param {MapStore<string, import('./state.js').State>} stateStore
|
|
175
179
|
* @param {ERef<Marshaller>} marshaller
|
|
176
180
|
* @param {ERef<StorageNode>} storageNode
|
|
177
181
|
* @returns {<T>(storedValue: T) => Promise<T>}
|
|
@@ -218,7 +222,7 @@ export const makeChainStorageCoordinator = (storageNode, marshaller) => {
|
|
|
218
222
|
storageNode,
|
|
219
223
|
);
|
|
220
224
|
|
|
221
|
-
/** @type {import('./types').Coordinator} */
|
|
225
|
+
/** @type {import('./types.js').Coordinator} */
|
|
222
226
|
const coord = Far('store cache coordinator', {
|
|
223
227
|
getRecentValue: async key => {
|
|
224
228
|
const keyStr = await serializePassable(key);
|
package/src/types.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
|
+
/// <reference types="@agoric/store/exported.js" />
|
|
4
|
+
|
|
3
5
|
// XXX package factoring debt
|
|
4
|
-
import '@agoric/notifier/exported.js';
|
|
5
|
-
import '@agoric/store/exported.js';
|
|
6
6
|
|
|
7
7
|
// Ensure this is a module.
|
|
8
8
|
export {};
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* @import { ERef } from '@endo/far'
|
|
12
|
+
* @import {Passable} from '@endo/pass-style'
|
|
13
|
+
* @import {Key, Pattern} from '@endo/patterns';
|
|
14
|
+
*/
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* @typedef {object} Updater
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// Must be first to set up globals
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- XXX
|
|
4
|
-
import '@agoric/swingset-vat/tools/prepare-test-env.js';
|
|
2
|
+
import '@agoric/zoe/tools/prepare-test-env.js';
|
|
5
3
|
|
|
6
4
|
import test from 'ava';
|
|
7
5
|
import { makeChainStorageRoot } from '@agoric/internal/src/lib-chainStorage.js';
|
|
@@ -29,13 +27,16 @@ harden(makeSimpleMarshaller);
|
|
|
29
27
|
|
|
30
28
|
const setup = () => {
|
|
31
29
|
const storageNodeState = {};
|
|
32
|
-
const chainStorage = makeChainStorageRoot(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
const chainStorage = makeChainStorageRoot(
|
|
31
|
+
Far('ToStorage', message => {
|
|
32
|
+
assert(message.method === 'set');
|
|
33
|
+
assert(message.args.length === 1);
|
|
34
|
+
const [[path, value]] = message.args;
|
|
35
|
+
assert(path === 'cache');
|
|
36
|
+
storageNodeState.cache = value;
|
|
37
|
+
}),
|
|
38
|
+
'cache',
|
|
39
|
+
);
|
|
39
40
|
const cache = makeCache(
|
|
40
41
|
makeChainStorageCoordinator(chainStorage, makeSimpleMarshaller()),
|
|
41
42
|
);
|
|
File without changes
|