Skip to content

Commit

Permalink
fix: deprecate kinds in favor of far classes
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Oct 20, 2022
1 parent 42fdddf commit 440cb4c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/vat-data/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ type DefineKindOptions<C> = {

export type VatData = {
// virtual kinds
/** @deprecated Use defineVirtualFarClass instead */
defineKind: <P, S, F>(
tag: string,
init: (...args: P) => S,
facet: F,
options?: DefineKindOptions<KindContext<S, F>>,
) => (...args: P) => KindFacet<F>;

/** @deprecated Use defineVirtualFarClassKit instead */
defineKindMulti: <P, S, B>(
tag: string,
init: (...args: P) => S,
Expand All @@ -111,12 +114,16 @@ export type VatData = {

// durable kinds
makeKindHandle: (descriptionTag: string) => DurableKindHandle;

/** @deprecated Use defineDurableFarClass instead */
defineDurableKind: <P, S, F>(
kindHandle: DurableKindHandle,
init: (...args: P) => S,
facet: F,
options?: DefineKindOptions<KindContext<S, F>>,
) => (...args: P) => KindFacet<F>;

/** @deprecated Use defineDurableFarClassKit instead */
defineDurableKindMulti: <P, S, B>(
kindHandle: DurableKindHandle,
init: (...args: P) => S,
Expand Down Expand Up @@ -166,6 +173,7 @@ interface PickFacet {
): (...args: Parameters<M>) => ReturnType<M>[F];
}

/** @deprecated Use vivifyFarClass instead */
type VivifyKind = <P, S, F>(
baggage: Baggage,
tag: string,
Expand All @@ -174,6 +182,7 @@ type VivifyKind = <P, S, F>(
options?: DefineKindOptions<KindContext<S, F>>,
) => (...args: P) => KindFacet<F>;

/** @deprecated Use vivifyFarClassKit instead */
type VivifyKindMulti = <P, S, B>(
baggage: Baggage,
tag: string,
Expand Down
23 changes: 18 additions & 5 deletions packages/zoe/src/makeHandle.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// @ts-check

import { assert } from '@agoric/assert';
import { initEmpty } from '@agoric/store';
import { provide, defineDurableKind, makeKindHandle } from '@agoric/vat-data';
import { Far } from '@endo/marshal';
import { initEmpty, makeHeapFarInstance } from '@agoric/store';
import {
provide,
defineDurableFarClass,
makeKindHandle,
} from '@agoric/vat-data';
import { HandleI } from './typeGuards.js';

/** @typedef {import('@agoric/vat-data').Baggage} Baggage */

Expand All @@ -20,7 +24,13 @@ export const defineDurableHandle = (baggage, handleType) => {
`${handleType}KindHandle`,
() => makeKindHandle(`${handleType}Handle`),
);
const makeHandle = defineDurableKind(durableHandleKindHandle, initEmpty, {});
const makeHandle = defineDurableFarClass(
durableHandleKindHandle,
HandleI,
initEmpty,
{},
);
// @ts-expect-error Bit by our own opaque types.
return /** @type {() => Handle<H>} */ (makeHandle);
};
harden(defineDurableHandle);
Expand All @@ -35,6 +45,9 @@ harden(defineDurableHandle);
export const makeHandle = handleType => {
assert.typeof(handleType, 'string', 'handleType must be a string');
// Return the intersection type (really just an empty object).
return /** @type {Handle<H>} */ (Far(`${handleType}Handle`));
// @ts-expect-error Bit by our own opaque types.
return /** @type {Handle<H>} */ (
makeHeapFarInstance(`${handleType}Handle`, HandleI, {})
);
};
harden(makeHandle);
2 changes: 2 additions & 0 deletions packages/zoe/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const AmountPatternKeywordRecordShape = M.recordOf(
M.pattern(),
);

export const HandleI = M.interface('Handle', {});

export const makeHandleShape = name => M.remotable(`${name}Handle`);
export const TimerShape = makeHandleShape('timer');

Expand Down

0 comments on commit 440cb4c

Please sign in to comment.