Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 8771 simplifications without 8781 import reforms #8782

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -26,7 +26,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
*/
1 change: 1 addition & 0 deletions packages/internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@agoric/assert": "^0.6.0",
"@agoric/base-zone": "^0.1.0",
"@endo/common": "^1.0.2",
"@endo/far": "^1.0.2",
"@endo/init": "^1.0.2",
"@endo/marshal": "^1.1.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/internal/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ export * from './debug.js';
export * from './utils.js';
export * from './method-tools.js';
export * from './typeGuards.js';

export { objectMap } from '@endo/common/object-map.js';
export { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
35 changes: 3 additions & 32 deletions packages/internal/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,16 @@
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;

const { quote: q, Fail } = assert;

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 @@ -140,7 +111,8 @@
* 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 @@ -166,7 +138,6 @@
* @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 Expand Up @@ -301,7 +272,7 @@
doneResult = { done: true, value: undefined };
},
);
resolvers.forEach(resolve => resolve(result));

Check warning on line 275 in packages/internal/src/utils.js

View workflow job for this annotation

GitHub Actions / lint-rest

Prefer for...of instead of Array.forEach
return pullNext();
};

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
Loading