Skip to content

Commit

Permalink
chore(types): @import
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Apr 28, 2024
1 parent 17f0ed1 commit 32c32ca
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
15 changes: 9 additions & 6 deletions packages/network/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { Shape } from './shapes.js';

import '@agoric/store/exported.js';
/// <reference path="./types.js" />
/**
* @import {VowTools} from '@agoric/vow';
*/

/**
* Compatibility note: this must match what our peers use, so don't change it
Expand Down Expand Up @@ -58,7 +61,7 @@ export function getPrefixes(addr) {

/**
* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {VowTools} powers
*/
const prepareHalfConnection = (zone, { watch }) => {
const makeHalfConnectionKit = zone.exoClassKit(
Expand Down Expand Up @@ -215,7 +218,7 @@ export const crossoverConnection = (
/**
* @param {import('@agoric/zone').Zone} zone
* @param {(opts: ConnectionOpts) => Connection} makeConnection
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {VowTools} powers
*/
const prepareInboundAttempt = (zone, makeConnection, { watch }) => {
const makeInboundAttemptKit = zone.exoClassKit(
Expand Down Expand Up @@ -380,7 +383,7 @@ const RevokeState = /** @type {const} */ ({

/**
* @param {import('@agoric/zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {VowTools} powers
*/
const preparePort = (zone, powers) => {
const makeIncapable = zone.exoClass('Incapable', undefined, () => ({}), {});
Expand Down Expand Up @@ -630,7 +633,7 @@ const preparePort = (zone, powers) => {

/**
* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {VowTools} powers
*/
const prepareBinder = (zone, powers) => {
const makeConnection = prepareHalfConnection(zone, powers);
Expand Down Expand Up @@ -1149,7 +1152,7 @@ const prepareBinder = (zone, powers) => {

/**
* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {VowTools} powers
*/
export const prepareNetworkProtocol = (zone, powers) => {
const makeBinderKit = prepareBinder(zone, powers);
Expand Down Expand Up @@ -1272,7 +1275,7 @@ export const prepareEchoConnectionKit = zone => {
* Create a protocol handler that just connects to itself.
*
* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {VowTools} powers
*/
export function prepareLoopbackProtocolHandler(zone, { watch, allVows }) {
const detached = zone.detached();
Expand Down
6 changes: 5 additions & 1 deletion packages/network/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { Shape } from './shapes.js';
import '@agoric/store/exported.js';
/// <reference path="./types.js" />

/**
* @import {VowTools} from '@agoric/vow';
*/

/**
* @template T
* @typedef {object} Router A delimited string router implementation
Expand Down Expand Up @@ -102,7 +106,7 @@ export const prepareRouter = zone => {
* Create a router that behaves like a Protocol.
*
* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
* @param {VowTools} powers
* @param {typeof defaultE} [E] Eventual sender
*/
export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/network/src/types.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check

/** @import {PromiseVow, Remote} from '@agoric/vow' */
/** @import {PromiseVow, Remote} from '@agoric/vow'; */

/**
* @template {import('@endo/exo').Methods} M
Expand Down
29 changes: 17 additions & 12 deletions packages/vow/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import { getVowPayload, basicE } from './vow-utils.js';
import { PromiseWatcherI, watchPromiseShim } from './watch-promise.js';

/**
* @import {PromiseWatcher} from './watch-promise.js';
* @import {ERef, Vow, VowKit, VowResolver, Watcher} from './types.js';
*/

const { apply } = Reflect;

/**
Expand All @@ -15,7 +20,7 @@ const makeWatchNextStep =
* (usually durable) watcher object with the promise.
*
* @param {any} specimen
* @param {import('./watch-promise.js').PromiseWatcher} promiseWatcher
* @param {PromiseWatcher} promiseWatcher
*/
(specimen, promiseWatcher) => {
let promise;
Expand All @@ -29,9 +34,9 @@ const makeWatchNextStep =
};

/**
* @param {import('./types.js').VowResolver | undefined} resolver
* @param {import('./types.js').Watcher<unknown, unknown, unknown> | undefined} watcher
* @param {keyof Required<import('./types.js').Watcher>} wcb
* @param {VowResolver | undefined} resolver
* @param {Watcher<unknown, unknown, unknown> | undefined} watcher
* @param {keyof Required<Watcher>} wcb
* @param {unknown} value
* @param {unknown} [watcherContext]
*/
Expand Down Expand Up @@ -68,8 +73,8 @@ const preparePromiseWatcher = (zone, isRetryableReason, watchNextStep) =>
* @template [T=any]
* @template [TResult1=T]
* @template [TResult2=never]
* @param {import('./types.js').VowResolver<TResult1 | TResult2>} resolver
* @param {import('./types.js').Watcher<T, TResult1, TResult2>} [watcher]
* @param {VowResolver<TResult1 | TResult2>} resolver
* @param {Watcher<T, TResult1, TResult2>} [watcher]
* @param {unknown} [watcherContext]
*/
(resolver, watcher, watcherContext) => {
Expand All @@ -82,7 +87,7 @@ const preparePromiseWatcher = (zone, isRetryableReason, watchNextStep) =>
return /** @type {Partial<typeof state>} */ (state);
},
{
/** @type {Required<import('./watch-promise.js').PromiseWatcher>['onFulfilled']} */
/** @type {Required<PromiseWatcher>['onFulfilled']} */
onFulfilled(value) {
const { watcher, watcherContext, resolver } = this.state;
if (getVowPayload(value)) {
Expand All @@ -95,7 +100,7 @@ const preparePromiseWatcher = (zone, isRetryableReason, watchNextStep) =>
this.state.resolver = undefined;
settle(resolver, watcher, 'onFulfilled', value, watcherContext);
},
/** @type {Required<import('./watch-promise.js').PromiseWatcher>['onRejected']} */
/** @type {Required<PromiseWatcher>['onRejected']} */
onRejected(reason) {
const { vow, watcher, watcherContext, resolver } = this.state;
if (vow && isRetryableReason(reason)) {
Expand All @@ -111,7 +116,7 @@ const preparePromiseWatcher = (zone, isRetryableReason, watchNextStep) =>

/**
* @param {import('@agoric/base-zone').Zone} zone
* @param {() => import('./types.js').VowKit<any>} makeVowKit
* @param {() => VowKit<any>} makeVowKit
* @param {typeof watchPromiseShim} [watchPromise]
* @param {(reason: any) => boolean} [isRetryableReason]
*/
Expand All @@ -133,12 +138,12 @@ export const prepareWatch = (
* @template [TResult1=T]
* @template [TResult2=T]
* @template [C=unknown] watcher context
* @param {import('./types.js').ERef<T | import('./types.js').Vow<T>>} specimenP
* @param {import('./types.js').Watcher<T, TResult1, TResult2>} [watcher]
* @param {ERef<T | Vow<T>>} specimenP
* @param {Watcher<T, TResult1, TResult2>} [watcher]
* @param {C} [watcherContext]
*/
const watch = (specimenP, watcher, watcherContext) => {
/** @type {import('./types.js').VowKit<TResult1 | TResult2>} */
/** @type {VowKit<TResult1 | TResult2>} */
const { resolver, vow } = makeVowKit();

// Create a promise watcher to track vows, retrying upon rejection as
Expand Down

0 comments on commit 32c32ca

Please sign in to comment.