Skip to content

Commit

Permalink
refactor(base-zone,store): prepare for migration to endo repo (Agoric…
Browse files Browse the repository at this point in the history
  • Loading branch information
erights authored Jan 27, 2024
1 parent f3c2b65 commit 7d47297
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 39 deletions.
4 changes: 4 additions & 0 deletions packages/base-zone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ the JS heap (ephemeral), pageable out to disk (virtual) or can be revived after
a vat upgrade (durable).

This library is used internally by [@agoric/zone](../zone/README.md); refer to it for more details. Unless you are an author of a new Zone backing store type, or want to use `makeHeapZone` without introducing build dependencies on [@agoric/vat-data](../vat-data/README.md), you should instead use [@agoric/zone](../zone/README.md).

---

Be aware that both this package `@agoric/base-zone` and `@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.
36 changes: 3 additions & 33 deletions packages/store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,6 @@ Store adds some additional functionality on top of Map.

See `makeScalarWeakMapStore` for the wrapper around JavaScript's WeakMap abstraction.

# External Store

An External Store is defined by its maker function, and provides abstractions
that are compatible with large, synchronous secondary storage that can be paged
in and out of local memory.

```js
import { makeExternalStore } from '@agoric/store';

// Here is us defining an instance store for 'hello' objects.
const estore = makeExternalStore((msg = 'Hello') => ({
hello(nickname) {
return `${msg}, ${nickname}!`;
},
}));

const h = estore.makeInstance('Hi');
h.hello('friend') === 'Hi, friend!';
const wm = estore.makeWeakMap('Hello object');
wm.init(h, 'data');
// ... time passes and h is paged out and reloaded.
wm.get(h) === 'data';
wm.set(h, 'new-data');
// ... time passes and h is paged out and reloaded.
map.delete(h);
```

Note that when you import and use the `makeExternalStore` function, the platform
you are running on may rewrite your code to use a more scalable implementation
of that function. If it is not rewritten, then `makeExternalStore` will use
`makeMemoryExternalStore`, a full-featured, though in-memory-only
implementation. If you don't desire rewriting, then use
`makeMemoryExternalStore` directly.
---

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.
2 changes: 0 additions & 2 deletions packages/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@
},
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
"dependencies": {
"@agoric/assert": "^0.6.0",
"@endo/exo": "^1.1.0",
"@endo/marshal": "^1.1.0",
"@endo/pass-style": "^1.1.0",
"@endo/patterns": "^1.1.0"
},
"devDependencies": {
"@agoric/time": "^0.3.2",
"@endo/init": "^1.0.2",
"@endo/ses-ava": "^1.1.0",
"ava": "^5.3.0"
Expand Down
5 changes: 3 additions & 2 deletions packages/store/src/legacy/legacyMap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { q, Fail } from '@agoric/assert';

import '../types.js';

// TODO, once migrated to endo, import from @endo/errors instead
const { Fail, quote: q } = assert;

/**
* This module and its fraternal sibling legacyWeakMap exist only to ease a
* transition to the modern `store` system, are deprecated, and will eventually
Expand Down
4 changes: 3 additions & 1 deletion packages/store/src/legacy/legacyWeakMap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { q, Fail } from '@agoric/assert';
import '../types.js';

// TODO, once migrated to endo, import from @endo/errors instead
const { Fail, quote: q } = assert;

/**
* See doccomment in the closely related `legacyMap.js` module.
*
Expand Down
9 changes: 8 additions & 1 deletion packages/store/test/borrow-guards.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { M } from '@endo/patterns';
import { TimestampShape } from '@agoric/time';

// The purpose of this module is to provide snapshotted (and possibly stale)
// copies of various patterns and guards from packages that this package
Expand All @@ -23,6 +22,14 @@ export const AmountShape = harden({
const AmountKeywordRecordShape = M.recordOf(M.string(), AmountShape);
const AmountPatternKeywordRecordShape = M.recordOf(M.string(), M.pattern());

const TimerBrandShape = M.remotable('TimerBrand');
const TimestampValueShape = M.nat();
const TimestampRecordShape = harden({
timerBrand: TimerBrandShape,
absValue: TimestampValueShape,
});
const TimestampShape = M.or(TimestampRecordShape, TimestampValueShape);

export const FullProposalShape = harden({
want: AmountPatternKeywordRecordShape,
give: AmountKeywordRecordShape,
Expand Down

0 comments on commit 7d47297

Please sign in to comment.