Skip to content

Commit

Permalink
refactor(store): Prepare for better guard typing from endo
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Aug 22, 2023
1 parent e59c977 commit edc8f9f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 92 deletions.
8 changes: 4 additions & 4 deletions packages/ERTP/src/issuerKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);
* `displayInfo` gives information to the UI on how to display the amount.
* @param {Baggage} issuerBaggage
* @param {string} name
* @param {K} [assetKind=AssetKind.NAT]
* @param {AdditionalDisplayInfo} [displayInfo={}]
* @param {K} [assetKind]
* @param {AdditionalDisplayInfo} [displayInfo]
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
* the middle of an atomic action (which btw should never happen), it
* potentially leaves its ledger in a corrupted state. If this function was
Expand Down Expand Up @@ -164,8 +164,8 @@ harden(makeDurableIssuerKit);
*
* `displayInfo` gives information to the UI on how to display the amount.
* @param {string} name
* @param {K} [assetKind='nat']
* @param {AdditionalDisplayInfo} [displayInfo={}]
* @param {K} [assetKind]
* @param {AdditionalDisplayInfo} [displayInfo]
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
* the middle of an atomic action (which btw should never happen), it
* potentially leaves its ledger in a corrupted state. If this function was
Expand Down
5 changes: 5 additions & 0 deletions packages/ERTP/src/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import { initEmpty } from '@agoric/store';
import { prepareExoClass } from '@agoric/vat-data';

/** @typedef {import('@endo/patterns').MethodGuard} MethodGuard */
/**
* @template {Record<string | symbol, MethodGuard>} [T=Record<string | symbol, MethodGuard>]
* @typedef {import('@endo/patterns').InterfaceGuard<T>} InterfaceGuard
*/
/** @typedef {import('@agoric/vat-data').Baggage} Baggage */

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/ERTP/src/types-ambient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

/// <reference types="ses"/>

/**
* @template {Key} [K=Key]
* @typedef {import('@endo/patterns').CopyBag<K>} CopyBag
*/

/**
* @template {AssetKind} [K=AssetKind]
* @typedef {object} Amount Amounts are descriptions of digital assets,
Expand Down
2 changes: 2 additions & 0 deletions packages/store/src/stores/store-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Far } from '@endo/marshal';
import { M, matches } from '@endo/patterns';

/** @typedef {import('@endo/marshal').RankCompare} RankCompare */

const { Fail, quote: q } = assert;

// TODO: Undate `@endo/patterns` to export the original, and delete the
Expand Down
89 changes: 6 additions & 83 deletions packages/store/src/types.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,19 @@
/// <reference types="ses"/>

/** @typedef {import('@endo/marshal').Passable} Passable */
/** @typedef {import('@endo/marshal').PassStyle} PassStyle */
/** @typedef {import('@endo/marshal').CopyTagged} CopyTagged */
/** @template T @typedef {import('@endo/marshal').CopyRecord<T>} CopyRecord */
/** @template T @typedef {import('@endo/marshal').CopyArray<T>} CopyArray */
/** @typedef {import('@endo/marshal').Checker} Checker */
/** @typedef {import('@endo/marshal/src/rankOrder').RankCompare} RankCompare */
/** @typedef {import('@endo/marshal/src/rankOrder').RankComparison} RankComparison */

// /////////////////////////////////////////////////////////////////////////////
// Placeholder redundant types, to be imported from `@endo/patterns` instead.

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/** @typedef {Passable} Key */

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/** @typedef {Passable} Pattern */

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/** @typedef {import('@endo/pass-style').Passable} Passable */
/** @typedef {import('@endo/pass-style').CopyTagged} CopyTagged */
/** @typedef {import('@endo/patterns').Pattern} Pattern */
/** @typedef {import('@endo/patterns').Key} Key */
/**
* @template {Key} [K=Key]
* @typedef {CopyTagged & {
* [Symbol.toStringTag]: 'copySet';
* payload: K[];
* }} CopySet
* @typedef {import('@endo/patterns').CopySet<K>} CopySet
*/

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/**
* @template {Key} [K=Key]
* @typedef {CopyTagged & {
* [Symbol.toStringTag]: 'copyBag';
* payload: [K, bigint][];
* }} CopyBag
*/

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/**
* @template {Key} [K=Key]
* @template {Passable} [V=Passable]
* @typedef {CopyTagged & {
* [Symbol.toStringTag]: 'copyMap';
* payload: { keys: K[]; values: V[] };
* }} CopyMap
*/

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/**
* @typedef {object} GuardMakers
* @property {<M extends Record<any, any>>(
* interfaceName: string,
* methodGuards: M,
* options?: { sloppy?: boolean },
* ) => InterfaceGuard} interface
* @property {(...argGuards: ArgGuard[]) => MethodGuardMaker} call Guard a
* synchronous call
* @property {(...argGuards: ArgGuard[]) => MethodGuardMaker} callWhen Guard an
* async call
* @property {(argGuard: ArgGuard) => ArgGuard} await Guard an await
*/

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/** @typedef {(...args: any[]) => any} Method */

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/**
* @typedef {{
* klass: 'Interface';
* interfaceName: string;
* methodGuards: Record<string | symbol, MethodGuard>;
* sloppy?: boolean;
* }} InterfaceGuard
* @typedef {import('@endo/patterns').CopyMap<K, V>} CopyMap
*/

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/** @typedef {any} MethodGuardMaker */

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/**
* @typedef {{
* klass: 'methodGuard';
* callKind: 'sync' | 'async';
* returnGuard: unknown;
* }} MethodGuard
*/

// TODO placeholder. Figure out how to import from `@endo/patterns` instead
/** @typedef {any} ArgGuard */

// /////////////////////////////////////////////////////////////////////////////

/**
* @typedef {object} StoreOptions Of the dimensions on which KeyedStores can
* differ, we only represent a few of them as standard options. A given store
Expand Down
7 changes: 4 additions & 3 deletions packages/swingset-liveslots/src/vatDataTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Behavior is a description when defining a kind of what facets it will have.
* For the non-multi defineKind, there is just one facet so it doesn't have a key.
*/
import type { InterfaceGuard, Pattern } from '@endo/patterns';
import type {
InterfaceGuard,
MapStore,
Pattern,
SetStore,
StoreOptions,
WeakMapStore,
Expand Down Expand Up @@ -105,7 +104,9 @@ export type DefineKindOptions<C> = {
* `prepareExoClass` use this internally to protect their raw class methods
* using the provided interface.
*/
interfaceGuard?: InterfaceGuard<unknown>;
interfaceGuard?:
| InterfaceGuard<unknown>
| Record<string, InterfaceGuard<unknown>>;
};

export type VatData = {
Expand Down
16 changes: 16 additions & 0 deletions packages/swingset-liveslots/src/virtualObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,14 @@ export const makeVirtualObjectManager = (
makeContextProviderKit(contextCache, getSlotForVal, facetNames),
behavior,
thisfulMethods,
// If annotating with the following at-ts-expect-error, then
// linting packages/telemetry complains of an unused
// at-ts-expect-error. But if it is removed, then linting
// here (swingset-liveslots) complains.
// at-ts-expect-error TS does not know it can only be a kit or undefined
//
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore
interfaceGuard,
);
} else {
Expand All @@ -962,6 +970,14 @@ export const makeVirtualObjectManager = (
makeContextProvider(contextCache, getSlotForVal),
behavior,
thisfulMethods,
// If annotating with the following at-ts-expect-error, then
// linting packages/telemetry complains of an unused
// at-ts-expect-error. But if it is removed, then linting
// here (swingset-liveslots) complains.
// at-ts-expect-error TS does not know it can only be a kit or undefined
//
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore
interfaceGuard,
);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/time/src/timeMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { RelativeTimeRecordShape, TimestampRecordShape } from './typeGuards.js';

const { Fail, quote: q } = assert;
/**
* @typedef {import('@endo/marshal').RankComparison} RankComparison
*
* @typedef {import('./types').TimerBrand} TimerBrand
* @typedef {import('./types').Timestamp} Timestamp
* @typedef {import('./types').RelativeTime} RelativeTime
* @typedef {import('./types').RelativeTimeValue} RelativeTimeValue
* @typedef {import('./types').TimestampValue} TimestampValue
* @typedef {import('./types').TimeMathType} TimeMathType
*
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/time/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-use-before-define, no-undef */
import type { ERef } from '@endo/eventual-send';

import type { RankComparison } from '@agoric/store';
import type { RankComparison } from '@endo/marshal';

/// <reference types="@agoric/notifier/src/types.js"/>

Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/contractFacet/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/// <reference types="ses"/>

/** @template T @typedef {import('@endo/pass-style').CopyRecord<T>} CopyRecord */
/** @typedef {import('@agoric/ertp').IssuerOptionsRecord} IssuerOptionsRecord */

// XXX can be tighter than 'any'
Expand Down

0 comments on commit edc8f9f

Please sign in to comment.