@agoric/cache 0.4.0 → 0.4.1-upgrade-23-dev-bd79330.0.bd79330

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/cache",
3
- "version": "0.4.0",
3
+ "version": "0.4.1-upgrade-23-dev-bd79330.0.bd79330",
4
4
  "description": "Agoric's simple cache interface",
5
5
  "type": "module",
6
6
  "main": "src/main.js",
@@ -13,24 +13,27 @@
13
13
  "lint-fix": "yarn lint:eslint --fix",
14
14
  "lint": "yarn run -T run-s --continue-on-error 'lint:*'",
15
15
  "lint:types": "yarn run -T tsc",
16
- "lint:eslint": "yarn run -T eslint ."
16
+ "lint:eslint": "node ../../scripts/eslint-repo.mjs ."
17
17
  },
18
18
  "keywords": [],
19
19
  "author": "Agoric",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@agoric/internal": "0.4.0",
23
- "@agoric/notifier": "0.7.0",
24
- "@agoric/store": "0.10.0",
25
- "@agoric/vat-data": "0.6.0",
22
+ "@agoric/internal": "0.4.1-upgrade-23-dev-bd79330.0.bd79330",
23
+ "@agoric/notifier": "0.7.1-upgrade-23-dev-bd79330.0.bd79330",
24
+ "@agoric/store": "0.10.1-upgrade-23-dev-bd79330.0.bd79330",
25
+ "@agoric/vat-data": "0.6.1-upgrade-23-dev-bd79330.0.bd79330",
26
26
  "@endo/far": "^1.1.14",
27
27
  "@endo/marshal": "^1.8.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@agoric/zoe": "0.27.0",
31
- "ava": "^5.3.0",
30
+ "@agoric/zoe": "0.27.1-upgrade-23-dev-bd79330.0.bd79330",
31
+ "ava": "^6.4.1",
32
32
  "c8": "^10.1.3"
33
33
  },
34
+ "files": [
35
+ "src"
36
+ ],
34
37
  "publishConfig": {
35
38
  "access": "public"
36
39
  },
@@ -49,5 +52,5 @@
49
52
  "typeCoverage": {
50
53
  "atLeast": 94.13
51
54
  },
52
- "gitHead": "0922d0447ab8fae9d2d87415964403330b5ca313"
55
+ "gitHead": "bd79330f78dae2faf9cc3d8b10063567700da07b"
53
56
  }
package/src/cache.js CHANGED
@@ -1,5 +1,3 @@
1
- // @jessie-check
2
-
3
1
  import { E, Far } from '@endo/far';
4
2
 
5
3
  import { makeScalarStoreCoordinator } from './store.js';
@@ -7,6 +5,8 @@ import { makeScalarStoreCoordinator } from './store.js';
7
5
  /**
8
6
  * @import {Passable, RemotableObject} from '@endo/pass-style';
9
7
  * @import {Key, Pattern} from '@endo/patterns';
8
+ * @import {Coordinator} from './types.js';
9
+ * @import {ERef} from '@endo/far';
10
10
  */
11
11
 
12
12
  /**
@@ -17,7 +17,7 @@ import { makeScalarStoreCoordinator } from './store.js';
17
17
  */
18
18
 
19
19
  /**
20
- * @param {ERef<import('./types.js').Coordinator>} [coordinator]
20
+ * @param {ERef<Coordinator>} [coordinator]
21
21
  */
22
22
  export const makeCache = (coordinator = makeScalarStoreCoordinator()) => {
23
23
  /**
package/src/main.js CHANGED
@@ -1,6 +1,3 @@
1
- // @jessie-check
2
- /// <reference types="@agoric/internal/exported" />
3
-
4
1
  // eslint-disable-next-line import/export
5
2
  export * from './types.js';
6
3
  export * from './store.js';
package/src/state.js CHANGED
@@ -1,4 +1,7 @@
1
- // @jessie-check
1
+ /**
2
+ * @import {State} from './state.js';
3
+ * @import {MapStore} from '@agoric/store';
4
+ */
2
5
 
3
6
  /**
4
7
  * @typedef {object} State
@@ -30,7 +33,7 @@ export const makeState = (value, priorState = GROUND_STATE) =>
30
33
  /**
31
34
  * Wrap a state store to have a default value using the GROUND_STATE
32
35
  *
33
- * @param {MapStore<string, import('./state.js').State>} stateStore
36
+ * @param {MapStore<string, State>} stateStore
34
37
  */
35
38
  export const withGroundState = stateStore => ({
36
39
  ...stateStore,
package/src/store.js CHANGED
@@ -6,8 +6,14 @@ import { untilTrue } from '@agoric/internal';
6
6
  import { withGroundState, makeState } from './state.js';
7
7
 
8
8
  /**
9
+ * @import {ERemote} from '@agoric/internal'
10
+ * @import {EMarshaller} from '@agoric/internal/src/marshal/wrap-marshaller.js';
9
11
  * @import {Passable, RemotableObject} from '@endo/pass-style';
10
12
  * @import {Key, Pattern} from '@endo/patterns';
13
+ * @import {State} from './state.js';
14
+ * @import {Coordinator} from './types.js';
15
+ * @import {StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
16
+ * @import {MapStore} from '@agoric/store';
11
17
  */
12
18
 
13
19
  /**
@@ -45,9 +51,9 @@ const makeKeyToString = (sanitize = obj => obj) => {
45
51
  * @param {(obj: Passable) => Passable} sanitize Process keys and values with
46
52
  * this function before storing them
47
53
  * @param {{
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;
54
+ * get(key: string): State;
55
+ * set(key: string, value: State): void;
56
+ * init(key: string, value: State): void;
51
57
  * }} stateStore
52
58
  * @returns {Promise<Passable>} the value of the updated state
53
59
  */
@@ -61,8 +67,8 @@ const applyCacheTransaction = async (
61
67
  /**
62
68
  * Retrieve a potential updated state from the transaction.
63
69
  *
64
- * @param {import('./state.js').State} basisState
65
- * @returns {Promise<import('./state.js').State | null>} the updated state, or null if no longer applicable
70
+ * @param {State} basisState
71
+ * @returns {Promise<State | null>} the updated state, or null if no longer applicable
66
72
  */
67
73
  const getUpdatedState = async basisState => {
68
74
  const { value } = basisState;
@@ -111,8 +117,8 @@ const applyCacheTransaction = async (
111
117
  };
112
118
 
113
119
  /**
114
- * @param {MapStore<string, import('./state.js').State>} stateStore
115
- * @param {ERef<Marshaller>} marshaller
120
+ * @param {MapStore<string, State>} stateStore
121
+ * @param {ERemote<EMarshaller>} marshaller
116
122
  * @returns {Promise<string>}
117
123
  */
118
124
  const stringifyStateStore = async (stateStore, marshaller) => {
@@ -130,7 +136,7 @@ const stringifyStateStore = async (stateStore, marshaller) => {
130
136
  * Make a cache coordinator backed by a MapStore. This coordinator doesn't
131
137
  * currently enforce any cache eviction, but that would be a useful feature.
132
138
  *
133
- * @param {MapStore<string, import('./state.js').State>} [stateStore]
139
+ * @param {MapStore<string, State>} [stateStore]
134
140
  * @param {(obj: Passable) => Passable} [sanitize] Process keys and values with
135
141
  * this function before storing them. Defaults to deeplyFulfilled.
136
142
  */
@@ -142,7 +148,7 @@ export const makeScalarStoreCoordinator = (
142
148
 
143
149
  const defaultStateStore = withGroundState(stateStore);
144
150
 
145
- /** @type {import('./types.js').Coordinator} */
151
+ /** @type {Coordinator} */
146
152
  const coord = Far('store cache coordinator', {
147
153
  getRecentValue: async key => {
148
154
  const keyStr = await serializePassable(key);
@@ -175,9 +181,9 @@ export const makeScalarStoreCoordinator = (
175
181
  /**
176
182
  * Don't write any marshalled value that's older than what's already pushed
177
183
  *
178
- * @param {MapStore<string, import('./state.js').State>} stateStore
179
- * @param {ERef<Marshaller>} marshaller
180
- * @param {ERef<StorageNode>} storageNode
184
+ * @param {MapStore<string, State>} stateStore
185
+ * @param {ERemote<EMarshaller>} marshaller
186
+ * @param {ERemote<StorageNode>} storageNode
181
187
  * @returns {<T>(storedValue: T) => Promise<T>}
182
188
  */
183
189
  const makeLastWinsUpdater = (stateStore, marshaller, storageNode) => {
@@ -205,8 +211,8 @@ const makeLastWinsUpdater = (stateStore, marshaller, storageNode) => {
205
211
  * Make a cache coordinator backed by a MapStore. This coordinator doesn't
206
212
  * currently enforce any cache eviction, but that would be a useful feature.
207
213
  *
208
- * @param {ERef<StorageNode>} storageNode
209
- * @param {ERef<Marshaller>} marshaller
214
+ * @param {ERemote<StorageNode>} storageNode
215
+ * @param {ERemote<EMarshaller>} marshaller
210
216
  */
211
217
  export const makeChainStorageCoordinator = (storageNode, marshaller) => {
212
218
  const stateStore = makeScalarBigMapStore('stateKey');
@@ -222,7 +228,7 @@ export const makeChainStorageCoordinator = (storageNode, marshaller) => {
222
228
  storageNode,
223
229
  );
224
230
 
225
- /** @type {import('./types.js').Coordinator} */
231
+ /** @type {Coordinator} */
226
232
  const coord = Far('store cache coordinator', {
227
233
  getRecentValue: async key => {
228
234
  const keyStr = await serializePassable(key);
package/src/types.js CHANGED
@@ -1,7 +1,3 @@
1
- // @jessie-check
2
-
3
- /// <reference types="@agoric/store/exported.js" />
4
-
5
1
  // XXX package factoring debt
6
2
 
7
3
  // Ensure this is a module.
package/CHANGELOG.md DELETED
@@ -1,69 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [0.4.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.4.0-u22.2...@agoric/cache@0.4.0) (2026-04-02)
7
-
8
- **Note:** Version bump only for package @agoric/cache
9
-
10
- ## [0.4.0-u22.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.4.0-u22.1...@agoric/cache@0.4.0-u22.2) (2025-09-09)
11
-
12
- **Note:** Version bump only for package @agoric/cache
13
-
14
- ## [0.4.0-u22.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.4.0-u22.0...@agoric/cache@0.4.0-u22.1) (2025-09-09)
15
-
16
- **Note:** Version bump only for package @agoric/cache
17
-
18
- ## [0.4.0-u22.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.3.2...@agoric/cache@0.4.0-u22.0) (2025-09-08)
19
-
20
- ### Features
21
-
22
- * **types:** ambient exports from agoric/internal ([71d18c4](https://github.com/Agoric/agoric-sdk/commit/71d18c4221f63f1c0e7c45562b5a0a86a0b4b5c0))
23
-
24
- ### [0.3.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.3.1...@agoric/cache@0.3.2) (2023-06-02)
25
-
26
- **Note:** Version bump only for package @agoric/cache
27
-
28
- ### [0.3.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.3.0...@agoric/cache@0.3.1) (2023-05-24)
29
-
30
- **Note:** Version bump only for package @agoric/cache
31
-
32
- ## [0.3.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.2.3...@agoric/cache@0.3.0) (2023-05-19)
33
-
34
- ### ⚠ BREAKING CHANGES
35
-
36
- * emit smallcaps-format data in all marshallers
37
- * remove storeName parameter
38
-
39
- ### Features
40
-
41
- * emit smallcaps-format data in all marshallers ([1753df8](https://github.com/Agoric/agoric-sdk/commit/1753df83465785b5ee71b250770c9b012d750ffc)), closes [#6822](https://github.com/Agoric/agoric-sdk/issues/6822)
42
-
43
- ### Miscellaneous Chores
44
-
45
- * remove storeName parameter ([452f9bc](https://github.com/Agoric/agoric-sdk/commit/452f9bc680d4f54bed5608eb0d7cf67d80d87ba0))
46
-
47
- ### [0.2.4](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.2.3...@agoric/cache@0.2.4) (2023-02-17)
48
-
49
- **Note:** Version bump only for package @agoric/cache
50
-
51
- ### [0.2.3](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.2.2...@agoric/cache@0.2.3) (2022-10-18)
52
-
53
- **Note:** Version bump only for package @agoric/cache
54
-
55
- ### [0.2.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.2.1...@agoric/cache@0.2.2) (2022-10-08)
56
-
57
- **Note:** Version bump only for package @agoric/cache
58
-
59
- ### [0.2.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/cache@0.2.0...@agoric/cache@0.2.1) (2022-10-05)
60
-
61
- **Note:** Version bump only for package @agoric/cache
62
-
63
- ## 0.2.0 (2022-09-20)
64
-
65
- ### Features
66
-
67
- * **cache:** makeChainStorageCoordinator ([a9b8f3e](https://github.com/Agoric/agoric-sdk/commit/a9b8f3ebe4ff3e25c857426781ae5c403198f234))
68
- * **cache:** new `@agoric/cache` implementation ([0626796](https://github.com/Agoric/agoric-sdk/commit/06267961d3de36b1ddd04d9a6345775846056755))
69
- * **cache:** send the updater to the coordinator, not client loop ([23b94b1](https://github.com/Agoric/agoric-sdk/commit/23b94b1ebd176a7f7ae90ca64d2252ed348e8836))
package/test/mvp.test.js DELETED
@@ -1,40 +0,0 @@
1
- // Must be first to set up globals
2
- import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';
3
- import { M } from '@agoric/store';
4
- import { makeScalarBigMapStore } from '@agoric/vat-data';
5
-
6
- import { makeCache } from '../src/cache.js';
7
- import { makeScalarStoreCoordinator } from '../src/store.js';
8
-
9
- // Taken from the README.
10
- test('mvp happy path', async t => {
11
- const store = makeScalarBigMapStore('cache');
12
- const coordinator = makeScalarStoreCoordinator(store);
13
- const cache = makeCache(coordinator);
14
-
15
- // Direct value manipulation.
16
- t.is(await cache('baz'), undefined);
17
- t.is(await cache('baz', 'barbosa'), 'barbosa');
18
-
19
- // Match-and-set.
20
- t.is(await cache('baz', 'babaloo', undefined), 'barbosa');
21
- t.is(await cache('baz', 'babaloo', 'barbosa'), 'babaloo');
22
-
23
- // One-time initialization.
24
- t.is(await cache('frotz', 'default'), 'default');
25
- t.is(await cache('frotz', 'ignored'), 'default');
26
-
27
- // Update function for the `'foo'` entry, using its old value (initially `undefined`).
28
- t.is(await cache('foo'), undefined);
29
- const updater = (oldValue = 'bar') => `${oldValue}1`;
30
- t.is(await cache('foo', updater, M.any()), 'bar1');
31
- t.is(await cache('foo', updater, M.any()), 'bar11');
32
- t.is(await cache('foo'), 'bar11');
33
-
34
- // You can also specify a guard pattern for the value to update. If it
35
- // doesn't match the latest value, then the cache isn't updated.
36
- t.is(await cache('foo', updater, 'nomatch'), 'bar11');
37
- t.is(await cache('foo', updater, 'bar11'), 'bar111');
38
- t.is(await cache('foo', updater, 'bar11'), 'bar111');
39
- t.is(await cache('foo'), 'bar111');
40
- });
@@ -1,187 +0,0 @@
1
- // Must be first to set up globals
2
- import '@agoric/zoe/tools/prepare-test-env.js';
3
-
4
- import test from 'ava';
5
- import { makeChainStorageRoot } from '@agoric/internal/src/lib-chainStorage.js';
6
-
7
- import { Far, makeMarshal } from '@endo/marshal';
8
- import { M } from '@agoric/store';
9
- import { makeCache } from '../src/cache.js';
10
- import { makeChainStorageCoordinator } from '../src/store.js';
11
-
12
- const makeSimpleMarshaller = () => {
13
- const vals = [];
14
- const fromVal = val => {
15
- vals.push(val);
16
- return vals.length - 1;
17
- };
18
- const toVal = slot => vals[slot];
19
- return makeMarshal(fromVal, toVal, {
20
- serializeBodyFormat: 'smallcaps',
21
- marshalSaveError: err => {
22
- throw err;
23
- },
24
- });
25
- };
26
- harden(makeSimpleMarshaller);
27
-
28
- const setup = () => {
29
- const storageNodeState = {};
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
- );
40
- const cache = makeCache(
41
- makeChainStorageCoordinator(chainStorage, makeSimpleMarshaller()),
42
- );
43
- return { cache, storageNodeState };
44
- };
45
-
46
- test('makeChainStorageCoordinator with non-remote values', async t => {
47
- const { cache, storageNodeState } = setup();
48
-
49
- t.is(await cache('brandName', 'barbosa'), 'barbosa');
50
- t.deepEqual(Object.keys(storageNodeState), ['cache']);
51
- t.deepEqual(JSON.parse(storageNodeState.cache), {
52
- '{"body":"#\\"brandName\\"","slots":[]}': {
53
- body: '#{"generation":"+1","value":"barbosa"}',
54
- slots: [],
55
- },
56
- });
57
-
58
- // One-time initialization (of 'frotz')
59
- t.is(await cache('frotz', 'default'), 'default');
60
- const afterFirstFrotz = {
61
- '{"body":"#\\"brandName\\"","slots":[]}': {
62
- body: '#{"generation":"+1","value":"barbosa"}',
63
- slots: [],
64
- },
65
- '{"body":"#\\"frotz\\"","slots":[]}': {
66
- body: '#{"generation":"+1","value":"default"}',
67
- slots: [],
68
- },
69
- };
70
- t.deepEqual(JSON.parse(storageNodeState.cache), afterFirstFrotz);
71
- // no change
72
- t.is(await cache('frotz', 'ignored'), 'default');
73
- t.deepEqual(JSON.parse(storageNodeState.cache), afterFirstFrotz);
74
-
75
- // cache more complex Passable
76
- const complexPassable = {
77
- str: 'string',
78
- big: 1n,
79
- num: 53,
80
- arr: ['hi', 'there'],
81
- };
82
- t.deepEqual(
83
- await cache(['complex', 'passable'], complexPassable),
84
- complexPassable,
85
- );
86
- t.deepEqual(JSON.parse(storageNodeState.cache), {
87
- ...afterFirstFrotz,
88
- '{"body":"#[\\"complex\\",\\"passable\\"]","slots":[]}': {
89
- body: '#{"generation":"+1","value":{"arr":["hi","there"],"big":"+1","num":53,"str":"string"}}',
90
- slots: [],
91
- },
92
- });
93
- });
94
-
95
- test('makeChainStorageCoordinator with remote values', async t => {
96
- const { cache, storageNodeState } = setup();
97
-
98
- const farThing = Far('farThing', { getAllegedName: () => 'dollaz' });
99
-
100
- t.is(await cache('brand', farThing), farThing);
101
- t.deepEqual(Object.keys(storageNodeState), ['cache']);
102
- t.deepEqual(JSON.parse(storageNodeState.cache), {
103
- '{"body":"#\\"brand\\"","slots":[]}': {
104
- body: '#{"generation":"+1","value":"$0.Alleged: farThing"}',
105
- slots: [0],
106
- },
107
- });
108
- });
109
-
110
- test('makeChainStorageCoordinator with updater', async t => {
111
- const { cache, storageNodeState } = setup();
112
-
113
- const increment = (counter = 0) => Promise.resolve(counter + 1);
114
-
115
- // Initial
116
- t.is(await cache('counter', increment), 1);
117
- t.deepEqual(Object.keys(storageNodeState), ['cache']);
118
- t.deepEqual(JSON.parse(storageNodeState.cache), {
119
- '{"body":"#\\"counter\\"","slots":[]}': {
120
- body: '#{"generation":"+1","value":1}',
121
- slots: [],
122
- },
123
- });
124
-
125
- // Again without a pattern
126
- t.is(await cache('counter', increment), 1);
127
- t.deepEqual(Object.keys(storageNodeState), ['cache']);
128
- t.deepEqual(JSON.parse(storageNodeState.cache), {
129
- '{"body":"#\\"counter\\"","slots":[]}': {
130
- body: '#{"generation":"+1","value":1}',
131
- slots: [],
132
- },
133
- });
134
-
135
- // Again with a matching pattern
136
- t.is(await cache('counter', increment, M.any()), 2);
137
- t.deepEqual(Object.keys(storageNodeState), ['cache']);
138
- t.deepEqual(JSON.parse(storageNodeState.cache), {
139
- '{"body":"#\\"counter\\"","slots":[]}': {
140
- body: '#{"generation":"+2","value":2}',
141
- slots: [],
142
- },
143
- });
144
- });
145
-
146
- test('makeChainStorageCoordinator with remote updater', async t => {
147
- const { cache, storageNodeState } = setup();
148
-
149
- let counter = 0;
150
- const counterObj = Far('counterObj', {
151
- increment: () => {
152
- return (counter += 1);
153
- },
154
- });
155
-
156
- // Initial
157
- t.is(await cache('counter', counterObj.increment), 1);
158
- t.deepEqual(Object.keys(storageNodeState), ['cache']);
159
- t.deepEqual(JSON.parse(storageNodeState.cache), {
160
- '{"body":"#\\"counter\\"","slots":[]}': {
161
- body: '#{"generation":"+1","value":1}',
162
- slots: [],
163
- },
164
- });
165
-
166
- // Again without a pattern, doesn't increment
167
- t.is(await cache('counter', counterObj.increment), 1);
168
- t.is(counter, 1);
169
- t.deepEqual(Object.keys(storageNodeState), ['cache']);
170
- t.deepEqual(JSON.parse(storageNodeState.cache), {
171
- '{"body":"#\\"counter\\"","slots":[]}': {
172
- body: '#{"generation":"+1","value":1}',
173
- slots: [],
174
- },
175
- });
176
-
177
- // Again with a matching pattern
178
- t.is(await cache('counter', counterObj.increment, M.any()), 2);
179
- t.is(counter, 2);
180
- t.deepEqual(Object.keys(storageNodeState), ['cache']);
181
- t.deepEqual(JSON.parse(storageNodeState.cache), {
182
- '{"body":"#\\"counter\\"","slots":[]}': {
183
- body: '#{"generation":"+2","value":2}',
184
- slots: [],
185
- },
186
- });
187
- });
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- // This file can contain .js-specific Typescript compiler config.
2
- {
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {},
5
- "include": [
6
- "*.js",
7
- "public/**/*.js",
8
- "src/**/*.js",
9
- "test/**/*.js",
10
- ],
11
- }