Skip to content

Commit 6cf51fe

Browse files
committed
feat(import-bundle): Add typedImportBundle (instead of type on importBundle)
1 parent d3304eb commit 6cf51fe

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

packages/import-bundle/NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ User-visible changes to `@endo/import-bundle`:
66
object that resembles a module exports namespace with the objects specified
77
on the symbol-named property @exports, which is deliberately not JSON
88
serializable or passable.
9+
- Exports a `typedImportBundle<ExpectedNamespaceType>` function so consumers
10+
can subscribe to a narrower type.
911

1012
# v1.3.0 (2024-10-10)
1113

packages/import-bundle/src/index.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,8 @@ import { wrapInescapableCompartment } from './compartment-wrapper.js';
1818
* @typedef {import('@endo/bundle-source').BundleSourceResult<any> | {moduleFormat: 'test'}} ImportableBundle
1919
*/
2020

21-
/**
22-
* importBundle takes the output of `bundleSource` or `bundleTestExports`, and returns a namespace
23-
* object (with .default, and maybe other properties for named exports)
24-
*
25-
* @template [T=any]
26-
* @param {ImportableBundle} bundle
27-
* @param {object} [options]
28-
* @param {object} [powers]
29-
* @returns {Promise<T>}
30-
*/
21+
// Adding a type signature in-place proved difficult to migrate in-place.
22+
// See typedImportBundle below.
3123
export async function importBundle(bundle, options = {}, powers = {}) {
3224
await null;
3325
const {
@@ -194,6 +186,22 @@ export async function importBundle(bundle, options = {}, powers = {}) {
194186
}
195187
}
196188

189+
/**
190+
* typedImportBundle<Expected> takes the output of `bundleSource` or
191+
* `bundleTestExports`, and returns a namespace object, with .default, and
192+
* maybe other properties for named exports.
193+
*
194+
* This is the intended signature but produces a type that is not suitable
195+
* in integration with legacy code of Agoric SDK.
196+
*
197+
* @template [T=any]
198+
* @param {ImportableBundle} bundle
199+
* @param {object} [options]
200+
* @param {object} [powers]
201+
* @returns {Promise<T>}
202+
*/
203+
export const typedImportBundle = importBundle;
204+
197205
/**
198206
* A utility function for producing test bundles, which are not serializable
199207
* as JSON or passable.

0 commit comments

Comments
 (0)