Skip to content

Commit

Permalink
Merge pull request #7363 from Agoric/markm-default-key-type
Browse files Browse the repository at this point in the history
fix(store,ERTP): collection type param defaults
  • Loading branch information
mergify[bot] authored Apr 10, 2023
2 parents 5fcfe1a + 7c529b0 commit 2b31d20
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 57 deletions.
4 changes: 2 additions & 2 deletions packages/ERTP/src/mathHelpers/copyBagMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
} from '@agoric/store';
import '../types-ambient.js';

/** @type {CopyBagValue} */
/** @type {CopyBag} */
const empty = makeCopyBag([]);

/**
* @type {MathHelpers<CopyBagValue>}
* @type {MathHelpers<CopyBag>}
*/
export const copyBagMathHelpers = harden({
doCoerce: bag => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ERTP/src/mathHelpers/copySetMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
} from '@agoric/store';
import '../types-ambient.js';

/** @type {CopySetValue} */
/** @type {CopySet} */
const empty = makeCopySet([]);

/**
* @type {CopySetMathHelpers}
* @type {MathHelpers<CopySet>}
*/
export const copySetMathHelpers = harden({
doCoerce: set => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/mathHelpers/natMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const empty = 0n;
*
* Natural numbers are used for fungible erights such as money because
* rounding issues make floats problematic. All operations should be
* done with the smallest whole unit such that the NatMathHelpers never
* done with the smallest whole unit such that the `natMathHelpers` never
* deals with fractional parts.
*
* @type {MathHelpers<NatValue>}
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/mathHelpers/setMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const empty = harden([]);

/**
* @deprecated Replace array-based SetMath with CopySet-based CopySetMath
* @type {SetMathHelpers}
* @type {MathHelpers<SetValue>}
*/
export const setMathHelpers = harden({
doCoerce: list => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ERTP/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ harden(isNatValue);
* Returns true if value is a CopySet
*
* @param {AmountValue} value
* @returns {value is CopySetValue}
* @returns {value is CopySet}
*/
export const isCopySetValue = value => matches(value, CopySetValueShape);
harden(isCopySetValue);
Expand All @@ -119,7 +119,7 @@ harden(isSetValue);
* Returns true if value is a CopyBag
*
* @param {AmountValue} value
* @returns {value is CopyBagValue}
* @returns {value is CopyBag}
*/
export const isCopyBagValue = value => matches(value, CopyBagValueShape);
harden(isCopyBagValue);
Expand Down
38 changes: 7 additions & 31 deletions packages/ERTP/src/types-ambient.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

/**
* @typedef {NatValue | SetValue | CopySetValue | CopyBagValue} AmountValue
* @typedef {NatValue | SetValue | CopySet | CopyBag} AmountValue
* An `AmountValue` describes a set or quantity of assets that can be owned or
* shared.
*
Expand All @@ -30,10 +30,10 @@
* key in a map (MapStore or CopyMap).
*
* `SetValue` is for the deprecated set representation, using an array directly
* to represent the array of its elements. `CopySetValue` is the proper
* to represent the array of its elements. `CopySet` is the proper
* representation using a CopySet.
*
* A semi-fungible `CopyBagValue` is represented as a
* A semi-fungible `CopyBag` is represented as a
* `CopyBag` of `Key` objects. "Bag" is synonymous with MultiSet, where an
* element of a bag can be present once or more times, i.e., some positive
* bigint number of times, representing that quantity of the asset represented
Expand All @@ -50,8 +50,8 @@
* @template {AssetKind} K
* @typedef {K extends 'nat' ? NatValue :
* K extends 'set' ? SetValue :
* K extends 'copySet' ? CopySetValue:
* K extends 'copyBag' ? CopyBagValue :
* K extends 'copySet' ? CopySet:
* K extends 'copyBag' ? CopyBag :
* never
* } AssetValueForKind
*/
Expand All @@ -60,8 +60,8 @@
* @template {AmountValue} V
* @typedef {V extends NatValue ? 'nat' :
* V extends SetValue ? 'set' :
* V extends CopySetValue ? 'copySet' :
* V extends CopyBagValue ? 'copyBag' :
* V extends CopySet ? 'copySet' :
* V extends CopyBag ? 'copyBag' :
* never} AssetKindForValue
*/

Expand Down Expand Up @@ -433,30 +433,6 @@
* @typedef {bigint} NatValue
*/

/**
* @typedef {MathHelpers<NatValue>} NatMathHelpers
*/

/**
* @typedef {Array<Key>} SetValue
*/

/**
* @typedef {MathHelpers<SetValue>} SetMathHelpers
*/

/**
* @typedef {CopySet<Key>} CopySetValue
*/

/**
* @typedef {MathHelpers<CopySetValue>} CopySetMathHelpers
*/

/**
* @typedef {CopyBag<Key>} CopyBagValue
*/

/**
* @typedef {MathHelpers<CopyBagValue>} CopyBagMathHelpers
*/
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('copyBag with strings getValue', t => {
);
t.deepEqual(
getCopyBagEntries(
/** @type {CopyBag<Key>} */ (
/** @type {CopyBag} */ (
m.getValue(
mockBrand,
harden({ brand: mockBrand, value: makeBag(['1']) }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test('copySet with strings getValue', t => {
);
t.deepEqual(
getCopySetKeys(
/** @type {CopySet<Key>} */ (
/** @type {CopySet} */ (
m.getValue(
mockBrand,
harden({ brand: mockBrand, value: makeCopySet(['1']) }),
Expand Down
12 changes: 6 additions & 6 deletions packages/store/src/keys/checkKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ harden(assertKey);
// Moved to here so they can check that the copySet contains only keys
// without creating an import cycle.

/** @type WeakSet<CopySet<Key>> */
/** @type WeakSet<CopySet> */
const copySetMemo = new WeakSet();

/**
Expand All @@ -170,7 +170,7 @@ harden(checkCopySet);
/**
* @callback IsCopySet
* @param {Passable} s
* @returns {s is CopySet<Key>}
* @returns {s is CopySet}
*/

/** @type {IsCopySet} */
Expand All @@ -180,7 +180,7 @@ harden(isCopySet);
/**
* @callback AssertCopySet
* @param {Passable} s
* @returns {asserts s is CopySet<Key>}
* @returns {asserts s is CopySet}
*/

/** @type {AssertCopySet} */
Expand Down Expand Up @@ -227,7 +227,7 @@ harden(makeCopySet);
// Moved to here so they can check that the copyBag contains only keys
// without creating an import cycle.

/** @type WeakSet<CopyBag<Key>> */
/** @type WeakSet<CopyBag> */
const copyBagMemo = new WeakSet();

/**
Expand All @@ -254,7 +254,7 @@ harden(checkCopyBag);
/**
* @callback IsCopyBag
* @param {Passable} b
* @returns {b is CopyBag<Key>}
* @returns {b is CopyBag}
*/

/** @type {IsCopyBag} */
Expand All @@ -264,7 +264,7 @@ harden(isCopyBag);
/**
* @callback AssertCopyBag
* @param {Passable} b
* @returns {asserts b is CopyBag<Key>}
* @returns {asserts b is CopyBag}
*/

/** @type {AssertCopyBag} */
Expand Down
20 changes: 10 additions & 10 deletions packages/store/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
// TODO parameterize CopyTagged to support these refinements

/**
* @template {Key} K
* @template {Key} [K=Key]
* @typedef {CopyTagged & {
* [Symbol.toStringTag]: 'copySet',
* payload: Array<K>,
Expand All @@ -94,7 +94,7 @@
*/

/**
* @template {Key} K
* @template {Key} [K=Key]
* @typedef {CopyTagged & {
* [Symbol.toStringTag]: 'copyBag',
* payload: Array<[K, bigint]>,
Expand All @@ -106,8 +106,8 @@
*/

/**
* @template {Key} K
* @template {Passable} V
* @template {Key} [K=Key]
* @template {Passable} [V=Passable]
* @typedef {CopyTagged & {
* [Symbol.toStringTag]: 'copyMap',
* payload: { keys: Array<K>, values: Array<V> },
Expand Down Expand Up @@ -168,7 +168,7 @@
*/

/**
* @template {Key & object} K
* @template {Key & object} [K=Key]
* @typedef {object} WeakSetStore
* @property {(key: K) => boolean} has
* Check if a key exists. The key can be any JavaScript value, though the
Expand All @@ -184,7 +184,7 @@
*/

/**
* @template {Key} K
* @template {Key} [K=Key]
* @typedef {object} SetStore
* @property {(key: K) => boolean} has
* Check if a key exists. The key can be any JavaScript value, though the
Expand All @@ -205,8 +205,8 @@
*/

/**
* @template {Key & object} K
* @template {Passable} V
* @template {Key & object} [K=Key]
* @template {Passable} [V=Passable]
* @typedef {object} WeakMapStore
* @property {(key: K) => boolean} has
* Check if a key exists. The key can be any JavaScript value, though the
Expand All @@ -225,8 +225,8 @@
*/

/**
* @template {Key} K
* @template {Passable} V
* @template {Key} [K=Key]
* @template {Passable} [V=Passable]
* @typedef {object} MapStore
* @property {(key: K) => boolean} has
* Check if a key exists. The key can be any JavaScript value, though the
Expand Down

0 comments on commit 2b31d20

Please sign in to comment.