Skip to content

Commit

Permalink
finish transitioning to @import (#2214)
Browse files Browse the repository at this point in the history
## Description

Follow up #2192

I think this wraps up the transition, save for the TODO.

### Security Considerations

n/a, typedefs

### Scaling Considerations

n/a, typedefs

### Documentation Considerations

not necessary

### Testing Considerations

CI
### Compatibility Considerations

Some reduction in exports, but those were deep imports so ok to break

### Upgrade Considerations

none
  • Loading branch information
turadg authored Apr 17, 2024
2 parents d521532 + ac551d5 commit 38e61af
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 259 deletions.
2 changes: 1 addition & 1 deletion packages/bundle-source/demo/comments/types.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/** @typedef {import('./types.js').Bogus} Bogus */
/** @import {Bogus} from './types.js' */
6 changes: 2 additions & 4 deletions packages/captp/src/captp.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// <reference types="ses"/>

/** @template [R=unknown] @typedef {import('@endo/eventual-send').Settler<R>} Settler */
/** @template [R=unknown] @typedef {import('@endo/eventual-send').HandledExecutor<R>} HandledExecutor */
/** @template [R=unknown] @typedef {import('@endo/eventual-send').RemoteKit<R>} RemoteKit */
/** @import {RemoteKit, Settler} from '@endo/eventual-send' */

// Your app may need to `import '@endo/eventual-send/shim.js'` to get HandledPromise

Expand Down Expand Up @@ -804,7 +802,7 @@ export const makeCapTP = (
serialize,
unserialize,
makeTrapHandler,
Trap: /** @type {import('./types.js').Trap | undefined} */ (undefined),
Trap: /** @type {import('./ts-types.js').Trap | undefined} */ (undefined),
};

if (trapGuest) {
Expand Down
5 changes: 1 addition & 4 deletions packages/captp/src/loopback.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { makeFinalizingMap } from './finalize.js';

export { E };

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

/**
* Create an async-isolated channel to an object.
Expand Down
2 changes: 1 addition & 1 deletion packages/captp/src/trap.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const TrapProxyHandler = (x, trapImpl) => {

/**
* @param {import('./types.js').TrapImpl} trapImpl
* @returns {Trap}
* @returns {import('./ts-types.js').Trap}
*/
export const makeTrap = trapImpl => {
const Trap = x => {
Expand Down
7 changes: 0 additions & 7 deletions packages/captp/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,3 @@ export {};
* @returns {AsyncIterator<void, void, any> | undefined} If an AsyncIterator is
* returned, it will satisfy a future guest IterationObserver.
*/

/** @typedef {import('./ts-types.js').Trap} Trap */

/**
* @template T
* @typedef {import('./ts-types').TrapHandler<T>} TrapHandler
*/
43 changes: 23 additions & 20 deletions packages/compartment-mapper/src/import-archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { assertCompartmentMap } from './compartment-map.js';
import { exitModuleImportHookMaker } from './import-hook.js';
import { attenuateModuleHook, enforceModulePolicy } from './policy.js';

/** @import {StaticModuleType} from 'ses' */
/** @import {Application, CompartmentDescriptor, ComputeSourceLocationHook, ComputeSourceMapLocationHook, ExecuteFn, ExecuteOptions, ExitModuleImportHook, HashFn, ImportHookMaker, LoadArchiveOptions, ParserImplementation, ReadPowers} from './types.js' */

const DefaultCompartment = Compartment;

const { Fail, quote: q } = assert;
Expand All @@ -23,7 +26,7 @@ const textDecoder = new TextDecoder();

const { freeze } = Object;

/** @type {Record<string, import('./types.js').ParserImplementation>} */
/** @type {Record<string, ParserImplementation>} */
const parserForLanguage = {
'pre-cjs-json': parserPreCjs,
'pre-mjs-json': parserPreMjs,
Expand All @@ -34,7 +37,7 @@ const parserForLanguage = {

/**
* @param {string} errorMessage - error to throw on execute
* @returns {import('./types.js').StaticModuleType}
* @returns {StaticModuleType}
*/
const postponeErrorToExecute = errorMessage => {
// Return a place-holder that'd throw an error if executed
Expand All @@ -55,13 +58,13 @@ const postponeErrorToExecute = errorMessage => {

/**
* @param {(path: string) => Uint8Array} get
* @param {Record<string, import('./types.js').CompartmentDescriptor>} compartments
* @param {Record<string, CompartmentDescriptor>} compartments
* @param {string} archiveLocation
* @param {import('./types.js').HashFn} [computeSha512]
* @param {import('./types.js').ComputeSourceLocationHook} [computeSourceLocation]
* @param {import('./types.js').ExitModuleImportHook} [exitModuleImportHook]
* @param {import('./types.js').ComputeSourceMapLocationHook} [computeSourceMapLocation]
* @returns {import('./types.js').ImportHookMaker}
* @param {HashFn} [computeSha512]
* @param {ComputeSourceLocationHook} [computeSourceLocation]
* @param {ExitModuleImportHook} [exitModuleImportHook]
* @param {ComputeSourceMapLocationHook} [computeSourceMapLocation]
* @returns {ImportHookMaker}
*/
const makeArchiveImportHookMaker = (
get,
Expand All @@ -73,7 +76,7 @@ const makeArchiveImportHookMaker = (
computeSourceMapLocation = undefined,
) => {
// per-assembly:
/** @type {import('./types.js').ImportHookMaker} */
/** @type {ImportHookMaker} */
const makeImportHook = ({
packageLocation,
packageName,
Expand Down Expand Up @@ -244,13 +247,13 @@ const makeFauxModuleExportsNamespace = Compartment => {
* @param {string} [archiveLocation]
* @param {object} [options]
* @param {string} [options.expectedSha512]
* @param {import('./types.js').HashFn} [options.computeSha512]
* @param {HashFn} [options.computeSha512]
* @param {Record<string, unknown>} [options.modules]
* @param {import('./types.js').ExitModuleImportHook} [options.importHook]
* @param {ExitModuleImportHook} [options.importHook]
* @param {CompartmentConstructor} [options.Compartment]
* @param {import('./types.js').ComputeSourceLocationHook} [options.computeSourceLocation]
* @param {import('./types.js').ComputeSourceMapLocationHook} [options.computeSourceMapLocation]
* @returns {Promise<import('./types.js').Application>}
* @param {ComputeSourceLocationHook} [options.computeSourceLocation]
* @param {ComputeSourceMapLocationHook} [options.computeSourceMapLocation]
* @returns {Promise<Application>}
*/
export const parseArchive = async (
archiveBytes,
Expand Down Expand Up @@ -356,7 +359,7 @@ export const parseArchive = async (
)}`;
}

/** @type {import('./types.js').ExecuteFn} */
/** @type {ExecuteFn} */
const execute = async options => {
const {
globals,
Expand Down Expand Up @@ -400,10 +403,10 @@ export const parseArchive = async (
};

/**
* @param {import('./types.js').ReadFn | import('./types.js').ReadPowers} readPowers
* @param {import('@endo/zip').ReadFn | ReadPowers} readPowers
* @param {string} archiveLocation
* @param {import('./types.js').LoadArchiveOptions} [options]
* @returns {Promise<import('./types.js').Application>}
* @param {LoadArchiveOptions} [options]
* @returns {Promise<Application>}
*/
export const loadArchive = async (
readPowers,
Expand All @@ -428,9 +431,9 @@ export const loadArchive = async (
};

/**
* @param {import('./types.js').ReadFn | import('./types.js').ReadPowers} readPowers
* @param {import('@endo/zip').ReadFn | ReadPowers} readPowers
* @param {string} archiveLocation
* @param {import('./types.js').ExecuteOptions & import('./types.js').LoadArchiveOptions} options
* @param {ExecuteOptions & LoadArchiveOptions} options
* @returns {Promise<object>}
*/
export const importArchive = async (readPowers, archiveLocation, options) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/compartment-mapper/src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
/** @import {ModuleDescriptor} from './types.js' */
/** @import {CompartmentDescriptor} from './types.js' */
/** @import {CompartmentMapDescriptor} from './types.js' */
/** @import {DeferredAttenuatorsProvider} from './types.js' */
/** @import {LinkOptions} from './types.js' */
/** @template T @typedef {import('@endo/eventual-send').ERef<T>} ERef */
/** @import {ERef} from '@endo/eventual-send' */

import { resolve as resolveFallback } from './node-module-specifier.js';
import { parseExtension } from './extension.js';
Expand Down
10 changes: 5 additions & 5 deletions packages/compartment-mapper/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

export {};

/** @typedef {import('ses').FinalStaticModuleType} FinalStaticModuleType */
/** @typedef {import('ses').ThirdPartyStaticModuleInterface} ThirdPartyStaticModuleInterface */
/** @typedef {import('ses').ImportHook} ImportHook */
/** @typedef {import('ses').StaticModuleType} StaticModuleType */
/** @typedef {import('ses').Transform} Transform */
/** @import {FinalStaticModuleType} from 'ses' */
/** @import {ThirdPartyStaticModuleInterface} from 'ses' */
/** @import {ImportHook} from 'ses' */
/** @import {StaticModuleType} from 'ses' */
/** @import {Transform} from 'ses' */

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

Expand Down
1 change: 1 addition & 0 deletions packages/far/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { E } from '@endo/eventual-send';
export { Far, getInterfaceOf, passStyleOf } from '@endo/pass-style';

// TODO re-export from eventual-send, may require .d.ts
/**
* @template Primary
* @template [Local=import('@endo/eventual-send').DataOnly<Primary>]
Expand Down
1 change: 0 additions & 1 deletion packages/marshal/src/deeplyFulfilled.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { isPromise } from '@endo/promise-kit';
import { getTag, isObject, makeTagged, passStyleOf } from '@endo/pass-style';

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

import { X, q } from '@endo/errors';

Expand Down
6 changes: 2 additions & 4 deletions packages/marshal/src/encodeToSmallcaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ import {
} from '@endo/pass-style';
import { X, Fail, q } from '@endo/errors';

/** @import {Passable} from '@endo/pass-style' */
/** @import {Remotable} from '@endo/pass-style' */
// @typedef {import('./types.js').SmallcapsEncoding} SmallcapsEncoding */
// @typedef {import('./types.js').SmallcapsEncodingUnion} SmallcapsEncodingUnion */
/** @import {Passable, Remotable} from '@endo/pass-style' */
// FIXME define actual types
/** @typedef {any} SmallcapsEncoding */
/** @typedef {any} SmallcapsEncodingUnion */

Expand Down
1 change: 0 additions & 1 deletion packages/marshal/src/marshal-justin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { q, X, Fail } from '@endo/errors';
import { QCLASS } from './encodeToCapData.js';

/** @import {Encoding} from './types.js' */
/** @template T @typedef {import('./types.js').CapData<T>} CapData */

const { ownKeys } = Reflect;
const { isArray } = Array;
Expand Down
6 changes: 1 addition & 5 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import {
makeEncodeToSmallcaps,
} from './encodeToSmallcaps.js';

/** @import {MakeMarshalOptions} from './types.js' */
/** @template Slot @typedef {import('./types.js').ConvertSlotToVal<Slot>} ConvertSlotToVal */
/** @template Slot @typedef {import('./types.js').ConvertValToSlot<Slot>} ConvertValToSlot */
/** @template Slot @typedef {import('./types.js').ToCapData<Slot>} ToCapData */
/** @template Slot @typedef {import('./types.js').FromCapData<Slot>} FromCapData */
/** @import {ConvertSlotToVal, ConvertValToSlot, FromCapData, MakeMarshalOptions, ToCapData} from './types.js' */
/** @import {Passable} from '@endo/pass-style' */
/** @import {InterfaceSpec} from '@endo/pass-style' */
/** @import {Encoding} from './types.js' */
Expand Down
6 changes: 3 additions & 3 deletions packages/pass-style/src/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { X, q } from '@endo/errors';
import { assertChecker } from './passStyle-helpers.js';

/** @import {PassStyleHelper} from './internal-types.js' */
/** @import {Checker} from './types.js' */
/** @import {Checker, PassStyleOf} from './types.js' */

const { getPrototypeOf, getOwnPropertyDescriptors, hasOwn, entries } = Object;

Expand Down Expand Up @@ -88,7 +88,7 @@ harden(isErrorLike);
/**
* @param {string} propName
* @param {PropertyDescriptor} desc
* @param {import('./internal-types.js').PassStyleOf} passStyleOfRecur
* @param {PassStyleOf} passStyleOfRecur
* @param {Checker} [check]
* @returns {boolean}
*/
Expand Down Expand Up @@ -157,7 +157,7 @@ harden(checkRecursivelyPassableErrorPropertyDesc);

/**
* @param {unknown} candidate
* @param {import('./internal-types.js').PassStyleOf} passStyleOfRecur
* @param {PassStyleOf} passStyleOfRecur
* @param {Checker} [check]
* @returns {boolean}
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/pass-style/src/internal-types.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export {};

/** @typedef {import('./types.js').Checker} Checker */
/** @typedef {import('./types.js').PassStyle} PassStyle */
/** @typedef {import('./types.js').PassStyleOf} PassStyleOf */
/** @import {Checker} from './types.js' */
/** @import {PassStyle} from './types.js' */
/** @import {PassStyleOf} from './types.js' */

/**
* The PassStyleHelper are only used to make a `passStyleOf` function.
Expand Down
2 changes: 1 addition & 1 deletion packages/pass-style/src/make-far.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { q, Fail } from '@endo/errors';
import { assertChecker, PASS_STYLE } from './passStyle-helpers.js';
import { assertIface, getInterfaceOf, RemotableHelper } from './remotable.js';

/** @import {RemotableBrand} from '@endo/eventual-send' */
/** @import {InterfaceSpec} from './types.js' */
/** @template L,R @typedef {import('@endo/eventual-send').RemotableBrand<L, R>} RemotableBrand */

const { prototype: functionPrototype } = Function;
const {
Expand Down
11 changes: 1 addition & 10 deletions packages/pass-style/src/typeGuards.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { Fail, q } from '@endo/errors';
import { passStyleOf } from './passStyleOf.js';

/** @import {Passable} from './types.js' */
/**
* @template {Passable} [T=Passable]
* @typedef {import('./types.js').CopyArray<T>} CopyArray
*/
/**
* @template {Passable} [T=Passable]
* @typedef {import('./types.js').CopyRecord<T>} CopyRecord
*/
/** @import {RemotableObject} from './types.js' */
/** @import {CopyArray, CopyRecord, Passable, RemotableObject} from './types.js' */

/**
* Check whether the argument is a pass-by-copy array, AKA a "copyArray"
Expand Down
8 changes: 1 addition & 7 deletions packages/patterns/src/keys/checkKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ const { ownKeys } = Reflect;

/** @import {Checker} from '@endo/marshal' */
/** @import {Passable} from '@endo/pass-style' */
/** @import {KeyComparison} from '../types' */
/** @import {Key} from '../types' */
/** @template {Key} [K=Key] @typedef {import('../types').CopyBag<K>} CopyBag */
/** @template {Key} [K=Key] @typedef {import('../types').CopySet<K>} CopySet */
/** @template {Key} [K=Key] @template {Passable} [V=Passable] @typedef {import('../types').CopyMap<K, V>} CopyMap */
/** @import {KeyCompare} from '../types' */
/** @import {FullCompare} from '../types' */
/** @import {CopyBag, CopyMap, CopySet, Key} from '../types' */

// ////////////////// Primitive and Scalar keys ////////////////////////////////

Expand Down
2 changes: 1 addition & 1 deletion packages/patterns/src/keys/compareKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './checkKey.js';
import { makeCompareCollection } from './keycollection-operators.js';

/** @template {import('../types.js').Key} [K=import('../types.js').Key] @typedef {import('../types').CopySet<K>} CopySet */
/** @import {CopySet} from '../types' */

/**
* CopySet X is smaller than CopySet Y iff all of these conditions hold:
Expand Down
3 changes: 1 addition & 2 deletions packages/patterns/src/keys/copyBag.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {

import { X } from '@endo/errors';

/** @template {Key} [K=Key] @typedef {import('../types').CopyBag<K>} CopyBag */
/** @import {Key} from '../types' */
/** @import {CopyBag} from '../types' */
/** @import {FullCompare} from '../types' */
/** @import {Checker} from '@endo/marshal' */
/** @import {Passable} from '@endo/pass-style' */
Expand Down
18 changes: 10 additions & 8 deletions packages/patterns/src/patterns/getGuardPayloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
} from './patternMatchers.js';
import { getCopyMapKeys, makeCopyMap } from '../keys/checkKey.js';

/** @import {AwaitArgGuard, AwaitArgGuardPayload, InterfaceGuard, InterfaceGuardPayload, MethodGuard, MethodGuardPayload} from '../types.js' */

// The get*GuardPayload functions exist to adapt to the worlds both
// before and after https://github.com/endojs/endo/pull/1712 . When
// given something that would be the expected guard in either world,
Expand Down Expand Up @@ -58,8 +60,8 @@ const LegacyAwaitArgGuardShape = harden({
* an argument that matches that pattern, i.e., a copyRecord argument that
* at least contains a `klass: 'awaitArgGuard'` property.
*
* @param {import('./types.js').AwaitArgGuard} awaitArgGuard
* @returns {import('./types.js').AwaitArgGuardPayload}
* @param {AwaitArgGuard} awaitArgGuard
* @returns {AwaitArgGuardPayload}
*/
export const getAwaitArgGuardPayload = awaitArgGuard => {
if (matches(awaitArgGuard, LegacyAwaitArgGuardShape)) {
Expand Down Expand Up @@ -142,8 +144,8 @@ const adaptLegacyArgGuard = argGuard =>
* currently any context where either a methodGuard or a copyRecord would
* both be meaningful.
*
* @param {import('./types.js').MethodGuard} methodGuard
* @returns {import('./types.js').MethodGuardPayload}
* @param {MethodGuard} methodGuard
* @returns {MethodGuardPayload}
*/
export const getMethodGuardPayload = methodGuard => {
if (matches(methodGuard, MethodGuardShape)) {
Expand Down Expand Up @@ -234,9 +236,9 @@ const adaptMethodGuard = methodGuard => {
* currently any context where either an interfaceGuard or a copyRecord would
* both be meaningful.
*
* @template {Record<PropertyKey, import('./types.js').MethodGuard>} [T=Record<PropertyKey, import('./types.js').MethodGuard>]
* @param {import('./types.js').InterfaceGuard<T>} interfaceGuard
* @returns {import('./types.js').InterfaceGuardPayload<T>}
* @template {Record<PropertyKey, MethodGuard>} [T=Record<PropertyKey, MethodGuard>]
* @param {InterfaceGuard<T>} interfaceGuard
* @returns {InterfaceGuardPayload<T>}
*/
export const getInterfaceGuardPayload = interfaceGuard => {
if (matches(interfaceGuard, InterfaceGuardShape)) {
Expand Down Expand Up @@ -264,7 +266,7 @@ harden(getInterfaceGuardPayload);
const emptyCopyMap = makeCopyMap([]);

/**
* @param {import('./types.js').InterfaceGuard} interfaceGuard
* @param {InterfaceGuard} interfaceGuard
* @returns {(string | symbol)[]}
*/
export const getInterfaceMethodKeys = interfaceGuard => {
Expand Down
Loading

0 comments on commit 38e61af

Please sign in to comment.