Skip to content

Commit

Permalink
refactor: remove migrated common
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 21, 2024
1 parent a49db10 commit ac7afd2
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 811 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ jobs:
- name: yarn test (notifier)
if: (success() || failure())
run: cd packages/notifier && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
- name: yarn test (same-structure)
if: (success() || failure())
run: cd packages/same-structure && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
- name: yarn test (sparse-ints)
if: (success() || failure())
run: cd packages/sparse-ints && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
Expand Down
1 change: 0 additions & 1 deletion packages/agoric-cli/src/sdk-package-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default [
"@agoric/network",
"@agoric/notifier",
"@agoric/pegasus",
"@agoric/same-structure",
"@agoric/smart-wallet",
"@agoric/solo",
"@agoric/sparse-ints",
Expand Down
5 changes: 3 additions & 2 deletions packages/assert/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* @callback AssertMakeError
*
* The `assert.error` method, recording details for the console.
* The `makeError` function, recording details for the console.
*
* The optional `optDetails` can be a string.
* @param {Details} [optDetails] The details of what was asserted
Expand Down Expand Up @@ -154,7 +154,7 @@

/**
* @callback AssertNote
* The `assert.note` method.
* The `errorNote` function.
*
* Annotate an error with details, potentially to be used by an
* augmented console such as the causal console of `console.js`, to
Expand Down Expand Up @@ -345,6 +345,7 @@
* details: DetailsTag,
* Fail: FailTag,
* quote: AssertQuote,
* bare: AssertQuote,
* makeAssert: MakeAssert,
* } } Assert
*/
35 changes: 3 additions & 32 deletions packages/internal/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,14 @@ import {
import { deeplyFulfilled, isObject } from '@endo/marshal';
import { makePromiseKit } from '@endo/promise-kit';
import { makeQueue } from '@endo/stream';
import { asyncGenerate, makeSet } from 'jessie.js';
import { asyncGenerate } from 'jessie.js';

const { fromEntries, keys, values } = Object;
const { ownKeys } = Reflect;

export const BASIS_POINTS = 10_000n;

/** @template T @typedef {import('@endo/eventual-send').ERef<T>} ERef<T> */

/**
* Throws if multiple entries use the same property name. Otherwise acts
* like `Object.fromEntries` but hardens the result.
* Use it to protect from property names computed from user-provided data.
*
* @template K,V
* @param {Iterable<[K,V]>} allEntries
* @returns {{[k: K]: V}}
*/
export const fromUniqueEntries = allEntries => {
const entriesArray = [...allEntries];
const result = harden(fromEntries(entriesArray));
if (ownKeys(result).length === entriesArray.length) {
return result;
}
const names = makeSet();
for (const [name, _] of entriesArray) {
if (names.has(name)) {
Fail`collision on property name ${q(name)}: ${entriesArray}`;
}
names.add(name);
}
throw Fail`internal: failed to create object from unique entries`;
};
harden(fromUniqueEntries);

export { objectMap } from '@endo/patterns';

/**
* @template T
* @typedef {{[KeyType in keyof T]: T[KeyType]} & {}} Simplify
Expand Down Expand Up @@ -146,7 +117,8 @@ export const PromiseAllOrErrors = async items => {
* trier: () => Promise<T>,
* finalizer: (error?: unknown) => Promise<void>,
* ) => Promise<T>}
*/ export const aggregateTryFinally = async (trier, finalizer) =>
*/
export const aggregateTryFinally = async (trier, finalizer) =>
trier().then(
async result => finalizer().then(() => result),
async tryError =>
Expand All @@ -172,7 +144,6 @@ export const PromiseAllOrErrors = async items => {
* @throws if any value in the object entries is not defined
* @returns {asserts obj is AllDefined<T>}
*/

export const assertAllDefined = obj => {
const missing = [];
for (const [key, val] of Object.entries(obj)) {
Expand Down
47 changes: 0 additions & 47 deletions packages/internal/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import test from 'ava';

import { Far } from '@endo/far';
import {
fromUniqueEntries,
objectMap,
makeMeasureSeconds,
assertAllDefined,
whileTrue,
Expand All @@ -14,51 +12,6 @@ import {
synchronizedTee,
} from '../src/utils.js';

test('fromUniqueEntries', t => {
/** @type {[string | symbol, number][]} */
const goodEntries = [
['a', 7],
['b', 8],
[Symbol.hasInstance, 9],
];
const goodObj1 = Object.fromEntries(goodEntries);
t.deepEqual(goodObj1, {
a: 7,
b: 8,
[Symbol.hasInstance]: 9,
});
const goodObj2 = fromUniqueEntries(goodEntries);
t.deepEqual(goodObj2, goodObj1);

/** @type {[string | symbol, number][]} */
const badEntries = [
['a', 7],
['a', 8],
[Symbol.hasInstance, 9],
];
const badObj = Object.fromEntries(badEntries);
t.deepEqual(badObj, {
a: 8,
[Symbol.hasInstance]: 9,
});
t.throws(() => fromUniqueEntries(badEntries), {
message: /^collision on property name "a": .*$/,
});
});

test('objectMap', t => {
// @ts-expect-error
t.throws(() => objectMap({ a: 1 }), { message: 'mapFn is not a function' });
t.deepEqual(
objectMap({ a: 1 }, val => val * 2),
{ a: 2 },
);
t.deepEqual(
objectMap({ a: 1 }, (val, key) => `${key}:${val}`),
{ a: 'a:1' },
);
});

test('deeplyFulfilledObject', async t => {
const someFar = Far('somefar', { getAsync: () => Promise.resolve('async') });
const unfulfilled = harden({
Expand Down
Loading

0 comments on commit ac7afd2

Please sign in to comment.