-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8144 from Agoric/mfig-base-zone
feat: add `@agoric/base-zone`
- Loading branch information
Showing
45 changed files
with
560 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Base Zone Library | ||
|
||
Each Zone provides an API that allows the allocation of [Exo objects](https://github.com/endojs/endo/tree/master/packages/exo#readme) and [Stores | ||
(object collections)](../store/README.md) which use the same underlying persistence mechanism. This | ||
allows library code to be agnostic to whether its objects are backed purely by | ||
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`, you should instead use `@agoric/zone`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @jessie-check | ||
|
||
export * from './src/heap.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": [ | ||
"./jsconfig.json", | ||
"../../tsconfig-build-options.json" | ||
], | ||
"exclude": [ | ||
"test", | ||
"scripts", | ||
"**/exports.js", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// This file can contain .js-specific Typescript compiler config. | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": [ | ||
"*.js", | ||
"scripts", | ||
"src/**/*.js", | ||
"test/**/*.js", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@agoric/base-zone", | ||
"version": "0.1.0", | ||
"description": "Allocation zone abstraction library and heap implementation", | ||
"type": "module", | ||
"repository": "https://github.com/Agoric/agoric-sdk", | ||
"main": "./src/index.js", | ||
"scripts": { | ||
"build": "exit 0", | ||
"prepack": "tsc --build jsconfig.build.json", | ||
"postpack": "git clean -f '*.d.ts*'", | ||
"test": "ava", | ||
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js", | ||
"test:xs": "exit 0", | ||
"lint-fix": "yarn lint:eslint --fix", | ||
"lint": "run-s --continue-on-error lint:*", | ||
"lint:types": "tsc -p jsconfig.json", | ||
"lint:eslint": "eslint ." | ||
}, | ||
"exports": { | ||
".": "./src/index.js", | ||
"./heap.js": "./heap.js", | ||
"./tools/*": "./tools/*" | ||
}, | ||
"keywords": [], | ||
"author": "Agoric", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@agoric/store": "^0.9.2", | ||
"@endo/exo": "^0.2.3", | ||
"@endo/far": "^0.2.19", | ||
"@endo/pass-style": "^0.1.4", | ||
"@endo/patterns": "^0.2.3" | ||
}, | ||
"devDependencies": { | ||
"@endo/init": "^0.5.57", | ||
"ava": "^5.3.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"engines": { | ||
"node": ">=14.15.0" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"test/**/test-*.js" | ||
], | ||
"timeout": "20m", | ||
"workerThreads": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable import/export */ | ||
|
||
// Module Types ////////////////////////////////////////////////////// | ||
// | ||
// Types exposed from modules. | ||
// | ||
|
||
// @ts-expect-error TS1383: Only named exports may use 'export type'. | ||
export type * from './types.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Just a dummy to use exports.d.ts and satisfy runtime imports. | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @jessie-check | ||
|
||
// eslint-disable-next-line import/export | ||
export * from './exports.js'; | ||
|
||
// Utilities for creating zones. | ||
export * from './make-once.js'; | ||
export * from './keys.js'; | ||
export * from './is-passable.js'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Prevent the compiler from complaining about the @agoric/store type not being | ||
// defined if `"noImplicitAny": true` is set in tsconfig.json. | ||
declare module '@agoric/store'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { makeExo, defineExoClass, defineExoClassKit } from '@endo/exo'; | ||
|
||
/** @typedef {'exoClass' | 'exoClassKit' | 'exo' | 'store' | 'zone'} KeyCategories */ | ||
/** @typedef {Record<KeyCategories, (label: string) => string[]>} KeyMakers */ | ||
|
||
/** | ||
* @typedef {ExoZone & Stores} Zone A bag of methods for creating defensible objects and | ||
* collections with the same allocation semantics (ephemeral, persistent, etc) | ||
*/ | ||
|
||
/** | ||
* @typedef {object} ExoZone | ||
* @property {typeof makeExo} exo create a singleton exo-object instance bound to this zone | ||
* @property {typeof defineExoClass} exoClass create a maker function that can be used to create exo-objects bound to this zone | ||
* @property {typeof defineExoClassKit} exoClassKit create a "kit" maker function that can be used to create a record of exo-objects sharing the same state | ||
* @property {<T>(key: string, maker: (key: string) => T) => T} makeOnce create or retrieve a singleton object bound to this zone | ||
* @property {(label: string, options?: StoreOptions) => Zone} subZone create a new Zone that can be passed to untrusted consumers without exposing the storage of the parent zone | ||
*/ | ||
|
||
/** | ||
* @typedef {object} Stores | ||
* @property {() => Stores} detached obtain store providers which are detached (the stores are anonymous rather than bound to `label` in the zone) | ||
* @property {(specimen: unknown) => boolean} isStorable return true if the specimen can be stored in the zone, whether as exo-object state or in a store | ||
* @property {<K,V>(label: string, options?: StoreOptions) => MapStore<K, V>} mapStore provide a Map-like store named `label` in the zone | ||
* @property {<K>(label: string, options?: StoreOptions) => SetStore<K>} setStore provide a Set-like store named `label` in the zone | ||
* @property {<K,V>( | ||
* label: string, options?: StoreOptions) => WeakMapStore<K, V> | ||
* } weakMapStore provide a WeakMap-like store named `label` in the zone | ||
* @property {<K>( | ||
* label: string, options?: StoreOptions) => WeakSetStore<K> | ||
* } weakSetStore provide a WeakSet-like store named `label` in the zone | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import '@endo/init/debug.js'; | ||
|
||
import test from 'ava'; | ||
|
||
export { test }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// eslint-disable-next-line import/order | ||
import { test } from './prepare-test-env-ava.js'; | ||
|
||
import { makeHeapZone } from '../heap.js'; | ||
import { testFirstZoneIncarnation } from '../tools/testers.js'; | ||
|
||
test('heapZone', t => { | ||
const zone = makeHeapZone(); | ||
testFirstZoneIncarnation(t, zone); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { test } from './prepare-test-env-ava.js'; | ||
|
||
import { makeHeapZone } from '../heap.js'; | ||
import { testMakeOnce } from '../tools/testers.js'; | ||
|
||
test('heapZone', t => { | ||
testMakeOnce(t, makeHeapZone()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { M } from '@endo/patterns'; | ||
|
||
export const bindAllMethodsTo = (obj, that = obj) => | ||
Object.fromEntries( | ||
Object.entries(obj).map(([name, fn]) => [name, fn.bind(that)]), | ||
); | ||
|
||
export const greetGuard = M.interface('Greeter', { | ||
greet: M.call().optional(M.string()).returns(M.string()), | ||
}); | ||
export const greetFacet = { | ||
greet(greeting = 'Hello') { | ||
return `${greeting}, ${this.state.nick}`; | ||
}, | ||
}; | ||
|
||
export const adminGuard = M.interface('GreeterAdmin', { | ||
setNick: M.call(M.string()).returns(), | ||
}); | ||
export const adminFacet = { | ||
setNick(nick) { | ||
this.state.nick = nick; | ||
}, | ||
}; | ||
|
||
export const combinedGuard = M.interface('GreeterWithAdmin', { | ||
...greetGuard.methodGuards, | ||
...adminGuard.methodGuards, | ||
}); | ||
|
||
export const prepareGreeterSingleton = (zone, label, nick) => { | ||
const myThis = Object.freeze({ state: { nick } }); | ||
return zone.exo(label, combinedGuard, { | ||
...bindAllMethodsTo(greetFacet, myThis), | ||
...bindAllMethodsTo(adminFacet, myThis), | ||
}); | ||
}; | ||
|
||
export const prepareGreeter = zone => | ||
zone.exoClass('Greeter', combinedGuard, nick => ({ nick }), { | ||
...greetFacet, | ||
...adminFacet, | ||
}); | ||
|
||
export const prepareGreeterKit = zone => | ||
zone.exoClassKit( | ||
'GreeterKit', | ||
{ greeter: greetGuard, admin: adminGuard }, | ||
nick => ({ nick }), | ||
{ | ||
greeter: greetFacet, | ||
admin: adminFacet, | ||
}, | ||
); |
Oops, something went wrong.