From 7d4729735e3ce04b146f8982e6b537e86546bc8b Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Sat, 27 Jan 2024 04:17:14 -0800 Subject: [PATCH] refactor(base-zone,store): prepare for migration to endo repo (#8749) --- packages/base-zone/README.md | 4 +++ packages/store/README.md | 36 ++-------------------- packages/store/package.json | 2 -- packages/store/src/legacy/legacyMap.js | 5 +-- packages/store/src/legacy/legacyWeakMap.js | 4 ++- packages/store/test/borrow-guards.js | 9 +++++- 6 files changed, 21 insertions(+), 39 deletions(-) diff --git a/packages/base-zone/README.md b/packages/base-zone/README.md index d13be8adc76..60700283322 100644 --- a/packages/base-zone/README.md +++ b/packages/base-zone/README.md @@ -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. diff --git a/packages/store/README.md b/packages/store/README.md index 94853c82806..f4ce46def29 100644 --- a/packages/store/README.md +++ b/packages/store/README.md @@ -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. diff --git a/packages/store/package.json b/packages/store/package.json index 2c94e9dc631..09cb4ddd4c9 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -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" diff --git a/packages/store/src/legacy/legacyMap.js b/packages/store/src/legacy/legacyMap.js index 82bd73e8783..9b40a0f2492 100644 --- a/packages/store/src/legacy/legacyMap.js +++ b/packages/store/src/legacy/legacyMap.js @@ -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 diff --git a/packages/store/src/legacy/legacyWeakMap.js b/packages/store/src/legacy/legacyWeakMap.js index 26337e07c12..e7167137927 100644 --- a/packages/store/src/legacy/legacyWeakMap.js +++ b/packages/store/src/legacy/legacyWeakMap.js @@ -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. * diff --git a/packages/store/test/borrow-guards.js b/packages/store/test/borrow-guards.js index 71d2fd54c25..2e8daf01810 100644 --- a/packages/store/test/borrow-guards.js +++ b/packages/store/test/borrow-guards.js @@ -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 @@ -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,