Skip to content

Commit

Permalink
fix: Improve typing information
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Feb 27, 2023
1 parent 246826f commit 7b3fc39
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
4 changes: 3 additions & 1 deletion packages/captp/src/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const reverseSlot = slot => {
};

/**
* @typedef {Object} CapTPOptions the options to makeCapTP
* @typedef {object} CapTPOptions the options to makeCapTP
* @property {(val: unknown, slot: CapTPSlot) => void} [exportHook]
* @property {(val: unknown, slot: CapTPSlot) => void} [importHook]
* @property {(err: any) => void} [onReject]
Expand All @@ -80,7 +80,9 @@ export const makeCapTP = (
bootstrapObj = undefined,
opts = {},
) => {
/** @type {Record<string, number>} */
const sendCount = {};
/** @type {Record<string, number>} */
const recvCount = {};
const getStats = () =>
harden({
Expand Down
37 changes: 23 additions & 14 deletions packages/compartment-mapper/src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/** @typedef {import('./types.js').CompartmentMapDescriptor} CompartmentMapDescriptor */
/** @typedef {import('./types.js').DeferredAttenuatorsProvider} DeferredAttenuatorsProvider */
/** @typedef {import('./types.js').LinkOptions} LinkOptions */
/** @template T @typedef {import('@endo/eventual-send').ERef<T>} ERef */

import { resolve } from './node-module-specifier.js';
import { parseExtension } from './extension.js';
Expand All @@ -28,6 +29,11 @@ const { entries, fromEntries } = Object;
const { hasOwnProperty } = Object.prototype;
const { apply } = Reflect;
const { allSettled } = Promise;

/**
* @template T
* @type {(iterable: Iterable<ERef<T>>) => Promise<Array<PromiseSettledResult<T>>>}
*/
const promiseAllSettled = allSettled.bind(Promise);

const inertStaticModuleRecord = {
Expand Down Expand Up @@ -494,20 +500,23 @@ export const link = (
compartments,
resolvers,
attenuatorsCompartment,
pendingJobsPromise: promiseAllSettled(pendingJobs).then(results => {
const errors = results
.filter(result => result.status === 'rejected')
.map(
/** @param {PromiseRejectedResult} result */ result => result.reason,
);
if (errors.length > 0) {
throw new Error(
`Globals attenuation errors: ${errors
.map(error => error.message)
.join(', ')}`,
);
}
}),
pendingJobsPromise: promiseAllSettled(pendingJobs).then(
/** @param {PromiseSettledResult<unknown>[]} results */ results => {
const errors = results
.filter(result => result.status === 'rejected')
.map(
/** @param {PromiseRejectedResult} result */ result =>
result.reason,
);
if (errors.length > 0) {
throw new Error(
`Globals attenuation errors: ${errors
.map(error => error.message)
.join(', ')}`,
);
}
},
),
};
};

Expand Down
8 changes: 8 additions & 0 deletions packages/compartment-mapper/src/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ const q = JSON.stringify;
*/
export const ATTENUATORS_COMPARTMENT = '<ATTENUATORS>';

/**
* Copies properties (optionally limited to a specific list) from one object to another.
*
* @param {object} from
* @param {object} to
* @param {Array<string | symbol>} [list]
* @returns {object}
*/
const selectiveCopy = (from, to, list) => {
if (!list) {
list = keys(from);
Expand Down

0 comments on commit 7b3fc39

Please sign in to comment.